Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / include / linux / vs_sched.h
1 #ifndef _VX_VS_SCHED_H
2 #define _VX_VS_SCHED_H
3
4 #include "vserver/sched.h"
5
6
7 #define VAVAVOOM_RATIO           50
8
9 #define MAX_PRIO_BIAS            20
10 #define MIN_PRIO_BIAS           -20
11
12
13 static inline int vx_tokens_avail(struct vx_info *vxi)
14 {
15         return atomic_read(&vxi->sched.tokens);
16 }
17
18 static inline void vx_consume_token(struct vx_info *vxi)
19 {
20         atomic_dec(&vxi->sched.tokens);
21 }
22
23 static inline int vx_need_resched(struct task_struct *p)
24 {
25 #ifdef  CONFIG_VSERVER_HARDCPU
26         struct vx_info *vxi = p->vx_info;
27 #endif
28         int slice = --p->time_slice;
29
30 #ifdef  CONFIG_VSERVER_HARDCPU
31         if (vxi) {
32                 int tokens;
33
34                 if ((tokens = vx_tokens_avail(vxi)) > 0)
35                         vx_consume_token(vxi);
36                 /* for tokens > 0, one token was consumed */
37                 if (tokens < 2)
38                         return 1;
39         }
40 #endif
41         return (slice == 0);
42 }
43
44
45 static inline void vx_onhold_inc(struct vx_info *vxi)
46 {
47         int onhold = atomic_read(&vxi->cvirt.nr_onhold);
48
49         atomic_inc(&vxi->cvirt.nr_onhold);
50         if (!onhold)
51                 vxi->cvirt.onhold_last = jiffies;
52 }
53
54 static inline void __vx_onhold_update(struct vx_info *vxi)
55 {
56         int cpu = smp_processor_id();
57         uint32_t now = jiffies;
58         uint32_t delta = now - vxi->cvirt.onhold_last;
59
60         vxi->cvirt.onhold_last = now;
61         vxi->sched.cpu[cpu].hold_ticks += delta;
62 }
63
64 static inline void vx_onhold_dec(struct vx_info *vxi)
65 {
66         if (atomic_dec_and_test(&vxi->cvirt.nr_onhold))
67                 __vx_onhold_update(vxi);
68 }
69
70 static inline void vx_account_user(struct vx_info *vxi,
71         cputime_t cputime, int nice)
72 {
73         int cpu = smp_processor_id();
74
75         if (!vxi)
76                 return;
77         vxi->sched.cpu[cpu].user_ticks += cputime;
78 }
79
80 static inline void vx_account_system(struct vx_info *vxi,
81         cputime_t cputime, int idle)
82 {
83         int cpu = smp_processor_id();
84
85         if (!vxi)
86                 return;
87         vxi->sched.cpu[cpu].sys_ticks += cputime;
88 }
89
90 #else
91 #warning duplicate inclusion
92 #endif