时钟二

内核中使用struct clocksource描述时钟源,

使用clocksource_list来维护struct clocksource;

使用struct clock_event_device来描述时钟发生的时间;

使用clockevent_devices来维护struct clock_event_device;

/include /linux/clocksource.h

/**
 * struct clocksource - hardware abstraction for a free running counter
 *      Provides mostly state-free accessors to the underlying hardware.
 *      This is the structure used for system time.
 *
 * @name:               ptr to clocksource name
 * @list:               list head for registration
 * @rating:             rating value for selection (higher is better)
 *                      To avoid rating inflation the following
 *                      list should give you a guide as to how
 *                      to assign your clocksource a rating
 *                      1-99: Unfit for real use
 *                              Only available for bootup and testing purposes.
 *                      100-199: Base level usability.
 *                              Functional for real use, but not desired.
 *                      200-299: Good.
 *                              A correct and usable clocksource.
 *                      300-399: Desired.
 *                              A reasonably fast and accurate clocksource.
 *                      400-499: Perfect
 *                              The ideal clocksource. A must-use where
 *                              available.

  * @read:               returns a cycle value, passes clocksource as argument
 * @enable:             optional function to enable the clocksource
 * @disable:            optional function to disable the clocksource
 * @mask:               bitmask for two's complement
 *                      subtraction of non 64 bit counters
 * @mult:               cycle to nanosecond multiplier (adjusted by NTP)
 * @mult_orig:          cycle to nanosecond multiplier (unadjusted by NTP)
 * @shift:              cycle to nanosecond divisor (power of two)
 * @flags:              flags describing special properties
 * @vread:              vsyscall based read
 * @resume:             resume function for the clocksource, if necessary
 * @cycle_interval:     Used internally by timekeeping core, please ignore.
 * @xtime_interval:     Used internally by timekeeping core, please ignore.
 */

struct clocksource {
        /*
         * First part of structure is read mostly
         */
        char *name;
        struct list_head list;
        int rating;
        cycle_t (*read)(struct clocksource *cs);
        int (*enable)(struct clocksource *cs);
        void (*disable)(struct clocksource *cs);
        cycle_t mask;
        u32 mult;
        u32 mult_orig;
        u32 shift;
        unsigned long flags;
        cycle_t (*vread)(void);
        void (*resume)(void);
#ifdef CONFIG_IA64
        void *fsys_mmio;        /* used by fsyscall asm code */
#define CLKSRC_FSYS_MMIO_SET(mmio, addr)      ((mmio) = (addr))
#else
#define CLKSRC_FSYS_MMIO_SET(mmio, addr)      do { } while (0)

#endif

        /* timekeeping specific data, ignore */
        cycle_t cycle_interval;
        u64     xtime_interval;
        u32     raw_interval;
        /*
         * Second part is written at each timer interrupt
         * Keep it in a different cache line to dirty no
         * more than one cache line.
         */
        cycle_t cycle_last ____cacheline_aligned_in_smp;
        u64 xtime_nsec;
        s64 error;
        struct timespec raw_time;

#ifdef CONFIG_CLOCKSOURCE_WATCHDOG
        /* Watchdog related data, used by the framework */
        struct list_head wd_list;
        cycle_t wd_last;
#endif
};

/include /linux/clockchip.h

/**
 * struct clock_event_device - clock event device descriptor
 * @name:               ptr to clock event name
 * @features:           features
 * @max_delta_ns:       maximum delta value in ns
 * @min_delta_ns:       minimum delta value in ns
 * @mult:               nanosecond to cycles multiplier
 * @shift:              nanoseconds to cycles divisor (power of two)
 * @rating:             variable to rate clock event devices
 * @irq:                IRQ number (only for non CPU local devices)
 * @cpumask:            cpumask to indicate for which CPUs this device works
 * @set_next_event:     set next event function
 * @set_mode:           set mode function
 * @event_handler:      Assigned by the framework to be called by the low
 *                      level handler of the event source
 * @broadcast:          function to broadcast events
 * @list:               list head for the management code
 * @mode:               operating mode assigned by the management code
 * @next_event:         local storage for the next event in oneshot mode
 */
struct clock_event_device {
        const char              *name;
        unsigned int            features;
        unsigned long           max_delta_ns;
        unsigned long           min_delta_ns;
        unsigned long           mult;
        int                     shift;
        int                     rating;
        int                     irq;
        const struct cpumask    *cpumask;
        int                     (*set_next_event)(unsigned long evt,
                                                  struct clock_event_device *);
        void                    (*set_mode)(enum clock_event_mode mode,
                                            struct clock_event_device *);
        void                    (*event_handler)(struct clock_event_device *);
        void                    (*broadcast)(const struct cpumask *mask);
        struct list_head        list;
        enum clock_event_mode   mode;
        ktime_t                 next_event;
};

/* Clock event mode commands */
enum clock_event_mode {
        CLOCK_EVT_MODE_UNUSED = 0,
        CLOCK_EVT_MODE_SHUTDOWN,
        CLOCK_EVT_MODE_PERIODIC,
        CLOCK_EVT_MODE_ONESHOT,
        CLOCK_EVT_MODE_RESUME,
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值