aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2013-01-10 17:45:18 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2013-01-10 17:45:18 -0500
commit1bf0f0094cd9671adfc07cf840bde67cd4cc0c38 (patch)
tree12df5ca23e87df7813e845cb816a57a1d4b75d7d /src
parent7ec25a0856dd998c4edd63dc4b91799a91158d00 (diff)
parentd427bf8561f488bfec36b14b02af5b8ca0b2782f (diff)
Merge branch 'mpi-master' into wip-2012.3-gpu
Conflicts: Makefile bin/rtspin.c include/litmus.h src/litmus.c
Diffstat (limited to 'src')
-rw-r--r--src/clocks.c11
-rw-r--r--src/kernel_iface.c50
-rw-r--r--src/litmus.c60
3 files changed, 117 insertions, 4 deletions
diff --git a/src/clocks.c b/src/clocks.c
index fcb94e5..74c2fb4 100644
--- a/src/clocks.c
+++ b/src/clocks.c
@@ -3,6 +3,8 @@
3#include <sys/time.h> 3#include <sys/time.h>
4#include <time.h> 4#include <time.h>
5 5
6#include "litmus.h"
7
6/* CPU time consumed so far in seconds */ 8/* CPU time consumed so far in seconds */
7double cputime(void) 9double cputime(void)
8{ 10{
@@ -21,3 +23,12 @@ double wctime(void)
21 gettimeofday(&tv, NULL); 23 gettimeofday(&tv, NULL);
22 return (tv.tv_sec + 1E-6 * tv.tv_usec); 24 return (tv.tv_sec + 1E-6 * tv.tv_usec);
23} 25}
26
27int lt_sleep(lt_t timeout)
28{
29 struct timespec delay;
30
31 delay.tv_sec = timeout / 1000000000L;
32 delay.tv_nsec = timeout % 1000000000L;
33 return nanosleep(&delay, NULL);
34}
diff --git a/src/kernel_iface.c b/src/kernel_iface.c
index 33d56df..4cc1af5 100644
--- a/src/kernel_iface.c
+++ b/src/kernel_iface.c
@@ -12,6 +12,8 @@
12#define LITMUS_CTRL_DEVICE "/dev/litmus/ctrl" 12#define LITMUS_CTRL_DEVICE "/dev/litmus/ctrl"
13#define CTRL_PAGES 1 13#define CTRL_PAGES 1
14 14
15#define LITMUS_STATS_FILE "/proc/litmus/stats"
16
15static int map_file(const char* filename, void **addr, size_t size) 17static int map_file(const char* filename, void **addr, size_t size)
16{ 18{
17 int error = 0; 19 int error = 0;
@@ -35,6 +37,43 @@ static int map_file(const char* filename, void **addr, size_t size)
35 return error; 37 return error;
36} 38}
37 39
40ssize_t read_file(const char* fname, void* buf, size_t maxlen)
41{
42 int fd;
43 ssize_t n = 0;
44 size_t got = 0;
45
46 fd = open(fname, O_RDONLY);
47 if (fd == -1)
48 return -1;
49
50 while (got < maxlen && (n = read(fd, buf + got, maxlen - got)) > 0)
51 got += n;
52 close(fd);
53 if (n < 0)
54 return -1;
55 else
56 return got;
57}
58
59int get_nr_ts_release_waiters(void)
60{
61 int ready = 0, all = 0;
62 char buf[100];
63 ssize_t len;
64
65 len = read_file(LITMUS_STATS_FILE, buf, sizeof(buf) - 1);
66 if (len >= 0)
67 len = sscanf(buf,
68 "real-time tasks = %d\n"
69 "ready for release = %d\n",
70 &all, &ready);
71 if (len == 2)
72 return ready;
73 else
74 return len;
75}
76
38/* thread-local pointer to control page */ 77/* thread-local pointer to control page */
39static __thread struct control_page *ctrl_page; 78static __thread struct control_page *ctrl_page;
40 79
@@ -43,7 +82,16 @@ int init_kernel_iface(void)
43 int err = 0; 82 int err = 0;
44 long page_size = sysconf(_SC_PAGESIZE); 83 long page_size = sysconf(_SC_PAGESIZE);
45 84
46 BUILD_BUG_ON(sizeof(union np_flag) != sizeof(uint32_t)); 85 BUILD_BUG_ON(sizeof(union np_flag) != sizeof(uint64_t));
86
87 BUILD_BUG_ON(offsetof(struct control_page, sched.raw)
88 != LITMUS_CP_OFFSET_SCHED);
89 BUILD_BUG_ON(offsetof(struct control_page, irq_count)
90 != LITMUS_CP_OFFSET_IRQ_COUNT);
91 BUILD_BUG_ON(offsetof(struct control_page, ts_syscall_start)
92 != LITMUS_CP_OFFSET_TS_SC_START);
93 BUILD_BUG_ON(offsetof(struct control_page, irq_syscall_start)
94 != LITMUS_CP_OFFSET_IRQ_SC_START);
47 95
48 err = map_file(LITMUS_CTRL_DEVICE, (void**) &ctrl_page, CTRL_PAGES * page_size); 96 err = map_file(LITMUS_CTRL_DEVICE, (void**) &ctrl_page, CTRL_PAGES * page_size);
49 if (err) { 97 if (err) {
diff --git a/src/litmus.c b/src/litmus.c
index 3bab483..c026af0 100644
--- a/src/litmus.c
+++ b/src/litmus.c
@@ -10,6 +10,55 @@
10#include "litmus.h" 10#include "litmus.h"
11#include "internal.h" 11#include "internal.h"
12 12
13#define LP(name) {name ## _SEM, #name}
14
15static struct {
16 int id;
17 const char* name;
18} protocol[] = {
19 LP(FMLP),
20 LP(SRP),
21 LP(MPCP),
22 LP(MPCP_VS),
23 {MPCP_VS_SEM, "MPCP-VS"},
24 LP(DPCP),
25 LP(PCP),
26
27 {RSM_MUTEX, "RSM"},
28 LP(IKGLP),
29 LP(KFMLP),
30
31 {IKGLP_SIMPLE_GPU_AFF_OBS, "IKGLP-GPU-SIMPLE"},
32 {IKGLP_GPU_AFF_OBS, "IKGLP-GPU"},
33 {KFMLP_SIMPLE_GPU_AFF_OBS, "KFMLP-GPU-SIMPLE"},
34 {KFMLP_GPU_AFF_OBS, "KFMLP-GPU"},
35};
36
37#define NUM_PROTOS (sizeof(protocol)/sizeof(protocol[0]))
38
39int lock_protocol_for_name(const char* name)
40{
41 int i;
42
43 for (i = 0; i < NUM_PROTOS; i++)
44 if (strcmp(name, protocol[i].name) == 0)
45 return protocol[i].id;
46
47 return -1;
48}
49
50const char* name_for_lock_protocol(int id)
51{
52 int i;
53
54 for (i = 0; i < NUM_PROTOS; i++)
55 if (protocol[i].id == id)
56 return protocol[i].name;
57
58 return "<UNKNOWN>";
59}
60
61
13void show_rt_param(struct rt_task* tp) 62void show_rt_param(struct rt_task* tp)
14{ 63{
15 printf("rt params:\n\t" 64 printf("rt params:\n\t"
@@ -42,17 +91,20 @@ int be_migrate_to(int target_cpu)
42} 91}
43 92
44int sporadic_task(lt_t e, lt_t p, lt_t phase, 93int sporadic_task(lt_t e, lt_t p, lt_t phase,
45 int cpu, task_class_t cls, 94 int cpu, unsigned int priority,
95 task_class_t cls,
46 budget_policy_t budget_policy, 96 budget_policy_t budget_policy,
47 budget_signal_policy_t budget_signal_policy, 97 budget_signal_policy_t budget_signal_policy,
48 int set_cpu_set) 98 int set_cpu_set)
49{ 99{
50 return sporadic_task_ns(e * NS_PER_MS, p * NS_PER_MS, phase * NS_PER_MS, 100 return sporadic_task_ns(e * NS_PER_MS, p * NS_PER_MS, phase * NS_PER_MS,
51 cpu, cls, budget_policy, budget_signal_policy, set_cpu_set); 101 cpu, priority, cls, budget_policy, budget_signal_policy,
102 set_cpu_set);
52} 103}
53 104
54int sporadic_task_ns(lt_t e, lt_t p, lt_t phase, 105int sporadic_task_ns(lt_t e, lt_t p, lt_t phase,
55 int cpu, task_class_t cls, 106 int cpu, unsigned int priority,
107 task_class_t cls,
56 budget_policy_t budget_policy, 108 budget_policy_t budget_policy,
57 budget_signal_policy_t budget_signal_policy, 109 budget_signal_policy_t budget_signal_policy,
58 int set_cpu_set) 110 int set_cpu_set)
@@ -67,11 +119,13 @@ int sporadic_task_ns(lt_t e, lt_t p, lt_t phase,
67 119
68 param.exec_cost = e; 120 param.exec_cost = e;
69 param.period = p; 121 param.period = p;
122 param.relative_deadline = p; /* implicit deadline */
70 param.cpu = cpu; 123 param.cpu = cpu;
71 param.cls = cls; 124 param.cls = cls;
72 param.phase = phase; 125 param.phase = phase;
73 param.budget_policy = budget_policy; 126 param.budget_policy = budget_policy;
74 param.budget_signal_policy = budget_signal_policy; 127 param.budget_signal_policy = budget_signal_policy;
128 param.priority = priority;
75 129
76 if (set_cpu_set) { 130 if (set_cpu_set) {
77 ret = be_migrate_to(cpu); 131 ret = be_migrate_to(cpu);