Skip to content

ps: fix schedstatistics#6975

Merged
smlng merged 3 commits intoRIOT-OS:masterfrom
OTAkeys:pr/ps_schedstatistics_fix
May 17, 2017
Merged

ps: fix schedstatistics#6975
smlng merged 3 commits intoRIOT-OS:masterfrom
OTAkeys:pr/ps_schedstatistics_fix

Conversation

@vincent-d
Copy link
Copy Markdown
Member

Fix xtimer_now() usage and fix columns alignment in ps command when
module schedstatistics is used.

Copy link
Copy Markdown
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

Why is runtime_ticks a double in the first place?

@PeterKietzmann PeterKietzmann added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Apr 27, 2017
@PeterKietzmann
Copy link
Copy Markdown
Member

How did you verify it's working and which platform did you use?

@vincent-d
Copy link
Copy Markdown
Member Author

I tested on cortex-m3 (stm32f2). I assumed it worked before. It must be a leftover of the recent xtimer works.

#endif
#ifdef MODULE_SCHEDSTATISTICS
double runtime_ticks = sched_pidlist[i].runtime_ticks / (double) xtimer_now() * 100;
double runtime_ticks = sched_pidlist[i].runtime_ticks /
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.

It seems like this only works for the first 2**32 ticks after boot, right? (Now that we're looking at it. :) )

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.

And ... can we get change this to use uint64_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will look into it

@vincent-d
Copy link
Copy Markdown
Member Author

vincent-d commented May 3, 2017

  • converted ps runtime_ticks to float
  • used _xtimer_now64() instead of xtimer_now()
  • used unsigned long long for ticks counting variables
  • fixed examples/default Makefile

* Scheduler statistics
*/
typedef struct {
unsigned int laststart; /**< Time stamp of the last time this thread was
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.

uint64_t would be more semantically correct since _xtimer_now64 returns an uint64_t

core/sched.c Outdated

#ifdef MODULE_SCHEDSTATISTICS
unsigned long time = _xtimer_now();
unsigned long long time = _xtimer_now64();
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.

a better name for this variable would be now or something. time() is a POSIX standard function in time.h so it's better to avoid that name for clarity.

@vincent-d
Copy link
Copy Markdown
Member Author

  • addressed @gebart comments
  • add a test app to ensure this code is compiled by Murdock

@smlng
Copy link
Copy Markdown
Member

smlng commented May 15, 2017

@vincent-d I think you address[ed] all comments, please rebase and squash accordingly; and we give Murdock a try 😉

@vincent-d vincent-d force-pushed the pr/ps_schedstatistics_fix branch from 29a1daa to b43ef8a Compare May 15, 2017 14:23
@vincent-d
Copy link
Copy Markdown
Member Author

squashed

@vincent-d vincent-d added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 15, 2017
@vincent-d
Copy link
Copy Markdown
Member Author

Why is runtime_ticks a double in the first place?

I think I understand now! printf wants a double when using %f. So either we cast or we use a double.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 15, 2017

or we don't use float nor double, see my follow up PR #7048. Your PR here already does a lot: use uint64_t and xtimer_now64 and adds a tests!

@vincent-d
Copy link
Copy Markdown
Member Author

@smlng I agree, but Murdock complains. I propose to move runtime_ticks back to double and finish the job in #7048.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 16, 2017

that's exactly what I meant: revert to double and refine that using #7048

Vincent Dupont added 3 commits May 16, 2017 10:33
Fix xtimer_now() usage and fix columns alignment in ps command when
module schedstatistics is used.
@vincent-d vincent-d force-pushed the pr/ps_schedstatistics_fix branch from b43ef8a to cfe5eac Compare May 16, 2017 08:33
@vincent-d
Copy link
Copy Markdown
Member Author

Fixed and squashed directly

@kaspar030 kaspar030 added the Area: core Area: RIOT kernel. Handle PRs marked with this with care! label May 16, 2017
@vincent-d
Copy link
Copy Markdown
Member Author

@smlng do you want to re-ACK ? Otherwise I think we can go.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 17, 2017

as @kaspar030 did not object, ACK and GO

@smlng smlng merged commit dd4f8f7 into RIOT-OS:master May 17, 2017
@kaspar030
Copy link
Copy Markdown
Contributor

Did you just merge 64bit calculations into the scheduler?! I thought adding the "core" flag would lead to more thorough review.

@kaspar030
Copy link
Copy Markdown
Contributor

Context switch performance goes down from 26k/sec to 18k/sec with this PR, with enabled schecstatistics...

#include <stdio.h>
#include <inttypes.h>

#include <shell.h>
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.

For future reference: internal includes are marked with #include "header.h" instead of #include <header.h>

@kaspar030
Copy link
Copy Markdown
Contributor

Context switch performance goes down from 26k/sec to 18k/sec with this PR

So guys, what do we do about it. Ignore it, revert, fix?

@smlng
Copy link
Copy Markdown
Member

smlng commented May 18, 2017

@kaspar030 please share your performance test application. And clarify what did you compare:

  • without and with MODULE_SCHEDSTATISTICS of this PR
  • or using MODULE_SCHEDSTATISTICS before (32Bit) or with this PR (64Bit)

@kaspar030
Copy link
Copy Markdown
Contributor

I used this: https://github.com/kaspar030/RIOT/tree/add_bench_msg/tests/bench_msg

The test sends messages in a loop from the main thread to a second thread, which just receives them in a loop. After one second, it stops and outputs how many messages could be sent.

I compared the results of master afgter merging this PR without MODULE_SCHEDSTATISTICS, then the module added to USEMODULE, then again with the module, but 6d5b955 reverted, all on samr21-xpro.

The results (Test complete. n=...) were ~42k, ~18k and ~26k.

(The benchmark result is very unstable on native, probably due to CPUs slowly scaling up. So to get meaningful results, run it on real hardware.)

@vincent-d
Copy link
Copy Markdown
Member Author

The module was broken, anyway.

We can go back to 32bits knowing that it would work only for the first 32bits ticks. This is a reasonable limitation I guess.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 18, 2017

I can confirm @kaspar030 findings that switching performance drops from 60% to 40% using schedstatistics with 64Bit instead of 32Bit compared to performance without stats. Besides other issue with the module, we already that know gathering stats will influence overall performance. Question remains: how to proceed, and is another drop that severe? What about impact of xtimer performance on this one - which can be improved as well as, see #7053?

Btw. I get a hardfault on pba-d-01-kw2x when using the stats module, regardless of the changes in this PR - even reverting them completely doesn't help.

@kaspar030
Copy link
Copy Markdown
Contributor

What about impact of xtimer performance on this one - which can be improved as well as, see #7053?

Good point, but only matters if xtimer is run with a timer on a different clock domain than the default.

@kaspar030
Copy link
Copy Markdown
Contributor

kaspar030 commented May 18, 2017

We can go back to 32bits knowing that it would work only for the first 32bits ticks. This is a reasonable limitation I guess.

Would it be possible to count using a 32bit variable on context switch, but record any overflows?
e.g.,

tmp = _tick_count;
stats->_tick_count += now-laststart;
if (_tick_count < tmp) stats->overflows++;

... and handle the 64bit math on printing?
That way we'd move the reasonable limitation to "if a thread runs for more than 71 minutes without context switch or interrupt, output is incorrect".

edit All variables being 32bit.

@smlng
Copy link
Copy Markdown
Member

smlng commented May 18, 2017

can't we use _xtimer_now_internal which gives the overflows, instead of keep track of them here again?

@cgundogan
Copy link
Copy Markdown
Member

can't we use _xtimer_now_internal which gives the overflows, instead of keep track of them here again?

wouldn't you need overflow detection per thread? I am not sure how to map from one value (_xtimer_now_internal) onto the runtime of several threads..

@smlng
Copy link
Copy Markdown
Member

smlng commented May 18, 2017

ah, right (in a way) - we may need to combine _xtimer_now_internal usage with @kaspar030 proposal, because for the latter: consecutive overflows would be missed, or not?

smlng added a commit to smlng/RIOT that referenced this pull request Jun 1, 2017
smlng added a commit to smlng/RIOT that referenced this pull request Jun 1, 2017
smlng added a commit to smlng/RIOT that referenced this pull request Jun 8, 2017
@aabadie aabadie modified the milestone: Release 2017.07 Jun 30, 2017
bergzand pushed a commit to bergzand/RIOT that referenced this pull request Sep 29, 2017
roberthartung pushed a commit to roberthartung/RIOT that referenced this pull request Oct 20, 2017
roberthartung pushed a commit to roberthartung/RIOT that referenced this pull request Oct 20, 2017
@toonst toonst deleted the pr/ps_schedstatistics_fix branch August 21, 2018 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants