Linux Time Subsystem II: Alarm Timer

Source: Internet
Author: User
Tags posix

First, preface

Strictly speaking ALARM timer is also a POSIX timer part, contains two types of Clock_realtime_alarm and Clock_boottime_alarm. Add _alarm to Clock_realtime and Clock_boottime, respectively. A POSIX timer other than the Alarm timer stops timing after the kernel enters Cpuidle or suspend, and then shuts down the clockevent device by saving power. While the alarm timer is based on the long power of the RTC device and has the wake-up function, in the system into the suspend process, the most recent timeout expires written to the RTC device, time-out will wake the system from the suspend state, execute Timer supermarket function.

This way, during the execution of the program, there is no need to hold wakelock.

Second, Background introduction

Alarm timer can be said to work in two states, one is the same as other timer based on Hrtimer, and the other is based on the RTC device after the system enters suspend.

The RTC device is powered independently of the system, and RTC has the alarm function. After the alarm is triggered, the suspend system is awakened by an interrupt.

At Device_initcall-->alarmtimer_init, register a Alarmtimer platform_device, which is driven by Alarmtimer_driver. Insert the alarmtimer_suspend as a hook function into the system suspend process, which hooks the suspend and alarm timer functions.

Third, important data structure

struct alarm_base as the Alarmtimer clock type struct, contains Alarm_rea Ltime and alarm_boottime two kinds.

static struct Alarm_base {
Spinlock_tlock;---------------------------------Mutex access lock
struct timerqueue_headtimerqueue;-------Alarmtimer himself maintained the expires red and black tree.
struct Hrtimertimer;--------------------------add it to the hrtimer_bases corresponding red-black tree.
ktime_t (*gettime) (void);--------------------get the time function of the corresponding type clock
clockid_tbase_clockid;------------------------clock type id,clock_realtime and Clock_boottime
} Alarm_bases[alarm_numtype];

Clock_realtime_alarm and Clock_realtime, Clock_boottime_alarm and Clock_boottime are all using the same base_clockid, but _alarm maintained alarm_ Bases[alarm_numtype].timerqueue them apart from the rest of the Hrtimer.

struct K_clock Alarm_clock acts as a common clock/timer function for two types:

struct K_clock Alarm_clock = {
. clock_getres= Alarm_clock_getres,
. clock_get= Alarm_clock_get,
. timer_create= Alarm_timer_create,
. timer_set= Alarm_timer_set,
. timer_del= Alarm_timer_del,
. timer_get= Alarm_timer_get,
. nsleep= Alarm_timer_nsleep,
};

static struct Rtc_timer rtctimer;--------------------RTC Timer

static struct Rtc_device *rtcdev;-------------------the corresponding structure of the RTC device

The struct rtc_time is the time format represented by the RTC device:

struct Rtc_time {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int Tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};

The struct ktime_t is the kernel time format.

The conversion of these two time formats, rtc_time to ktime_t through rtc_tm_to_ktime;ktime_t to rtc_time through RTC_KTIME_TO_TM.

Iv. Alarmtimer operating under normal operating conditions

The state analysis of Alarmtimer when entering suspend, suspend and resume

Linux Time Subsystem II: Alarm Timer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.