diff --git a/boards/posix/native_posix/Kconfig.defconfig b/boards/posix/native_posix/Kconfig.defconfig index 89e48ecca75..01ae4e747ad 100644 --- a/boards/posix/native_posix/Kconfig.defconfig +++ b/boards/posix/native_posix/Kconfig.defconfig @@ -81,13 +81,6 @@ config SDL_DISPLAY endif # DISPLAY -if TRACING_CTF - -config TRACING_CTF_BOTTOM_POSIX - default y - -endif # TRACING_CTF - if FLASH config FLASH_SIMULATOR diff --git a/doc/guides/tracing/index.rst b/doc/guides/tracing/index.rst index 10ad3c4584b..e9e64ddf352 100644 --- a/doc/guides/tracing/index.rst +++ b/doc/guides/tracing/index.rst @@ -133,8 +133,7 @@ internally and statically at compile-time in the bottom-layer. How to Activate? ================ -Make sure :option:`CONFIG_TRACING_CTF` is set to ``y`` (:option:`CONFIG_TRACING_CTF_BOTTOM_POSIX` -is selected by default when using ``BOARD_NATIVE_POSIX``). +Make sure :option:`CONFIG_TRACING_CTF` is set to ``y`` How to Use? diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index a6ce22e7e4b..6b5b66e7b8f 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -433,16 +433,14 @@ config TRACING_CTF select THREAD_MONITOR select TRACING help - Enable tracing to a Common Trace Format stream. In order to use it a - CTF bottom layer should be selected, such as TRACING_CTF_BOTTOM_POSIX. + Enable tracing to a Common Trace Format stream. -config TRACING_CTF_BOTTOM_POSIX - bool "CTF backend for the native_posix port, using a file in the host filesystem" - depends on TRACING_CTF - depends on ARCH_POSIX +config TRACING_CTF_TIMESTAMP + bool "Enable CTF internal timestamp" + default y help - Enable POSIX backend for CTF tracing. It will output the CTF stream to a - file using fwrite. + Timestamp prefix will be added to the beginning of CTF + event internally. source "subsys/debug/Kconfig.segger" diff --git a/subsys/debug/tracing/ctf/CMakeLists.txt b/subsys/debug/tracing/ctf/CMakeLists.txt index 0e7cf129f69..86c1dc16769 100644 --- a/subsys/debug/tracing/ctf/CMakeLists.txt +++ b/subsys/debug/tracing/ctf/CMakeLists.txt @@ -10,5 +10,3 @@ zephyr_library_include_directories( ) zephyr_include_directories(.) - -add_subdirectory_ifdef(CONFIG_TRACING_CTF_BOTTOM_POSIX bottoms/posix) diff --git a/subsys/debug/tracing/ctf/bottoms/posix/CMakeLists.txt b/subsys/debug/tracing/ctf/bottoms/posix/CMakeLists.txt deleted file mode 100644 index 6bd04fe560c..00000000000 --- a/subsys/debug/tracing/ctf/bottoms/posix/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -zephyr_include_directories(.) -zephyr_sources(ctf_bottom.c) diff --git a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c b/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c deleted file mode 100644 index d85bd378bdc..00000000000 --- a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "ctf_bottom.h" -#include "soc.h" -#include "cmdline.h" /* native_posix command line options header */ -#include - - -ctf_bottom_ctx_t ctf_bottom; - -void ctf_bottom_configure(void) -{ - if (ctf_bottom.pathname == NULL) { - ctf_bottom.pathname = "channel0_0"; - } - - ctf_bottom.ostream = fopen(ctf_bottom.pathname, "wb"); - if (ctf_bottom.ostream == NULL) { - posix_print_error_and_exit("CTF trace: " - "Problem opening file %s.\n", - ctf_bottom.pathname); - } -} - -void ctf_bottom_start(void) -{ -} - -/* command line option to specify ctf output file */ -void add_ctf_option(void) -{ - static struct args_struct_t ctf_options[] = { - /* - * Fields: - * manual, mandatory, switch, - * option_name, var_name ,type, - * destination, callback, - * description - */ - { .manual = false, - .is_mandatory = false, - .is_switch = false, - .option = "ctf-path", - .name = "file_name", - .type = 's', - .dest = (void *)&ctf_bottom.pathname, - .call_when_found = NULL, - .descript = "File name for CTF tracing output." }, - ARG_TABLE_ENDMARKER - }; - - native_add_command_line_opts(ctf_options); -} -NATIVE_TASK(add_ctf_option, PRE_BOOT_1, 1); diff --git a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.h b/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.h deleted file mode 100644 index cdddc4fa5fa..00000000000 --- a/subsys/debug/tracing/ctf/bottoms/posix/ctf_bottom.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2018 Oticon A/S - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H -#define SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H - -#include -#include -#include -#include -#include - - -/* Obtain a field's size at compile-time. - * Internal to this bottom-layer. - */ -#define CTF_BOTTOM_INTERNAL_FIELD_SIZE(x) + sizeof(x) - -/* Append a field to current event-packet. - * Internal to this bottom-layer. - */ -#define CTF_BOTTOM_INTERNAL_FIELD_APPEND(x) \ - { \ - memcpy(epacket_cursor, &(x), sizeof(x)); \ - epacket_cursor += sizeof(x); \ - } - -/* Gather fields to a contiguous event-packet, then atomically emit. - * Used by middle-layer. - */ -#define CTF_BOTTOM_FIELDS(...) \ -{ \ - u8_t epacket[0 MAP(CTF_BOTTOM_INTERNAL_FIELD_SIZE, ##__VA_ARGS__)]; \ - u8_t *epacket_cursor = &epacket[0]; \ - \ - MAP(CTF_BOTTOM_INTERNAL_FIELD_APPEND, ##__VA_ARGS__) \ - ctf_bottom_emit(epacket, sizeof(epacket)); \ -} - -/* No need for locking when ctf_bottom_emit does POSIX fwrite(3) which is thread - * safe. Used by middle-layer. - */ -#define CTF_BOTTOM_LOCK() { /* empty */ } -#define CTF_BOTTOM_UNLOCK() { /* empty */ } - -/* On native_posix board, the code must sample time by itself. - * Used by middle-layer. - */ -#define CTF_BOTTOM_TIMESTAMPED_INTERNALLY - - -typedef struct { - const char *pathname; - FILE *ostream; -} ctf_bottom_ctx_t; - -extern ctf_bottom_ctx_t ctf_bottom; - - -/* Configure initializes ctf_bottom context and opens the IO channel */ -void ctf_bottom_configure(void); - -/* Start a new trace stream */ -void ctf_bottom_start(void); - -/* Emit IO in system-specific way */ -static inline void ctf_bottom_emit(const void *ptr, size_t size) -{ - /* Simplest possible example is atomic fwrite */ - fwrite(ptr, size, 1, ctf_bottom.ostream); -} - -#endif /* SUBSYS_DEBUG_TRACING_BOTTOMS_POSIX_CTF_BOTTOM_H */ diff --git a/subsys/debug/tracing/ctf/ctf_top.c b/subsys/debug/tracing/ctf/ctf_top.c index b198288bcbc..ed3dff5b120 100644 --- a/subsys/debug/tracing/ctf/ctf_top.c +++ b/subsys/debug/tracing/ctf/ctf_top.c @@ -6,9 +6,8 @@ #include #include -#include #include -#include "ctf_top.h" +#include void sys_trace_thread_switched_out(void) { @@ -142,14 +141,3 @@ void sys_trace_end_call(unsigned int id) { ctf_top_end_call(id); } - -static int ctf_top_init(struct device *arg) -{ - ARG_UNUSED(arg); - - ctf_bottom_configure(); - ctf_bottom_start(); - return 0; -} - -SYS_INIT(ctf_top_init, PRE_KERNEL_1, 0); diff --git a/subsys/debug/tracing/ctf/ctf_top.h b/subsys/debug/tracing/ctf/ctf_top.h index 5ac8712b874..d1abdef8948 100644 --- a/subsys/debug/tracing/ctf/ctf_top.h +++ b/subsys/debug/tracing/ctf/ctf_top.h @@ -9,37 +9,51 @@ #include #include -#include +#include +#include /* Limit strings to 20 bytes to optimize bandwidth */ #define CTF_MAX_STRING_LEN 20 -/* Optionally enter into a critical region, decided by bottom layer */ -#define CTF_CRITICAL_REGION(x) \ - { \ - CTF_BOTTOM_LOCK(); \ - x; \ - CTF_BOTTOM_UNLOCK(); \ +/* + * Obtain a field's size at compile-time. + */ +#define CTF_INTERNAL_FIELD_SIZE(x) + sizeof(x) + +/* + * Append a field to current event-packet. + */ +#define CTF_INTERNAL_FIELD_APPEND(x) \ + { \ + memcpy(epacket_cursor, &(x), sizeof(x)); \ + epacket_cursor += sizeof(x); \ } +/* + * Gather fields to a contiguous event-packet, then atomically emit. + */ +#define CTF_GATHER_FIELDS(...) \ +{ \ + u8_t epacket[0 MAP(CTF_INTERNAL_FIELD_SIZE, ##__VA_ARGS__)]; \ + u8_t *epacket_cursor = &epacket[0]; \ + \ + MAP(CTF_INTERNAL_FIELD_APPEND, ##__VA_ARGS__) \ + tracing_format_raw_data(epacket, sizeof(epacket)); \ +} -#ifdef CTF_BOTTOM_TIMESTAMPED_EXTERNALLY -/* Emit CTF event using the bottom-level IO mechanics */ -#define CTF_EVENT(...) \ - { \ - CTF_CRITICAL_REGION(CTF_BOTTOM_FIELDS(__VA_ARGS__)) \ - } -#endif /* CTF_BOTTOM_TIMESTAMPED_EXTERNALLY */ - -#ifdef CTF_BOTTOM_TIMESTAMPED_INTERNALLY -/* Emit CTF event using the bottom-level IO mechanics. Prefix by sample time */ +#ifdef CONFIG_TRACING_CTF_TIMESTAMP #define CTF_EVENT(...) \ { \ const u32_t tstamp = k_cycle_get_32(); \ - CTF_CRITICAL_REGION(CTF_BOTTOM_FIELDS(tstamp, __VA_ARGS__)) \ + \ + CTF_GATHER_FIELDS(tstamp, __VA_ARGS__) \ } -#endif /* CTF_BOTTOM_TIMESTAMPED_INTERNALLY */ - +#else +#define CTF_EVENT(...) \ + { \ + CTF_GATHER_FIELDS(__VA_ARGS__) \ + } +#endif /* Anonymous compound literal with 1 member. Legal since C99. * This permits us to take the address of literals, like so: @@ -52,7 +66,6 @@ */ #define CTF_LITERAL(type, value) ((type) { (type)(value) }) - typedef enum { CTF_EVENT_THREAD_SWITCHED_OUT = 0x10, CTF_EVENT_THREAD_SWITCHED_IN = 0x11,