[IMPROVE] energy: add current parameters in debugfs
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 27 Sep 2013 13:23:01 +0000 (17:23 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 27 Sep 2013 13:23:01 +0000 (17:23 +0400)
except application parameters

Change-Id: I01c17d7d589cd679100b62d72a3e9110a3f2489b
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
energy/debugfs_energy.c
energy/energy.c
energy/energy.h

index 1a1e33e..4ca5705 100644 (file)
@@ -26,7 +26,9 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/debugfs.h>
+#include <linux/math64.h>
 #include <driver/swap_debugfs.h>
+#include "energy.h"
 
 
 /* CPU running */
@@ -35,14 +37,16 @@ static u64 cpu_denominator = 1;
 
 static u64 cpu_system(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 time = get_parameter_energy(PE_TIME_SYSTEM);
+
+       return div_u64(time * cpu_numerator, cpu_denominator);
 }
 
 static u64 cpu_apps(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 time = get_parameter_energy(PE_TIME_APPS);
+
+       return div_u64(time * cpu_numerator, cpu_denominator);
 }
 
 
@@ -52,8 +56,9 @@ static u64 cpu_idle_denominator = 1;
 
 static u64 cpu_idle_system(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 time = get_parameter_energy(PE_TIME_IDLE);
+
+       return div_u64(time * cpu_idle_numerator, cpu_idle_denominator);
 }
 
 
@@ -63,14 +68,16 @@ static u64 fr_denominator = 1;
 
 static u64 fr_system(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 byte = get_parameter_energy(PE_READ_SYSTEM);
+
+       return div_u64(byte * fr_numerator, fr_denominator);
 }
 
 static u64 fr_apps(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 byte = get_parameter_energy(PE_READ_APPS);
+
+       return div_u64(byte * fr_numerator, fr_denominator);
 }
 
 
@@ -80,14 +87,16 @@ static u64 fw_denominator = 1;
 
 static u64 fw_system(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 byte = get_parameter_energy(PE_WRITE_SYSTEM);
+
+       return div_u64(byte * fw_numerator, fw_denominator);
 }
 
 static u64 fw_apps(void)
 {
-       /* TODO: implement */
-       return 0;
+       u64 byte = get_parameter_energy(PE_WRITE_APPS);
+
+       return div_u64(byte * fw_numerator, fw_denominator);
 }
 
 
index 2bed6fd..e429f61 100644 (file)
@@ -35,6 +35,7 @@
 #include <us_manager/sspt/sspt_proc.h>
 #include <us_manager/sspt/sspt_feature.h>
 #include <linux/atomic.h>
+#include "energy.h"
 
 
 static u64 get_ntime(void)
@@ -67,9 +68,15 @@ static void cpus_time_init(struct cpus_time *ct, u64 time)
        }
 }
 
-static u64 cpus_time_get_running(struct cpus_time *ct, int cpu)
+static u64 cpus_time_get_running_all(struct cpus_time *ct)
 {
-       return ct->time_running[cpu];
+       u64 time = 0;
+       int cpu;
+
+       for (cpu = 0; cpu < NR_CPUS; ++cpu)
+               time += ct->time_running[cpu];
+
+       return time;
 }
 
 static void cpus_time_save_entry(struct cpus_time *ct, int cpu, u64 time)
@@ -100,6 +107,15 @@ static void init_data_energy(void)
        cpus_time_init(&ct_system, time);
 }
 
+static void uninit_data_energy(void)
+{
+       atomic64_set(&sys_read_byte, 0);
+       atomic64_set(&sys_write_byte, 0);
+
+       cpus_time_init(&ct_idle, 0);
+       cpus_time_init(&ct_system, 0);
+}
+
 
 
 
@@ -370,6 +386,57 @@ static struct kretprobe sys_write_krp = {
 
 
 
+static u64 current_time_apps(void)
+{
+       /* TODO: implement */
+       return 0;
+}
+
+static u64 current_read_apps(void)
+{
+       /* TODO: implement */
+       return 0;
+}
+
+static u64 current_write_apps(void)
+{
+       /* TODO: implement */
+       return 0;
+}
+
+u64 get_parameter_energy(enum parameter_energy pe)
+{
+       u64 val = 0;
+
+       switch (pe) {
+       case PE_TIME_IDLE:
+               val = cpus_time_get_running_all(&ct_idle);
+               break;
+       case PE_TIME_SYSTEM:
+               val = cpus_time_get_running_all(&ct_system);
+               break;
+       case PE_TIME_APPS:
+               val = current_time_apps();
+               break;
+       case PE_READ_SYSTEM:
+               val = atomic64_read(&sys_read_byte);
+               break;
+       case PE_WRITE_SYSTEM:
+               val = atomic64_read(&sys_write_byte);
+               break;
+       case PE_READ_APPS:
+               val = current_read_apps();
+               break;
+       case PE_WRITE_APPS:
+               val = current_write_apps();
+               break;
+       default:
+               break;
+       }
+
+       return val;
+}
+
 int set_energy(void)
 {
        int ret = 0;
@@ -411,6 +478,8 @@ void unset_energy(void)
        dbi_unregister_kretprobe(&switch_to_krp);
        dbi_unregister_kretprobe(&sys_write_krp);
        dbi_unregister_kretprobe(&sys_read_krp);
+
+       uninit_data_energy();
 }
 EXPORT_SYMBOL_GPL(unset_energy);
 
index 6a3224d..b77efc8 100644 (file)
  */
 
 
+#include <linux/types.h>
+
+
+enum parameter_energy {
+       PE_TIME_IDLE,
+       PE_TIME_SYSTEM,
+       PE_TIME_APPS,
+       PE_READ_SYSTEM,
+       PE_WRITE_SYSTEM,
+       PE_READ_APPS,
+       PE_WRITE_APPS
+};
+
+
 int energy_init(void);
 void energy_uninit(void);
 
 int set_energy(void);
 void unset_energy(void);
 
+u64 get_parameter_energy(enum parameter_energy pe);
+
 #endif /* _ENERGY_H */