aboutsummaryrefslogblamecommitdiffstats
path: root/litmus/fifo_common.c
blob: 84ae98e42ae49af96c38d54970f5fed3ec8e1bdf (plain) (tree)

























































                                                                             
/*
 * 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);
}