1 /* Copyright (c) 2009 The Regents of the University of California.
2 * See the COPYRIGHT files at the top of this source tree for full
5 * Kevin Klues <klueska@cs.berkeley.edu>
8 #ifndef ROS_KERN_COLORED_CACHES_H
9 #define ROS_KERN_COLORED_CACHES_H
11 #include <ros/common.h>
15 /****************** Cache Structures ********************/
16 typedef struct Cache {
20 uint8_t* free_colors_map;
22 //Added as optimization (derived from above);
26 typedef struct AvailableCaches {
32 /******** Externally visible global variables ************/
33 extern available_caches_t RO available_caches;
34 extern cache_t* llc_cache;
35 extern spinlock_t cache_colors_lock;
37 /************** Cache Related Functions *****************/
39 void cache_color_alloc_init();
40 void init_cache_properties(cache_t RO*c, size_t sz_k, size_t wa, size_t clsz);
41 void init_free_cache_colors_map(cache_t* c);
42 size_t get_offset_in_cache_line(uintptr_t addr, cache_t RO*c);
43 void print_cache_properties(char *NT lstring, cache_t RO*c);
45 static inline size_t get_page_color(uintptr_t page, cache_t *c) {
46 return (page & (c->num_colors-1));
50 uint8_t* cache_colors_map_alloc();
51 void cache_colors_map_free(uint8_t* colors_map);
52 error_t cache_color_alloc(cache_t* c, uint8_t* colors_map);
53 error_t cache_color_alloc_specific(size_t color, cache_t* c,
55 void cache_color_free(cache_t* c, uint8_t* colors_map);
56 void cache_color_free_specific(size_t color, cache_t* c, uint8_t* colors_map);
58 /****************** Cache Properties *********************/
59 inline size_t get_cache_ways_associative(cache_t RO*c);
60 inline size_t get_cache_line_size_bytes(cache_t RO*c);
61 inline size_t get_cache_size_bytes(cache_t RO*c);
62 inline size_t get_cache_size_kilobytes(cache_t RO*c);
63 inline size_t get_cache_size_megabytes(cache_t RO*c);
64 inline size_t get_cache_num_offset_bits(cache_t RO*c);
65 inline size_t get_cache_num_index_bits(cache_t RO*c);
66 inline size_t get_cache_num_tag_bits(cache_t RO*c);
67 inline size_t get_cache_num_page_color_bits(cache_t RO*c);
68 inline size_t get_cache_bytes_per_line(cache_t RO*c);
69 inline size_t get_cache_num_lines(cache_t RO*c);
70 inline size_t get_cache_num_sets(cache_t RO*c);
71 inline size_t get_cache_lines_per_set(cache_t RO*c);
72 inline size_t get_cache_lines_per_page(cache_t RO*c);
73 inline size_t get_cache_bytes_per_way(cache_t RO*c);
74 inline size_t get_cache_lines_per_way(cache_t RO*c);
75 inline size_t get_cache_pages_per_way(cache_t RO*c);
76 inline size_t get_cache_num_page_colors(cache_t RO*c);
78 #endif // ROS_KERN_COLORED_CACHES_H