aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/event_group.h
blob: 7b15a7e0412d986fb86ae0e1409f611a9fdf820e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef _LINUX_EVENT_QUEUE_H_
#define _LINUX_EVENT_QUEUE_H_

#define EVENT_QUEUE_SLOTS 127 /* prime */

#define NUM_EVENT_PRIORITIES 4 /* num crit levels really */

struct rt_event;
typedef void (*fire_event_t)(struct rt_event *e);

struct event_group {
	lt_t 			res;
	int 			cpu;
	struct list_head 	event_queue[EVENT_QUEUE_SLOTS];
	raw_spinlock_t 		queue_lock;
};

/**
 * A group of actions to fire at a given time
 */
struct event_list {
	/* Use multiple list heads so that inserts are O(1) */
	struct list_head events[NUM_EVENT_PRIORITIES];

	/* For timer firing */
	lt_t 				fire_time;
	struct hrtimer 			timer;
	struct hrtimer_start_on_info	info;

	struct list_head    queue_node;  /* For event_queue */
	struct event_group* group; /* For callback    */
};

/**
 * A single action to fire at a time
 */
struct rt_event {
	/* Function to call on event expiration */
	fire_event_t 	 function;
	/* Priority of this event (lower is better) */
	int 		 prio;

	/* For membership in the event_list */
	struct list_head 	events_node;
	/* To avoid runtime allocation. This is NOT necessarily
	 * the event_list containing this event. This is just a
	 * pre-allocated event list which can be used for merging
	 * events.
	 */
	struct event_list* 	event_list;
	/* Pointer set by add_event() so that we can cancel this event
	 * without knowing what group it is in (don't touch it).
	 */
	struct event_group*	_event_group;
};

/**
 * add_event() - Add timer to event group.
 * @group	Group with which to merge event. If NULL, use the event
 *		group of whatever CPU currently executing on.
 * @e		Event to be fired at a specific time
 * @time	Time to fire event
 */
void add_event(struct event_group* group, struct rt_event* e, lt_t time);

/**
 * cancel_event() - Remove event from the group.
 */
void cancel_event(struct rt_event*);

/**
 * init_event() - Create an event.
 * @e		Event to create
 * @prio 	Priority of the event (lower is better)
 * @function	Function to fire when event expires
 * @el		Pre-allocated event list for timer merging
 */
void init_event(struct rt_event* e, int prio, fire_event_t function,
		struct event_list *el);

struct event_list* event_list_alloc(int);
void event_list_free(struct event_list *el);

/**
 * get_event_group_for() - Get the event group for a CPU.
 * @cpu		The CPU to get the event group for. Use NO_CPU to get the
 *		event group of the CPU that the call is executing on.
 */
struct event_group *get_event_group_for(const int cpu);

#endif