Reduced boot time
authorAndrew Waterman <waterman@ubuntu.(none)>
Sun, 3 Jan 2010 01:05:23 +0000 (17:05 -0800)
committerAndrew Waterman <waterman@ubuntu.(none)>
Sun, 3 Jan 2010 01:05:23 +0000 (17:05 -0800)
Most boot time is spent adding pages to the free list.
I inlined the function to determine the page color, and
added the assumption that there is a power of two number
of colors (true for all commercial processor caches).

kern/include/colored_caches.h
kern/include/colored_page_alloc.h
kern/src/page_alloc.c

index ee32cf5..fdc3b40 100644 (file)
@@ -39,10 +39,14 @@ void cache_init();
 void cache_color_alloc_init();
 void init_cache_properties(cache_t RO*c, size_t sz_k, size_t wa, size_t clsz);
 void init_free_cache_colors_map(cache_t* c);
-size_t get_page_color(uintptr_t page, cache_t RO*c);
 size_t get_offset_in_cache_line(uintptr_t addr, cache_t RO*c);
 void print_cache_properties(char *NT lstring, cache_t RO*c);
 
+static inline size_t get_page_color(uintptr_t page, cache_t *c) {
+    return (page & (c->num_colors-1));
+}
+
+
 uint8_t* cache_colors_map_alloc();
 void cache_colors_map_free(uint8_t* colors_map);
 error_t cache_color_alloc(cache_t* c, uint8_t* colors_map);
index 865c405..5cbed43 100644 (file)
@@ -43,7 +43,8 @@ error_t _cache##_page_alloc(page_t** page, size_t color)                      \
 {                                                                             \
        if(available_caches._cache == TRUE) {                                     \
            _cache##_num_colors = get_cache_num_page_colors(&(_cache));           \
-           size_t list_size = _cache##_num_colors*sizeof(page_list_t);            \
+           assert(((_cache##_num_colors) & ((_cache##_num_colors)-1)) == 0);     \
+           size_t list_size = _cache##_num_colors*sizeof(page_list_t);           \
            _cache##_cache_colored_page_list                                      \
               = (page_list_t*) boot_alloc(list_size, PGSIZE);                    \
                for(int i=0; i<_cache##_num_colors; i++) {                            \
index 96ba288..ba98c5b 100644 (file)
@@ -127,7 +127,8 @@ error_t upage_alloc(struct proc* p, page_t** page)
        if(ret >= 0)
        {
                memset(page2kva(*page),0,PGSIZE);
-               p->next_cache_color = (ret + 1) % llc_cache->num_colors;
+               p->next_cache_color = (ret + 1) & (llc_cache->num_colors-1);
+               return 0;
        }
        return ret;
 }