lkml.org 
[lkml]   [2018]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH v4 12/12] OPTIONAL: cpufreq: dt: Register an Energy Model
On Friday 06 Jul 2018 at 12:10:02 (+0200), Vincent Guittot wrote:
> On Thu, 28 Jun 2018 at 13:41, Quentin Perret <quentin.perret@arm.com> wrote:
> > +static int of_est_power(unsigned long *mW, unsigned long *KHz, int cpu)
> > +{
> > + unsigned long mV, Hz, MHz;
> > + struct device *cpu_dev;
> > + struct dev_pm_opp *opp;
> > + struct device_node *np;
> > + u32 cap;
> > + u64 tmp;
> > +
> > + cpu_dev = get_cpu_device(cpu);
> > + if (!cpu_dev)
> > + return -ENODEV;
> > +
> > + np = of_node_get(cpu_dev->of_node);
> > + if (!np)
> > + return -EINVAL;
> > +
> > + if (of_property_read_u32(np, "dynamic-power-coefficient", &cap))
> > + return -EINVAL;
> > +
> > + Hz = *KHz * 1000;
> > + opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);
> > + if (IS_ERR(opp))
> > + return -EINVAL;
> > +
> > + mV = dev_pm_opp_get_voltage(opp) / 1000;
> > + dev_pm_opp_put(opp);
> > +
> > + MHz = Hz / 1000000;
> > + tmp = (u64)cap * mV * mV * MHz;
> > + do_div(tmp, 1000000000);
>
> Could you explain the formula above ? and especially the 1000000000 it
> seems related to the use of mV and mW instead of uV and uW ...

That's correct, this is just a matter of units. I simply tried to
reproduce here what is currently done for IPA:

https://elixir.bootlin.com/linux/latest/source/drivers/thermal/cpu_cooling.c#L252

>
> Can't you just optimize that into
> tmp = (u64)cap * mV * mV * Hz;
> do_div(tmp, 1000);

I don't think that'll work. If you use Hz instead of MHz you'll need to
divide tmp by 1000000000000000 to get milli-watts, as specified by the
EM framework.

FYI, I don't consider this patch to be ready to be merged. I kept it
self-contained and simple for the example but I actually think that this
of_est_power function should probably be factored-out somewhere else.
scpi-cpufreq could use it as well. Anyway, I guess we can discuss that
later once the APIs of the EM framework are agreed :-)

Thanks,
Quentin

\
 
 \ /
  Last update: 2018-07-06 12:19    [W:0.105 / U:1.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site