aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMahircan Gul <mahircg@mpi-sws.org>2016-01-20 11:10:08 -0500
committerBjoern Brandenburg <bbb@mpi-sws.org>2016-03-20 14:07:43 -0400
commita409d6c24a9d1035f6c5f26248651aa83ea8d727 (patch)
tree465c569502ca97708ba971d3f978fa17cfd5c4d2
parente2c555d3dd253e1a15745777bbe6b7c7f9a5597d (diff)
Add memory thrashing option to rtspin
-rw-r--r--bin/rtspin.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/bin/rtspin.c b/bin/rtspin.c
index 31962ec..e45f376 100644
--- a/bin/rtspin.c
+++ b/bin/rtspin.c
@@ -8,6 +8,8 @@
8#include <string.h> 8#include <string.h>
9#include <assert.h> 9#include <assert.h>
10#include <inttypes.h> 10#include <inttypes.h>
11#include <sys/mman.h>
12#include <errno.h>
11 13
12#include "litmus.h" 14#include "litmus.h"
13#include "common.h" 15#include "common.h"
@@ -24,10 +26,12 @@ static void usage(char *error) {
24 "\n" 26 "\n"
25 "COMMON-OPTS = [-w] [-s SCALE]\n" 27 "COMMON-OPTS = [-w] [-s SCALE]\n"
26 " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-c CLASS]\n" 28 " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-c CLASS]\n"
27 " [-X LOCKING-PROTOCOL] [-L CRITICAL SECTION LENGTH] [-Q RESOURCE-ID]" 29 " [-X LOCKING-PROTOCOL] [-L CRITICAL SECTION LENGTH] [-Q RESOURCE-ID]\n"
30 " [-m RESIDENT SET SIZE]"
28 "\n" 31 "\n"
29 "WCET and PERIOD are milliseconds, DURATION is seconds.\n" 32 "WCET and PERIOD are milliseconds, DURATION is seconds.\n"
30 "CRITICAL SECTION LENGTH is in milliseconds.\n"); 33 "CRITICAL SECTION LENGTH is in milliseconds.\n"
34 "RESIDENT SET SIZE is in number of pages\n");
31 exit(EXIT_FAILURE); 35 exit(EXIT_FAILURE);
32} 36}
33 37
@@ -103,6 +107,10 @@ static void get_exec_times(const char *file, const int column,
103static int num[NUMS]; 107static int num[NUMS];
104static char* progname; 108static char* progname;
105 109
110static int nr_of_pages = 0;
111static int page_size;
112static void *base = NULL;
113
106static int loop_once(void) 114static int loop_once(void)
107{ 115{
108 int i, j = 0; 116 int i, j = 0;
@@ -111,6 +119,17 @@ static int loop_once(void)
111 return j; 119 return j;
112} 120}
113 121
122static int loop_once_with_mem(void)
123{
124 int i;
125 int rand;
126 for(i=0; i<NUMS; i++) {
127 rand=lrand48() % (nr_of_pages - 1);
128 memset(base + (rand * page_size),rand,1024);
129 }
130 return 0;
131}
132
114static int loop_for(double exec_time, double emergency_exit) 133static int loop_for(double exec_time, double emergency_exit)
115{ 134{
116 double last_loop = 0, loop_start; 135 double last_loop = 0, loop_start;
@@ -121,7 +140,10 @@ static int loop_for(double exec_time, double emergency_exit)
121 140
122 while (now + last_loop < start + exec_time) { 141 while (now + last_loop < start + exec_time) {
123 loop_start = now; 142 loop_start = now;
124 tmp += loop_once(); 143 if (nr_of_pages)
144 tmp += loop_once_with_mem();
145 else
146 tmp += loop_once();
125 now = cputime(); 147 now = cputime();
126 last_loop = now - loop_start; 148 last_loop = now - loop_start;
127 if (emergency_exit && wctime() > emergency_exit) { 149 if (emergency_exit && wctime() > emergency_exit) {
@@ -185,7 +207,7 @@ static int job(double exec_time, double program_end, int lock_od, double cs_leng
185 } 207 }
186} 208}
187 209
188#define OPTSTR "p:c:wlveo:f:s:q:r:X:L:Q:viRu:" 210#define OPTSTR "p:c:wlveo:f:s:m:q:r:X:L:Q:viRu:B:"
189int main(int argc, char** argv) 211int main(int argc, char** argv)
190{ 212{
191 int ret; 213 int ret;
@@ -196,7 +218,7 @@ int main(int argc, char** argv)
196 int migrate = 0; 218 int migrate = 0;
197 int cluster = 0; 219 int cluster = 0;
198 int reservation = -1; 220 int reservation = -1;
199 int create_reservation = -1; 221 int create_reservation = 0;
200 int opt; 222 int opt;
201 int wait = 0; 223 int wait = 0;
202 int test_loop = 0; 224 int test_loop = 0;
@@ -210,6 +232,9 @@ int main(int argc, char** argv)
210 int cur_job = 0, num_jobs = 0; 232 int cur_job = 0, num_jobs = 0;
211 struct rt_task param; 233 struct rt_task param;
212 234
235 int rss=0;
236 int idx;
237
213 int verbose = 0; 238 int verbose = 0;
214 unsigned int job_no; 239 unsigned int job_no;
215 struct control_page* cp; 240 struct control_page* cp;
@@ -263,6 +288,9 @@ int main(int argc, char** argv)
263 case 'f': 288 case 'f':
264 file = optarg; 289 file = optarg;
265 break; 290 break;
291 case 'm':
292 nr_of_pages = atoi(optarg);
293 break;
266 case 's': 294 case 's':
267 scale = atof(optarg); 295 scale = atof(optarg);
268 break; 296 break;
@@ -302,6 +330,26 @@ int main(int argc, char** argv)
302 } 330 }
303 } 331 }
304 332
333 if(nr_of_pages) {
334 page_size = getpagesize();
335 rss = page_size * nr_of_pages;
336 base = mmap(NULL, rss, PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
337 if(base == MAP_FAILED) {
338 fprintf(stderr,"mmap failed: %s\n",strerror(errno));
339 exit(EXIT_FAILURE);
340 }
341
342 /* pin frames to prevent swapping */
343 ret = mlock(base,rss);
344 if (ret) {
345 fprintf(stderr,"mlock failed: %s\n",strerror(errno));
346 }
347
348 /* touch every allocated page */
349 for(idx = 0; idx < nr_of_pages; idx++)
350 memset(base + (idx * page_size), 1, page_size);
351 }
352
305 if (test_loop) { 353 if (test_loop) {
306 debug_delay_loop(); 354 debug_delay_loop();
307 return 0; 355 return 0;
@@ -354,6 +402,7 @@ int main(int argc, char** argv)
354 bail_out("could not migrate to target partition or cluster."); 402 bail_out("could not migrate to target partition or cluster.");
355 } 403 }
356 404
405
357 init_rt_task_param(&param); 406 init_rt_task_param(&param);
358 param.exec_cost = wcet; 407 param.exec_cost = wcet;
359 param.period = period; 408 param.period = period;
@@ -467,5 +516,8 @@ int main(int argc, char** argv)
467 if (file) 516 if (file)
468 free(exec_times); 517 free(exec_times);
469 518
519 if(base != MAP_FAILED)
520 munlock(base, rss);
521
470 return 0; 522 return 0;
471} 523}