_st_epoll_dispatch firing too often
CN <[email protected]> Sun, 2 Dec 2012 17:48:01 -0800 (PST)
| Newsgroups | gmane.comp.lib.state-threads.user |
|---|---|
| Message-ID | <[email protected]> |
_st_epoll_dispatch seems to fire too often when the sleepq is not empty.=A0
My guess is that it has something to do with granularity.
Here's some basic code to reproduce:
#include <stdio.h>
#include "st.h"
int main(int argc, char *argv[])
{
=A0 =A0 st_utime_t t1, t2;
=A0 =A0 st_set_eventsys(ST_EVENTSYS_ALT);
=A0 =A0 st_init();
=A0 =A0 for (;;) {
=A0 =A0 =A0 =A0 t1 =3D st_utime();
=A0 =A0 =A0 =A0=A0st_sleep(1);
=A0 =A0 =A0 =A0=A0t2 =3D st_utime();
=A0 =A0 =A0 =A0=A0fprintf(stderr, "%p MAIN diff =3D %llu\n", st_thread_self=
(), t2 - t1);
=A0 =A0 }
=A0 =A0 return 0;
}
And add some logging to event.c @ line 1244.
ie.
1243: =A0timeout =3D (int) (min_timeout / 1000);
1244: =A0if (timeout =3D=3D 0 && _ST_SLEEPQ->due > _ST_LAST_CLOCK)
1245: =A0 =A0 =A0fprintf(stderr, "%p ST =A0 diff=3D%llu\n", _ST_SLEEPQ, _ST=
_SLEEPQ->due - _ST_LAST_CLOCK);
1245: }
You'll also need "#include <stdio.h>" .
If you run the test, you'll see something like:
0x805f068 MAIN diff =3D 999992
0x805f068 ST =A0 diff=3D241
0x805f068 ST =A0 diff=3D222
0x805f068 ST =A0 diff=3D210
0x805f068 ST =A0 diff=3D199
0x805f068 ST =A0 diff=3D188
0x805f068 ST =A0 diff=3D177
0x805f068 ST =A0 diff=3D166
0x805f068 ST =A0 diff=3D155
0x805f068 ST =A0 diff=3D144
0x805f068 ST =A0 diff=3D133
0x805f068 ST =A0 diff=3D122
0x805f068 ST =A0 diff=3D111
0x805f068 ST =A0 diff=3D100
0x805f068 ST =A0 diff=3D89
0x805f068 ST =A0 diff=3D78
0x805f068 ST =A0 diff=3D66
0x805f068 ST =A0 diff=3D55
0x805f068 ST =A0 diff=3D44
0x805f068 ST =A0 diff=3D33
0x805f068 ST =A0 diff=3D23
0x805f068 ST =A0 diff=3D12
0x805f068 ST =A0 diff=3D1
0x805f068 MAIN diff =3D 1000000
The unnecessary firing gets worse when the sleepq gets longer.
My "fix" for this is to put a limit on the timeout, like so:
if (_ST_SLEEPQ->due <=3D _ST_LAST_CLOCK) {
=A0 =A0 timeout =3D 0;
} else {
=A0 =A0 min_timeout =3D _ST_SLEEPQ->due - _ST_LAST_CLOCK;
=A0 =A0 if (min_timeout < 300) /* magic number 300 seems to work well */
=A0 =A0 =A0 =A0 timeout =3D 1;
=A0 =A0 else
=A0 =A0 =A0 =A0 timeout =3D (int) (min_timeout / 1000);
}
Is this a bug or am I using st-threads incorrectly?
If it's a bug, is there a better way to fix it without using magic numbers?
Regards,
C.
---------------------------------------------------------------------------=
---
Keep yourself connected to Go Parallel: =
BUILD Helping you discover the best ways to construct your parallel project=
s.
http://goparallel.sourceforge.net