rk_pm_tests: add cpu_usage.c, add open&&close clk
author陈亮 <cl@rock-chips.com>
Tue, 15 Apr 2014 03:37:52 +0000 (20:37 -0700)
committer陈亮 <cl@rock-chips.com>
Tue, 15 Apr 2014 03:37:52 +0000 (20:37 -0700)
arch/arm/mach-rockchip/rk_pm_tests/Makefile
arch/arm/mach-rockchip/rk_pm_tests/clk_rate.c
arch/arm/mach-rockchip/rk_pm_tests/clk_volt.c
arch/arm/mach-rockchip/rk_pm_tests/cpu_usage.c
arch/arm/mach-rockchip/rk_pm_tests/dvfs_table_scan.c
arch/arm/mach-rockchip/rk_pm_tests/rk_pm_tests.c [changed mode: 0755->0644]
arch/arm/mach-rockchip/rk_pm_tests/rk_pm_tests.h

index f83d41ce34d9493fbdf24f543b4a051628520565..0ebed8a61b387e73081f4d2654c66a3e4b759df2 100644 (file)
@@ -1,5 +1,5 @@
 obj-y += rk_pm_tests.o
 obj-y += clk_rate.o
 obj-y += clk_volt.o
-obj-y += clk_volt.o
-obj-y += dvfs_table_scan.o
\ No newline at end of file
+obj-y += cpu_usage.o
+obj-y += dvfs_table_scan.o
index ec9aed64d36e62d4e22e154ae59cfaca487d61c5..fb4cf44d66bbb5984288af7ff8a25d01b35f8cbb 100644 (file)
 #include "clk_rate.h"
 /***************************************************************************/
 #define FILE_GOV_MODE "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
-#define FILE_SETSPEED "/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
-#define FILE_CUR_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
 
+#if 0
 static int file_read(char *file_path, char *buf)
 {
        struct file *file = NULL;
        mm_segment_t old_fs;
        loff_t offset = 0;
 
-       PM_DBG("read %s\n", file_path);
+       PM_DBG("%s: read %s\n", __func__, file_path);
        file = filp_open(file_path, O_RDONLY, 0);
 
        if (IS_ERR(file)) {
-               PM_ERR("%s error open file  %s\n", __func__, file_path);
+               PM_ERR("%s: error open file  %s\n", __func__, file_path);
                return -1;
        }
 
@@ -57,6 +56,7 @@ static int file_read(char *file_path, char *buf)
        return 0;
 
 }
+#endif
 
 static int file_write(char *file_path, char *buf)
 {
@@ -64,11 +64,11 @@ static int file_write(char *file_path, char *buf)
        mm_segment_t old_fs;
        loff_t offset = 0;
 
-       PM_DBG("write %s %s size = %d\n", file_path, buf, strlen(buf));
+       PM_DBG("%s: write %s %s size = %d\n", __func__, file_path, buf, strlen(buf));
        file = filp_open(file_path, O_RDWR, 0);
 
        if (IS_ERR(file)) {
-               PM_ERR("%s error open file  %s\n", __func__, file_path);
+               PM_ERR("%s: error open file  %s\n", __func__, file_path);
                return -1;
        }
 
@@ -90,8 +90,8 @@ ssize_t clk_rate_show(struct kobject *kobj, struct kobj_attribute *attr,
                char *buf)
 {
        char *str = buf;
-       str += sprintf(str, "set        [clk_name]      [rate(Hz)]\n"
-                       "reset  [clk_name]      [rate(Hz) = 0]\n");
+       str += sprintf(str, "set [clk_name] [rate(Hz)]\n"
+                       "rawset [clk_name] [rate(Hz)]\n");
        if (str != buf)
                *(str - 1) = '\n';
        return (str - buf);
@@ -102,53 +102,50 @@ ssize_t clk_rate_store(struct kobject *kobj, struct kobj_attribute *attr,
                const char *buf, size_t n)
 {
        struct dvfs_node *clk_dvfs_node = NULL;
-       char cmd[20], clk_name[20], msg[50];
-       int rate;
-       printk("%s: %s\n", __func__, buf);
-       sscanf(buf, "%s %s %d", cmd, clk_name, &rate);
-
-       clk_dvfs_node = clk_get_dvfs_node(clk_name);
-       if (!clk_dvfs_node) {
-               PM_ERR("%s: clk(%s) get dvfs node error\n", __func__, clk_name);
-               return n;
-       }
+       struct clk *clk;
+       char cmd[20], clk_name[20];
+       unsigned long rate=0;
+       int ret=0;
+               
+       sscanf(buf, "%s %s %lu", cmd, clk_name, &rate);
+       
+       PM_DBG("%s: cmd(%s), clk_name(%s), rate(%lu)\n", __func__, cmd, clk_name, rate);
 
-       if (0 == strncmp(cmd, "set", strlen("set"))) {
-               PM_DBG("Get command set %s %dHz\n", clk_name, rate);
-               if (file_read(FILE_GOV_MODE, msg) != 0) {
-                       PM_ERR("read current governor error\n");
+       if (!strncmp(cmd, "set", strlen("set"))) {
+               clk_dvfs_node = clk_get_dvfs_node(clk_name);
+               if (!clk_dvfs_node) {
+                       PM_ERR("%s: clk(%s) get dvfs node error\n", __func__, clk_name);
                        return n;
-               } else {
-                       PM_DBG("current governor = %s\n", msg);
                }
-
-               strcpy(msg, "userspace");
-               if (file_write(FILE_GOV_MODE, msg) != 0) {
-                       PM_ERR("set current governor error\n");
-                       return n;
+               
+               if (!strncmp(clk_name, "clk_core", strlen("clk_core"))) {
+                       if (file_write(FILE_GOV_MODE, "userspace") != 0) {
+                               PM_ERR("%s: set current governor error\n", __func__);
+                               return n;
+                       }
                }
 
-               dvfs_clk_enable_limit(clk_dvfs_node, rate, rate);
-               dvfs_clk_set_rate(clk_dvfs_node, rate);
-
-       } else if (0 == strncmp(cmd, "reset", strlen("reset"))) {       
-               PM_DBG("Get command reset %s\n", clk_name);
-               if (file_read(FILE_GOV_MODE, msg) != 0) {
-                       PM_ERR("read current governor error\n");
+               ret = dvfs_clk_enable_limit(clk_dvfs_node, rate, rate);
+       } else {
+               clk = clk_get(NULL, clk_name);
+               if (IS_ERR_OR_NULL(clk)) {
+                       PM_ERR("%s: get clk(%s) err(%ld)\n", 
+                               __func__, clk_name, PTR_ERR(clk));
                        return n;
-               } else {
-                       PM_DBG("current governor = %s\n", msg);
                }
-
-               strcpy(msg, "interactive");
-               if (file_write(FILE_GOV_MODE, msg) != 0) {
-                       PM_ERR("set current governor error\n");
-                       return n;
+               
+               if (!strncmp(cmd, "rawset", strlen("rawset"))) {
+                       ret = clk_set_rate(clk, rate);
+               } else if (!strncmp(cmd, "open", strlen("open"))) {
+                       ret = clk_prepare_enable(clk);
+               } else if (!strncmp(cmd, "close", strlen("close"))) {   
+                       clk_disable_unprepare(clk);
                }
+       }
 
-               dvfs_clk_disable_limit(clk_dvfs_node);
+       if (ret) {
+               PM_ERR("%s: set rate err(%d)", __func__, ret);
        }
-       
        return n;
 }
 
index 631414519c379a8b9af82a215bb9afd7e73f7351..aaf10ce971523fcb29ee0af10f027fdf04280cf1 100644 (file)
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
 #include <linux/regulator/machine.h>
-//#include <plat/dma-pl330.h>
 #include <linux/mfd/wm831x/core.h>
 #include <linux/sysfs.h>
 #include <linux/err.h>
 #include <linux/rockchip/dvfs.h>
 
-//#include <mach/ddr.h>
-//#include <mach/dvfs.h>
-
 #include "rk_pm_tests.h"
 #include "clk_volt.h"
 /***************************************************************************/
@@ -44,50 +40,52 @@ ssize_t clk_volt_show(struct kobject *kobj, struct kobj_attribute *attr,
 ssize_t clk_volt_store(struct kobject *kobj, struct kobj_attribute *attr,
                const char *buf, size_t n)
 {
+       
+       struct regulator *regulator;
        char cmd[20], regulator_name[20];
        unsigned int volt;
-       int ret = 0;
-       int need_put_regulator=0;
-       struct regulator *regulator;
+       int need_put_regulator=0, ret=0;
 
-       printk("%s: %s\n", __func__, buf);
        sscanf(buf, "%s %s %u", cmd, regulator_name, &volt);
 
+       PM_DBG("%s: cmd(%s), regulator_name(%s), volt(%u)\n", 
+               __func__, cmd, regulator_name, volt);
+
        regulator = dvfs_get_regulator(regulator_name);
        if (IS_ERR_OR_NULL(regulator)) {
                regulator = regulator_get(NULL, regulator_name);
                if (IS_ERR(regulator)){
-                       PM_ERR("%s get dvfs_regulator %s error\n", __func__, regulator_name);
+                       PM_ERR("%s: get dvfs_regulator %s error\n", __func__, regulator_name);
                        return n;
                }
                need_put_regulator = 1;
        }       
 
-       if (0 == strncmp(cmd, "set", strlen("set"))){
+       if (!strncmp(cmd, "set", strlen("set"))){
                if (volt & SET_SUSPEND_VOLT_FLAG){
                        volt &= ~SET_SUSPEND_VOLT_FLAG;
                        //ret = regulator_set_suspend_voltage(regulator, volt); 
                        if (!ret)
-                               printk("set %s suspend volt to %uuV ok\n", regulator_name, volt);
+                               PM_DBG("%s: set %s suspend volt to %u uV ok\n", __func__, regulator_name, volt);
                        else
-                               printk("regulator_set_suspend_voltage err:%d\n", ret);
+                               PM_DBG("%s: regulator_set_suspend_voltage err(%d)\n", __func__, ret);
                }else{
                        ret = regulator_set_voltage(regulator, volt, volt); 
                        if (!ret)
-                               printk("set %s volt to %uuV ok\n", regulator_name, regulator_get_voltage(regulator));
+                               PM_DBG("%s: set %s volt to %u uV ok\n", __func__, regulator_name, regulator_get_voltage(regulator));
                        else
-                               printk("regulator_set_voltage err:%d\n", ret);
+                               PM_DBG("%s: regulator_set_voltage err(%d)\n", __func__, ret);
                }
                
        }
-       if (0 == strncmp(cmd, "get", strlen("get"))){
-               printk("%s:%duV\n", regulator_name, regulator_get_voltage(regulator));
+       if (!strncmp(cmd, "get", strlen("get"))){
+               printk("%s: %s current is %d uV\n", 
+                       __func__, regulator_name, regulator_get_voltage(regulator));
        }
 
        if (need_put_regulator)
                regulator_put(regulator);
 
-//     if (0 == strncmp(cmd, "enable", strlen("enable"))) {
        return n;
 }
 
index 3089e3de3b12853ba52de031fac0d81a1641d988..91e445ab3d2a94bb20d54fce55f4500fc8f320e2 100644 (file)
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
 #include <linux/regulator/machine.h>
-#include <plat/dma-pl330.h>
 #include <linux/mfd/wm831x/core.h>
 #include <linux/sysfs.h>
 #include <linux/err.h>
-#include <mach/cru.h>
-#include <mach/dvfs.h>
-#include <mach/sram.h>
 #include <linux/random.h>
 
 #include <linux/fs.h>
@@ -85,7 +81,7 @@ ssize_t cpu_usage_store(struct kobject *kobj, struct kobj_attribute *attr,
 
        sscanf(buf, "%s %d", cmd, &usage);
 
-       if((strncmp(cmd, "start", strlen("start")) == 0)) {
+       if((!strncmp(cmd, "start", strlen("start")))) {
                PM_DBG("get cmd start\n");
                cpu_usage_run = 1;
                
@@ -107,7 +103,7 @@ ssize_t cpu_usage_store(struct kobject *kobj, struct kobj_attribute *attr,
                add_timer(&arm_mode_timer);
 #endif
        
-       } else if (strncmp(cmd, "stop", strlen("stop")) == 0) {
+       } else if (!strncmp(cmd, "stop", strlen("stop"))) {
                PM_DBG("get cmd stop\n");
                cpu_usage_run = 0;
        }
index 2f68ee56881da8aa3acdabf379fc0bb028b3e058..b29243ea85eb60a50ba7055c70c07c782ce72ef2 100644 (file)
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
 #include <linux/regulator/machine.h>
-//#include <plat/dma-pl330.h>
 #include <linux/mfd/wm831x/core.h>
 #include <linux/sysfs.h>
 #include <linux/err.h>
-//#include <mach/ddr.h>
-//#include <mach/dvfs.h>
 #include <linux/watchdog.h>
 
-
 #include <linux/fs.h>
 #include <asm/unistd.h>
 #include <asm/uaccess.h>
 #include "rk_pm_tests.h"
 #include "dvfs_table_scan.h"
 /***************************************************************************/
-struct workqueue_struct        *workqueue_dvfs_table_scan;
-struct work_struct     work_dvfs_table_scan;
-struct timer_list dvfs_table_scan_timer;
-#define DVFS_TABLE_T_MSEC      1000
-struct file *file = NULL;
-mm_segment_t old_fs;
-loff_t offset = 0;
-static int dvfs_table_scan_run = 0;
+void rk29_wdt_start(void);
+void rk29_wdt_stop(void);
+void rk29_wdt_keepalive(void);
+int rk29_wdt_set_heartbeat(int timeout);
+
+#define ALIVE_INTERVAL                 2       //s
+#define WATCHDOG_TIMEOUT               (10*ALIVE_INTERVAL)
+#define RESERVE_TIME_FOR_TIMEOUT       600000  //ms
 
 ssize_t dvfs_table_scan_show(struct kobject *kobj, struct kobj_attribute *attr,
                char *buf)
 {
        char *str = buf;
-       str += sprintf(str, "start: \tstart scan dvfs table, send alive every 1s\n"
+       str += sprintf(str, "start: \tstart scan dvfs table, send alive every 2s\n"
                        "stop: \tstop send alive signal\n");
        if (str != buf)
                *(str - 1) = '\n';
        return (str - buf);
 
 }
-void rk29_wdt_start(void);
-void rk29_wdt_stop(void);
-void rk29_wdt_keepalive(void);
-int rk29_wdt_set_heartbeat(int timeout);
-
-#define ALIVE_INTERVAL                 2       //s
-#define WATCHDOG_TIMEOUT               (10*ALIVE_INTERVAL)
-#define RESERVE_TIME_FOR_TIMEOUT       600000  //ms
 
 ssize_t dvfs_table_scan_store(struct kobject *kobj, struct kobj_attribute *attr,
                const char *buf, size_t n)
 {
        char cmd[20];
        int cur_test_need_time=0; //ms
-       static int cur_test_timeout_cnt = 0, start_flag = 0;
+       static int cur_test_timeout_cnt = 0;
 
        sscanf(buf, "%s %d", cmd, &cur_test_need_time);
-
-       printk("%s: get command <%s>\n", __func__, cmd);
-       if (0 == strncmp(cmd, "start", strlen("start"))) {
+       
+       PM_DBG("%s: cmd(%s), cur_test_need_time(%d)\n", __func__, cmd, cur_test_need_time);
+               
+       if (!strncmp(cmd, "start", strlen("start"))) {
                if (cur_test_need_time == 0)
                        return n;
                cur_test_timeout_cnt = (cur_test_need_time + RESERVE_TIME_FOR_TIMEOUT)/1000/ALIVE_INTERVAL;
                rk29_wdt_start();
                rk29_wdt_set_heartbeat(WATCHDOG_TIMEOUT);
-               start_flag = 1;
-       } else if (0 == strncmp(cmd, "alive", strlen("alive"))) {
-               if(start_flag == 0)
-                       return n;
+       } else if (!strncmp(cmd, "alive", strlen("alive"))) {
                printk("cur_test_timeout_cnt:%d\n", cur_test_timeout_cnt);
                if (cur_test_timeout_cnt-- > 0)         
                        rk29_wdt_keepalive();
 
-       } else if (0 == strncmp(cmd, "stop", strlen("stop"))) {
-               if(start_flag == 0)
-                       return n;
+       } else if (!strncmp(cmd, "stop", strlen("stop"))) {
                cur_test_timeout_cnt = -1;
                rk29_wdt_stop();
-               start_flag = 0;
        }
 
        return n;
old mode 100755 (executable)
new mode 100644 (file)
index 742a3f5..5e033f2
@@ -40,14 +40,11 @@ REVISION 0.01
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
 #include <linux/regulator/machine.h>
-//#include <plat/dma-pl330.h>
 #include <linux/mfd/wm831x/core.h>
 #include <linux/sysfs.h>
 #include <linux/err.h>
-//#include <mach/ddr.h>
 
 #include "rk_pm_tests.h"
-
 #include "clk_rate.h"
 #include "clk_volt.h"
 #include "cpu_usage.h"
@@ -67,6 +64,8 @@ static struct pm_attribute pm_attrs[] = {
        __ATTR(clk_rate, S_IRUGO | S_IWUSR | S_IWUGO, clk_rate_show, clk_rate_store),
        __ATTR(clk_volt, S_IRUGO | S_IWUSR | S_IWUGO, clk_volt_show, clk_volt_store),
        __ATTR(dvfs_table_scan, S_IRUGO | S_IWUSR | S_IWUGO, dvfs_table_scan_show, dvfs_table_scan_store),
+       __ATTR(cpu_usage, S_IRUGO | S_IWUSR, cpu_usage_show, cpu_usage_store),
+
 /*
        __ATTR(maxfreq_volt, S_IRUGO | S_IWUSR, maxfreq_show, maxfreq_store),
        __ATTR(freq_limit, S_IRUGO | S_IWUSR, freq_limit_show, freq_limit_store),
@@ -82,7 +81,6 @@ static void __exit rk_pm_tests_exit(void)
        kobject_put(rk_pm_tests_kobj);
 }
 
-
 struct kobject *get_rk_pm_tests_kobj(void)
 {
 
index 2d4abb517b39792d6fdd68a054ce4dbd23455cdb..d0d7a8d2aa65ce630dcd8d40a241720dc9cd796a 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef _RK_PM_TESTS_H_
 #define _RK_PM_TESTS_H_
-#define PM_DBG(fmt, args...) printk(KERN_INFO "PM_TESTS_DBG:\t"fmt, ##args)
+#define PM_DBG(fmt, args...) printk(KERN_DEBUG "PM_TESTS_DBG:\t"fmt, ##args)
 #define PM_ERR(fmt, args...) printk(KERN_ERR "PM_TESTS_ERR:\t"fmt, ##args)
 #endif