diff options
author | Nathan Otterness <otternes@cs.unc.edu> | 2016-04-11 10:39:42 -0400 |
---|---|---|
committer | Nathan Otterness <otternes@cs.unc.edu> | 2016-04-11 10:39:42 -0400 |
commit | 71be8f78e6d27b70983a51b7b5d223ffe59e8fbb (patch) | |
tree | 315db137784592a7d84c5d8868b168273592a621 | |
parent | 73d907a984439a26b77d6a88cc24d17745eab9a8 (diff) |
Changes to make things build
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | include/atomic.h | 4 | ||||
-rw-r--r-- | include/wait_free.h | 93 | ||||
-rw-r--r-- | src/pgm.cpp | 12 | ||||
-rw-r--r-- | tools/pgmrt.cpp | 13 | ||||
-rw-r--r-- | tools/pingpong.cpp | 4 | ||||
-rw-r--r-- | tools/ringtest.cpp | 2 |
7 files changed, 108 insertions, 24 deletions
@@ -9,7 +9,7 @@ host-arch := $(shell uname -m | \ | |||
9 | -include .config | 9 | -include .config |
10 | 10 | ||
11 | # ARCH -- what architecture are we compiling for? | 11 | # ARCH -- what architecture are we compiling for? |
12 | ARCH ?= ${host-arch} | 12 | ARCH ?= arm |
13 | 13 | ||
14 | # LIBLITMUS -- where to find liblitmus? | 14 | # LIBLITMUS -- where to find liblitmus? |
15 | LIBLITMUS ?= ../liblitmus | 15 | LIBLITMUS ?= ../liblitmus |
@@ -28,7 +28,7 @@ flags-debug = -Wall -Werror -Wno-unused-function -Wno-sign-compare | |||
28 | flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -pthread | 28 | flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -pthread |
29 | 29 | ||
30 | # Comment out 'flags-litmus' to disable Litmus support | 30 | # Comment out 'flags-litmus' to disable Litmus support |
31 | #flags-litmus = -D_USE_LITMUS | 31 | flags-litmus = -D_USE_LITMUS |
32 | 32 | ||
33 | # architecture-specific flags | 33 | # architecture-specific flags |
34 | flags-i386 = -m32 | 34 | flags-i386 = -m32 |
diff --git a/include/atomic.h b/include/atomic.h index ec5c09c..50d4788 100644 --- a/include/atomic.h +++ b/include/atomic.h | |||
@@ -5,9 +5,5 @@ | |||
5 | 5 | ||
6 | static inline void __sync_pause() | 6 | static inline void __sync_pause() |
7 | { | 7 | { |
8 | #if (ARCH == x86_64) || (ARCH == i386) || (ARCH == i686) | ||
9 | asm volatile("pause": : :"memory"); | ||
10 | #else | ||
11 | __sync_synchronize(); | 8 | __sync_synchronize(); |
12 | #endif | ||
13 | } | 9 | } |
diff --git a/include/wait_free.h b/include/wait_free.h new file mode 100644 index 0000000..e5aa453 --- /dev/null +++ b/include/wait_free.h | |||
@@ -0,0 +1,93 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <stdatomic.h> | ||
4 | #include <stdint.h> | ||
5 | |||
6 | #define BUFFER_SIZE (8) | ||
7 | |||
8 | // Implements a wait-free buffer where each buffer is an 8 byte uint64_t. | ||
9 | struct wait_free { | ||
10 | atomic_char latest; | ||
11 | atomic_char reading; | ||
12 | int wdcnt; | ||
13 | uint8_t out[BUFFER_SIZE]; | ||
14 | uint8_t buffer[3][BUFFER_SIZE]; | ||
15 | }; | ||
16 | |||
17 | // Initializes the state of the wait-free buffer. | ||
18 | static inline int InitWaitFree(struct wait_free *b) { | ||
19 | if (!b) return -1; | ||
20 | // Disregarding the actual values of min_count and size for now; as the wait- | ||
21 | // free buffer should only require two of them anyway. | ||
22 | b->latest = ATOMIC_VAR_INIT(0); | ||
23 | b->wdcnt = -1; | ||
24 | b->reading = ATOMIC_VAR_INIT(0); | ||
25 | } | ||
26 | |||
27 | static inline void UpdateReading(struct wait_free *b) { | ||
28 | b->reading = 0; | ||
29 | atomic_char l = ATOMIC_VAR_INIT(b->latest); | ||
30 | atomic_char desired = ATOMIC_VAR_INIT(0); | ||
31 | atomic_compare_exchange_strong(&(b->reading), &desired, l); | ||
32 | } | ||
33 | |||
34 | static inline void HelpRead(struct wait_free *b) { | ||
35 | atomic_char bf = ATOMIC_VAR_INIT(b->reading); | ||
36 | int wc = b->wdcnt; | ||
37 | while (wc >= 0) { | ||
38 | b->out[wc] = b->buffer[bf][wc]; | ||
39 | b->wdcnt = (wc + 1) % (BUFFER_SIZE + 1); | ||
40 | if (b->wdcnt == BUFFER_SIZE) { | ||
41 | // The algorithm in the paper uses 0 to mean "not reading"; we'll use -1. | ||
42 | b->wdcnt = -1; | ||
43 | } | ||
44 | wc = b->wdcnt; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | // Reads the content of the next available buffer, up to size bytes (unread | ||
49 | // bytes remaining in the buffer will be lost). | ||
50 | static inline size_t ReadWaitFree(struct wait_free *b, void *dest, | ||
51 | size_t size) { | ||
52 | UpdateReading(b); | ||
53 | b->wdcnt = 0; | ||
54 | HelpRead(b); | ||
55 | if (size > BUFFER_SIZE) { | ||
56 | size = BUFFER_SIZE; | ||
57 | } | ||
58 | for (size_t i = 0; i < size; i++) { | ||
59 | ((uint8_t*) dest)[i] = b->out[i]; | ||
60 | } | ||
61 | return size; | ||
62 | } | ||
63 | |||
64 | static inline atomic_char FindNext(struct wait_free *b) { | ||
65 | char in_use[3]; | ||
66 | atomic_char l = ATOMIC_VAR_INIT(b->latest); | ||
67 | atomic_char desired = ATOMIC_VAR_INIT(0); | ||
68 | atomic_char next = ATOMIC_VAR_INIT(0); | ||
69 | atomic_compare_exchange_strong(&(b->reading), &desired, l); | ||
70 | for (int i = 0; i < 3; i++) { | ||
71 | in_use[i] = 0; | ||
72 | } | ||
73 | in_use[l] = 1; | ||
74 | in_use[b->reading] = 1; | ||
75 | while (in_use[next] && (next < 2)) { | ||
76 | next++; | ||
77 | } | ||
78 | return next; | ||
79 | } | ||
80 | |||
81 | // Writes data into the next available buffer. | ||
82 | static inline size_t WriteWaitFree(struct wait_free *b, void *src, | ||
83 | size_t size) { | ||
84 | atomic_char bf = FindNext(b); | ||
85 | if (size > BUFFER_SIZE) { | ||
86 | size = BUFFER_SIZE; | ||
87 | } | ||
88 | for (size_t n = 0; n < size; n++) { | ||
89 | b->buffer[bf][n] = ((uint8_t*) src)[n]; | ||
90 | } | ||
91 | b->latest = bf; | ||
92 | return size; | ||
93 | } | ||
diff --git a/src/pgm.cpp b/src/pgm.cpp index 5e30d32..afb551f 100644 --- a/src/pgm.cpp +++ b/src/pgm.cpp | |||
@@ -1299,7 +1299,7 @@ void* __pgm_swap_edge_buf(edge_t edge, void* new_uptr, bool swap_producer) | |||
1299 | if(hdr->usersize != old_hdr->usersize) | 1299 | if(hdr->usersize != old_hdr->usersize) |
1300 | { | 1300 | { |
1301 | E("Buffer %p is the wrong size. (is %lu, expected %lu)\n", | 1301 | E("Buffer %p is the wrong size. (is %lu, expected %lu)\n", |
1302 | new_uptr, hdr->usersize, old_hdr->usersize); | 1302 | new_uptr, (unsigned long) hdr->usersize, (unsigned long) old_hdr->usersize); |
1303 | goto out; | 1303 | goto out; |
1304 | } | 1304 | } |
1305 | 1305 | ||
@@ -1357,7 +1357,7 @@ int pgm_swap_edge_bufs(void* a, void* b) | |||
1357 | if(hdra->usersize != hdrb->usersize) | 1357 | if(hdra->usersize != hdrb->usersize) |
1358 | { | 1358 | { |
1359 | E("Buffers are not the same size: %p:%lu vs %p:%lu\n", | 1359 | E("Buffers are not the same size: %p:%lu vs %p:%lu\n", |
1360 | a, hdra->usersize, b, hdrb->usersize); | 1360 | a, (unsigned long) hdra->usersize, b, (unsigned long) hdrb->usersize); |
1361 | goto out; | 1361 | goto out; |
1362 | } | 1362 | } |
1363 | 1363 | ||
@@ -3977,11 +3977,11 @@ int pgm_print_graph(graph_t graph, FILE* outs) | |||
3977 | 3977 | ||
3978 | if(!e->is_backedge) | 3978 | if(!e->is_backedge) |
3979 | { | 3979 | { |
3980 | snprintf(thresh, sizeof(thresh), "(%lu)", e->attr.nr_threshold); | 3980 | snprintf(thresh, sizeof(thresh), "(%lu)", (unsigned long) e->attr.nr_threshold); |
3981 | } | 3981 | } |
3982 | else | 3982 | else |
3983 | { | 3983 | { |
3984 | snprintf(thresh, sizeof(thresh), "(%lu, %lu)", e->attr.nr_threshold, e->nr_skips); | 3984 | snprintf(thresh, sizeof(thresh), "(%lu, %lu)", (unsigned long) e->attr.nr_threshold, (unsigned long) e->nr_skips); |
3985 | } | 3985 | } |
3986 | 3986 | ||
3987 | fprintf(outs, | 3987 | fprintf(outs, |
@@ -3993,9 +3993,9 @@ int pgm_print_graph(graph_t graph, FILE* outs) | |||
3993 | (is_signal_driven(e) && e->ops != &pgm_cv_edge_ops) ? "fast_" : "", | 3993 | (is_signal_driven(e) && e->ops != &pgm_cv_edge_ops) ? "fast_" : "", |
3994 | edgeTypeStr(e), | 3994 | edgeTypeStr(e), |
3995 | namebuf, | 3995 | namebuf, |
3996 | e->attr.nr_consume, | 3996 | (unsigned long) e->attr.nr_consume, |
3997 | thresh, | 3997 | thresh, |
3998 | e->attr.nr_produce); | 3998 | (unsigned long) e->attr.nr_produce); |
3999 | } | 3999 | } |
4000 | 4000 | ||
4001 | fprintf(outs, "}\n"); | 4001 | fprintf(outs, "}\n"); |
diff --git a/tools/pgmrt.cpp b/tools/pgmrt.cpp index 865d0ab..4969f3a 100644 --- a/tools/pgmrt.cpp +++ b/tools/pgmrt.cpp | |||
@@ -190,19 +190,14 @@ void sleep_ns(uint64_t ns) | |||
190 | { | 190 | { |
191 | int64_t seconds = ns / s2ns(1); | 191 | int64_t seconds = ns / s2ns(1); |
192 | ns -= s2ns(seconds); | 192 | ns -= s2ns(seconds); |
193 | struct timespec ts = {.tv_sec = seconds, .tv_nsec = (int64_t)ns}; | 193 | struct timespec ts = {.tv_sec = (time_t) seconds, .tv_nsec = (time_t) ns}; |
194 | nanosleep(&ts, NULL); | 194 | nanosleep(&ts, NULL); |
195 | } | 195 | } |
196 | 196 | ||
197 | inline void relax(void) | 197 | inline void relax(void) |
198 | { | 198 | { |
199 | #if defined(__i386__) || defined(__x86_64__) | 199 | // Deleted some conditions that weren't occuring properly. |
200 | asm volatile("pause\n"); | ||
201 | #elif defined(__arm__) | ||
202 | asm volatile("nop\n"); | 200 | asm volatile("nop\n"); |
203 | #else | ||
204 | #error "Unsupported arch." | ||
205 | #endif | ||
206 | } | 201 | } |
207 | 202 | ||
208 | uint64_t loop_once(void) | 203 | uint64_t loop_once(void) |
@@ -670,8 +665,8 @@ void validate_rate(node_t n, const std::map<std::string, rate>& rates) | |||
670 | bool __valid = (a == b); | 665 | bool __valid = (a == b); |
671 | 666 | ||
672 | if(!__valid) { | 667 | if(!__valid) { |
673 | printf("%s (%lu = %lu * (%lu / %lu)) " | 668 | printf("%s (%llu = %llu * (%llu / %llu)) " |
674 | "and %s (%lu = %lu * (%lu / %lu)) incompatible\n", | 669 | "and %s (%llu = %llu * (%llu / %llu)) incompatible\n", |
675 | pgm_get_name(preds_w_rates[i-1].first), | 670 | pgm_get_name(preds_w_rates[i-1].first), |
676 | p1, prev.x, scale, prev.y, | 671 | p1, prev.x, scale, prev.y, |
677 | pgm_get_name(preds_w_rates[i].first), | 672 | pgm_get_name(preds_w_rates[i].first), |
diff --git a/tools/pingpong.cpp b/tools/pingpong.cpp index da45ef6..d6f9cbc 100644 --- a/tools/pingpong.cpp +++ b/tools/pingpong.cpp | |||
@@ -110,7 +110,7 @@ void fifo_worker(Args args) | |||
110 | 110 | ||
111 | string name = (args.is_master) ? "A" : "B"; | 111 | string name = (args.is_master) ? "A" : "B"; |
112 | 112 | ||
113 | printf("(fifo) %s: time: %lu (ns) average rtt: %lu (ns) token value: %d\n", name.c_str(), elapsed, avg_round, (int)token); | 113 | printf("(fifo) %s: time: %llu (ns) average rtt: %llu (ns) token value: %d\n", name.c_str(), elapsed, avg_round, (int)token); |
114 | } | 114 | } |
115 | 115 | ||
116 | void mq_worker(Args args) | 116 | void mq_worker(Args args) |
@@ -208,7 +208,7 @@ void mq_worker(Args args) | |||
208 | 208 | ||
209 | string name = (args.is_master) ? "A" : "B"; | 209 | string name = (args.is_master) ? "A" : "B"; |
210 | 210 | ||
211 | printf("(mq) %s: time: %lu (ns) average rtt: %lu (ns) token value: %d\n", name.c_str(), elapsed, avg_round, (int)token); | 211 | printf("(mq) %s: time: %llu (ns) average rtt: %llu (ns) token value: %d\n", name.c_str(), elapsed, avg_round, (int)token); |
212 | } | 212 | } |
213 | 213 | ||
214 | int main(int argc, char** argv) | 214 | int main(int argc, char** argv) |
diff --git a/tools/ringtest.cpp b/tools/ringtest.cpp index 3f2bbb5..faf8b73 100644 --- a/tools/ringtest.cpp +++ b/tools/ringtest.cpp | |||
@@ -95,7 +95,7 @@ void* thread(void* _graph_t) | |||
95 | } | 95 | } |
96 | else | 96 | else |
97 | { | 97 | { |
98 | fprintf(stdout, "%s%d terminates: sum: %lu\n", tabbuf, node.node, sum); | 98 | fprintf(stdout, "%s%d terminates: sum: %llu\n", tabbuf, node.node, sum); |
99 | 99 | ||
100 | if(is_src) | 100 | if(is_src) |
101 | CheckError(pgm_terminate(node)); | 101 | CheckError(pgm_terminate(node)); |