[TRACKING] xtimer/xtimer.c: xtimer_mutex_lock_timeout fix and improvements#11660
Conversation
3c65bc6 to
b9b3cd4
Compare
|
rebase because #11679 got merged |
b9b3cd4 to
a1c5030
Compare
sys/xtimer/xtimer.c
Outdated
| } | ||
| sched_set_status(thread, STATUS_PENDING); | ||
| irq_restore(irqstate); | ||
| thread_yield_higher(); |
There was a problem hiding this comment.
It looks like it is sched_switch that may need to be used here instead to be working everywhere.
But from the implementation, thread_yield_higher in cpu/atmega_common/thread_arch.c, does the check for is_in_irq…
I will do a dedicated test for this.
There was a problem hiding this comment.
Implementation in the CPU is wrong, this code is correct #11759 (comment)
There was a problem hiding this comment.
I will change it to sched_switch for now until #11759 is solved/discussed/closed.
There was a problem hiding this comment.
done in: sys/xtimer/xtimer.c: _mutex_timeout() clean ups #11807
f00b6df to
25ffbc4
Compare
f5b931d to
ec2933a
Compare
17c6311 to
8ffafdb
Compare
8ffafdb to
cbe6a24
Compare
cbe6a24 to
8853126
Compare
|
rebased on master |
|
The |
8853126 to
9fc60bd
Compare
|
rebased on master |
MichelRottleuthner
left a comment
There was a problem hiding this comment.
Tested and was able to reproduce the bug and verify the fix.
Some of the added debug output lines are longer than the absolute maximum of 120 chars and some are outdated (changed variable names).
While the debug messages probably were helpful for working on the test I don't think we should keep (all of) them.
Please squash so we can put Murdock to work.
9fc60bd to
05c88f4
Compare
|
@MichelRottleuthner done. Removed debug msg. |
05c88f4 to
40bf85e
Compare
MichelRottleuthner
left a comment
There was a problem hiding this comment.
Sorry I didn't see that before: the commit message is outdated (and contains typos).
Also see below.
core/include/mutex.h
Outdated
| static inline int mutex_trylock(mutex_t *mutex) | ||
| { | ||
| return _mutex_lock(mutex, 0); | ||
| uint8_t blocking = 0; |
There was a problem hiding this comment.
This should be declared as volatile explicitly.
core/include/mutex.h
Outdated
| static inline void mutex_lock(mutex_t *mutex) | ||
| { | ||
| _mutex_lock(mutex, 1); | ||
| uint8_t blocking = 1; |
sys/xtimer/xtimer.c
Outdated
| unsigned int irqstate = irq_disable(); | ||
|
|
||
| mutex_thread_t *mt = (mutex_thread_t *)arg; | ||
|
|
|
@MichelRottleuthner can I just rebase after the changes? (do you want fixup commits?) |
_mutex_lock uses a volatile int pointer for the parameter blocking instead of an int.
|
sure |
40bf85e to
dd6e51b
Compare
|
done |
MichelRottleuthner
left a comment
There was a problem hiding this comment.
Changes make sense and were tested -> ACK
This pr tracks the fix for
xtimer/xtimer.c: xtimer_mutex_lock_timeoutThis pr includes two throwaway test commits.
Contribution description
This pr fixes Bugs in
xtimer.c: xtimer_mutex_lock_timeout()and improves it. It addresses concurrency issues. The timer can trigger at a different time than expected.Before there were problems when the timer spins. This happens when the timeout is less than
XTIMER_BACKOFF.This pr also creates a new static function called
_mutex_remove_thread_from_waiting_queue. The function removes a thread from a mutex waiting queue, when the thread waiting for the mutex. This was already used inside of the_mutex_timeoutfunction. It is needed for thextimer_mutex_lock_timeoutfunction.This function should go into
core/mutexin the future because it modifies queue of the mutex_t struct. (in mutex_t struct comment:@brief Mutex structure. Must never be modified by the user.and in comment of queue@brief The process waiting queue of the mutex. **Must never be changed by the user.**)This pr also fixes
core/mutex.c:_mutex_lock()there was a problem when it gets interrupted before disabling interrupt. This is fixed by giving it a pointer to blocking.This pr also has tests and throwaway commits to show the bug and fix.
The struct for the
xtimer_mutex_lock_timeoutfunction calledmutex_thread_twas changed to fix the function and name changes for better understanding.This pull request is split into smaller parts:
Testing procedure
BOARD=native make -C tests/xtimer_mutex_lock timeout/ flash testit outputs:
Without the fixes this would fail.
The remove me commits show other bugs.
Go to the commit before "REMOVE ME" commit gets reverted.
Test will work.
Now go to the "REMOVE ME" commit.
Test will fail.
To test the bug in mutex.c:_mutex_lock revert to the second "REMOVE ME" commit with the commit message
Issues/PRs references
#11679: first tests
#11807: sys/xtimer/xtimer.c: _mutex_timeout() clean ups
#11992: sys/xtimer/xtimer.c: _mutex_timeout() bug fix
#12008: tests/xtimer_mutex_lock_timeout: New test
#13185: xtimer/xtimer.c:_mutex_timeout() improved
#13199: xtimer/xtimer.c: xtimer_mutex_lock_timeout fix with short timeout
needed for:
- #11977: xtimer/xtimer.c: xtimer_rmutex_lock_timeout
- #11485: [TRACKING] FreeRTOS Adaption Layer