#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 */
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);
}
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);
}
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);
}
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);
}
#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)
}
}
-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)
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);
+}
+
+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;
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);