Skip to content

Commit

Permalink
workqueue: Schedule workers on CPU0 or 0-3 by default
Browse files Browse the repository at this point in the history
For regular bound workers that don't request to be queued onto a specific
CPU, just use CPU0 to save power. Additionally, adjust the CPU affinity of
unbound workqueues to force their workers onto the power cluster (CPUs 0-3)
to further improve power consumption.

Signed-off-by: Sultanxda <sultanxda@gmail.com>
Signed-off-by: Panchajanya1999 <panchajanya@azure-dev.live>
Signed-off-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
Signed-off-by: sohamxda7 <sensoham135@gmail.com>
Signed-off-by: RyuujiX <saputradenny712@gmail.com>
Signed-off-by: wHo-EM-i <ehteshammalik18998@gmail.com>
Signed-off-by: Santhosh <santhosh.user.why.red@gmail.com>
  • Loading branch information
kerneltoast authored and user-why-red committed Jun 12, 2024
1 parent ad4711f commit 3aa3f0c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,9 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
if (unlikely(wq->flags & __WQ_DRAINING) &&
WARN_ON_ONCE(!is_chained_work(wq)))
return;

if (req_cpu == WORK_CPU_UNBOUND)
cpu = wq_select_unbound_cpu(0);
retry:
/* pwq which will be used unless @work is executing elsewhere */
if (wq->flags & WQ_UNBOUND) {
Expand Down Expand Up @@ -1577,7 +1580,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq,
if (unlikely(cpu != WORK_CPU_UNBOUND))
add_timer_on(timer, cpu);
else
add_timer(timer);
add_timer_on(timer, 0);
}

/**
Expand Down Expand Up @@ -3280,14 +3283,15 @@ void free_workqueue_attrs(struct workqueue_attrs *attrs)
struct workqueue_attrs *alloc_workqueue_attrs(gfp_t gfp_mask)
{
struct workqueue_attrs *attrs;
const unsigned long allowed_cpus = 0xf;

attrs = kzalloc(sizeof(*attrs), gfp_mask);
if (!attrs)
goto fail;
if (!alloc_cpumask_var(&attrs->cpumask, gfp_mask))
goto fail;

cpumask_copy(attrs->cpumask, cpu_possible_mask);
cpumask_copy(attrs->cpumask, to_cpumask(&allowed_cpus));
return attrs;
fail:
free_workqueue_attrs(attrs);
Expand Down Expand Up @@ -4429,7 +4433,7 @@ bool workqueue_congested(int cpu, struct workqueue_struct *wq)
rcu_read_lock_sched();

if (cpu == WORK_CPU_UNBOUND)
cpu = smp_processor_id();
cpu = 0;

if (!(wq->flags & WQ_UNBOUND))
pwq = per_cpu_ptr(wq->cpu_pwqs, cpu);
Expand Down

0 comments on commit 3aa3f0c

Please sign in to comment.