Skip to contentSkip to conversation

locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

PATCH Superseded Zqiang 3 participants 8 messages Feb 15, 2023 – Feb 23, 2023 Torture-test modules

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

For PREEMPT_RT kernel, the spin_lock, spin_lock_irq will converted to sleepable rt_spin_lock and the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect CPU's interrupt state. this commit therefore add raw_spin_lock torture tests, this is a strict spin lock implementation in RT kernels.

---
 kernel/locking/locktorture.c | 58 ++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
kernel/locking/locktorture.c +58 -0
index 9425aff08936..521197366f27 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);
+
+static int torture_raw_spin_lock_write_lock(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	raw_spin_lock(&torture_raw_spinlock);
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock(&torture_raw_spinlock);
+}
+
+static struct lock_torture_ops raw_spin_lock_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock"
+};
+
+static int torture_raw_spin_lock_write_lock_irq(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&torture_raw_spinlock, flags);
+	cxt.cur_ops->flags = flags;
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock_irq(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock_irqrestore(&torture_raw_spinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_spin_lock_irq_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock_irq,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock_irq,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock_irq"
+};
+#endif
+
 static DEFINE_RWLOCK(torture_rwlock);
 
 static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1017,6 +1072,9 @@ static int __init lock_torture_init(void)
 	static struct lock_torture_ops *torture_ops[] = {
 		&lock_busted_ops,
 		&spin_lock_ops, &spin_lock_irq_ops,
+#ifdef CONFIG_PREEMPT_RT
+		&raw_spin_lock_ops, &raw_spin_lock_irq_ops,
+#endif
 		&rw_lock_ops, &rw_lock_irq_ops,
 		&mutex_lock_ops,
 		&ww_mutex_lock_ops,
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 7 lines · Zqiang

For PREEMPT_RT kernel, the spin_lock, spin_lock_irq will converted to sleepable rt_spin_lock and the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect CPU's interrupt state. this commit therefore add raw_spin_lock torture tests, this is a strict spin lock implementation in RT kernels.

A nice addition! Is this something you will be testing regularly? If not, should there be additional locktorture scenarios, perhaps prefixed by "RT-" to hint that they are not normally available?

Or did you have some other plan for making use of these?

Thanx, Paul

Quoted 83 lines
---
 kernel/locking/locktorture.c | 58 ++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
kernel/locking/locktorture.c +58 -0
index 9425aff08936..521197366f27 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);
+
+static int torture_raw_spin_lock_write_lock(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	raw_spin_lock(&torture_raw_spinlock);
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock(&torture_raw_spinlock);
+}
+
+static struct lock_torture_ops raw_spin_lock_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock"
+};
+
+static int torture_raw_spin_lock_write_lock_irq(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&torture_raw_spinlock, flags);
+	cxt.cur_ops->flags = flags;
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock_irq(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock_irqrestore(&torture_raw_spinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_spin_lock_irq_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock_irq,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock_irq,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock_irq"
+};
+#endif
+
 static DEFINE_RWLOCK(torture_rwlock);
 
 static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1017,6 +1072,9 @@ static int __init lock_torture_init(void)
 	static struct lock_torture_ops *torture_ops[] = {
 		&lock_busted_ops,
 		&spin_lock_ops, &spin_lock_irq_ops,
+#ifdef CONFIG_PREEMPT_RT
+		&raw_spin_lock_ops, &raw_spin_lock_irq_ops,
+#endif
 		&rw_lock_ops, &rw_lock_irq_ops,
 		&mutex_lock_ops,
 		&ww_mutex_lock_ops,
Signature · 1 line
2.25.1
#2 lore raw
Quoted 8 lines · Zqiang

For PREEMPT_RT kernel, the spin_lock, spin_lock_irq will converted to sleepable rt_spin_lock and the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect CPU's interrupt state. this commit therefore add raw_spin_lock torture tests, this is a strict spin lock implementation in RT kernels.

Quoted 7 lines

A nice addition! Is this something you will be testing regularly? If not, should there be additional locktorture scenarios, perhaps prefixed by "RT-" to hint that they are not normally available?

Or did you have some other plan for making use of these?

Hi Paul

Thanks for reply, in fact, I want to enrich the test of locktorture, after all, under the PREEMPT_RT kernel, we lost the test of the real spin lock.

Thanks
Zqiang

Quoted 86 lines

Thanx, Paul

---
 kernel/locking/locktorture.c | 58 ++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
kernel/locking/locktorture.c +58 -0
index 9425aff08936..521197366f27 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);
+
+static int torture_raw_spin_lock_write_lock(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	raw_spin_lock(&torture_raw_spinlock);
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock(&torture_raw_spinlock);
+}
+
+static struct lock_torture_ops raw_spin_lock_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock"
+};
+
+static int torture_raw_spin_lock_write_lock_irq(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&torture_raw_spinlock, flags);
+	cxt.cur_ops->flags = flags;
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock_irq(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock_irqrestore(&torture_raw_spinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_spin_lock_irq_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock_irq,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock_irq,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock_irq"
+};
+#endif
+
 static DEFINE_RWLOCK(torture_rwlock);
 
 static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1017,6 +1072,9 @@ static int __init lock_torture_init(void)
 	static struct lock_torture_ops *torture_ops[] = {
 		&lock_busted_ops,
 		&spin_lock_ops, &spin_lock_irq_ops,
+#ifdef CONFIG_PREEMPT_RT
+		&raw_spin_lock_ops, &raw_spin_lock_irq_ops,
+#endif
 		&rw_lock_ops, &rw_lock_irq_ops,
 		&mutex_lock_ops,
 		&ww_mutex_lock_ops,
Signature · 1 line
2.25.1
maintainer
#3 lore raw
Quoted 14 lines · On Sun, Feb 19, 2023 at 05:04:41AM +0000, Zhang, Qiang1 wrote:
Quoted 14 lines · Zqiang

For PREEMPT_RT kernel, the spin_lock, spin_lock_irq will converted to sleepable rt_spin_lock and the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect CPU's interrupt state. this commit therefore add raw_spin_lock torture tests, this is a strict spin lock implementation in RT kernels.

A nice addition! Is this something you will be testing regularly? If not, should there be additional locktorture scenarios, perhaps prefixed by "RT-" to hint that they are not normally available?

Quoted 7 lines
Quoted 1 line

Or did you have some other plan for making use of these?

Hi Paul

Thanks for reply, in fact, I want to enrich the test of locktorture, after all, under the PREEMPT_RT kernel, we lost the test of the real spin lock.

Very well, how does the following look?

Thanx, Paul

------------------------------------------------------------------------

commit edc9d419ee8c22821ffd664466a5cf19208c3f02

Author: Zqiang <[email protected]>
Date:   Wed Feb 15 14:10:35 2023 +0800

locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted to sleepable rt_spin_lock(). This means that the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's interrupt state. This commit therefore adds raw spin-lock torture tests. This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.

kernel/locking/locktorture.c +58 -0
index 9425aff089365..ed8e5baafe49f 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);
+
+static int torture_raw_spin_lock_write_lock(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	raw_spin_lock(&torture_raw_spinlock);
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock(&torture_raw_spinlock);
+}
+
+static struct lock_torture_ops raw_spin_lock_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock"
+};
+
+static int torture_raw_spin_lock_write_lock_irq(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&torture_raw_spinlock, flags);
+	cxt.cur_ops->flags = flags;
+	return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock_irq(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+	raw_spin_unlock_irqrestore(&torture_raw_spinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_spin_lock_irq_ops = {
+	.writelock	= torture_raw_spin_lock_write_lock_irq,
+	.write_delay	= torture_spin_lock_write_delay,
+	.task_boost	= torture_rt_boost,
+	.writeunlock	= torture_raw_spin_lock_write_unlock_irq,
+	.readlock	= NULL,
+	.read_delay	= NULL,
+	.readunlock	= NULL,
+	.name		= "raw_spin_lock_irq"
+};
+#endif // #ifdef CONFIG_PREEMPT_RT
+
 static DEFINE_RWLOCK(torture_rwlock);
 
 static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1017,6 +1072,9 @@ static int __init lock_torture_init(void)
 	static struct lock_torture_ops *torture_ops[] = {
 		&lock_busted_ops,
 		&spin_lock_ops, &spin_lock_irq_ops,
+#ifdef CONFIG_PREEMPT_RT
+		&raw_spin_lock_ops, &raw_spin_lock_irq_ops,
+#endif // #ifdef CONFIG_PREEMPT_RT
 		&rw_lock_ops, &rw_lock_irq_ops,
 		&mutex_lock_ops,
 		&ww_mutex_lock_ops,
maintainer
#4 lore raw
Quoted 6 lines · Paul E. McKenney

commit edc9d419ee8c22821ffd664466a5cf19208c3f02

Author: Zqiang <[email protected]>
Date:   Wed Feb 15 14:10:35 2023 +0800

locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

Quoted 8 lines

In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted to sleepable rt_spin_lock(). This means that the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's interrupt state. This commit therefore adds raw spin-lock torture tests. This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.

This is a nice addition, thanks. Just one comment below.

kernel/locking/locktorture.c static struct lock_torture_ops spin_lock_irq_ops = { · line 261

Quoted 10 lines
kernel/locking/locktorture.c +2 -0
index 9425aff089365..ed8e5baafe49f 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);

How about leaving raw spinlocks regardless of preempt-rt, and instead change the default lock (which is spin_lock) based on CONFIG_PREEMPT_RT and use the raw one in that case?

Thanks,
Davidlohr

maintainer
#5 lore raw
Quoted 27 lines · Davidlohr Bueso
Quoted 6 lines · Paul E. McKenney

commit edc9d419ee8c22821ffd664466a5cf19208c3f02

Author: Zqiang <[email protected]>
Date:   Wed Feb 15 14:10:35 2023 +0800

locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

Quoted 8 lines

In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted to sleepable rt_spin_lock(). This means that the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's interrupt state. This commit therefore adds raw spin-lock torture tests. This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.

This is a nice addition, thanks. Just one comment below.

Quoted 8 lines
kernel/locking/locktorture.c +0 -0
index 9425aff089365..ed8e5baafe49f 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
Quoted 6 lines

kernel/locking/locktorture.c static struct lock_torture_ops spin_lock_irq_ops = { · line 261

Quoted 2 lines
kernel/locking/locktorture.c +2 -0
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);

How about leaving raw spinlocks regardless of preempt-rt, and instead change the default lock (which is spin_lock) based on CONFIG_PREEMPT_RT and use the raw one in that case?

That makes a lot of sense to me! In fact, I tested this by deleting those #ifdef statements. ;-)

Zqiang, would you like to take the patch and make that change, with attribution?

Thanx, Paul

#6 lore raw
Quoted 35 lines · Paul E. McKenney
Quoted 7 lines

commit edc9d419ee8c22821ffd664466a5cf19208c3f02

Author: Zqiang <[email protected]>
Date:   Wed Feb 15 14:10:35 2023 +0800

locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels

Quoted 8 lines

In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted to sleepable rt_spin_lock(). This means that the interrupt related suffix for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's interrupt state. This commit therefore adds raw spin-lock torture tests. This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.

This is a nice addition, thanks. Just one comment below.

kernel/locking/locktorture.c static struct lock_torture_ops spin_lock_irq_ops = { · line 261

Quoted 10 lines
kernel/locking/locktorture.c +2 -0
index 9425aff089365..ed8e5baafe49f 100644
@@ -257,6 +257,61 @@ static struct lock_torture_ops spin_lock_irq_ops = {
 	.name		= "spin_lock_irq"
 };
 
+#ifdef CONFIG_PREEMPT_RT
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);

How about leaving raw spinlocks regardless of preempt-rt, and instead change the default lock (which is spin_lock) based on CONFIG_PREEMPT_RT and use the raw one in that case?

Quoted 5 lines

That makes a lot of sense to me! In fact, I tested this by deleting those #ifdef statements. ;-)

Zqiang, would you like to take the patch and make that change, with attribution?

If I understand correctly, I should remove #ifdef statements, right? If yes, I will change and resend 😊.

Thanks
Zqiang

Quoted 2 lines

Thanx, Paul

maintainer
#7 lore raw
Quoted 1 line · On Thu, 23 Feb 2023, Zhang, Qiang1 wrote:

If I understand correctly, I should remove #ifdef statements, right?

Yes, but also please make torture_type default depend on PREEMPT_RT.

Thanks,
Davidlohr