Skip to content

Commit

Permalink
[iphb] Make RTC power on reliable. Contributes to JB#50354
Browse files Browse the repository at this point in the history
Currently iphb module uses plain RTC writes combined
with one of time APIs without much consideration.

Queued timers have quite big chance of overwriting
RTC value as well as vice versa. Especially this plays
bad with power on timer which is set upon DSME shutdown
which should power on the device. When it is overwritten
by suspend timer we have all kinds of bad luck.

This patch:
- Prevents using RTC writes for suspend timers when one of timer
queue APIs are available.
- Makes sure to close all timer queue APIs file descriptors to
flush the state before shutdown timer write.

Signed-off-by: Sergey Lapin <s.lapin@omprussia.ru>
  • Loading branch information
slapin committed Jun 29, 2020
1 parent 8f0b8a7 commit c953445
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions modules/iphb.c
Expand Up @@ -1441,9 +1441,9 @@ static bool rtc_set_alarm_after(time_t delay)
android_alarm_clear();
linux_alarm_clear();
}

if( !rtc_set_alarm_tm(&tm, enabled) )
goto cleanup;
if (linux_alarm_timerfd == -1 && android_alarm_fd == -1)
if( !rtc_set_alarm_tm(&tm, enabled) )
goto cleanup;

result = true;

Expand All @@ -1461,6 +1461,7 @@ static void rtc_set_alarm_powerup(void)
{
time_t sys = time(0);
time_t rtc = alarm_powerup;
struct tm tm;

/* how far in the future the next poweup alarm is */
if( rtc > sys )
Expand All @@ -1484,7 +1485,10 @@ static void rtc_set_alarm_powerup(void)
/* always log the state we leave rtc wakeup on dsme exit */
log_time_t(LOG_WARNING, PFIX"powerup via RTC", rtc ? sys+rtc : 0, sys);

rtc_set_alarm_after(rtc);
if( rtc_get_time_tm(&tm) != (time_t)-1 ) {
tm.tm_sec += rtc;
rtc_set_alarm_tm(&tm, (rtc == 0) ? false: true);
}
}

/** Flag for: update system time on rtc interrupt */
Expand Down Expand Up @@ -3372,13 +3376,13 @@ void module_fini(void)
/* stop timerfd alarm */
linux_alarm_quit();

/* close android alarm device */
android_alarm_quit();

/* set wakeup alarm before closing the rtc */
rtc_set_alarm_powerup();
rtc_detach();

/* close android alarm device */
android_alarm_quit();

/* cleanup rest of what is in the epoll set */
listenfd_quit();
kernelfd_close();
Expand Down

0 comments on commit c953445

Please sign in to comment.