diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-16 15:13:43 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-09-16 15:13:43 -0400 |
commit | 59e67e78312843793f299dbd9554afe09c23cad8 (patch) | |
tree | 23491748b60efb2759d6d74c801e6dd9702dac35 | |
parent | 3bc3a229f237fd62820efdbf7d5eb9dc8b2f8cb3 (diff) |
sched_trace: remove old definitions, include kernel header
-rw-r--r-- | include/sched_trace.h | 112 | ||||
-rw-r--r-- | src/sched_trace.c | 126 |
2 files changed, 10 insertions, 228 deletions
diff --git a/include/sched_trace.h b/include/sched_trace.h index 5d2ddb3..0e08c69 100644 --- a/include/sched_trace.h +++ b/include/sched_trace.h | |||
@@ -6,116 +6,8 @@ | |||
6 | typedef __u8 u8; | 6 | typedef __u8 u8; |
7 | typedef __u32 u32; | 7 | typedef __u32 u32; |
8 | typedef __u16 u16; | 8 | typedef __u16 u16; |
9 | typedef __u64 u64; | ||
9 | 10 | ||
10 | typedef enum { | 11 | #include <litmus/sched_trace.h> |
11 | ST_INVOCATION = 0, | ||
12 | ST_ARRIVAL = 1, | ||
13 | ST_DEPARTURE = 2, | ||
14 | ST_PREEMPTION = 3, | ||
15 | ST_SCHEDULED = 4, | ||
16 | ST_JOB_RELEASE = 5, | ||
17 | ST_JOB_COMPLETION = 6, | ||
18 | ST_CAPACITY_RELEASE = 7, | ||
19 | ST_CAPACITY_ALLOCATION = 8, | ||
20 | 12 | ||
21 | ST_MAX | ||
22 | } trace_type_t; | ||
23 | |||
24 | |||
25 | typedef struct { | ||
26 | trace_type_t trace:8; | ||
27 | unsigned int size:24; | ||
28 | unsigned long long timestamp; | ||
29 | } trace_header_t; | ||
30 | |||
31 | typedef struct { | ||
32 | unsigned int is_rt:1; | ||
33 | unsigned int is_server:1; | ||
34 | task_class_t class:4; | ||
35 | unsigned int budget:24; | ||
36 | u32 deadline; | ||
37 | |||
38 | pid_t pid; | ||
39 | } task_info_t; | ||
40 | |||
41 | typedef struct { | ||
42 | trace_header_t header; | ||
43 | unsigned long flags; | ||
44 | } invocation_record_t; | ||
45 | |||
46 | typedef struct { | ||
47 | trace_header_t header; | ||
48 | task_info_t task; | ||
49 | } arrival_record_t; | ||
50 | |||
51 | typedef struct { | ||
52 | trace_header_t header; | ||
53 | task_info_t task; | ||
54 | } departure_record_t; | ||
55 | |||
56 | typedef struct { | ||
57 | trace_header_t header; | ||
58 | task_info_t task; | ||
59 | task_info_t by; | ||
60 | } preemption_record_t; | ||
61 | |||
62 | typedef struct { | ||
63 | trace_header_t header; | ||
64 | task_info_t task; | ||
65 | } scheduled_record_t; | ||
66 | |||
67 | typedef struct { | ||
68 | trace_header_t header; | ||
69 | task_info_t task; | ||
70 | u16 period; | ||
71 | u16 wcet; | ||
72 | } release_record_t; | ||
73 | |||
74 | typedef struct { | ||
75 | trace_header_t header; | ||
76 | task_info_t task; | ||
77 | u16 period; | ||
78 | u16 wcet; | ||
79 | int tardiness; | ||
80 | unsigned int job_no; | ||
81 | } completion_record_t; | ||
82 | |||
83 | typedef struct { | ||
84 | trace_header_t header; | ||
85 | task_info_t task; | ||
86 | } cap_release_record_t; | ||
87 | |||
88 | typedef struct { | ||
89 | trace_header_t header; | ||
90 | task_info_t task; | ||
91 | u16 budget; | ||
92 | u32 deadline; | ||
93 | pid_t donor; | ||
94 | } cap_allocation_record_t; | ||
95 | |||
96 | |||
97 | |||
98 | |||
99 | |||
100 | enum { | ||
101 | INVALID_HEADER = 1 | ||
102 | }; | ||
103 | |||
104 | typedef int (*record_callback_fn)(trace_header_t* hdr); | ||
105 | |||
106 | typedef struct { | ||
107 | record_callback_fn handler[ST_MAX]; | ||
108 | } record_callback_t; | ||
109 | |||
110 | #define init_record_callback(a) memset(a, 0, sizeof(record_callback_t)) | ||
111 | #define set_callback(type, fn, a) do {(a)->handler[type] = fn; } while (0); | ||
112 | |||
113 | int walk_sched_trace(void* start, void* end, record_callback_t *cb); | ||
114 | int walk_sched_traces_ordered(void** start, void** end, unsigned int count, | ||
115 | record_callback_t *cb); | ||
116 | |||
117 | int walk_sched_trace_file(const char* name, int keep_mapped, | ||
118 | record_callback_t *cb); | ||
119 | int walk_sched_trace_files_ordered(const char** names, unsigned int count, | ||
120 | int keep_mapped, record_callback_t *cb); | ||
121 | #endif | 13 | #endif |
diff --git a/src/sched_trace.c b/src/sched_trace.c index c3a603b..17d3d06 100644 --- a/src/sched_trace.c +++ b/src/sched_trace.c | |||
@@ -10,148 +10,38 @@ | |||
10 | #include "litmus.h" | 10 | #include "litmus.h" |
11 | #include "sched_trace.h" | 11 | #include "sched_trace.h" |
12 | 12 | ||
13 | 13 | static int map_file(const char* filename, void **addr, size_t *size) | |
14 | int walk_sched_trace(void* start, void* end, record_callback_t *cb) | ||
15 | { | ||
16 | void* pos = start; | ||
17 | trace_header_t* header; | ||
18 | int ret = 0; | ||
19 | |||
20 | while (pos < end) { | ||
21 | header = (trace_header_t*) pos; | ||
22 | if (header->trace >= ST_MAX) | ||
23 | return INVALID_HEADER; | ||
24 | if (cb->handler[header->trace]) | ||
25 | ret = cb->handler[header->trace](header); | ||
26 | if (ret) | ||
27 | return ret; | ||
28 | pos += header->size; | ||
29 | } | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | int walk_sched_traces_ordered(void** start, void** end, unsigned int count, | ||
34 | record_callback_t *cb) | ||
35 | { | ||
36 | void** pos; | ||
37 | trace_header_t* header; | ||
38 | int ret = 0, i, adv; | ||
39 | |||
40 | pos = malloc(sizeof(void*) * count); | ||
41 | |||
42 | for (i = 0; i < count; i++) | ||
43 | pos[i] = start[i]; | ||
44 | |||
45 | do { | ||
46 | header = NULL; | ||
47 | for (i = 0; i < count; i++) | ||
48 | if (pos[i] < end[i] && | ||
49 | (!header || header->timestamp > | ||
50 | ((trace_header_t*) pos[i])->timestamp)) { | ||
51 | header = (trace_header_t*) pos[i]; | ||
52 | adv = i; | ||
53 | } | ||
54 | if (header) { | ||
55 | pos[adv] += header->size; | ||
56 | /* printf("header id: %d pos=%p adv=%d\n", | ||
57 | header->trace, pos[adv], adv); | ||
58 | */ | ||
59 | if (header->trace >= ST_MAX) | ||
60 | return INVALID_HEADER; | ||
61 | if (cb->handler[header->trace]) | ||
62 | ret = cb->handler[header->trace](header); | ||
63 | } | ||
64 | } while (header != NULL && !ret); | ||
65 | |||
66 | free(pos); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static int map_file(const char* filename, void **addr, size_t *size) | ||
71 | { | 14 | { |
72 | struct stat info; | 15 | struct stat info; |
73 | int error = 0; | 16 | int error = 0; |
74 | int fd; | 17 | int fd; |
75 | 18 | ||
76 | error = stat(filename, &info); | 19 | error = stat(filename, &info); |
77 | if (!error) { | 20 | if (!error) { |
78 | *size = info.st_size; | 21 | *size = info.st_size; |
79 | if (info.st_size > 0) { | 22 | if (info.st_size > 0) { |
80 | fd = open(filename, O_RDONLY); | 23 | fd = open(filename, O_RDONLY); |
81 | if (fd >= 0) { | 24 | if (fd >= 0) { |
82 | *addr = mmap(NULL, *size, | 25 | *addr = mmap(NULL, *size, |
83 | PROT_READ | PROT_WRITE, | 26 | PROT_READ | PROT_WRITE, |
84 | MAP_PRIVATE, fd, 0); | 27 | MAP_PRIVATE, fd, 0); |
85 | if (*addr == MAP_FAILED) | 28 | if (*addr == MAP_FAILED) |
86 | error = -1; | 29 | error = -1; |
87 | close(fd); | 30 | close(fd); |
88 | } else | 31 | } else |
89 | error = fd; | 32 | error = fd; |
90 | } else | 33 | } else |
91 | *addr = NULL; | 34 | *addr = NULL; |
92 | } | 35 | } |
93 | return error; | 36 | return error; |
94 | } | 37 | } |
95 | 38 | ||
96 | static int map_trace(const char *name, void **start, void **end, size_t *size) | 39 | static int map_trace(const char *name, void **start, void **end, size_t *size) |
97 | { | 40 | { |
98 | int ret; | 41 | int ret; |
99 | 42 | ||
100 | ret = map_file(name, start, size); | 43 | ret = map_file(name, start, size); |
101 | if (!ret) | 44 | if (!ret) |
102 | *end = *start + *size; | 45 | *end = *start + *size; |
103 | return ret; | 46 | return ret; |
104 | } | 47 | } |
105 | |||
106 | int walk_sched_trace_file(const char* name, int keep_mapped, | ||
107 | record_callback_t *cb) | ||
108 | { | ||
109 | int ret; | ||
110 | size_t size; | ||
111 | void *start, *end; | ||
112 | |||
113 | ret = map_trace(name, &start, &end, &size); | ||
114 | if (!ret) | ||
115 | ret = walk_sched_trace(start, end, cb); | ||
116 | |||
117 | if (!keep_mapped) | ||
118 | munmap(start, size); | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | |||
123 | int walk_sched_trace_files_ordered(const char** names, unsigned int count, | ||
124 | int keep_mapped, record_callback_t *cb) | ||
125 | { | ||
126 | void **start, **end; | ||
127 | size_t *size; | ||
128 | int i; | ||
129 | int ret = 0; | ||
130 | |||
131 | /* printf("count=%d\n", count); */ | ||
132 | |||
133 | start = malloc(sizeof(void*) * count); | ||
134 | end = malloc(sizeof(void*) * count); | ||
135 | size = malloc(sizeof(size_t) * count); | ||
136 | |||
137 | for (i = 0; i < count; i++) | ||
138 | size[i] = 0; | ||
139 | for (i = 0; i < count && !ret; i++) { | ||
140 | /* printf("mapping %s\n", names[i]); */ | ||
141 | ret = map_trace(names[i], start + i, end + i, size + i); | ||
142 | } | ||
143 | |||
144 | if (!ret) | ||
145 | /* everything mapped, now walk it */ | ||
146 | ret = walk_sched_traces_ordered(start, end, count, cb); | ||
147 | |||
148 | if (!keep_mapped) | ||
149 | for (i = 0; i < count; i++) | ||
150 | if (size[i]) | ||
151 | munmap(start[i], size[i]); | ||
152 | |||
153 | free(start); | ||
154 | free(end); | ||
155 | free(size); | ||
156 | return ret; | ||
157 | } | ||