Skip to content

Commit 69f08d3

Browse files
Sebastian Andrzej Siewiorpaulmckrcu
authored andcommitted
rcu/tree: Use static initializer for krc.lock
The per-CPU variable is initialized at runtime in kfree_rcu_batch_init(). This function is invoked before 'rcu_scheduler_active' is set to 'RCU_SCHEDULER_RUNNING'. After the initialisation, '->initialized' is to true. The raw_spin_lock is only acquired if '->initialized' is set to true. The worqueue item is only used if 'rcu_scheduler_active' set to RCU_SCHEDULER_RUNNING which happens after initialisation. Use a static initializer for krc.lock and remove the runtime initialisation of the lock. Since the lock can now be always acquired, remove the '->initialized' check. Cc: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 952371d commit 69f08d3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

kernel/rcu/tree.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,7 @@ struct kfree_rcu_cpu_work {
30023002
* @lock: Synchronize access to this structure
30033003
* @monitor_work: Promote @head to @head_free after KFREE_DRAIN_JIFFIES
30043004
* @monitor_todo: Tracks whether a @monitor_work delayed work is pending
3005-
* @initialized: The @lock and @rcu_work fields have been initialized
3005+
* @initialized: The @rcu_work fields have been initialized
30063006
* @count: Number of objects for which GP not started
30073007
*
30083008
* This is a per-CPU structure. The reason that it is not included in
@@ -3022,7 +3022,9 @@ struct kfree_rcu_cpu {
30223022
int count;
30233023
};
30243024

3025-
static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc);
3025+
static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc) = {
3026+
.lock = __RAW_SPIN_LOCK_UNLOCKED(krc.lock),
3027+
};
30263028

30273029
static __always_inline void
30283030
debug_rcu_bhead_unqueue(struct kfree_rcu_bulk_data *bhead)
@@ -3042,17 +3044,15 @@ krc_this_cpu_lock(unsigned long *flags)
30423044

30433045
local_irq_save(*flags); // For safely calling this_cpu_ptr().
30443046
krcp = this_cpu_ptr(&krc);
3045-
if (likely(krcp->initialized))
3046-
raw_spin_lock(&krcp->lock);
3047+
raw_spin_lock(&krcp->lock);
30473048

30483049
return krcp;
30493050
}
30503051

30513052
static inline void
30523053
krc_this_cpu_unlock(struct kfree_rcu_cpu *krcp, unsigned long flags)
30533054
{
3054-
if (likely(krcp->initialized))
3055-
raw_spin_unlock(&krcp->lock);
3055+
raw_spin_unlock(&krcp->lock);
30563056
local_irq_restore(flags);
30573057
}
30583058

@@ -4278,7 +4278,6 @@ static void __init kfree_rcu_batch_init(void)
42784278
for_each_possible_cpu(cpu) {
42794279
struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
42804280

4281-
raw_spin_lock_init(&krcp->lock);
42824281
for (i = 0; i < KFREE_N_BATCHES; i++) {
42834282
INIT_RCU_WORK(&krcp->krw_arr[i].rcu_work, kfree_rcu_work);
42844283
krcp->krw_arr[i].krcp = krcp;

0 commit comments

Comments
 (0)