1 #if defined(__KERNEL__) && defined(_VX_INFO_DEF_)
3 #include <linux/spinlock.h>
4 #include <linux/jiffies.h>
6 #include <asm/cpumask.h>
8 /* context sub struct */
11 spinlock_t tokens_lock; /* lock for this structure */
13 int fill_rate; /* Fill rate: add X tokens... */
14 int interval; /* Divisor: per Y jiffies */
15 int tokens; /* number of CPU tokens in this context */
16 int tokens_min; /* Limit: minimum for unhold */
17 int tokens_max; /* Limit: no more than N tokens */
18 uint32_t jiffies; /* add an integral multiple of Y to this */
20 uint64_t ticks; /* token tick events */
21 cpumask_t cpus_allowed; /* cpu mask for context */
24 static inline void vx_info_init_sched(struct _vx_sched *sched)
26 /* scheduling; hard code starting values as constants */
29 sched->tokens = HZ >> 2;
30 sched->tokens_min = HZ >> 4;
31 sched->tokens_max = HZ >> 1;
32 sched->jiffies = jiffies;
33 sched->tokens_lock = SPIN_LOCK_UNLOCKED;
36 static inline int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
38 return sprintf(buffer,
55 #else /* _VX_INFO_DEF_ */
61 /* sched vserver commands */
63 #define VCMD_set_sched_v1 VC_CMD(SYSTEST, 1, 1)
65 struct vcmd_set_sched_v1 {
72 #define VCMD_set_sched VC_CMD(SCHED, 1, 2)
74 struct vcmd_set_sched_v2 {
83 #define SCHED_KEEP (-2)
87 extern int vc_set_sched_v1(uint32_t, void *);
88 extern int vc_set_sched(uint32_t, void *);
91 #define VAVAVOOM_RATIO 50
96 /* scheduling stuff */
98 int effective_vavavoom(struct task_struct *, int);
100 int vx_tokens_recalc(struct vx_info *);
102 /* update the token allocation for a process */
103 static inline int vx_tokens_avail(struct task_struct *tsk)
105 struct vx_info *vxi = tsk->vx_info;
108 spin_lock(&vxi->sched.tokens_lock);
109 tokens = vx_tokens_recalc(vxi);
110 spin_unlock(&vxi->sched.tokens_lock);
116 static inline int vx_need_resched(struct task_struct *p, struct vx_info *vxi)
122 if (vxi->sched.tokens > 0) {
123 spin_lock(&vxi->sched.tokens_lock);
124 tokens = --vxi->sched.tokens;
125 spin_unlock(&vxi->sched.tokens_lock);
127 return ((p->time_slice == 0) || (tokens == 0));
129 return (p->time_slice == 0);
133 #endif /* __KERNEL__ */
135 #endif /* _VX_SCHED_H */