[IMPROVE] add calculation energy for LCD
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 15 Nov 2013 17:18:52 +0000 (21:18 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 18 Nov 2013 10:30:40 +0000 (14:30 +0400)
Change-Id: Iba5a1f4ed707e42a007e6b0cda706d8239ed2379
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
energy/lcd/lcd_base.c
energy/lcd/lcd_base.h
energy/lcd/lcd_debugfs.c

index c3cd702..cd75b20 100644 (file)
@@ -191,8 +191,6 @@ static void add_lcd(struct lcd_ops *ops)
 static void del_lcd(struct lcd_ops *ops)
 {
        list_del(&ops->list);
-
-       get_energy_lcd(ops);
        destroy_lcd_priv(ops->priv);
 }
 
@@ -218,28 +216,26 @@ static int lcd_is_register(struct lcd_ops *ops)
        return 0;
 }
 
-u64 get_energy_lcd(struct lcd_ops *ops)
+size_t get_lcd_size_array(struct lcd_ops *ops)
 {
        struct lcd_priv_data *lcd = get_lcd_priv(ops);
-       const size_t brt_cnt_1 = lcd->tms_brt_cnt - 1;
-       u64 i_max, j_min, t, e = 0;
-       int i, j;
+
+       return lcd->tms_brt_cnt;
+}
+
+void get_lcd_array_time(struct lcd_ops *ops, u64 *array_time)
+{
+       struct lcd_priv_data *lcd = get_lcd_priv(ops);
+       int i;
 
        spin_lock(&lcd->lock_tms);
        for (i = 0; i < lcd->tms_brt_cnt; ++i) {
-               t = tm_stat_running(&lcd->tms_brt[i]);
+               array_time[i] = tm_stat_running(&lcd->tms_brt[i]);
                if (i == lcd->brt_old)
-                       t += get_ntime() - tm_stat_timestamp(&lcd->tms_brt[i]);
-
-               /* e = (i * max + (k - i) * min) * t / k */
-               j = brt_cnt_1 - i;
-               i_max = div_u64(i * lcd->max_num * t, lcd->max_denom);
-               j_min = div_u64(j * lcd->min_num * t, lcd->min_denom);
-               e += div_u64(i_max + j_min, brt_cnt_1);
+                       array_time[i] += get_ntime() -
+                                        tm_stat_timestamp(&lcd->tms_brt[i]);
        }
        spin_unlock(&lcd->lock_tms);
-
-       return e;
 }
 
 int register_lcd(struct lcd_ops *ops)
index 6d44742..1626e1f 100644 (file)
@@ -65,7 +65,8 @@ struct lcd_ops {
        void *priv;
 };
 
-u64 get_energy_lcd(struct lcd_ops *ops);
+size_t get_lcd_size_array(struct lcd_ops *ops);
+void get_lcd_array_time(struct lcd_ops *ops, u64 *array_time);
 
 int register_lcd(struct lcd_ops *ops);
 void unregister_lcd(struct lcd_ops *ops);
index 6a8b9e9..5e436ba 100644 (file)
 
 #include <linux/debugfs.h>
 #include <linux/export.h>
+#include <linux/slab.h>
 #include <energy/lcd/lcd_base.h>
 #include <energy/rational_debugfs.h>
 
 
 static int get_system(void *data, u64 *val)
 {
-       /* TODO: implement */
+       struct lcd_ops *ops = (struct lcd_ops *)data;
+       const size_t size = get_lcd_size_array(ops);
+       const size_t size_1 = size - 1;
+       u64 i_max, j_min, t, e = 0;
+       u64 *array_time;
+       int i, j;
+
+       array_time = kmalloc(sizeof(*array_time) * size, GFP_KERNEL);
+       if (array_time == NULL)
+               return -ENOMEM;
+
+       get_lcd_array_time(ops, array_time);
+
+       for (i = 0; i < size; ++i) {
+               t = array_time[i];
+
+               /* e = (i * max + (k - i) * min) * t / k */
+               j = size_1 - i;
+               i_max = div_u64(i * ops->max_coef.num * t,
+                               ops->max_coef.denom);
+               j_min = div_u64(j * ops->min_coef.num * t,
+                               ops->min_coef.denom);
+               e += div_u64(i_max + j_min, size_1);
+       }
+
+       kfree(array_time);
+
+       *val = e;
 
        return 0;
 }