[PATCH v3 06/14] locking/mutex: Expose mutex_owner()

John Stultz posted 14 patches 2 years, 10 months ago
There is a newer version of this series
[PATCH v3 06/14] locking/mutex: Expose mutex_owner()
Posted by John Stultz 2 years, 10 months ago
From: Juri Lelli <juri.lelli@redhat.com>

Implementing proxy execution requires that scheduler code be able to
identify the current owner of a mutex. Expose a new helper
mutex_owner() for this purpose.

Cc: Joel Fernandes <joelaf@google.com>
Cc: Qais Yousef <qyousef@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Zimuzo Ezeozue <zezeozue@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Will Deacon <will@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: "Paul E . McKenney" <paulmck@kernel.org>
Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
[Removed the EXPORT_SYMBOL]
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Connor O'Brien <connoro@google.com>
[jstultz: Tweaked subject line]
Signed-off-by: John Stultz <jstultz@google.com>
---
 include/linux/mutex.h  | 2 ++
 kernel/locking/mutex.c | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 8f226d460f51..ebdc59cb0bf6 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -118,6 +118,8 @@ do {									\
 extern void __mutex_init(struct mutex *lock, const char *name,
 			 struct lock_class_key *key);
 
+extern struct task_struct *mutex_owner(struct mutex *lock);
+
 /**
  * mutex_is_locked - is the mutex locked
  * @lock: the mutex to be queried
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 45f1b7519f63..cbc34d5f4486 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -81,6 +81,11 @@ static inline struct task_struct *__mutex_owner(struct mutex *lock)
 	return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
 }
 
+struct task_struct *mutex_owner(struct mutex *lock)
+{
+	return __mutex_owner(lock);
+}
+
 static inline struct task_struct *__owner_task(unsigned long owner)
 {
 	return (struct task_struct *)(owner & ~MUTEX_FLAGS);
-- 
2.40.0.577.gac1e443424-goog
Re: [PATCH v3 06/14] locking/mutex: Expose mutex_owner()
Posted by Peter Zijlstra 2 years, 9 months ago
On Tue, Apr 11, 2023 at 04:25:03AM +0000, John Stultz wrote:

>  include/linux/mutex.h  | 2 ++
>  kernel/locking/mutex.c | 5 +++++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/include/linux/mutex.h b/include/linux/mutex.h
> index 8f226d460f51..ebdc59cb0bf6 100644
> --- a/include/linux/mutex.h
> +++ b/include/linux/mutex.h
> @@ -118,6 +118,8 @@ do {									\
>  extern void __mutex_init(struct mutex *lock, const char *name,
>  			 struct lock_class_key *key);
>  
> +extern struct task_struct *mutex_owner(struct mutex *lock);
> +
>  /**
>   * mutex_is_locked - is the mutex locked
>   * @lock: the mutex to be queried
> diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> index 45f1b7519f63..cbc34d5f4486 100644
> --- a/kernel/locking/mutex.c
> +++ b/kernel/locking/mutex.c
> @@ -81,6 +81,11 @@ static inline struct task_struct *__mutex_owner(struct mutex *lock)
>  	return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
>  }
>  
> +struct task_struct *mutex_owner(struct mutex *lock)
> +{
> +	return __mutex_owner(lock);
> +}
> +
>  static inline struct task_struct *__owner_task(unsigned long owner)
>  {
>  	return (struct task_struct *)(owner & ~MUTEX_FLAGS);


Urgh, no.

It exposes mutex_owner() far wider than it should be, and also it turns
what should be a simple load into a function call :/

Looking at the lastest patches I have here this used to be an inline in
kernel/locking/mutex.h and kernel/sched/core.c got to #include
"../locking/mutex.h".
Re: [PATCH v3 06/14] locking/mutex: Expose mutex_owner()
Posted by John Stultz 2 years, 9 months ago
On Sat, Apr 22, 2023 at 11:36 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Tue, Apr 11, 2023 at 04:25:03AM +0000, John Stultz wrote:
>
> >  include/linux/mutex.h  | 2 ++
> >  kernel/locking/mutex.c | 5 +++++
> >  2 files changed, 7 insertions(+)
> >
> > diff --git a/include/linux/mutex.h b/include/linux/mutex.h
> > index 8f226d460f51..ebdc59cb0bf6 100644
> > --- a/include/linux/mutex.h
> > +++ b/include/linux/mutex.h
> > @@ -118,6 +118,8 @@ do {                                                                      \
> >  extern void __mutex_init(struct mutex *lock, const char *name,
> >                        struct lock_class_key *key);
> >
> > +extern struct task_struct *mutex_owner(struct mutex *lock);
> > +
> >  /**
> >   * mutex_is_locked - is the mutex locked
> >   * @lock: the mutex to be queried
> > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
> > index 45f1b7519f63..cbc34d5f4486 100644
> > --- a/kernel/locking/mutex.c
> > +++ b/kernel/locking/mutex.c
> > @@ -81,6 +81,11 @@ static inline struct task_struct *__mutex_owner(struct mutex *lock)
> >       return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
> >  }
> >
> > +struct task_struct *mutex_owner(struct mutex *lock)
> > +{
> > +     return __mutex_owner(lock);
> > +}
> > +
> >  static inline struct task_struct *__owner_task(unsigned long owner)
> >  {
> >       return (struct task_struct *)(owner & ~MUTEX_FLAGS);
>
>
> Urgh, no.
>
> It exposes mutex_owner() far wider than it should be, and also it turns
> what should be a simple load into a function call :/
>
> Looking at the lastest patches I have here this used to be an inline in
> kernel/locking/mutex.h and kernel/sched/core.c got to #include
> "../locking/mutex.h".

Sure. I'll rework it this way.

Thanks again for the feedback, and apologies for any frustration caused.
-john