Commit graph

707 commits

Author SHA1 Message Date
Jukka Rissanen
5a9a39caf3 net: mgmt: Convert the mgmt API to use 64-bit masks
Instead of using 32 bit enum values for event numbers, convert
the code to use 64 bit long bit fields. This means that the
user API is changed to use 64 bit event values instead of 32
bit event values.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-18 10:54:44 +02:00
Arif Balik
1939ba64c3 logging: backend: mqtt
Added MQTT logging backend

Signed-off-by: Arif Balik <arifbalik@outlook.com>
2025-06-11 16:18:51 -07:00
Fin Maaß
265eb71eef logging: backend: net: use connection mgr
Use connection manager to deactivate and activate
net log backend.
This removes the warnings about dropped packages
completly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Fin Maaß
8ce499665b logging: backend: net: avoid automatic enabling
Avoid automatic enabling of the syslog backend by
the logging subsystem.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Fin Maaß
0d74f6239b logging: backend: net: use sizeof to check Kconfig
Use sizeof to check if the Kconfig value had been
set, to allow the compiler to optimize.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-05 12:21:00 +02:00
Abderrahmane JARMOUNI
63cf0c803f logging: uart_backend: add uncached buffers support
When async UART is used & DCache is enabled, some SoCs, like STM32H7,
require UART buffers to be placed in nocache memory to avoid cache
coherence issues.

Fixes issue 87795

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
2025-05-05 12:20:42 +02:00
Christoph Winklhofer
13054293ad tests: logging: Allow LOG_PRINTK from user space
The commit '3b29b9fa3b (tests: logging: restore userspace testing,
2025-04-18)' set CONFIG_LOG_PRINTK=n which brakes the build on the
platform 'ip_k66f'.

Without CONFIG_LOG_PRINTK=n (dependency from CONFIG_USERSPACE=y) some
tests in 'tests/subsys/logging/log_core_additional/logging.log_user'
would not build.

Remove this dependency so that LOG_PRINTK can also be used from user
space, which is possible since '77925656ab (logging: Fix runtime
message creation in user-mode thread, 2025-04-18)' and reset
CONFIG_LOG_PRINTK=y.

Fixes: #89067
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-05-05 12:20:34 +02:00
Daniel Leung
5682a7f09e logging: backend/xtensa_sim: more generic enabling condition
Instead of using individual SoC kconfigs to determine whether
to enable the Xtensa simulator logging backend, simply use
CONFIG_SIMULATOR_XTENSA.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-05-01 18:16:20 +02:00
Guennadi Liakhovetski
1b7eae43db logging: mtrace: don't activate with hook == NULL
adsp_mtrace_log_init() can be called with its argument equal NULL,
mtrace_active shouldn't be set to true in that case.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-04-25 19:00:49 +02:00
Christoph Winklhofer
8c7aded4c1 logging: Assign module data to memory partition 'k_log_partition'
The logging module data is assigned to the memory partition
'k_log_partition' so that a user mode thread can access this data (see
k_mem_domain_add_thread()). The 'k_log_partition' is created when:
- CONFIG_USERSPACE=y
- CONFIG_LOG_ALWAYS_RUNTIME=y

The option CONFIG_NO_OPTIMIZATIONS=y forces the logging module to use
the runtime message creation CONFIG_LOG_ALWAYS_RUNTIME=y. This raises a
MPU violation when logging is used in a user mode thread since this
thread is not allowed to access the module data (e.g. __log_level,
__log_current_const_data).

Note that the user mode thread may also require access to the partition
'z_libc_partition'.

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-23 02:15:25 +02:00
Christoph Winklhofer
77925656ab logging: Fix runtime message creation in user-mode thread
The runtime message creation (CONFIG_LOG_ALWAYS_RUNTIME=y) in a user-
mode thread raises a MPU violation, e.g. call LOG_INF("Test") in a
user-mode thread.

The function 'z_log_msg_runtime_vcreate' runs in user mode but works
with Kernel data. Hence, create the cbprintf package on the stack (of
the user mode thread) and pass it further to the syscall
'z_log_msg_static_create'.

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-23 02:15:25 +02:00
Krzysztof Chruściński
aaeb015ec4 logging: frontends: stmesp: Fix sending string location
String location information should only be sent for core which
do not append strings to the log message (PPR, FLPR). Without
this, cpurad was also sending that information and that was
redundant.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-04-01 16:26:50 +02:00
Krzysztof Chruściński
c8d7d577a6 logging: frontend_stmesp: Fix string addresses from remote core
When decoding logs from a remote core with memory that APP can
access, wrong address of an array with string addresses was used.
Log message contains index of a string and APP strings array was
used instead of remote core. Extend STMESP logging so that address
of string array of a remote core is send during startup to the APP
and APP is using this array to decode strings from remote cores.
Bug applies only to PPR and FLPR as APP has no access to RAD memory.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-04-01 16:26:50 +02:00
Tahsin Mutlugun
d4e87247f0 logging: backends: xtensa_sim: Drop SoC dependencies
Make Xtensa simulator logging backend depend on more generic
SIMULATOR_XTENSA setting instead of individual SoCs.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2025-03-27 09:51:17 +01:00
Eric Holmberg
d7bf4b3ddd logging: backend_fs: disable ANSI color for filesystem logging
Before the fix for #77150 was merged, with LOG_BACKEND_SHOW_COLOR=n and
CONFIG_SHELL_VT100_COLORS=y the shell would still display colors by
enabling the flag in the shell_log_backend.c.

Now, LOG_BACKEND_SHOW_COLOR has to be enabled to allow shell logging
color, but that writes ANSI escape sequences to the log files.

Explicitly disable ANSI color output for the filesystem logging backend.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
2025-03-27 09:50:59 +01:00
Dong Wang
3fac83151d logging: Assign IDs to log backends early during log_core_init
This commit moves the assignment of backend IDs from the 'z_log_init'
function to the earlier 'log_core_init' function. This ensures that
backend IDs are assigned before they are used in the 'log_backend_enable'
function, preventing incorrect settings of log dynamic filters.

Signed-off-by: Dong Wang <dong.d.wang@intel.com>
2025-03-18 16:42:07 +01:00
Helmut Lord
84163d35e6 logging: rtt: add dictionary hex logging
Adds hex dictionary logging for RTT backend

Signed-off-by: Helmut Lord <kellyhlord@gmail.com>
2025-03-13 16:57:05 +00:00
Lars-Ove Karlsson
8d3dcd79f4 logging: Added config to disable vla in statements
The config LOG_USE_VLA depends on that MISRA_SANE is not set.
Unfortunately the IAR toolchain can't handle vla:s inside a
statement, which the LOG_USE_VLA macro does.

I've added a new, hidden config to check if vla is ok inside
statements, SUPPORT_VLA_IN_STATEMENTS. Default is always y, but
a toolchain can override it so that VLA is not used by
Z_LOG_MSG_ON_STACK_ALLOC.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-11 18:55:08 +01:00
Guennadi Liakhovetski
57e8d5ecfb log: fix log_flush()
The logging thread is usually woken up by a timer, if the timer
period is longer than 10ms, log_flush() can iterate multiple times
needlessly, while waiting for the next timer. Instead wake up the
logging thread to let it flush the queue immediately. Besides a
hard-coded polling period of 10ms is too long for some applications,
make it a Kconfig parameter.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-03-07 20:20:00 +01:00
Krzysztof Chruściński
d23e12ac45 logging: backends: rtt: Do not enable when shell logging is used
Typically, when shell logging backend is used user wants to get
logs on shell instances so do not enable raw RTT log backend in
that case. When raw backend is enabled then initial logs go to
RTT backend and they are not visible on shell which starts later
as it requires additional thread.

It can be assumed that when RTT backend is used it will be
explicitly enabled by the user.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-02-14 19:40:23 +00:00
Emil Gydesen
571f26cf1a Bluetooth: Rename BLE to Bluetooth (LE) where applicable
The BLE acronym is not an official description of Bluetooth
LE, and the Bluetooth SIG only ever refers to it as Bluetooth
Low Energy or Bluetooth LE, so Zephyr should as well.

This commit does not change any board or vendor specific
documentation, and the term BLE may still be used in those.
It will be up to the vendors to update it if they want,
since many of them are using the term BLE in their
products.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-12 12:24:18 +01:00
Luca Burelli
802156c0cb logging: improve log_flush() robustness
The 'log_flush()' function is used to wait for all pending log messages
to be processed by the background thread. This is performed by polling
the 'log_data_pending()' function, which scans all available buffers.

The log core already provides a 'buffered_cnt' variable that keeps track
of the number of pending messages. This variable is updated atomically
and could be a more efficient implementation for that check.

This commit moves the 'buffered_cnt' decrement _after_ the message
processing and buffer release, to ensure that the variable reflects
the number of pending messages at any moment in time.

The 'log_data_pending()' function is then replaced with a direct check
of the 'buffered_cnt' variable.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-11 15:39:29 +01:00
Kamil Krzyzanowski
cd281ab40b logging: fs backend: simplify checking if file exists
In order to check if the desired log file exists, the backend would open
the directory, then go through all the files seeing if one of them matches
the correct filename. Simplify to just `fs_stat` the file instead.

This has the added side effect of lowering the time spent checking if the
file exists after every log. Some quick testing revealed the time spent
checking went down from ~150-300ms to ~10ms (on my specific board, with a
nRF9160 writing to a LittleFS on external flash).

Signed-off-by: Kamil Krzyzanowski <kamnxt@kamnxt.com>
2025-02-07 14:33:35 +01:00
Kamil Krzyzanowski
41f2c64e97 logging: fs backend: only fs_sync when done with a batch of logs
The previous behavior was to call `fs_sync` on the file after every log
item written. In many cases, log messages come in bursts, and `log_core`
already operates in batches, configurable using
`CONFIG_LOG_PROCESS_THREAD_SLEEP_MS` and
`CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD`. Once the batch is done, the
backends get notified with `LOG_BACKEND_EVT_PROCESS_THREAD_DONE` if any
logs were processed. This is a nice time to `fs_sync` the written changes.

This change both speeds up the time spent writing logs and reduces the
amount of block erases done on the flash, as the previous implementation
erased blocks after each individual log message.

Signed-off-by: Kamil Krzyzanowski <kamnxt@kamnxt.com>
2025-02-07 14:32:06 +01:00
Joakim Andersson
dc97cc0cd5 tests: logging: Convert unit test to include the full FS backend
Convert testing of the logging backend for file-system to include the
full implementation.
Need to disable logging and just include the unit under test to make
this simpler.
The API functions for the backend can then be called on the backend
object.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2025-02-07 14:32:06 +01:00
Yong Cong Sin
f840a35be3 logging: log_cmds: init uninitialized backend on log_go()
For backends that do not autostart themselves, initialize
& enable them on `log backend <log_backend_*> go`, so
that they function properly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-02-04 15:00:58 +01:00
Yong Cong Sin
8dd9d924fe logging: init backend id regardless of autostart
The `id` is basically a compile-time constant. Setting it every
time the backend is enabled is unnecessary. Instead, set it on
`z_log_init()` regardless of whether or not it requires to be
`autostart`ed.

Fixes an issue where the `filter_get`/`filter_set`
accessed the wrong index and displayed the wrong log level when
user accesses the status of an uninitialized backend via:
`log backend <uninitialized_backend> status`.

Also fixes an issue when user tries to list the backends via:
`log list_backends`, where all uninitialized backends will have
ID = 0.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2025-02-04 15:00:58 +01:00
Krzysztof Chruściński
9b2532ab43 logging: frontends: stmesp: Fix logging single argument log twice
Macro was missing a break when single argument with non 32 bit
word argument was detect. Because of that, there were two
logging messages created for a single log entry.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-01-24 15:43:19 +01:00
Tom Burdick
5de7e415a0 logging: Add a log flush operation
Ensure all pending log messages are processed by the log processing
thread when log_flush is called, blocking the caller until done.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2025-01-15 09:33:28 +01:00
Robert Lubos
77810b373a log: websocket: Remove debug printing
The debug printing feature seems to be broken by design - not only in a
default configuration it would trigger endless logging loop (as printk
is piped through logging subsys), it also doesn't work well with
deferred logging (additional artifacts in the output).
Since similar effect can be achieved by enabling any other logger
backend, which should receive the same data as the websocket one, simply
remove it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
02b5ec62c7 log: websocket: Avoid byte drop for long messages
In case the log message length exceeded the websocket buffer size, the
backend would drop the overflowing character, instead of sending it as a
part of the next message.

Rework the ws_console_out() logic a bit to prevent that.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Robert Lubos
224ffca819 log: websocket: Fix log output function return value
The log output function registered for the logger backend is expected to
return the number of bytes processed, but currently it returns the TX
retry count. This commit fixes it. In case data could only partially be
sent, respective bytes count is returned. In case of TX error, the bytes
are assumed dropped to prevent busy looping in the logger.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-13 20:23:07 +01:00
Jungo Lin
7019abb820 logging: increase the maximum value of LOG_BUFFER_SIZE
Increase the maximum value of LOG_BUFFER_SIZE from 64 KB to 1 MB
to accommodate varying device requirements.

Signed-off-by: Jungo Lin <jungolin.tw@gmail.com>
2024-12-12 19:59:51 +01:00
Krzysztof Chruściński
ca4f2d94f8 Revert "segger: rtt: disable unsupported shell/log features"
This reverts commit c88a9ef272.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-11 21:30:19 +01:00
Krzysztof Chruściński
d1bd45739a logging: frontends: stmesp: Move zephyr_custom_log.h to the unique path
Logging with STMESP frontend is using custom logging header feature.
Put that specific header file in a custom path which is added to the
build only if that logging frontend is used.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-10 20:37:22 +01:00
Krzysztof Chruściński
9d478d7675 logging: frontends: stmesp_demux: Add support for turbo logs
Add support for handling optimized short log messages (aka turbo logs).
There are 2 types of turbo log messages:
- No arguments. D16MTS is used for that on channel > 32768
- One numeric argument. DM16 followed by D32MTS is used.

Additionally, in order to be able to get source name for log messages
coming from owned by cpuapp co-processors (PPR and FLPR) there must
be a way of passing location of constant source data from PPR/FLPR to
cpuapp which handles ETR data. This method is added in the commit as
well. PPR/FLPR sends D32M during the boot with address of constant
source data section. Demultiplexer stores those addresses and it is
able to retrieve source name for log messages from PPR/FLPR.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-10 11:09:55 +01:00
Krzysztof Chruściński
752f8b0176 logging: frontends: stmesp: Add optimized short logs
Add 'turbo' logging feature. When enabled, short logs (no argument
or one numeric, 32 bit argument) are handled in a special way that
is much faster than the default one (5-10x faster). Additionally,
there is an option to remove all other logs from the system which
allows to not include almost any logging framework code in the
binary (~170 bytes of code is needed). It may be especially
valueable for memory constraint targets (ppr, flpr) where with
only 170 byte of code (+code for each log message) we can provide
limited formatted string logging support.

'Turbo' logging is using following to achieve that:
- logging strings are put into a memory section and additional
memory section is created which holds addresses of those strings.
Index in that array is used to identify a string (32 bit address
is encoded into a smaller number, 15 bits is more than enough).
This index is used for a STMESP register set (there are 2^16
available). So STMESP channel encodes string.
- Logging level is stringified and prepended to a string
- Source ID is encoded by using DM16 (so far not used).
- Log without arguments is written as DMTS16
- Log with one argumetn is written as DM16+DMTS32

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-10 11:09:55 +01:00
Krzysztof Chruściński
3f4739834f logging: Set frontend filters only when filtering enabled
Set initial filtering settings in the log core init only if
runtime filtering is enabled. It saves few bytes when runtime
filtering is off.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-10 11:09:55 +01:00
Fin Maaß
5d2068f491 logging: log_output: move partly unused code
move code, that is only needed for one case
to that case.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-12-10 08:06:25 +01:00
Fin Maaß
1d4249dea6 logging: remove part for when gmtime_r is not available
now that CONFIG_POSIX_C_LANG_SUPPORT_R will
add a custom implementation for gmtime_r() if that
is not provided by the toolchain, we can simply depend on
that, instead of using out own.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-12-10 08:06:25 +01:00
Fin Maaß
fc50427f3e logging: backend: net: add missing dependency
add missing dependency of NET_SOCKETS to LOG_BACKEND_NET.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-12-10 08:06:25 +01:00
Krzysztof Chruściński
9917ea4fe6 logging: formatting: Allow coloring in custom cases
In order to support error and warning message coloring
LOG_BACKEND_SHOW_COLOR must be set. Allow setting it for
customized cases.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-11-19 10:12:05 -05:00
Carles Cufi
9643ca20e9 nordic: Remove the nRF54H20 Engineering B
The production version of the nRF54H20 SoC is now available, so remove
the initial Engineering B (EngB) preview version.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2024-11-16 15:09:14 -05:00
Juha Sunnari
51bc60e142 logging: frontends: stmesp: alternate message output option
Add an alternate message output option in which messages are
ended with an additional zero data byte with marker and timestamp.
Can be used to maintain compatibility with certain decoders.

Signed-off-by: Juha Sunnari <juha.sunnari@nordicsemi.no>
2024-11-16 13:37:02 -05:00
Jacob McClellan
39042dc9cc logging: Initialize 'chosen' pointer in z_log_msg_claim_oldest to NULL
Fixes a compiler warning 'chosen' may be uninitialized when later
dereferenced

Signed-off-by: Jacob McClellan <mcclellanjacob@meta.com>
2024-10-30 14:28:52 -05:00
Jukka Rissanen
34bb8cb35c logging: backend: websocket: Avoid uninit variable warning
The ret variable might be used uninitialized.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-10-25 12:50:54 -05:00
Grzegorz Swiderski
bcf6a91689 logging: stmesp: Do not append strings on nRF54H20 EngB VPRs
Just like on nRF54H20 EngC.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-10-24 16:55:44 +01:00
Krzysztof Chruściński
b6f7eac00a logging: Fix LOG_IMMEDIATE_CLEAN_OUTPUT
There was a kconfig option used in v1 logging to get clean
output in the immediate mode. It was lost during the transition
to v2 but Kconfig remained. Adding spin_lock to log processing
to ensure that log messages are not interleaved in the output
in the immediate mode.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-23 16:53:30 +02:00
Krzysztof Chruściński
60d8482348 logging: log_cmds: Enable log commands for shell with the logging frontend
When shell is integrated with the logging frontend then pointer to
the logging backend in the shell structure is null. When null pointer
is found assume that it is a shell instance with logging frontend
integration and use frontend in the logging commands.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-17 10:48:25 -04:00
Jukka Rissanen
7408004531 logging: backend: Add websocket backend
Allow logging output to websocket console. Requires that
websocket shell backend and websocket HTTP server support
is also enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-10-15 04:11:03 -04:00