Limit the number for ioctl()s per second to about 125 for mouse transfers. This

fixes the high CPU usage when using USB mice. I experimented with transfers
scheduled at fixed intervals, and with using a fixed pause between transfers.
The fixed pauses, though much less sophisticated, give the smoothest drawing
in WonderBrush. ;-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29413 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-03-06 11:11:58 +00:00
parent 58336b68a9
commit 7d1d70339a
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2007, Haiku.
* Copyright 2004-2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -373,8 +373,21 @@ MouseDevice::_ControlThread()
float historyDeltaX = 0.0;
float historyDeltaY = 0.0;
static const bigtime_t kTransferDelay = 1000000 / 125;
// 125 transfers per second should be more than enough
#define USE_REGULAR_INTERVAL 0
#if USE_REGULAR_INTERVAL
bigtime_t nextTransferTime = system_time() + kTransferDelay;
#endif
while (fActive) {
mouse_movement movements;
#if USE_REGULAR_INTERVAL
snooze_until(nextTransferTime, B_SYSTEM_TIMEBASE);
nextTransferTime += kTransferDelay;
#endif
if (ioctl(fDevice, MS_READ, &movements) != B_OK) {
_ControlThreadCleanup();
// TOAST!
@@ -450,6 +463,10 @@ MouseDevice::_ControlThread()
else
delete message;
}
#if !USE_REGULAR_INTERVAL
snooze(kTransferDelay);
#endif
}
}