diff mbox series

cgroup: Add a comment to cgroup_rstat_flush_locked().

Message ID Yh+DOK73hfVV5ThX@linutronix.de (mailing list archive)
State New
Headers show
Series cgroup: Add a comment to cgroup_rstat_flush_locked(). | expand

Commit Message

Sebastian Andrzej Siewior March 2, 2022, 2:46 p.m. UTC
Add a comment why spin_lock_irq() -> raw_spin_lock_irqsave() is needed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
On 2022-03-01 20:38:51 [-1000], Tejun Heo wrote:
> Hello,

Hello Tejun,

> Can you please add a comment explaining why irqsave is being used? As it
> stands, it just looks spurious.

Something like this?

 kernel/cgroup/rstat.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Tejun Heo March 2, 2022, 3:47 p.m. UTC | #1
On Wed, Mar 02, 2022 at 03:46:16PM +0100, Sebastian Andrzej Siewior wrote:
> Add a comment why spin_lock_irq() -> raw_spin_lock_irqsave() is needed.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> On 2022-03-01 20:38:51 [-1000], Tejun Heo wrote:
> > Hello,
> 
> Hello Tejun,
> 
> > Can you please add a comment explaining why irqsave is being used? As it
> > stands, it just looks spurious.
> 
> Something like this?

Yeah, looks good to me.

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
diff mbox series

Patch

diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 53b771c20ee50..ba7a660184e41 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -155,6 +155,14 @@  static void cgroup_rstat_flush_locked(struct cgroup *cgrp, bool may_sleep)
 		struct cgroup *pos = NULL;
 		unsigned long flags;
 
+		/*
+		 * The _irqsave() is needed because cgroup_rstat_lock is
+		 * spinlock_t which is a sleeping lock on PREEMPT_RT. Acquiring
+		 * this lock with the _irq() suffix only disables interrupts on
+		 * a non-PREEMPT_RT kernel. The raw_spinlock_t below disables
+		 * interrupts on both configurations. The _irqsave() ensures
+		 * that interrupts are always disabled and later restored.
+		 */
 		raw_spin_lock_irqsave(cpu_lock, flags);
 		while ((pos = cgroup_rstat_cpu_pop_updated(pos, cgrp, cpu))) {
 			struct cgroup_subsys_state *css;