aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorztong <ztong@cs.unc.edu>2021-02-19 01:35:08 -0500
committerztong <ztong@cs.unc.edu>2021-02-19 01:35:08 -0500
commit8ef3072216b4e19789418052b4196584048cdb4e (patch)
tree55bba23230aa6957ea4e37c341690ca040c90e6a
parent78c0cda81ab19c68ee8302d24c7e30e3c45e8618 (diff)
Added liblitmus support for locking with CS length
-rw-r--r--bin/rtspin.c19
-rw-r--r--include/litmus.h6
-rw-r--r--src/syscalls.c8
3 files changed, 29 insertions, 4 deletions
diff --git a/bin/rtspin.c b/bin/rtspin.c
index 28bc956..74d97e2 100644
--- a/bin/rtspin.c
+++ b/bin/rtspin.c
@@ -83,6 +83,7 @@ const char *usage_msg =
83 " -L CS-LENGTH simulate a critical section length of CS-LENGTH milliseconds\n" 83 " -L CS-LENGTH simulate a critical section length of CS-LENGTH milliseconds\n"
84 " -Q RESOURCE-ID access the resource identified by RESOURCE-ID\n" 84 " -Q RESOURCE-ID access the resource identified by RESOURCE-ID\n"
85 " -Z enable checking for forbidden zones after locking a resource\n" 85 " -Z enable checking for forbidden zones after locking a resource\n"
86 " -K enable passing worst-case critical-section duration to lock calls\n"
86 "\n" 87 "\n"
87 "Units:\n" 88 "Units:\n"
88 " WCET and PERIOD are expected in milliseconds.\n" 89 " WCET and PERIOD are expected in milliseconds.\n"
@@ -299,9 +300,10 @@ static int generate_output(int output_fd)
299 return written == len; 300 return written == len;
300} 301}
301 302
302static void job(double exec_time, double program_end, int lock_od, double cs_length, int check_fz) 303static void job(double exec_time, double program_end, int lock_od, double cs_length, int check_fz, int pass_cs_len)
303{ 304{
304 double chunk1, chunk2; 305 double chunk1, chunk2;
306 int lock_res;
305 307
306 if (lock_od >= 0) { 308 if (lock_od >= 0) {
307 /* simulate critical section somewhere in the middle */ 309 /* simulate critical section somewhere in the middle */
@@ -312,7 +314,12 @@ static void job(double exec_time, double program_end, int lock_od, double cs_len
312 loop_for(chunk1, program_end + 1); 314 loop_for(chunk1, program_end + 1);
313 315
314 /* critical section */ 316 /* critical section */
315 litmus_lock(lock_od); 317 if (pass_cs_len == 1)
318 lock_res = litmus_lock_cs(lock_od, cs_length);
319 else
320 lock_res = litmus_lock(lock_od);
321 if (lock_res != 0)
322 printf("Result of lock call: %d\n", lock_res);
316 if (check_fz) 323 if (check_fz)
317 litmus_access_forbidden_zone_check(lock_od, s2ns(cs_length), 0.9 * s2ns(cs_length)); 324 litmus_access_forbidden_zone_check(lock_od, s2ns(cs_length), 0.9 * s2ns(cs_length));
318 loop_for(cs_length, program_end + 1); 325 loop_for(cs_length, program_end + 1);
@@ -339,7 +346,7 @@ static lt_t choose_inter_arrival_time_ns(
339 return ms2ns(iat_ms); 346 return ms2ns(iat_ms);
340} 347}
341 348
342#define OPTSTR "p:c:wlveo:s:m:q:r:X:L:Q:ZiRu:U:Bhd:C:S::O::TD:E:A:a:" 349#define OPTSTR "p:c:wlveo:s:m:q:r:X:L:Q:ZKiRu:U:Bhd:C:S::O::TD:E:A:a:"
343 350
344int main(int argc, char** argv) 351int main(int argc, char** argv)
345{ 352{
@@ -406,6 +413,7 @@ int main(int argc, char** argv)
406 int protocol = -1; 413 int protocol = -1;
407 double cs_length = 1; /* millisecond */ 414 double cs_length = 1; /* millisecond */
408 int check_fz = 0; 415 int check_fz = 0;
416 int pass_cs_len = 0;
409 417
410 progname = argv[0]; 418 progname = argv[0];
411 419
@@ -537,6 +545,9 @@ int main(int argc, char** argv)
537 case 'Z': 545 case 'Z':
538 check_fz = 1; 546 check_fz = 1;
539 break; 547 break;
548 case 'K':
549 pass_cs_len = 1;
550 break;
540 case 'v': 551 case 'v':
541 verbose = 1; 552 verbose = 1;
542 break; 553 break;
@@ -810,7 +821,7 @@ int main(int argc, char** argv)
810 (acet * 1000 / wcet_ms) * 100); 821 (acet * 1000 / wcet_ms) * 100);
811 822
812 /* burn cycles */ 823 /* burn cycles */
813 job(acet, start + duration, lock_od, cs_length * 0.001, check_fz); 824 job(acet, start + duration, lock_od, cs_length * 0.001, check_fz, pass_cs_len);
814 825
815 if (want_output) { 826 if (want_output) {
816 /* generate some output at end of job */ 827 /* generate some output at end of job */
diff --git a/include/litmus.h b/include/litmus.h
index b4affb1..dd9b95f 100644
--- a/include/litmus.h
+++ b/include/litmus.h
@@ -235,6 +235,12 @@ int litmus_open_lock(obj_type_t protocol, int lock_id, const char* name_space,
235 */ 235 */
236int litmus_lock(int od); 236int litmus_lock(int od);
237/** 237/**
238 * Obtain lock with specified worst-case critical section duration
239 * @param od Object descriptor obtained by litmus_open_lock()
240 * @return 0 iff the lock was opened successfully
241 */
242int litmus_lock_cs(int od, lt_t cs_len);
243/**
238 * Access protected resource (wait if in forbidden zone) 244 * Access protected resource (wait if in forbidden zone)
239 * @param od Object descriptor obtained by litmus_open_lock() 245 * @param od Object descriptor obtained by litmus_open_lock()
240 * @return 0 iff the resource access was granted successfully 246 * @return 0 iff the resource access was granted successfully
diff --git a/src/syscalls.c b/src/syscalls.c
index a87a6fe..7d1b12a 100644
--- a/src/syscalls.c
+++ b/src/syscalls.c
@@ -67,6 +67,14 @@ int litmus_lock(int od)
67 return litmus_syscall(LRT_litmus_lock, od); 67 return litmus_syscall(LRT_litmus_lock, od);
68} 68}
69 69
70int litmus_lock_cs(int od, lt_t cs_len)
71{
72 union litmus_syscall_args args;
73 args.litmus_lock_cs.sem_od = od;
74 args.litmus_lock_cs.cs_len = cs_len;
75 return litmus_syscall(LRT_litmus_lock_cs, (unsigned long) &args);
76}
77
70int litmus_access_forbidden_zone_check(int od, lt_t fz_len, lt_t fz_police) 78int litmus_access_forbidden_zone_check(int od, lt_t fz_len, lt_t fz_police)
71{ 79{
72 union litmus_syscall_args args; 80 union litmus_syscall_args args;