@@ -31,7 +31,6 @@ typedef void (*postgp_func_t)(struct rcu_tasks *rtp);
31
31
* @barrier_q_head: RCU callback for barrier operation.
32
32
* @rtp_blkd_tasks: List of tasks blocked as readers.
33
33
* @cpu: CPU number corresponding to this entry.
34
- * @index: Index of this CPU in rtpcp_array of the rcu_tasks structure.
35
34
* @rtpp: Pointer to the rcu_tasks structure.
36
35
*/
37
36
struct rcu_tasks_percpu {
@@ -44,7 +43,6 @@ struct rcu_tasks_percpu {
44
43
struct rcu_head barrier_q_head ;
45
44
struct list_head rtp_blkd_tasks ;
46
45
int cpu ;
47
- int index ;
48
46
struct rcu_tasks * rtpp ;
49
47
};
50
48
@@ -70,7 +68,6 @@ struct rcu_tasks_percpu {
70
68
* @postgp_func: This flavor's post-grace-period function (optional).
71
69
* @call_func: This flavor's call_rcu()-equivalent function.
72
70
* @rtpcpu: This flavor's rcu_tasks_percpu structure.
73
- * @rtpcp_array: Array of pointers to rcu_tasks_percpu structure of CPUs in cpu_possible_mask.
74
71
* @percpu_enqueue_shift: Shift down CPU ID this much when enqueuing callbacks.
75
72
* @percpu_enqueue_lim: Number of per-CPU callback queues in use for enqueuing.
76
73
* @percpu_dequeue_lim: Number of per-CPU callback queues in use for dequeuing.
@@ -103,7 +100,6 @@ struct rcu_tasks {
103
100
postgp_func_t postgp_func ;
104
101
call_rcu_func_t call_func ;
105
102
struct rcu_tasks_percpu __percpu * rtpcpu ;
106
- struct rcu_tasks_percpu * * rtpcp_array ;
107
103
int percpu_enqueue_shift ;
108
104
int percpu_enqueue_lim ;
109
105
int percpu_dequeue_lim ;
@@ -168,8 +164,6 @@ module_param(rcu_task_contend_lim, int, 0444);
168
164
static int rcu_task_collapse_lim __read_mostly = 10 ;
169
165
module_param (rcu_task_collapse_lim , int , 0444 );
170
166
171
- static int rcu_task_cpu_ids ;
172
-
173
167
/* RCU tasks grace-period state for debugging. */
174
168
#define RTGS_INIT 0
175
169
#define RTGS_WAIT_WAIT_CBS 1
@@ -234,8 +228,6 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
234
228
unsigned long flags ;
235
229
int lim ;
236
230
int shift ;
237
- int maxcpu ;
238
- int index = 0 ;
239
231
240
232
raw_spin_lock_irqsave (& rtp -> cbs_gbl_lock , flags );
241
233
if (rcu_task_enqueue_lim < 0 ) {
@@ -246,9 +238,14 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
246
238
}
247
239
lim = rcu_task_enqueue_lim ;
248
240
249
- rtp -> rtpcp_array = kcalloc (num_possible_cpus (), sizeof (struct rcu_tasks_percpu * ), GFP_KERNEL );
250
- BUG_ON (!rtp -> rtpcp_array );
251
-
241
+ if (lim > nr_cpu_ids )
242
+ lim = nr_cpu_ids ;
243
+ shift = ilog2 (nr_cpu_ids / lim );
244
+ if (((nr_cpu_ids - 1 ) >> shift ) >= lim )
245
+ shift ++ ;
246
+ WRITE_ONCE (rtp -> percpu_enqueue_shift , shift );
247
+ WRITE_ONCE (rtp -> percpu_dequeue_lim , lim );
248
+ smp_store_release (& rtp -> percpu_enqueue_lim , lim );
252
249
for_each_possible_cpu (cpu ) {
253
250
struct rcu_tasks_percpu * rtpcp = per_cpu_ptr (rtp -> rtpcpu , cpu );
254
251
@@ -261,33 +258,16 @@ static void cblist_init_generic(struct rcu_tasks *rtp)
261
258
INIT_WORK (& rtpcp -> rtp_work , rcu_tasks_invoke_cbs_wq );
262
259
rtpcp -> cpu = cpu ;
263
260
rtpcp -> rtpp = rtp ;
264
- rtpcp -> index = index ;
265
- rtp -> rtpcp_array [index ] = rtpcp ;
266
- index ++ ;
267
261
if (!rtpcp -> rtp_blkd_tasks .next )
268
262
INIT_LIST_HEAD (& rtpcp -> rtp_blkd_tasks );
269
263
raw_spin_unlock_rcu_node (rtpcp ); // irqs remain disabled.
270
- maxcpu = cpu ;
271
264
}
272
265
raw_spin_unlock_irqrestore (& rtp -> cbs_gbl_lock , flags );
273
266
274
267
if (rcu_task_cb_adjust )
275
268
pr_info ("%s: Setting adjustable number of callback queues.\n" , __func__ );
276
269
277
- rcu_task_cpu_ids = maxcpu + 1 ;
278
- if (lim > rcu_task_cpu_ids )
279
- lim = rcu_task_cpu_ids ;
280
- shift = ilog2 (rcu_task_cpu_ids / lim );
281
- if (((rcu_task_cpu_ids - 1 ) >> shift ) >= lim )
282
- shift ++ ;
283
- WRITE_ONCE (rtp -> percpu_enqueue_shift , shift );
284
- WRITE_ONCE (rtp -> percpu_dequeue_lim , lim );
285
- smp_store_release (& rtp -> percpu_enqueue_lim , lim );
286
-
287
- pr_info ("%s: Setting shift to %d and lim to %d rcu_task_cb_adjust=%d rcu_task_cpu_ids=%d.\n" ,
288
- rtp -> name , data_race (rtp -> percpu_enqueue_shift ), data_race (rtp -> percpu_enqueue_lim ),
289
- rcu_task_cb_adjust , rcu_task_cpu_ids );
290
-
270
+ pr_info ("%s: Setting shift to %d and lim to %d.\n" , __func__ , data_race (rtp -> percpu_enqueue_shift ), data_race (rtp -> percpu_enqueue_lim ));
291
271
}
292
272
293
273
// IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic().
@@ -327,7 +307,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
327
307
rtpcp -> rtp_n_lock_retries = 0 ;
328
308
}
329
309
if (rcu_task_cb_adjust && ++ rtpcp -> rtp_n_lock_retries > rcu_task_contend_lim &&
330
- READ_ONCE (rtp -> percpu_enqueue_lim ) != rcu_task_cpu_ids )
310
+ READ_ONCE (rtp -> percpu_enqueue_lim ) != nr_cpu_ids )
331
311
needadjust = true; // Defer adjustment to avoid deadlock.
332
312
}
333
313
if (!rcu_segcblist_is_enabled (& rtpcp -> cblist )) {
@@ -340,10 +320,10 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
340
320
raw_spin_unlock_irqrestore_rcu_node (rtpcp , flags );
341
321
if (unlikely (needadjust )) {
342
322
raw_spin_lock_irqsave (& rtp -> cbs_gbl_lock , flags );
343
- if (rtp -> percpu_enqueue_lim != rcu_task_cpu_ids ) {
323
+ if (rtp -> percpu_enqueue_lim != nr_cpu_ids ) {
344
324
WRITE_ONCE (rtp -> percpu_enqueue_shift , 0 );
345
- WRITE_ONCE (rtp -> percpu_dequeue_lim , rcu_task_cpu_ids );
346
- smp_store_release (& rtp -> percpu_enqueue_lim , rcu_task_cpu_ids );
325
+ WRITE_ONCE (rtp -> percpu_dequeue_lim , nr_cpu_ids );
326
+ smp_store_release (& rtp -> percpu_enqueue_lim , nr_cpu_ids );
347
327
pr_info ("Switching %s to per-CPU callback queuing.\n" , rtp -> name );
348
328
}
349
329
raw_spin_unlock_irqrestore (& rtp -> cbs_gbl_lock , flags );
@@ -414,8 +394,6 @@ static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
414
394
int needgpcb = 0 ;
415
395
416
396
for (cpu = 0 ; cpu < smp_load_acquire (& rtp -> percpu_dequeue_lim ); cpu ++ ) {
417
- if (!cpu_possible (cpu ))
418
- continue ;
419
397
struct rcu_tasks_percpu * rtpcp = per_cpu_ptr (rtp -> rtpcpu , cpu );
420
398
421
399
/* Advance and accelerate any new callbacks. */
@@ -448,7 +426,7 @@ static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
448
426
if (rcu_task_cb_adjust && ncbs <= rcu_task_collapse_lim ) {
449
427
raw_spin_lock_irqsave (& rtp -> cbs_gbl_lock , flags );
450
428
if (rtp -> percpu_enqueue_lim > 1 ) {
451
- WRITE_ONCE (rtp -> percpu_enqueue_shift , order_base_2 (rcu_task_cpu_ids ));
429
+ WRITE_ONCE (rtp -> percpu_enqueue_shift , order_base_2 (nr_cpu_ids ));
452
430
smp_store_release (& rtp -> percpu_enqueue_lim , 1 );
453
431
rtp -> percpu_dequeue_gpseq = get_state_synchronize_rcu ();
454
432
gpdone = false;
@@ -463,9 +441,7 @@ static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
463
441
pr_info ("Completing switch %s to CPU-0 callback queuing.\n" , rtp -> name );
464
442
}
465
443
if (rtp -> percpu_dequeue_lim == 1 ) {
466
- for (cpu = rtp -> percpu_dequeue_lim ; cpu < rcu_task_cpu_ids ; cpu ++ ) {
467
- if (!cpu_possible (cpu ))
468
- continue ;
444
+ for (cpu = rtp -> percpu_dequeue_lim ; cpu < nr_cpu_ids ; cpu ++ ) {
469
445
struct rcu_tasks_percpu * rtpcp = per_cpu_ptr (rtp -> rtpcpu , cpu );
470
446
471
447
WARN_ON_ONCE (rcu_segcblist_n_cbs (& rtpcp -> cblist ));
@@ -480,32 +456,30 @@ static int rcu_tasks_need_gpcb(struct rcu_tasks *rtp)
480
456
// Advance callbacks and invoke any that are ready.
481
457
static void rcu_tasks_invoke_cbs (struct rcu_tasks * rtp , struct rcu_tasks_percpu * rtpcp )
482
458
{
459
+ int cpu ;
460
+ int cpunext ;
483
461
int cpuwq ;
484
462
unsigned long flags ;
485
463
int len ;
486
- int index ;
487
464
struct rcu_head * rhp ;
488
465
struct rcu_cblist rcl = RCU_CBLIST_INITIALIZER (rcl );
489
466
struct rcu_tasks_percpu * rtpcp_next ;
490
467
491
- index = rtpcp -> index * 2 + 1 ;
492
- if (index < num_possible_cpus ()) {
493
- rtpcp_next = rtp -> rtpcp_array [index ];
494
- if (rtpcp_next -> cpu < smp_load_acquire (& rtp -> percpu_dequeue_lim )) {
495
- cpuwq = rcu_cpu_beenfullyonline (rtpcp_next -> cpu ) ? rtpcp_next -> cpu : WORK_CPU_UNBOUND ;
468
+ cpu = rtpcp -> cpu ;
469
+ cpunext = cpu * 2 + 1 ;
470
+ if (cpunext < smp_load_acquire (& rtp -> percpu_dequeue_lim )) {
471
+ rtpcp_next = per_cpu_ptr (rtp -> rtpcpu , cpunext );
472
+ cpuwq = rcu_cpu_beenfullyonline (cpunext ) ? cpunext : WORK_CPU_UNBOUND ;
473
+ queue_work_on (cpuwq , system_wq , & rtpcp_next -> rtp_work );
474
+ cpunext ++ ;
475
+ if (cpunext < smp_load_acquire (& rtp -> percpu_dequeue_lim )) {
476
+ rtpcp_next = per_cpu_ptr (rtp -> rtpcpu , cpunext );
477
+ cpuwq = rcu_cpu_beenfullyonline (cpunext ) ? cpunext : WORK_CPU_UNBOUND ;
496
478
queue_work_on (cpuwq , system_wq , & rtpcp_next -> rtp_work );
497
- index ++ ;
498
- if (index < num_possible_cpus ()) {
499
- rtpcp_next = rtp -> rtpcp_array [index ];
500
- if (rtpcp_next -> cpu < smp_load_acquire (& rtp -> percpu_dequeue_lim )) {
501
- cpuwq = rcu_cpu_beenfullyonline (rtpcp_next -> cpu ) ? rtpcp_next -> cpu : WORK_CPU_UNBOUND ;
502
- queue_work_on (cpuwq , system_wq , & rtpcp_next -> rtp_work );
503
- }
504
- }
505
479
}
506
480
}
507
481
508
- if (rcu_segcblist_empty (& rtpcp -> cblist ))
482
+ if (rcu_segcblist_empty (& rtpcp -> cblist ) || ! cpu_possible ( cpu ) )
509
483
return ;
510
484
raw_spin_lock_irqsave_rcu_node (rtpcp , flags );
511
485
rcu_segcblist_advance (& rtpcp -> cblist , rcu_seq_current (& rtp -> tasks_gp_seq ));
0 commit comments