1 #if defined(__KERNEL__) && defined(_VX_INFO_DEF_)
3 #include <linux/spinlock.h>
4 #include <linux/jiffies.h>
5 #include <asm/atomic.h>
7 #include <asm/cpumask.h>
9 /* context sub struct */
12 spinlock_t tokens_lock; /* lock for this structure */
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 */
21 uint64_t ticks; /* token tick events */
22 cpumask_t cpus_allowed; /* cpu mask for context */
25 static inline void vx_info_init_sched(struct _vx_sched *sched)
27 /* scheduling; hard code starting values as constants */
30 sched->tokens_min = HZ >> 4;
31 sched->tokens_max = HZ >> 1;
32 sched->jiffies = jiffies;
33 sched->tokens_lock = SPIN_LOCK_UNLOCKED;
35 atomic_set(&sched->tokens, HZ >> 2);
36 sched->cpus_allowed = CPU_MASK_ALL;
39 static inline int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
41 return sprintf(buffer,
49 ,atomic_read(&sched->tokens)
58 #else /* _VX_INFO_DEF_ */
64 /* sched vserver commands */
66 #define VCMD_set_sched VC_CMD(SCHED, 1, 2)
68 struct vcmd_set_sched_v2 {
77 #define SCHED_KEEP (-2)
81 extern int vc_set_sched_v1(uint32_t, void __user *);
82 extern int vc_set_sched(uint32_t, void __user *);
85 #define VAVAVOOM_RATIO 50
90 /* scheduling stuff */
92 int effective_vavavoom(struct task_struct *, int);
94 int vx_tokens_recalc(struct vx_info *);
98 static inline int vx_tokens_avail(struct vx_info *vxi)
100 return atomic_read(&vxi->sched.tokens);
103 static inline void vx_consume_token(struct vx_info *vxi)
105 atomic_dec(&vxi->sched.tokens);
108 static inline int vx_need_resched(struct task_struct *p)
110 #ifdef CONFIG_VSERVER_HARDCPU
111 struct vx_info *vxi = p->vx_info;
117 if (atomic_read(&vxi->vx_refcount) < 1)
118 printk("need_resched: p=%p, s=%ld, ref=%d, id=%d/%d\n",
119 p, p->state, atomic_read(&vxi->vx_refcount),
121 if ((tokens = vx_tokens_avail(vxi)) > 0)
122 vx_consume_token(vxi);
123 return ((p->time_slice == 0) || (tokens < 1));
127 return (p->time_slice == 0);
131 #endif /* __KERNEL__ */
133 #endif /* _VX_SCHED_H */