aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched_plugin.h
blob: 1ea8178b25820a7d6b7a373f28dc39898b6bad62 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Definition of the scheduler plugin interface.
 * 
 */
#ifndef _LINUX_SCHED_PLUGIN_H_
#define _LINUX_SCHED_PLUGIN_H_

#include <linux/sched.h>

/* struct for semaphore with priority inheritance */
struct pi_semaphore {
	atomic_t count;
	int sleepers;
	wait_queue_head_t wait;
	union {
		/* highest-prio holder/waiter */
		struct task_struct *task; 
		struct task_struct* cpu_task[NR_CPUS];
	} hp;
	/* current lock holder */
	struct task_struct *holder; 
	/* is the semaphore being used? */
	int used; 
};


/* Enforce runqueues to be opaque objects.
 * 
 * This allows us to pass around pointers to runqueues, 
 * without actually having to rip it out of sched.c. It
 * also discourages plugins from trying to be
 * overly clever. 
 */
typedef void runqueue_t;


/********************* scheduler invocation ******************/

typedef enum {
	NO_RESCHED    = 0,
	FORCE_RESCHED = 1  
} reschedule_check_t;


/*  Plugin-specific realtime tick handler */
typedef reschedule_check_t (*scheduler_tick_t) (void);
/* Novell make sched decision function */
typedef int (*schedule_t) (struct task_struct * prev, 
			   struct task_struct ** next,
			   runqueue_t * rq);
/* Clean up after the task switch has occured.
 * This function is called after every (even non-rt) task switch.
 */
typedef void (*finish_switch_t)(struct task_struct *prev);


/********************* task state changes ********************/

/* called to setup a new real-time task */
typedef long (*prepare_task_t) (struct task_struct *task);
/* called to re-introduce a task after blocking */
typedef void (*wake_up_task_t) (struct task_struct *task);
/* called to notify the plugin of a blocking real-time task
 * it will only be called for real-time tasks and before schedule is called */
typedef void (*task_blocks_t)  (struct task_struct *task);
/* called when a real-time task exits. Free any allocated resources */
typedef long (*tear_down_t)    (struct task_struct *);

/* Called when the new_owner is released from the wait queue 
 * it should now inherit the priority from sem, _before_ it gets readded
 * to any queue
 */
typedef long (*inherit_priority_t) (struct pi_semaphore *sem,
				    struct task_struct *new_owner);

/* Called when the current task releases a semahpore where it might have
 * inherited a piority from
 */
typedef long (*return_priority_t) (struct pi_semaphore *sem);

/* Called when a task tries to acquire a semaphore and fails. Check if its
 * priority is higher than that of the current holder.
 */
typedef long (*pi_block_t) (struct pi_semaphore *sem, struct task_struct *t);


/********************* sys call backends  ********************/
/* This function causes the caller to sleep until the next release */
typedef long (*sleep_next_period_t) (void);

typedef int (*scheduler_setup_t) (int cmd, void __user *parameter);

typedef int (*mode_change_t) (int);

struct sched_plugin {
	/* 	basic info 		*/
	char 			*plugin_name;
	int 			ready_to_use;

	/* 	management interface 	*/
	mode_change_t 		mode_change;

	/* 	scheduler invocation 	*/
	scheduler_tick_t 	scheduler_tick;
	schedule_t 		schedule;	
	finish_switch_t 	finish_switch;

	/*	syscall backend 	*/
	sleep_next_period_t 	sleep_next_period;
	scheduler_setup_t   	scheduler_setup;

	/*	task state changes 	*/
	prepare_task_t 		prepare_task;
	wake_up_task_t 		wake_up_task;
	task_blocks_t		task_blocks;
	tear_down_t 		tear_down;

	/*     priority inheritance 	*/
	inherit_priority_t	inherit_priority;
	return_priority_t	return_priority;
	pi_block_t		pi_block;
} __attribute__ ((__aligned__(SMP_CACHE_BYTES)));

typedef struct sched_plugin sched_plugin_t;

extern sched_plugin_t *curr_sched_plugin;


/* common scheduler tick */
reschedule_check_t rt_scheduler_tick(void);


/* Don't pull in our definitions on top of the real ones
 * in sched.c!
 */
#ifndef __SCHED_C__

/*	External linux scheduler facilities */
void deactivate_task(struct task_struct *, runqueue_t *);
/* This function is defined in sched.c. We need acces to it for 
 * indirect switching.
 */
void __activate_task(struct task_struct *, runqueue_t *);
void __setscheduler(struct task_struct *, int, int);

#endif

extern int get_sched_options(void);
#endif