diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-04-20 10:38:14 -0400 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-04-20 10:38:14 -0400 |
| commit | 169bf0f2fe1ea4b733e45efb544b650f0787e0ca (patch) | |
| tree | cedfaec55e9d9755fdfc5ac01edf27b94c660537 | |
| parent | a563ee7d54d549deacaaa1503016f882369b2087 (diff) | |
equal probability migrations; specific to Ludwig
| -rw-r--r-- | bin/cache_cost.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/bin/cache_cost.c b/bin/cache_cost.c index c41fa01..6e82c62 100644 --- a/bin/cache_cost.c +++ b/bin/cache_cost.c | |||
| @@ -126,13 +126,62 @@ static int touch_mem(int *mem, int wss, int write_cycle) | |||
| 126 | return sum; | 126 | return sum; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | static int l2buddy(int cpu) { | ||
| 130 | if (cpu % 8 < 4) | ||
| 131 | return cpu + 4; | ||
| 132 | else | ||
| 133 | return cpu - 4; | ||
| 134 | } | ||
| 135 | |||
| 136 | static int is_l3_buddy(int x, int y) { | ||
| 137 | return x != y && (y % 4) == (x % 4) && x != l2buddy(y); | ||
| 138 | } | ||
| 139 | |||
| 140 | int kind_counter[] = {0, 0, 0, 0}; | ||
| 141 | |||
| 142 | static int pick_next_cpu(int num_cpus, int cur_cpu) | ||
| 143 | { | ||
| 144 | int next_cpu; | ||
| 145 | int kind; | ||
| 146 | |||
| 147 | |||
| 148 | kind = random() % 4; | ||
| 149 | |||
| 150 | switch (kind) { | ||
| 151 | case 0: | ||
| 152 | /* preemption */ | ||
| 153 | next_cpu = cur_cpu; | ||
| 154 | break; | ||
| 155 | case 1: | ||
| 156 | /* L2 */ | ||
| 157 | next_cpu = l2buddy(cur_cpu); | ||
| 158 | break; | ||
| 159 | case 2: | ||
| 160 | do { | ||
| 161 | next_cpu = random() % num_cpus; | ||
| 162 | } while (!is_l3_buddy(next_cpu, cur_cpu)); | ||
| 163 | break; | ||
| 164 | case 3: | ||
| 165 | /* mem */ | ||
| 166 | do { | ||
| 167 | next_cpu = random() % num_cpus; | ||
| 168 | } while (next_cpu == cur_cpu || l2buddy(next_cpu) == cur_cpu || is_l3_buddy(next_cpu, cur_cpu)); | ||
| 169 | break; | ||
| 170 | } | ||
| 171 | kind_counter[kind]++; | ||
| 172 | |||
| 173 | /* hard coded for ludwig atm */ | ||
| 174 | |||
| 175 | return next_cpu; | ||
| 176 | } | ||
| 177 | |||
| 129 | static void do_random_experiment(FILE* outfile, | 178 | static void do_random_experiment(FILE* outfile, |
| 130 | int num_cpus, int wss, | 179 | int num_cpus, int wss, |
| 131 | int sleep_min, int sleep_max, | 180 | int sleep_min, int sleep_max, |
| 132 | int write_cycle, int sample_count) | 181 | int write_cycle, int sample_count) |
| 133 | { | 182 | { |
| 134 | int last_cpu, next_cpu, delay; | 183 | int last_cpu, next_cpu, delay; |
| 135 | unsigned long counter = 1; | 184 | unsigned long counter = 1, enough = 0, i; |
| 136 | 185 | ||
| 137 | cycles_t start, stop; | 186 | cycles_t start, stop; |
| 138 | cycles_t cold, hot1, hot2, hot3, after_resume; | 187 | cycles_t cold, hot1, hot2, hot3, after_resume; |
| @@ -147,9 +196,9 @@ static void do_random_experiment(FILE* outfile, | |||
| 147 | 196 | ||
| 148 | 197 | ||
| 149 | iopl(3); | 198 | iopl(3); |
| 150 | while (!sample_count || sample_count >= counter) { | 199 | while (!enough) { |
| 151 | delay = sleep_min + random() % (sleep_max - sleep_min + 1); | 200 | delay = sleep_min + random() % (sleep_max - sleep_min + 1); |
| 152 | next_cpu = random() % num_cpus; | 201 | next_cpu = pick_next_cpu(num_cpus, last_cpu); |
| 153 | 202 | ||
| 154 | mem = allocate(wss); | 203 | mem = allocate(wss); |
| 155 | 204 | ||
| @@ -199,6 +248,11 @@ static void do_random_experiment(FILE* outfile, | |||
| 199 | after_resume); | 248 | after_resume); |
| 200 | last_cpu = next_cpu; | 249 | last_cpu = next_cpu; |
| 201 | deallocate(mem); | 250 | deallocate(mem); |
| 251 | enough = sample_count; | ||
| 252 | for (i = 0; i < 4; i++) { | ||
| 253 | if (kind_counter[i] < sample_count) | ||
| 254 | enough = 0; | ||
| 255 | } | ||
| 202 | } | 256 | } |
| 203 | } | 257 | } |
| 204 | 258 | ||
