Every system has at least one clock counter. As with any hardware device in a machine, this counter too is represented and managed by a structure. Hardware abstraction is provided by struct clocksource, defined in the include/linux/clocksource.h header file. This structure provides callbacks to access and handle power management on the counter through the read, enable, disable, suspend, and resume routines:
struct clocksource { u64 (*read)(struct clocksource *cs); u64 mask; u32 mult; u32 shift; u64 max_idle_ns; u32 maxadj; #ifdef CONFIG_ARCH_CLOCKSOURCE_DATA struct arch_clocksource_data archdata; #endif u64 max_cycles; const char *name; struct list_head list; int rating; int (*enable)(struct clocksource *cs); void (*disable)(struct clocksource *cs); unsigned long flags; void (*suspend)(struct clocksource *cs); void (*resume)(struct clocksource *cs); void (*mark_unstable)(struct clocksource *cs); void (*tick_stable)(struct clocksource *cs); /* private: */ #ifdef CONFIG_CLOCKSOURCE_WATCHDOG /* Watchdog related data, used by the framework */ struct list_head wd_list; u64 cs_last; u64 wd_last; #endif struct module *owner; };
Members mult and shift are useful in obtaining elapsed time in relevant units.