Skip to content

Commit 3bd3706

Browse files
Sebastian Andrzej Siewioringomolnar
authored andcommitted
sched/core: Provide a pointer to the valid CPU mask
In commit: 4b53a34 ("sched/core: Remove the tsk_nr_cpus_allowed() wrapper") the tsk_nr_cpus_allowed() wrapper was removed. There was not much difference in !RT but in RT we used this to implement migrate_disable(). Within a migrate_disable() section the CPU mask is restricted to single CPU while the "normal" CPU mask remains untouched. As an alternative implementation Ingo suggested to use: struct task_struct { const cpumask_t *cpus_ptr; cpumask_t cpus_mask; }; with t->cpus_ptr = &t->cpus_mask; In -RT we then can switch the cpus_ptr to: t->cpus_ptr = &cpumask_of(task_cpu(p)); in a migration disabled region. The rules are simple: - Code that 'uses' ->cpus_allowed would use the pointer. - Code that 'modifies' ->cpus_allowed would use the direct mask. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lkml.kernel.org/r/20190423142636.14347-1-bigeasy@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f2c7c76 commit 3bd3706

23 files changed

Lines changed: 75 additions & 73 deletions

File tree

‎arch/ia64/kernel/mca.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ format_mca_init_stack(void *mca_data, unsigned long offset,
18311831
ti->cpu = cpu;
18321832
p->stack = ti;
18331833
p->state = TASK_UNINTERRUPTIBLE;
1834-
cpumask_set_cpu(cpu, &p->cpus_allowed);
1834+
cpumask_set_cpu(cpu, &p->cpus_mask);
18351835
INIT_LIST_HEAD(&p->tasks);
18361836
p->parent = p->real_parent = p->group_leader = p;
18371837
INIT_LIST_HEAD(&p->children);

‎arch/mips/include/asm/switch_to.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern struct task_struct *ll_task;
4242
* inline to try to keep the overhead down. If we have been forced to run on
4343
* a "CPU" with an FPU because of a previous high level of FP computation,
4444
* but did not actually use the FPU during the most recent time-slice (CU1
45-
* isn't set), we undo the restriction on cpus_allowed.
45+
* isn't set), we undo the restriction on cpus_mask.
4646
*
4747
* We're not calling set_cpus_allowed() here, because we have no need to
4848
* force prompt migration - we're already switching the current CPU to a
@@ -57,7 +57,7 @@ do { \
5757
test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
5858
(!(KSTK_STATUS(prev) & ST0_CU1))) { \
5959
clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
60-
prev->cpus_allowed = prev->thread.user_cpus_allowed; \
60+
prev->cpus_mask = prev->thread.user_cpus_allowed; \
6161
} \
6262
next->thread.emulated_fp = 0; \
6363
} while(0)

‎arch/mips/kernel/mips-mt-fpaff.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ asmlinkage long mipsmt_sys_sched_getaffinity(pid_t pid, unsigned int len,
177177
if (retval)
178178
goto out_unlock;
179179

180-
cpumask_or(&allowed, &p->thread.user_cpus_allowed, &p->cpus_allowed);
180+
cpumask_or(&allowed, &p->thread.user_cpus_allowed, p->cpus_ptr);
181181
cpumask_and(&mask, &allowed, cpu_active_mask);
182182

183183
out_unlock:

‎arch/mips/kernel/traps.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,12 @@ static void mt_ase_fp_affinity(void)
891891
* restricted the allowed set to exclude any CPUs with FPUs,
892892
* we'll skip the procedure.
893893
*/
894-
if (cpumask_intersects(&current->cpus_allowed, &mt_fpu_cpumask)) {
894+
if (cpumask_intersects(&current->cpus_mask, &mt_fpu_cpumask)) {
895895
cpumask_t tmask;
896896

897897
current->thread.user_cpus_allowed
898-
= current->cpus_allowed;
899-
cpumask_and(&tmask, &current->cpus_allowed,
898+
= current->cpus_mask;
899+
cpumask_and(&tmask, &current->cpus_mask,
900900
&mt_fpu_cpumask);
901901
set_cpus_allowed_ptr(current, &tmask);
902902
set_thread_flag(TIF_FPUBOUND);

‎arch/powerpc/platforms/cell/spufs/sched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void __spu_update_sched_info(struct spu_context *ctx)
128128
* runqueue. The context will be rescheduled on the proper node
129129
* if it is timesliced or preempted.
130130
*/
131-
cpumask_copy(&ctx->cpus_allowed, &current->cpus_allowed);
131+
cpumask_copy(&ctx->cpus_allowed, current->cpus_ptr);
132132

133133
/* Save the current cpu id for spu interrupt routing. */
134134
ctx->last_ran = raw_smp_processor_id();

‎arch/x86/kernel/cpu/resctrl/pseudo_lock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)
15031503
* may be scheduled elsewhere and invalidate entries in the
15041504
* pseudo-locked region.
15051505
*/
1506-
if (!cpumask_subset(&current->cpus_allowed, &plr->d->cpu_mask)) {
1506+
if (!cpumask_subset(current->cpus_ptr, &plr->d->cpu_mask)) {
15071507
mutex_unlock(&rdtgroup_mutex);
15081508
return -EINVAL;
15091509
}

‎drivers/infiniband/hw/hfi1/affinity.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,15 +1038,15 @@ int hfi1_get_proc_affinity(int node)
10381038
struct hfi1_affinity_node *entry;
10391039
cpumask_var_t diff, hw_thread_mask, available_mask, intrs_mask;
10401040
const struct cpumask *node_mask,
1041-
*proc_mask = &current->cpus_allowed;
1041+
*proc_mask = current->cpus_ptr;
10421042
struct hfi1_affinity_node_list *affinity = &node_affinity;
10431043
struct cpu_mask_set *set = &affinity->proc;
10441044

10451045
/*
10461046
* check whether process/context affinity has already
10471047
* been set
10481048
*/
1049-
if (cpumask_weight(proc_mask) == 1) {
1049+
if (current->nr_cpus_allowed == 1) {
10501050
hfi1_cdbg(PROC, "PID %u %s affinity set to CPU %*pbl",
10511051
current->pid, current->comm,
10521052
cpumask_pr_args(proc_mask));
@@ -1057,7 +1057,7 @@ int hfi1_get_proc_affinity(int node)
10571057
cpu = cpumask_first(proc_mask);
10581058
cpumask_set_cpu(cpu, &set->used);
10591059
goto done;
1060-
} else if (cpumask_weight(proc_mask) < cpumask_weight(&set->mask)) {
1060+
} else if (current->nr_cpus_allowed < cpumask_weight(&set->mask)) {
10611061
hfi1_cdbg(PROC, "PID %u %s affinity set to CPU set(s) %*pbl",
10621062
current->pid, current->comm,
10631063
cpumask_pr_args(proc_mask));

‎drivers/infiniband/hw/hfi1/sdma.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,14 +855,13 @@ struct sdma_engine *sdma_select_user_engine(struct hfi1_devdata *dd,
855855
{
856856
struct sdma_rht_node *rht_node;
857857
struct sdma_engine *sde = NULL;
858-
const struct cpumask *current_mask = &current->cpus_allowed;
859858
unsigned long cpu_id;
860859

861860
/*
862861
* To ensure that always the same sdma engine(s) will be
863862
* selected make sure the process is pinned to this CPU only.
864863
*/
865-
if (cpumask_weight(current_mask) != 1)
864+
if (current->nr_cpus_allowed != 1)
866865
goto out;
867866

868867
cpu_id = smp_processor_id();

‎drivers/infiniband/hw/qib/qib_file_ops.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ static __poll_t qib_poll(struct file *fp, struct poll_table_struct *pt)
11421142
static void assign_ctxt_affinity(struct file *fp, struct qib_devdata *dd)
11431143
{
11441144
struct qib_filedata *fd = fp->private_data;
1145-
const unsigned int weight = cpumask_weight(&current->cpus_allowed);
1145+
const unsigned int weight = current->nr_cpus_allowed;
11461146
const struct cpumask *local_mask = cpumask_of_pcibus(dd->pcidev->bus);
11471147
int local_cpu;
11481148

@@ -1623,9 +1623,8 @@ static int qib_assign_ctxt(struct file *fp, const struct qib_user_info *uinfo)
16231623
ret = find_free_ctxt(i_minor - 1, fp, uinfo);
16241624
else {
16251625
int unit;
1626-
const unsigned int cpu = cpumask_first(&current->cpus_allowed);
1627-
const unsigned int weight =
1628-
cpumask_weight(&current->cpus_allowed);
1626+
const unsigned int cpu = cpumask_first(current->cpus_ptr);
1627+
const unsigned int weight = current->nr_cpus_allowed;
16291628

16301629
if (weight == 1 && !test_bit(cpu, qib_cpulist))
16311630
if (!find_hca(cpu, &unit) && unit >= 0)

‎fs/proc/array.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ static inline void task_context_switch_counts(struct seq_file *m,
381381
static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
382382
{
383383
seq_printf(m, "Cpus_allowed:\t%*pb\n",
384-
cpumask_pr_args(&task->cpus_allowed));
384+
cpumask_pr_args(task->cpus_ptr));
385385
seq_printf(m, "Cpus_allowed_list:\t%*pbl\n",
386-
cpumask_pr_args(&task->cpus_allowed));
386+
cpumask_pr_args(task->cpus_ptr));
387387
}
388388

389389
static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm)

0 commit comments

Comments
 (0)