@@ -166,23 +166,12 @@ EXPORT_SYMBOL(padata_do_parallel);
166
166
*/
167
167
static struct padata_priv * padata_get_next (struct parallel_data * pd )
168
168
{
169
- int cpu , num_cpus ;
170
- unsigned int next_nr , next_index ;
171
169
struct padata_parallel_queue * next_queue ;
172
170
struct padata_priv * padata ;
173
171
struct padata_list * reorder ;
172
+ int cpu = pd -> cpu ;
174
173
175
- num_cpus = cpumask_weight (pd -> cpumask .pcpu );
176
-
177
- /*
178
- * Calculate the percpu reorder queue and the sequence
179
- * number of the next object.
180
- */
181
- next_nr = pd -> processed ;
182
- next_index = next_nr % num_cpus ;
183
- cpu = padata_index_to_cpu (pd , next_index );
184
174
next_queue = per_cpu_ptr (pd -> pqueue , cpu );
185
-
186
175
reorder = & next_queue -> reorder ;
187
176
188
177
spin_lock (& reorder -> lock );
@@ -193,7 +182,8 @@ static struct padata_priv *padata_get_next(struct parallel_data *pd)
193
182
list_del_init (& padata -> list );
194
183
atomic_dec (& pd -> reorder_objects );
195
184
196
- pd -> processed ++ ;
185
+ pd -> cpu = cpumask_next_wrap (cpu , pd -> cpumask .pcpu , -1 ,
186
+ false);
197
187
198
188
spin_unlock (& reorder -> lock );
199
189
goto out ;
@@ -216,6 +206,7 @@ static void padata_reorder(struct parallel_data *pd)
216
206
struct padata_priv * padata ;
217
207
struct padata_serial_queue * squeue ;
218
208
struct padata_instance * pinst = pd -> pinst ;
209
+ struct padata_parallel_queue * next_queue ;
219
210
220
211
/*
221
212
* We need to ensure that only one cpu can work on dequeueing of
@@ -247,7 +238,6 @@ static void padata_reorder(struct parallel_data *pd)
247
238
* so exit immediately.
248
239
*/
249
240
if (PTR_ERR (padata ) == - ENODATA ) {
250
- del_timer (& pd -> timer );
251
241
spin_unlock_bh (& pd -> lock );
252
242
return ;
253
243
}
@@ -266,70 +256,29 @@ static void padata_reorder(struct parallel_data *pd)
266
256
267
257
/*
268
258
* The next object that needs serialization might have arrived to
269
- * the reorder queues in the meantime, we will be called again
270
- * from the timer function if no one else cares for it.
259
+ * the reorder queues in the meantime.
271
260
*
272
- * Ensure reorder_objects is read after pd->lock is dropped so we see
273
- * an increment from another task in padata_do_serial. Pairs with
261
+ * Ensure reorder queue is read after pd->lock is dropped so we see
262
+ * new objects from another task in padata_do_serial. Pairs with
274
263
* smp_mb__after_atomic in padata_do_serial.
275
264
*/
276
265
smp_mb ();
277
- if (atomic_read (& pd -> reorder_objects )
278
- && !(pinst -> flags & PADATA_RESET ))
279
- mod_timer (& pd -> timer , jiffies + HZ );
280
- else
281
- del_timer (& pd -> timer );
282
266
283
- return ;
267
+ next_queue = per_cpu_ptr (pd -> pqueue , pd -> cpu );
268
+ if (!list_empty (& next_queue -> reorder .list ))
269
+ queue_work (pinst -> wq , & pd -> reorder_work );
284
270
}
285
271
286
272
static void invoke_padata_reorder (struct work_struct * work )
287
273
{
288
- struct padata_parallel_queue * pqueue ;
289
274
struct parallel_data * pd ;
290
275
291
276
local_bh_disable ();
292
- pqueue = container_of (work , struct padata_parallel_queue , reorder_work );
293
- pd = pqueue -> pd ;
277
+ pd = container_of (work , struct parallel_data , reorder_work );
294
278
padata_reorder (pd );
295
279
local_bh_enable ();
296
280
}
297
281
298
- static void padata_reorder_timer (unsigned long arg )
299
- {
300
- struct parallel_data * pd = (struct parallel_data * )arg ;
301
- unsigned int weight ;
302
- int target_cpu , cpu ;
303
-
304
- cpu = get_cpu ();
305
-
306
- /* We don't lock pd here to not interfere with parallel processing
307
- * padata_reorder() calls on other CPUs. We just need any CPU out of
308
- * the cpumask.pcpu set. It would be nice if it's the right one but
309
- * it doesn't matter if we're off to the next one by using an outdated
310
- * pd->processed value.
311
- */
312
- weight = cpumask_weight (pd -> cpumask .pcpu );
313
- target_cpu = padata_index_to_cpu (pd , pd -> processed % weight );
314
-
315
- /* ensure to call the reorder callback on the correct CPU */
316
- if (cpu != target_cpu ) {
317
- struct padata_parallel_queue * pqueue ;
318
- struct padata_instance * pinst ;
319
-
320
- /* The timer function is serialized wrt itself -- no locking
321
- * needed.
322
- */
323
- pinst = pd -> pinst ;
324
- pqueue = per_cpu_ptr (pd -> pqueue , target_cpu );
325
- queue_work_on (target_cpu , pinst -> wq , & pqueue -> reorder_work );
326
- } else {
327
- padata_reorder (pd );
328
- }
329
-
330
- put_cpu ();
331
- }
332
-
333
282
static void padata_serial_worker (struct work_struct * serial_work )
334
283
{
335
284
struct padata_serial_queue * squeue ;
@@ -383,9 +332,8 @@ void padata_do_serial(struct padata_priv *padata)
383
332
384
333
cpu = get_cpu ();
385
334
386
- /* We need to run on the same CPU padata_do_parallel(.., padata, ..)
387
- * was called on -- or, at least, enqueue the padata object into the
388
- * correct per-cpu queue.
335
+ /* We need to enqueue the padata object into the correct
336
+ * per-cpu queue.
389
337
*/
390
338
if (cpu != padata -> cpu ) {
391
339
reorder_via_wq = 1 ;
@@ -395,26 +343,20 @@ void padata_do_serial(struct padata_priv *padata)
395
343
pqueue = per_cpu_ptr (pd -> pqueue , cpu );
396
344
397
345
spin_lock (& pqueue -> reorder .lock );
398
- atomic_inc (& pd -> reorder_objects );
399
346
list_add_tail (& padata -> list , & pqueue -> reorder .list );
347
+ atomic_inc (& pd -> reorder_objects );
400
348
spin_unlock (& pqueue -> reorder .lock );
401
349
402
350
/*
403
- * Ensure the atomic_inc of reorder_objects above is ordered correctly
351
+ * Ensure the addition to the reorder list is ordered correctly
404
352
* with the trylock of pd->lock in padata_reorder. Pairs with smp_mb
405
353
* in padata_reorder.
406
354
*/
407
355
smp_mb__after_atomic ();
408
356
409
357
put_cpu ();
410
358
411
- /* If we're running on the wrong CPU, call padata_reorder() via a
412
- * kernel worker.
413
- */
414
- if (reorder_via_wq )
415
- queue_work_on (cpu , pd -> pinst -> wq , & pqueue -> reorder_work );
416
- else
417
- padata_reorder (pd );
359
+ padata_reorder (pd );
418
360
}
419
361
EXPORT_SYMBOL (padata_do_serial );
420
362
@@ -470,14 +412,12 @@ static void padata_init_pqueues(struct parallel_data *pd)
470
412
continue ;
471
413
}
472
414
473
- pqueue -> pd = pd ;
474
415
pqueue -> cpu_index = cpu_index ;
475
416
cpu_index ++ ;
476
417
477
418
__padata_list_init (& pqueue -> reorder );
478
419
__padata_list_init (& pqueue -> parallel );
479
420
INIT_WORK (& pqueue -> work , padata_parallel_worker );
480
- INIT_WORK (& pqueue -> reorder_work , invoke_padata_reorder );
481
421
atomic_set (& pqueue -> num_obj , 0 );
482
422
}
483
423
}
@@ -505,12 +445,13 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
505
445
506
446
padata_init_pqueues (pd );
507
447
padata_init_squeues (pd );
508
- setup_timer (& pd -> timer , padata_reorder_timer , (unsigned long )pd );
509
448
atomic_set (& pd -> seq_nr , -1 );
510
449
atomic_set (& pd -> reorder_objects , 0 );
511
450
atomic_set (& pd -> refcnt , 1 );
512
451
pd -> pinst = pinst ;
513
452
spin_lock_init (& pd -> lock );
453
+ pd -> cpu = cpumask_first (pcpumask );
454
+ INIT_WORK (& pd -> reorder_work , invoke_padata_reorder );
514
455
515
456
return pd ;
516
457
0 commit comments