moused(8) consuming cpu for nothing

Dan Nelson dnelson at allantgroup.com
Wed Aug 8 12:59:37 PDT 2007


In the last episode (Aug 08), Oliver Fromme said:
> I noticed that the moused(8) process had accumulated about one minute
> of CPU time, after only three days of uptime. That's really a lot,
> given the fact that this server doesn't have a mouse connected at
> all.  :-) Well, it is connected to a KVM switch, but it was never
> used since the last reboot.  Accoding to "vmstat -i" psm0 received
> zero interrupts.  So I really wonder why it has consumed that much
> CPU time.
> 
> So I tried to strace the process, and got an endless series
> of these:
> 
> 15:22:31.122276 gettimeofday({...}, NULL) = 0
> 15:22:31.122388 select(1024, [?], NULL, NULL, {...}) = 0 (Timeout)
> 15:22:31.143275 gettimeofday({...}, NULL) = 0
> 15:22:31.143386 select(1024, [?], NULL, NULL, {...}) = 0 (Timeout)
> 15:22:31.164276 gettimeofday({...}, NULL) = 0
> 15:22:31.164388 select(1024, [?], NULL, NULL, {...}) = 0 (Timeout)
> 15:22:31.185276 gettimeofday({...}, NULL) = 0
> 15:22:31.185387 select(1024, [?], NULL, NULL, {...}) = 0 (Timeout)
> .. and so on.
> 
> So it seems to call select(2) with a 0.02s timeout and
> then gettimeofday(2) within a loop.  50 times per second.
> Without doing anything useful (remember there's no mouse
> device connected and zero interrupts occuring).

Moused only selects with a timeout when you have 3-button emulation
enabled, so try disabling that.  One possible optimization to moused
would be to only use the timeout if the current button state requires
one (i.e. only if button1 or button3 is pressed, or the virtual button3
is pressed).

BTW - running with /usr/bin/truss instead of strace would have let you see
the timeout directly without having to subtract timestamps:

select(1024,{3},0x0,0x0,{0.020000})              = 0 (0x0)
gettimeofday({1186587244.432606},0x0)            = 0 (0x0)
select(1024,{3},0x0,0x0,{0.020000})              = 0 (0x0)
gettimeofday({1186587244.457868},0x0)            = 0 (0x0)


-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-stable mailing list