ia64/xen-unstable

view xen/include/xen/timer.h @ 18392:070688cdf62c

Fall back to a timer linked list when the timer heap overflows.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 13:24:35 2008 +0100 (2008-08-27)
parents d795e15b85a7
children f12d9595d07c
line source
1 /******************************************************************************
2 * timer.h
3 *
4 * Copyright (c) 2002-2003 Rolf Neugebauer
5 * Copyright (c) 2002-2005 K A Fraser
6 */
8 #ifndef _TIMER_H_
9 #define _TIMER_H_
11 #include <xen/spinlock.h>
12 #include <xen/time.h>
13 #include <xen/string.h>
15 struct timer {
16 /* System time expiry value (nanoseconds since boot). */
17 s_time_t expires;
19 /* Position in active-timer data structure. */
20 union {
21 /* Timer-heap offset. */
22 unsigned int heap_offset;
23 /* Overflow linked list. */
24 struct timer *list_next;
25 };
27 /* On expiry, '(*function)(data)' will be executed in softirq context. */
28 void (*function)(void *);
29 void *data;
31 /* CPU on which this timer will be installed and executed. */
32 uint16_t cpu;
34 /* Timer status. */
35 #define TIMER_STATUS_inactive 0 /* Not in use; can be activated. */
36 #define TIMER_STATUS_killed 1 /* Not in use; canot be activated. */
37 #define TIMER_STATUS_in_heap 2 /* In use; on timer heap. */
38 #define TIMER_STATUS_in_list 3 /* In use; on overflow linked list. */
39 uint8_t status;
40 };
42 /*
43 * All functions below can be called for any CPU from any CPU in any context.
44 */
46 /*
47 * Returns TRUE if the given timer is on a timer list.
48 * The timer must *previously* have been initialised by init_timer(), or its
49 * structure initialised to all-zeroes.
50 */
51 static inline int active_timer(struct timer *timer)
52 {
53 return (timer->status >= TIMER_STATUS_in_heap);
54 }
56 /*
57 * Initialise a timer structure with an initial callback CPU, callback
58 * function and callback data pointer. This function may be called at any
59 * time (and multiple times) on an inactive timer. It must *never* execute
60 * concurrently with any other operation on the same timer.
61 */
62 static inline void init_timer(
63 struct timer *timer,
64 void (*function)(void *),
65 void *data,
66 unsigned int cpu)
67 {
68 memset(timer, 0, sizeof(*timer));
69 timer->function = function;
70 timer->data = data;
71 timer->cpu = cpu;
72 }
74 /*
75 * Set the expiry time and activate a timer. The timer must *previously* have
76 * been initialised by init_timer() (so that callback details are known).
77 */
78 extern void set_timer(struct timer *timer, s_time_t expires);
80 /*
81 * Deactivate a timer This function has no effect if the timer is not currently
82 * active.
83 * The timer must *previously* have been initialised by init_timer(), or its
84 * structure initialised to all zeroes.
85 */
86 extern void stop_timer(struct timer *timer);
88 /*
89 * Migrate a timer to a different CPU. The timer may be currently active.
90 * The timer must *previously* have been initialised by init_timer(), or its
91 * structure initialised to all zeroes.
92 */
93 extern void migrate_timer(struct timer *timer, unsigned int new_cpu);
95 /*
96 * Deactivate a timer and prevent it from being re-set (future calls to
97 * set_timer will silently fail). When this function returns it is guaranteed
98 * that the timer callback handler is not running on any CPU.
99 * The timer must *previously* have been initialised by init_timer(), or its
100 * structure initialised to all zeroes.
101 */
102 extern void kill_timer(struct timer *timer);
104 /*
105 * Process pending timers on this CPU. This should be called periodically
106 * when performing work that prevents softirqs from running in a timely manner.
107 */
108 extern void process_pending_timers(void);
110 /*
111 * Bootstrap initialisation. Must be called before any other timer function.
112 */
113 extern void timer_init(void);
115 /*
116 * Next timer deadline for each CPU.
117 * Modified only by the local CPU and never in interrupt context.
118 */
119 DECLARE_PER_CPU(s_time_t, timer_deadline);
121 /* Arch-defined function to reprogram timer hardware for new deadline. */
122 extern int reprogram_timer(s_time_t timeout);
124 #endif /* _TIMER_H_ */
126 /*
127 * Local variables:
128 * mode: C
129 * c-set-style: "BSD"
130 * c-basic-offset: 4
131 * tab-width: 4
132 * indent-tabs-mode: nil
133 * End:
134 */