Commit graph

180 commits

Author SHA1 Message Date
Krzysztof Chruscinski
f346af2c58 logging: Extend support for compilation with up to 31 arguments
Logging v2 supports 255 arguments but since logging v1 was supporting
only 15, and it is still compiled, more than 15 could not be used.
Extending logging v1 macro to accept up to 31 arguments. It will fail
during processing in case of v1 but will work with v2 enabled. It is
a temporary solution since v1 will be removed at some point.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-12-04 12:19:27 +01:00
Krzysztof Chruscinski
7831bfcce8 lib: os: cbprintf: Add flags to CBPRINTF_MUST_RUNTIME_PACKAGE
Add flags to macro which checks if string must be packaged
using runtime approach.

Added flag CBPRINTF_MUST_RUNTIME_PACKAGE_CONST_CHAR. When flag
is set then const char pointers are considered as pointers to
fixed strings and do not require runtime packaging.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-29 21:13:56 +01:00
Krzysztof Chruscinski
22d53f9152 logging: Add function for checking if there is pending data
Add function which can be used to check if there is any pending
data to process. It can be used to determine if deferred logging
has completed processing.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-20 11:58:40 -05:00
Krzysztof Chruscinski
c0808e3f59 logging: Minimal mode configuration cleanup
Remove LOG_MINIMAL kconfig option which was confusing
since LOG_MODE_MINIMAL existed. LOG_MINIMAL was used to
force minimal mode but because of invalid dependencies
it was leading to issues.

Refactored code to use LOG_MODE_MINIMAL everywhere and
renamed LOG_MINIMAL to LOG_DEFAULT_MINIMAL which has impact
on defualt logging mode (which still can be later changed
in conf file or in menuconfig).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-20 11:58:40 -05:00
Stefan Eicher
fbe7d7297e comments: minor typo fixes
Fixing minor typos in comments

Signed-off-by: Stefan Eicher <stefan.eicher@ypsomed.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-10-05 07:18:13 -04:00
Krzysztof Chruscinski
a18bc0f4f7 logging: Cleaning references to tracing in logging
There were some leftovers in logging after attempt to use
logging as tracing backend. Removing all references since it
lead to test compilation failures.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-09-29 14:59:36 +02:00
Krzysztof Chruscinski
abf8c741e4 logging: Prefix internal functions with z_
There are 2 function in log_internal that were not prefixed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-09-28 20:31:52 -04:00
Krzysztof Chruscinski
03165c914b logging: Cleanup in the internal headers
Added log_internal.h for internal APIs. Move functions out of
log_core.h. Log_core.h shall have only macros and functions related
to logging message creation. Log_core.h is included by log.h thus
number of dependencies in that headers must be limited to minimum
to allow including without risk of circular dependencies.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-09-28 20:31:52 -04:00
Krzysztof Chruscinski
ba60c94b48 lib: os: mpsc_pbuf: Add const qualifier to API calls
Add const qualifier where it was missing. Updating
relevant code.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-09-28 06:15:39 -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
Ryan Erickson
e4dc8ed26b logging: Add log mem shell command
Add log mem shell command to determine memory pool
usage of logging system.

Signed-off-by: Ryan Erickson <ryan.erickson@lairdconnect.com>
2021-08-12 11:06:32 -04:00
Andrew Hedin
b52ad8f3e1 logging: Add strdup current use to shell cmd
Add the number of strdup buffers currently in use to the
`log strdup_utilization` shell command.

Signed-off-by: Andrew Hedin <andrew.hedin@lairdconnect.com>
2021-08-12 11:06:32 -04:00
Krzysztof Chruscinski
6024bbc601 logging: Split log_core into two files
Extract functions which are managing logging sources
and backends into separate file: log_mgmt.

So far those functions were in log_core mixed with functions
specific to log message creation and log processing.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-07-30 19:58:13 -04:00
Krzysztof Chruscinski
5d80cbae59 lib: os: cbprintf: Add support for conversion to fsc package
Added support for conversion from a standard package which contains
pointers to read only strings to fully self-contained (fsc) package.
Fsc package contains all strings associated with the package thus
access to read only strings is not needed to format a string.

In order to allow conversion to fsc package, standard package must
contain locations of all string pointers within the package. Appending
that information is optional and is controlled by flags parameter
which was added to packaging API. If option flag is set then
package contains header, arguments, locations of read only strings and
transient strings (each prefixed with string argument location).
Package header has been extended with field which contains number of
read only string locations.

A function for conversion to fsc package has been added
(cbprintf_fsc_package()).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-07-27 14:50:45 +02:00
Krzysztof Chruscinski
81046088af logging: Remove code duplication from log_backend_std
log_backend_std_put had its own implementation for getting standard
flags which was identical to the one in log_backend_std_get_flags().

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-07-23 16:06:37 -04:00
Jan Pohanka
1064f6e09f logging: Eclipse CDT parser workaround
Recent rework in logging api brings complicated macros which can
overhelm Eclipse CDT parser.
This workaround disables expansion of LOG_xxx macros in Eclipse.

Signed-off-by: Jan Pohanka <xhpohanka@gmail.com>
2021-06-02 06:41:35 -05:00
Maksim Masalski
5a9e9e8fd1 logging: remove dead code enum
Remove dead code enum tracing_log_id
Not used anywhere in the code. Also it caused MISRA rule 8.12
violation.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2021-05-21 18:09:23 -04:00
Krzysztof Chruscinski
8ffc8ff267 logging: Add missing initialization of structure fields
C++ compiliation may generate warning if some fields are not
explicitly initialized. Added explicit initialization to 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-05-20 08:23:31 -05:00
Krzysztof Chruscinski
98ef609443 logging: Add empty Z_LOG_MSG2_SIMPLE_CREATE version
Add empty Z_LOG_MSG2_SIMPLE_CREATE when CONFIG_LOG_SPEED=n. It
allows to reduce compilation time by removing code at preprocessor
stage. Previously functionality was the same, compiler was removing
unused code but because logging is widely use that had a visible
impact on compile time.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-05-19 12:01:49 -05:00
Krzysztof Chruscinski
8152992a13 logging: Simplify runtime filtering
Simplified handling of runtime filtering that lead to removal
of LOG_CHECK_CTX_LVL_FILTER macro. Fixing multiply coverity issues
like CID 236013.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-05-13 22:08:44 -04:00
Krzysztof Chruscinski
d9518ce4cc logging: Add optional context argument to LOG_BACKEND_DEFINE
Extended LOG_BACKEND_DEFINE to support optional context argument.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-05-06 15:40:05 +02:00
Daniel Leung
a5ab1a7518 logging: add support for dictionary based logging
This adds dictionary based logging support. Dictionary based
logging is binary based where one big difference is that
static strings are stored as pointers instead of the whole
string. This results in reduced space requirements for
storing log messages in certain scenairos.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-04-28 22:25:42 +02:00
Krzysztof Chruscinski
2115964929 logging: Fix casting related C++ warnings
Fixed C++ warnings coming from implicit casting.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-27 08:48:03 -05:00
Krzysztof Chruscinski
1f3758ff9e logging: Macro cleanup to fix cpp warnings
Cleanup to fix warnings coming from c++ compilation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-27 08:48:03 -05:00
Krzysztof Chruscinski
afe87be841 logging: Add mising handling of function prefix
When printk is redirected to the logging it is using level 0.
Level 0 was missing a define used for detection of function
prefix use which lead to compilation failure when logging v2
was used with CONFIG_LOG_PRINTK=y.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-26 13:38:52 +02:00
Krzysztof Chruscinski
0365a6f852 logging: Fix UTIL_CAT misuse
Arguments for UTIL_CAT were accidentaly concatenated instead of passed
separated by comma.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-26 13:38:52 +02:00
Krzysztof Chruscinski
cf98ee776f logging: Tweaks to speed up compilation
Logging attempts to do most of the work at compile time instead
of preprocessor by using conditions which can be resolved at
compile time (e.g. if (IS_ENABLED(...))). Apparently, such extensive
use significantly loads the compiler since all paths are compiled
even though cut from final binary. Patch reduces it by replacing
some compile time switch with preprocessor.

Handling of function name prefix has been moved to preprocessor.
Immediate logging v2 has also been moved to preprocessor.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-22 15:29:15 -05:00
Marcin Niestroj
552028dd20 logging: add log_output_timestamp_to_us() helper function
So far we only have log_msg_timestamp_get() function, which returns
internal timestamp representation. This is either clock cycles or uptime
in ms, depending on main clock precision.

Introduce log_output_timestamp_to_us() helper function, which allows to
convert internal logging timestamp to us.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2021-04-20 18:21:26 -04:00
Krzysztof Chruscinski
963d60cec5 logging: Add LOG_PRINTK macro for printing via logging
Added macro which allows to print formatted string using
logging infrastructure.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Krzysztof Chruscinski
f1bb20f6b4 logging: Adapt logger to support both versions
Adapted to be able to switch between v1 and v2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Krzysztof Chruscinski
902ccd7235 logging: log_output: Extend to support log_msg2 parsing
Added parsing of log_msg2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Krzysztof Chruscinski
f6a40ae183 logging: Add logging v2 implementation for log_msg
Added implementation of log_msg2 which is creating log messages
using cbprintf packaging and storing them in circular ring buffer
(mpsg_pbuf).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Krzysztof Chruscinski
ba1aa75c66 logging: Refactor in preparation for logging v2
Refactor and cleanup in preparation for v2.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-19 10:59:23 -04:00
Anas Nashif
0ec3774bde userspace: rename _is_user_context -> k_is_user_context
This functions is being called across the tree, no reason why it should
not be a public API.

The current usage violates a few MISRA rules.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-01 05:34:17 -04:00
Anas Nashif
2976e12946 logging : do not reuse tag name log_output
Do not reuse tag name (misra rule 5.7).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 19:48:14 -04:00
Krzysztof Chruscinski
7e125fe7e4 logging: Add backend parameter to the init function
Added backend parameter to the backend init interface function.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-03-12 09:24:54 -05:00
Krzysztof Chruscinski
e0392c5a86 logging: Cleaning up log minimal
Removed printk.h include from log_core.h.

Since LOG_PRINTK cannot be enabled with LOG_MINIMAL removed
support for both.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-02-28 17:12:29 -05:00
Emil Lindqvist
a904330d4f logging: fix warnings when building with -Wunused-variable
Said warning comes when building with LOG_MODE_MINIMAL and
including logging/log.h. This commit adds ARG_UNUSED on
relevant variables.

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2021-02-04 07:43:07 -05:00
Fabio Utzig
8713da70a3 doc: fix @param usage in callbacks
The proper usage of @param in callbacks is currently unsupported by
Doxygen so not warnings are generated. The issues fixed with this commit
where found while adding support to Doxygen for validating @param in
callbacks like it currently does for functions.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-12-18 12:18:28 +01:00
Katsuhiro Suzuki
76b3a50e7f logging: add padding for RISC-V 64bits environment
This patch add padding in filter structure of log system.
In RISCV && 64BIT environment. Log system is facing alignment bug.

struct log_source_dynamic_data {
	uint32_t filters;
};

static inline uint32_t *log_dynamic_filters_get(uint32_t source_id)
{
	return &__log_dynamic_start[source_id].filters;
}

A sizeof(log_source_dynamic_data) = 4, address offset of
&__log_dynamic_start[] are:
  - &__log_dynamic_start[0]: +0
  - &__log_dynamic_start[1]: +4
  - &__log_dynamic_start[2]: +8

But RISCV 64bit gcc/ld places each log_dynamic_log, log_dynamic_os
and log_dynamic_test per 8bytes alignment. So address offset of
log_dynamic_* are:
  - &log_dynamic_log : +0
  - &log_dynamic_os  : +8
  - &log_dynamic_test: +16

tests/subsys/logging/log_core cannot set correct log filters in
RISCV && 64BIT environment, so test is always going to fail.

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
2020-11-19 12:46:35 -05:00
Emil Hammarstrom
746ba2dd9c logging: make log_backend_std header public
Exported header oftenly used when creating a logging
backend that inpects the log 'stream'.
Enables use in external Zephyr modules implementing the
logging backend interface.

Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
2020-10-21 10:21:05 -04:00
Jennifer Williams
5bda586c64 logging: fix if else if constructs missing final else
The logging subsytsem had if else if constructs without final
else statement. This commit adds else {} to comply with
coding guideline 15.7.

Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
2020-10-07 23:05:18 -07:00
Torstein Grindvik
84cdc6fd92 logging: Refactoring macro to avoid Coverity issue
Change a runtime log check such that Coverity does not report a
needless issue on every use of any log macro.

Before the change, this was used in log macros:

    else if(is_user_context || (_level <= LOG_RUNTIME_FILTER(_filter)))

If runtime filtering is not enabled, this expands to:

    else if(is_user_context || 1)

Because the level is compared to log level debug (4) and will always be,
equal or lower.
Coverity always reports this as a potential issue, since the
variable part (is_user_context) makes no difference.

After the change, a macro is used which expands into the original code
when runtime filtering is used, else it simply expands to:

    else if(true)

Which has equal semantics as the previous code but isn't flagged by
Coverity.

Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
2020-10-04 14:45:45 -07:00
Aastha Grover
83b9f69755 code-guideline: Fixing code violation 10.4 Rule
Both operands of an operator in the arithmetic conversions
performed shall have the same essential type category.

Changes are related to converting the integer constants to the
unsigned integer constants

Signed-off-by: Aastha Grover <aastha.grover@intel.com>
2020-10-01 17:13:29 -04:00
Daniel Leung
79b044b61b logging: move _is_user_context() check down one level
MISRA-C Directive 4.7 says that error information returned from
a function needs to be tested. In the logging macros,
return from _is_user_context() is not needed until logging is
enabled and above minimal logging level. There is a potential
that the return is not being used at all. So move it one level
below as it is surely being used within the if block.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-08-06 08:59:33 -04:00
Krzysztof Chruscinski
2809cad50e logging: Add fields initialization in z_log_msg_std_alloc
Added initialization of ids fields in the log message in
z_log_msg_std_alloc(). If user space is enabled then msg_free()
function is reading log level and previously it may have been
uninitialized.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-07-09 13:46:07 +02:00
Krzysztof Chruscinski
b8781e27b0 sys: util: Deprecate GET_ARGS_LESS_1 macro
GET_ARGS_LESS_N must be used instead.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-22 15:18:07 +02:00
Krzysztof Chruscinski
dd9da9c8c4 sys: util: Deprecate GET_ARG2 macro
GET_ARG_N should be used instead.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-22 15:18:07 +02:00
Krzysztof Chruscinski
0afb3445a5 sys: util: Deprecate GET_ARG1 macro
GET_ARG_N(1,...) can be used instead.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-22 15:18:07 +02:00
Tomasz Konieczny
c73578f37a logging: enhanced external logsystems
Introduced interface for efficient logging from external logsystems:
Added handling of vaargs and automatic strdup to macros intended
to be used in logging interface function. Fast path to less then 4
arguments to speed up the execution. Made log_count_args external,
if external logsystem cannot count arguments.

Signed-off-by: Tomasz Konieczny <tomasz.konieczny@nordicsemi.no>
2020-06-17 17:08:12 +02:00