aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Kenna <cjk@cs.unc.edu>2012-05-04 12:20:52 -0400
committerChristopher Kenna <cjk@cs.unc.edu>2012-05-04 12:20:52 -0400
commit803e44774958312123b0bee0fcffd4e97c7c88aa (patch)
treee3014f61ed2bff071569745c2ab7e618001c42e4
parentb881d3cdf01cd463073b016261b9af2cfe3ed417 (diff)
Move nr_colors into color_cache_info and extern it for everyone.
-rw-r--r--arch/x86/kernel/cpu/intel_cacheinfo.c2
-rw-r--r--include/litmus/color.h4
-rw-r--r--include/litmus/rt_param.h12
-rw-r--r--litmus/color.c34
-rw-r--r--litmus/color_dev.c8
5 files changed, 36 insertions, 24 deletions
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 482e068a236a..95d5636720a6 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -1217,8 +1217,6 @@ static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
1217 1217
1218#include <litmus/color.h> 1218#include <litmus/color.h>
1219 1219
1220extern struct color_cache_info color_cache_info;
1221
1222static void set_color_vars(void) 1220static void set_color_vars(void)
1223{ 1221{
1224 struct _cpuid4_info *leaf = CPUID4_INFO_IDX( 1222 struct _cpuid4_info *leaf = CPUID4_INFO_IDX(
diff --git a/include/litmus/color.h b/include/litmus/color.h
index 250f08a6e1f3..03524692511a 100644
--- a/include/litmus/color.h
+++ b/include/litmus/color.h
@@ -14,8 +14,12 @@ struct color_cache_info {
14 unsigned long line_size; 14 unsigned long line_size;
15 unsigned long ways; 15 unsigned long ways;
16 unsigned long sets; 16 unsigned long sets;
17 unsigned long nr_colors;
17}; 18};
18 19
20/* defined in litmus/color.c */
21extern struct color_cache_info color_cache_info;
22
19struct page* get_colored_page(unsigned long); 23struct page* get_colored_page(unsigned long);
20void add_page_to_color_list(struct page*); 24void add_page_to_color_list(struct page*);
21void add_page_to_alloced_list(struct page*, struct vm_area_struct*); 25void add_page_to_alloced_list(struct page*, struct vm_area_struct*);
diff --git a/include/litmus/rt_param.h b/include/litmus/rt_param.h
index 2991fff58bc6..7dfcd333bd18 100644
--- a/include/litmus/rt_param.h
+++ b/include/litmus/rt_param.h
@@ -78,13 +78,17 @@ struct control_page {
78}; 78};
79 79
80#ifndef __KERNEL__ 80#ifndef __KERNEL__
81/* XXX This is a terrible hack. */ 81/*
82#if defined(CONFIG_X86) 82 * XXX This is a terrible hack so liblitmus can use the PAGE_SIZE macro.
83 * We should fix liblitmus to do setup the page size at runtime.
84 */
85#if (ARCH == x86_64)
83#define PAGE_SIZE 4096 86#define PAGE_SIZE 4096
84#elif defined(CONFIG_SPARC) || (ARCH == sparc64) 87#elif (ARCH == sparc64)
85#define PAGE_SIZE 8192 88#define PAGE_SIZE 8192
86#endif /* X86/SPARC */
87#endif 89#endif
90#endif /* ifndef __KERNEL__ */
91
88typedef uint8_t color_t; 92typedef uint8_t color_t;
89#define COLORS_PER_CONTROL_PAGE (PAGE_SIZE / sizeof(color_t)) 93#define COLORS_PER_CONTROL_PAGE (PAGE_SIZE / sizeof(color_t))
90struct color_ctrl_page { 94struct color_ctrl_page {
diff --git a/litmus/color.c b/litmus/color.c
index 93d12a718543..21bb0ee81895 100644
--- a/litmus/color.c
+++ b/litmus/color.c
@@ -32,10 +32,7 @@ static struct color_group *color_groups;
32 32
33 33
34/* non-static: extern'ed in various files */ 34/* non-static: extern'ed in various files */
35unsigned long nr_colors;
36#ifdef CONFIG_X86
37struct color_cache_info color_cache_info; 35struct color_cache_info color_cache_info;
38#endif
39int color_sysctl_add_pages_data; 36int color_sysctl_add_pages_data;
40 37
41static inline unsigned long page_color(struct page *page) 38static inline unsigned long page_color(struct page *page)
@@ -67,7 +64,7 @@ struct page* get_colored_page(unsigned long color)
67 struct color_group *cgroup; 64 struct color_group *cgroup;
68 struct page *page = NULL; 65 struct page *page = NULL;
69 66
70 if (color >= nr_colors) 67 if (color >= color_cache_info.nr_colors)
71 goto out; 68 goto out;
72 69
73 cgroup = &color_groups[color]; 70 cgroup = &color_groups[color];
@@ -93,7 +90,7 @@ static unsigned long smallest_nr_pages(void)
93{ 90{
94 unsigned long i, min_pages = -1; 91 unsigned long i, min_pages = -1;
95 struct color_group *cgroup; 92 struct color_group *cgroup;
96 for (i = 0; i < nr_colors; ++i) { 93 for (i = 0; i < color_cache_info.nr_colors; ++i) {
97 cgroup = &color_groups[i]; 94 cgroup = &color_groups[i];
98 if (atomic_read(&cgroup->nr_pages) < min_pages) 95 if (atomic_read(&cgroup->nr_pages) < min_pages)
99 min_pages = atomic_read(&cgroup->nr_pages); 96 min_pages = atomic_read(&cgroup->nr_pages);
@@ -226,7 +223,7 @@ int color_nr_pages_handler(struct ctl_table *table, int write, void __user *buff
226 ret = -EPERM; 223 ret = -EPERM;
227 goto out; 224 goto out;
228 } 225 }
229 for (i = 0; i < nr_colors; ++i) { 226 for (i = 0; i < color_cache_info.nr_colors; ++i) {
230 cgroup = &color_groups[i]; 227 cgroup = &color_groups[i];
231 buf = ((char*)table->data) + used; 228 buf = ((char*)table->data) + used;
232 used += snprintf(buf, table->maxlen - used, ONE_COLOR_FMT, 229 used += snprintf(buf, table->maxlen - used, ONE_COLOR_FMT,
@@ -275,16 +272,24 @@ static int __init init_mask(void)
275 BUG_ON(PAGE_SIZE >= (color_cache_info.sets << line_size_log)); 272 BUG_ON(PAGE_SIZE >= (color_cache_info.sets << line_size_log));
276 color_mask = ((color_cache_info.sets << line_size_log) - 1) ^ 273 color_mask = ((color_cache_info.sets << line_size_log) - 1) ^
277 (PAGE_SIZE - 1); 274 (PAGE_SIZE - 1);
278 nr_colors = (color_mask >> PAGE_SHIFT) + 1; 275 color_cache_info.nr_colors = (color_mask >> PAGE_SHIFT) + 1;
279out: 276out:
280 return err; 277 return err;
281} 278}
282#elif defined(CONFIG_SPARC) /* X86 */ 279#elif defined(CONFIG_SPARC) /* X86 */
283static int __init init_mask(void) 280static int __init init_mask(void)
284{ 281{
285 /* bits 17:13 */ 282 /*
286 color_mask = 0x3e000UL; 283 * Static assuming we are using Flare (our Niagara machine).
287 nr_colors = (1 << hweight_long(color_mask)); 284 * This machine has weirdness with cache banks, and I don't want
285 * to waste time trying to auto-detect this.
286 */
287 color_mask = 0x3e000UL; /* bits 17:13 */
288 color_cache_info.size = 3 * 1024 * 1024; /* 3 MB */
289 color_cache_info.line_size = 64;
290 color_cache_info.ways = 12;
291 color_cache_info.sets = 1024 * 4;
292 color_cache_info.nr_colors = (1 << hweight_long(color_mask));
288 return 0; 293 return 0;
289} 294}
290#endif /* SPARC/X86 */ 295#endif /* SPARC/X86 */
@@ -297,14 +302,15 @@ static int __init init_color_groups(void)
297 unsigned long i; 302 unsigned long i;
298 int err = 0; 303 int err = 0;
299 304
300 color_groups = kmalloc(nr_colors * sizeof(struct color_group), GFP_KERNEL); 305 color_groups = kmalloc(color_cache_info.nr_colors *
306 sizeof(struct color_group), GFP_KERNEL);
301 if (!color_groups) { 307 if (!color_groups) {
302 printk(KERN_WARNING "Could not allocate color groups.\n"); 308 printk(KERN_WARNING "Could not allocate color groups.\n");
303 err = -ENOMEM; 309 err = -ENOMEM;
304 goto out; 310 goto out;
305 } 311 }
306 312
307 for (i = 0; i < nr_colors; ++i) { 313 for (i = 0; i < color_cache_info.nr_colors; ++i) {
308 cgroup = &color_groups[i]; 314 cgroup = &color_groups[i];
309 atomic_set(&cgroup->nr_pages, 0); 315 atomic_set(&cgroup->nr_pages, 0);
310 INIT_LIST_HEAD(&cgroup->list); 316 INIT_LIST_HEAD(&cgroup->list);
@@ -326,9 +332,9 @@ static int __init init_color(void)
326 332
327 err = init_mask(); 333 err = init_mask();
328 printk("PAGE_SIZE: %lu Color mask: 0x%lx Total colors: %lu\n", 334 printk("PAGE_SIZE: %lu Color mask: 0x%lx Total colors: %lu\n",
329 PAGE_SIZE, color_mask, nr_colors); 335 PAGE_SIZE, color_mask, color_cache_info.nr_colors);
330 336
331 BUG_ON(LOCKDEP_MAX_NR_COLORS < nr_colors); 337 BUG_ON(LOCKDEP_MAX_NR_COLORS < color_cache_info.nr_colors);
332 err = init_color_groups(); 338 err = init_color_groups();
333 return err; 339 return err;
334} 340}
diff --git a/litmus/color_dev.c b/litmus/color_dev.c
index d681f57be01f..7ccdaf03740b 100644
--- a/litmus/color_dev.c
+++ b/litmus/color_dev.c
@@ -102,8 +102,6 @@ static int map_color_ctrl_page(struct vm_area_struct *vma)
102 /* Map it into the vma. Make sure to use PAGE_SHARED, otherwise 102 /* Map it into the vma. Make sure to use PAGE_SHARED, otherwise
103 * userspace actually gets a copy-on-write page. */ 103 * userspace actually gets a copy-on-write page. */
104 err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, PAGE_SHARED); 104 err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, PAGE_SHARED);
105 TRACE_CUR("page shared: guess:0x1(63)...1??111 actual:0x%lx\n", PAGE_SHARED);
106 /* present, RW, user, accessed, NX=63 */
107 105
108 if (err) 106 if (err)
109 TRACE_CUR(CTRL_NAME ": remap_pfn_range() failed (%d)\n", err); 107 TRACE_CUR(CTRL_NAME ": remap_pfn_range() failed (%d)\n", err);
@@ -181,10 +179,12 @@ static int do_map_colored_pages(struct vm_area_struct *vma)
181 clear_user_highpage(page, addr); 179 clear_user_highpage(page, addr);
182#endif 180#endif
183 TRACE_CUR(ALLOC_NAME ": insert page (pa:0x%10llx, pfn:%8lu, " 181 TRACE_CUR(ALLOC_NAME ": insert page (pa:0x%10llx, pfn:%8lu, "
184 "color:%3lu) at 0x%lx (flags:%lx prot:%lx\n", 182 "color:%3lu) at 0x%lx (flags:%16lx prot:%16lx) "
183 "PAGE_SHARED:0x%16lx\n",
185 page_to_phys(page), 184 page_to_phys(page),
186 page_to_pfn(page), this_color, addr, 185 page_to_pfn(page), this_color, addr,
187 vma->vm_flags, pgprot_val(vma->vm_page_prot)); 186 vma->vm_flags, pgprot_val(vma->vm_page_prot),
187 PAGE_SHARED);
188 //err = vm_insert_page(vma, addr, page); 188 //err = vm_insert_page(vma, addr, page);
189 err = remap_pfn_range(vma, addr, page_to_pfn(page), 189 err = remap_pfn_range(vma, addr, page_to_pfn(page),
190 PAGE_SIZE, PAGE_SHARED); 190 PAGE_SIZE, PAGE_SHARED);