2023-10-10 09:54:06

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH] locking/osq: remove spin node definition from header

This structure is an implementation detail of osq_lock.c, and there are
no external users.

Also drop the redundant overview comment from osq_lock.c.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
include/linux/osq_lock.h | 5 -----
kernel/locking/osq_lock.c | 9 ++++++---
2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/include/linux/osq_lock.h b/include/linux/osq_lock.h
index 5581dbd3bd34..ea8fb31379e3 100644
--- a/include/linux/osq_lock.h
+++ b/include/linux/osq_lock.h
@@ -6,11 +6,6 @@
* An MCS like lock especially tailored for optimistic spinning for sleeping
* lock implementations (mutex, rwsem, etc).
*/
-struct optimistic_spin_node {
- struct optimistic_spin_node *next, *prev;
- int locked; /* 1 if lock acquired */
- int cpu; /* encoded CPU # + 1 value */
-};

struct optimistic_spin_queue {
/*
diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index d5610ad52b92..918866edbc30 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -3,10 +3,13 @@
#include <linux/sched.h>
#include <linux/osq_lock.h>

+struct optimistic_spin_node {
+ struct optimistic_spin_node *next, *prev;
+ int locked; /* 1 if lock acquired */
+ int cpu; /* encoded CPU # + 1 value */
+};
+
/*
- * An MCS like lock especially tailored for optimistic spinning for sleeping
- * lock implementations (mutex, rwsem, etc).
- *
* Using a single mcs node per CPU is safe because sleeping locks should not be
* called from interrupt context and we have preemption disabled while
* spinning.

---
base-commit: 94f6f0550c625fab1f373bb86a6669b45e9748b3
change-id: 20231010-osq-header-9aca778ade30

Best regards,
--
Thomas Weißschuh <[email protected]>


2023-10-10 23:08:22

by Waiman Long

[permalink] [raw]
Subject: Re: [PATCH] locking/osq: remove spin node definition from header


On 10/10/23 05:53, Thomas Weißschuh wrote:
> This structure is an implementation detail of osq_lock.c, and there are
> no external users.
>
> Also drop the redundant overview comment from osq_lock.c.
>
> Signed-off-by: Thomas Weißschuh <[email protected]>
> ---
> include/linux/osq_lock.h | 5 -----
> kernel/locking/osq_lock.c | 9 ++++++---
> 2 files changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/osq_lock.h b/include/linux/osq_lock.h
> index 5581dbd3bd34..ea8fb31379e3 100644
> --- a/include/linux/osq_lock.h
> +++ b/include/linux/osq_lock.h
> @@ -6,11 +6,6 @@
> * An MCS like lock especially tailored for optimistic spinning for sleeping
> * lock implementations (mutex, rwsem, etc).
> */
> -struct optimistic_spin_node {
> - struct optimistic_spin_node *next, *prev;
> - int locked; /* 1 if lock acquired */
> - int cpu; /* encoded CPU # + 1 value */
> -};

It is probably better to drop the MCS like lock comment here as it is
not relevant without the optimistic_spin_node struct.


>
> struct optimistic_spin_queue {
> /*
> diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
> index d5610ad52b92..918866edbc30 100644
> --- a/kernel/locking/osq_lock.c
> +++ b/kernel/locking/osq_lock.c
> @@ -3,10 +3,13 @@
> #include <linux/sched.h>
> #include <linux/osq_lock.h>
>
> +struct optimistic_spin_node {
> + struct optimistic_spin_node *next, *prev;
> + int locked; /* 1 if lock acquired */
> + int cpu; /* encoded CPU # + 1 value */
> +};
> +
> /*
> - * An MCS like lock especially tailored for optimistic spinning for sleeping
> - * lock implementations (mutex, rwsem, etc).
> - *
> * Using a single mcs node per CPU is safe because sleeping locks should not be
> * called from interrupt context and we have preemption disabled while
> * spinning.

We should keep the MCS comment here. My other suggestion is to put the
structure definition after the comment.

Other than these minor nits, it is a worthwhile cleanup patch.

Cheers,
Longman