aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/jobs.c
blob: 1d97462cc128f7fda0d410b0e10d3def18d39c8c (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
/* litmus/jobs.c - common job control code
 */

#include <linux/sched.h>

#include <litmus/litmus.h>
#include <litmus/jobs.h>

void prepare_for_next_period(struct task_struct *t)
{
	BUG_ON(!t);
	/* prepare next release */

	if(tsk_rt(t)->task_params.cls == RT_CLASS_SOFT_W_SLIP) {
		/* allow the release point to slip if we've passed our deadline. */
		lt_t now = litmus_clock();
		t->rt_param.job_params.release =
			(t->rt_param.job_params.deadline < now) ?
				now : t->rt_param.job_params.deadline;
		t->rt_param.job_params.deadline =
			t->rt_param.job_params.release + get_rt_period(t);
	}
	else {
		t->rt_param.job_params.release   = t->rt_param.job_params.deadline;
		t->rt_param.job_params.deadline += get_rt_period(t);
	}

	t->rt_param.job_params.exec_time = 0;
	/* update job sequence number */
	t->rt_param.job_params.job_no++;

	/* don't confuse Linux */
	t->rt.time_slice = 1;
}

void release_at(struct task_struct *t, lt_t start)
{
	t->rt_param.job_params.deadline = start;
	prepare_for_next_period(t);
	set_rt_flags(t, RT_F_RUNNING);
}


/*
 *	Deactivate current task until the beginning of the next period.
 */
long complete_job(void)
{
	/* Mark that we do not excute anymore */
	set_rt_flags(current, RT_F_SLEEP);
	/* call schedule, this will return when a new job arrives
	 * it also takes care of preparing for the next release
	 */
	schedule();
	return 0;
}