Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239472
  • 博文数量: 33
  • 博客积分: 2511
  • 博客等级: 少校
  • 技术积分: 391
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-06 09:24
文章分类
文章存档

2011年(3)

2010年(9)

2009年(3)

2008年(18)

我的朋友

分类: LINUX

2010-10-24 20:53:37

1. 时钟源
时钟源其实只是为了提供一个单调递增的时钟函数

  1. struct clocksource {
  2.     /*
  3.      * First part of structure is read mostly
  4.      */
  5.     char *name;
  6.     struct list_head list;
  7.     int rating; // 表明时钟源的能力,值越大表示精度越高
  8.     cycle_t (*read)(struct clocksource *cs); // 获取计数值
  9.     int (*enable)(struct clocksource *cs);
  10.     void (*disable)(struct clocksource *cs);
  11.     cycle_t mask; // 由于cycle_t是一个64bit的值,该mask表明多少bit是有效的
  12.     u32 mult; // 和下面的shift将cycle值转换为ns, 计算方式为: (cycle * mult)/2^shift = x ns
  13.     u32 shift;
  14.     u64 max_idle_ns;
  15.     unsigned long flags;
  16.     cycle_t (*vread)(void);
  17.     void (*suspend)(struct clocksource *cs);
  18.     void (*resume)(struct clocksource *cs);
  19. #ifdef CONFIG_IA64
  20.     void *fsys_mmio; /* used by fsyscall asm code */
  21. #define CLKSRC_FSYS_MMIO_SET(mmio, addr) ((mmio) = (addr))
  22. #else
  23. #define CLKSRC_FSYS_MMIO_SET(mmio, addr) do { } while (0)
  24. #endif

  25.     /*
  26.      * Second part is written at each timer interrupt
  27.      * Keep it in a different cache line to dirty no
  28.      * more than one cache line.
  29.      */
  30.     cycle_t cycle_last ____cacheline_aligned_in_smp;

  31. #ifdef CONFIG_CLOCKSOURCE_WATCHDOG
  32.     /* Watchdog related data, used by the framework */
  33.     struct list_head wd_list;
  34.     cycle_t wd_last;
  35. #endif
  36. };


2. 时钟事件设备

  1. struct clock_event_device {
  2.     const char *name;
  3.     unsigned int features;
  4.     u64 max_delta_ns;
  5.     u64 min_delta_ns;
  6.     u32 mult;
  7.     u32 shift;
  8.     int rating;
  9.     int irq; // 对应的中断号,区分多核和单核的情况
  10.     const struct cpumask *cpumask;
  11.     int (*set_next_event)(unsigned long evt,
  12.                           struct clock_event_device *);
  13.     void (*set_mode)(enum clock_event_mode mode,
  14.                         struct clock_event_device *); // 设置模式
  15.     void (*event_handler)(struct clock_event_device *);
  16.     void (*broadcast)(const struct cpumask *mask);
  17.     struct list_head list;
  18.     enum clock_event_mode mode;
  19.     ktime_t next_event;
  20.     unsigned long retries;
  21. };


需要注意的是,其实这2个概念并无联系,而是两个独立的概念,没有任何关系,只是实现时候一般一个硬件会同时提供这两种机制,内核中,对于clock_event_device的使用其实更多一些.

阅读(1597) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-25 16:14:22

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com