[RFC,0/4] Extend rseq with sched_state field

Message ID 20230517152654.7193-1-mathieu.desnoyers@efficios.com
Headers
Series Extend rseq with sched_state field |

Message

Mathieu Desnoyers May 17, 2023, 3:26 p.m. UTC
  This prototype extends struct rseq with a new sched_state field, which
contains a "on-cpu" flag kept up-to-date by the scheduler.

It is meant to be used by userspace adaptative mutexes to decide between
busy-wait and futex wait system call (releasing the CPU) behaviors based
on the current state of the mutex owner.

The goal is to improve use-cases where the duration of the critical
sections for a given lock follows a multi-modal distribution, preventing
statistical guesses from doing a good job at choosing between busy-wait
and futex wait behavior.

This is in response to the LWN coverage of 2023 Open Source Summit North
America (https://lwn.net/Articles/931789/) unscheduled slot "Adaptive
spinning in user space" presented by André Almeida.

Feedback is welcome!

Mathieu

Mathieu Desnoyers (4):
  rseq: Add sched_state field to struct rseq
  selftests/rseq: Add sched_state rseq field and getter
  selftests/rseq: Implement sched state test program
  selftests/rseq: Implement rseq_mutex test program

 include/linux/sched.h                         |  12 ++
 include/uapi/linux/rseq.h                     |  17 +++
 kernel/rseq.c                                 |  14 ++
 tools/testing/selftests/rseq/.gitignore       |   2 +
 tools/testing/selftests/rseq/Makefile         |   3 +-
 tools/testing/selftests/rseq/rseq-abi.h       |  17 +++
 tools/testing/selftests/rseq/rseq.h           |   5 +
 tools/testing/selftests/rseq/rseq_mutex.c     | 120 ++++++++++++++++++
 .../testing/selftests/rseq/sched_state_test.c |  71 +++++++++++
 9 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/rseq/rseq_mutex.c
 create mode 100644 tools/testing/selftests/rseq/sched_state_test.c
  

Comments

Davidlohr Bueso May 17, 2023, 4:07 p.m. UTC | #1
+Cc Waiman.

On Wed, 17 May 2023, Mathieu Desnoyers wrote:

>This prototype extends struct rseq with a new sched_state field, which
>contains a "on-cpu" flag kept up-to-date by the scheduler.
>
>It is meant to be used by userspace adaptative mutexes to decide between
>busy-wait and futex wait system call (releasing the CPU) behaviors based
>on the current state of the mutex owner.
>
>The goal is to improve use-cases where the duration of the critical
>sections for a given lock follows a multi-modal distribution, preventing
>statistical guesses from doing a good job at choosing between busy-wait
>and futex wait behavior.
>
>This is in response to the LWN coverage of 2023 Open Source Summit North
>America (https://lwn.net/Articles/931789/) unscheduled slot "Adaptive
>spinning in user space" presented by André Almeida.
>
>Feedback is welcome!
>
>Mathieu
>
>Mathieu Desnoyers (4):
>  rseq: Add sched_state field to struct rseq
>  selftests/rseq: Add sched_state rseq field and getter
>  selftests/rseq: Implement sched state test program
>  selftests/rseq: Implement rseq_mutex test program
>
> include/linux/sched.h                         |  12 ++
> include/uapi/linux/rseq.h                     |  17 +++
> kernel/rseq.c                                 |  14 ++
> tools/testing/selftests/rseq/.gitignore       |   2 +
> tools/testing/selftests/rseq/Makefile         |   3 +-
> tools/testing/selftests/rseq/rseq-abi.h       |  17 +++
> tools/testing/selftests/rseq/rseq.h           |   5 +
> tools/testing/selftests/rseq/rseq_mutex.c     | 120 ++++++++++++++++++
> .../testing/selftests/rseq/sched_state_test.c |  71 +++++++++++
> 9 files changed, 260 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/rseq/rseq_mutex.c
> create mode 100644 tools/testing/selftests/rseq/sched_state_test.c
>
>--
>2.25.1
>
  
Steven Rostedt May 17, 2023, 6:36 p.m. UTC | #2
On Wed, 17 May 2023 11:26:50 -0400
Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:

> This prototype extends struct rseq with a new sched_state field, which
> contains a "on-cpu" flag kept up-to-date by the scheduler.
> 
> It is meant to be used by userspace adaptative mutexes to decide between
> busy-wait and futex wait system call (releasing the CPU) behaviors based
> on the current state of the mutex owner.

Woot!

I'm so glad I talked Jon into hanging around for André's spurious talk.
He's the one that brought up rseq (as he mentioned in his article), and I
guess you read that :-)

Unfortunately, I'm in the process of a lot of trips and
meetings/presentations over the next few weeks, and I will not be able to
look into this. But I hope that André could test it out.

Cheers!

-- Steve