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

struct enforcement_timer {
	struct hrtimer		timer;
	int			armed;
};

/**
 * update_enforcement_timer() - Update per-processor enforcement timer for
 * the next scheduled task.
 *
 * If @t is not NULL and has a precisely enforced budget, the timer will be
 * armed to trigger a reschedule when the budget is exhausted. Otherwise,
 * the timer will be cancelled.
*/
void update_enforcement_timer(struct task_struct* t);

void init_enforcement_timer(struct enforcement_timer *et);

void arm_enforcement_timer(struct enforcement_timer* et, struct task_struct* t);

void cancel_enforcement_timer(struct enforcement_timer* et);

/* True if a task's server has progressed farther than the task
 * itself. This happens when budget enforcement has caused a task to be
 * booted off until the next period.
 */


/**
 * server_release() - Prepare the task server parameters for the next period.
 * The server for @t is what is actually executed from the schedulers
 * perspective.
 */
void server_release(struct task_struct *t);

/**
 * task_release() - Prepare actual task parameters for the next period.
 * The actual task parameters for @t, real_deadline and real_release, are
 * the deadline and release from the tasks perspective. We only record these
 * so that we can write them to feather trace.
 */
void task_release(struct task_struct *t);

inline static int budget_exhausted(struct task_struct* t)
{
	return get_exec_time(t) >= get_exec_cost(t);
}

inline static lt_t budget_remaining(struct task_struct* t)
{
	if (!budget_exhausted(t))
		return get_exec_cost(t) - get_exec_time(t);
	else
		/* avoid overflow */
		return 0;
}

#define budget_enforced(t) (tsk_rt(t)->task_params.budget_policy != NO_ENFORCEMENT)

#define budget_precisely_enforced(t) (tsk_rt(t)->task_params.budget_policy \
				      == PRECISE_ENFORCEMENT)

static inline int requeue_preempted_job(struct task_struct* t)
{
	/* Add task to ready queue only if not subject to budget enforcement or
	 * if the job has budget remaining. t may be NULL.
	 */
	return t && (!budget_exhausted(t) || !budget_enforced(t));
}

#endif