This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / kernel / ckrm_sched.c
1 /* kernel/ckrm_sched.c - Supporting functions for ckrm scheduling
2  *
3  * Copyright (C) Haoqiang Zheng,  IBM Corp. 2004
4  *           (C) Hubertus Franke, IBM Corp. 2004
5  * 
6  * Latest version, more details at http://ckrm.sf.net
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  */
14 #include <linux/mm.h>
15 #include <linux/init.h>
16 #include <linux/ckrm_sched.h>
17
18 /*******************************************************/
19 /*                CVT Management                       */
20 /*******************************************************/
21 #define CVT_WINDOW_SIZE (CLASSQUEUE_SIZE << CLASS_BONUS_RATE)
22 static CVT_t max_CVT = CVT_WINDOW_SIZE;
23
24 /*
25  *  Also ensure that the classes global cvt is upgraded to the 
26  * minimum CVT in the system, as a class might not have run for a while
27  */
28 static void update_global_cvt(struct ckrm_cpu_class *cpu_class, int cpu)
29 {
30         struct ckrm_local_runqueue *class_queue =
31             get_ckrm_local_runqueue(cpu_class, cpu);
32         CVT_t min_cvt;
33         CVT_t local_cvt_old = class_queue->local_cvt;
34
35         spin_lock(&cvt_lock);
36         if (class_queue->uncounted_cvt) {
37                 cpu_class->global_cvt += class_queue->uncounted_cvt;
38                 class_queue->uncounted_cvt = 0;
39         }
40         min_cvt = max_CVT - CVT_WINDOW_SIZE;
41         if (cpu_class->global_cvt < min_cvt)
42                 cpu_class->global_cvt = min_cvt;
43         else  if (cpu_class->global_cvt > max_CVT)
44                 max_CVT = cpu_class->global_cvt;
45
46 /* update local cvt from global cvt*/
47 #if 0
48         class_queue->local_cvt = cpu_class->global_cvt;
49 #endif
50         spin_unlock(&cvt_lock);
51
52         if (class_queue->local_cvt != local_cvt_old)
53                 update_class_priority(class_queue);
54 }
55
56 /*
57  * class_list_lock must have been acquired 
58  */
59 void update_global_cvts(int this_cpu)
60 {
61         struct ckrm_cpu_class *clsptr;
62         struct ckrm_local_runqueue *class_queue;
63
64         /*for each class*/
65         list_for_each_entry(clsptr, &active_cpu_classes, links) {
66                 update_global_cvt(clsptr, this_cpu);
67                 class_queue = get_ckrm_local_runqueue(clsptr, this_cpu);
68                 clsptr->stat.total_ns += class_queue->uncounted_ns;
69                 class_queue->uncounted_ns = 0;
70         }
71 }