fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / vs_sched.h
1 #ifndef _VS_SCHED_H
2 #define _VS_SCHED_H
3
4 #include "vserver/base.h"
5 #include "vserver/context.h"
6 #include "vserver/sched.h"
7
8
9 #define VAVAVOOM_RATIO           50
10
11 #define MAX_PRIO_BIAS            20
12 #define MIN_PRIO_BIAS           -20
13
14
15 #ifdef CONFIG_VSERVER_HARDCPU
16
17 /*
18  * effective_prio - return the priority that is based on the static
19  * priority but is modified by bonuses/penalties.
20  *
21  * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
22  * into a -4 ... 0 ... +4 bonus/penalty range.
23  *
24  * Additionally, we scale another amount based on the number of
25  * CPU tokens currently held by the context, if the process is
26  * part of a context (and the appropriate SCHED flag is set).
27  * This ranges from -5 ... 0 ... +15, quadratically.
28  *
29  * So, the total bonus is -9 .. 0 .. +19
30  * We use ~50% of the full 0...39 priority range so that:
31  *
32  * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
33  * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
34  *    unless that context is far exceeding its CPU allocation.
35  *
36  * Both properties are important to certain workloads.
37  */
38 static inline
39 int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
40 {
41         int vavavoom, max;
42
43         /* lots of tokens = lots of vavavoom
44          *      no tokens = no vavavoom      */
45         if ((vavavoom = sched_pc->tokens) >= 0) {
46                 max = sched_pc->tokens_max;
47                 vavavoom = max - vavavoom;
48                 max = max * max;
49                 vavavoom = max_prio * VAVAVOOM_RATIO / 100
50                         * (vavavoom*vavavoom - (max >> 2)) / max;
51                 return vavavoom;
52         }
53         return 0;
54 }
55
56
57 static inline
58 int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
59 {
60         struct vx_info *vxi = p->vx_info;
61         struct _vx_sched_pc *sched_pc;
62
63         if (!vxi)
64                 return prio;
65
66         sched_pc = &vx_cpu(vxi, sched_pc);
67         if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
68                 int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
69
70                 sched_pc->vavavoom = vavavoom;
71                 prio += vavavoom;
72         }
73         prio += sched_pc->prio_bias;
74         return prio;
75 }
76
77 #else /* !CONFIG_VSERVER_HARDCPU */
78
79 static inline
80 int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
81 {
82         struct vx_info *vxi = p->vx_info;
83
84         if (vxi)
85                 prio += vx_cpu(vxi, sched_pc).prio_bias;
86         return prio;
87 }
88
89 #endif /* CONFIG_VSERVER_HARDCPU */
90
91
92 static inline void vx_account_user(struct vx_info *vxi,
93         cputime_t cputime, int nice)
94 {
95         if (!vxi)
96                 return;
97         vx_cpu(vxi, sched_pc).user_ticks += cputime;
98 }
99
100 static inline void vx_account_system(struct vx_info *vxi,
101         cputime_t cputime, int idle)
102 {
103         if (!vxi)
104                 return;
105         vx_cpu(vxi, sched_pc).sys_ticks += cputime;
106 }
107
108 #else
109 #warning duplicate inclusion
110 #endif