aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/bank_proc.c
diff options
context:
space:
mode:
authorNamhoon Kim <namhoonk@cs.unc.edu>2017-05-01 14:13:05 -0400
committerNamhoon Kim <namhoonk@cs.unc.edu>2017-05-01 14:13:05 -0400
commitd97c84a58867f481fede002fbd1510fc51b34e9e (patch)
treee38052cab5dc4fb81207e979d56e53aeb55029c1 /litmus/bank_proc.c
parentb388244876da9dbb2b7449bcc467fe4378ce1009 (diff)
RTSS 2017 submissionwip-modechange
Diffstat (limited to 'litmus/bank_proc.c')
-rw-r--r--litmus/bank_proc.c80
1 files changed, 13 insertions, 67 deletions
diff --git a/litmus/bank_proc.c b/litmus/bank_proc.c
index 08b58f94c391..097cff177a2d 100644
--- a/litmus/bank_proc.c
+++ b/litmus/bank_proc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * bank_proc.c -- Implementation of the page coloring for cache and bank partition. 2 * bank_proc.c -- Implementation of the page coloring for cache and bank partition.
3 * The file will keep a pool of colored pages. Users can require pages with 3 * The file will keep a pool of colored pages. Users can require pages with
4 * specific color or bank number. 4 * specific color or bank number.
5 * Part of the code is modified from Jonathan Herman's code 5 * Part of the code is modified from Jonathan Herman's code
6 */ 6 */
7#include <linux/init.h> 7#include <linux/init.h>
@@ -19,9 +19,6 @@
19#include <litmus/sched_trace.h> 19#include <litmus/sched_trace.h>
20#include <litmus/litmus.h> 20#include <litmus/litmus.h>
21 21
22//#define TRACE(fmt, args...) do {} while (false)
23//#define TRACE_TASK(fmt, args...) do {} while (false)
24
25#define LITMUS_LOCKDEP_NAME_MAX_LEN 50 22#define LITMUS_LOCKDEP_NAME_MAX_LEN 50
26 23
27// This Address Decoding is used in imx6-sabredsd platform 24// This Address Decoding is used in imx6-sabredsd platform
@@ -86,7 +83,6 @@ int node_index[9] = {
86 83
87struct mutex void_lockdown_proc; 84struct mutex void_lockdown_proc;
88 85
89
90/* 86/*
91 * Every page list should contain a lock, a list, and a number recording how many pages it store 87 * Every page list should contain a lock, a list, and a number recording how many pages it store
92 */ 88 */
@@ -105,7 +101,6 @@ static struct color_group *color_groups;
105 */ 101 */
106unsigned int counting_one_set(unsigned int v) 102unsigned int counting_one_set(unsigned int v)
107{ 103{
108// unsigned int v; // count the number of bits set in v
109 unsigned int c; // c accumulates the total bits set in v 104 unsigned int c; // c accumulates the total bits set in v
110 105
111 for (c = 0; v; v >>= 1) 106 for (c = 0; v; v >>= 1)
@@ -257,8 +252,6 @@ static inline unsigned int page_list_index(struct page *page)
257{ 252{
258 unsigned int idx; 253 unsigned int idx;
259 idx = (page_color(page) + page_bank(page)*(number_cachecolors)); 254 idx = (page_color(page) + page_bank(page)*(number_cachecolors));
260// printk("address = %lx, ", page_to_phys(page));
261// printk("color(%d), bank(%d), indx = %d\n", page_color(page), page_bank(page), idx);
262 255
263 return idx; 256 return idx;
264} 257}
@@ -289,10 +282,10 @@ static void show_nr_pages(void)
289 printk("show nr pages***************************************\n"); 282 printk("show nr pages***************************************\n");
290 for (i = 0; i < NUM_PAGE_LIST; ++i) { 283 for (i = 0; i < NUM_PAGE_LIST; ++i) {
291 cgroup = &color_groups[i]; 284 cgroup = &color_groups[i];
292 printk("(%03d) = %03d, ", i, atomic_read(&cgroup->nr_pages)); 285 printk("(%03ld) = %03d, ", i, atomic_read(&cgroup->nr_pages));
293 if((i % 8) ==7){ 286 if((i % 8) ==7) {
294 printk("\n"); 287 printk("\n");
295 } 288 }
296 } 289 }
297} 290}
298 291
@@ -316,6 +309,7 @@ void add_page_to_color_list(struct page *page)
316 * Replenish the page pool. 309 * Replenish the page pool.
317 * If the newly allocate page is what we want, it will be pushed to the correct page list 310 * If the newly allocate page is what we want, it will be pushed to the correct page list
318 * otherwise, it will be freed. 311 * otherwise, it will be freed.
312 * A user needs to invoke this function until the page pool has enough pages.
319 */ 313 */
320static int do_add_pages(void) 314static int do_add_pages(void)
321{ 315{
@@ -329,8 +323,6 @@ static int do_add_pages(void)
329 323
330 // until all the page lists contain enough pages 324 // until all the page lists contain enough pages
331 for (i=0; i< 1024*20;i++) { 325 for (i=0; i< 1024*20;i++) {
332 //while (smallest_nr_pages() < PAGES_PER_COLOR) {
333 // printk("smallest = %d\n", smallest_nr_pages());
334 page = alloc_page(GFP_HIGHUSER_MOVABLE); 326 page = alloc_page(GFP_HIGHUSER_MOVABLE);
335 327
336 if (unlikely(!page)) { 328 if (unlikely(!page)) {
@@ -340,55 +332,20 @@ static int do_add_pages(void)
340 } 332 }
341 color = page_list_index(page); 333 color = page_list_index(page);
342 counter[color]++; 334 counter[color]++;
343 // printk("page(%d) = color %x, bank %x, [color] =%d \n", color, page_color(page), page_bank(page), atomic_read(&color_groups[color].nr_pages)); 335 if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR && color>=0) {
344 //show_nr_pages();
345 //if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR && color>=16) {
346 if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR) {
347 //if ( PAGES_PER_COLOR && color>=16*2) {
348 add_page_to_color_list(page); 336 add_page_to_color_list(page);
349 // printk("add page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page)); 337 } else {
350 } else{
351 // Pages here will be freed later 338 // Pages here will be freed later
352 list_add_tail(&page->lru, &free_later); 339 list_add_tail(&page->lru, &free_later);
353 free_counter++; 340 free_counter++;
354 //list_del(&page->lru);
355 // __free_page(page);
356 // printk("useless page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page));
357 } 341 }
358 //show_nr_pages(); 342 }
359 /*
360 if(free_counter >= PAGES_PER_COLOR)
361 {
362 printk("free unwanted page list eariler");
363 free_counter = 0;
364 list_for_each_entry_safe(page, page_tmp, &free_later, lru) {
365 list_del(&page->lru);
366 __free_page(page);
367 }
368
369 show_nr_pages();
370 }
371 */
372 }
373/* printk("page counter = \n");
374 for (i=0; i<128; i++)
375 {
376 printk("(%03d) = %4d, ", i , counter[i]);
377 if(i%8 == 7){
378 printk("\n");
379 }
380 343
381 }
382*/
383 //printk("After refill : \n");
384 //show_nr_pages();
385#if 1
386 // Free the unwanted pages 344 // Free the unwanted pages
387 list_for_each_entry_safe(page, page_tmp, &free_later, lru) { 345 list_for_each_entry_safe(page, page_tmp, &free_later, lru) {
388 list_del(&page->lru); 346 list_del(&page->lru);
389 __free_page(page); 347 __free_page(page);
390 } 348 }
391#endif
392out: 349out:
393 return ret; 350 return ret;
394} 351}
@@ -407,7 +364,6 @@ static struct page *new_alloc_page_color( unsigned long color)
407 364
408 if( (color <0) || (color)>(number_cachecolors*number_banks -1)) { 365 if( (color <0) || (color)>(number_cachecolors*number_banks -1)) {
409 TRACE_CUR("Wrong color %lu\n", color); 366 TRACE_CUR("Wrong color %lu\n", color);
410// printk(KERN_WARNING "Wrong color %lu\n", color);
411 goto out; 367 goto out;
412 } 368 }
413 369
@@ -416,7 +372,6 @@ static struct page *new_alloc_page_color( unsigned long color)
416 spin_lock(&cgroup->lock); 372 spin_lock(&cgroup->lock);
417 if (unlikely(!atomic_read(&cgroup->nr_pages))) { 373 if (unlikely(!atomic_read(&cgroup->nr_pages))) {
418 TRACE_CUR("No free %lu colored pages.\n", color); 374 TRACE_CUR("No free %lu colored pages.\n", color);
419// printk(KERN_WARNING "no free %lu colored pages.\n", color);
420 goto out_unlock; 375 goto out_unlock;
421 } 376 }
422 rPage = list_first_entry(&cgroup->list, struct page, lru); 377 rPage = list_first_entry(&cgroup->list, struct page, lru);
@@ -428,12 +383,6 @@ static struct page *new_alloc_page_color( unsigned long color)
428out_unlock: 383out_unlock:
429 spin_unlock(&cgroup->lock); 384 spin_unlock(&cgroup->lock);
430out: 385out:
431/*
432 if( smallest_nr_pages() == 0) {
433 //do_add_pages();
434 //printk(KERN_ALERT "ERROR(bank_proc.c) = We don't have enough pages in bank_proc.c\n");
435 }
436*/
437 return rPage; 386 return rPage;
438} 387}
439 388
@@ -456,9 +405,7 @@ struct page* get_colored_page(unsigned long color)
456 */ 405 */
457struct page *new_alloc_page(struct page *page, unsigned long node, int **x) 406struct page *new_alloc_page(struct page *page, unsigned long node, int **x)
458{ 407{
459 struct color_group *cgroup;
460 struct page *rPage = NULL; 408 struct page *rPage = NULL;
461 unsigned int color;
462 int try = 0; 409 int try = 0;
463 unsigned int idx; 410 unsigned int idx;
464 411
@@ -479,7 +426,7 @@ struct page *new_alloc_page(struct page *page, unsigned long node, int **x)
479 if (try>=256) 426 if (try>=256)
480 break; 427 break;
481 idx = get_next_index(node, idx); 428 idx = get_next_index(node, idx);
482 printk(KERN_ALERT "try = %d out of page! requesting node = %d, idx = %d\n", try, node, idx); 429 printk(KERN_ALERT "try = %d out of page! requesting node = %ld, idx = %d\n", try, node, idx);
483 BUG_ON(idx<0 || idx>127); 430 BUG_ON(idx<0 || idx>127);
484 rPage = new_alloc_page_color(idx); 431 rPage = new_alloc_page_color(idx);
485 } 432 }
@@ -494,20 +441,19 @@ struct page *new_alloc_page(struct page *page, unsigned long node, int **x)
494void reclaim_page(struct page *page) 441void reclaim_page(struct page *page)
495{ 442{
496 const unsigned long color = page_list_index(page); 443 const unsigned long color = page_list_index(page);
497 unsigned long nr_reclaimed = 0;
498 spin_lock(&reclaim_lock); 444 spin_lock(&reclaim_lock);
499 put_page(page); 445 put_page(page);
500 add_page_to_color_list(page); 446 add_page_to_color_list(page);
501 447
502 spin_unlock(&reclaim_lock); 448 spin_unlock(&reclaim_lock);
503 printk("Reclaimed page(%d) = color %x, bank %x, [color] =%d \n", color, page_color(page), page_bank(page), atomic_read(&color_groups[color].nr_pages)); 449 printk("Reclaimed page(%ld) = color %x, bank %x, [color] =%d \n", color, page_color(page), page_bank(page), atomic_read(&color_groups[color].nr_pages));
504} 450}
505 451
506 452
507/* 453/*
508 * Initialize the numbers of banks and cache colors 454 * Initialize the numbers of banks and cache colors
509 */ 455 */
510static int __init init_variables(void) 456static void __init init_variables(void)
511{ 457{
512 number_banks = counting_one_set(BANK_MASK); 458 number_banks = counting_one_set(BANK_MASK);
513 number_banks = two_exp(number_banks); 459 number_banks = two_exp(number_banks);
@@ -592,7 +538,7 @@ out:
592int show_page_pool_handler(struct ctl_table *table, int write, void __user *buffer, 538int show_page_pool_handler(struct ctl_table *table, int write, void __user *buffer,
593 size_t *lenp, loff_t *ppos) 539 size_t *lenp, loff_t *ppos)
594{ 540{
595 int ret = 0, i = 0; 541 int ret = 0;
596 mutex_lock(&void_lockdown_proc); 542 mutex_lock(&void_lockdown_proc);
597 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 543 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
598 if (ret) 544 if (ret)
@@ -608,7 +554,7 @@ out:
608int refill_page_pool_handler(struct ctl_table *table, int write, void __user *buffer, 554int refill_page_pool_handler(struct ctl_table *table, int write, void __user *buffer,
609 size_t *lenp, loff_t *ppos) 555 size_t *lenp, loff_t *ppos)
610{ 556{
611 int ret = 0, i = 0; 557 int ret = 0;
612 mutex_lock(&void_lockdown_proc); 558 mutex_lock(&void_lockdown_proc);
613 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 559 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
614 if (ret) 560 if (ret)