From d97c84a58867f481fede002fbd1510fc51b34e9e Mon Sep 17 00:00:00 2001 From: Namhoon Kim Date: Mon, 1 May 2017 14:13:05 -0400 Subject: RTSS 2017 submission --- litmus/bank_proc.c | 80 +++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 67 deletions(-) (limited to 'litmus/bank_proc.c') 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 @@ /* * bank_proc.c -- Implementation of the page coloring for cache and bank partition. * The file will keep a pool of colored pages. Users can require pages with - * specific color or bank number. + * specific color or bank number. * Part of the code is modified from Jonathan Herman's code */ #include @@ -19,9 +19,6 @@ #include #include -//#define TRACE(fmt, args...) do {} while (false) -//#define TRACE_TASK(fmt, args...) do {} while (false) - #define LITMUS_LOCKDEP_NAME_MAX_LEN 50 // This Address Decoding is used in imx6-sabredsd platform @@ -86,7 +83,6 @@ int node_index[9] = { struct mutex void_lockdown_proc; - /* * Every page list should contain a lock, a list, and a number recording how many pages it store */ @@ -105,7 +101,6 @@ static struct color_group *color_groups; */ unsigned int counting_one_set(unsigned int v) { -// unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v for (c = 0; v; v >>= 1) @@ -257,8 +252,6 @@ static inline unsigned int page_list_index(struct page *page) { unsigned int idx; idx = (page_color(page) + page_bank(page)*(number_cachecolors)); -// printk("address = %lx, ", page_to_phys(page)); -// printk("color(%d), bank(%d), indx = %d\n", page_color(page), page_bank(page), idx); return idx; } @@ -289,10 +282,10 @@ static void show_nr_pages(void) printk("show nr pages***************************************\n"); for (i = 0; i < NUM_PAGE_LIST; ++i) { cgroup = &color_groups[i]; - printk("(%03d) = %03d, ", i, atomic_read(&cgroup->nr_pages)); - if((i % 8) ==7){ + printk("(%03ld) = %03d, ", i, atomic_read(&cgroup->nr_pages)); + if((i % 8) ==7) { printk("\n"); - } + } } } @@ -316,6 +309,7 @@ void add_page_to_color_list(struct page *page) * Replenish the page pool. * If the newly allocate page is what we want, it will be pushed to the correct page list * otherwise, it will be freed. + * A user needs to invoke this function until the page pool has enough pages. */ static int do_add_pages(void) { @@ -329,8 +323,6 @@ static int do_add_pages(void) // until all the page lists contain enough pages for (i=0; i< 1024*20;i++) { - //while (smallest_nr_pages() < PAGES_PER_COLOR) { - // printk("smallest = %d\n", smallest_nr_pages()); page = alloc_page(GFP_HIGHUSER_MOVABLE); if (unlikely(!page)) { @@ -340,55 +332,20 @@ static int do_add_pages(void) } color = page_list_index(page); counter[color]++; - // printk("page(%d) = color %x, bank %x, [color] =%d \n", color, page_color(page), page_bank(page), atomic_read(&color_groups[color].nr_pages)); - //show_nr_pages(); - //if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR && color>=16) { - if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR) { - //if ( PAGES_PER_COLOR && color>=16*2) { + if (atomic_read(&color_groups[color].nr_pages) < PAGES_PER_COLOR && color>=0) { add_page_to_color_list(page); - // printk("add page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page)); - } else{ + } else { // Pages here will be freed later list_add_tail(&page->lru, &free_later); free_counter++; - //list_del(&page->lru); - // __free_page(page); - // printk("useless page(%d) = color %x, bank %x\n", color, page_color(page), page_bank(page)); } - //show_nr_pages(); - /* - if(free_counter >= PAGES_PER_COLOR) - { - printk("free unwanted page list eariler"); - free_counter = 0; - list_for_each_entry_safe(page, page_tmp, &free_later, lru) { - list_del(&page->lru); - __free_page(page); - } - - show_nr_pages(); - } - */ - } -/* printk("page counter = \n"); - for (i=0; i<128; i++) - { - printk("(%03d) = %4d, ", i , counter[i]); - if(i%8 == 7){ - printk("\n"); - } + } - } -*/ - //printk("After refill : \n"); - //show_nr_pages(); -#if 1 // Free the unwanted pages list_for_each_entry_safe(page, page_tmp, &free_later, lru) { list_del(&page->lru); __free_page(page); } -#endif out: return ret; } @@ -407,7 +364,6 @@ static struct page *new_alloc_page_color( unsigned long color) if( (color <0) || (color)>(number_cachecolors*number_banks -1)) { TRACE_CUR("Wrong color %lu\n", color); -// printk(KERN_WARNING "Wrong color %lu\n", color); goto out; } @@ -416,7 +372,6 @@ static struct page *new_alloc_page_color( unsigned long color) spin_lock(&cgroup->lock); if (unlikely(!atomic_read(&cgroup->nr_pages))) { TRACE_CUR("No free %lu colored pages.\n", color); -// printk(KERN_WARNING "no free %lu colored pages.\n", color); goto out_unlock; } rPage = list_first_entry(&cgroup->list, struct page, lru); @@ -428,12 +383,6 @@ static struct page *new_alloc_page_color( unsigned long color) out_unlock: spin_unlock(&cgroup->lock); out: -/* - if( smallest_nr_pages() == 0) { - //do_add_pages(); - //printk(KERN_ALERT "ERROR(bank_proc.c) = We don't have enough pages in bank_proc.c\n"); - } -*/ return rPage; } @@ -456,9 +405,7 @@ struct page* get_colored_page(unsigned long color) */ struct page *new_alloc_page(struct page *page, unsigned long node, int **x) { - struct color_group *cgroup; struct page *rPage = NULL; - unsigned int color; int try = 0; unsigned int idx; @@ -479,7 +426,7 @@ struct page *new_alloc_page(struct page *page, unsigned long node, int **x) if (try>=256) break; idx = get_next_index(node, idx); - printk(KERN_ALERT "try = %d out of page! requesting node = %d, idx = %d\n", try, node, idx); + printk(KERN_ALERT "try = %d out of page! requesting node = %ld, idx = %d\n", try, node, idx); BUG_ON(idx<0 || idx>127); rPage = new_alloc_page_color(idx); } @@ -494,20 +441,19 @@ struct page *new_alloc_page(struct page *page, unsigned long node, int **x) void reclaim_page(struct page *page) { const unsigned long color = page_list_index(page); - unsigned long nr_reclaimed = 0; spin_lock(&reclaim_lock); put_page(page); add_page_to_color_list(page); spin_unlock(&reclaim_lock); - 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)); + 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)); } /* * Initialize the numbers of banks and cache colors */ -static int __init init_variables(void) +static void __init init_variables(void) { number_banks = counting_one_set(BANK_MASK); number_banks = two_exp(number_banks); @@ -592,7 +538,7 @@ out: int show_page_pool_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = 0, i = 0; + int ret = 0; mutex_lock(&void_lockdown_proc); ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); if (ret) @@ -608,7 +554,7 @@ out: int refill_page_pool_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - int ret = 0, i = 0; + int ret = 0; mutex_lock(&void_lockdown_proc); ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); if (ret) -- cgit v1.2.2