summaryrefslogtreecommitdiffstats
path: root/include/linux/log2.h
diff options
context:
space:
mode:
authorPatrick Bellasi <patrick.bellasi@arm.com>2019-06-21 04:42:02 -0400
committerIngo Molnar <mingo@kernel.org>2019-06-24 13:23:44 -0400
commit69842cba9ace84849bb9b8edcdf2cefccd97901c (patch)
tree7d56d19500dc261558b8f4550119fc8950fac904 /include/linux/log2.h
parenta3df067974c52df936f548ed218120f623c4c560 (diff)
sched/uclamp: Add CPU's clamp buckets refcounting
Utilization clamping allows to clamp the CPU's utilization within a [util_min, util_max] range, depending on the set of RUNNABLE tasks on that CPU. Each task references two "clamp buckets" defining its minimum and maximum (util_{min,max}) utilization "clamp values". A CPU's clamp bucket is active if there is at least one RUNNABLE tasks enqueued on that CPU and refcounting that bucket. When a task is {en,de}queued {on,from} a rq, the set of active clamp buckets on that CPU can change. If the set of active clamp buckets changes for a CPU a new "aggregated" clamp value is computed for that CPU. This is because each clamp bucket enforces a different utilization clamp value. Clamp values are always MAX aggregated for both util_min and util_max. This ensures that no task can affect the performance of other co-scheduled tasks which are more boosted (i.e. with higher util_min clamp) or less capped (i.e. with higher util_max clamp). A task has: task_struct::uclamp[clamp_id]::bucket_id to track the "bucket index" of the CPU's clamp bucket it refcounts while enqueued, for each clamp index (clamp_id). A runqueue has: rq::uclamp[clamp_id]::bucket[bucket_id].tasks to track how many RUNNABLE tasks on that CPU refcount each clamp bucket (bucket_id) of a clamp index (clamp_id). It also has a: rq::uclamp[clamp_id]::bucket[bucket_id].value to track the clamp value of each clamp bucket (bucket_id) of a clamp index (clamp_id). The rq::uclamp::bucket[clamp_id][] array is scanned every time it's needed to find a new MAX aggregated clamp value for a clamp_id. This operation is required only when it's dequeued the last task of a clamp bucket tracking the current MAX aggregated clamp value. In this case, the CPU is either entering IDLE or going to schedule a less boosted or more clamped task. The expected number of different clamp values configured at build time is small enough to fit the full unordered array into a single cache line, for configurations of up to 7 buckets. Add to struct rq the basic data structures required to refcount the number of RUNNABLE tasks for each clamp bucket. Add also the max aggregation required to update the rq's clamp value at each enqueue/dequeue event. Use a simple linear mapping of clamp values into clamp buckets. Pre-compute and cache bucket_id to avoid integer divisions at enqueue/dequeue time. Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alessio Balsini <balsini@android.com> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com> Cc: Joel Fernandes <joelaf@google.com> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Morten Rasmussen <morten.rasmussen@arm.com> Cc: Paul Turner <pjt@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quentin Perret <quentin.perret@arm.com> Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com> Cc: Steve Muckle <smuckle@google.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Todd Kjos <tkjos@google.com> Cc: Vincent Guittot <vincent.guittot@linaro.org> Cc: Viresh Kumar <viresh.kumar@linaro.org> Link: https://lkml.kernel.org/r/20190621084217.8167-2-patrick.bellasi@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/log2.h')
-rw-r--r--include/linux/log2.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 1aec01365ed4..83a4a3ca3e8a 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -220,4 +220,38 @@ int __order_base_2(unsigned long n)
220 ilog2((n) - 1) + 1) : \ 220 ilog2((n) - 1) + 1) : \
221 __order_base_2(n) \ 221 __order_base_2(n) \
222) 222)
223
224static inline __attribute__((const))
225int __bits_per(unsigned long n)
226{
227 if (n < 2)
228 return 1;
229 if (is_power_of_2(n))
230 return order_base_2(n) + 1;
231 return order_base_2(n);
232}
233
234/**
235 * bits_per - calculate the number of bits required for the argument
236 * @n: parameter
237 *
238 * This is constant-capable and can be used for compile time
239 * initializations, e.g bitfields.
240 *
241 * The first few values calculated by this routine:
242 * bf(0) = 1
243 * bf(1) = 1
244 * bf(2) = 2
245 * bf(3) = 2
246 * bf(4) = 3
247 * ... and so on.
248 */
249#define bits_per(n) \
250( \
251 __builtin_constant_p(n) ? ( \
252 ((n) == 0 || (n) == 1) \
253 ? 1 : ilog2(n) + 1 \
254 ) : \
255 __bits_per(n) \
256)
223#endif /* _LINUX_LOG2_H */ 257#endif /* _LINUX_LOG2_H */