[PATCH 9/9] Xext: Add per-device SyncCounters

Peter Hutterer peter.hutterer at who-t.net
Wed Mar 14 16:30:49 PDT 2012


On Wed, Mar 14, 2012 at 03:47:26PM +1000, Peter Hutterer wrote:
> Previously, we only had one idle alarm that was triggered for all devices,
> whenever the user used any device, came back from suspend, etc.
> 
> Add system SyncCounters for each device (named "DEVICEIDLETIME x", with x
> being the device id) that trigger on that device only. This allows for
> enabling/disabling devices based on interaction with other devices.
> 
> Popular use-case: disable the touchpad when the keyboard just above the
> touchpad stops being idle.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  Xext/sync.c        |   59 +++++++++++++++++++++++++++++++++++++++++++++++----
>  Xext/syncsrv.h     |    3 ++
>  dix/devices.c      |    8 +++++++
>  include/inputstr.h |    2 +
>  4 files changed, 67 insertions(+), 5 deletions(-)
> 
> diff --git a/Xext/sync.c b/Xext/sync.c
> index 13c9a91..99d0ce5 100644
> --- a/Xext/sync.c
> +++ b/Xext/sync.c
[...]
> @@ -2868,8 +2878,8 @@ IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less,
>      priv->value_less    = pbracket_less;
>  }
>  
> -static void
> -SyncInitIdleTime (void)
> +static SyncCounter*
> +init_system_idle_counter(const char *name, int deviceid)
>  {
>      CARD64 resolution;
>      XSyncValue idle;
> @@ -2879,12 +2889,51 @@ SyncInitIdleTime (void)
>      IdleTimeQueryValue (NULL, &idle);
>      XSyncIntToValue (&resolution, 4);
>  
> -    idle_time_counter = SyncCreateSystemCounter("IDLETIME", idle, resolution,
> +    idle_time_counter = SyncCreateSystemCounter(name, idle, resolution,
>  						XSyncCounterUnrestricted,
>  						IdleTimeQueryValue,
>  						IdleTimeBracketValues);
>  
> +    priv->deviceid = deviceid;
>      priv->value_less = priv->value_greater = NULL;
>  
>      SYSCOUNTERPRIV(idle_time_counter) = priv;
> +
> +    return idle_time_counter;
> +}
> +
> +static void
> +SyncInitIdleTime (void)
> +{
> +    init_system_idle_counter("IDLETIME", XIAllDevices);
> +}
> +
> +SyncCounter*
> +SyncInitDeviceIdleTime(DeviceIntPtr dev)
> +{
> +    char timer_name[64];
> +    sprintf(timer_name, "DEVICEIDLETIME %d", dev->id);
> +
> +    return init_system_idle_counter(timer_name, dev->id);
> +}
> +
> +void SyncRemoveDeviceIdleTime(SyncCounter *counter)
> +{
> +    int i;
> +
> +    /* Counters are removed when a device is disabled, but
> +     * on shutdown, SyncResetProc is called before devices are disabled, so
> +     * we need to check if the counter is still valid */
> +    if (SyncNumSystemCounters == 0)
> +	return;

one minor correction here: this needs to be <= 0 instead (see also the
discussion with Jamie on Patch 0/9]). On shutdown, the SyncNumSystemCounters
is set to 0 when SyncResetProc is called. After that, once the counters are
cleaned up by the resource system, the number is decreased so it ends up
with a negative value when the devices are removed, triggering the
BUG_WARN_MSG below.

Depending on whether the diff to not decrease the system counters is merged,
we need to change this to <= 0.

Cheers,
  Peter



More information about the xorg-devel mailing list