aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/ce_domain.c
blob: c3ddc9dd63ad0077432020f8983cc50e02ba2e05 (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
#include <linux/pid.h>
#include <linux/sched.h>
#include <linux/hrtimer.h>
#include <linux/slab.h>

#include <litmus/litmus.h>
#include <litmus/debug_trace.h>
#include <litmus/rt_param.h>
#include <litmus/domain.h>
#include <litmus/event_group.h>
#include <litmus/sched_mc.h>
#include <litmus/ce_domain.h>

/*
 * Called for:
 * task_new
 * job_completion
 * wake_up
 */
void ce_requeue(domain_t *dom, struct task_struct *ts)
{
	const struct ce_dom_data *ce_data = dom->data;
	const int idx = tsk_mc_data(ts)->mc_task.lvl_a_id;
	const unsigned int just_finished = tsk_rt(ts)->job_params.job_no;
	const unsigned int expected_job =
		mc_ce_get_expected_job(ce_data->cpu, idx);
	const int asleep = RT_F_SLEEP == get_rt_flags(ts);

	TRACE_MC_TASK(ts, "entered ce_requeue. asleep: %d  just_finished: %3u  "
			"expected_job: %3u\n",
			asleep, just_finished, expected_job);

	/* When coming from job completion, the task will be asleep. */
	if (asleep && just_finished < expected_job) {
		TRACE_MC_TASK(ts, "appears behind\n");
	} else if (asleep && expected_job < just_finished) {
		TRACE_MC_TASK(ts, "job %u completed in expected job %u which "
				"seems too early\n", just_finished,
				expected_job);
	}
}

/*
 * ce_take_ready and ce_peek_ready
 */
struct task_struct* ce_peek_and_take_ready(domain_t *dom)
{
	struct task_struct *ret = NULL;
	const struct ce_dom_data *ce_data = dom->data;
	const int exists = NULL != ce_data->should_schedule;
	const int blocked = exists && !is_running(ce_data->should_schedule);

	/* Return the task we should schedule if it is not blocked or sleeping. */
	if (exists && !blocked)
		ret = ce_data->should_schedule;
	return ret;
}

int ce_higher_prio(struct task_struct *_a, struct task_struct *_b)
{
	const struct task_struct *a = _a;
	const domain_t *dom = get_task_domain(a);
	const struct ce_dom_data *ce_data = dom->data;
	return (a == ce_data->should_schedule);
}

void ce_domain_init(domain_t *dom,
		raw_spinlock_t *lock,
		requeue_t requeue,
		peek_ready_t peek_ready,
		take_ready_t take_ready,
		preempt_needed_t preempt_needed,
		task_prio_t task_prio,
		struct ce_dom_data *dom_data,
		const int cpu,
		ce_timer_callback_t ce_timer_callback)
{
	domain_init(dom, lock, requeue, peek_ready, take_ready, preempt_needed,
			task_prio);
	dom->data = dom_data;
	dom_data->cpu = cpu;
#ifdef CONFIG_MERGE_TIMERS
	init_event(&dom_data->event, CRIT_LEVEL_A, ce_timer_callback,
			event_list_alloc(GFP_ATOMIC));
#else
	hrtimer_start_on_info_init(&dom_data->timer_info);
	hrtimer_init(&dom_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
	dom_data->timer.function = ce_timer_callback;
#endif
}