Skip to content

Commit cf5868c

Browse files
minipliherbertx
authored andcommitted
padata: ensure the reorder timer callback runs on the correct CPU
The reorder timer function runs on the CPU where the timer interrupt was handled which is not necessarily one of the CPUs of the 'pcpu' CPU mask set. Ensure the padata_reorder() callback runs on the correct CPU, which is one in the 'pcpu' CPU mask set and, preferrably, the next expected one. Do so by comparing the current CPU with the expected target CPU. If they match, call padata_reorder() right away. If they differ, schedule a work item on the target CPU that does the padata_reorder() call for us. Signed-off-by: Mathias Krause <minipli@googlemail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 1bd845b commit cf5868c

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎include/linux/padata.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct padata_serial_queue {
8585
* @swork: work struct for serialization.
8686
* @pd: Backpointer to the internal control structure.
8787
* @work: work struct for parallelization.
88+
* @reorder_work: work struct for reordering.
8889
* @num_obj: Number of objects that are processed by this cpu.
8990
* @cpu_index: Index of the cpu.
9091
*/
@@ -93,6 +94,7 @@ struct padata_parallel_queue {
9394
struct padata_list reorder;
9495
struct parallel_data *pd;
9596
struct work_struct work;
97+
struct work_struct reorder_work;
9698
atomic_t num_obj;
9799
int cpu_index;
98100
};

‎kernel/padata.c‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,51 @@ static void padata_reorder(struct parallel_data *pd)
275275
return;
276276
}
277277

278+
static void invoke_padata_reorder(struct work_struct *work)
279+
{
280+
struct padata_parallel_queue *pqueue;
281+
struct parallel_data *pd;
282+
283+
local_bh_disable();
284+
pqueue = container_of(work, struct padata_parallel_queue, reorder_work);
285+
pd = pqueue->pd;
286+
padata_reorder(pd);
287+
local_bh_enable();
288+
}
289+
278290
static void padata_reorder_timer(unsigned long arg)
279291
{
280292
struct parallel_data *pd = (struct parallel_data *)arg;
293+
unsigned int weight;
294+
int target_cpu, cpu;
281295

282-
padata_reorder(pd);
296+
cpu = get_cpu();
297+
298+
/* We don't lock pd here to not interfere with parallel processing
299+
* padata_reorder() calls on other CPUs. We just need any CPU out of
300+
* the cpumask.pcpu set. It would be nice if it's the right one but
301+
* it doesn't matter if we're off to the next one by using an outdated
302+
* pd->processed value.
303+
*/
304+
weight = cpumask_weight(pd->cpumask.pcpu);
305+
target_cpu = padata_index_to_cpu(pd, pd->processed % weight);
306+
307+
/* ensure to call the reorder callback on the correct CPU */
308+
if (cpu != target_cpu) {
309+
struct padata_parallel_queue *pqueue;
310+
struct padata_instance *pinst;
311+
312+
/* The timer function is serialized wrt itself -- no locking
313+
* needed.
314+
*/
315+
pinst = pd->pinst;
316+
pqueue = per_cpu_ptr(pd->pqueue, target_cpu);
317+
queue_work_on(target_cpu, pinst->wq, &pqueue->reorder_work);
318+
} else {
319+
padata_reorder(pd);
320+
}
321+
322+
put_cpu();
283323
}
284324

285325
static void padata_serial_worker(struct work_struct *serial_work)
@@ -399,6 +439,7 @@ static void padata_init_pqueues(struct parallel_data *pd)
399439
__padata_list_init(&pqueue->reorder);
400440
__padata_list_init(&pqueue->parallel);
401441
INIT_WORK(&pqueue->work, padata_parallel_worker);
442+
INIT_WORK(&pqueue->reorder_work, invoke_padata_reorder);
402443
atomic_set(&pqueue->num_obj, 0);
403444
}
404445
}

0 commit comments

Comments
 (0)