aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChengYang Fu <chengyangfu@gmail.com>2015-03-23 23:31:09 -0400
committerChengYang Fu <chengyangfu@gmail.com>2015-03-23 23:31:09 -0400
commit0041e83c7994510cebe9f335eb30b6049d8b4c1f (patch)
treee9ab018060e3cad45a17df529e859303d96addd7
parent56a820730e5ba600fa2654db635cf21b6cde5f21 (diff)
solve the bug in bank_proc.c
-rw-r--r--litmus/bank_proc.c95
1 files changed, 79 insertions, 16 deletions
diff --git a/litmus/bank_proc.c b/litmus/bank_proc.c
index 7cf07ee1dad9..3cf9cda9bbc0 100644
--- a/litmus/bank_proc.c
+++ b/litmus/bank_proc.c
@@ -26,7 +26,7 @@
26#define CACHE_MASK 0x0000f000 26#define CACHE_MASK 0x0000f000
27#define CACHE_SHIFT 12 27#define CACHE_SHIFT 12
28 28
29#define PAGES_PER_COLOR 256 29#define PAGES_PER_COLOR 512
30unsigned int NUM_PAGE_LIST; //8*16 30unsigned int NUM_PAGE_LIST; //8*16
31 31
32unsigned int number_banks; 32unsigned int number_banks;
@@ -37,6 +37,8 @@ unsigned int set_partition_min = 0;
37unsigned int bank_partition_max = 0x000000ff; 37unsigned int bank_partition_max = 0x000000ff;
38unsigned int bank_partition_min = 0; 38unsigned int bank_partition_min = 0;
39 39
40int show_page_pool = 0;
41
40unsigned int set_partition[9] = { 42unsigned int set_partition[9] = {
41 0x00000003, /* Core 0, and Level A*/ 43 0x00000003, /* Core 0, and Level A*/
42 0x00000003, /* Core 0, and Level B*/ 44 0x00000003, /* Core 0, and Level B*/
@@ -58,7 +60,7 @@ unsigned int bank_partition[9] = {
58 0x00000040, /* Core 2, and Level B*/ 60 0x00000040, /* Core 2, and Level B*/
59 0x00000080, /* Core 3, and Level A*/ 61 0x00000080, /* Core 3, and Level A*/
60 0x00000080, /* Core 3, and Level B*/ 62 0x00000080, /* Core 3, and Level B*/
61 0x0000000f, /* Level C */ 63 0x0000000c, /* Level C */
62}; 64};
63 65
64unsigned int set_index[9] = { 66unsigned int set_index[9] = {
@@ -161,9 +163,11 @@ static inline unsigned int page_list_index(struct page *page)
161 */ 163 */
162static unsigned long smallest_nr_pages(void) 164static unsigned long smallest_nr_pages(void)
163{ 165{
164 unsigned long i, min_pages = -1; 166 unsigned long i, min_pages;
165 struct color_group *cgroup; 167 struct color_group *cgroup;
166 for (i = 0; i < NUM_PAGE_LIST; ++i) { 168 cgroup = &color_groups[16*2];
169 min_pages =atomic_read(&cgroup->nr_pages);
170 for (i = 16*2; i < NUM_PAGE_LIST; ++i) {
167 cgroup = &color_groups[i]; 171 cgroup = &color_groups[i];
168 if (atomic_read(&cgroup->nr_pages) < min_pages) 172 if (atomic_read(&cgroup->nr_pages) < min_pages)
169 min_pages = atomic_read(&cgroup->nr_pages); 173 min_pages = atomic_read(&cgroup->nr_pages);
@@ -175,9 +179,13 @@ static void show_nr_pages(void)
175{ 179{
176 unsigned long i; 180 unsigned long i;
177 struct color_group *cgroup; 181 struct color_group *cgroup;
182 printk("show nr pages***************************************\n");
178 for (i = 0; i < NUM_PAGE_LIST; ++i) { 183 for (i = 0; i < NUM_PAGE_LIST; ++i) {
179 cgroup = &color_groups[i]; 184 cgroup = &color_groups[i];
180 printk("i =%d, nr_pages = %d\n", i, atomic_read(&cgroup->nr_pages)); 185 printk("(%03d) = %03d, ", i, atomic_read(&cgroup->nr_pages));
186 if((i % 8) ==7){
187 printk("\n");
188 }
181 } 189 }
182} 190}
183 191
@@ -193,6 +201,7 @@ void add_page_to_color_list(struct page *page)
193 spin_lock(&cgroup->lock); 201 spin_lock(&cgroup->lock);
194 list_add_tail(&page->lru, &cgroup->list); 202 list_add_tail(&page->lru, &cgroup->list);
195 atomic_inc(&cgroup->nr_pages); 203 atomic_inc(&cgroup->nr_pages);
204 SetPageLRU(page);
196 spin_unlock(&cgroup->lock); 205 spin_unlock(&cgroup->lock);
197} 206}
198 207
@@ -210,30 +219,65 @@ static int do_add_pages(void)
210 unsigned long color; 219 unsigned long color;
211 int ret = 0; 220 int ret = 0;
212 int i = 0; 221 int i = 0;
222 int free_counter = 0;
223 unsigned long counter[128]= {0};
224
225 printk("Before refill : \n");
226 show_nr_pages();
213 227
214 // until all the page lists contain enough pages 228 // until all the page lists contain enough pages
215 //for (i =0; i<5; i++) { 229 //for (i =0; i<5; i++) {
216 while (smallest_nr_pages() < PAGES_PER_COLOR) { 230 for (i=0; i< 1024*100;i++) {
217 231// while (smallest_nr_pages() < PAGES_PER_COLOR) {
232 // printk("smallest = %d\n", smallest_nr_pages());
218 page = alloc_page(GFP_HIGHUSER_MOVABLE); 233 page = alloc_page(GFP_HIGHUSER_MOVABLE);
234 // page = alloc_pages_exact_node(0, GFP_HIGHUSER_MOVABLE, 0);
235
219 if (unlikely(!page)) { 236 if (unlikely(!page)) {
220 printk(KERN_WARNING "Could not allocate pages.\n"); 237 printk(KERN_WARNING "Could not allocate pages.\n");
221 ret = -ENOMEM; 238 ret = -ENOMEM;
222 goto out; 239 goto out;
223 } 240 }
224 color = page_list_index(page); 241 color = page_list_index(page);
242 counter[color]++;
243 // printk("page(%d) = color %x, bank %x, [color] =%d \n", color, page_color(page), page_bank(page), atomic_read(&color_groups[color].nr_pages));
225 //show_nr_pages(); 244 //show_nr_pages();
226 //printk("before : nr_pages = %d\n", atomic_read(&color_groups[color].nr_pages)); 245 if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR && color>=32) {
227 if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR) {
228 add_page_to_color_list(page); 246 add_page_to_color_list(page);
247 // printk("add page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page));
229 } else{ 248 } else{
230 // Pages here will be freed later 249 // Pages here will be freed later
231 list_add_tail(&page->lru, &free_later); 250 list_add_tail(&page->lru, &free_later);
251 free_counter++;
252 //list_del(&page->lru);
253 // __free_page(page);
254 // printk("useless page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page));
232 } 255 }
233 //show_nr_pages(); 256 //show_nr_pages();
234 //printk("after : nr_pages = %d\n", atomic_read(&color_groups[color].nr_pages)); 257 /*
258 if(free_counter >= PAGES_PER_COLOR)
259 {
260 printk("free unwanted page list eariler");
261 free_counter = 0;
262 list_for_each_entry_safe(page, page_tmp, &free_later, lru) {
263 list_del(&page->lru);
264 __free_page(page);
265 }
266
267 show_nr_pages();
268 }
269 */
270 }
271 printk("page counter = \n");
272 for (i=0; i<128; i++)
273 {
274 printk("(%03d) = %4d, ", i , counter[i]);
275 if(i%8 == 7){
276 printk("\n");
277 }
235 278
236 } 279 }
280 printk("After refill : \n");
237 show_nr_pages(); 281 show_nr_pages();
238#if 1 282#if 1
239 // Free the unwanted pages 283 // Free the unwanted pages
@@ -274,10 +318,10 @@ static struct page *new_alloc_page_color( unsigned long color)
274 } 318 }
275 rPage = list_first_entry(&cgroup->list, struct page, lru); 319 rPage = list_first_entry(&cgroup->list, struct page, lru);
276 BUG_ON(page_count(rPage) > 1); 320 BUG_ON(page_count(rPage) > 1);
277 get_page(rPage); 321// get_page(rPage);
278 list_del(&rPage->lru); 322 list_del(&rPage->lru);
279 atomic_dec(&cgroup->nr_pages); 323 atomic_dec(&cgroup->nr_pages);
280// ClearPageLRU(rPage); 324 ClearPageLRU(rPage);
281out_unlock: 325out_unlock:
282 spin_unlock(&cgroup->lock); 326 spin_unlock(&cgroup->lock);
283out: 327out:
@@ -311,7 +355,7 @@ struct page *new_alloc_page(struct page *page, unsigned long node, int **x)
311 unsigned int idx = 0; 355 unsigned int idx = 0;
312 idx += num_by_bitmask_index(set_partition[node], set_index[node]); 356 idx += num_by_bitmask_index(set_partition[node], set_index[node]);
313 idx += number_cachecolors* num_by_bitmask_index(bank_partition[node], bank_index[node]); 357 idx += number_cachecolors* num_by_bitmask_index(bank_partition[node], bank_index[node]);
314 printk("node = %d, idx = %d\n", node, idx); 358 //printk("node = %d, idx = %d\n", node, idx);
315 359
316 rPage = new_alloc_page_color(idx); 360 rPage = new_alloc_page_color(idx);
317 361
@@ -407,7 +451,21 @@ out:
407 return ret; 451 return ret;
408} 452}
409 453
410 454int show_page_pool_handler(struct ctl_table *table, int write, void __user *buffer,
455 size_t *lenp, loff_t *ppos)
456{
457 int ret = 0, i = 0;
458 mutex_lock(&void_lockdown_proc);
459 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
460 if (ret)
461 goto out;
462 if (write) {
463 show_nr_pages();
464 }
465out:
466 mutex_unlock(&void_lockdown_proc);
467 return ret;
468}
411static struct ctl_table cache_table[] = 469static struct ctl_table cache_table[] =
412{ 470{
413 471
@@ -573,8 +631,13 @@ static struct ctl_table cache_table[] =
573 .extra1 = &bank_partition_min, 631 .extra1 = &bank_partition_min,
574 .extra2 = &bank_partition_max, 632 .extra2 = &bank_partition_max,
575 }, 633 },
576 634 {
577 635 .procname = "show_page_pool",
636 .mode = 0666,
637 .proc_handler = show_page_pool_handler,
638 .data = &show_page_pool,
639 .maxlen = sizeof(show_page_pool),
640 },
578 { } 641 { }
579}; 642};
580 643