Merge remote branch 'origin/sparc-dev'
[akaros.git] / kern / src / testing.c
index 5126074..544e8c0 100644 (file)
 #include <kmalloc.h>
 #include <hashtable.h>
 
+#define l1 (available_caches.l1)
+#define l2 (available_caches.l2)
+#define l3 (available_caches.l3)
+
 #ifdef __i386__
 
 void test_ipi_sending(void)
@@ -113,12 +117,13 @@ void test_print_info(void)
 
 void test_page_coloring(void) 
 {
+/*
        //Print the different cache properties of our machine
-       print_cache_properties("L1", &l1);
+       print_cache_properties("L1", l1);
        cprintf("\n");
-       print_cache_properties("L2", &l2);
+       print_cache_properties("L2", l2);
        cprintf("\n");
-       print_cache_properties("L3", &l3);
+       print_cache_properties("L3", l3);
        cprintf("\n");
 
        //Print some stats about our memory
@@ -129,7 +134,7 @@ void test_page_coloring(void)
        page_t* page;
 
        cprintf("Contents of the page free list:\n");
-       for(int i=0; i<llc_num_colors; i++) {
+       for(int i=0; i<llc_cache->num_colors; i++) {
                cprintf("  COLOR %d:\n", i);
                LIST_FOREACH(page, &colored_page_free_list[i], page_link) {
                        cprintf("    Page: %d\n", page2ppn(page));
@@ -138,9 +143,9 @@ void test_page_coloring(void)
 
        //Run through and allocate all pages through l1_page_alloc
        cprintf("Allocating from L1 page colors:\n");
-       for(int i=0; i<get_cache_num_page_colors(&l1); i++) {
+       for(int i=0; i<get_cache_num_page_colors(l1); i++) {
                cprintf("  COLOR %d:\n", i);
-               while(l1_page_alloc(&page, i) != -ENOMEM)
+               while(colored_page_alloc(l1, &page, i) != -ENOMEM)
                        cprintf("    Page: %d\n", page2ppn(page));
        }
 
@@ -149,9 +154,9 @@ void test_page_coloring(void)
        
        //Run through and allocate all pages through l2_page_alloc
        cprintf("Allocating from L2 page colors:\n");
-       for(int i=0; i<get_cache_num_page_colors(&l2); i++) {
+       for(int i=0; i<get_cache_num_page_colors(l2); i++) {
                cprintf("  COLOR %d:\n", i);
-               while(l2_page_alloc(&page, i) != -ENOMEM)
+               while(colored_page_alloc(l2, &page, i) != -ENOMEM)
                        cprintf("    Page: %d\n", page2ppn(page));
        }
 
@@ -160,9 +165,9 @@ void test_page_coloring(void)
        
        //Run through and allocate all pages through l3_page_alloc
        cprintf("Allocating from L3 page colors:\n");
-       for(int i=0; i<get_cache_num_page_colors(&l3); i++) {
+       for(int i=0; i<get_cache_num_page_colors(l3); i++) {
                cprintf("  COLOR %d:\n", i);
-               while(l3_page_alloc(&page, i) != -ENOMEM)
+               while(colored_page_alloc(l3, &page, i) != -ENOMEM)
                        cprintf("    Page: %d\n", page2ppn(page));
        }
        
@@ -171,10 +176,10 @@ void test_page_coloring(void)
        
        //Run through and allocate all pages through page_alloc
        cprintf("Allocating from global allocator:\n");
-       while(page_alloc(&page) != -ENOMEM)
+       while(upage_alloc(&page) != -ENOMEM)
                cprintf("    Page: %d\n", page2ppn(page));
        
-       if(l2_page_alloc(&page, 0) != -ENOMEM)
+       if(colored_page_alloc(l2, &page, 0) != -ENOMEM)
                cprintf("Should not get here, all pages should already be gone!\n");
        cprintf("All pages gone for sure...\n");
        
@@ -186,8 +191,50 @@ void test_page_coloring(void)
        page_free(&pages[6]);
        page_free(&pages[4]);
 
-       while(page_alloc(&page) != -ENOMEM)
+       while(upage_alloc(&page) != -ENOMEM)
                cprintf("Page: %d\n", page2ppn(page));  
+       
+       page_init();
+*/
+}
+
+void test_color_alloc() {
+       size_t checkpoint = 0;
+       uint8_t* colors_map = kmalloc(BYTES_FOR_BITMASK(llc_cache->num_colors), 0);
+       cache_color_alloc(l2, colors_map);
+       cache_color_alloc(l3, colors_map);
+       cache_color_alloc(l3, colors_map);
+       cache_color_alloc(l2, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(l2, colors_map);
+       cache_color_free(llc_cache, colors_map);
+       cache_color_free(llc_cache, colors_map);
+
+print_cache_colors:
+       printk("L1 free colors, tot colors: %d\n", l1->num_colors);
+       PRINT_BITMASK(l1->free_colors_map, l1->num_colors);
+       printk("L2 free colors, tot colors: %d\n", l2->num_colors);
+       PRINT_BITMASK(l2->free_colors_map, l2->num_colors);
+       printk("L3 free colors, tot colors: %d\n", l3->num_colors);
+       PRINT_BITMASK(l3->free_colors_map, l3->num_colors);
+       printk("Process allocated colors\n");
+       PRINT_BITMASK(colors_map, llc_cache->num_colors);
+       printk("test_color_alloc() complete!\n");
 }
 
 barrier_t test_cpu_array;