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 <jay.xu@rock-chips.com>
This commit is contained in:
Jianqun Xu 2016-08-17 16:43:57 +08:00 committed by Tao Huang
parent d85e70122d
commit 6e488e859f

View File

@ -1762,6 +1762,40 @@ static ssize_t timer_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RW(timer);
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_name.attr,
&dev_attr_governor.attr,
@ -1774,6 +1808,7 @@ static struct attribute *devfreq_attrs[] = {
&dev_attr_max_freq.attr,
&dev_attr_trans_stat.attr,
&dev_attr_timer.attr,
&dev_attr_load.attr,
NULL,
};
ATTRIBUTE_GROUPS(devfreq);