diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-12 16:47:35 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-12 16:47:35 -0500 |
commit | 06472070084d807d02b414326b07638deed2d1f8 (patch) | |
tree | 896e875457ccaa91a3c97b347b68e9384efa49e3 | |
parent | 9acc84176fc4aae0622ebfc7edb3200018ce6969 (diff) |
generate preemptions and migrations with equal probability
-rw-r--r-- | bin/cache_cost.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/cache_cost.c b/bin/cache_cost.c index 808ca33..db395e4 100644 --- a/bin/cache_cost.c +++ b/bin/cache_cost.c | |||
@@ -131,7 +131,18 @@ static int touch_mem(int *mem, int wss, int write_cycle) | |||
131 | return sum; | 131 | return sum; |
132 | } | 132 | } |
133 | 133 | ||
134 | 134 | static int pick_cpu(int last_cpu, int num_cpus) | |
135 | { | ||
136 | int cpu; | ||
137 | if (random() % 2 == 0) | ||
138 | return last_cpu; /* preemption */ | ||
139 | else { | ||
140 | do { | ||
141 | cpu = random() % num_cpus; | ||
142 | } while (cpu == last_cpu); | ||
143 | return cpu; | ||
144 | } | ||
145 | } | ||
135 | 146 | ||
136 | static void do_random_experiment(FILE* outfile, | 147 | static void do_random_experiment(FILE* outfile, |
137 | int num_cpus, int wss, | 148 | int num_cpus, int wss, |
@@ -162,7 +173,7 @@ static void do_random_experiment(FILE* outfile, | |||
162 | sample_count >= migration_counter) { | 173 | sample_count >= migration_counter) { |
163 | 174 | ||
164 | delay = sleep_min + random() % (sleep_max - sleep_min + 1); | 175 | delay = sleep_min + random() % (sleep_max - sleep_min + 1); |
165 | next_cpu = random() % num_cpus; | 176 | next_cpu = pick_cpu(last_cpu, num_cpus); |
166 | 177 | ||
167 | if (sample_count) | 178 | if (sample_count) |
168 | show = (next_cpu == last_cpu && sample_count >= preempt_counter) || | 179 | show = (next_cpu == last_cpu && sample_count >= preempt_counter) || |