On Thu, Jun 2, 2011 at 5:10 AM, Marc Lehmann <[email protected]> wrote:
> On Thu, Jun 02, 2011 at 01:55:43AM +0400, Alexey Borzenkov <[email protected]>
> wrote:
>> This patch works around the problem with some ev_timer timeout values
>> causing extreme cpu load on win32, that at the moment is observed at
>> least on WinXP virtual machine under Parallels (ev_time is ticking at
>> 64Hz in that case, compared to 2000Hz on Windows 7 physical machine).
> Thanks...
>
> Can you try whether the constants 1e-5 or 1e-6 work as fudge? That should
> be all that is required for this case, unless the win32 select is broken
> w.r.t. timeouts.
Oh, hmm, silly me, it was time to go sleep and I didn't realize a
small enough constant should work just as well. Ok, a very simple
timer that loops around 128 times:
fudge = 0:
with ev_io: prepare called 106567 times
without ev_io: prepare called 2444550 times
fudge = 1e-6:
with ev_io: prepare called 128 times
without ev_io: prepare called 1765445 times
fudge = 1e-3:
with ev_io: prepare called 128 times
without ev_io: prepare called 128 times
Which makes sense, because on Windows if there are no descriptors for
select, Sleep() API is used and it only has 1ms resolution, so for
fudge 1e-6 it becomes Sleep(0) which is equivalent to task yield on
Windows, it doesn't wait for the next timeslice, just a mere task
reschedule.
Which is also why calculating fudge the way I did is meaningless,
because if it happens to be smaller than 1e-3 it would fold into
Sleep(0), and remember that by my calculations on Windows 7 ev_time
resolution is 5e-4, so it would cause problems.
Here's the obvious patch:
diff --git a/ev_select.c b/ev_select.c
index 0ea9467..26907af 100644
--- a/ev_select.c
+++ b/ev_select.c
@@ -269,7 +269,11 @@ select_poll (EV_P_ ev_tstamp timeout)
int inline_size
select_init (EV_P_ int flags)
{
+#ifdef _WIN32
+ backend_fudge = 1e-3;
+#else
backend_fudge = 0.; /* posix says this is zero */
+#endif
backend_modify = select_modify;
backend_poll = select_poll;
Best regards,
Alexey.
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev