Commit graph

621 commits

Author SHA1 Message Date
Yong Cong Sin 2049aa8d16 logging: backend: uart: variable shouldn't have the same name as struct
Rename the `device` variable in the `struct lbu_cb_ctx` to
`uart_dev`, as it is a convention in Zephyr to not have the
struct variable name after the struct.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-11-14 12:26:48 -05:00
Yong Cong Sin 1b4a647950 logging: backend: uart: append index conditionally for compatibility
Updated the `LBU_DEFINE` so that the index is appended only
when given to improve backward compatibility.

When it is depending on the `zephyr,console` node, the backend
is defined as `log_backend_uart`.

When it is depending on the new `zephyr,log-uart` node, the
backend is defined as `log_backend_uart0`,
`log_backend_uart1`, and so on.

Updated the names of the internal variables to follow the same
naming convention.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-11-14 12:26:48 -05:00
Chris Friedt c0064f1de8 logging: uart: support multiple instances
Extends the log_backend_uart to support logging to multiple
UART instances.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-13 09:47:06 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 684b8fcdd0 syscall: Z_SYSCALL_VERIFY_MSG -> K_SYSCALL_VERIFY_MSG
Rename macros and do not use Z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Krzysztof Chruściński 01cf78ad39 logging: Do not check pointers when strings are stripped
When logging strings are stripped from the binary prevent
performing check of pointers which requires access to the
string.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-31 09:01:38 +01:00
Krzysztof Chruściński 9470e3d129 logging: Imply strings stripping if dictionary frontend is used
When UART dictionary frontend is used strings can be removed
from the binary.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-27 11:42:21 +02:00
Krzysztof Chruściński 59abf921c1 logging: Add option to remove strings from binary
Add option to remove string literals which are constant and
never touched by the firmware. It can save significant amount
of RO memory.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-27 11:42:21 +02:00
Krzysztof Chruściński a68cdb0558 logging: Optimize handling of simple and common log messages
Some compilers (e.g. riscv32) does not handle well complex macros
for logging. Generated code is bigger than expected (e.g. riscv32
code is almost twice bigger than cortex-m code). Use of logging can
lead to unexpected code increase.

To handle that an analysis of the zephyr code base was performed and
it shown that 75-80% of logs are simple strings with 0 arguments
(~45%), one 32 bit argument (~26%) or two 32 bit arguments (~6%).
Given that a set of dedicated macro were created which are applied
to those 3 cases which on 32 bit platform create very simple log
messages without padding or alignment needed.

Such dedicated macros save up to 40% of code (riscv32) and also
executes 30% faster (arm cortex and riscv32).

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-27 10:50:39 +02:00
Krzysztof Chruściński 900f9c3b24 logging: log_frontend: Add optional API for common messages
Extend frontend API with optional set of functions which can
be used when simplified log message handling is enabled. If this
mode is enabled then there are dedicated macros for processing the
most common messages (string + 0-2 word arguments). Using this API
can speed up the processing of messages that are the most common.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-27 10:50:39 +02:00
Krzysztof Chruściński 1a0e8d6f9e logging: log_msg: Add functions for handling simple log messages
In preparation for new feature which optimizes handling of
the most common log messages (0-2 32 bit word arguments) add
functions dedicated for that purpose.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-27 10:50:39 +02:00
Flavio Ceolin 84f679d22d logging: Fix misuse of const and k_tid_t
"const k_tid_t" is "struct k_thread * const" and not
"const struct k_thread *" as the code may be assuming. Just
drop it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-20 15:08:42 +02:00
Anas Nashif 996c8457d7 ztest: remove old ztest api
Remove old Ztest API entirely. New API is the now the default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Christopher Friedt 137097f5c3 logging: log_core: correct timeout of -1 ms to K_FOREVER
Many releases ago, specifying to block indefinitely in the log
processing thread would do just that.

However, a subtle bug was introduced  such that specifying -1
for `CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS` would have the
exact opposite effect than what was intended.

As per Kconfig, a value of -1 should translate to a timeout of
`K_FOREVER`. However, conversion via `K_MSEC(-1)` results in
a `k_timeout_t` that is equal to `K_NO_WAIT` rather than the
intent which is `K_FOREVER`.

Add a dedicated check to to ensure that a value of -1 is
correctly interpreted as `K_FOREVER` in `log_core.c`.

For reference, the blocking feature was described in #15196,
added in #16194, and it would appear that the regression
happened in c5f2cdef09.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-10-16 12:06:42 +02:00
Ladislav Podivin 390b6520b8 Logging: improve help message of LOG_PRINTK Kconfig option
Improve it so that:
- it mentions the important fact that it redirects `printk` messages
 to the logging subsystem
- it is consistent with the help messages of the other options in this
 file (i.e. it starts with "If enabled")

Signed-off-by: Ladislav Podivin <ladislav.podivin@tietoevry.com>
2023-10-13 22:36:47 +03:00
David Corbeil 8a25b039e4 logging: net: changing syslog server address while running bug
Fixed bug where changing the syslog network server's address while it's
still running would fail most of the time

Signed-off-by: David Corbeil <david.corbeil@dynon.com>
2023-09-29 16:27:04 +02:00
Krzysztof Chruściński 6b7c8ae1b3 logging: log_output: Minor code cleanup
Z_LOG_EVAL was used in place where COND_CODE_1 was a much
better fit. Z_LOG_EVAL gave the same result but it was not
intended to be used here.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-09-29 09:48:57 +02:00
Armin Brauns 9727f61371 logging: return actual filter level when runtime filter is disabled
log_filter_set() is defined to return the actual level that was set by the
call. In case runtime filtering is disabled, this is always the compiled-in
log level, not the level passed by the user.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-09-29 09:48:49 +02:00
David Corbeil d732a8678b logging: runtime setting of syslog server ip address
Added functionality to change the syslog server's
ip address at runtime as well as sample for
syslog network backend

Signed-off-by: David Corbeil <david.corbeil@dynon.com>
2023-09-27 09:13:23 +02:00
Marcin Niestroj a9fbcd2785 logging: swo: add Kconfig option for SWO reference frequency
SWO reference frequency was set based on `swo-ref-frequency` under `itm`
nodelabel or `/cpus/cpu@0/clock-frequency` property. Not all platforms
configure those.

All ST devices configure CPU frequency in `clock-frequency` under `rcc`
nodelabel. Configuring the same value for each board in
`/cpus/cpu@0/clock-frequency` would be one way to make SWO work out of the
box. There is lots of copy-pasting involved in this, which makes this very
error-prone.

Introduce Kconfig option, which will default to values configured in `itm`
or `/cpus/cpu@0`. The main advantage will be for platforms like ST, where
CPU clock frequency is already configured in another place. Thsoe could
override default value in SoC, board or any other platform specific layer.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-09-13 16:29:56 +02:00
Xudong Zheng 7188f925f9 logging: fix timestamp scaling with 64-bit timestamp
In default_get_timestamp(), sys_clock_tick_get() is returned when
CONFIG_LOG_TIMESTAMP_64BIT=y. The timestamp frequency should reflect this.

Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com>
2023-09-06 17:23:59 +02:00
Fabio Baltieri 56b4225126 logging: fix few mismatched CONTAINER_OF
Fix few mismatched CONTAINER_OF, few missing pointers to the first
element, one explicit casting.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-08-31 14:08:31 +02:00
Krzysztof Chruściński cebd140bee logging: log_output: Add optional tid formatting
Add option to prefix log message with thread ID or thread name.
Align tests and add test case to the log_output test.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-08-31 14:08:19 +02:00
Krzysztof Chruściński 70dce83f14 logging: Add option to store tid in the log message
Add Kconfig LOG_THREAD_ID_PREFIX option which allows storing
thread id in the log message and process it as message prefix
(as id or thread name).

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-08-31 14:08:19 +02:00
Gerard Marull-Paretas 4c86dbd4a6 logging: backends: adsp_hda: add missing init.h, device.h
File was using device.h/init.h API without including respective headers.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-30 11:54:48 +02:00
Gerard Marull-Paretas 528a6f5e79 logging: frontend_dict_uart: add missing init.h
File is using SYS_INIT, from init.h.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-30 11:53:21 +02:00
Daniel Leung 169f505226 xtensa: add support for dc233c SoC for QEMU
This adds SoC and board configs to support the dc233c core
that is available on QEMU. This core has more features than
sample_controller, such as MMU support.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-26 16:50:40 -04:00
Daniel Leung 8bfdb23a08 logging: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Daniel Leung 287916c71e logging: sys_t/catalog: fix unaligned access
When copying parameters into payload buffer, it is possible
that after copying a string over, the pointer to buffer is
no longer aligned on 4 or 8 bytes. And some toolchains may
decide to treat the copy as aligned since the values being
copied are 4 or 8 bytes. This results in unaligned memory
access and hardware exception. So change the copy to memcpy
to avoid potential unaligned access.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-07-25 09:14:17 +02:00
Pieter De Gendt a21c8f0281 logging: cmake: Remove duplicate source entry
log_cache.c was listed twice for zephyr_sources_ifdef.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-07-07 09:20:11 +02:00
Florian Grandel c88a9ef272 segger: rtt: disable unsupported shell/log features
The RTT backend of the shell does not support several of the more
advanced terminal features. This commit proposes to inactivate these
features by default when RTT is selected as shell backend.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-06-23 14:42:41 +02:00
Andrey Borisovich 23b3cae1b1 inte_adsp: ipc: prevent ipc message send during Device power transition
When CONFIG_PM_DEVICE is enabled IPC Device may be during power transition
during a call to intel_adsp_ipc_send_message function.
Changed signatures of intel_adsp_ipc_send_message and its sync version
to return int and negative error codes on error.
On attempt to send IPC message during Device power transition
-ESHUTDOWN error code is returned, on busy state -EBUSY.
Updated all function references.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
2023-06-22 06:14:57 -04:00
Victor Chavez bee43bd972 logging: Fixed BLE backend buffer size independent of MTU
The BLE backend has a bug that when the MTU size is less than
the buffer the notification always fails and does not allow
to flush the buffer.

This fix checks for the MTU size of the current connection
and adjusts it. In addition, the buffer size is no longer
settable by the user and depends on the transmission size
of MTU set with CONFIG_BT_L2CAP_TX_MTU.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
2023-06-19 08:38:08 +02:00
Daniel Leung 057ceb1408 logging: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Krzysztof Chruściński 6718869658 logging: log_output: Fix for Coverity issue 316014
Log level is stored on 3 bits thus in theory it can be set to 7
and yet accepted levels are up to 4 thus Coverity complains.
Adding assert that prevents use of levels above 4.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-06-02 15:07:08 -04:00
Krzysztof Chruściński 314fb05166 logging: log_output: Fix for Coverity issue 316019
Adding missing casting.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-06-02 15:07:08 -04:00
Qipeng Zha 7aa618d288 logging: trigger log process once reach threshold
atomic_inc(&buffered_cnt) return previous count of log messages,
should use current count to compare with threshold config value.

Signed-off-by: Dong Wang <dong.d.wang@intel.com>
Signed-off-by: Qipeng Zha <qipeng.zha@intel.com>
2023-05-24 05:06:11 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Xudong Zheng 79c4c82baf logging: change log_output_timestamp_to_us() to take log_timestamp_t
If CONFIG_LOG_TIMESTAMP_64BIT is enabled, the timestamp will be 64-bit

Signed-off-by: Xudong Zheng <7pkvm5aw@slicealias.com>
2023-05-08 16:57:02 -04:00
Kumar Gala b07be57875 logging: Use TYPE_SECTION macros for log dynamic
Clean up log_dynamic to utilize macros for handling sections.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-03 10:43:31 +02:00
Kumar Gala bae0a5b8b6 logging: Use TYPE_SECTION macros for log const
Clean up log_const to utilize macros for handling sections.

Update database_gen.py to match naming convention change.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-03 10:43:31 +02:00
Anas Nashif 6388f5f106 xtensa: use sys_cache API instead of custom interfaces
Use sys_cache instead of custom and internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-26 07:31:22 -04:00
Kumar Gala caea9dc196 logging: Use TYPE_SECTION macros for log strings
Clean up log_strings to utilize macros for handling sections.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-20 10:52:07 +02:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Kumar Gala c7c8ea6a45 logging: Fix build issues with arm-clang
The arm-clang compiler/linker does not optimize away unused function
symbols and thus will error if symbols that are referenced are not
defined.  To fix this add needed ifdef'ry.

Fixes #56630
Fixes #56628

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-14 06:04:11 -04:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Gerard Marull-Paretas 0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Kamil Kasperczyk 6fe83ea810 logging: Changed log template to consider default log level
Added using LOG_DEFAULT_LEVEL kconfig option in log module
template for assigning the default log level to newly created
module instance, instead of assuming always INFO level.

Signed-off-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
2023-04-05 13:47:06 +02:00
Hein Wessels 8735d0f653 logging: support custom timestamp formatting
This feature adds support for using a custom function to format
the timestamp used for all logging backends. When the kconfig
option LOG_OUTPUT_FORMAT_CUSTOM_TIMESTAMP is set the custom
formatting function will always be used.

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-04-04 13:41:17 +02:00
Victor Chavez 649570ebc4 logging: Fixed BLE backend when used alone
There was a bug in the BLE backend when it was the only enabled
backend. Instead of using the API `log_backend_activate` to
activate the backend, the logger requires the first time to be
enabled with `log_backend_enable`.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
2023-04-04 08:53:25 +00:00
Victor Chavez a18aa915ce logging: Added BLE Backend Service
Added a new logger backend to recieve data over a BLE
notification characteristic.
The characteristic is based on the UUID from the Nordic connect SDK
service NUS, which allows to have a UART shell over BLE.
The idea behind this, is that this logger can be used directly
with the NRF apps or any other BLE UART terminal app.

Signed-off-by: Victor Chavez <chavez-bermudez@fh-aachen.de>
2023-04-03 15:17:57 +02:00
Kumar Gala 831bd2f841 armclang: fix compiler warnings with isprint()
We get compile warnings of the form:

drivers/console/uart_console.c:508:8: error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint returns an int, change check to an explicit test against
the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-17 09:30:01 +01:00
Krzysztof Chruscinski 68955ebdb6 logging: Increase package size limit to 2047
Package length was previously stored on 10 bits which limited
package size to 1023 bytes. Descriptor which contained package
length field had one unused bit which can be used to increase
package length field to 11 bits doubling the maximum package
length.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-09 15:10:06 -08:00
Krzysztof Chruscinski a5979dcfa1 logging: Log warning and drop too big message
When packacge exceeds the limitation warning log is printed
and message is dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-09 15:10:06 -08:00
Krzysztof Chruscinski 24ad096232 logging: Renamed internal defines to get rid of 2 suffix
Some internal macros were still using 2 suffix which comes from
time when there was v1 and v2. Cleaning up by removing the suffix.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-03-09 15:10:06 -08:00
Martin Sollie e94c33d530 logging: add support for 64 bit timestamps with Linux format
Combining CONFIG_LOG_OUTPUT_FORMAT_LINUX_TIMESTAMP and
CONFIG_LOG_TIMESTAMP_64BIT results in a wrong timestamp, as the
Linux timestamp format print call assumes a 32 bit variable for
the seconds. Fix it by using a different print format for 64 bit
timestamps.

Fixes: #55372

Signed-off-by: Martin Sollie <ms@aziwell.no>
2023-03-03 11:36:14 +01:00
Jordan Yates 30dbaa83f7 logging: backend_uart: handle PM on panic
Handling panicking while in an ISR. Instead of attempting to call
`pm_device_get` for each character, ensure that the hardware is enabled
when `log_panic` is called.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-03-03 09:17:49 +01:00
Jordan Yates 997dce97bf logging: backend_uart: handle runtime PM
Allow the log_backend_uart char_out implementation to integrate with
'Device Runtime Power Management'.

Without using runtime PM, it is impossible for the application to manage
the power state of a UART instance, given that any module in the
application could theoretically LOG_* or printk at any point in time.

This removes the need to manually call `pm_device_state_set` when the
lowest power states must be reached, while still allowing log messages
to be output.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-03-03 09:17:49 +01:00
Marco Argiolas 92a739e4b4 logging: shell command "disable" fails for "backend" subcommand
A fix to accept valid shell commands of the form `log backend
 shell_rtt_backend disable`, i.e. to affect all modules when no modules are
 specified.

Signed-off-by: Marco Argiolas <marco.argiolas@ftpsolutions.com.au>
2023-02-20 11:13:15 +01:00
Mikhail Siomin b608ddc40f logging: the 'log backend' shell cmd will result in the infinite loop.
The backend_name_get() function always sets 'entry->syntax' to
the name of the last backend, but a calling function iterates
over the idx until 'entry->syntax' is null.
Solution: Added a check that the index is less than the number
of backends and added getting the name of the backend
by the given index.

Signed-off-by: Mikhail Siomin <victorovich.01@mail.ru>
2023-02-19 20:37:53 -05:00
Andrei Emeltchenko 62ab576a6a logging: shell: Fix using uninitialized variables
Fixes using uninitialized variables using returns with correct return
code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-28 08:55:41 +09:00
PawelX Dobrowolski 07052aba13 logging: days in months calculation fix
Array 'days_in_month' of size 12 may use index value bigger then
count of its elements.

Signed-off-by: PawelX Dobrowolski <pawelx.dobrowolski@intel.com>
2023-01-10 09:23:35 +01:00
PawelX Dobrowolski 20ed64be62 logging: prevent of NULL pointer comparison
Add prevent dereference NULL in strcmp

Signed-off-by: PawelX Dobrowolski <pawelx.dobrowolski@intel.com>
2023-01-10 09:23:35 +01:00
Krzysztof Chruscinski 63eba62876 logging: Reset buffered message counter on init
Add reset of buffered messages counter to the initialization function.
It is for testing purposes sinces in the application logging is
initialized only once.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-29 10:33:29 +01:00
Kai Vehmanen 0368b49ea7 logging: fix error handling in link_filters_init
If k_malloc() of filters fails in log_mgmt.c:link_filters_init(),
return an error and do not rely on the __ASSERT(0).

If __ASSERT_ON==0 in the build, assert will not trigger and
code will proceed to execute

  memset(NULL, 0, sizeof(uint32_t) * total_cnt);

Avoid this by returning -ENOMEM on error.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2022-12-22 14:43:43 +01:00
Rob Barnes 61b5566e74 logging: Add an option for a custom log header
There are scenarios when it is necessary to globally redefine
a log macro. The existing logging frontend is not sufficient since
it redirects at the function level.

One example is using pigweed_tokenzier. The pigweed tokenizer depends
on intercepting log strings at the macro level to function.

Introduce an option to include a custom application provided header
named "zephyr_custom_log.h" at the end of log.h. This allows an
application to extend the LOG_* macros globally.

This change includes a simple test that redefines the core LOG macros
to include a custom prefix.

Signed-off-by: Rob Barnes <robbarnes@google.com>
2022-12-22 11:09:59 +01:00
Trent Piepho 2112844eea logging: backend_uart: Reword buffer size Kconfig text
As written, the title and description of the Kconfig option seem to
specify the logging sub-system will not flush until the buffer is full.
Someone reading this would expect that shorter log message will not be
flushed until the specified number of bytes accumulate.

This is not the case.  Each log message is flushed when finished.  The
size is only the maximum bytes of a single formatted message's contents
that will be accumated before the backend flushes.

What's more, it only applies in deferred mode.  In immediate mode there
is no buffering, not just of multiple log messages but also of the
message contents as they are formatted.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2022-12-21 12:23:23 +01:00
Ian Oliver 1675d49b4c log_core: Add Kconfig symbol for init priority
Users may want to do some configuration after the kernel is up, but
before initializing the log_core. Making the log_core's init priority
configurable makes that possible.

Signed-off-by: Ian Oliver <io@amperecomputing.com>
2022-12-14 15:16:54 +01:00
Jamie McCrae 47518d47a2 logging: minimal: Change imply to select for printk
This changes the minimal logging Kconfig to select printk rather
than imply it, this is because if someone turns printk off,
minimal footprint logging does not work, therefore it needs to be
a requirement.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-12-02 16:17:35 +01:00
Armin Brauns 7e0e9d0d7e logging: allow disabling auto-start of UART backend
This allows putting the UART backend on a serial device that has to be
quiet unless logging is explicitly enabled at runtime.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2022-12-01 09:48:42 +01:00
Théo Battrel ff5b8f003e Logging: Add Kconfig template for log inheriting
Add a new Kconfig template that allow log modules to inherit their log
level from their parent module.
For example, the logs used in the Bluetooth audio like
`BT_AUDIO_STREAM_LOG_LEVEL` can inherit their level from
`BT_AUDIO_LOG_LEVEL`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2022-11-30 14:37:58 +01:00
Jamie McCrae c5a40e3a9d logging: Enable LOG_PRINTK if PRINTK is enabled
This change will enable the logging system to handle printk() calls by
default if printk support is enabled, which improves output resiliency
when logging, mcumgr and printk calls are used. Will disable keep
LOG_PRINTK disabled for tests which are not using the new API as
moving to LOG_PRINTK causes test data to be output to a different UART
in the old test system.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2022-11-29 10:46:26 +01:00
Adrian Warecki aac03280ec dma: dts: Rename of the dma_buf_alignment to dma-buf-addr-alignment
Renamed the dma-buf-alignment field to a more explicit
and descriptive name dma-buf-addr-alignment.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2022-11-23 15:36:31 -05:00
Wojciech Slenska 861f4f81c3 logging: log_backend_fs: added LOG_BACKEND_FS_AUTOSTART configuration
This configuration option gives the possibility to not enable
the fs backend on startup.
Backend can be enabled in runtime using log_backend_init and
log_backend_enable functions.
Implementation is based on log_backend_net.

Signed-off-by: Wojciech Slenska <wsl@trackunit.com>
2022-10-26 12:00:29 +02:00
Krzysztof Chruscinski af573dbffb logging: Add ipc_service log link
Added link that sends messages over ipc_service. It uses
log_link_remote and will talk to log_backend_ipc_service based
on log_link_backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Krzysztof Chruscinski b01867812e logging: Add ipc_service log backend
Added backend that sends messages over ipc_service. It uses
log_backend_remote and will talk to log_link_ipc_service based
on log_link_remote.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Krzysztof Chruscinski 6c785b5677 logging: Add remote link and backend
Added implementation of link and backend that are intended to
complement each other. Both requires transport function hooks
to be provided.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Krzysztof Chruscinski 050378ab39 logging: log_output: Adapt to multidomain support
Add support to multidomain case where source field contains
ID and not address of the source structure.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Krzysztof Chruscinski e322447109 logging: Initial multidomain support
Adding multidomain support by introducing log_link module which
acts as a receiver of log messages created by another domain.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Krzysztof Chruscinski 1b3a12ce8e logging: Add log_cache module for caching remote names
log_cache is capable of storing fixed length byte arrays
identified by a generic ID. If entry identified by given ID
is not found in cache, the least recently used entry is evicted
from cache.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-17 10:16:53 +02:00
Anas Nashif 46af0620b3 console: move winstream console to drivers/
This was all done as part of the soc and called from the soc. Define
this type of console under drivers/console and use it in the SoCs
supporting that via SYS_INIT instead of calling the console code
directly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-10-11 08:28:25 -04:00
Daniel Leung 90456c94f7 logging: workaround hard fault on Cortex-M0 with sys-t/catalog.
For some reason, running sys-t with catalog message on
Cortex-M0 would result in hard fault in mipi_catalog_formatter()
if log_output_syst.c is complied before the backends (and weird
enough, only with SIZE optimization). This new ordering was
introduced in commit f5587552bb
as it was to group all backend source files under a single
directory.

Workaround the issue by compiling file later after backends
as this issue is causing CI failures. Actual root-cause is TBD.

Relates #50941

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-10-10 18:02:08 +02:00
Krzysztof Chruscinski 02664dbc91 logging: Use cbprintf flags for log_printk
Use cbprintf flags also when creating log message for printk entry.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-08 18:32:57 +02:00
Krzysztof Chruscinski dc9c5fca4f logging: Add option LOG_MSG_APPEND_RO_STRING_LOC
Bring back Kconfig option which was previously removed by
9cd5086407 (previously named LOG_MSG_PKG_ALWAYS_ADD_RO_STRING_IDXS).
Renamed to shorten and be more descriptive. It can be useful for
external backends or frontends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-08 18:32:57 +02:00
Lucas Denefle 2efc9cc847 logging: enable setting custom logging output func
To enable custom formatting of the log output while still using existing
backend, this commit adds the `log_output_custom` feature.
To use, register a commit with `log_custom_output_msg_set` then set the
log backend format set using `log_backend_format_set` with
`LOG_OUTPUT_CUSTOM`

Signed-off-by: Lucas Denefle <lucas.denefle@converge.io>
2022-10-06 19:15:35 -04:00
Krzysztof Chruscinski e6bbc6941a logging: Use STRUCT_SECTION macros for log backend
Clean up logging code to utilize macros for handling sections.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-10-03 10:11:03 +02:00
Christopher Friedt f5587552bb logging: move backends to subdirectory
This is mainly to reduce clutter in `subsys/logging`, but also to make
backend management slightly easier.

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-10-01 03:34:48 -07:00
Krzysztof Chruscinski 4ece3406f5 logging: Add log_output dependency to mipi syst
Add missing dependency since log_output_syst.c is calling functions
from log_output module.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-19 14:15:17 +00:00
Krzysztof Chruscinski b097f5c5f8 logging: Use new cbprintf check for pointers
Cbprintf has new feature where it can distinguish between
character pointers used for %p and %s. It is enabled by
flag CBPRINTF_PACKAGE_CONVERT_PTR_CHECK.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-19 10:14:23 +00:00
Dennis Sitelew 42f9b69f50 logging: Fix signed integer cast for isprint
Casting the value byte to char may result in it being a negative
number. On some platforms this could lead to either UB, or a crash.

Signed-off-by: Dennis Sitelew <dennis.sitelew@grandcentrix.net>
2022-09-13 08:51:22 +00:00
Kai Vehmanen 6c71ddc2c6 logging: allow to select FORMAT_TIMESTAMP for ADSP_MTRACE backend
The CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP cannot be selected unless one of
the enumerated backends is selected. Add the ADSP_MTRACE backend to the
list, so timestamp formatting can be selected when only this backend is
enabled in the build.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2022-09-09 16:25:47 -04:00
Krzysztof Chruscinski b17823d063 logging: Allow use of log_output without subsystem
Allow using log_output without the logging subsystem. It can be
used in the situation where external messages are processed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-09 16:41:50 +00:00
Ryan Erickson 820fca76cc logging: fs backend: only delete old files if necessary
During initialization of the FS backed, the oldest
file is always deleted.
Fix this to prevent throwing away useful historic logs.
If there is space left in the newest file, append to it instead
of creating a new file and removing the oldest.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2022-09-09 10:04:24 +02:00
Tom Burdick 54474510b3 logging: adsp hda backend refinements and additional test
Additional testing showed that when using printk the logger would start
sticking and spitting out nulls which is wrong. This made it appear as if
the firmware had locked up. The issue seems to have been caused by the
initial ipc message to read all the dma buffers on the host.

Removing that, the issue seems to have been solved.

This also improves the test case to ensure printk with LOG_PRINTK=y
works as expected. It also adds a last log message between some
timeouts of the flush timer length to ensure the padding and timer
flush are working properly.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-09-07 20:27:44 -04:00
Kai Vehmanen eac6176961 logging: adsp_mtrace: fix handling of buffer full condition
If the mtrace buffer gets full, the entries are dropped. This
is however not reflected in the "bytes_written" argument passed
to the hook function used to notify of new data in the buffer.

This behaviour becomes problematic in the case there is no
active consumer of the mtrace logs. To allow the client that has
registered the hook function, to act correctly in this case,
the bytes_written should reflect the actual bytes that have been
added to buffer.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2022-09-06 17:43:08 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Krzysztof Chruscinski dbda37ddf0 logging: Add LOG_RAW macro
Add macro for logging raw formatted string. It is similar to
LOG_PRINTK macro but contrary to LOG_PRINTK it should not append
carriage return character to any new line character found in the
string. LOG_PRINTK processed by log_output module has that to
mimic printk behavior.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-05 06:26:54 -04:00
Krzysztof Chruscinski 89de6d19af logging: log_output: Use \r\n instead of \n\r for printk
Replace order to be compatible with printk and other logging outputs.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-09-05 06:18:17 -04:00
Andrey Borisovich 2e04bfdfe0 soc: intel_adsp: Refactored IPC/IDC
Changes to code:
1. Renamed CAVS_IPC API from common/include/cavs_ipc.h to
common/include/intel_adsp_ipc.h. Renamed all API functions and structs -
added "intel_adsp_" prefix.
2. Moved definitions from intel-ipc-regs.h and ace-ipc-regs.g to SOC
specific headers include/<soc_name>/adsp_ipc_regs.h.
3. Added new common intel_adsp_ipc_devtree.h header with new
macros to retrieve IPC and IDC nodes and register addresses.
Put those new macros in code replacing hardcoded values outside of
devicetree.
4. Changed documentation of IDC and renamed IDC register struct
to have common name between all intel adsp socs.
5. Removed excessive docs description on cAVS IPC protocol.

Changes to Devicetree:
1. Renamed in all CAVS boards .dtsi files content in IPC nodes:
   - "cavs_host_ipc" node labels to "adsp_ipc" labels.
   - compatible "intel,cavs-host-ipc" renamed to
     "intel,adsp-host-ipc".
2. Added (previously missing) yaml file for "intel,adsp-host-ipc"
   compatible.
3. Renamed in all CAVS boards .dtsi files content in IDC nodes:
   - "idc" node labels to "adsp_idc" labels.
   - compatible "intel,cavs-idc" renamed to "intel-adsp-idc"
4. Renamed intel,cavs_idc.yaml file to intel,adsp_idc.yaml
   so it is suitable for both CAVS and ACE SoC family.
   Moved it from ipm bindings to ipc bindings where it belongs.

Changes to Kconfig:
1. Renamed existing Kconfig option CONFIG_CAVS_IPC to
   INTEL_ADSP_IPC.
2. For renamed INTEL_ADSP_IPC addded default value based on
   status of the "adsp-ipc" and "adsp-ipc" node.

Signed-off-by: Andrey Borisovich <andrey.borisovich@intel.com>
2022-09-02 08:18:32 -04:00