aboutsummaryrefslogtreecommitdiffstats
path: root/litmus
diff options
context:
space:
mode:
authorChristopher Kenna <cjk@cs.unc.edu>2012-04-08 17:48:18 -0400
committerChristopher Kenna <cjk@cs.unc.edu>2012-04-08 17:48:18 -0400
commit461e3fdc9cfcc51cfbd6ea9833ff6715b9cb235f (patch)
tree24b24584200ca408bec91cdc3291e1634427e304 /litmus
parentae95a4582d707de8a57a8159ea81b16ba7bddd54 (diff)
Allocate colored pages according to color ctrl page.
Diffstat (limited to 'litmus')
-rw-r--r--litmus/color.c15
-rw-r--r--litmus/color_dev.c61
2 files changed, 39 insertions, 37 deletions
diff --git a/litmus/color.c b/litmus/color.c
index a3cc193418c0..6f017e388c12 100644
--- a/litmus/color.c
+++ b/litmus/color.c
@@ -10,10 +10,6 @@
10#include <litmus/color.h> 10#include <litmus/color.h>
11#include <litmus/litmus.h> /* for in_list(...) */ 11#include <litmus/litmus.h> /* for in_list(...) */
12 12
13#define MPRINT(fmt, args...) \
14 printk(KERN_INFO "[%s@%s:%d]: " fmt, \
15 __FUNCTION__, __FILE__, __LINE__, ## args)
16
17#define PAGES_PER_COLOR 2000 13#define PAGES_PER_COLOR 2000
18 14
19/* 15/*
@@ -77,10 +73,14 @@ struct page* get_colored_page(unsigned long color)
77{ 73{
78 struct color_group *cgroup; 74 struct color_group *cgroup;
79 struct page *page = NULL; 75 struct page *page = NULL;
80 BUG_ON(color >= nr_colors); 76
77 if (color >= nr_colors)
78 goto out;
79
81 cgroup = &color_groups[color]; 80 cgroup = &color_groups[color];
82 spin_lock(&cgroup->lock); 81 spin_lock(&cgroup->lock);
83 if (unlikely(!atomic_read(&cgroup->nr_pages))) { 82 if (unlikely(!atomic_read(&cgroup->nr_pages))) {
83 TRACE_CUR("No free %lu colored pages.\n", color);
84 printk(KERN_WARNING "no free %lu colored pages.\n", color); 84 printk(KERN_WARNING "no free %lu colored pages.\n", color);
85 goto out_unlock; 85 goto out_unlock;
86 } 86 }
@@ -91,6 +91,7 @@ struct page* get_colored_page(unsigned long color)
91 ClearPageLRU(page); 91 ClearPageLRU(page);
92out_unlock: 92out_unlock:
93 spin_unlock(&cgroup->lock); 93 spin_unlock(&cgroup->lock);
94out:
94 return page; 95 return page;
95} 96}
96 97
@@ -117,7 +118,7 @@ static int do_add_pages(void)
117 page = alloc_page(GFP_HIGHUSER | __GFP_ZERO | 118 page = alloc_page(GFP_HIGHUSER | __GFP_ZERO |
118 __GFP_MOVABLE); 119 __GFP_MOVABLE);
119 if (unlikely(!page)) { 120 if (unlikely(!page)) {
120 MPRINT("could not allocate pages\n"); 121 printk(KERN_WARNING "Could not allocate pages.\n");
121 ret = -ENOMEM; 122 ret = -ENOMEM;
122 goto out; 123 goto out;
123 } 124 }
@@ -146,8 +147,6 @@ static int do_reclaim_pages(void)
146 ClearPageLRU(page); 147 ClearPageLRU(page);
147 add_page_to_color_list(page); 148 add_page_to_color_list(page);
148 nr_reclaimed++; 149 nr_reclaimed++;
149 TRACE_CUR("Reclaimed page (pfn:%lu phys:0x%lx).\n",
150 page_to_pfn(page), page_to_phys(page));
151 } 150 }
152 } 151 }
153 spin_unlock(&alloced_pages.lock); 152 spin_unlock(&alloced_pages.lock);
diff --git a/litmus/color_dev.c b/litmus/color_dev.c
index b8218b6d1d9c..6e7ab3a28b87 100644
--- a/litmus/color_dev.c
+++ b/litmus/color_dev.c
@@ -11,11 +11,6 @@
11#define ALLOC_NAME "litmus/color_alloc" 11#define ALLOC_NAME "litmus/color_alloc"
12#define CTRL_NAME "litmus/color_ctrl" 12#define CTRL_NAME "litmus/color_ctrl"
13 13
14static struct non_rt_colors {
15 spinlock_t lock;
16 unsigned long color;
17} non_rt_colors;
18
19extern unsigned long nr_colors; 14extern unsigned long nr_colors;
20 15
21/*********************************************************** 16/***********************************************************
@@ -145,25 +140,27 @@ out:
145 * Allocation device 140 * Allocation device
146***********************************************************/ 141***********************************************************/
147 142
148static int map_colored_pages_non_rt(struct vm_area_struct *vma) 143#define vma_nr_pages(vma) \
144 ({unsigned long v = ((vma->vm_end - vma->vm_start) >> PAGE_SHIFT); v;})
145
146#define next_color(c) ({unsigned long _x = (c + 1) % nr_colors; _x;})
147
148static int do_map_colored_pages(struct vm_area_struct *vma)
149{ 149{
150 unsigned long color, mapped; 150 const unsigned long nr_pages = vma_nr_pages(vma);
151 unsigned long mapped;
152 uint32_t *cur_color;
151 int err; 153 int err;
152 const unsigned long nr_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
153 154
154 spin_lock(&non_rt_colors.lock); 155 TRACE_CUR(ALLOC_NAME ": allocating %lu pages\n", nr_pages);
155 color = non_rt_colors.color;
156 non_rt_colors.color = (non_rt_colors.color + nr_pages) % nr_colors;
157 spin_unlock(&non_rt_colors.lock);
158 156
159 TRACE_CUR(ALLOC_NAME ": allocating %lu pages from color %lu.\n", 157 for (mapped = 0, cur_color = tsk_rt(current)->color_ctrl_page->colors;
160 nr_pages, color); 158 mapped < nr_pages;
161 159 mapped++, cur_color++)
162 for (mapped = 0; mapped < nr_pages;
163 mapped++, color = (color + 1) % nr_colors)
164 { 160 {
161 const unsigned long color = *cur_color;
162 const unsigned long addr = vma->vm_start + (mapped << PAGE_SHIFT);
165 struct page *page = get_colored_page(color); 163 struct page *page = get_colored_page(color);
166 const unsigned long addr = vma->vm_start + PAGE_SIZE * mapped;
167 164
168 if (!page) { 165 if (!page) {
169 TRACE_CUR(ALLOC_NAME ": Could not get page with " 166 TRACE_CUR(ALLOC_NAME ": Could not get page with "
@@ -189,17 +186,25 @@ static int map_colored_pages_non_rt(struct vm_area_struct *vma)
189 return err; 186 return err;
190} 187}
191 188
192static int map_colored_pages_rt(struct vm_area_struct *vma)
193{
194 /* TODO */
195 return -EINVAL;
196}
197
198static int map_colored_pages(struct vm_area_struct *vma) 189static int map_colored_pages(struct vm_area_struct *vma)
199{ 190{
200 if (likely(is_realtime(current))) 191 int err = 0;
201 return map_colored_pages_rt(vma); 192
202 return map_colored_pages_non_rt(vma); 193 if (!tsk_rt(current)->color_ctrl_page) {
194 TRACE_CUR("Process has no color control page.\n");
195 err = -EINVAL;
196 goto out;
197 }
198
199 if (COLORS_PER_CONTROL_PAGE < vma_nr_pages(vma)) {
200 TRACE_CUR("Max page request %lu but want %lu.\n",
201 COLORS_PER_CONTROL_PAGE, vma_nr_pages(vma));
202 err = -EINVAL;
203 goto out;
204 }
205 err = do_map_colored_pages(vma);
206out:
207 return err;
203} 208}
204 209
205static void litmus_color_alloc_vm_close(struct vm_area_struct *vma) 210static void litmus_color_alloc_vm_close(struct vm_area_struct *vma)
@@ -297,8 +302,6 @@ static int __init init_dev(const char* name, struct miscdevice *dev)
297static int __init init_color_devices(void) 302static int __init init_color_devices(void)
298{ 303{
299 int err; 304 int err;
300 spin_lock_init(&non_rt_colors.lock);
301 non_rt_colors.color = 0;
302 305
303 printk("Allocating LITMUS^RT color devices.\n"); 306 printk("Allocating LITMUS^RT color devices.\n");
304 err = init_dev(ALLOC_NAME, &litmus_color_alloc_dev); 307 err = init_dev(ALLOC_NAME, &litmus_color_alloc_dev);