Skip to content

mutex: move nxmutex to sched#8645

Closed
zyfeier wants to merge 2 commits into
apache:masterfrom
zyfeier:mutex
Closed

mutex: move nxmutex to sched#8645
zyfeier wants to merge 2 commits into
apache:masterfrom
zyfeier:mutex

Conversation

@zyfeier

@zyfeier zyfeier commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

Summary

  1. Move nxmutex to sched;
  2. Add mutex_clocklock, mutex_set_protocol and mutex_get_protocol interface;
  3. Mutex is not cancellation point, delete cancellation point check;

Impact

Mutex

Testing

sabre-6quad:nsh ostest

Comment thread libs/libnx/nxfonts/nxfonts_cache.c Outdated
Comment thread sched/mutex/mutex.h
Comment thread sched/mutex/mutex_breaklock.c Outdated
Comment thread sched/mutex/mutex_breaklock.c Outdated
@zyfeier zyfeier force-pushed the mutex branch 10 times, most recently from 8047165 to 3926ae5 Compare March 1, 2023 01:34
@zyfeier zyfeier marked this pull request as ready for review March 1, 2023 03:28
Comment thread include/mutex.h Outdated
Comment thread include/nuttx/mutex.h Outdated
@pkarashchenko

Copy link
Copy Markdown
Contributor

I'm still not sure about this change. I know that some time in the past I drafter something similar, but after re-thinking I'm looking into a next direction: there is already one mutex layer available in user space and it is pthread_mutex. I do not think we need to introduce another layer otherwise it will bring duplication. We need to think how to solve libc issue in a different way. Till now nxmutex was simply a wrapper on top of sem/nxsem, but now it seems to be something more.

@zyfeier

zyfeier commented Mar 3, 2023

Copy link
Copy Markdown
Contributor Author

I'm still not sure about this change. I know that some time in the past I drafter something similar, but after re-thinking I'm looking into a next direction: there is already one mutex layer available in user space and it is pthread_mutex. I do not think we need to introduce another layer otherwise it will bring duplication. We need to think how to solve libc issue in a different way. Till now nxmutex was simply a wrapper on top of sem/nxsem, but now it seems to be something more.

@pkarashchenko
Yes, this is only the first step of the modification, the following changes will be dependent on this modification:

  1. pthread mutex is changed to depend on nxmutex instead of nxsem.
  2. nxmutex no longer depends on nxsem and is implemented independently;
  3. Move priority inheritance from nxsem to nxmutex, and optimize the performance of priority inheritance;

@zyfeier zyfeier force-pushed the mutex branch 4 times, most recently from cce5b1e to 1e7e1b8 Compare March 3, 2023 09:00
@zyfeier zyfeier changed the title mutex: move nxmutex to sched and add mutex_ interface for userspace mutex: move nxmutex to sched Mar 3, 2023
Comment thread syscall/syscall.csv Outdated
Comment thread sched/mutex/mutex_reset.c Outdated
Comment thread include/sys/syscall_lookup.h Outdated
Comment thread include/sys/syscall_lookup.h Outdated
Comment thread sched/mutex/mutex.h Outdated
@zyfeier zyfeier force-pushed the mutex branch 2 times, most recently from 8f24d1b to 5356830 Compare March 6, 2023 10:42
Comment thread sched/mutex/mutex_unlock.c Outdated
Comment thread sched/mutex/mutex_trylock.c Outdated
Comment thread sched/mutex/mutex_unlock.c
Comment thread sched/mutex/mutex_timedlock.c Outdated
Comment thread sched/mutex/mutex_restorelock.c
Comment thread sched/mutex/mutex_reset.c Outdated
Comment thread sched/mutex/mutex_lock.c Outdated
Comment thread sched/mutex/mutex_is_hold.c
Comment thread sched/mutex/mutex_destroy.c Outdated
Comment thread sched/mutex/mutex_breaklock.c
@zyfeier zyfeier force-pushed the mutex branch 2 times, most recently from 1ff51b4 to 56616b5 Compare March 7, 2023 12:55
@zyfeier

zyfeier commented Mar 9, 2023

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 @pkarashchenko Any comments on this PR? Please help to review it again.

@pkarashchenko

Copy link
Copy Markdown
Contributor

I will take a look over the weekend.

Comment thread libs/libc/mutex/mutex_reset.c Outdated
Comment thread libs/libc/mutex/mutex_is_hold.c
Comment thread sched/mutex/mutex_breaklock.c Outdated
Comment thread sched/mutex/mutex_trylock.c Outdated
Comment thread sched/mutex/mutex_timedlock.c Outdated
Comment thread sched/mutex/mutex_timedlock.c Outdated
Comment thread sched/mutex/mutex.h Outdated
Comment thread sched/mutex/mutex_clocklock.c
Comment thread sched/mutex/mutex_clocklock.c Outdated
Comment thread libs/libc/mutex/mutex_clocklock.c
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

I will take a look over the weekend.

@pkarashchenko do you finish the review?

Comment thread include/nuttx/mutex.h Outdated
Comment thread include/nuttx/mutex.h Outdated
Comment thread sched/mutex/mutex_lock.c Outdated
Comment thread sched/mutex/mutex_timedlock.c Outdated
Comment thread sched/mutex/mutex_trylock.c Outdated
@pkarashchenko

Copy link
Copy Markdown
Contributor

I will take a look over the weekend.

@pkarashchenko do you finish the review?

Done. Sorry, I experienced many delays during my trip, so was not able to review on time

@pkarashchenko pkarashchenko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I do not see any issues that stop this PR from merging except one.
I'm missing the overall roadmap for the mutex support. The nxmutex is not a cancellation point but if I recall correctly (@xiaoxiang781216 please correct me if I'm wrong) there is an intention to move pthread_mutex (and maybe pthead_rwlock) to use nxmutex interface. The pthread_mutex interface is not a cancellation point, so all seems to be fine, but pthread_rwlock is a cancellation point.

I really would like to re-inspect the affected area and have nxmutex discussion moving to the mailing list before we are not too far away. By the affected area I mean that printf for example is a cancellation point and many other places as well. I will spend some time this week to figure out if those functions rely on the sem/pthread_mutex interface in user mode and how this change will affect that.

@zyfeier

zyfeier commented Mar 14, 2023

Copy link
Copy Markdown
Contributor Author

In general I do not see any issues that stop this PR from merging except one. I'm missing the overall roadmap for the mutex support. The nxmutex is not a cancellation point but if I recall correctly (@xiaoxiang781216 please correct me if I'm wrong) there is an intention to move pthread_mutex (and maybe pthead_rwlock) to use nxmutex interface. The pthread_mutex interface is not a cancellation point, so all seems to be fine, but pthread_rwlock is a cancellation point.

I really would like to re-inspect the affected area and have nxmutex discussion moving to the mailing list before we are not too far away. By the affected area I mean that printf for example is a cancellation point and many other places as well. I will spend some time this week to figure out if those functions rely on the sem/pthread_mutex interface in user mode and how this change will affect that.

@pkarashchenko About pthread rwlock, although pthread_mutex is not a cancellation point, but pthread_cond_wait is, so i think this should be no problem. But it's still necessary to re-inspect the affected area.

zhangyuan21 added 2 commits March 22, 2023 13:39
1. Move nxmutex to sched and directly depends on the nxsem;
2. Mutex is not cancellation point, delete cancellation point check;

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
add nxmutex_clocklock, nxmutex_set_protocol and nxmutex_get_protocol interface

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
@pkarashchenko

Copy link
Copy Markdown
Contributor

I'm planning to start mailing list discussion till the end of this week.

@zyfeier zyfeier marked this pull request as draft April 11, 2023 06:13
@zyfeier zyfeier closed this Apr 18, 2023
@zyfeier zyfeier deleted the mutex branch April 28, 2023 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants