Skip to content

added test program for priority inversion problem#7372

Merged
smlng merged 1 commit intoRIOT-OS:masterfrom
dailab:priority_inversion
Dec 21, 2017
Merged

added test program for priority inversion problem#7372
smlng merged 1 commit intoRIOT-OS:masterfrom
dailab:priority_inversion

Conversation

@geith
Copy link
Copy Markdown
Contributor

@geith geith commented Jul 17, 2017

added simple test program for priority inversion problem as discussed in #7365

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should be the same as the directory name -> thread_priority_inversion

{
/* starting working loop immediately */
while(1){
printf("t_low: allocating resource...\n");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

replace printf withputs here and below. puts can output static strings only, but is less expensive than printf.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IIRC GCC should replace printf by puts automatically when optimizing if the string is static and ends in a newline.

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: tests Area: tests and testing framework labels Jul 17, 2017
@smlng smlng added this to the Release 2017.10 milestone Jul 17, 2017
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Jul 17, 2017

requested changes done.

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: /tis/its/

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: /wach/each/


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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: /come/some/

void *t_low_handler(void *arg)
{
/* starting working loop immediately */
while(1){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

indention seems off

void *t_mid_handler(void *arg)
{
/* starting working loop after 3s */
xtimer_sleep(3);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

indention seem off

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 6, 2017
@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 6, 2017

also consider squashing

@geith geith force-pushed the priority_inversion branch 2 times, most recently from fdd7084 to 1deb82b Compare December 7, 2017 15:21
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Dec 7, 2017

requested changes done...

@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 7, 2017

Looks better now, however Murdock isn't happy - some minor issues with unused variables (add (void)arg; for instance) and a whitespace error in Makefile. Please fix, Pre-ACK.

@geith geith force-pushed the priority_inversion branch 2 times, most recently from 84f6813 to 0f43ccd Compare December 11, 2017 13:28
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Dec 11, 2017

unused variables and makefile issues fixed...

@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 11, 2017

we are nearly there, you need to add the following directive to the Makefile of your test

BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 nucleo32-f042

that should fix last problem!

@geith geith force-pushed the priority_inversion branch from 0f43ccd to 9621eb3 Compare December 12, 2017 12:25
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Dec 12, 2017

done.

Copy link
Copy Markdown
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

on a second review round I found some minor issues.

(void) arg;

/* starting working loop immediately */
while(1){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

here


/* starting working loop after 500 ms */
xtimer_usleep(500);
while(1){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

abd here, too

(void) arg;

/* starting working loop after 500 ms */
xtimer_usleep(500);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMHO THREAD_STACKSIZE_DEFAULT will be sufficient, too and will lower required memory considerably.

@geith geith force-pushed the priority_inversion branch from 9621eb3 to bbbdb9f Compare December 15, 2017 14:25
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Dec 15, 2017

changes done; compiles now for the nucleo32-f042 too (but still not for the nucleo32-f031)

@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 18, 2017

tested on macOS and PhyNode works (or actually for now: fails) as expected 😉

@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 21, 2017
@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 21, 2017

ACK & GO

@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 21, 2017

ah damn, @geith can you reword you commit message? We typically have the module name first, i.e., tests: add program for priority inversion problem would fit here.

@smlng
Copy link
Copy Markdown
Member

smlng commented Dec 21, 2017

otherwise we are clear to merge here ...

@geith geith force-pushed the priority_inversion branch from bbbdb9f to 1ebecc7 Compare December 21, 2017 10:51
@geith
Copy link
Copy Markdown
Contributor Author

geith commented Dec 21, 2017

done ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants