aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNamhoon Kim <namhoonk@cs.unc.edu>2016-10-13 16:27:40 -0400
committerNamhoon Kim <namhoonk@cs.unc.edu>2016-10-13 16:27:40 -0400
commitb6ef12e31351d23a439597162f8d0fa7031b771d (patch)
tree9e1c36eabaef6def1df0c0ffe56db608f0c5852c
parent262677fc436c3e2109e628bb2f4708c6b279a551 (diff)
RTAS 2017 submissionwip-shared-lib
-rw-r--r--.gitignore4
-rw-r--r--Makefile12
-rw-r--r--bin/mc2mem.c304
-rw-r--r--bin/mc2spin.c250
-rw-r--r--include/cache_common.h140
-rw-r--r--include/litmus.h20
-rw-r--r--src/syscalls.c25
7 files changed, 753 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index a52500b..f42c50a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,10 @@ showst
23rtspin 23rtspin
24cycles 24cycles
25measure_syscall 25measure_syscall
26mc2spin
27mc2mem_stc
28mc2mem_ssh
29mc2mem
26 30
27# build system files 31# build system files
28.config 32.config
diff --git a/Makefile b/Makefile
index 4742fd2..ee2a9b2 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ LITMUS_KERNEL ?= ../litmus-rt
19# Internal configuration. 19# Internal configuration.
20 20
21# compiler flags 21# compiler flags
22flags-debug = -O2 -Wall -Werror -g -Wdeclaration-after-statement 22flags-debug = -O2 -Wall -g -Wdeclaration-after-statement
23flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE 23flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE
24 24
25# architecture-specific flags 25# architecture-specific flags
@@ -73,7 +73,7 @@ AR := ${CROSS_COMPILE}${AR}
73 73
74all = lib ${rt-apps} 74all = lib ${rt-apps}
75rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ 75rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \
76 base_mt_task uncache runtests 76 base_mt_task uncache runtests mc2mem_stc mc2mem_ssh mc2spin
77 77
78.PHONY: all lib clean dump-config TAGS tags cscope help doc 78.PHONY: all lib clean dump-config TAGS tags cscope help doc
79 79
@@ -234,6 +234,14 @@ obj-release_ts = release_ts.o
234obj-measure_syscall = null_call.o 234obj-measure_syscall = null_call.o
235lib-measure_syscall = -lm 235lib-measure_syscall = -lm
236 236
237obj-mc2mem_stc = mc2mem.o common.o
238lib-mc2mem_stc = -lrt -static
239
240obj-mc2mem_ssh = mc2mem.o common.o
241lib-mc2mem_ssh = -lrt
242
243obj-mc2spin = mc2spin.o common.o
244lib-mc2spin = -lrt
237# ############################################################################## 245# ##############################################################################
238# Build everything that depends on liblitmus. 246# Build everything that depends on liblitmus.
239 247
diff --git a/bin/mc2mem.c b/bin/mc2mem.c
new file mode 100644
index 0000000..2fba878
--- /dev/null
+++ b/bin/mc2mem.c
@@ -0,0 +1,304 @@
1#include <sys/time.h>
2#include <sys/mman.h>
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <time.h>
8#include <string.h>
9#include <assert.h>
10#include <limits.h>
11#include <fcntl.h>
12#include <math.h>
13
14#include "litmus.h"
15#include "common.h"
16#include "cache_common.h"
17
18#define PAGE_SIZE (4096)
19#define CACHELINE_SIZE 32
20#define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int))
21#define CACHELINES_IN_1KB (1024 / sizeof(cacheline_t))
22#define INTS_IN_1KB (1024 / sizeof(int))
23#define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int))
24
25static int loops = 100;
26static cacheline_t* arena = NULL;
27static int verbose = 0;
28
29#define UNCACHE_DEV "/dev/litmus/uncache"
30
31/* Random walk around the arena in cacheline-sized chunks.
32 Cacheline-sized chucks ensures the same utilization of each
33 hit line as sequential read. (Otherwise, our utilization
34 would only be 1/INTS_IN_CACHELINE.) */
35static int random_walk(cacheline_t *mem, int wss, int write_cycle)
36{
37 /* a random cycle among the cache lines was set up by init_arena(). */
38 int sum, i, next;
39
40 int numlines = wss * CACHELINES_IN_1KB;
41
42 sum = 0;
43
44 /* contents of arena is structured s.t. offsets are all
45 w.r.t. to start of arena, so compute the initial offset */
46 next = mem - arena;
47
48 if (write_cycle == 0) {
49 for (i = 0; i < numlines; i++) {
50 /* every element in the cacheline has the same value */
51 next = arena[next].line[0];
52 sum += next;
53 }
54 }
55
56 else {
57 int w, which_line;
58 for (i = 0, w = 0; i < numlines; i++) {
59 which_line = next;
60 next = arena[next].line[0];
61 if((w % write_cycle) != (write_cycle - 1)) {
62 sum += next;
63 }
64 else {
65 ((volatile cacheline_t*)arena)[which_line].line[0] = next;
66 }
67 }
68 }
69 return sum;
70}
71
72static cacheline_t* random_start(int wss)
73{
74 return arena + randrange(0, ((wss * 1024)/sizeof(cacheline_t)));
75}
76
77static volatile int dont_optimize_me = 0;
78
79static void usage(char *error) {
80 fprintf(stderr, "Error: %s\n", error);
81 fprintf(stderr,
82 "Usage:\n"
83 " rt_spin [COMMON-OPTS] WCET PERIOD DURATION\n"
84 " rt_spin [COMMON-OPTS] -f FILE [-o COLUMN] WCET PERIOD\n"
85 " rt_spin -l\n"
86 "\n"
87 "COMMON-OPTS = [-w] [-s SCALE]\n"
88 " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-m CRITICALITY LEVEL]\n"
89 " [-k WSS] [-l LOOPS] [-b BUDGET]\n"
90 "\n"
91 "WCET and PERIOD are milliseconds, DURATION is seconds.\n");
92 exit(EXIT_FAILURE);
93}
94
95static int loop_once(int wss)
96{
97 cacheline_t *mem;
98 int temp;
99
100 mem = random_start(wss);
101 temp = random_walk(mem, wss, 0);
102
103 dont_optimize_me = temp;
104
105 return dont_optimize_me;
106}
107
108static int job(int wss, double exec_time, double program_end)
109{
110 if (wctime() > program_end)
111 return 0;
112 else {
113 register unsigned int iter = 0;
114 register cycles_t t;
115 t = get_cycles();
116 while(iter++ < loops) {
117 loop_once(wss);
118 }
119 t = get_cycles() - t;
120 if (verbose)
121 printf("%ld cycles\n", t);
122 sleep_next_period();
123 return 1;
124 }
125}
126
127#define OPTSTR "p:wl:m:i:b:k:v"
128int main(int argc, char** argv)
129{
130 int ret;
131 lt_t wcet, period, budget;
132 double wcet_ms, period_ms, budget_ms;
133 unsigned int priority = LITMUS_NO_PRIORITY;
134 int migrate = 0;
135 int cluster = 0;
136 int opt;
137 int wait = 0;
138 double duration = 0, start = 0;
139 struct rt_task param;
140 struct mc2_task mc2_param;
141 struct reservation_config config;
142 int res_type = PERIODIC_POLLING;
143 size_t arena_sz;
144 int wss = 0;
145
146 /* default for reservation */
147 config.id = 0;
148 config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */
149 config.cpu = -1;
150
151 mc2_param.crit = CRIT_LEVEL_C;
152
153 budget_ms = 1000;
154
155 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
156 switch (opt) {
157 case 'w':
158 wait = 1;
159 break;
160 case 'p':
161 cluster = atoi(optarg);
162 migrate = 1;
163 config.cpu = cluster;
164 break;
165 case 'l':
<