1 /* include/linux/ckrm_classqueue.h : cpu control for CKRM
3 * Copyright (C) Haoqiang Zheng, IBM Corp. 2003
4 * (C) Hubertus Franke, IBM Corp. 2003
6 * Circular queue functionality for CKRM cpu controller
8 * Latest version, more details at http://ckrm.sf.net
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
22 * clean up, add comments
28 * Please read Documentation/ckrm/cpu_sched for a general overview of
29 * how the O(1) CKRM scheduler.
31 * ckrm_classqueue.h provides the definition to maintain the
32 * per cpu class runqueue.
36 #ifndef _CKRM_CLASSQUEUE_H
37 #define _CKRM_CLASSQUEUE_H
39 #include <linux/list.h>
41 #warning mef: is classqueue_size big enough for PlanetLab
42 #define CLASSQUEUE_SIZE_SHIFT 7
43 #define CLASSQUEUE_SIZE ( 1 << CLASSQUEUE_SIZE_SHIFT )
44 #define CQ_BITMAP_SIZE ((((CLASSQUEUE_SIZE+1+7)/8)+sizeof(long)-1)/sizeof(long))
47 * struct cq_prio_array: duplicates prio_array defined in sched.c
49 struct cq_prio_array {
51 unsigned long bitmap[CQ_BITMAP_SIZE];
52 struct list_head queue[CLASSQUEUE_SIZE];
56 * struct classqueue_struct - a runqueue of class local runqueues
57 * @array: priority array
58 * @base: base priority
59 * @base_offset: index in array for the base
61 * classqueue can be thought of as runqueue of lrq's (per cpu object of
62 * a CKRM class as task runqueue (instead of runqueue of tasks)
63 * - a class's local lrq is enqueued into the local classqueue when a
64 * first task is enqueued lrq.
65 * - a class's local lrq is removed from the local classqueue when the
66 * last task is dequeued from the lrq.
67 * - lrq's are ordered based on their priority (determined elsewhere)
68 * ( CKRM: caculated based on it's progress (cvt) and urgency (top_priority)
71 struct classqueue_struct {
72 int enabled; // support dynamic on/off
74 unsigned long base_offset;
75 struct cq_prio_array array;
79 * struct cq_node_struct:
80 * - the link object between class local runqueue and classqueue
81 * @list: links the class local runqueue to classqueue
82 * @prio: class priority
83 * @index: real index into the classqueue array, calculated based on priority
85 struct cq_node_struct {
86 struct list_head list;
90 * set when the class jump out of the class queue window
91 * class with this value set should be repositioned whenever classqueue slides window
92 * real_prio is valid when need_repos is set
97 typedef struct cq_node_struct cq_node_t;
99 static inline void cq_node_init(cq_node_t * node)
104 node->need_repos = 0;
105 INIT_LIST_HEAD(&node->list);
108 /*if the class is in classqueue*/
109 static inline int cls_in_classqueue(cq_node_t * node)
111 return !list_empty(&node->list);
114 /*initialize the data structure*/
115 int classqueue_init(struct classqueue_struct *cq, int enabled);
117 /*add the class to classqueue at given priority */
118 void classqueue_enqueue(struct classqueue_struct *cq,
119 cq_node_t * node, int prio);
121 /*remove the class from classqueue */
122 void classqueue_dequeue(struct classqueue_struct *cq, cq_node_t * node);
124 /*change the position of the class in classqueue*/
125 void classqueue_update_prio(struct classqueue_struct *cq,
126 cq_node_t * node, int new_prio);
128 /*return the first class in classqueue*/
129 cq_node_t *classqueue_get_head(struct classqueue_struct *cq);
131 /*update the base priority of the classqueue*/
132 void classqueue_update_base(struct classqueue_struct *cq);
135 * class_compare_prio: compare the priority of this two nodes
137 static inline int class_compare_prio(struct cq_node_struct* node1,
138 struct cq_node_struct* node2)
140 return ( node1->prio - node2->prio);