aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/fifo_common.c
blob: 84ae98e42ae49af96c38d54970f5fed3ec8e1bdf (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
/*
 * kernel/edf_common.c
 *
 * Common functions for EDF based scheduler.
 */

#include <linux/percpu.h>
#include <linux/sched.h>
#include <linux/list.h>

#include <litmus/litmus.h>
#include <litmus/sched_plugin.h>
#include <litmus/sched_trace.h>

#include <litmus/fifo_common.h>

int fifo_higher_prio(struct task_struct* first,
		    struct task_struct* second)
{
	/* There is no point in comparing a task to itself. */
	if (first && first == second) {
		TRACE_TASK(first,
			   "WARNING: pointless fifo priority comparison.\n");
		BUG_ON(1);
		return 0;
	}

	if (!first || !second)
		return first && !second;

	/* Tiebreak by PID */
	return  (get_release(first) == get_release(second) &&
		 first->pid > second->pid) ||
		(get_release(first) < get_release(second));


}

int fifo_ready_order(struct bheap_node* a, struct bheap_node* b)
{
	return fifo_higher_prio(bheap2task(a), bheap2task(b));
}

void fifo_domain_init(rt_domain_t* rt, check_resched_needed_t resched,
		      release_jobs_t release)
{
	rt_domain_init(rt,  fifo_ready_order, resched, release);
}

int fifo_preemption_needed(rt_domain_t* rt, struct task_struct *t)
{
	if (!__jobs_pending(rt))
		return 0;
	if (!t)
		return 1;

	return !is_realtime(t) || fifo_higher_prio(__next_ready(rt), t);
}