On Tue, 21 Feb 2023 at 16:01, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote: > > On Fri, Jan 13, 2023 at 03:12:31PM +0100, Vincent Guittot wrote: > > > +static s64 cpu_latency_nice_read_s64(struct cgroup_subsys_state *css, > > + struct cftype *cft) > > +{ > > + int prio, delta, last_delta = INT_MAX; > > + s64 weight; > > + > > + weight = css_tg(css)->latency_offset * NICE_LATENCY_WEIGHT_MAX; > > + weight = div_s64(weight, get_sleep_latency(false)); > > + > > + /* Find the closest nice value to the current weight */ > > This comment isn't entirely accurate, since we only have the nice_write > interface below, this will be an exact match. The thing with weight is > that we first had the raw weight value interface and then the nice > interface had to map random values back to a 'nice' value. Yes, there was a long discussion about the interface and without any simple raw value to share, we decided to only use latency_nice until we found a generic metric > > Arguably we can simply store the raw nice value in write and print it > out again here. Probably, I just wanted to prevent the latency.nice being the main value saved in cgroup . But I suppose it could be ok to save it directly > > > + for (prio = 0; prio < ARRAY_SIZE(sched_latency_to_weight); prio++) { > > + delta = abs(sched_latency_to_weight[prio] - weight); > > + if (delta >= last_delta) > > + break; > > + last_delta = delta; > > + } > > + > > + return LATENCY_TO_NICE(prio-1); > > +} > > + > > +static int cpu_latency_nice_write_s64(struct cgroup_subsys_state *css, > > + struct cftype *cft, s64 nice) > > +{ > > + s64 latency_offset; > > + long weight; > > + int idx; > > + > > + if (nice < MIN_LATENCY_NICE || nice > MAX_LATENCY_NICE) > > + return -ERANGE; > > + > > + idx = NICE_TO_LATENCY(nice); > > + idx = array_index_nospec(idx, LATENCY_NICE_WIDTH); > > + weight = sched_latency_to_weight[idx]; > > + > > + latency_offset = weight * get_sleep_latency(false); > > + latency_offset = div_s64(latency_offset, NICE_LATENCY_WEIGHT_MAX); > > + > > + return sched_group_set_latency(css_tg(css), latency_offset); > > +}