2 * Dynamic Binary Instrumentation Module based on KProbes
3 * energy/debugfs_energy.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
27 #include <linux/module.h>
28 #include <linux/debugfs.h>
29 #include <linux/math64.h>
30 #include <master/swap_debugfs.h>
32 #include "debugfs_energy.h"
33 #include "rational_debugfs.h"
34 #include "lcd/lcd_debugfs.h"
35 #include "lcd/lcd_base.h"
39 static DEFINE_RATIONAL(cpu0_running_coef); /* boot core uses distinct coeff */
40 static DEFINE_RATIONAL(cpuN_running_coef);
42 static u64 __energy_cpu(enum parameter_energy pe)
44 u64 times[NR_CPUS] = { 0 };
48 if (get_parameter_energy(pe, times, sizeof(times)) == 0) {
49 val = div_u64(times[0] * cpu0_running_coef.num,
50 cpu0_running_coef.denom);
51 for (i = 1; i < NR_CPUS; i++)
52 val += div_u64(times[i] * cpuN_running_coef.num,
53 cpuN_running_coef.denom);
59 static u64 cpu_system(void)
61 return __energy_cpu(PE_TIME_SYSTEM);
64 static u64 cpu_apps(void)
66 return __energy_cpu(PE_TIME_APPS);
71 static DEFINE_RATIONAL(cpu_idle_coef);
73 static u64 cpu_idle_system(void)
77 get_parameter_energy(PE_TIME_IDLE, &time, sizeof(time));
78 return div_u64(time * cpu_idle_coef.num, cpu_idle_coef.denom);
83 static DEFINE_RATIONAL(fr_coef);
85 static u64 fr_system(void)
89 get_parameter_energy(PE_READ_SYSTEM, &byte, sizeof(byte));
90 return div_u64(byte * fr_coef.num, fr_coef.denom);
93 static u64 fr_apps(void)
97 get_parameter_energy(PE_READ_APPS, &byte, sizeof(byte));
98 return div_u64(byte * fr_coef.num, fr_coef.denom);
103 static DEFINE_RATIONAL(fw_coef);
105 static u64 fw_system(void)
109 get_parameter_energy(PE_WRITE_SYSTEM, &byte, sizeof(byte));
110 return div_u64(byte * fw_coef.num, fw_coef.denom);
113 static u64 fw_apps(void)
117 get_parameter_energy(PE_WRITE_APPS, &byte, sizeof(byte));
118 return div_u64(byte * fw_coef.num, fw_coef.denom);
123 static DEFINE_RATIONAL(wf_recv_coef);
125 static u64 wf_recv_system(void)
129 get_parameter_energy(PE_WF_RECV_SYSTEM, &byte, sizeof(byte));
131 return div_u64(byte * wf_recv_coef.num, wf_recv_coef.denom);
134 static u64 wf_recv_apps(void)
138 get_parameter_energy(PE_WF_RECV_APPS, &byte, sizeof(byte));
140 return div_u64(byte * wf_recv_coef.num, wf_recv_coef.denom);
144 static DEFINE_RATIONAL(wf_send_coef);
146 static u64 wf_send_system(void)
150 get_parameter_energy(PE_WF_SEND_SYSTEM, &byte, sizeof(byte));
152 return div_u64(byte * wf_send_coef.num, wf_send_coef.denom);
155 static u64 wf_send_apps(void)
159 get_parameter_energy(PE_WF_SEND_APPS, &byte, sizeof(byte));
161 return div_u64(byte * wf_send_coef.num, wf_send_coef.denom);
164 /* ============================================================================
166 * ============================================================================
168 static int get_func_u64(void *data, u64 *val)
170 u64 (*func)(void) = data;
175 SWAP_DEFINE_SIMPLE_ATTRIBUTE(fops_get_u64, get_func_u64, NULL, "%llu\n");
180 struct rational *coef;
185 static struct dentry *create_parameter(struct dentry *parent,
186 struct param_data *param)
188 struct dentry *name, *system, *apps = NULL;
190 name = debugfs_create_dir(param->name, parent);
194 system = debugfs_create_file("system", 0600, name, param->system,
200 apps = debugfs_create_file("apps", 0600, name, param->apps,
206 if (create_rational_files(name, param->coef,
207 "numerator", "denominator"))
214 debugfs_remove(apps);
216 debugfs_remove(system);
218 debugfs_remove(name);
223 struct param_data parameters[] = {
225 .name = "cpu_running",
226 .coef = &cpu0_running_coef,
227 .system = cpu_system,
231 .name = "cpuN_running",
232 .coef = &cpuN_running_coef,
233 .system = cpu_system,
238 .coef = &cpu_idle_coef,
239 .system = cpu_idle_system,
243 .name = "flash_read",
249 .name = "flash_write",
256 .coef = &wf_recv_coef,
257 .system = wf_recv_system,
262 .coef = &wf_send_coef,
263 .system = wf_send_system,
269 parameters_cnt = sizeof(parameters) / sizeof(struct param_data)
276 /* ============================================================================
278 * ============================================================================
280 static struct dentry *energy_dir;
283 * @brief Destroy debugfs for LCD
285 * @return Dentry of energy debugfs
287 struct dentry *get_energy_dir(void)
293 * @brief Destroy debugfs for energy
297 void exit_debugfs_energy(void)
303 debugfs_remove_recursive(energy_dir);
309 * @brief Create debugfs for energy
313 int init_debugfs_energy(void)
316 struct dentry *swap_dir, *dentry;
318 swap_dir = swap_debugfs_getdir();
319 if (swap_dir == NULL)
322 energy_dir = debugfs_create_dir("energy", swap_dir);
323 if (energy_dir == NULL)
326 for (i = 0; i < parameters_cnt; ++i) {
327 dentry = create_parameter(energy_dir, ¶meters[i]);
332 if (init_lcd_debugfs(energy_dir))
335 /* Actually, the only goal of lcd_init() is to register lcd screen's
336 debugfs, so it is called here. */
344 exit_debugfs_energy();