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
|
/* PFAIR Mathematical functions */
#ifndef __UNC_PFAIR_MATH_H__
#define __UNC_PFAIR_MATH_H__
#include <linux/rt_param.h>
#include <asm/div64.h>
#include <linux/litmus.h>
#include <linux/sched.h>
/* 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__ */
|