added test program for priority inversion problem#7372
Conversation
smlng
left a comment
There was a problem hiding this comment.
Thanks for tackling this issue and provide a suitable test! Some minor corrections, see comment.
Please also add a README.md to shortly describe what the test does and what output to expect in case of either success or failure.
| USEMODULE += shell | ||
| USEMODULE += shell_commands | ||
| USEMODULE += ps | ||
| USEMODULE += xtimer |
There was a problem hiding this comment.
only xtimer is needed for your test, the 3 modules above can safely be removed.
| @@ -0,0 +1,25 @@ | |||
| # name of your application | |||
| APPLICATION = Scheduling-Test | |||
There was a problem hiding this comment.
this should be the same as the directory name -> thread_priority_inversion
| { | ||
| /* starting working loop immediately */ | ||
| while(1){ | ||
| printf("t_low: allocating resource...\n"); |
There was a problem hiding this comment.
replace printf withputs here and below. puts can output static strings only, but is less expensive than printf.
There was a problem hiding this comment.
IIRC GCC should replace printf by puts automatically when optimizing if the string is static and ends in a newline.
|
requested changes done. |
smlng
left a comment
There was a problem hiding this comment.
sorry for leaving my review unattended for such a long time. However, please revise coding style, you seem to use tabs (size 8) instead of spaces with indention 4 spaces per level. Please also review coding style in the Wiki
|
|
||
| This application uses three threads for demonstrating the | ||
| priority inversion problem. In theory, the highest priority thread (**t_high**) | ||
| should periodically and produce some output: |
There was a problem hiding this comment.
missing word? ... should [be scheduled] periodically ...
| ``` | ||
| During this phase of 1s, **t_high** lockes the mutex **res_mtx** which | ||
| represents a shared ressource. After unlocking the mutex, **t_high** waits 1s | ||
| before restaring tis cycle again. |
| before restaring tis cycle again. | ||
|
|
||
| A low priority thread **t_low** is doing the same. Since both threads sharing | ||
| the same resource **res_mtx**, they have to wait for wach other until the mutex |
|
|
||
| After 3s, a third thread with medium priority (**t_mid**) is started. This | ||
| thread does not touch **res_mtx**, but it runs an infinite loop without leaving | ||
| come CPU time to lower priority tasks. This prevents **t_low** from freeing the |
| void *t_low_handler(void *arg) | ||
| { | ||
| /* starting working loop immediately */ | ||
| while(1){ |
| void *t_mid_handler(void *arg) | ||
| { | ||
| /* starting working loop after 3s */ | ||
| xtimer_sleep(3); |
|
also consider squashing |
fdd7084 to
1deb82b
Compare
|
requested changes done... |
|
Looks better now, however Murdock isn't happy - some minor issues with unused variables (add |
84f6813 to
0f43ccd
Compare
|
unused variables and makefile issues fixed... |
|
we are nearly there, you need to add the following directive to the Makefile of your test that should fix last problem! |
0f43ccd to
9621eb3
Compare
|
done. |
smlng
left a comment
There was a problem hiding this comment.
on a second review round I found some minor issues.
| (void) arg; | ||
|
|
||
| /* starting working loop immediately */ | ||
| while(1){ |
There was a problem hiding this comment.
coding style here and 2x below: add missing spaces around parentheses, should be while(1) {
| xtimer_sleep(3); | ||
|
|
||
| puts("t_mid: doing some stupid stuff..."); | ||
| while(1){ |
|
|
||
| /* starting working loop after 500 ms */ | ||
| xtimer_usleep(500); | ||
| while(1){ |
| (void) arg; | ||
|
|
||
| /* starting working loop after 500 ms */ | ||
| xtimer_usleep(500); |
There was a problem hiding this comment.
this actually only 500 microseconds, if you want milliseconds change to: 500U * US_PER_MS
|
|
||
| mutex_t res_mtx; | ||
|
|
||
| char stack_high[THREAD_STACKSIZE_MAIN]; |
There was a problem hiding this comment.
IMHO THREAD_STACKSIZE_DEFAULT will be sufficient, too and will lower required memory considerably.
9621eb3 to
bbbdb9f
Compare
|
changes done; compiles now for the nucleo32-f042 too (but still not for the nucleo32-f031) |
|
tested on macOS and PhyNode works (or actually for now: fails) as expected 😉 |
|
ACK & GO |
|
ah damn, @geith can you reword you commit message? We typically have the module name first, i.e., |
|
otherwise we are clear to merge here ... |
bbbdb9f to
1ebecc7
Compare
|
done ;-) |
added simple test program for priority inversion problem as discussed in #7365