Skip to content

Commit 952371d

Browse files
urezkipaulmckrcu
authored andcommitted
rcu/tree: Move kfree_rcu_cpu locking/unlocking to separate functions
Introduce helpers to lock and unlock per-cpu "kfree_rcu_cpu" structures. That will make kfree_call_rcu() more readable and prevent programming errors. Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 3af8486 commit 952371d

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

kernel/rcu/tree.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,27 @@ debug_rcu_bhead_unqueue(struct kfree_rcu_bulk_data *bhead)
30353035
#endif
30363036
}
30373037

3038+
static inline struct kfree_rcu_cpu *
3039+
krc_this_cpu_lock(unsigned long *flags)
3040+
{
3041+
struct kfree_rcu_cpu *krcp;
3042+
3043+
local_irq_save(*flags); // For safely calling this_cpu_ptr().
3044+
krcp = this_cpu_ptr(&krc);
3045+
if (likely(krcp->initialized))
3046+
raw_spin_lock(&krcp->lock);
3047+
3048+
return krcp;
3049+
}
3050+
3051+
static inline void
3052+
krc_this_cpu_unlock(struct kfree_rcu_cpu *krcp, unsigned long flags)
3053+
{
3054+
if (likely(krcp->initialized))
3055+
raw_spin_unlock(&krcp->lock);
3056+
local_irq_restore(flags);
3057+
}
3058+
30383059
/*
30393060
* This function is invoked in workqueue context after a grace period.
30403061
* It frees all the objects queued on ->bhead_free or ->head_free.
@@ -3260,11 +3281,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
32603281
struct kfree_rcu_cpu *krcp;
32613282
void *ptr;
32623283

3263-
local_irq_save(flags); // For safely calling this_cpu_ptr().
3264-
krcp = this_cpu_ptr(&krc);
3265-
if (krcp->initialized)
3266-
raw_spin_lock(&krcp->lock);
3267-
3284+
krcp = krc_this_cpu_lock(&flags);
32683285
ptr = (void *)head - (unsigned long)func;
32693286

32703287
// Queue the object but don't yet schedule the batch.
@@ -3295,9 +3312,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
32953312
}
32963313

32973314
unlock_return:
3298-
if (krcp->initialized)
3299-
raw_spin_unlock(&krcp->lock);
3300-
local_irq_restore(flags);
3315+
krc_this_cpu_unlock(krcp, flags);
33013316
}
33023317
EXPORT_SYMBOL_GPL(kfree_call_rcu);
33033318

0 commit comments

Comments
 (0)