Commit Graph

86 Commits

Author SHA1 Message Date
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Keith Packard 7ec1fb632b subsys/tracing: Use z_current_get for thread tracing
The thread switching hooks are invoked in the middle of thread
switching, after the out-going thread registers are saved, but before
the in-coming thread registers are restored, and also before
z_thread_entry is called if the thread is just starting.

When the core is first starting, the TLS base register won't be set at
all, so accessing variables will fault. When switching threads, the
in-coming thread TLS base register will not have been restored, so the
z_tls_current value will end up getting the out-going thread instead.

To fix this, switch from k_current_get() to z_current_get().

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-04-28 11:09:01 +09:00
Bartosz Bilas 306f92e646 tracing: remove superfluous default n for boolean
bool symbols implicitly default to n so
there is no need to redundant those values.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2022-04-19 11:49:27 +02:00
Anas Nashif 68670d71b8 tracing: kconfig: move RAM_TRACING_BUFFER_SIZE out of choice
This kconfig is not a choice, it is an option needed by one of the
choices, so move it out.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-12 11:39:11 -04:00
Anas Nashif af2d83e66f tracing: add missing macros needed for k_thread_foreach
Add those dummy tracing functions to get the test to build when using
k_thread_foreach.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-12 11:39:11 -04:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Wealian Liao 7467dc4c12 tracing_user: Add ISR nest level parameter
For tracing_user, the sys_trace_isr_enter() & sys_trace_isr_exit()
block any nest interrupts & most SMP interrupts for the user. It is
hard to analyze the IRQ preemption(e.g., each IRQ counter and execution
time). This commit adds ISR nest level for each CPU to the user instead
of blocking user call back when nest interrupts.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2022-01-21 14:38:35 -05:00
Wealian Liao 1fd29fb131 tracing: Fix tracing_user config
`tracing_user.h` lost several definitions, which made
CONFIG_TRACING_USER build fail. This fixes the TRACING_USER
config & adds it to the test case.

Moreover, the idle task stack is overflow on qemu_x86, qemu_cortex_m0 &
qemu_riscv64. This makes the test fail. So this commit sets the idle
stack size to 2048 for this sample to avoid it.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2022-01-11 18:13:18 -05:00
Peter Mitsis d1353a4584 kernel: pipes: add pipe flush routines
Adds two routines to flush pipe objects:
   k_pipe_flush()
     - This routine flushes the entire pipe. That includes both
     the pipe's buffer and all pended writers. It is equivalent
     to reading everything into a giant temporary buffer which
     is then discarded.
   k_pipe_buffer_flush()
     - This routine flushes only the pipe's buffer (if it exists).
     It is equivalent to reading a maximum of "buffer size" bytes
     into a temporary buffer which is then discarded.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-01-10 12:17:14 -05:00
Flavio Ceolin 18b932f10d pm: device_runtime: Return possible error on enable
Change the function pm_device_runtime_enable() to return 0 on
success or an error code in case of error.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-12-14 19:23:05 -05:00
Ederson de Souza bdaac354f4 kernel: Bring back object tracking
When CONFIG_TRACING_OBJECT_TRACKING is enabled, the kernel will keep
lists of some objects (detailed below), so that debuggers or other tools
can keep track of them.

The lists of objects are:

struct k_timer *_track_list_k_timer;
struct k_mem_slab *_track_list_k_mem_slab;
struct k_sem *_track_list_k_sem;
struct k_mutex *_track_list_k_mutex;
struct k_stack *_track_list_k_stack;
struct k_msgq *_track_list_k_msgq;
struct k_mbox *_track_list_k_mbox;
struct k_pipe *_track_list_k_pipe;
struct k_queue *_track_list_k_queue;

Note that while CONFIG_TRACING is needed, one can always use
CONFIG_TRACE_NONE=y. Also, tracking will only be done for objects that
are also being traced (so, to prevent tracking of some type of object,
such as k_timer, just make CONFIG_TRACING_TIMER=n).

Some simple "sanity checking" tests are also added in this patch.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2021-12-14 07:42:31 -05:00
Johann Fischer 5296339fde usb: rework to use macro STRUCT_SECTION_FOREACH
Replace deprecated macro USBD_CFG_DATA_DEFINE by
USBD_DEFINE_CFG_DATA which places usb_cfg_data structures
in specific iterable section.

Replace __usb_data_start, __usb_data_end usage patterns
  size_t size = (__usb_data_end - __usb_data_start);
  for (size_t i = 0; i < size; i++) {...}
by
  STRUCT_SECTION_FOREACH(usb_cfg_data, ...) {...}

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-12-10 07:22:15 -06:00
Torbjörn Leksell 86d8b36955 Tracing: k_free tracing hook heap reference added
Added heap reference parameter to k_free tracing
hook to allow tracing of the pointer which was
passed as a parameter to a k_free call.
As part of this update the defines
(for this hook) in the various tracing formats
was also updated.

Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
2021-11-16 09:45:01 -05:00
Flavio Ceolin 9444480c7b pm: Better return type for pm_system_suspend
Instead of returning PM_STATE_ACTIVE for when the cpu didn't enter a
low power state and a different state when it entered, but has
already left the state and is active again, it changes
pm_system_suspend to return true when the cpu has entered a low power
state and false otherwise.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Gerard Marull-Paretas 64aea4d57e tracing: fix PM system tracing
System PM tracing was broken for SEGGER SystemView, and was missing
proper documentation.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 16:37:33 -04:00
Gerard Marull-Paretas 866b88fd2c tracing: update pm device runtime
Update the tracing definitions used by the device runtime API.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 16:37:33 -04:00
Tom Burdick 97dc88bb6d tracing: Automatic syscall tracing
When generating syscall wrappers, call a tracing macro with the id,
name, and all parameters of the syscall as params when entering and
leaving the syscall. This can be disabled in certain call sites
by defining DISABLE_SYSCALL_TRACING which is useful for certain
tracing implementations which require syscalls themselves to work.

Notably some syscalls *cannot* be automatically traced this way and
headers where exclusions are set are in the gen_syscall.py as notracing.

Includes a systemview and test format implementation.

Tested with systemview, usb, and uart backends with the string
formatter using the tracing sample app.

Debugging the trace wrapper can be aided by setting the TRACE_DIAGNOSTIC
env var and rebuilding from scratch, a warning is issued for every
instance a syscall is traced.

Automatically generating a name mapping for SYSVIEW_Zephyr.txt is a
future item as is documenting how to capture and use the tracing data
generated.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2021-10-23 20:45:17 -04:00
Peter Mitsis ae394bff7c kernel: add support for event objects
Threads may wait on an event object such that any events posted to
that event object may wake a waiting thread if the posting satisfies
the waiting threads' event conditions.

The configuration option CONFIG_EVENTS is used to control the inclusion
of events in a system as their use increases the size of
'struct k_thread'.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2021-10-16 06:27:10 -04:00
Lixin Guo d39410a217 tests: subsys: fixed the samples/tracing code can not generate coverage
Add some tracing functions to fix that the samples/tracing code
cannot generate coverage by twister.

Fixed #38323

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-09-08 10:28:10 -04:00
Nicholas Lowell cc8ab95760 tracing: Add user-definable tracing interface
Create a new tracing option TRACING_USER that allows
the user to define certain user_sys_trace_... functions
to perform whatever work desired for tracing when
tasks are swiched in/out, during isr enter/exit, and when
cpu is idle.

This infrastructure can be useful for plugging into
locally defined tracing tools or any user-specific
debugging environment.

Signed-off-by: Nicholas Lowell <nlowell@lexmark.com>
2021-09-02 06:54:35 -04:00
Flavio Ceolin 3c0e7ade99 tracing: Add k_work_queue_init info
Add tracing information for k_work_queue_init

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-08-25 22:07:04 -04:00
Fabio Baltieri f88a420d69 toolchain: migrate iterable sections calls to the external API
This migrates all the current iterable section usages to the external
API, dropping the "Z_" prefix:

Z_ITERABLE_SECTION_ROM
Z_ITERABLE_SECTION_ROM_GC_ALLOWED
Z_ITERABLE_SECTION_RAM
Z_ITERABLE_SECTION_RAM_GC_ALLOWED
Z_STRUCT_SECTION_ITERABLE
Z_STRUCT_SECTION_ITERABLE_ALTERNATE
Z_STRUCT_SECTION_FOREACH

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-08-12 17:47:04 -04:00
Johann Fischer ae074e81d4 usb: remove Kconfig option CONFIG_USB
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.

USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.

With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.

CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Johann Fischer 6408d40fd6 usb: use new USB framework header
Replace all macros and types with the new ones from
usb/usb_ch9.h header.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 13:20:07 +02:00
Torbjörn Leksell 22071d613c Tracing: TRACING_NONE Compilation Fix
Fixed several compilation errors that resulted from selecting
TRACING without specifying a tracing system (Tracerecorder,
CTF, Systemview). In this case (TRACING_NONE), some default trace hooks
(in tracing.h) were incorrectly named resulting in compilation errors.
The legacy sys_trace_isr_enter, sys_trace_isr_exit, and sys_trace_idle
also caused problems since these were only given as defines, resulting
in undefined reference errors since they are required by the assembly
files calling these. To solve this issue I've added a stub file
"tracing_none.c" (only compiled if TRACING_NONE) and declared the
functions in tracing.h if no tracing system is selected.

Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
2021-05-27 14:39:40 -05:00
Anas Nashif 108129cf7d tracing: fix conflict with RTT locking
Make custom RTT locking configurable and select it where it is needed.
When using RTT for tracing we want to use the default locking.

Update both segger and tracerecorder modules to support that.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-25 07:36:38 -05:00
Anas Nashif acee43a176 tracing: fix indentation of config entries
Fix indentation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-25 07:36:38 -05:00
Anas Nashif cd9421a45e tracing: systemview: display return value of APIs
In systemview, display return value correctly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-17 18:45:57 -04:00
Anas Nashif 3b82c388f6 pm: trace pm_device_enable/disable
Trace both pm_device_enable and pm_device_disable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-17 18:45:57 -04:00
Anas Nashif eccda68418 power: trace power events
Trace PM transition sequence and events.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-17 18:45:57 -04:00
Anas Nashif b865c85ef4 tracing: fix test format
Add missing defines causing build errors in some scenarios.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-17 18:45:57 -04:00
Anas Nashif 7c582f4b7c tracing: systemview: rework IDs and make them match APIs
New version of Systemview has Zephyr API description that did not match
what we had, align with what the tools provides and expand hooks to
support additional APIs. We now cover most kernel APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-11 12:59:03 -05:00
Anas Nashif 72c830c3ee tracing: test format: print more details
Print timeouts and other details.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-11 12:59:03 -05:00
Anas Nashif fe14c23852 tracing: move test format into its own directory
Minor cleanup keep format location uniform.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-11 12:59:03 -05:00
Anas Nashif 6a8148f384 tracing: systemview: cleanup headers
Cleanup systemview headers and move sysview hooks into sysview_config.c

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-08 17:06:24 -04:00
Anas Nashif 1af037f477 modules: enable percepio tracerecorder for tracing
Add support for percepio tracealyzer.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Anas Nashif f477bac818 tracing: support new macros with systemview
Use new macros with systemview and rework hooks adding support for new
trace points.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Anas Nashif a35bb82539 tracing: Use new macros with CTF based tracing
Use new tracing macros to generate tracing output in CTF format.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Anas Nashif 270be80caa tracing: add empty test macros
Add support for new tracing macros in test backend. Move header from
sample into the subsystem and make it available for general testing with
any application.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Torbjörn Leksell 16bbb8ef34 Tracing: Trace hook support macros
Adds generic trace hook macros for inserting trace hook for
function entry, exit, blocking, and object initialization
with a variable number of arguments (objects, return values,
etc.). Utilizing macro concatenation these macros produce
trace hooks of a similar format to the old trace system
with SYS_TRACING_OBJ_FUNC(k_thread, switched_in) being
turned into sys_trace_k_thread_switched_in() by the
preprocessor. Although these macros still rely on the manual
definition of each unique trace hook in tracing.h, the benefit
of not directly calling those is that we can enable/disable
trace hooks based on object type (k_thread, k_sem, etc.)
through the preprocessor while providing the ability of adding
type specific runtime trace processing similar to
SYS_TRACING_OBJ_INIT.

Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Jan Müller 10ee29e947 tracing: Add ISR numbers to SystemView for Cortex-M
The sysview module does not set an interrupt number when recording ISRs
using SEGGER SystemView. Added ISR numbers for Cortex-M based chips.

Signed-off-by: Jan Müller <jan.mueller@nordicsemi.no>
2021-05-04 10:17:23 -05:00
Anas Nashif bc747e7167 tracing: remove cpu_stats in favor of thread runtime stats
Removing CONFIG_TRACING_CPU_STATS in favor of
CONFIG_THREAD_RUNTIME_STATS which provides per thread stats. The same
functionality is also available when Thread analyzer is enabled with the
runtime stats enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-16 15:31:24 -04:00
Julien Massot 80402f7f8b tracing: add RAM backend
If Zephyr is running on a coprocessor we might lack I/O
such as uart or usb to output tracing datas but we might
have gigabytes of RAM available.

This patch allows to output trace datas to a ram buffer, which then
may be retrieved using gdb.

e.g:
(gdb) dump binary memory channel0_0 <ram_tracing_start> \
<ram_tracing_end>

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
2021-03-06 07:33:59 -05:00
Rubin Gerritsen bc6d16e422 systemview: Use common function to get sysview thread name
Use a common function to get the thread name.
There was no necessity in keeping sys_trace_thread_info() inline,

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-11-21 08:29:26 -05:00
Rubin Gerritsen 7a9da57cd8 systemview: Use thread name when available
This may make it easier to debug.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-11-21 08:29:26 -05:00
Rubin Gerritsen 5d121a95e9 systemview: SystemView tracing requires THREAD_MONITOR
Otherwise it will not be able to send its thread list.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2020-11-21 08:29:26 -05:00
Maureen Helm 57b756b442 debug: tracing: Add Segger RTT and SystemView linker section options
Enables optionally placing Segger RTT and SystemView data in the DTCM
linker section instead of the default data section. This is needed on
SoCs in the i.MX RT series that use cacheable external SDRAM to store
data.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-20 12:54:09 -06:00
Peter Bigot 017bca3920 tracing: switch to cbprintf as basis for printf functionality
Replace use of z_prf with cbprintf.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-13 06:38:01 -05:00
Daniel Leung 11e6b43090 tracing: roll thread switch in/out into thread stats functions
Since the tracing of thread being switched in/out has the same
instrumentation points, we can roll the tracing function calls
into the one for thread stats gathering functions.
This avoids duplicating code to call another function.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-11-11 23:55:49 -05:00