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(cpu_running_coef);
39 static u64 cpu_system(void)
41 u64 time = get_parameter_energy(PE_TIME_SYSTEM);
43 return div_u64(time * cpu_running_coef.num, cpu_running_coef.denom);
46 static u64 cpu_apps(void)
48 u64 time = get_parameter_energy(PE_TIME_APPS);
50 return div_u64(time * cpu_running_coef.num, cpu_running_coef.denom);
55 static DEFINE_RATIONAL(cpu_idle_coef);
57 static u64 cpu_idle_system(void)
59 u64 time = get_parameter_energy(PE_TIME_IDLE);
61 return div_u64(time * cpu_idle_coef.num, cpu_idle_coef.denom);
66 static DEFINE_RATIONAL(fr_coef);
68 static u64 fr_system(void)
70 u64 byte = get_parameter_energy(PE_READ_SYSTEM);
72 return div_u64(byte * fr_coef.num, fr_coef.denom);
75 static u64 fr_apps(void)
77 u64 byte = get_parameter_energy(PE_READ_APPS);
79 return div_u64(byte * fr_coef.num, fr_coef.denom);
84 static DEFINE_RATIONAL(fw_coef);
86 static u64 fw_system(void)
88 u64 byte = get_parameter_energy(PE_WRITE_SYSTEM);
90 return div_u64(byte * fw_coef.num, fw_coef.denom);
93 static u64 fw_apps(void)
95 u64 byte = get_parameter_energy(PE_WRITE_APPS);
97 return div_u64(byte * fw_coef.num, fw_coef.denom);
104 /* ============================================================================
106 * ============================================================================
108 static int get_func_u64(void *data, u64 *val)
110 u64 (*func)(void) = data;
115 DEFINE_SIMPLE_ATTRIBUTE(fops_get_u64, get_func_u64, NULL, "%llu\n");
120 struct rational *coef;
125 static struct dentry *create_parameter(struct dentry *parent,
126 struct param_data *param)
128 struct dentry *name, *system, *apps = NULL;
130 name = debugfs_create_dir(param->name, parent);
134 system = debugfs_create_file("system", 0600, name, param->system,
140 apps = debugfs_create_file("apps", 0600, name, param->apps,
146 if (create_rational_files(name, param->coef,
147 "numerator", "denominator"))
154 debugfs_remove(apps);
156 debugfs_remove(system);
158 debugfs_remove(name);
163 struct param_data parameters[] = {
165 .name = "cpu_running",
166 .coef = &cpu_running_coef,
167 .system = cpu_system,
172 .coef = &cpu_idle_coef,
173 .system = cpu_idle_system,
177 .name = "flash_read",
183 .name = "flash_write",
191 parameters_cnt = sizeof(parameters) / sizeof(struct param_data)
198 /* ============================================================================
200 * ============================================================================
202 static struct dentry *energy_dir = NULL;
204 void exit_debugfs_energy(void)
208 debugfs_remove_recursive(energy_dir);
213 int init_debugfs_energy(void)
215 int i, ret = -ENOMEM;
216 struct dentry *swap_dir, *dentry;
218 swap_dir = get_swap_debugfs_dir();
219 if (swap_dir == NULL)
222 energy_dir = debugfs_create_dir("energy", swap_dir);
223 if (energy_dir == NULL)
226 for (i = 0; i < parameters_cnt; ++i) {
227 dentry = create_parameter(energy_dir, ¶meters[i]);
232 ret = init_lcd_debugfs(energy_dir);
239 exit_debugfs_energy();