1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include <linux/spinlock.h>
#include <linux/mmzone.h>
#include <linux/module.h>
#include <linux/cpu.h>
#include <litmus/color.h>
#define MPRINT(fmt, args...) \
printk(KERN_INFO "[%s@%s:%d]: " fmt, \
__FUNCTION__, __FILE__, __LINE__, ## args)
#define ALLOC_ORDER (MAX_ORDER - 1)
#define PAGES_PER_COLOR 10000
struct color_cache_info color_cache_info;
unsigned long color_mask;
unsigned long nr_colors;
struct color_group {
spinlock_t lock;
struct list_head list;
int nr_pages;
};
struct color_group *colors;
/* slowest possible way to find a log, but we only do this once on boot */
static unsigned int slow_log(unsigned int v)
{
unsigned int r = 0;
while (v >>= 1)
r++;
return r;
}
static void __init setup_mask(void)
{
const unsigned int line_size_log = slow_log(color_cache_info.line_size);
BUG_ON(color_cache_info.size / color_cache_info.line_size /
color_cache_info.ways != color_cache_info.sets);
BUG_ON(PAGE_SIZE >= (color_cache_info.sets << line_size_log));
color_mask = ((color_cache_info.sets << line_size_log) - 1) ^
(PAGE_SIZE - 1);
nr_colors = (color_mask >> PAGE_SHIFT) + 1;
MPRINT("color mask: 0x%lx total colors: %lu\n", color_mask,
nr_colors);
}
static int __init init_color_lists(void)
{
struct page *page;
page = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, ALLOC_ORDER);
if (!page) {
MPRINT("could not allocate pages\n");
BUG();
}
return 0;
}
static int __init init_color(void)
{
MPRINT("ALLOC_ORDER is %d\n", ALLOC_ORDER);
MPRINT("Cache size: %lu line-size: %lu ways: %lu sets: %lu\n",
color_cache_info.size, color_cache_info.line_size,
color_cache_info.ways, color_cache_info.sets);
if (!color_cache_info.size){
printk(KERN_WARNING "No cache information found.\n");
return -EINVAL;
}
BUG_ON(color_cache_info.size <= 1048576 ||
color_cache_info.ways < 15 ||
color_cache_info.line_size != 64);
setup_mask();
return init_color_lists();
}
module_init(init_color);
|