-
Notifications
You must be signed in to change notification settings - Fork 2
Add HaveIdleWork to avoid excessive CPU cost for spinning. #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
3568e53
b46f61a
a0c2b28
091b436
4900397
10f4ef5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,15 +98,26 @@ void CommonBase::MPISpinner() | |
|
|
||
| int MSGBUFSIZ = 1024; // Individual incoming message buffer | ||
| char * MSGBUF = new char[MSGBUFSIZ]; // Pull it off the heap | ||
|
|
||
| const int MAX_PROBE_IDLE_BACKOFF_US=100000; // Maximum is 100,000us, i.e. 10hz | ||
| int probe_idle_backoff_us=0; | ||
| for (;;) { | ||
| // See if there are any MPI packets coming down the pipe | ||
| MPI_Status status; // Note the multi-threaded MPI probe | ||
| int flag; | ||
| MPI_Iprobe(MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&flag,&status); | ||
| if (flag==0) { // Nothing there.... | ||
| OnIdle(); // Guess | ||
| if(HaveIdleWork()){ | ||
| OnIdle(); // Guess | ||
| }else{ | ||
| probe_idle_backoff_us=std::min<int>(MAX_PROBE_IDLE_BACKOFF_US, std::max<int>(10, (probe_idle_backoff_us*5)/4)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to see some documentation about this, explaning how Small note on styling - we generally try to adhere to the same style as neighbouring source when introducing modifications. In this case, lines of source in the Orchestrator source shouldn't span more than 79 characters, and we generally avoid underscores in variable names over camel case. We do have a style guide, at https://github.com/POETSII/Orchestrator/wiki/Code-Style, but I don't want to dissuade you from contributing!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't really think about the schedule, it's just exponential backoff with a slow-ish In terms of style, I generally try to match where possible, but it is a balance |
||
| OSFixes::sleep( probe_idle_backoff_us / 1000 ); | ||
| } | ||
| continue; // And try again | ||
| } | ||
|
|
||
| probe_idle_backoff_us=0; | ||
|
|
||
| int count; | ||
| MPI_Get_count(&status,MPI_CHAR,&count); | ||
| if (count > MSGBUFSIZ) { // Ensure we have the space for it | ||
|
|
@@ -142,6 +153,13 @@ void CommonBase::OnIdle() | |
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
||
| bool CommonBase::HaveIdleWork() | ||
| { | ||
| return true; // For compatibility with existing users of OnIdle | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
||
| unsigned CommonBase::OnPmap(PMsg_p * Z) | ||
| { | ||
| pPmap->Register(Z); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ virtual unsigned Decode(PMsg_p *) = 0; | |
| void Dump(unsigned = 0,FILE * = stdout); | ||
| unsigned OnExit(PMsg_p *); | ||
| virtual void OnIdle(); | ||
| virtual bool HaveIdleWork(); // Return false if there is something we want to do in OnIdle | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this comment be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, comment is flipped. I think originally I had it as NoIdleWork, then changed the sense. |
||
| unsigned OnPmap(PMsg_p *); | ||
| unsigned OnSystPingAck(PMsg_p *); | ||
| unsigned OnSystPingReq(PMsg_p *); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,17 @@ fflush(fp); | |
|
|
||
| //------------------------------------------------------------------------------ | ||
|
|
||
| bool Root::HaveIdleWork() | ||
| { | ||
| // If a scheduled exit condition is satisfied, we have work to do. | ||
| if((pCmCall->IsEmpty() and exitOnEmpty) or (appJustStopped and exitOnStop)){ | ||
| return true; | ||
| } | ||
|
|
||
| // Otherwise, simply check the queue. | ||
| return !pCmCall->IsEmpty(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| void Root::OnIdle() | ||
| { | ||
| Cli Cm = pCmCall->Front(); // Anything in the batch queue? | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just having a think about this - shouldn't the sleep period be reset if there is idle work and
OnIdle()is called? 🍠Currently, the period is incremented any time there is no idle work, but it is not reset if there is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mental model was that the OnIdle was mostly draining work that arrived in messages, so it was something like:
But if idle work can arrive from elsewhere (i.e. not from a message), then I guess that you'd
want any return from HaveIdleWork to reset the counter too.