/* PFAIR Mathematical functions */ #ifndef __UNC_PFAIR_MATH_H__ #define __UNC_PFAIR_MATH_H__ #include #include #include #include /* Type definition for our quantums */ typedef unsigned long long quantum_t; /* * This file defines mathematical functions "ceiling", "floor", * and PFAIR specific functions for computing the release and * the deadline of a subtask, as well as tie breakers: * b-bit and group deadline. */ static inline quantum_t FLOOR(quantum_t a, unsigned long b) { BUG_ON( b == 0); do_div(a, b); return a; } static inline quantum_t CEIL(quantum_t a, unsigned long b) { quantum_t t = FLOOR(a, b); return (quantum_t)((t * b == a) ? t : (t + 1)); } /* * invariant - i-1=get_passed_quanta(t) * * release time of i-th subtask of j-th job is * r_{ij}+\lfloor i-1/wt(T) \rfloor * This operation should be robust to wrap-around * so we can compare the result with jiffies safely */ static inline quantum_t release_time(struct task_struct * t) { quantum_t e = get_exec_cost(t); quantum_t p = get_rt_period(t); return FLOOR((get_passed_quanta(t)) * p, e); } /* * deadline time of i-th subtask of j-th job is * r_{ij}+\lceil i/wt(T) \rceil * This operation should be robust to wrap-around * so we can compare the result with jiffies safely */ static inline quantum_t pfair_deadline(struct task_struct * t) { quantum_t e = get_exec_cost(t); quantum_t p = get_rt_period(t); return CEIL((get_passed_quanta(t) + 1) * p, e); } /* In PFAIR b-bit is defined as * \lceil i/wt(T) \rceil-\lfloor i/wt(T) \rfloor */ static inline int b_bit(struct task_struct *t) { quantum_t e = get_exec_cost(t); quantum_t p = get_rt_period(t); return CEIL((get_passed_quanta(t) + 1) * p, e)- FLOOR((get_passed_quanta(t) + 1) * p, e); } /* * Group deadline */ static inline quantum_t group_deadline(struct task_struct * t) { quantum_t p = get_rt_period(t); quantum_t e = get_exec_cost(t); quantum_t stage1 = CEIL((get_passed_quanta(t) + 1) * p, e); quantum_t stage2 = CEIL(stage1 * (p - e), p); return CEIL(stage2 * p, p - e); } #endif /* __UNC_PFAIR_MATH_H__ */