aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/budget.h
blob: 8e426a71f03df2aa5bbe9a340f70a0d694d27fcb (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
#ifndef _LITMUS_BUDGET_H_
#define _LITMUS_BUDGET_H_

#include <linux/hrtimer.h>
#include <linux/semaphore.h>

struct enforcement_timer
{
	raw_spinlock_t lock;
	struct hrtimer timer;
	int armed:1;
};

typedef void (*scheduled_t)(struct task_struct* t);
typedef void (*blocked_t)(struct task_struct* t);
typedef void (*preempt_t)(struct task_struct* t);
typedef void (*sleep_t)(struct task_struct* t);
typedef enum hrtimer_restart (*exhausted_t)(struct task_struct* t);
typedef void (*exit_t)(struct task_struct* t);
typedef void (*inherit_t)(struct task_struct* t, struct task_struct* prio_inh);
typedef void (*disinherit_t)(struct task_struct* t, struct task_struct* prio_inh);

struct budget_tracker_ops
{
	scheduled_t			on_scheduled;	/* called from litmus_schedule(). */
	blocked_t			on_blocked;		/* called from plugin::schedule() */
	preempt_t			on_preempt;		/* called from plugin::schedule() */
	sleep_t				on_sleep;		/* called from plugin::schedule() */

	exit_t				on_exit;		/* task exiting rt mode */

	exhausted_t			on_exhausted;	/* called by plugin::tick() or timer interrupt */

	inherit_t			on_inherit;
	disinherit_t		on_disinherit;
};

struct budget_tracker
{
	struct enforcement_timer timer;
	const struct budget_tracker_ops* ops;
	unsigned long flags;
};

/* budget tracker flags */
enum BT_FLAGS
{
	BTF_BUDGET_EXHAUSTED = 0,
	BTF_SIG_BUDGET_SENT	= 1,
};

/* Functions for simple DRAIN_SIMPLE policy common
 * to every scheduler. Scheduler must provide
 * implementation for simple_on_exhausted().
 */
void simple_on_scheduled(struct task_struct* t);
void simple_on_blocked(struct task_struct* t);
void simple_on_preempt(struct task_struct* t);
void simple_on_sleep(struct task_struct* t);
void simple_on_exit(struct task_struct* t);


/* Functions for DRAIN_SOBLIV policy common
 * to every scheduler. Scheduler must provide
 * implementation for sobliv_on_exhausted().
 *
 * Limitation: Quantum budget tracking is unsupported.
 */
void sobliv_on_scheduled(struct task_struct* t);
void sobliv_on_blocked(struct task_struct* t);
void sobliv_on_sleep(struct task_struct* t);
/* Use the DRAIN_SIMPLE implementations */
#define sobliv_on_preempt	simple_on_preempt
#define sobliv_on_exit	simple_on_exit
void sobliv_on_inherit(struct task_struct* t, struct task_struct* prio_inh);
void sobliv_on_disinherit(struct task_struct* t, struct task_struct* prio_inh);
void sobliv_revaluate_task(struct task_struct* t);


void init_budget_tracker(struct budget_tracker* bt,
				const struct budget_tracker_ops* ops);


/* Send SIG_BUDGET to a real-time task. */
void send_sigbudget(struct task_struct* t);

#endif