This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vserver / sched.h
1 #if     defined(__KERNEL__) && defined(_VX_INFO_DEF_)
2
3 #include <linux/spinlock.h>
4 #include <linux/jiffies.h>
5 #include <asm/atomic.h>
6 #include <asm/param.h>
7 #include <asm/cpumask.h>
8
9 /* context sub struct */
10
11 struct _vx_sched {
12         spinlock_t tokens_lock; /* lock for this structure */
13
14         int fill_rate;          /* Fill rate: add X tokens... */
15         int interval;           /* Divisor:   per Y jiffies   */
16         atomic_t tokens;        /* number of CPU tokens in this context */
17         int tokens_min;         /* Limit:     minimum for unhold */
18         int tokens_max;         /* Limit:     no more than N tokens */
19         uint32_t jiffies;       /* add an integral multiple of Y to this */
20
21         uint64_t ticks;         /* token tick events */
22         cpumask_t cpus_allowed; /* cpu mask for context */
23 };
24
25 static inline void vx_info_init_sched(struct _vx_sched *sched)
26 {
27         /* scheduling; hard code starting values as constants */
28         sched->fill_rate        = 1;
29         sched->interval         = 4;
30         sched->tokens_min       = HZ >> 4;
31         sched->tokens_max       = HZ >> 1;
32         sched->jiffies          = jiffies;
33         sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
34
35         atomic_set(&sched->tokens, HZ >> 2);
36         sched->cpus_allowed     = CPU_MASK_ALL;
37 }
38
39 static inline void vx_info_exit_sched(struct _vx_sched *sched)
40 {
41         return;
42 }
43
44 static inline int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
45 {
46         return sprintf(buffer,
47                 "Ticks:\t%16lld\n"
48                 "Token:\t\t%8d\n"
49                 "FillRate:\t%8d\n"
50                 "Interval:\t%8d\n"              
51                 "TokensMin:\t%8d\n"
52                 "TokensMax:\t%8d\n"
53                 ,sched->ticks
54                 ,atomic_read(&sched->tokens)
55                 ,sched->fill_rate
56                 ,sched->interval
57                 ,sched->tokens_min
58                 ,sched->tokens_max
59                 );
60 }
61
62
63 #else   /* _VX_INFO_DEF_ */
64 #ifndef _VX_SCHED_H
65 #define _VX_SCHED_H
66
67 #include "switch.h"
68
69 /*  sched vserver commands */
70
71 #define VCMD_set_sched          VC_CMD(SCHED, 1, 2)
72
73 struct  vcmd_set_sched_v2 {
74         int32_t fill_rate;
75         int32_t interval;
76         int32_t tokens;
77         int32_t tokens_min;
78         int32_t tokens_max;
79         uint64_t cpu_mask;
80 };
81
82 #define SCHED_KEEP              (-2)
83
84 #ifdef  __KERNEL__
85
86 extern int vc_set_sched_v1(uint32_t, void __user *);
87 extern int vc_set_sched(uint32_t, void __user *);
88
89
90 #define VAVAVOOM_RATIO          50
91
92 #include "context.h"
93
94
95 /* scheduling stuff */
96
97 int effective_vavavoom(struct task_struct *, int);
98
99 int vx_tokens_recalc(struct vx_info *);
100
101 /* new stuff ;) */
102
103 static inline int vx_tokens_avail(struct vx_info *vxi)
104 {
105         return atomic_read(&vxi->sched.tokens);
106 }
107
108 static inline void vx_consume_token(struct vx_info *vxi)
109 {
110         atomic_dec(&vxi->sched.tokens);
111 }
112
113 static inline int vx_need_resched(struct task_struct *p)
114 {
115 #ifdef  CONFIG_VSERVER_HARDCPU
116         struct vx_info *vxi = p->vx_info;
117
118         if (vxi) {
119                 int tokens;
120
121                 p->time_slice--;
122                 if (atomic_read(&vxi->vx_refcount) < 1)
123                         printk("need_resched: p=%p, s=%ld, ref=%d, id=%d/%d\n",
124                                 p, p->state, atomic_read(&vxi->vx_refcount),
125                                 vxi->vx_id, p->xid);
126                 if ((tokens = vx_tokens_avail(vxi)) > 0)
127                         vx_consume_token(vxi);
128                 return ((p->time_slice == 0) || (tokens < 1));
129         }
130 #endif
131         p->time_slice--;
132         return (p->time_slice == 0);
133 }
134
135
136 #endif  /* __KERNEL__ */
137
138 #endif  /* _VX_SCHED_H */
139 #endif