diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/sched_trace.h (renamed from include/logformat.h) | 81 | ||||
-rw-r--r-- | src/sched_trace.c | 75 |
3 files changed, 127 insertions, 31 deletions
@@ -39,5 +39,5 @@ rt_launch: liblitmus.a litmus.h rt_launch.o | |||
39 | edfhsb: liblitmus.a edf-hsb.o litmus.h edf-hsb.h hrt.o | 39 | edfhsb: liblitmus.a edf-hsb.o litmus.h edf-hsb.h hrt.o |
40 | cc -o edfhsb hrt.o edf-hsb.o ${LIBS} | 40 | cc -o edfhsb hrt.o edf-hsb.o ${LIBS} |
41 | 41 | ||
42 | liblitmus.a: litmus.o adaptive.o adaptive.h litmus.h edf-hsb.o edf-hsb.h | 42 | liblitmus.a: litmus.o sched_trace.o adaptive.o adaptive.h litmus.h edf-hsb.o edf-hsb.h |
43 | ${AR} rcs liblitmus.a litmus.o adaptive.o edf-hsb.o | 43 | ${AR} rcs liblitmus.a litmus.o adaptive.o edf-hsb.o |
diff --git a/include/logformat.h b/include/sched_trace.h index 3a74bf7..57f7876 100644 --- a/include/logformat.h +++ b/include/sched_trace.h | |||
@@ -1,37 +1,40 @@ | |||
1 | #ifndef LOGFORMAT_H | 1 | #ifndef __SCHED_TRACE_H_ |
2 | #define LOGFORMAT_H | 2 | #define __SCHED_TRACE_H_ |
3 | 3 | ||
4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
5 | 5 | ||
6 | #include "litmus.h" | ||
7 | |||
8 | typedef __u8 u8; | 6 | typedef __u8 u8; |
9 | typedef __u32 u32; | 7 | typedef __u32 u32; |
10 | typedef __u16 u16; | 8 | typedef __u16 u16; |
11 | 9 | ||
12 | typedef enum { | 10 | typedef enum { |
13 | ST_INVOCATION = 0, | 11 | ST_INVOCATION = 0, |
14 | ST_ARRIVAL = 1, | 12 | ST_ARRIVAL = 1, |
15 | ST_DEPARTURE = 2, | 13 | ST_DEPARTURE = 2, |
16 | ST_PREEMPTION = 3, | 14 | ST_PREEMPTION = 3, |
17 | ST_SCHEDULED = 4, | 15 | ST_SCHEDULED = 4, |
18 | ST_JOB_RELEASE = 5, | 16 | ST_JOB_RELEASE = 5, |
19 | ST_JOB_COMPLETION = 6, | 17 | ST_JOB_COMPLETION = 6, |
20 | ST_CAPACITY_RELEASE = 7, | 18 | ST_CAPACITY_RELEASE = 7, |
21 | ST_CAPACITY_ALLOCATION = 8, | 19 | ST_CAPACITY_ALLOCATION = 8, |
22 | ST_LAST_TYPE = 8 | 20 | ST_SERVICE_LEVEL_CHANGE = 9, |
21 | ST_WEIGHT_ERROR = 10, | ||
22 | |||
23 | |||
24 | ST_MAX | ||
23 | } trace_type_t; | 25 | } trace_type_t; |
24 | 26 | ||
27 | |||
25 | typedef struct { | 28 | typedef struct { |
26 | trace_type_t trace:8; | 29 | trace_type_t trace:8; |
27 | unsigned long long timestamp; | 30 | unsigned int size:24; |
31 | unsigned long long timestamp; | ||
28 | } trace_header_t; | 32 | } trace_header_t; |
29 | 33 | ||
30 | |||
31 | typedef struct { | 34 | typedef struct { |
32 | unsigned int is_rt:1; | 35 | unsigned int is_rt:1; |
33 | unsigned int is_server:1; | 36 | unsigned int is_server:1; |
34 | task_class_t cls:4; | 37 | task_class_t class:4; |
35 | unsigned int budget:24; | 38 | unsigned int budget:24; |
36 | u32 deadline; | 39 | u32 deadline; |
37 | 40 | ||
@@ -40,7 +43,7 @@ typedef struct { | |||
40 | 43 | ||
41 | typedef struct { | 44 | typedef struct { |
42 | trace_header_t header; | 45 | trace_header_t header; |
43 | unsigned long flags; | 46 | unsigned long flags; |
44 | } invocation_record_t; | 47 | } invocation_record_t; |
45 | 48 | ||
46 | typedef struct { | 49 | typedef struct { |
@@ -68,7 +71,7 @@ typedef struct { | |||
68 | trace_header_t header; | 71 | trace_header_t header; |
69 | task_info_t task; | 72 | task_info_t task; |
70 | u16 period; | 73 | u16 period; |
71 | u16 wcet; | 74 | u16 wcet; |
72 | } release_record_t; | 75 | } release_record_t; |
73 | 76 | ||
74 | typedef struct { | 77 | typedef struct { |
@@ -92,21 +95,39 @@ typedef struct { | |||
92 | pid_t donor; | 95 | pid_t donor; |
93 | } cap_allocation_record_t; | 96 | } cap_allocation_record_t; |
94 | 97 | ||
98 | typedef struct { | ||
99 | trace_header_t header; | ||
100 | task_info_t task; | ||
101 | service_level_t new_level; | ||
102 | } service_level_change_record_t; | ||
103 | |||
104 | typedef struct { | ||
105 | trace_header_t header; | ||
106 | pid_t task; | ||
107 | fp_t estimate; | ||
108 | fp_t actual; | ||
109 | } weight_error_record_t; | ||
110 | |||
111 | |||
112 | |||
95 | 113 | ||
96 | typedef union { | ||
97 | trace_header_t header; | ||
98 | invocation_record_t invocation; | ||
99 | arrival_record_t arrival; | ||
100 | preemption_record_t preemption; | ||
101 | scheduled_record_t scheduled; | ||
102 | 114 | ||
103 | release_record_t release; | ||
104 | completion_record_t completion; | ||
105 | 115 | ||
106 | cap_release_record_t cap_release; | ||
107 | cap_allocation_record_t cap_alloc; | ||
108 | } trace_record_t; | ||
109 | 116 | ||
117 | enum { | ||
118 | INVALID_HEADER = 1 | ||
119 | }; | ||
120 | |||
121 | typedef int (*record_callback_fn)(trace_header_t* hdr); | ||
122 | |||
123 | typedef struct { | ||
124 | record_callback_fn handler[ST_MAX]; | ||
125 | } record_callback_t; | ||
110 | 126 | ||
127 | #define init_record_callback(a) memset(a, 0, sizeof(record_callback_t)) | ||
128 | #define set_callback(type, fn, a) do {(a)->handler[type] = fn; } while (0); | ||
111 | 129 | ||
130 | int walk_sched_trace(void* start, void* end, record_callback_t *cb); | ||
131 | int walk_sched_trace_file(const char* name, int keep_mapped, | ||
132 | record_callback_t *cb); | ||
112 | #endif | 133 | #endif |
diff --git a/src/sched_trace.c b/src/sched_trace.c new file mode 100644 index 0000000..011b13b --- /dev/null +++ b/src/sched_trace.c | |||
@@ -0,0 +1,75 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <sys/mman.h> | ||
7 | #include <fcntl.h> | ||
8 | #include <unistd.h> | ||
9 | |||
10 | #include "litmus.h" | ||
11 | #include "adaptive.h" | ||
12 | #include "sched_trace.h" | ||
13 | |||
14 | |||
15 | int walk_sched_trace(void* start, void* end, record_callback_t *cb) | ||
16 | { | ||
17 | void* pos = start; | ||
18 | trace_header_t* header; | ||
19 | int ret; | ||
20 | |||
21 | while (pos < end) { | ||
22 | header = (trace_header_t*) pos; | ||
23 | if (header->trace >= ST_MAX) | ||
24 | return INVALID_HEADER; | ||
25 | if (cb->handler[header->trace]) | ||
26 | ret = cb->handler[header->trace](header); | ||
27 | if (ret) | ||
28 | return ret; | ||
29 | pos += header->size; | ||
30 | } | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | static int map_file(const char* filename, void **addr, size_t *size) | ||
35 | { | ||
36 | struct stat info; | ||
37 | int error = 0; | ||
38 | int fd; | ||
39 | |||
40 | error = stat(filename, &info); | ||
41 | if (!error) { | ||
42 | *size = info.st_size; | ||
43 | if (info.st_size > 0) { | ||
44 | fd = open(filename, O_RDONLY); | ||
45 | if (fd >= 0) { | ||
46 | *addr = mmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | ||
47 | if (*addr == MAP_FAILED) | ||
48 | error = -1; | ||
49 | close(fd); | ||
50 | } else | ||
51 | error = fd; | ||
52 | } else | ||
53 | *addr = NULL; | ||
54 | } | ||
55 | return error; | ||
56 | } | ||
57 | |||
58 | int walk_sched_trace_file(const char* name, int keep_mapped, | ||
59 | record_callback_t *cb) | ||
60 | { | ||
61 | int ret; | ||
62 | size_t size; | ||
63 | void *start, *end; | ||
64 | |||
65 | ret = map_file(name, &start, &size); | ||
66 | if (!ret) { | ||
67 | end = start + size; | ||
68 | ret = walk_sched_trace(start, end, cb); | ||
69 | } | ||
70 | if (!keep_mapped) | ||
71 | munmap(start, size); | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | |||