Add period and count to #alarm
[akaros.git] / kern / include / colored_page_alloc.h
1 /*
2  * Copyright (c) 2009 The Regents of the University  of California.  
3  * See the COPYRIGHT files at the top of this source tree for full 
4  * license information.
5  */
6 /**
7  * @author Kevin Klues <klueska@cs.berkeley.edu>
8  */
9  
10 #pragma once
11
12 #include <colored_caches.h>
13 #include <arch/colored_page_alloc.h>
14 #include <stdio.h>
15         
16 #define DECLARE_CACHE_COLORED_PAGE_LINK(_cache)                               \
17         page_list_entry_t _cache##_cache_colored_pg_link;
18         
19 #define DECLARE_CACHE_COLORED_PAGE_FREE_LIST(_cache)                          \
20         uint8_t _cache##_num_colors = 0;                                          \
21         page_list_t *_cache##_cache_colored_page_list = NULL;
22         
23 #define DECLARE_EXTERN_CACHE_COLORED_PAGE_FREE_LIST(_cache)                   \
24     extern uint8_t _cache##_num_colors;                                       \
25         extern page_list_t *_cache##_cache_colored_page_list;
26         
27 #define DECLARE_CACHE_COLORED_PAGE_ALLOC_FUNCTION(_cache)                     \
28 error_t _cache##_page_alloc(page_t** page, size_t color)                      \
29 {                                                                             \
30         /*      TODO: Put a lock around this */                                       \
31         if(available_caches._cache && !LIST_EMPTY(&(_cache##_cache_colored_page_list)[(color)])) {           \
32                 *(page) = LIST_FIRST(&(_cache##_cache_colored_page_list)[(color)]);   \
33                 LIST_REMOVE(*page, global_link);                                      \
34                 REMOVE_CACHE_COLORING_PAGE_FROM_FREE_LISTS(page);                     \
35                 page_clear(*page);                                                    \
36                 return ESUCCESS;                                                      \
37         }                                                                         \
38         return -ENOMEM;                                                           \
39 }
40
41 #define INIT_CACHE_COLORED_PAGE_FREE_LIST(_cache)                             \
42 {                                                                             \
43         if(available_caches._cache == TRUE) {                                     \
44             _cache##_num_colors = get_cache_num_page_colors(&(_cache));           \
45             assert(((_cache##_num_colors) & ((_cache##_num_colors)-1)) == 0);     \
46             size_t list_size = _cache##_num_colors*sizeof(page_list_t);           \
47             _cache##_cache_colored_page_list                                      \
48                = (page_list_t*) boot_alloc(list_size, PGSIZE);                    \
49                 for(int i=0; i<_cache##_num_colors; i++) {                            \
50                         LIST_INIT(&(_cache##_cache_colored_page_list[i]));                \
51                 }                                                                     \
52         }                                                                         \
53 }
54
55 #define REMOVE_CACHE_COLORING_PAGE_FROM_FREE_LIST(_page, _cache)              \
56         if(available_caches._cache == TRUE)                                       \
57                 LIST_REMOVE(*(_page), _cache##_cache_colored_pg_link);
58
59
60 #define INSERT_CACHE_COLORING_PAGE_ONTO_FREE_LIST(_page, _cache)              \
61         if(available_caches._cache == TRUE) {                                     \
62                 LIST_INSERT_HEAD(                                                     \
63                    &(_cache##_cache_colored_page_list                                 \
64                          [get_page_color(page2ppn((_page)), &(_cache))]),             \
65                    (_page),                                                           \
66                    _cache##_cache_colored_pg_link                                   \
67                 );                                                                    \
68         }