Commit graph

34 commits

Author SHA1 Message Date
Tom Hughes
15411747e7 everywhere: Use correct macro for gcc-specific warnings
Many warnings were disabled for all compilers, even though they are
gcc-specific warnings. Now that clang has -Wunknown-warning-option
enabled, this can cause compilation failures when building with clang
toolchains.

Use TOOLCHAIN_DISABLE_GCC_WARNING for all gcc-specific macros.

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
https://clang.llvm.org/docs/DiagnosticsReference.html

Fixes: #84138

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-20 21:57:47 +01:00
Tom Hughes
11d70c61e5 everywhere: Replace diagnostic pragmas with TOOLCHAIN_* macros
The TOOLCHAIN_DISABLE_WARNING/TOOLCHAIN_ENABLE_WARNING macros are easier
to read and compiler agnostic.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-20 21:57:47 +01:00
Dong Wang
872f363696 logging: Ensure atomic update of log filter slot in LOG_FILTER_SLOT_SET
Replaced the read-modify-write sequence with a single read and write
operation, preventing the intermediate value is wrongly used to filter
out logs of another thread with higher priority that preempts the current
thread.

Signed-off-by: Dong Wang <dong.d.wang@intel.com>
2025-03-18 16:42:18 +01:00
Sebastian Huber
cd0a20d1a9 logging: Fix set but not used warning
Fix this warning:

zephyr/logging/log_core.h:356:21: \
warning: variable 'mode' set but not used [-Wunused-but-set-variable]
  356 |                 int mode; \
      |                     ^~~~

Use the same approach as in Z_LOG2().

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2025-01-17 06:43:18 +01:00
Krzysztof Chruściński
835dd0b83e logging: Refactor filtering macros
Create a macro that encapsulates all filtering and use it in standard
and hexdump macros.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-15 04:09:04 -04:00
Krzysztof Chruściński
6adfd4ba89 logging: Minor cleanup in logging helper macros
Change logging level definitions to just numbers instead of
numbers with unsigned indicator (e.g. 1 instead of 1U). Levels
from Kconfig comes as just numbers and often levels are used
for IS_ENABLED-type of macros where values are concatenated
into tokens and it actually makes the difference if value is
1 or 1U. It allows minor cleanup in the internal macros.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-15 04:09:04 -04:00
Krzysztof Chruściński
8fc0aba4ae logging: Add log_source_id helper function
There are many places where source_id is retrieved and it
depends on runtime filtering being enabled. So far it was
all exposed but lets encapsulate that into a helper function.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-08 16:57:59 +02:00
Krzysztof Chruściński
347eeababf logging: Fix runtime filtering when frontend and userspace is used
When userspace is used and frontend was used for logging then runtime
filtering was failing because in user context filtering data was
accessed and filtering data is in the kernel space. Fixing that and
adding runtime filtering to the pre frontend function which is
already executed in the kernel space and filter data can be
accessed.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-07-09 14:01:56 +02:00
frei tycho
f299516e01 include: logging: added missing parenthesis
- added missing parenthesis around macro argument expansion

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-27 15:16:17 -04:00
Christoph Schnetzler
239c20d2c7 logging: use #ifdef instead of #if
use #ifdef to avoid to use undefined macros in #if expressions

Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
2024-06-17 15:29:39 +02:00
Christoph Schnetzler
3c9e05959b logging: cmsis: prevent wundef warnings
If -Werror is used compilation fails due to wundef warning.

Signed-off-by: Christoph Schnetzler <christoph.schnetzler@husqvarnagroup.com>
2024-06-17 15:29:39 +02:00
Christopher Friedt
2155a9e5f7 logging: rename log2_generic to log_generic
The log2 prefix was deprecated and changed to log some time ago,
but log2_generic() seems to have been inadvertantly left with
the old prefix.

Rename log2_generic() to log_generic() to follow suit.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2024-02-14 19:07:30 +01:00
Krzysztof Chruściński
b819b51fe7 logging: Add support for runtime filtering in frontend
So far frontend supported only compile time filtering. Adding
support for runtime filtering. From runtime filtering perspective
frontend is treated similar to any other backend but since
it is a singleton it has fixed ID.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-01-15 09:57:54 +01:00
Krzysztof Chruściński
465446e5aa logging: Add string validation to detect %p misuse
Logging shall not use character pointers with %p because in
certain configurations it may lead to memory faults. A compile
time detection is added. If faulty usage is detected then
message is replaced with error message which indicates which
message failed and what shall be done (casting to a pointer
of different type).

Validation is enabled only for configurations which remove
strings from binary as otherwise it may impact CI execution
time.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-11-24 09:23:18 +01: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
94e5311215 logging: Fix logical operator use
Replace & with &&. In that case there is no difference in the
behavior but logical operator should be used here.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-20 15:20:52 +02:00
Krzysztof Chruściński
a52e92a148 Revert "logging: Fix case when LOG_LEVEL is 0"
This reverts commit bd428663e9.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-09-29 09:48:57 +02:00
Krzysztof Chruściński
5191444316 logging: Minor improvement in instance logging
When using instance logging (e.g. LOG_INST_INF) first argument is
a pointer to the logging object associated with an instance. It is
not used if logging is disabled and that can generate 'unused
variable' warning when logging is disabled.

Previously logging object was not created when logging was disabled
That was done to save memory but because of that object could not be
referenced when logging was disabled. Better approach is to create
empty array instead of a logging object. It does not increase memory
usage but can be referenced and potential compilation warning is
suppressed.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-09-12 17:23:31 +01:00
Krzysztof Chruscinski
9bf333aa8d logging: Fix user space crash when runtime filtering is on
Logging module data (including filters) are not accessible by
the user space. Macro for creating logs where creating local
variable with filters before checking is we are in the user
context. It was not used in that case but creating variable
was violating access writes that resulted in failure.

Removing variable creation and using filters directly in the
if clause but after checking condition that it is not the
user context. With this approach data is accessed only in
the kernel mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-05-16 20:15:06 -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
Guennadi Liakhovetski
a0a0739992 log: fix a harmless bug
Z_LOG2() has a typo, confusing & with &&. The result is the same but
using && is more logical in that case and it eliminates a flood of

warning: dubious: x & !y

static analyser warnings. Also compare to 0 explicitly to fix a
coding style violation.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-04-20 10:52:18 +02:00
Krzysztof Chruscinski
f167e5c9b4 logging: Fix LOG_RAW failing when logging is disabled
Macro was not taking into account case when logging was disabled
and it was failing to link in that case.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2023-04-17 22:24:08 -04: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
Krzysztof Chruscinski
bd428663e9 logging: Fix case when LOG_LEVEL is 0
Setting LOG_LEVEL to 0 was not covered. It resulted in the
logging misbehavior when module logging level was set using
LOG_LEVEL define method and it was set to 0. Instead of
filtering all levels it was applying the default filtering.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-12-09 09:46:11 -05: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
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
Gerson Fernando Budke
09cad20b48 logging/log_core.h: Fix unused variable diagnose
The current _mode variable can be diagnosed as unused by tools like
clang-tidy-14. This add a small fix to by pass this situation and allow
run analysis tool without this warning/error.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2022-08-24 10:06:53 +02:00
Gerard Marull-Paretas
a7c3e7e84a doxygen: remove redundant usages of def
The def command Indicates that a comment block contains documentation
for a #define macro. This is useful if the comment block documents a
macro not adjacent to it, e.g.

```c
/**
 * @def MAX(x,y)
 * @brief Computes the maximum of @a x and @a y.
 */
 #ifdef XXX
 #define MAX(x,y) ...
 #endif
```

However, it is not necessary if the comment is adjacent to the
definition, e.g.

```c
/**
 * @brief Computes the maximum of @a x and @a y.
 */
 #define MAX(x,y) ...
```

This patch removes all unnecessary def entries in-tree.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-09 12:29:28 +02:00
Krzysztof Chruscinski
9833ca61c9 logging: Removing v2 suffix from logging names
Renaming objects which had 2 in the name to indicate that
it is v2 specific. Once logging v1 has been removed such
suffixes are redundant.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 15:46:37 -04:00
Krzysztof Chruscinski
7f1b4f88e3 logging: Rename files and test from log_msg2 to log_msg
Renaming log_msg2 files to log_msg.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-23 09:10:33 +02:00
Krzysztof Chruscinski
c5f2cdef09 logging: Remove logging v1 from the logging
Remove v1 implementation from log_core and all references in the tree.
Remove modules used by v1: log_list and log_msg.
Remove Kconfig v1 specific options.
Remove Kconfig flags used for distinction between v1 and v2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-06-16 10:51:15 -04:00
Gerard Marull-Paretas
fb9b3bcd93 include: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all includes within
include directory 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-06 20:03:00 +02:00
Yuval Peress
53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Renamed from include/logging/log_core.h (Browse further)