Re: [PATCH 2/2] sched/uclamp: Protect uclamp fast path code with static key
From: Peter Zijlstra
Date: Fri Jun 19 2020 - 13:45:30 EST
On Thu, Jun 18, 2020 at 08:55:25PM +0100, Qais Yousef wrote:
> +/*
> + * This static key is used to reduce the uclamp overhead in the fast path. It
> + * only disables the call to uclamp_rq_{inc, dec}() in enqueue/dequeue_task().
> + *
> + * This allows users to continue to enable uclamp in their kernel config with
> + * minimum uclamp overhead in the fast path.
> + *
> + * As soon as userspace modifies any of the uclamp knobs, the static key is
> + * disabled, since we have an actual users that make use of uclamp
> + * functionality.
> + *
> + * The knobs that would disable this static key are:
> + *
> + * * A task modifying its uclamp value with sched_setattr().
> + * * An admin modifying the sysctl_sched_uclamp_{min, max} via procfs.
> + * * An admin modifying the cgroup cpu.uclamp.{min, max}
> + */
> +DEFINE_STATIC_KEY_TRUE(sched_uclamp_unused);
Maybe call the thing: 'sched_uclamp_users', instead?
> + if (static_branch_unlikely(&sched_uclamp_unused))
> + static_branch_disable(&sched_uclamp_unused);
> + if (static_branch_unlikely(&sched_uclamp_unused))
> + static_branch_disable(&sched_uclamp_unused);
> + if (static_branch_unlikely(&sched_uclamp_unused))
> + static_branch_disable(&sched_uclamp_unused);
That's an anti-pattern... just static_branch_disable(), or _enable()
with a 'better' name is sufficient.