diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-08-09 07:18:44 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2017-05-26 17:12:19 -0400 |
commit | b06b1335d1d4481b893a8683406b52ed28e228fd (patch) | |
tree | fbc4af0b5171f3499d2747e4470ef0bb7304fa1e | |
parent | 226447ffbc294ab3cf8b8d67d46c43ac49967f66 (diff) |
Feather-Trace: add platform independent implementation
This patch adds the simple fallback implementation and creates dummy
hooks in the x86 and ARM Kconfig files.
Feather-Buffer: convert to atomic_t
Feather-Trace: remove custom atomic ops - patch by Namhoon Kim (UNC).
Feather-Trace: switch to correct portable atomics header - thanks Andrea Bastoni
-rw-r--r-- | arch/arm/Kconfig | 3 | ||||
-rw-r--r-- | arch/x86/Kconfig | 3 | ||||
-rw-r--r-- | include/litmus/feather_buffer.h | 118 | ||||
-rw-r--r-- | include/litmus/feather_trace.h | 53 | ||||
-rw-r--r-- | litmus/Kconfig | 25 | ||||
-rw-r--r-- | litmus/Makefile | 2 | ||||
-rw-r--r-- | litmus/ft_event.c | 43 |
7 files changed, 247 insertions, 0 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 6d0974122093..68e007a7e7fb 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -2210,5 +2210,8 @@ source "lib/Kconfig" | |||
2210 | 2210 | ||
2211 | source "arch/arm/kvm/Kconfig" | 2211 | source "arch/arm/kvm/Kconfig" |
2212 | 2212 | ||
2213 | config ARCH_HAS_FEATHER_TRACE | ||
2214 | def_bool n | ||
2215 | |||
2213 | source "litmus/Kconfig" | 2216 | source "litmus/Kconfig" |
2214 | 2217 | ||
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 762bf038ab03..d4c29c8046dd 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -2775,4 +2775,7 @@ source "arch/x86/kvm/Kconfig" | |||
2775 | 2775 | ||
2776 | source "lib/Kconfig" | 2776 | source "lib/Kconfig" |
2777 | 2777 | ||
2778 | config ARCH_HAS_FEATHER_TRACE | ||
2779 | def_bool n | ||
2780 | |||
2778 | source "litmus/Kconfig" | 2781 | source "litmus/Kconfig" |
diff --git a/include/litmus/feather_buffer.h b/include/litmus/feather_buffer.h new file mode 100644 index 000000000000..7857cd2c1938 --- /dev/null +++ b/include/litmus/feather_buffer.h | |||
@@ -0,0 +1,118 @@ | |||
1 | #ifndef _FEATHER_BUFFER_H_ | ||
2 | #define _FEATHER_BUFFER_H_ | ||
3 | |||
4 | /* requires UINT_MAX and memcpy */ | ||
5 | |||
6 | #define SLOT_FREE 0 | ||
7 | #define SLOT_BUSY 1 | ||
8 | #define SLOT_READY 2 | ||
9 | |||
10 | struct ft_buffer { | ||
11 | unsigned int slot_count; | ||
12 | unsigned int slot_size; | ||
13 | |||
14 | atomic_t free_count; | ||
15 | atomic_t write_idx; | ||
16 | unsigned int read_idx; | ||
17 | |||
18 | char* slots; | ||
19 | void* buffer_mem; | ||
20 | atomic_t failed_writes; | ||
21 | }; | ||
22 | |||
23 | static inline int init_ft_buffer(struct ft_buffer* buf, | ||
24 | unsigned int slot_count, | ||
25 | unsigned int slot_size, | ||
26 | char* slots, | ||
27 | void* buffer_mem) | ||
28 | { | ||
29 | int i = 0; | ||
30 | if (!slot_count || UINT_MAX % slot_count != slot_count - 1) { | ||
31 | /* The slot count must divide UNIT_MAX + 1 so that when it | ||
32 | * wraps around the index correctly points to 0. | ||
33 | */ | ||
34 | return 0; | ||
35 | } else { | ||
36 | buf->slot_count = slot_count; | ||
37 | buf->slot_size = slot_size; | ||
38 | buf->slots = slots; | ||
39 | buf->buffer_mem = buffer_mem; | ||
40 | atomic_set(&buf->free_count, slot_count); | ||
41 | atomic_set(&buf->write_idx, 0); | ||
42 | buf->read_idx = 0; | ||
43 | atomic_set(&buf->failed_writes, 0); | ||
44 | for (i = 0; i < slot_count; i++) | ||
45 | buf->slots[i] = SLOT_FREE; | ||
46 | return 1; | ||
47 | } | ||
48 | } | ||
49 | |||
50 | static inline int ft_buffer_start_write(struct ft_buffer* buf, void **ptr) | ||
51 | { | ||
52 | int free = atomic_fetch_dec(&buf->free_count); | ||
53 | unsigned int idx; | ||
54 | if (free <= 0) { | ||
55 | atomic_fetch_inc(&buf->free_count); | ||
56 | *ptr = 0; | ||
57 | atomic_fetch_inc(&buf->failed_writes); | ||
58 | return 0; | ||
59 | } else { | ||
60 | idx = atomic_fetch_inc(&buf->write_idx) % buf->slot_count; | ||
61 | buf->slots[idx] = SLOT_BUSY; | ||
62 | *ptr = ((char*) buf->buffer_mem) + idx * buf->slot_size; | ||
63 | return 1; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | /* For single writer scenarios, with fewer atomic ops. */ | ||
68 | static inline int ft_buffer_start_single_write(struct ft_buffer* buf, void **ptr) | ||
69 | { | ||
70 | unsigned int idx; | ||
71 | |||
72 | if (buf->free_count.counter <= 0) { | ||
73 | *ptr = 0; | ||
74 | /* single writer: no atomicity needed */ | ||
75 | buf->failed_writes.counter++; | ||
76 | return 0; | ||
77 | } else { | ||
78 | /* free_count is positive, and can only increase since we are | ||
79 | * (by assumption) the only writer accessing the buffer. | ||
80 | */ | ||
81 | |||
82 | idx = buf->write_idx.counter++ % buf->slot_count; | ||
83 | buf->slots[idx] = SLOT_BUSY; | ||
84 | *ptr = ((char*) buf->buffer_mem) + idx * buf->slot_size; | ||
85 | |||
86 | atomic_dec(&buf->free_count); | ||
87 | return 1; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | static inline void ft_buffer_finish_write(struct ft_buffer* buf, void *ptr) | ||
92 | { | ||
93 | unsigned int idx = ((char*) ptr - (char*) buf->buffer_mem) / buf->slot_size; | ||
94 | buf->slots[idx] = SLOT_READY; | ||
95 | } | ||
96 | |||
97 | |||
98 | /* exclusive reader access is assumed */ | ||
99 | static inline int ft_buffer_read(struct ft_buffer* buf, void* dest) | ||
100 | { | ||
101 | unsigned int idx; | ||
102 | if (atomic_read(&buf->free_count) == buf->slot_count) | ||
103 | /* nothing available */ | ||
104 | return 0; | ||
105 | idx = buf->read_idx % buf->slot_count; | ||
106 | if (buf->slots[idx] == SLOT_READY) { | ||
107 | memcpy(dest, ((char*) buf->buffer_mem) + idx * buf->slot_size, | ||
108 | buf->slot_size); | ||
109 | buf->slots[idx] = SLOT_FREE; | ||
110 | buf->read_idx++; | ||
111 | atomic_fetch_inc(&buf->free_count); | ||
112 | return 1; | ||
113 | } else | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | |||
118 | #endif | ||
diff --git a/include/litmus/feather_trace.h b/include/litmus/feather_trace.h new file mode 100644 index 000000000000..36c75cb8741e --- /dev/null +++ b/include/litmus/feather_trace.h | |||
@@ -0,0 +1,53 @@ | |||
1 | #ifndef _FEATHER_TRACE_H_ | ||
2 | #define _FEATHER_TRACE_H_ | ||
3 | |||
4 | #include <linux/atomic.h> | ||
5 | |||
6 | int ft_enable_event(unsigned long id); | ||
7 | int ft_disable_event(unsigned long id); | ||
8 | int ft_is_event_enabled(unsigned long id); | ||
9 | int ft_disable_all_events(void); | ||
10 | |||
11 | /* Don't use rewriting implementation if kernel text pages are read-only. | ||
12 | * Ftrace gets around this by using the identity mapping, but that's more | ||
13 | * effort that is warrented right now for Feather-Trace. | ||
14 | * Eventually, it may make sense to replace Feather-Trace with ftrace. | ||
15 | */ | ||
16 | #if defined(CONFIG_ARCH_HAS_FEATHER_TRACE) && !defined(CONFIG_DEBUG_RODATA) | ||
17 | |||
18 | #include <asm/feather_trace.h> | ||
19 | |||
20 | #else /* !__ARCH_HAS_FEATHER_TRACE */ | ||
21 | |||
22 | /* provide default implementation */ | ||
23 | #include <linux/timex.h> /* for get_cycles() */ | ||
24 | |||
25 | static inline unsigned long long ft_timestamp(void) | ||
26 | { | ||
27 | return get_cycles(); | ||
28 | } | ||
29 | |||
30 | #define feather_callback | ||
31 | |||
32 | #define MAX_EVENTS 1024 | ||
33 | |||
34 | extern int ft_events[MAX_EVENTS]; | ||
35 | |||
36 | #define ft_event(id, callback) \ | ||
37 | if (ft_events[id]) callback(); | ||
38 | |||
39 | #define ft_event0(id, callback) \ | ||
40 | if (ft_events[id]) callback(id); | ||
41 | |||
42 | #define ft_event1(id, callback, param) \ | ||
43 | if (ft_events[id]) callback(id, param); | ||
44 | |||
45 | #define ft_event2(id, callback, param, param2) \ | ||
46 | if (ft_events[id]) callback(id, param, param2); | ||
47 | |||
48 | #define ft_event3(id, callback, p, p2, p3) \ | ||
49 | if (ft_events[id]) callback(id, p, p2, p3); | ||
50 | |||
51 | #endif /* __ARCH_HAS_FEATHER_TRACE */ | ||
52 | |||
53 | #endif | ||
diff --git a/litmus/Kconfig b/litmus/Kconfig index 382b2e426437..70ddbaddc06f 100644 --- a/litmus/Kconfig +++ b/litmus/Kconfig | |||
@@ -1,3 +1,28 @@ | |||
1 | menu "LITMUS^RT" | 1 | menu "LITMUS^RT" |
2 | 2 | ||
3 | menu "Tracing" | ||
4 | |||
5 | config FEATHER_TRACE | ||
6 | bool "Feather-Trace Infrastructure" | ||
7 | default y | ||
8 | help | ||
9 | Feather-Trace basic tracing infrastructure. Includes device file | ||
10 | driver and instrumentation point support. | ||
11 | |||
12 | There are actually two implementations of Feather-Trace. | ||
13 | 1) A slower, but portable, default implementation. | ||
14 | 2) Architecture-specific implementations that rewrite kernel .text at runtime. | ||
15 | |||
16 | If enabled, Feather-Trace will be based on 2) if available (currently only for x86). | ||
17 | However, if DEBUG_RODATA=y, then Feather-Trace will choose option 1) in any case | ||
18 | to avoid problems with write-protected .text pages. | ||
19 | |||
20 | Bottom line: to avoid increased overheads, choose DEBUG_RODATA=n. | ||
21 | |||
22 | Note that this option only enables the basic Feather-Trace infrastructure; | ||
23 | you still need to enable SCHED_TASK_TRACE and/or SCHED_OVERHEAD_TRACE to | ||
24 | actually enable any events. | ||
25 | |||
26 | endmenu | ||
27 | |||
3 | endmenu | 28 | endmenu |
diff --git a/litmus/Makefile b/litmus/Makefile index f0ed31faf582..4c6130b58bae 100644 --- a/litmus/Makefile +++ b/litmus/Makefile | |||
@@ -1,3 +1,5 @@ | |||
1 | # | 1 | # |
2 | # Makefile for LITMUS^RT | 2 | # Makefile for LITMUS^RT |
3 | # | 3 | # |
4 | |||
5 | obj-$(CONFIG_FEATHER_TRACE) += ft_event.o | ||
diff --git a/litmus/ft_event.c b/litmus/ft_event.c new file mode 100644 index 000000000000..399a07becca5 --- /dev/null +++ b/litmus/ft_event.c | |||
@@ -0,0 +1,43 @@ | |||
1 | #include <linux/types.h> | ||
2 | |||
3 | #include <litmus/feather_trace.h> | ||
4 | |||
5 | #if !defined(CONFIG_ARCH_HAS_FEATHER_TRACE) || defined(CONFIG_DEBUG_RODATA) | ||
6 | /* provide dummy implementation */ | ||
7 | |||
8 | int ft_events[MAX_EVENTS]; | ||
9 | |||
10 | int ft_enable_event(unsigned long id) | ||
11 | { | ||
12 | if (id < MAX_EVENTS) { | ||
13 | ft_events[id]++; | ||
14 | return 1; | ||
15 | } else | ||
16 | return 0; | ||
17 | } | ||
18 | |||
19 | int ft_disable_event(unsigned long id) | ||
20 | { | ||
21 | if (id < MAX_EVENTS && ft_events[id]) { | ||
22 | ft_events[id]--; | ||
23 | return 1; | ||
24 | } else | ||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | int ft_disable_all_events(void) | ||
29 | { | ||
30 | int i; | ||
31 | |||
32 | for (i = 0; i < MAX_EVENTS; i++) | ||
33 | ft_events[i] = 0; | ||
34 | |||
35 | return MAX_EVENTS; | ||
36 | } | ||
37 | |||
38 | int ft_is_event_enabled(unsigned long id) | ||
39 | { | ||
40 | return id < MAX_EVENTS && ft_events[id]; | ||
41 | } | ||
42 | |||
43 | #endif | ||