Skip to content

Commit

Permalink
sched/core: Force trivial, unbound kthreads onto low-power CPUs
Browse files Browse the repository at this point in the history
In order to reduce power consumption, force all non-perf-critical,
unbound kthreads onto the low-power CPUs. Note that init must be
explicitly excluded from this so that all processes forked from init
have a sane default CPU affinity mask.

Change-Id: Ic86928a058d8fb033adc834572cd71248d29e705
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Alex Winkowski <dereference23@outlook.com>
Signed-off-by: Richard Raya <rdxzv.dev@gmail.com>
  • Loading branch information
kerneltoast authored and pascua28 committed Jan 11, 2025
1 parent 2dbe504 commit 8792d87
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,18 @@ void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_ma
p->nr_cpus_allowed = cpumask_weight(new_mask);
}

static const struct cpumask *
adjust_cpumask(struct task_struct *p,
const struct cpumask *orig_mask)
{
/* Force all trivial, unbound kthreads onto the little cluster */
if (p->flags & PF_KTHREAD && !is_global_init(p) &&
cpumask_equal(orig_mask, cpu_all_mask))
return cpu_lp_mask;

return orig_mask;
}

void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
{
struct rq *rq = task_rq(p);
Expand Down Expand Up @@ -1121,6 +1133,8 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
int ret = 0;
cpumask_t allowed_mask;

new_mask = adjust_cpumask(p, new_mask);

rq = task_rq_lock(p, &rf);
update_rq_clock(rq);

Expand Down

0 comments on commit 8792d87

Please sign in to comment.