On Wed, Jan 12, 2022 at 10:32 PM Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx> wrote: > > On Wed, 2022-01-12 at 20:25 +0100, Rafael J. Wysocki wrote: > > On Thu, Jan 6, 2022 at 3:49 AM Ricardo Neri > > <ricardo.neri-calderon@xxxxxxxxxxxxxxx> wrote: > > > From: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx> > > > > > > Add a new netlink event to notify change in CPU capabilities in > > > terms of > > > performance and efficiency. > > > > > > Firmware may change CPU capabilities as a result of thermal events > > > in the > > > system or to account for changes in the TDP (thermal design power) > > > level. > > > > > > This notification type will allow user space to avoid running > > > workloads > > > on certain CPUs or proactively adjust power limits to avoid future > > > events. > > > > > > The netlink message consists of a nested attribute > > > (THERMAL_GENL_ATTR_CPU_CAPABILITY) with three attributes: > > > > > > * THERMAL_GENL_ATTR_CPU_CAPABILITY_ID (type u32): > > > -- logical CPU number > > > * THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE (type u32): > > > -- Scaled performance from 0-1023 > > > * THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY (type u32): > > > -- Scaled efficiency from 0-1023 > > > > > > Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx> > > > Cc: Aubrey Li <aubrey.li@xxxxxxxxxxxxxxx> > > > Cc: Lukasz Luba <lukasz.luba@xxxxxxx> > > > Cc: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx> > > > Cc: "Ravi V. Shankar" <ravi.v.shankar@xxxxxxxxx> > > > Reviewed-by: Len Brown <len.brown@xxxxxxxxx> > > > Signed-off-by: Srinivas Pandruvada < > > > srinivas.pandruvada@xxxxxxxxxxxxxxx> > > > > Of course, I need to know if Daniel and Lukasz agree with this patch. > > > I pinged Daniel offline. I accommodated comments from Lukasz. > > > > --- > > > > > [...] > > > > +static int thermal_genl_event_cpu_capability_change(struct param > > > *p) > > > +{ > > > + struct cpu_capability *cpu_cap = p->cpu_capabilities; > > > + struct sk_buff *msg = p->msg; > > > + struct nlattr *start_cap; > > > + int i, ret; > > > + > > > + start_cap = nla_nest_start(msg, > > > THERMAL_GENL_ATTR_CPU_CAPABILITY); > > > + if (!start_cap) > > > + return -EMSGSIZE; > > > + > > > + for (i = 0; i < p->cpu_capabilities_count; ++i) { > > > + if (nla_put_u32(msg, > > > THERMAL_GENL_ATTR_CPU_CAPABILITY_ID, > > > + cpu_cap->cpu)) { > > > + ret = -EMSGSIZE; > > > + goto out_cancel_nest; > > > + } > > > + if (nla_put_u32(msg, > > > THERMAL_GENL_ATTR_CPU_CAPABILITY_PERFORMANCE, > > > + cpu_cap->performance)) { > > > + ret = -EMSGSIZE; > > > + goto out_cancel_nest; > > > + } > > > + if (nla_put_u32(msg, > > > THERMAL_GENL_ATTR_CPU_CAPABILITY_EFFICIENCY, > > > + cpu_cap->efficiency)) { > > > + ret = -EMSGSIZE; > > > + goto out_cancel_nest; > > > + } > > > + ++cpu_cap; > > > + } > > > + > > > + nla_nest_end(msg, start_cap); > > > + > > > + return 0; > > > +out_cancel_nest: > > > + nla_nest_cancel(msg, start_cap); > > > + > > > + return ret; > > > > It looks like ret is never different from -EMSGSIZE here, so I'd just > > return that error and drop the ret variable. > > > ret is initialized for every case when it will be returned. Right, but it is redundant. > But agree > that we can just return -EMSGSIZE as there is no other return value > here. > > > > +} > > > + > > > > > [...] > > > > +struct cpu_capability { > > > > I'm wondering if the struct name is not too generic as the purpose it > > is used for is rather narrow and specific. > > > This was named something else before. What about cpu_energy_perf_cap? Because it is only used in the thermal_genl_cpu_capability_event() interface, it would be good to make the name reflect that IMO. Something like thermal_genl_cpu_caps would work in this regard.