aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rt_field.c
diff options
context:
space:
mode:
authorNamhoon Kim <namhoonk@cs.unc.edu>2017-05-01 16:02:05 -0400
committerNamhoon Kim <namhoonk@cs.unc.edu>2017-05-01 16:02:05 -0400
commit11765fcf37057053065abd3715cf9cb46f2fa4db (patch)
tree8403d716bbcbd96493c481a82e7e02b5da9231e8 /bin/rt_field.c
parentbfee87a910560e022b04c81a026b1f88522cd62f (diff)
RTSS17 submitwip-modechange
Diffstat (limited to 'bin/rt_field.c')
-rw-r--r--bin/rt_field.c379
1 files changed, 0 insertions, 379 deletions
diff --git a/bin/rt_field.c b/bin/rt_field.c
deleted file mode 100644
index ac79020..0000000
--- a/bin/rt_field.c
+++ /dev/null
@@ -1,379 +0,0 @@
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
12#include "litmus.h"
13#include "common.h"
14#include "DISstressmarkRNG.h"
15
16#define MIN_FIELD_SIZE 16
17#define MAX_FIELD_SIZE 16777216
18#define MIN_SEED -2147483647
19#define MAX_SEED -1
20#define MIN_MOD_OFFSET 0
21#define MAX_MOD_OFFSET 65535
22#define MIN_TOKENS 1
23#define MAX_TOKENS 256
24#define MIN_TOKEN_LENGTH 1
25#define MAX_TOKEN_LENGTH 8
26#define MIN_TOKEN_VALUE 0
27#define MAX_TOKEN_VALUE 255
28#define MAX_SUBFIELDS 256
29
30static char* progname;
31int loops = 1;
32
33struct timeval t1, t2;
34
35struct tokenS{
36 unsigned char delimiter[MAX_TOKEN_LENGTH];
37 unsigned char length;
38 struct statisticS{
39 unsigned int count;
40 unsigned char min;
41 unsigned char sum;
42 } stat[MAX_SUBFIELDS];
43 unsigned char subfields;
44} token[MAX_TOKENS];
45
46unsigned char *field;
47unsigned int f_max;
48int seed;
49int mod_offset;
50unsigned int n_max;
51
52unsigned char input_token[8] = {0x1, 0x1, 0x22, 0x1, 0xc2, 0x1, 0x2d, 0x0};
53
54int init_job(){
55 //fscanf(stdin, "%d %d %d %d", &f, &seed, &mod_offset, &n);
56 f_max = 262144;
57 seed = -2;
58 n_max = 128;
59
60 assert((seed >= MIN_SEED) && (seed <= MAX_SEED));
61
62 if ((field = (unsigned char*)malloc(f_max*sizeof(unsigned char))) == NULL)
63 return (-1);
64
65 randInit(seed);
66
67 return 0;
68}
69
70int main_job() {
71 unsigned int l, f, n;
72
73 /* for online */
74/* f = randInt(65536, f_max);
75 mod_offset = randInt(128, 8192);
76 n = 20; //randInt(64, n_max);
77*/
78
79 /* for case */
80
81 f = randInt(64, 18000);
82 mod_offset = randInt(128, 8192);
83 n = 1; //randInt(64, n_max);
84
85
86 assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE));
87 assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET));
88 assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS));
89
90 for (l=0; l<n; l++){
91 int index;
92 for (index = 0; index<MAX_TOKEN_LENGTH; index++) {
93 unsigned char x = input_token[index];
94 assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE));
95 token[l].delimiter[index] = (unsigned char )x;
96 }
97 token[l].length = index;
98 }
99
100 for (l =0; l<f; l++){
101 field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE);
102 }
103
104 for (l =0; l<n; l++){
105 unsigned int index;
106
107 token[l].subfields = 0;
108 token[l].stat[0].count = 0;
109 token[l].stat[0].sum = 0;
110 token[l].stat[0].min = MAX_TOKEN_VALUE;
111
112 index = 0;
113 while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)){
114 unsigned char offset;
115 offset = 0;
116 while ((field[index+offset] == token[l].delimiter[offset]) &&
117 (offset < token[l].length)){
118 offset++;
119 }
120
121 if (offset == token[l].length){
122 for (offset=0; offset<token[l].length; offset++){
123 field[index+offset] = (field[index+offset] +
124 field[(index+offset+mod_offset) % f])
125 %(MAX_TOKEN_VALUE+1);
126 }
127 index += token[l].length-1;
128 token[l].subfields++;
129 token[l].stat[token[l].subfields].count = 0;
130 token[l].stat[token[l].subfields].sum = 0;
131 token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE;
132 }
133 else {
134 token[l].stat[token[l].subfields].count++;
135 token[l].stat[token[l].subfields].sum += field[index];
136 if (token[l].stat[token[l].subfields].min > field[index])
137 token[l].stat[token[l].subfields].min = field[index];
138 }
139 index++;
140 }
141 }
142
143 return 0;
144}
145
146int post_job() {
147 if (field) {
148 free(field);
149 field = NULL;
150 }
151
152 return(0);
153}
154
155static void usage(char *error) {
156 fprintf(stderr, "Error: %s\n", error);
157 fprintf(stderr,
158 "Usage:\n"
159 " rt_spin [COMMON-OPTS] WCET PERIOD DURATION\n"
160 " rt_spin [COMMON-OPTS] -f FILE [-o COLUMN] WCET PERIOD\n"
161 " rt_spin -l\n"
162 "\n"
163 "COMMON-OPTS = [-w] [-s SCALE]\n"
164 " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-c CLASS] [-m CRITICALITY LEVEL]\n"
165 "\n"
166 "WCET and PERIOD are microseconds, DURATION is seconds.\n");
167 exit(EXIT_FAILURE);
168}
169
170inline unsigned long get_cyclecount (void)
171{
172 unsigned long value;
173 // Read CCNT Register
174 asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));
175 return value;
176}
177
178static int job(double exec_time, double program_end)
179{
180 if (wctime() > program_end)
181 return 0;
182 else {
183 register int iter = 0;
184 //register unsigned long t;
185 //t = get_cyclecount();
186 //gettimeofday(&t1, NULL);
187 while (iter++ < loops) {
188 main_job();
189 }
190 //t = get_cyclecount() - t;
191 //printf("%ld cycles\n", t);
192 //gettimeofday(&t2, NULL);
193 //printf("%ld\n", ((t2.tv_sec * 1000000 + t2.tv_usec) - (t1.tv_sec * 1000000 + t1.tv_usec)));
194 sleep_next_period();
195 return 1;
196 }
197}
198
199#define OPTSTR "p:wves:l:m:i:b:"
200int main(int argc, char** argv)
201{
202 int ret;
203 lt_t wcet;
204 lt_t period;
205 lt_t budget;
206 double wcet_ms, period_ms, budget_ms;
207 unsigned int priority = LITMUS_NO_PRIORITY;
208 int migrate = 0;
209 int cluster = 0;
210 int opt;
211 int wait = 0;
212 int want_enforcement = 0;
213 double duration = 0, start = 0;
214 double scale = 1.0;
215 task_class_t class = RT_CLASS_HARD;
216 struct rt_task param;
217 struct mc2_task mc2_param;
218 struct reservation_config config;
219 int res_type = PERIODIC_POLLING;
220
221 progname = argv[0];
222
223 /* default for reservation */
224 config.id = 0;
225 config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */
226 config.cpu = -1;
227
228 mc2_param.crit = CRIT_LEVEL_C;
229
230 budget_ms = 10;
231
232 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
233 switch (opt) {
234 case 'w':
235 wait = 1;
236 break;
237 case 'p':
238 cluster = atoi(optarg);
239 migrate = 1;
240 config.cpu = cluster;
241 break;
242 case 'e':
243 want_enforcement = 1;
244 break;
245 case 's':
246 scale = atof(optarg);
247 break;
248 case 'l':
249 loops = atoi(optarg);
250 break;
251 case 'm':
252 mc2_param.crit = atoi(optarg);
253 if (mc2_param.crit < CRIT_LEVEL_A || mc2_param.crit == NUM_CRIT_LEVELS) {
254 usage("Invalid criticality level.");
255 }
256 res_type = PERIODIC_POLLING;
257 break;
258 case 'b':
259 budget_ms = atof(optarg);
260 break;
261 case 'i':
262 config.priority = atoi(optarg);
263 break;
264 case ':':
265 usage("Argument missing.");
266 break;
267 case '?':
268 default:
269 usage("Bad argument.");
270 break;
271 }
272 }
273
274 if (mc2_param.crit > CRIT_LEVEL_A && config.priority != LITMUS_NO_PRIORITY)
275 usage("Bad criticailty level or priority");
276
277 if (argc - optind < 3)
278 usage("Arguments missing.");
279
280 wcet_ms = atof(argv[optind + 0]);
281 period_ms = atof(argv[optind + 1]);
282
283 wcet = ms2ns(wcet_ms);
284 period = ms2ns(period_ms);
285 budget = ms2ns(budget_ms);
286
287 if (wcet <= 0)
288 usage("The worst-case execution time must be a "
289 "positive number.");
290 if (period <= 0)
291 usage("The period must be a positive number.");
292 if (wcet > period) {
293 usage("The worst-case execution time must not "
294 "exceed the period.");
295 }
296
297 duration = atof(argv[optind + 2]);
298
299 if (migrate) {
300 ret = be_migrate_to_domain(cluster);
301 if (ret < 0)
302 bail_out("could not migrate to target partition or cluster.");
303 }
304
305 /* reservation config */
306 config.id = gettid();
307
308 config.polling_params.budget = budget;
309 config.polling_params.period = period;
310 config.polling_params.offset = 0;
311 config.polling_params.relative_deadline = 0;
312 if (config.polling_params.budget > config.polling_params.period) {
313 usage("The budget must not exceed the period.");
314 }
315
316 /* create a reservation */
317 ret = reservation_create(res_type, &config);
318 if (ret < 0) {
319 bail_out("failed to create reservation.");
320 }
321 init_job();
322
323 init_rt_task_param(&param);
324 param.exec_cost = wcet;
325 param.period = period;
326 param.priority = priority;
327 param.cls = class;
328 param.release_policy = TASK_PERIODIC;
329 param.budget_policy = (want_enforcement) ?
330 PRECISE_ENFORCEMENT : NO_ENFORCEMENT;
331 if (migrate) {
332 param.cpu = gettid();
333 }
334 ret = set_rt_task_param(gettid(), &param);
335
336 if (ret < 0)
337 bail_out("could not setup rt task params");
338
339 mc2_param.res_id = gettid();
340 ret = set_mc2_task_param(gettid(), &mc2_param);
341//printf("SET_MC2_TASK\n");
342 if (ret < 0)
343 bail_out("could not setup mc2 task params");
344
345 init_litmus();
346//printf("CALL\n");
347 if (mc2_param.crit == CRIT_LEVEL_C)
348 set_page_color(-1);
349 else if (mc2_param.crit < CRIT_LEVEL_C)
350 set_page_color(config.cpu);
351//printf("CALL\n");
352
353//printf("INIT_LITMUS\n");
354 start = wctime();
355 ret = task_mode(LITMUS_RT_TASK);
356//printf("TASK_MODE\n");
357 if (ret != 0)
358 bail_out("could not become RT task");
359
360
361 if (wait) {
362//printf("BEFORE WAIT\n");
363 ret = wait_for_ts_release();
364 if (ret != 0)
365 bail_out("wait_for_ts_release()");
366 start = wctime();
367 }
368
369 while (job(wcet_ms * 0.001 * scale, start + duration)) {};
370
371 ret = task_mode(BACKGROUND_TASK);
372 if (ret != 0)
373 bail_out("could not become regular task (huh?)");
374
375 reservation_destroy(gettid(), config.cpu);
376 post_job();
377 printf("%s/%d finished.\n",progname, gettid());
378 return 0;
379}