summaryrefslogtreecommitdiffstats
path: root/extra_prev.h
diff options
context:
space:
mode:
authorleochanj105 <leochanj@live.unc.edu>2021-10-28 11:15:36 -0400
committerleochanj105 <leochanj@live.unc.edu>2021-10-28 11:15:36 -0400
commitedfb01f94b56fcc3e3bc7098e233fcbbb862b462 (patch)
tree1328ed4594a2fea8ac3d1abae6bd53006e59ca8f /extra_prev.h
parent14c854543b1a3cf344a371a5b45595657f95786b (diff)
fix stitch and loc, added flush
Diffstat (limited to 'extra_prev.h')
-rw-r--r--extra_prev.h601
1 files changed, 601 insertions, 0 deletions
diff --git a/extra_prev.h b/extra_prev.h
new file mode 100644
index 0000000..64d334f
--- /dev/null
+++ b/extra_prev.h
@@ -0,0 +1,601 @@
1/**
2 * Copyright 2019 Sims Hill Osborne and 2020 Joshua Bakita
3 *
4 * This header provides facilities by which to separably run and time TACLeBench
5 * To use this for paired task timing, define PAIRED (pass CFLAGS=-DPAIRED to make)
6 **/
7#define _GNU_SOURCE
8#include <fcntl.h> // For O_CREAT and O_RDWR
9#include <sched.h> // For sched_yield()
10#include <semaphore.h> // For sem_{open, post, wait}()
11#include <stdio.h>
12#include <stdlib.h> // For exit()
13#include <string.h> // For strlen()
14#include <sys/mman.h> // For mlockall()
15#include <unistd.h> // For ftruncate()
16#include <time.h>
17
18// This is only visible if _GNU_SOURCE is defined, and that define does not
19// come along to places where this file is included. Address this by manually
20// forcing it into the global namespace.
21extern int sched_getcpu();
22
23// These constants correspond to the imx6q-sabredb platform
24#define LINE_SIZE 32
25#define L2_SIZE 16*2048*32
26
27#if __arm__
28#include <unistd.h>
29#include <sys/syscall.h>
30#endif
31
32// This is a proxy for "case study mode" now
33#define LITMUS 0
34#define MMDC_PROF 0
35
36#if LITMUS
37#include <litmus.h>
38#endif
39
40#if MMDC_PROF
41#include "/media/speedy/litmus/tools/mmdc/mmdc.h"
42#endif
43
44// Store state globally so that the job can be outside main()
45// Arrays use float as a comprimise between overflow and size
46// Paired arrays use long longs as precision is more important for those times
47// #ifdef PAIRED
48long long *_rt_start_time;
49long long *_rt_end_time;
50// #else
51float *_rt_exec_time;
52// #endif
53#if MMDC_PERF
54float *_rt_mmdc_read;
55float *_rt_mmdc_write;
56#endif
57long _rt_jobs_complete;
58long _rt_max_jobs;
59int _rt_core;
60int _rt_will_output;
61struct timespec _rt_start, _rt_end;
62
63char *_rt_run_id;
64char *_rt_our_prog_name;
65char *_rt_other_prog_name;
66char *_rt_other_core;
67#define _RT_FILENAME_LEN 64
68#define _BILLION (1000*1000*1000)
69#ifdef PAIRED
70char *_rt_barrier;
71sem_t *_rt_first_sem, *_rt_second_sem;
72int _rt_lock_id;
73#define _ID_SZ 128
74char _rt_sem1_name[_ID_SZ] = "/_libextra_first_sem-";
75char _rt_sem2_name[_ID_SZ] = "/_libextra_second_sem-";
76char _rt_shm_name[_ID_SZ] = "/_libextra_barrier-";
77#endif /* PAIRED */
78
79#if LITMUS
80lt_t _rt_period;
81lt_t _rt_phase;
82lt_t _rt_cost;
83lt_t _rt_deadline;
84int _rt_crit;
85struct control_page *_rt_cp;
86#endif
87
88static void _rt_load_params_itrl(int argc, char **argv) {
89#ifdef PAIRED
90 if (argc != (8 + LITMUS*5) && argc != (9 + LITMUS*5)) {
91 fprintf(stderr, "Usage: %s <name> <loops> <my core> <other core> <other name> <runID> <save results?> <pairID>\n", argv[0]);
92#else
93 if (argc != (6 + LITMUS*5)) {
94 fprintf(stderr, "Usage: %s <name> <loops> <my core> <runID> <save results?>\n", argv[0]);
95#endif /* PAIRED */
96 fprintf(stderr, " <name> string for logging. Name of this task.\n");
97 fprintf(stderr, " <loops> integer number of iterations. -1 for infinite.\n");
98 fprintf(stderr, " <my core> integer core number. Only used for LITMUS-RT.\n");
99#ifdef PAIRED
100 fprintf(stderr, " <other core> integer for logging. Core of paired task.\n");
101 fprintf(stderr, " <other name> string for logging. Name of paired task.\n");
102#endif /* PAIRED */
103 fprintf(stderr, " <runID> string to append with .txt to yield output file name.\n");
104 fprintf(stderr, " <save results?> 1 to save results, 0 to discard.\n");
105#ifdef PAIRED
106 fprintf(stderr, " <pairID> (optional).\n");
107#endif
108#if LITMUS
109 fprintf(stderr, " <task period> in ms\n");
110 fprintf(stderr, " <task criticality level> 0 for Level-A, 1 for Level-B, 2 for Level-C\n");
111 fprintf(stderr, " <task phase> in ms\n");
112 fprintf(stderr, " <task cost> in ms\n");
113 fprintf(stderr, " <task deadline> in ms\n");
114#endif /* LITMUS */
115 exit(1);
116 }
117 _rt_our_prog_name = argv[1];
118 _rt_max_jobs = atol(argv[2]);
119#if !LITMUS
120 _rt_core = sched_getcpu();
121#else
122 _rt_core = atoi(argv[3]);
123#endif
124#ifdef PAIRED
125 _rt_other_core = argv[4];
126 _rt_other_prog_name = argv[5];
127 _rt_run_id = argv[6];
128 _rt_will_output = atoi(argv[7]);
129 char *pairId;
130 int end;
131 if (argc > 8) {
132 pairId = argv[8];
133 end = 9;
134 } else {
135 pairId = "none";
136 end = 8;
137 }
138#else
139 _rt_other_core = "none";
140 _rt_other_prog_name = "none";
141 _rt_run_id = argv[4];
142 _rt_will_output = atoi(argv[5]);
143 int end = 6;
144#endif /* PAIRED */
145 if (_rt_max_jobs < 0 && _rt_will_output != 0) {
146 fprintf(stderr, "Infinite loops only supported when output is disabled!\n");
147 exit(1);
148 }
149 if (strlen(_rt_run_id) + 5 > _RT_FILENAME_LEN) {
150 fprintf(stderr, "Run ID is too large! Keep it to less than %d characters.\n", _RT_FILENAME_LEN);
151 exit(1);
152 }
153#ifdef PAIRED
154 // __rt_sem2_name happens to be the longest
155 if (strlen(pairId) + strlen(_rt_sem2_name) > _ID_SZ) {
156 fprintf(stderr, "PairID is too long! Maximum length is %ld characters.\n", _ID_SZ - strlen(_rt_sem2_name));
157 exit(1);
158 }
159 _rt_start_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long));
160 _rt_end_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long));
161 _rt_exec_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(float));
162 if (!_rt_end_time || !_rt_start_time) {
163 perror("Unable to allocate buffers for execution times");
164 exit(1);
165 }
166 // Use PairID to create unique semaphore and shared memory paths
167 strcat(_rt_sem1_name, pairId);
168 strcat(_rt_sem2_name, pairId);
169 strcat(_rt_shm_name, pairId);
170 _rt_first_sem = sem_open(_rt_sem1_name, O_CREAT, 644, 0);
171 _rt_second_sem = sem_open(_rt_sem2_name, O_CREAT, 644, 0);
172 if (_rt_first_sem == SEM_FAILED || _rt_second_sem == SEM_FAILED) {
173 perror("Error while creating semaphores");
174 exit(1);
175 }
176 // Create shared memory for barrier synchronization and infer lock ID
177 int barrier_file = shm_open(_rt_shm_name, O_CREAT | O_RDWR | O_EXCL, 644);
178 if (barrier_file == -1) {
179 // File already existed - we're the 2nd program and thus lock ID 2
180 _rt_lock_id = 2;
181 barrier_file = shm_open(_rt_shm_name, O_CREAT | O_RDWR, 644);
182 } else {
183 _rt_lock_id = 1;
184 }
185 if (barrier_file == -1) {
186 perror("Error while creating shared memory for barrier synchronization");
187 exit(1);
188 }
189 if (ftruncate(barrier_file, 2) == -1) {
190 perror("Error while setting size of shared memory for barrier synchronization");
191 exit(1);
192 }
193 _rt_barrier = mmap(NULL, 2, PROT_WRITE, MAP_SHARED, barrier_file, 0);
194 if (_rt_barrier == MAP_FAILED) {
195 perror("Error while mapping shared memory for barrier synchronization");
196 exit(1);
197 }
198 // If we're the 2nd user of this barrier, mark it as in-use
199 if (_rt_lock_id == 2 && !__sync_bool_compare_and_swap(_rt_barrier+1, 0, 1)) {
200 fprintf(stderr, "Pair ID already in use!\n");
201 exit(1);
202 }
203 *_rt_barrier = 0;
204#else
205 _rt_start_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long));
206 _rt_end_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long));
207 _rt_exec_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(float));
208 if (!_rt_exec_time) {
209 perror("Unable to allocate buffer for execution times");
210 exit(1);
211 }
212#endif /* PAIRED */
21