4 #include "vserver/base.h"
5 #include "vserver/context.h"
6 #include "vserver/sched.h"
9 #define VAVAVOOM_RATIO 50
11 #define MAX_PRIO_BIAS 20
12 #define MIN_PRIO_BIAS -20
15 #ifdef CONFIG_VSERVER_HARDCPU
18 * effective_prio - return the priority that is based on the static
19 * priority but is modified by bonuses/penalties.
21 * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
22 * into a -4 ... 0 ... +4 bonus/penalty range.
24 * Additionally, we scale another amount based on the number of
25 * CPU tokens currently held by the context, if the process is
26 * part of a context (and the appropriate SCHED flag is set).
27 * This ranges from -5 ... 0 ... +15, quadratically.
29 * So, the total bonus is -9 .. 0 .. +19
30 * We use ~50% of the full 0...39 priority range so that:
32 * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
33 * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
34 * unless that context is far exceeding its CPU allocation.
36 * Both properties are important to certain workloads.
39 int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
43 /* lots of tokens = lots of vavavoom
44 * no tokens = no vavavoom */
45 if ((vavavoom = sched_pc->tokens) >= 0) {
46 max = sched_pc->tokens_max;
47 vavavoom = max - vavavoom;
49 vavavoom = max_prio * VAVAVOOM_RATIO / 100
50 * (vavavoom*vavavoom - (max >> 2)) / max;
58 int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
60 struct vx_info *vxi = p->vx_info;
61 struct _vx_sched_pc *sched_pc;
66 sched_pc = &vx_cpu(vxi, sched_pc);
67 if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
68 int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
70 sched_pc->vavavoom = vavavoom;
73 prio += sched_pc->prio_bias;
77 #else /* !CONFIG_VSERVER_HARDCPU */
80 int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
82 struct vx_info *vxi = p->vx_info;
85 prio += vx_cpu(vxi, sched_pc).prio_bias;
89 #endif /* CONFIG_VSERVER_HARDCPU */
92 static inline void vx_account_user(struct vx_info *vxi,
93 cputime_t cputime, int nice)
97 vx_cpu(vxi, sched_pc).user_ticks += cputime;
100 static inline void vx_account_system(struct vx_info *vxi,
101 cputime_t cputime, int idle)
105 vx_cpu(vxi, sched_pc).sys_ticks += cputime;
109 #warning duplicate inclusion