Skip to content

Commit

Permalink
[dbus] Try to avoid reporting negative suspend time. Fixes JB#44904
Browse files Browse the repository at this point in the history
If device does not suspend at all, querying suspend stats from mce
can yield (small, but) negative suspend time - which is confusing.

Suspend time is calculated by subtracting active time from uptime.

Get subtrahend before minuend - so that if the time values should
increase in between timer reads, the error is to positive direction.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 25, 2019
1 parent 5897ad0 commit 42f84d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mce-dbus.c
Expand Up @@ -2671,9 +2671,12 @@ static gboolean suspend_stats_get_dbus_cb(DBusMessage *const req)
mce_log(LL_DEVEL, "suspend info request from %s",
mce_dbus_get_message_sender_ident(req));

/* get stats */
/* Get time values - in an order that is less
* likely to produce negative values on subtract.
*/
dbus_int64_t active_ms = mce_lib_get_mono_tick();
dbus_int64_t uptime_ms = mce_lib_get_boot_tick();
dbus_int64_t suspend_ms = uptime_ms - mce_lib_get_mono_tick();
dbus_int64_t suspend_ms = uptime_ms - active_ms;

/* create and send reply message */
rsp = dbus_new_method_reply(req);
Expand Down

0 comments on commit 42f84d0

Please sign in to comment.