Skip to content

Commit

Permalink
[inactivity] Use heartbeat timer to enter inactive state. Contributes…
Browse files Browse the repository at this point in the history
… to JB#31927

Normal timers are used for switching from active to inactive state. If
device suspends before that takes place before the timer gets triggered,
the device can stay in active state much longer than expected.

Use iphb based heartbeat timer to make sure the activity state change
takes place even if the device happens to suspend.

Note: The mce hbtimers use heartbeat wide ranged wakeup - which means
that the activity state change can happen up to 12 seconds later than
expected if the device actually suspends.
  • Loading branch information
spiiroin committed Sep 2, 2015
1 parent b2f2416 commit 5d8ac67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -631,6 +631,7 @@ modules/inactivity.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-hbtimer.h\
mce-log.h\
mce.h\

Expand All @@ -639,6 +640,7 @@ modules/inactivity.pic.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-hbtimer.h\
mce-log.h\
mce.h\

Expand Down
42 changes: 33 additions & 9 deletions modules/inactivity.c
Expand Up @@ -24,6 +24,7 @@
#include "../mce.h"
#include "../mce-log.h"
#include "../mce-dbus.h"
#include "../mce-hbtimer.h"

#include <string.h>

Expand Down Expand Up @@ -142,6 +143,9 @@ static gboolean mia_timer_cb (gpointer data);
static void mia_timer_start (void);
static void mia_timer_stop (void);

static void mia_timer_init (void);
static void mia_timer_quit (void);

/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
* ------------------------------------------------------------------------- */
Expand All @@ -159,8 +163,8 @@ static GSList *activity_action_list = NULL;
/** List of monitored activity requesters */
static GSList *activity_action_owners = NULL;

/** ID for inactivity timeout source */
static guint inactivity_timeout_id = 0;
/** Heartbeat timer for inactivity timeout */
static mce_hbtimer_t *inactivity_timer_hnd = 0;

/** Cached device inactivity state
*
Expand Down Expand Up @@ -1028,7 +1032,6 @@ static gboolean mia_timer_cb(gpointer data)
(void)data;

mce_log(LL_DEBUG, "inactivity timeout triggered");
inactivity_timeout_id = 0;

mia_generate_inactivity();

Expand All @@ -1045,8 +1048,9 @@ static void mia_timer_start(void)
goto EXIT;

mce_log(LL_DEBUG, "inactivity timeout in %d seconds", inactivity_timeout);
inactivity_timeout_id = g_timeout_add_seconds(inactivity_timeout,
mia_timer_cb, 0);
mce_hbtimer_set_period(inactivity_timer_hnd, inactivity_timeout * 1000);
mce_hbtimer_start(inactivity_timer_hnd);

EXIT:
return;
}
Expand All @@ -1055,13 +1059,31 @@ static void mia_timer_start(void)
*/
static void mia_timer_stop(void)
{
if( inactivity_timeout_id ) {
if( mce_hbtimer_is_active(inactivity_timer_hnd) ) {
mce_log(LL_DEBUG, "inactivity timeout canceled");
g_source_remove(inactivity_timeout_id),
inactivity_timeout_id = 0;
mce_hbtimer_stop(inactivity_timer_hnd);
}
}

/** Initialize inactivity heartbeat timer
*/
static void
mia_timer_init(void)
{
inactivity_timer_hnd = mce_hbtimer_create("inactivity-timer",
inactivity_timeout * 1000,
mia_timer_cb, 0);
}

/** Cleanup inactivity heartbeat timer
*/
static void
mia_timer_quit(void)
{
mce_hbtimer_delete(inactivity_timer_hnd),
inactivity_timer_hnd = 0;
}

/* ========================================================================= *
* MODULE_LOAD_UNLOAD
* ========================================================================= */
Expand All @@ -1076,6 +1098,8 @@ const gchar *g_module_check_init(GModule *module)
{
(void)module;

mia_timer_init();

/* Append triggers/filters to datapipes */
mia_datapipe_init();

Expand Down Expand Up @@ -1108,7 +1132,7 @@ void g_module_unload(GModule *module)
mia_datapipe_quit();

/* Do not leave any timers active */
mia_timer_stop();
mia_timer_quit();

/* Flush activity actions */
mia_activity_action_remove_all();
Expand Down

0 comments on commit 5d8ac67

Please sign in to comment.