@@ -116,8 +116,9 @@ do { \
116
116
/*
117
117
* Initialize SRCU per-CPU data. Note that statically allocated
118
118
* srcu_struct structures might already have srcu_read_lock() and
119
- * srcu_read_unlock() running against them. So if the is_static parameter
120
- * is set, don't initialize ->srcu_lock_count[] and ->srcu_unlock_count[].
119
+ * srcu_read_unlock() running against them. So if the is_static
120
+ * parameter is set, don't initialize ->srcu_ctrs[].srcu_locks and
121
+ * ->srcu_ctrs[].srcu_unlocks.
121
122
*/
122
123
static void init_srcu_struct_data (struct srcu_struct * ssp )
123
124
{
@@ -128,8 +129,6 @@ static void init_srcu_struct_data(struct srcu_struct *ssp)
128
129
* Initialize the per-CPU srcu_data array, which feeds into the
129
130
* leaves of the srcu_node tree.
130
131
*/
131
- BUILD_BUG_ON (ARRAY_SIZE (sdp -> srcu_lock_count ) !=
132
- ARRAY_SIZE (sdp -> srcu_unlock_count ));
133
132
for_each_possible_cpu (cpu ) {
134
133
sdp = per_cpu_ptr (ssp -> sda , cpu );
135
134
spin_lock_init (& ACCESS_PRIVATE (sdp , lock ));
@@ -429,10 +428,10 @@ static bool srcu_gp_is_expedited(struct srcu_struct *ssp)
429
428
}
430
429
431
430
/*
432
- * Computes approximate total of the readers' ->srcu_lock_count[] values
433
- * for the rank of per-CPU counters specified by idx, and returns true if
434
- * the caller did the proper barrier (gp), and if the count of the locks
435
- * matches that of the unlocks passed in.
431
+ * Computes approximate total of the readers' ->srcu_ctrs[].srcu_locks
432
+ * values for the rank of per-CPU counters specified by idx, and returns
433
+ * true if the caller did the proper barrier (gp), and if the count of
434
+ * the locks matches that of the unlocks passed in.
436
435
*/
437
436
static bool srcu_readers_lock_idx (struct srcu_struct * ssp , int idx , bool gp , unsigned long unlocks )
438
437
{
@@ -443,7 +442,7 @@ static bool srcu_readers_lock_idx(struct srcu_struct *ssp, int idx, bool gp, uns
443
442
for_each_possible_cpu (cpu ) {
444
443
struct srcu_data * sdp = per_cpu_ptr (ssp -> sda , cpu );
445
444
446
- sum += atomic_long_read (& sdp -> srcu_lock_count [idx ]);
445
+ sum += atomic_long_read (& sdp -> srcu_ctrs [idx ]. srcu_locks );
447
446
if (IS_ENABLED (CONFIG_PROVE_RCU ))
448
447
mask = mask | READ_ONCE (sdp -> srcu_reader_flavor );
449
448
}
@@ -455,8 +454,8 @@ static bool srcu_readers_lock_idx(struct srcu_struct *ssp, int idx, bool gp, uns
455
454
}
456
455
457
456
/*
458
- * Returns approximate total of the readers' ->srcu_unlock_count[] values
459
- * for the rank of per-CPU counters specified by idx.
457
+ * Returns approximate total of the readers' ->srcu_ctrs[].srcu_unlocks
458
+ * values for the rank of per-CPU counters specified by idx.
460
459
*/
461
460
static unsigned long srcu_readers_unlock_idx (struct srcu_struct * ssp , int idx , unsigned long * rdm )
462
461
{
@@ -467,7 +466,7 @@ static unsigned long srcu_readers_unlock_idx(struct srcu_struct *ssp, int idx, u
467
466
for_each_possible_cpu (cpu ) {
468
467
struct srcu_data * sdp = per_cpu_ptr (ssp -> sda , cpu );
469
468
470
- sum += atomic_long_read (& sdp -> srcu_unlock_count [idx ]);
469
+ sum += atomic_long_read (& sdp -> srcu_ctrs [idx ]. srcu_unlocks );
471
470
mask = mask | READ_ONCE (sdp -> srcu_reader_flavor );
472
471
}
473
472
WARN_ONCE (IS_ENABLED (CONFIG_PROVE_RCU ) && (mask & (mask - 1 )),
@@ -510,9 +509,9 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *ssp, int idx)
510
509
* been no readers on this index at some point in this function.
511
510
* But there might be more readers, as a task might have read
512
511
* the current ->srcu_idx but not yet have incremented its CPU's
513
- * ->srcu_lock_count [idx] counter. In fact, it is possible
512
+ * ->srcu_ctrs [idx].srcu_locks counter. In fact, it is possible
514
513
* that most of the tasks have been preempted between fetching
515
- * ->srcu_idx and incrementing ->srcu_lock_count [idx]. And there
514
+ * ->srcu_idx and incrementing ->srcu_ctrs [idx].srcu_locks . And there
516
515
* could be almost (ULONG_MAX / sizeof(struct task_struct)) tasks
517
516
* in a system whose address space was fully populated with memory.
518
517
* Call this quantity Nt.
@@ -521,36 +520,36 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *ssp, int idx)
521
520
* code for a long time. That now-preempted updater has already
522
521
* flipped ->srcu_idx (possibly during the preceding grace period),
523
522
* done an smp_mb() (again, possibly during the preceding grace
524
- * period), and summed up the ->srcu_unlock_count [idx] counters.
523
+ * period), and summed up the ->srcu_ctrs [idx].srcu_unlocks counters.
525
524
* How many times can a given one of the aforementioned Nt tasks
526
- * increment the old ->srcu_idx value's ->srcu_lock_count [idx]
525
+ * increment the old ->srcu_idx value's ->srcu_ctrs [idx].srcu_locks
527
526
* counter, in the absence of nesting?
528
527
*
529
528
* It can clearly do so once, given that it has already fetched
530
- * the old value of ->srcu_idx and is just about to use that value
531
- * to index its increment of ->srcu_lock_count [idx]. But as soon as
532
- * it leaves that SRCU read-side critical section, it will increment
533
- * ->srcu_unlock_count [idx], which must follow the updater's above
534
- * read from that same value. Thus, as soon the reading task does
535
- * an smp_mb() and a later fetch from ->srcu_idx, that task will be
536
- * guaranteed to get the new index. Except that the increment of
537
- * ->srcu_unlock_count[idx] in __srcu_read_unlock() is after the
538
- * smp_mb(), and the fetch from ->srcu_idx in __srcu_read_lock()
539
- * is before the smp_mb(). Thus, that task might not see the new
540
- * value of ->srcu_idx until the -second- __srcu_read_lock(),
541
- * which in turn means that this task might well increment
542
- * ->srcu_lock_count [idx] for the old value of ->srcu_idx twice,
543
- * not just once.
529
+ * the old value of ->srcu_idx and is just about to use that
530
+ * value to index its increment of ->srcu_ctrs [idx].srcu_locks.
531
+ * But as soon as it leaves that SRCU read-side critical section,
532
+ * it will increment ->srcu_ctrs [idx].srcu_unlocks , which must
533
+ * follow the updater's above read from that same value. Thus,
534
+ * as soon the reading task does an smp_mb() and a later fetch from
535
+ * ->srcu_idx, that task will be guaranteed to get the new index.
536
+ * Except that the increment of ->srcu_ctrs[idx].srcu_unlocks
537
+ * in __srcu_read_unlock() is after the smp_mb(), and the fetch
538
+ * from ->srcu_idx in __srcu_read_lock() is before the smp_mb().
539
+ * Thus, that task might not see the new value of ->srcu_idx until
540
+ * the -second- __srcu_read_lock(), which in turn means that this
541
+ * task might well increment ->srcu_ctrs [idx].srcu_locks for the
542
+ * old value of ->srcu_idx twice, not just once.
544
543
*
545
544
* However, it is important to note that a given smp_mb() takes
546
545
* effect not just for the task executing it, but also for any
547
546
* later task running on that same CPU.
548
547
*
549
- * That is, there can be almost Nt + Nc further increments of
550
- * ->srcu_lock_count [idx] for the old index, where Nc is the number
551
- * of CPUs. But this is OK because the size of the task_struct
552
- * structure limits the value of Nt and current systems limit Nc
553
- * to a few thousand.
548
+ * That is, there can be almost Nt + Nc further increments
549
+ * of ->srcu_ctrs [idx].srcu_locks for the old index, where Nc
550
+ * is the number of CPUs. But this is OK because the size of
551
+ * the task_struct structure limits the value of Nt and current
552
+ * systems limit Nc to a few thousand.
554
553
*
555
554
* OK, but what about nesting? This does impose a limit on
556
555
* nesting of half of the size of the task_struct structure
@@ -581,10 +580,10 @@ static bool srcu_readers_active(struct srcu_struct *ssp)
581
580
for_each_possible_cpu (cpu ) {
582
581
struct srcu_data * sdp = per_cpu_ptr (ssp -> sda , cpu );
583
582
584
- sum += atomic_long_read (& sdp -> srcu_lock_count [0 ]);
585
- sum += atomic_long_read (& sdp -> srcu_lock_count [1 ]);
586
- sum -= atomic_long_read (& sdp -> srcu_unlock_count [0 ]);
587
- sum -= atomic_long_read (& sdp -> srcu_unlock_count [1 ]);
583
+ sum += atomic_long_read (& sdp -> srcu_ctrs [0 ]. srcu_locks );
584
+ sum += atomic_long_read (& sdp -> srcu_ctrs [1 ]. srcu_locks );
585
+ sum -= atomic_long_read (& sdp -> srcu_ctrs [0 ]. srcu_unlocks );
586
+ sum -= atomic_long_read (& sdp -> srcu_ctrs [1 ]. srcu_unlocks );
588
587
}
589
588
return sum ;
590
589
}
@@ -746,7 +745,7 @@ int __srcu_read_lock(struct srcu_struct *ssp)
746
745
int idx ;
747
746
748
747
idx = READ_ONCE (ssp -> srcu_idx ) & 0x1 ;
749
- this_cpu_inc (ssp -> sda -> srcu_lock_count [idx ].counter );
748
+ this_cpu_inc (ssp -> sda -> srcu_ctrs [idx ]. srcu_locks .counter );
750
749
smp_mb (); /* B */ /* Avoid leaking the critical section. */
751
750
return idx ;
752
751
}
@@ -760,7 +759,7 @@ EXPORT_SYMBOL_GPL(__srcu_read_lock);
760
759
void __srcu_read_unlock (struct srcu_struct * ssp , int idx )
761
760
{
762
761
smp_mb (); /* C */ /* Avoid leaking the critical section. */
763
- this_cpu_inc (ssp -> sda -> srcu_unlock_count [idx ].counter );
762
+ this_cpu_inc (ssp -> sda -> srcu_ctrs [idx ]. srcu_unlocks .counter );
764
763
}
765
764
EXPORT_SYMBOL_GPL (__srcu_read_unlock );
766
765
@@ -777,7 +776,7 @@ int __srcu_read_lock_nmisafe(struct srcu_struct *ssp)
777
776
struct srcu_data * sdp = raw_cpu_ptr (ssp -> sda );
778
777
779
778
idx = READ_ONCE (ssp -> srcu_idx ) & 0x1 ;
780
- atomic_long_inc (& sdp -> srcu_lock_count [idx ]);
779
+ atomic_long_inc (& sdp -> srcu_ctrs [idx ]. srcu_locks );
781
780
smp_mb__after_atomic (); /* B */ /* Avoid leaking the critical section. */
782
781
return idx ;
783
782
}
@@ -793,7 +792,7 @@ void __srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx)
793
792
struct srcu_data * sdp = raw_cpu_ptr (ssp -> sda );
794
793
795
794
smp_mb__before_atomic (); /* C */ /* Avoid leaking the critical section. */
796
- atomic_long_inc (& sdp -> srcu_unlock_count [idx ]);
795
+ atomic_long_inc (& sdp -> srcu_ctrs [idx ]. srcu_unlocks );
797
796
}
798
797
EXPORT_SYMBOL_GPL (__srcu_read_unlock_nmisafe );
799
798
@@ -1123,17 +1122,17 @@ static void srcu_flip(struct srcu_struct *ssp)
1123
1122
/*
1124
1123
* Because the flip of ->srcu_idx is executed only if the
1125
1124
* preceding call to srcu_readers_active_idx_check() found that
1126
- * the ->srcu_unlock_count[] and ->srcu_lock_count[] sums matched
1127
- * and because that summing uses atomic_long_read(), there is
1128
- * ordering due to a control dependency between that summing and
1129
- * the WRITE_ONCE() in this call to srcu_flip(). This ordering
1130
- * ensures that if this updater saw a given reader's increment from
1131
- * __srcu_read_lock(), that reader was using a value of ->srcu_idx
1132
- * from before the previous call to srcu_flip(), which should be
1133
- * quite rare. This ordering thus helps forward progress because
1134
- * the grace period could otherwise be delayed by additional
1135
- * calls to __srcu_read_lock() using that old (soon to be new)
1136
- * value of ->srcu_idx.
1125
+ * the ->srcu_ctrs[].srcu_unlocks and ->srcu_ctrs[].srcu_locks sums
1126
+ * matched and because that summing uses atomic_long_read(),
1127
+ * there is ordering due to a control dependency between that
1128
+ * summing and the WRITE_ONCE() in this call to srcu_flip().
1129
+ * This ordering ensures that if this updater saw a given reader's
1130
+ * increment from __srcu_read_lock(), that reader was using a value
1131
+ * of ->srcu_idx from before the previous call to srcu_flip(),
1132
+ * which should be quite rare. This ordering thus helps forward
1133
+ * progress because the grace period could otherwise be delayed
1134
+ * by additional calls to __srcu_read_lock() using that old (soon
1135
+ * to be new) value of ->srcu_idx.
1137
1136
*
1138
1137
* This sum-equality check and ordering also ensures that if
1139
1138
* a given call to __srcu_read_lock() uses the new value of
@@ -1914,17 +1913,17 @@ void srcu_torture_stats_print(struct srcu_struct *ssp, char *tt, char *tf)
1914
1913
struct srcu_data * sdp ;
1915
1914
1916
1915
sdp = per_cpu_ptr (ssp -> sda , cpu );
1917
- u0 = data_race (atomic_long_read (& sdp -> srcu_unlock_count [!idx ]));
1918
- u1 = data_race (atomic_long_read (& sdp -> srcu_unlock_count [idx ]));
1916
+ u0 = data_race (atomic_long_read (& sdp -> srcu_ctrs [!idx ]. srcu_unlocks ));
1917
+ u1 = data_race (atomic_long_read (& sdp -> srcu_ctrs [idx ]. srcu_unlocks ));
1919
1918
1920
1919
/*
1921
1920
* Make sure that a lock is always counted if the corresponding
1922
1921
* unlock is counted.
1923
1922
*/
1924
1923
smp_rmb ();
1925
1924
1926
- l0 = data_race (atomic_long_read (& sdp -> srcu_lock_count [!idx ]));
1927
- l1 = data_race (atomic_long_read (& sdp -> srcu_lock_count [idx ]));
1925
+ l0 = data_race (atomic_long_read (& sdp -> srcu_ctrs [!idx ]. srcu_locks ));
1926
+ l1 = data_race (atomic_long_read (& sdp -> srcu_ctrs [idx ]. srcu_locks ));
1928
1927
1929
1928
c0 = l0 - u0 ;
1930
1929
c1 = l1 - u1 ;
0 commit comments