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 <driver/swap_debugfs.h>
32 #include "rational_debugfs.h"
33 #include "lcd/lcd_debugfs.h"
37 static DEFINE_RATIONAL(cpu0_running_coef); /* boot core uses distinct coeff */
38 static DEFINE_RATIONAL(cpuN_running_coef);
40 static u64 __energy_cpu(enum parameter_energy pe)
42 u64 times[NR_CPUS] = { 0 };
46 if (get_parameter_energy(pe, times, sizeof(times)) == 0) {
47 val = div_u64(times[0] * cpu0_running_coef.num,
48 cpu0_running_coef.denom);
49 for (i = 1; i < NR_CPUS; i++)
50 val += div_u64(times[i] * cpuN_running_coef.num,
51 cpuN_running_coef.denom);
57 static u64 cpu_system(void)
59 return __energy_cpu(PE_TIME_SYSTEM);
62 static u64 cpu_apps(void)
64 return __energy_cpu(PE_TIME_APPS);
69 static DEFINE_RATIONAL(cpu_idle_coef);
71 static u64 cpu_idle_system(void)
75 get_parameter_energy(PE_TIME_IDLE, &time, sizeof(time));
76 return div_u64(time * cpu_idle_coef.num, cpu_idle_coef.denom);
81 static DEFINE_RATIONAL(fr_coef);
83 static u64 fr_system(void)
87 get_parameter_energy(PE_READ_SYSTEM, &byte, sizeof(byte));
88 return div_u64(byte * fr_coef.num, fr_coef.denom);
91 static u64 fr_apps(void)
95 get_parameter_energy(PE_READ_APPS, &byte, sizeof(byte));
96 return div_u64(byte * fr_coef.num, fr_coef.denom);
101 static DEFINE_RATIONAL(fw_coef);
103 static u64 fw_system(void)
107 get_parameter_energy(PE_WRITE_SYSTEM, &byte, sizeof(byte));
108 return div_u64(byte * fw_coef.num, fw_coef.denom);
111 static u64 fw_apps(void)
115 get_parameter_energy(PE_WRITE_APPS, &byte, sizeof(byte));
116 return div_u64(byte * fw_coef.num, fw_coef.denom);
123 /* ============================================================================
125 * ============================================================================
127 static int get_func_u64(void *data, u64 *val)
129 u64 (*func)(void) = data;
134 DEFINE_SIMPLE_ATTRIBUTE(fops_get_u64, get_func_u64, NULL, "%llu\n");
139 struct rational *coef;
144 static struct dentry *create_parameter(struct dentry *parent,
145 struct param_data *param)
147 struct dentry *name, *system, *apps = NULL;
149 name = debugfs_create_dir(param->name, parent);
153 system = debugfs_create_file("system", 0600, name, param->system,
159 apps = debugfs_create_file("apps", 0600, name, param->apps,
165 if (create_rational_files(name, param->coef,
166 "numerator", "denominator"))
173 debugfs_remove(apps);
175 debugfs_remove(system);
177 debugfs_remove(name);
182 struct param_data parameters[] = {
184 .name = "cpu_running",
185 .coef = &cpu0_running_coef,
186 .system = cpu_system,
190 .name = "cpuN_running",
191 .coef = &cpuN_running_coef,
192 .system = cpu_system,
197 .coef = &cpu_idle_coef,
198 .system = cpu_idle_system,
202 .name = "flash_read",
208 .name = "flash_write",
216 parameters_cnt = sizeof(parameters) / sizeof(struct param_data)
223 /* ============================================================================
225 * ============================================================================
227 static struct dentry *energy_dir = NULL;
230 * @brief Destroy debugfs for LCD
232 * @return Dentry of energy debugfs
234 struct dentry *get_energy_dir(void)
240 * @brief Destroy debugfs for energy
244 void exit_debugfs_energy(void)
247 debugfs_remove_recursive(energy_dir);
253 * @brief Create debugfs for energy
257 int init_debugfs_energy(void)
260 struct dentry *swap_dir, *dentry;
262 swap_dir = get_swap_debugfs_dir();
263 if (swap_dir == NULL)
266 energy_dir = debugfs_create_dir("energy", swap_dir);
267 if (energy_dir == NULL)
270 for (i = 0; i < parameters_cnt; ++i) {
271 dentry = create_parameter(energy_dir, ¶meters[i]);
279 exit_debugfs_energy();