06330bfa24c912b124cbc1fbd9cfc3d6eb0e0568
[linux-2.6.git] / include / linux / vs_sched.h
1 #ifndef _VX_VS_SCHED_H
2 #define _VX_VS_SCHED_H
3
4 #ifndef CONFIG_VSERVER
5 #warning config options missing
6 #endif
7
8 #include "vserver/sched.h"
9
10
11 #define VAVAVOOM_RATIO           50
12
13 #define MAX_PRIO_BIAS            20
14 #define MIN_PRIO_BIAS           -20
15
16
17 static inline int vx_tokens_avail(struct vx_info *vxi)
18 {
19         return atomic_read(&vxi->sched.tokens);
20 }
21
22 static inline void vx_consume_token(struct vx_info *vxi)
23 {
24         atomic_dec(&vxi->sched.tokens);
25 }
26
27 static inline int vx_need_resched(struct task_struct *p)
28 {
29 #ifdef  CONFIG_VSERVER_HARDCPU
30         struct vx_info *vxi = p->vx_info;
31 #endif
32         int slice = --p->time_slice;
33
34 #ifdef  CONFIG_VSERVER_HARDCPU
35         if (vxi) {
36                 int tokens;
37
38                 if ((tokens = vx_tokens_avail(vxi)) > 0)
39                         vx_consume_token(vxi);
40                 /* for tokens > 0, one token was consumed */
41                 if (tokens < 2)
42                         return 1;
43         }
44 #endif
45         return (slice == 0);
46 }
47
48
49 static inline void vx_onhold_inc(struct vx_info *vxi)
50 {
51         int onhold = atomic_read(&vxi->cvirt.nr_onhold);
52
53         atomic_inc(&vxi->cvirt.nr_onhold);
54         if (!onhold)
55                 vxi->cvirt.onhold_last = jiffies;
56 }
57
58 static inline void __vx_onhold_update(struct vx_info *vxi)
59 {
60         int cpu = smp_processor_id();
61         uint32_t now = jiffies;
62         uint32_t delta = now - vxi->cvirt.onhold_last;
63
64         vxi->cvirt.onhold_last = now;
65         vxi->sched.cpu[cpu].hold_ticks += delta;
66 }
67
68 static inline void vx_onhold_dec(struct vx_info *vxi)
69 {
70         if (atomic_dec_and_test(&vxi->cvirt.nr_onhold))
71                 __vx_onhold_update(vxi);
72 }
73
74 #else
75 #warning duplicate inclusion
76 #endif