PM / devfreq: add to show current load of device
authorJianqun Xu <jay.xu@rock-chips.com>
Wed, 17 Aug 2016 08:43:57 +0000 (16:43 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 29 Aug 2016 06:58:21 +0000 (14:58 +0800)
Calculate current load with busytime / totaltime from status,
also show the current frequency.

Change-Id: Ic310035db9c5478aa3d0b1e526b47c451fe09d23
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
drivers/devfreq/devfreq.c

index b8fdf7a6608c25f1bf0d0ff5a4979256d1c72238..d73f1fec3fd70daa3ac688dba3f5af880d6aa9bb 100644 (file)
@@ -1123,6 +1123,40 @@ static ssize_t trans_stat_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(trans_stat);
 
+static ssize_t load_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       int err;
+       struct devfreq *devfreq = to_devfreq(dev);
+       struct devfreq_dev_status stat = devfreq->last_status;
+       unsigned long freq;
+       ssize_t len;
+
+       err = devfreq_update_stats(devfreq);
+       if (err)
+               return err;
+
+       if (stat.total_time < stat.busy_time) {
+               err = devfreq_update_stats(devfreq);
+               if (err)
+                       return err;
+       };
+
+       if (!stat.total_time)
+               return 0;
+
+       len = sprintf(buf, "%lu", stat.busy_time * 100 / stat.total_time);
+
+       if (devfreq->profile->get_cur_freq &&
+               !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq))
+                       len += sprintf(buf + len, "@%luHz\n", freq);
+       else
+               len += sprintf(buf + len, "@%luHz\n", devfreq->previous_freq);
+
+       return len;
+}
+static DEVICE_ATTR_RO(load);
+
 static struct attribute *devfreq_attrs[] = {
        &dev_attr_governor.attr,
        &dev_attr_available_governors.attr,
@@ -1133,6 +1167,7 @@ static struct attribute *devfreq_attrs[] = {
        &dev_attr_min_freq.attr,
        &dev_attr_max_freq.attr,
        &dev_attr_trans_stat.attr,
+       &dev_attr_load.attr,
        NULL,
 };
 ATTRIBUTE_GROUPS(devfreq);