Re: [PATCH v10 6/9] sched/fair: Add sched group latency support

From: Peter Zijlstra
Date: Tue Feb 21 2023 - 10:02:14 EST


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.

Arguably we can simply store the raw nice value in write and print it
out again here.

> + 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);
> +}