Re: [PATCH V2 1/3] Calculate Thermal Pressure

Peter Zijlstra
2019-04-24T16:45:34Z

On Tue, Apr 16, 2019 at 03:38:39PM -0400, Thara Gopinath wrote:
> +static void __init init_thermal_pressure(void)
> +{
> + struct thermal_pressure *cpu_thermal;
> + unsigned long scale;
> + int cpu;
> +
> + pr_debug("Init thermal pressure\n");
> + for_each_possible_cpu(cpu) {
> + cpu_thermal = per_cpu(thermal_pressure_cpu, cpu);
> + if (cpu_thermal)
> + continue;
> +
> + cpu_thermal = kzalloc(sizeof(*cpu_thermal), GFP_KERNEL);
> + if (!cpu_thermal)
> + continue;

So if you unconditinoally allocate this memory, why not just have:

DEFINE_PER_CPU(struct thermal_pressure, cpu_thermal_pressure); ?

Or stick it in struct rq or whatever.

> + scale = SCHED_CAPACITY_SCALE;
> + cpu_thermal->scale = scale;
> + cpu_thermal->old_scale = scale;
> + cpu_thermal->raw_scale = scale;
> + cpu_thermal->age_stamp = sched_clock_cpu(cpu);
> + cpu_thermal->last_update = sched_clock_cpu(cpu);
> + cpu_thermal->cpu = cpu;
> + spin_lock_init(&cpu_thermal->lock);
> + timer_setup(&cpu_thermal->timer, thermal_pressure_timeout,
> + TIMER_DEFERRABLE);
> + per_cpu(thermal_pressure_cpu, cpu) = cpu_thermal;
> + pr_debug("cpu %d thermal scale = %ld\n", cpu, cpu_thermal->scale);
> + }
> +
> + for_each_possible_cpu(cpu) {

You just done that, what gives?

> + cpu_thermal = per_cpu(thermal_pressure_cpu, cpu);
> + if (!cpu_thermal)
> + continue;
> + cpu_thermal->timer.expires = jiffies +
> + usecs_to_jiffies(TICK_USEC);

That's like a very copmlicated way of writing: '1', right?

> + add_timer(&cpu_thermal->timer);
> + }
> +}

So really what you want is a hook into the tick?