对于时钟源设备来说,其最为重要的是在时钟源设备定义中实现一个read函数,此函数用于


读取计数值。


static cycle_t jiffies_read(struct clocksource *cs)
{
 return (cycle_t) jiffies;
}
 
static struct clocksource clocksource_jiffies = {
 .name  = "jiffies",
 .rating  = 1, /* lowest valid rating*/
 .read  = jiffies_read,
 .mask  = CLOCKSOURCE_MASK(32),
 .mult  = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
 .shift  = JIFFIES_SHIFT,
 .max_cycles = 10,
};
 
 
 
/*
 * .mask MUST be CLOCKSOURCE_MASK(64). See comment above read_tsc()
 */
static struct clocksource clocksource_tsc = {
 .name                   = "tsc",
 .rating                 = 300,
 .read                   = read_tsc,
 .mask                   = CLOCKSOURCE_MASK(64),
 .flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
      CLOCK_SOURCE_MUST_VERIFY,
 .archdata               = { .vclock_mode = VCLOCK_TSC },
};
 
static cycle_t read_tsc(struct clocksource *cs)
{
 return (cycle_t)rdtsc_ordered();
}