From: Jianqun Xu Date: Wed, 17 Aug 2016 08:43:57 +0000 (+0800) Subject: PM / devfreq: add to show current load of device X-Git-Tag: firefly_0821_release~1651 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0f75dc420951837e983a98a591055f58d4ff1f2a;p=firefly-linux-kernel-4.4.55.git PM / devfreq: add to show current load of device Calculate current load with busytime / totaltime from status, also show the current frequency. Change-Id: Ic310035db9c5478aa3d0b1e526b47c451fe09d23 Signed-off-by: Jianqun Xu --- diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b8fdf7a6608c..d73f1fec3fd7 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -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);