Thread 'User activity detection on Linux'

Message boards : BOINC Manager : User activity detection on Linux
Message board moderation

To post messages, you must log in.

AuthorMessage
Anonyymi

Send message
Joined: 20 Dec 05
Posts: 5
Finland
Message 27860 - Posted: 10 Oct 2009, 12:11:44 UTC

I noticed that BOINC is not able to detect user input on Linux http://boinc.berkeley.edu/trac/ticket/463. I need mouse event detection and interpretation too and I have noticed that whether /dev/input/events work depends on which mouse/usbhid/evdev drivers are loaded. I guess some drivers just do not use the /dev/input/event interface. The /dev/input/events used to work on my laptop and Vojtech Pavlik's evtest worked. But afterwards I have changed the software configuration (upgraded distribution, probably X and Linux). Now I am using Ubuntu's Linux 2.6.27-11-generic and BOINC 6.2.12 i686-pc-linux-gnu. As expected, BOINC does not detect USB mouse activity.

Gnome's Tracker indexing and search tool uses X to detect mouse events and to stop indexing when user activity is detected. Perhaps BOINC could also use X until this shortcoming is fixed in Linux? I made (or actually copied it from somewhere and modified a bit) this little program which waits for mouse events and exits when 50 movements (MotionNotify) have been detected:

#include <stdio.h>
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xutil.h>
#include <X11/Shell.h>


Display *d;

void snoop_all_windows(Window root, unsigned long type)
{

  static int level = 0;
  Window parent, *children, *child2;
  unsigned int nchildren;
  int stat, i,j,k;

  level++;

  stat = XQueryTree(d, root, &root, &parent, &children, &nchildren);
  if (stat == FALSE)
   {
     fprintf(stderr, "Can't query window tree...\n");
     return;
   }

  if (nchildren == 0)
  
    return;

  XSelectInput(d, root, type);

  for(i=0; i < nchildren; i++)
   {
     XSelectInput(d, children[i], type);
     snoop_all_windows(children[i], type);
   }

  XFree((char *)children);
}


int main(int argc, char **argv)
{
  //daemon(0,0);
  //sleep(10);

  char *hostname;
  char *string;
  XEvent xev;
  int count = 0;

  if (argv[1] == NULL)
    hostname = ":0";
  else
    hostname = argv[1];

  d = XOpenDisplay(hostname);
  if (d == NULL)
   {
     fprintf(stderr, "Blah, can't open display: %s\n", hostname);
     exit(10);
   }

  snoop_all_windows(DefaultRootWindow(d), PointerMotionMask);

  while(1)
    {
      int k;
      k = 1;
      while (k<50) {
	XNextEvent(d, &xev);
	k++;
	}
      

      switch (xev.type) {
	
      case MotionNotify:
	return;
	
      }

   }
}


/proc/interrupts cannot be used to detect USB mouse activity because it sums all USB interrupts. Here is my /proc/interrupts sampled at 1 second interval while not moving the mouse or typing:
           CPU0       CPU1       
  0:   13250755    7627303   IO-APIC-edge      timer
  1:      73286       6555   IO-APIC-edge      i8042
  8:         72         65   IO-APIC-edge      rtc0
  9:      19177       1334   IO-APIC-fasteoi   acpi
 12:      16868       4253   IO-APIC-edge      i8042
 14:      92427      12625   IO-APIC-edge      ata_piix
 15:          0          0   IO-APIC-edge      ata_piix
 16:   32063753    1108943   IO-APIC-fasteoi   uhci_hcd:usb1, HDA Intel, fglrx[0]@PCI:1:0:0
 17:          0          0   IO-APIC-fasteoi   uhci_hcd:usb2
 18:          0          0   IO-APIC-fasteoi   ehci_hcd:usb3, uhci_hcd:usb6
 20:  127813539    7708352   IO-APIC-fasteoi   uhci_hcd:usb4, ehci_hcd:usb7
 21:   24865509     278023   IO-APIC-fasteoi   uhci_hcd:usb5
219:    7669594     117154   PCI-MSI-edge      ahci
NMI:          0          0   Non-maskable interrupts
LOC:  293717402  249457069   Local timer interrupts
RES:    3507848    5451895   Rescheduling interrupts
CAL:      13948      16305   function call interrupts
TLB:      60245     133669   TLB shootdowns
SPU:          0          0   Spurious interrupts
ERR:          2
MIS:          0
           CPU0       CPU1       
  0:   13250755    7627303   IO-APIC-edge      timer
  1:      73290       6555   IO-APIC-edge      i8042
  8:         72         65   IO-APIC-edge      rtc0
  9:      19177       1334   IO-APIC-fasteoi   acpi
 12:      16868       4253   IO-APIC-edge      i8042
 14:      92427      12625   IO-APIC-edge      ata_piix
 15:          0          0   IO-APIC-edge      ata_piix
 16:   32063861    1108943   IO-APIC-fasteoi   uhci_hcd:usb1, HDA Intel, fglrx[0]@PCI:1:0:0
 17:          0          0   IO-APIC-fasteoi   uhci_hcd:usb2
 18:          0          0   IO-APIC-fasteoi   ehci_hcd:usb3, uhci_hcd:usb6
 20:  127813564    7708352   IO-APIC-fasteoi   uhci_hcd:usb4, ehci_hcd:usb7
 21:   24865866     278023   IO-APIC-fasteoi   uhci_hcd:usb5
219:    7669625     117154   PCI-MSI-edge      ahci
NMI:          0          0   Non-maskable interrupts
LOC:  293717980  249457392   Local timer interrupts
RES:    3507850    5451898   Rescheduling interrupts
CAL:      13948      16305   function call interrupts
TLB:      60245     133669   TLB shootdowns
SPU:          0          0   Spurious interrupts
ERR:          2
MIS:          0



Perhaps this message about putting an activity counter into Linux is also of interest.

The Windows version of BOINC uses the GetLastInputInfo API which is not system-wide but apparently BOINC tries to make it system-wide with some kind of shared file/memory and DLL. Perhaps this could be ported to X?
ID: 27860 · Report as offensive
ProfileJord
Volunteer tester
Help desk expert
Avatar

Send message
Joined: 29 Aug 05
Posts: 15563
Netherlands
Message 27862 - Posted: 10 Oct 2009, 13:48:52 UTC - in response to Message 27860.  

Now I am using Ubuntu's Linux 2.6.27-11-generic and BOINC 6.2.12 i686-pc-linux-gnu.

Can you please test if it still doesn't work with Boinc 6.10.13? It's easy to say it doesn't work on a version that's over a year old, but that doesn't mean it may not have been fixed in the mean time (and the ticket be forgotten to close).
ID: 27862 · Report as offensive
Anonyymi

Send message
Joined: 20 Dec 05
Posts: 5
Finland
Message 27867 - Posted: 10 Oct 2009, 21:35:02 UTC - in response to Message 27862.  

Can you please test if it still doesn't work with Boinc 6.10.13? It's easy to say it doesn't work on a version that's over a year old, but that doesn't mean it may not have been fixed in the mean time (and the ticket be forgotten to close).

I assumed that it wouldn't work because the trunk still has the algorithm that relies on /proc/interrupt. The function is here: http://boinc.berkeley.edu/trac/browser/trunk/boinc/client/hostinfo_unix.cpp#L1330. But to be absolutely sure I tested version 6.10.13 i686-pc-linux-gnu and it behaves like the old version 6.2.12: detects keyboard but not USB mouse.
ID: 27867 · Report as offensive
ProfileJord
Volunteer tester
Help desk expert
Avatar

Send message
Joined: 29 Aug 05
Posts: 15563
Netherlands
Message 27869 - Posted: 10 Oct 2009, 21:39:15 UTC - in response to Message 27867.  

Ok, with thanks on that. I have forwarded this thread to the developers.
ID: 27869 · Report as offensive
ProfileJord
Volunteer tester
Help desk expert
Avatar

Send message
Joined: 29 Aug 05
Posts: 15563
Netherlands
Message 27941 - Posted: 12 Oct 2009, 20:43:03 UTC - in response to Message 27869.  

The developers are adding code to the Linux client now to detect mouse movements. It is a work in progress, but there is a good chance this code will be available in the next BOINC 6.10 release candidate.
ID: 27941 · Report as offensive

Message boards : BOINC Manager : User activity detection on Linux

Copyright © 2024 University of California.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.