Commit graph

621 commits

Author SHA1 Message Date
Krzysztof Chruscinski 960041bfa5 logging: Duplicate only strings from rw memory
If argument for log_strdup is from ro memory then there is
no point to duplicate it. This may happen if function logs
variables coming from outside, e.g. function argument.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-06-07 12:05:31 -04:00
Krzysztof Chruscinski a211afb041 logging: Add option to detect missed transient string duplication
Added CONFIG_LOG_DETECT_MISSED_STRDUP (by default on) which enables
scanning of log message strings in search for %s and reports if
string address is not from strdup buffer pool and outside read only
memory section which indicates that log_strdup() wrapping is missing

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-05-29 13:52:31 +02:00
Luiz Augusto von Dentz ad769e9c04 Log: Fix build error on Fedora 30
Fedora 30 uses GCC 9.1 which fails to build when loggin is enabled:

zephyr/subsys/logging/log_core.c: In function ‘log_is_strdup’:
zephyr/subsys/logging/log_core.c:665:22:
warning: array subscript -1 is outside array bounds of
‘u8_t[]’ [-Warray-bounds]
  665 |         ((char *)buf <= pool_last->buf);
      |                      ^~
zephyr/subsys/logging/log_core.c:52:3:
note: while referencing ‘log_strdup_pool_buf’
   52 |   log_strdup_pool_buf[LOG_STRDUP_POOL_BUFFER_SIZE];

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2019-05-27 11:42:07 -04:00
Krzysztof Chruscinski 04a5cee556 logging: Add string duplicates pool profiling
Added option profiling instrumentation which can help determine
string duplicates pool configuration. Added shell command to
read current peak utilization of the pool.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-05-27 10:18:10 +02:00
Krzysztof Chruscinski f35b854345 logging: Fix RTT backend drop mode and coverity issue
Drop mode in RTT backend was broken. It is not the default
one so most likely it was unnoticed for a long time. Fixed
to report drop message when logs are lost.

Additionally, added assert to ensure that memmove does not
do memory overwrite.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-04-12 08:38:16 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Piotr Mienkowski 7a9c1f101d logging: Add support for new 'in place' mode to SWO backend
Extended SWO backend to support new backend API for 'in place'
mode.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-04-03 10:46:57 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Ulf Magnusson 7ccc7889fa logging: Remove SYS_LOG implementation
Replaced by the new CONFIG_LOG system.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-28 09:30:29 -04:00
Ulf Magnusson 0eb6ffa3e9 logging: kconfig: Remove legacy SYS_LOG symbols
Replaced by the new CONFIG_LOG system.

Also remove the "Logging Options" menu and turn the LOG symbol into a
'menuconfig', with prompt "Logging", which appears in the top menu. LOG
and its dependent symbols make up all of the logging Kconfig symbols
now.

Piggyback some minor cleanup.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-28 09:30:29 -04:00
Krzysztof Chruscinski aa0c417e38 logging: defines clean up
RTT backend supports two modes blocking and drop. Apparently,
defines used lead to warning while clang compilation. Define
that caused warning has been changed together with clean up
which removed #ifdefs for definitions.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-26 13:55:59 -05:00
Ulf Magnusson 047868f84a log: net: Fix CONFIG_LOG_IMMEDIATE typo in comment
CONFIG_LOG_IMMEDIATE_MODE doesn't exist, only CONFIG_LOG_IMMEDIATE.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-26 07:45:20 -05:00
Jukka Rissanen 3f34fead60 log: net: Fix the immediate logging mode in network backend
If CONFIG_LOG_IMMEDIATE is enabled, then we need to handle
the output strings using a different output function.
The issue was noticed with native_posix board where no syslog
output strings were sent to network.

Fixes #14661

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-03-20 11:38:29 -05:00
Tomasz Bursztyka 03bfc5dd0f net/context: Remove token parameter from net_context_send/sendto
And also to the relevant callbacks.

That parameter is not used anywhere so it is useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Tomasz Bursztyka 172fe5a87b net/context: Remove _new suffix on net_context_send/sendto functions
Now that legacy functions are removew, let's rename the new functions by
removing the _new suffix.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-20 10:27:14 -05:00
Krzysztof Chruscinski 94ae61f765 logging: Force LOG_PRINTK option if RTT backend is used
Log RTT backed is using mutex for locking access to RTT data.
RTT console (which by default is used by printk) writes to
RTT data directly and it cannot use mutex because it can be
called from any context (including interrupt). If both
modules access RTT buffer 0, data can be corrupted.

This patch forces LOG_PRINTK option if RTT backend is used to
ensure single point of access to RTT buffer 0 data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-19 12:15:50 -05:00
Krzysztof Chruscinski d915fa0c35 logging: rtt: Fix backend behavior when LOG_IMMEDIATE enabled
Backend was not initialized to work in synchronous mode if LOG_IMMEDIATE
was enabled. That causes use of rtt_lock which uses mutex. That lead to
assert in application.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-18 11:28:50 -05:00
Krzysztof Chruscinski 0e72962a77 logging: replace assert calls with __ASSERT_NO_MSG
File was using not recommended assert call.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-18 11:28:50 -05:00
Kumar Gala cb3fe3cc46 logging: Workaround build warning with clang
when building with clang we get the following warning:

log_core.c:358:40: error: use of logical '&&' with constant operand
[-Werror,-Wconstant-logical-operand]

This is because we are mix a constant IS_ENABLED(CONFIG_LOG_IMMEDIATE)
with non-constants.

Split out the check into its own statement to workaround the warning.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-15 06:42:25 -05:00
Tomasz Bursztyka 01d41f25b7 logging: Switch to new net_pkt/net_context API
Let's still use local pool for a buffer to avoid using stack.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2019-03-11 20:56:44 -07:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Krzysztof Chruscinski cae3c28a96 logging: Fix RTT log backend lagging if no host
In case it was detected that RTT host was not present
backend was still performing single sleep or busy wait
round before dropping data. That was degrading log
processing performance.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-07 13:06:52 +01:00
Krzysztof Chruscinski fb4f5e727b logging: Use k_uptime_get_32 for high frequency system clock
If system clock runs fast k_cycle_get_32(), which is the timestamp
source, wraps often (few minutes). This patch changes default
timestamp function to use k_uptime_get_32() if system clock
frequency is higher than 1 MHz and k_cycle_get_32() otherwise.

If system clock runs at 1 MHz, counter will wrap every 71.5 minutes.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-06 16:11:23 +01:00
Krzysztof Chruscinski 987586d914 logging: Use vprintk for string formatting by default
Previously, _prf function was used when present and _vprintk
was used otherwise. _prf supports reacher formatting but at
cost of 3k flash and >250 bytes on stack. Stack usage then
depended on which function was used and that was causing
troubles when trimming stack sizes.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-05 08:24:50 -05:00
Krzysztof Chruscinski ba991c3be1 logging: Add assert when no backends defined
Added an assert in the logger thread in case there
is no backends, instead of having that thread spinning
forever. Disabled log in qemu_xtensa board due to lack
of backends.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-04 11:47:34 -05:00
Anas Nashif 5cf49956e7 logging: add backend for xtensa simulator
Add backend for the xtensa simulator.

Fixes #10164

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-04 10:35:07 -05:00
Krzysztof Chruscinski e64cd5c74d logging: Fix silent logs dropping when LOG_MODE_OVERFLOW disabled
There was no notification about dropped logs When logger operated
in the mode where message is dropped when logger has no space to
store the message. Notification was printed only if logger operated
in the mode which overwrites oldest log.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-27 08:32:14 -06:00
Ulf Magnusson 9aab5cef96 kconfig: Remove redundant 'default n' properties
Some more were added since the cleanup pass in June 2018. See e.g.
commit 2d50da70a1 ("drivers: ipm: Kconfig: Remove redundant 'default n'
properties") for a motivation. It also avoids people wondering whether
or not they need to put in 'default n'.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-27 09:25:22 +01:00
Krzysztof Chruscinski a64b0fe1e3 shell: Deprecate macros for subcommands creation
Macros are replaced by C++ friendly versions:
- SHELL_CREATE_STATIC_SUBCMD_SET by SHELL_STATIC_SUBCMD_SET_CREATE
- SHELL_CREATE_DYNAMIC_CMD by SHELL_DYNAMIC_CMD_CREATE

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Krzysztof Chruscinski 3605e48c44 shell: Modify subcommands to use SHELL_STATIC_SUBCMD_SET_CREATE
It is planned to deprecate SHELL_CREATE_STATIC_SUBCMD_SET macro
which is replaced by SHELL_STATIC_SUBCMD_SET_CREATE.

Additionally, removed irrelevant comments about alphabetical
ordering which is no longer needed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-20 07:31:35 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Krzysztof Chruscinski f81346cbd9 logging: Set panic_mode flag after flushing in log_panic
In case log_panic is called from context which can be
interrupted, it is safer to set panic_mode flag after
logs are flushed. If flag was set before flushing and
log_panic was interrupted then another context was
attempting to process log message directly, competing
for log backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-11 11:40:13 -06:00
Anas Nashif 239805b2d8 logger: xtensa: increase logger stack
Crashes observed with default logger stack. Xtensa usually needs more
thread stack.

Fixes #12201

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-11 08:48:58 -05:00
Sebastian Bøe d5afe27207 logging: Increase log processing stack size when NO_OPTIMIZATIONS
When optimizations are disabled more RAM is used and we get a stack
overflow on CONFIG_LOG_PROCESS_THREAD_STACK_SIZE. To rectify this,
increase the stack size when CONFIG_NO_OPTIMIZATIONS.

This does not scale well, and will have to be replaced by a a more
general solution eventually, but in the mean time it follows the
existing best practice established by the GCOV infrastructure in
commit e908ea9aa5

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-07 11:16:59 -06:00
Michael Scott d646eff3d3 logging: introduce LOG_DISABLE_FANCY_OUTPUT_FORMATTING to save flash
The new Logger subsys uses a very robust formatter function in minimal
libc: _prf().  This adds up to ~3K flash.  For resource constrained
devices running samples that don't use the extra formatting options,
allow them to select LOG_DISABLE_FANCY_OUTPUT_FORMATTING to revert
back to vprintk.

MCUBOOT is one such sample that has a very limited amount of output
and benefits from the flash savings due to small bootloader partition
sizes.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-04 08:04:38 -05:00
Krzysztof Chruscinski a0904ff86a logging: Handle panic occuring before log initialization
Log backends (marked as autostart) are initialized late. By default
in logger thread which has the lowest priority. If log_panic() occurs
earlier no logs is printed because there is no backend enabled.

This patch fixes it by adding log_init() call to log_panic(). Log_init()
can be called multiple times.

This patch ensures that logs are printed if early panic occurs if
backend is configured to auto-start. This is not the case if shell
is acting as log backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 23:26:13 +01:00
Krzysztof Chruscinski eac2f7c763 logging: log_backend_rtt: Fix panic behavior when no host
RTT log backend was locking in panic if host absense was not yet
detected (early panic). It is fixed by adding detection of host
absense while pending on data being read by the host.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-30 08:21:04 -05:00
Krzysztof Chruscinski 790fdb9ebd logging: Add support for new 'in place' mode to native posix backend
Extended native posix backend to support new backend API for
'in place' mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 8e9cc62e7a logging: Add support for new 'in place' mode to RTT backend
Extended RTT backend to support new backend API for 'in place' mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 71697969c7 logging: Add support for new 'in place' mode to UART backend
Extended UART backend to support new backend API for 'in place'
mode.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 08e5103105 logging: Extend log_output to support raw data
Added functions for processing log string and hexdump. Details
are passed as function parameters and not as log_msg. Those
functions can be used when logger works in  synchronous mode
and log messages are not created.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 1d9e5ee108 logging: Refactoring 'in place' mode to reduce memory footprint
Changed 'in place' mode to bypass logger system and directly
call active backends. With this approach memory footprint of
the logger can be significantly reduced in terms of RAM and ROM.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 880bfb37c0 logging: Fix reporting of dropped logs before backend init
Dropped logs were not counted if logger has no backend
attached (system startup phase).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-24 08:39:29 -05:00
Adithya Baglody e908ea9aa5 logging: Increase the stack size when coverage is enabled.
This prevents the stack overflow which is caused by gcov.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05:00
Krzysztof Chruscinski 4e32721135 logging: Add buffer flushing on entering panic
It may happen that panic occured while logger backend
was formatting output data. In that case output buffer
could get corrupted as logger assumes that processing
happens in one context only (panic is the only exception).

Added log output buffer flushing on entering panic state.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-10 07:27:14 -05:00
Piotr Mienkowski 03eaafddfd logger: add a SWO backend
This commit adds Serial Wire Output (SWO) logger backend. SWO is an
extension of Serial Wire Debug (SWD) port developed by ARM.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-01-09 15:30:59 +01:00
Flavio Ceolin f342019986 log: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-01-07 08:52:07 -05:00
Flavio Ceolin 1036edcfbb log: Fix switch statement
MISRA-C has several rules about switch statements like each clause
end with an unconditional break. This commit fix these problems to
be in accordance with the standard.

MISRA-C rules 16.1, 16.3 and 16.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-21 21:06:18 +01:00
Krzysztof Chruscinski 1cc9e98ae6 logging: Refactor RTT backend to handle host absence
Refactored blocking operation of RTT backend. Log_output buffer
is used directly in case of blocking operation. Detection of
host presence added. Prevent use of RTT lock when in panic mode.
Removed pending on data being read by the host on every message.

Refactor gives savings of 300 bytes in ROM and 120 bytes in RAM.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-19 14:53:48 +01:00
Flavio Ceolin 27435e4cb3 log: Explicitly ignoring return of memcpy
According with MISRA-C the value returned by a non-void function has
to be used. As memcpy return is almost useless, we are explicitly
ignoring it.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-19 14:37:25 +01:00
Krzysztof Chruscinski fcc7240fbe logging: Add handling of dropped messages to native POSIX backend
Extended native POSIX backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 31a90ca592 logging: Add handling of dropped messages to RTT backend
Extend RTT backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 1edf09e17a logging: Add handling of dropped messages to UART backend
Extend UART backend to handle dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski a7568e4a6a logging: Handle dropped messages in log_output
Extended log_output interface to handle dropped
messages. Log_output is printing a message containing
number of dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 0899a6c0b7 logging: severity-wise filtering of function name prefix presence
Extended logger configuration to allow function name prefix for
messages with certain severity levels. By default only debug
messages are prefixed with function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Krzysztof Chruscinski aa19fd9298 logging: Fix allocation of single chunk log messages
Generic log message allocator was wrongly allocating single
chunk messages as initially it was intended to allocate only
multichunk messages. It resulted in invalid pointer being freed
on log message free. Issue detected by valgrind.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 12:46:29 +01:00
Jukka Rissanen 86689030e8 net: Clarify logging in networking code
Remove network specific default and max log level setting
and start to use the zephyr logging values for those.

Remove LOG_MODULE_REGISTER() from net_core.h and place the
calls into .c files. This is done in order to avoid weird
compiler errors in some cases and to make the code look similar
as other subsystems.

Fixes #11343
Fixes #11659

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-07 12:00:04 +02:00
Jakub Rzeszutko 3064ca4f2f shell: creating new module for help functionality
1. Created new shell module: shell_help.
2. Simplified command handlers with new shell print macros.
3. Removed help functions from command handlers.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko e0be6a10b3 shell: printing command's help by shell engine
Removed printing command help from help handler. It is now
realized by the shell engine. This change saves a lot of flash
but still allows to print help in command handler with function
shell_help_print.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Jakub Rzeszutko 5451ff2848 shell: remove "options" concept
Removing help "options" from shell API.

Currently SHELL_OPT macro is not used by users. What is more
commit: a89690d10f ignores possible options created in
command handler by the user. As a result they are not printed
in help message.

Second, currntly implemented "options" in command handlers options are
implemented without SHELL_OPT macro.

And last but not least this change will allow to implement
help handler in a way that user will not need to think about calling
functions printing help in a command handler.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-12-05 15:15:44 +01:00
Pawel Dunaj e344e5752c ext: debug: segger: Fix SEGGER header inclusion
Fix issue caused by 3fc497ac9a

This change removes `rtt` and `systemview` from header includes
as these are already placed in the path.

Also `SEGGER_SYSVIEW_ConfDefaults.h` header included from
`SEGGER_SYSVIEW_Int.h` is placed higher to make sure `INLINE`
definition is properly visible.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2018-12-05 14:35:42 +01:00
Krzysztof Chruscinski 7c68befb15 logging: Fix initial log level in shell
Shell log backends were initialized from shell context. After
lowering logger thread priority order has been flipped. That
revealed a bug where shell logger backend was enabled before
backend ID's has been assigned during logger initialization.

ID assignment is moved to log backend enabling function making
it independent of order of initialization.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-05 14:35:33 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Jukka Rissanen 44a9bb6abe logging: Add network backend
Allow logging subsystem to send the logging messages to outside
system. This backend implements RFC 5424 (syslog protocol) and
RFC 5426 (syslog over UDP).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Krzysztof Chruscinski 0c24e62f2c logging: Fix log_core initialization
Timestamp function and pool for log_strdup were initialized
in log thread initialization while they should be initialized
in log_core_init() which is performed earliest possible. Log
API was using uninitialized data when called before log thread
was started.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-04 15:05:18 +01:00
Krzysztof Chruscinski a211c42a29 logging: Add dropped messages notification to backends
Extended backend interface to allow notifying backend
that log messages has been dropped due to insufficient
internal buffer size. Notification contains number of
log messages dropped since last notification. It
is optional for a backend to implement handler.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-03 14:22:42 -08:00
Krzysztof Chruscinski 65b5e86c52 logging: Fix RTT backend being enabled with shell RTT
If USE_SEGGER_RTT option was enabled then LOG_BACKEND_RTT was
enabled by default. In case shell RTT was also used then both
write to RTT. Updated Kconfig to prevent such situation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-03 11:55:33 +01:00
Krzysztof Chruscinski 4d94257162 logging: Make logging thread priority fixed
Removed kconfig option for setting logging thread priority
and fix it to K_LOWEST_APPLICATION_THREAD_PRIO.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-30 10:59:02 -08:00
Paul Sokolovsky 226ff48384 logging: Elaborate description of CONFIG_LOG_STRDUP_BUF_COUNT
Description is improved, guidelines for when increase is required are
provided, together with associated overheads information.

Fixes: #11007

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:04:33 -08:00
Paul Sokolovsky 600a2340f2 logging: log_core: Clarify message when log_strdup failed allocation
Don't say that pool is empty, say that allocation failed, because
that's what happened (because the pool is full apparently).

Partially addresses #11007.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-30 08:04:33 -08:00
Tavish Naruka 68a14eda15 log: Don't enable LOG_CMDS if SHELL is disabled
This was preventing compilation due to undefined
symbols like 'shell_fprintf' etc.

Signed-off-by: Tavish Naruka <tavishnaruka@gmail.com>
2018-11-30 08:01:39 -08:00
Flavio Ceolin c16b1d08df misra: Ignoring the return atomic_set when not used
The function atomic_set return the previous value of the
target. Sometimes this value is irrelevant, e.g when initializing a
variable.

As MISRA-C rule 17.7 requires that the value returned by a non-void
function must be used, we have to explicitly ignore some cases.

MISRA-C rule 17.7

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 10:18:59 -08:00
Krzysztof Chruscinski 2d6a226b2e logging: Fix lost printk output when no newline
Log_output module was always postfixing printk strings
with '\r'. If printk message did not ended with '\n'
it lead to last printk message being overwritten.

Fixed by adding '\r' only when string was ended by '\n'.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-22 19:18:41 -05:00
Krzysztof Chruscinski e85986e153 logging: refactor log_filter_set to set existing log level
Modified log_filter_set function to limit level if requested
level is not compiled in. Additionally, extended function to
return actually set level. Removed redundant code from log_cmds.

Change fixes shell log backend initialization which was setting
log levels without taking into account compiled in limits.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-20 08:43:34 -05:00
Flavio Ceolin c554ab7100 subsys: logging: Fix invalid memory access
Coverity-CID: 189512

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-20 11:14:31 +01:00
Pavel Kral 47f529829f logger: fix missing macro in RTT backend, when blocking mode is selected
This simple patch fix compiler error when RTT blocking mode is selected.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-11-13 09:27:37 -05:00
Krzysztof Chruscinski 6d1a31b3fc logging: Add uart backend dependency to shell uart backend
If shell UART backend was enabled and logger uart backend was
not explicitly disabled then both were used resulting in logs
being printed twice on terminal.

Patch modifies default state of log uart backend to depend on
state of shell uart backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-13 09:17:05 -05:00
Michael Scott 6575e84002 logging: start log processing thread in enable_logger()
Currently, if CONFIG_LOG_PROCESS_THREAD is enabled, log processing
does not start until just before the main() function is called in
the user sample.  This means that no real-time logging information
will be sent to the backends while drivers and/or other processes
which are triggered during kernel boot are processing their tasks.
Worse, if they take a longish time to finish, the user is
presented with a blank log backend regardless of the debug levels.

Let's start processing logs earlier to avoid this issue.

NOTE: Since this thread is now triggered specifically rather than
started during static thread init, let's also name it.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-11-07 14:39:55 +02:00
Flavio Ceolin 3ced176088 subsys: logging: Fix switch statement
According with MISRA-C and unconditional break statement must
terminate every switch-clause.

MISRA-C rule 16.1 and 16.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-06 16:20:15 -05:00
David B. Kinder ee47f7fb7a doc: fix kconfig misspellings
Fix misspellings in Kconfig files that show up in the configuration
documentation (and make menuconfig screens).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-11-02 17:58:16 -04:00
Anas Nashif 0ab6da1e03 logging: make LOG_LEVEL depend on LOG
We are getting all of those Kconfigs related to logging even without
having logging enabled, make the variables depend on LOG for all users
of the template.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-02 15:31:44 -05:00
Pavel Kral e781997450 logger: rtt backend don't let starve others in blocking mode
When a RTT logger backend is configured to blocks, allow other threads
to continue during waiting for data to be transferred to host.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-11-02 12:24:05 -04:00
Krzysztof Chruscinski 62d011549a logging: Support for up to 15 arguments in log message
Extended support in the log_core and log_output to 15 arguments
which is the hard limitation of log message format.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 12:22:01 -04:00
Krzysztof Chruscinski 4213dbb2e6 logging: add arguments counting in log_generic
Log_generic() can be used by external logger systems to map to zephyr
logger subsystem. Function has variable number of arguments. So far
logger assumed maximal number of arguments to avoid scanning
string to count number of arguments. In outcome, uninitialized memory
was treated as valid argument in a message (but discarded when actual
string formatting took place). Valgrind complained about that so
log_generic() has been extended to scan the string and count number
of arguments and build message with valid number of arguments.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-31 14:32:21 +01:00
Pavel Kral a19726ee1e logger: console: init rtt only once
As RTT is used by more subsystem in Zephyr, initialization is moved
from RTT console and RTT logger backend to common kernel init phase.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 9eba380cf7 logger: replace hardcoded constant in rtt backend
Replace hardcoded report limit of dropped message by macro.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 02afc16dcb logger: fix line_pos setup in rtt backend drop mode
Fix initial write position in line_buf when drop mode is selected.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 0459ee4fa1 logger: better code maintainability in rtt backend
Better use of preprocessor to be aware of external library API
changes.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral ced1592e54 logger: fix PR codestyle issues
Fix some issues as complained by shippable.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
David Kinder a7e74b8fdc subsys: logging: Fix grammar in Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig
Fix grammar in subsys/logging/Kconfig

Signed-off-by: David Kinder <david.b.kinder@intel.com>
Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 1a583fa8be ext: debug: segger: Add USE_SEGGER_RTT that enables RTT libraries.
This option allows to explicitly include Segger RTT libraries and
enables use of it for various subsystems. It is disabled by
default as it consumes more RAM.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 2c84fd2631 ext: debug: segger: Terminal sharing using SEGGER_RTT_LOCK/UNLOCK macros
This commit allows to share default RTT (terminal) buffer with various
Zephyr subsystems.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral f19f217f08 logger: fix grammar/punctuation in rtt backend Kconfig
Fix some czenglish grammar issues.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Pavel Kral 89b355c916 logger: Add a Segger RTT backend
Add logger backend that uses Segger RTT for message output. Several
options are provided allowing configuration of up-buffer and logger
behaviour.

Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
2018-10-31 12:47:53 +01:00
Krzysztof Chruscinski 9f7e25ad22 logging: Fix possible out-of-bound access in log_output
Coverity issue #187067

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-30 15:29:28 +01:00
qianfan Zhao 02bd01e856 subsys: logging: Using struct to manger log_strdup buffer.
log_strdup requested for a piece of memory, with the first 4 bytes as
the number of references and the next used to copy strings. In the
implementation of this function, the memory is managed by user and
is a little hard to understand.

Rewriting this part of code, using structure to manage the memory
requested, make it easier to understand.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2018-10-29 09:46:01 -04:00
Johann Fischer ce4be3af86 logging: fix out of bounds write in log_strdup
log_strdup writes out of bounds of a strdup slab.
e.g: CONFIG_LOG_STRDUP_MAX_STRING=46 and
     LOG_STRBUF_STR_SIZE=47 then in the line L:529
sdupl[LOG_STRBUF_STR_SIZE - 1] = '\0';
writes out of bounds because the available buffer space
is only 44 bytes (rounded up to 48 bytes and minus 4 bytes
for the allocated flag).

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-10-24 16:41:21 +01:00
Krzysztof Chruscinski 5d28fcd689 logging: Add optional function name prefix
Extended logger to support optional log message prepending with
function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Krzysztof Chruscinski c696e68bb9 logging: Added support for 10 arguments in log message
Extended supported number of arguments in log message. Support for
messages consisting of more than 2 chunks had to be added. So far
messages could consist of one chunk (up to 3 args) or two chunks
(2 args in first chunk and 7 in second chunk). Once 2+ chunks
support is added number of arguments is techinically limited to
15 (4 bit field). log_core and log_output extended to suppor 10
arguments.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Jakub Rzeszutko 147122e77f shell: examples unification
Updating examples according to new return value of function
shell_cmd_precheck.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-19 13:35:56 +02:00
Carles Cufi 322647129f subsys: logging: Add CR/LF handling flags
Add 2 new flags to control the output of newlines by the logger output
module. By default the logger adds both CR and LF, and with these 2 new
flags it is now possible to request LF only or no newlines at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-18 17:53:11 -04:00
Krzysztof Chruscinski 05b854c168 logging: Postpone log processing when no backends enabled
In initial state of the system it is possible that no backends are
yet enabled and log processing is triggered. In that case logs were
discarded. A flag has been added to the log core to do processing
only if at least one backend is enabled. It is applicable only to
initial phase. If backends are disabled in application lifetime
logs will be discarded.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-11 13:29:50 +03:00
Krzysztof Chruscinski 5f6070e2f7 logging: Add autostart option to LOG_BACKEND_DEFINE
Extended macro to accept flag indicating if given backend must be
initialized and enabled when log subsystem starts. Typically, simple
backends will have autostart flag set. More complex may require
explicit enabling (e.g. shell over BLE can only be enabled when
BLE connection is established).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-11 13:29:50 +03:00
Michael Scott 518444487c logging: init strdup mem_slab with aligned buffer size
We are using a non-32-bit aligned value as the block size
when initializing the strdup mem_slab for Logger.

When the non-aligned pointer is being freed, it's converted
to a u32_t and this generates the following:
***** USAGE FAULT *****
  Unaligned memory access

Let's use the aligned buffer size as the block size instead.

Signed-off-by: Michael Scott <mike@foundries.io>
2018-10-11 13:20:32 +03:00
Jukka Rissanen 65477b7391 logging: Make log_strdup() parameter const
The string parameter needs to be const as otherwise calling this
function using a const string pointer will lead to a warning.
Besides the function does not modify the parameter so should be
const anyway.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-10-03 13:05:49 +03:00
Jakub Rzeszutko 0eea1ef212 subsys: shell: add int ret_val to command handlers
1. Command handler can return command exectution status as int.
2. Existing command handlers rework.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2018-10-02 14:44:25 +02:00
Krzysztof Chruscinski a15438e8f5 logging: add mechanism for handling transient strings
Extending logger to support logging transient strings (with %s).
With dedicated call (log_strdup), string is duplicated to a buffer
from internal logger pool. Logger implicitly manages the pool.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-01 15:26:14 -04:00
Krzysztof Chruscinski 87d177a6fb logging: allow mulitple log_panic calls
Ensure that only first log_panic() sends panic signal to backends

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-27 13:11:26 +05:30
Anas Nashif 1aed3858ac logging: rename log_process_thread to logging
Keep the name short to make usuable when thread names are enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Krzysztof Chruscinski 2cc6d0c9c2 logging: Add option to suppress timestamp printing in log_output
Added flag in log_output module to add timestamp when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Krzysztof Chruscinski 07da32aae5 logging: Add option to suppress level printing in log_output
Added flag in log_output module to add severity level when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Olivier Martin 7c19e90612 subsys: logging: Mark the local functions as 'static'
After the recent change in `struct log_backend_api` (ie: add
of `init` function), init function can be marked as `static`
as it is only used in the scope of the file.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-09-24 22:51:53 +05:30
Alberto Escolar Piedras 204acc8232 subsys: logger: fix merge error
Fix merge error introduced in:
ba01a3952f
(as part of #9362)
which deleted the native_posix backend for the logger.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-24 12:06:12 +02:00
Krzysztof Chruscinski ba01a3952f logging: Add shell commands
Added commands for getting current status and controlling which log
messages are forwared to available backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-19 09:30:29 -04:00
Olivier Martin 2328ed7e21 subsys: logging: native_posix: Fixed output buffer size
`LOG_OUTPUT_DEFINE()` accepts buffer size as a last parameter.

Signed-off-by: Olivier Martin <olivier.martin@proglove.de>
2018-09-19 09:07:26 -04:00
Andrei Emeltchenko 8fc5fd55de logger: Simplify UART backend initialization
Move definition to sources of UART backend.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 94bae6a462 logger: Move native_posix_backend definition
Move definition to appropriate place removing ugly defines.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 6162caf787 logger: Add init() api and simplify init and activate
Simplify logger initialization process using already existing loops.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Alberto Escolar Piedras 2f6370c0dd subsys: logging: for native_posix use appropriate tracing
For the native_posix backend, use the appropiate tracing
functions and enable color if it should be

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-18 14:56:10 +02:00
Alberto Escolar Piedras f8b97ab70e subsys: logging: Fix for no CONFIG_LOG_PROCESS_THREAD
When CONFIG_LOG_PROCESS_THREAD was not set the logger
was not initialized.
Register a POST_KERNEL init for that case.

Also added an assert in the logger thread in case there
is no backends, instead of having that thread spinning
forever.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko e65ee6870e logger: Add native backend for native_posix
Add backend to be used in native_posix arch.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Andrei Emeltchenko 70f046e396 logger: Rename SHOW_COLOR and FORMAT_TIMESTAMP options
Make options available for other backends

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Krzysztof Chruscinski a728a46a60 logging: add template for log configuration
Added Kconfig.log_template file with template for module log
configuration.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-14 12:32:56 -04:00
Krzysztof Chruscinski 1fbea945f4 logging: Refactor log_output module
Module refactored: splitted data into read-only part and control block,
adding macro for creating log_output instance

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-14 15:05:50 +02:00
Anas Nashif a9f32d66cf tracing: remove stray event_logger code
Remove obsolete kernel event logger code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-05 16:05:08 -04:00
Subramanian Meenakshi Sundaram 591985140b subsys: logging: Fix possible null dereference
Fixing a possible null dereferencing in log_msg_create_n

Signed-off-by: Subramanian Meenakshi Sundaram <subbu147@gmail.com>
2018-08-29 15:21:19 -04:00
Flavio Ceolin 9624593a0c subsys: logging: Fix possible out-of-bounds read
Coverity issue #187069

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-29 15:15:50 -04:00
Anas Nashif a2248782a2 kernel: event_logger: remove kernel_event_logger
Move to more generic tracing hooks that can be implemented in different
ways and do not interfere with the kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Ulf Magnusson 8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Krzysztof Chruscinski 3c63d05dfc logging: Add metadata to hexdump
Extended hexdump API with a raw string attached to the data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-08-14 07:14:34 -07:00
Krzysztof Chruscinski c859e2a254 logging: Replace ifdefs with if
Replacing preprocessor with compiler in UART backend initialization.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-08-13 13:20:27 -07:00
David B. Kinder 7c89b63b7c doc: fix kconfig misspellings
Fix misspellings in Kconfig files missed during normal reviews

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-08-08 01:48:24 -05:00
Marti Bolivar 55327a183d logging: fix runtime filtering initialization
The runtime filters (both aggregated and per-backend) are all getting
initialized to the default level CONFIG_LOG_DEFAULT_LEVEL. This is not
correct behavior: the initial runtime setting for each source ID
should match its compile-time level setting.

Otherwise, setting CONFIG_LOG_RUNTIME_FILTERING=y changes the logging
behavior for messages that pass the compile time filter check, but not
the runtime check (this currently happens when LOG_LEVEL=4, since
CONFIG_LOG_DEFAULT_LEVEL=3).

Fix this by initializing all filters to their module's compile time
settings. Also make sure that filters are set up before backends are
activated, to avoid race conditions.

Fix a stray documentation typo while we are here.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-02 19:18:05 +02:00
Johan Hedberg 1292609458 logging: Use vsnprintk instead of vsnprintf
The printk family of functions is used elsewhere, so make this
consistent. Also, printk has a smaller stack footprint.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-25 17:41:05 +03:00
Marti Bolivar 1bfcea244b subsys: logging: fix trigger threshold corner case
The CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD option can be used to wake up
the background log processing thread when a given number of messages
have been queued.

Currently, the msg_finalize() routine which is responsible for
queueing a log message for later handling appends messages to the
global list after performing the threshold check and waking up the
thread.

This leads to a race condition with undesirable behavior if the
threshold == 1:

- the msg_finalize() thread is scheduled out by calling k_wakeup()
- the log processing thread wakes up, notice that no messages are
  queued, and goes back to sleep
- the msg_finalize() thread is scheduled back in and the message is
  queued for processing

This defers the handling of the message until the processing thread
wakes up again after the CONFIG_LOG_PROCESS_THREAD_SLEEP_MS timeout,
which is not what the user wants.

Fix this by queueing the message before waking up the handler thread.
(This also may improve responsiveness for larger threshold values.)

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-07-25 07:14:16 -04:00
Johan Hedberg 83db9ad753 logging: Make prefixes the same length
Make the severity level prefixes the same length. This helps both
readability of mixed level logs, and it's also consistent with how the
levels are named in the public API macros.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-19 16:23:19 -04:00
Krzysztof Chruscinski 86b5edc4d0 logging: Internal processing thread enabled by default
Enabling internal processing thread allows implicit initialization
and processing log messages in case mutlithreading is enabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-19 09:50:18 -04:00
Krzysztof Chruscinski 46db70ac4c doc: subsys: logging: internal thread and thread wake up
Documenting new logger features: waking up processing thread
and internal logger processing thread.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Krzysztof Chruscinski 000aaf96fb logging: Add internal thread for log processing
When enabled, logger is creating own thread which processes buffered
logs. When no logs to process, thread sleeps for configurable period.
Thread can be waken up if number of buffered log messages exceeds
configured threshold. Logging sample aligned to use new feature.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Krzysztof Chruscinski 1ba542c352 logging: Logger to wake up logs processing thread
Added configurable threshold of number of buffered log messages
on which log wakes up thread which processes buffered logs. Thread
ID is provided during logger initialization. Feature is optional
and can be disabled by setting CONFIG_LOG_PROCESS_TRIGGER_THR to 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-16 11:12:16 -04:00
Krzysztof Chruscinski 6b01c89935 logging: Add log initialization to system startup
Log API can be used before user can explicitly initialize the logger.
In order to ensure that logger core is ready to buffer log messages
it must be initialize as early as possible. Initialization does not
include initialization of default backend since driver may not be
ready and backend is needed only when log messages are processed.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-14 08:32:44 -04:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Krzysztof Chruscinski d731e539ce logging: Handle 0 Hz frequency in log_output
It is possible that user provides 0 hz frquency to the log_output
(if CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=0). In that case timestamp
must not be formatted to avoid division by 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-11 10:56:07 -04:00
Krzysztof Chruscinski e854dd0069 logging: log_output: Data lost because of uninitialized variable
Uninitialized variable error could lead to a situation where
printk calls processed by the logger were dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-09 12:09:43 -04:00
Jukka Rissanen f10cbe5ee9 logging: Print 7, 8 or 9 parameter macros properly
The log prints for 7, 8 and 9 parameters were not properly printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-09 11:16:49 -04:00
Krzysztof Chruściński bbeef4155c logging: subsystem major redesign
Adding new implementation of logging subsystem. New features
includes: support for multiple backends, improving performance
by deferring log processing to the known context, adding
timestamps and logs filtering options (compile time, runtime,
module level, instance level). Console backend added as the
example backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2018-06-29 10:16:45 +02:00
Andy Ross ccf3bf7ed3 kernel: Fix sloppy wait queue API
There were multiple spots where code was using the _wait_q_t
abstraction as a synonym for a dlist and doing direct list management
on them with the dlist APIs.  Refactor _wait_q_t into a proper opaque
struct (not a typedef for sys_dlist_t) and write a simple wrapper API
for the existing usages.  Now replacement of wait_q with a different
data structure is much cleaner.

Note that there were some SYS_DLIST_FOR_EACH_SAFE loops in mailbox.c
that got replaced by the normal/non-safe macro.  While these loops do
mutate the list in the code body, they always do an early return in
those circumstances instead of returning into the macro'd for() loop,
so the _SAFE usage was needless.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-05-18 01:48:48 +03:00
Jukka Rissanen be6bf29363 syslog: net: Fix multiple network interface selection for IPv4
In IPv4 we need to select the network interface, where the packet
is to be sent, using the IPv4 address instead of default network
interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-04-13 08:29:44 -04:00
Jukka Rissanen ca8b00a3cc net: if: Make interface IP configuration more flexible
Instead of always allocating both IPv6 and IPv4 address information
to every network interface, allow more fine grained address
configuration. So it is possible to have IPv6 or IPv4 only network
interfaces.

This commit introduces two new config options:
CONFIG_NET_IF_MAX_IPV4_COUNT and CONFIG_NET_IF_MAX_IPV6_COUNT
which tell how many IP address information structs are allocated
statically. At runtime when network interface is setup, it is then
possible to attach this IP address info struct to a specific
network interface. This can save considerable amount of memory
as the IP address information struct can be quite large (depends
on how many IP addresses user configures in the system).

Note that the value of CONFIG_NET_IF_MAX_IPV4_COUNT and
CONFIG_NET_IF_MAX_IPV6_COUNT should reflect the estimated number of
network interfaces in the system. So if if CONFIG_NET_IF_MAX_IPV6_COUNT
is set to 1 and there are two network interfaces that need IPv6
addresses, then the system will not be able to setup IPv6 addresses to
the second network interface in this case. This scenario might be
just fine if the second network interface is IPv4 only. The net_if.c
will print a warning during startup if mismatch about the counts and
the actual number of network interface is detected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-27 10:06:54 -04:00
Andy Ross c7ceef6751 kernel_event_logger: Ignore events before subsystem init
Thread and interrupt events may well arrive before the subsystem
initialization call has been made.  Just swallow such events.

In particular, an incoming change to the way _ready_thread works
causes the main and idle thread initialization to throw thread ready
events (which isn't wrong!), which the current setup can't handle.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-03-18 16:58:12 -04:00
Jukka Rissanen 9f73d5e2fd syslog: Add networking backend
If network based syslog backend is enabled in Kconfig file,
then syslog messages are sent to external system using UDP.
See RFC 5424 and RFC 5426 for details about the syslog protocol.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-03-15 15:19:46 +02:00
Anas Nashif e2122cbf89 lib: move ring_buffer from misc/ to lib/
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-15 20:02:01 -05:00
Anas Nashif 429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Sebastian Bøe 0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Savinay Dharmappa 0106059ff0 subsys: logging: event_logger: Fix CPU fault
A CPU fault occurs when sys_k_event_logger_get_wait()
api invoked with config KERNEL_EVENT_LOGGER_THREAD
enabled.

sys_k_event_logger_get_wait() supposed to pend  on a
semaphore when all the events from kernel event logger
are read.But when sys_k_event_logger_get_wait() inovked
with config KERNEL_EVENT_LOGGER_THREAD(i.e captures thread
events) subsquent call inside this function will write to
kernel event log buffer to capture pend event.This will
release the semaphore on which sys_k_event_logger_get_wait()
was pending hence thread gets unpend before swap gets called.

Which in other words a thread which is invoking
sys_k_event_logger_get_wait()(i. e sem_count = 0) get pends
and unpends in single function flow when KERNEL_EVENT_LOGGER_THREAD
enabled.

This would cause overlapping of the stack address where
return address of "_pend_current_thread" stored with esp of
callee saved(i. e thread->callee_saved.esp). Thus return adrress
of "_pend_current_thread" would be overwitten with zero. Which
in turn causes CPU fault.

The thread invoking sys_k_event_logger_get_wait() supposed
to only read the events of the threads which logged to kernel event
logger buffer. But it should not write to kernel event logger
buffer. Otherwise it would cause the race condition explained above.

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-11-02 22:22:54 -04:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
Anas Nashif cf9613deec kconfig: build code conditionally when possible
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-08-14 20:32:26 -04:00
Kumar Gala 05196f0320 kernel: event_logger: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Change-Id: I9ccb7c01a7d8c4ad8b1e55a1b45622aad2a57e57
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-25 22:09:12 +00:00
Leandro Pereira ffe74b45fa kernel: Add thread events to kernel event logger
This adds a new event type to the kernel event logger that tracks
thread-related events: being added to the ready queue, pending a
thread, and exiting a thread.

It's the only event type that contains "subevents" and thus has a
non-void parameter in their respective _sys_k_event_logger_*()
function.  Luckily, as isn't the case with other events (such as IRQs
and thread switching), these functions are called from
platform-agnostic places, so there's no need to worry about changing
the assembly guts.

This is the first patch in a series adding support for better real-time
profiling of Zephyr applications.

Jira: ZEP-1463
Change-Id: I6d63607ba347f7a9cac3d016fef8f5a0a830e267
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-04-25 02:16:36 +00:00
David B. Kinder 61de8f892b spell: Kconfig help typos: /kernel /misc /subsys
Fix misspellings in Kconfig help text

Change-Id: I6eda081c7b6f38287ace8c0a741e65df92d6817b
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-22 01:04:56 +00:00
Kumar Gala 6da829690f subsys: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99
integer types.

Jira: ZEP-2051

Change-Id: Icbf9e542b23208890a3a32358447d44cdc274ef1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-21 09:36:22 -05:00
David B. Kinder 0ffb648210 spell: fix doxygen comment typos: /subsys
Fix doxygen comment typos used to generate API docs

Change-Id: I3efff6f5fa26f87d1e658d6336fef01ce45f5bb0
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-04-19 18:44:06 +00:00
Paul Sokolovsky 4a928409e8 subsys/logging: sys_event_logger_get: Fix k_sem_take() success check.
k_sem_take() is documented as returning negative value for error and
0 for success. The old code didn't work.

Change-Id: I717b35d73fced476b50e3207410858f86c2ef9bc
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-06 21:14:22 +00:00
Anas Nashif 69170173c8 kernel: use k_cycle_get_32 instead of sys_cycle_get_32
Jira: ZEP-1787
Change-Id: I948100e75697dc106a4ba12ce51401673d79fe68
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-02-27 21:10:32 +00:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Anas Nashif f6e039062a kernel: remove dependency on CONFIG_NANO_TIMERS/TIMEOUTS
Remove legacy option and use SYS_CLOCK_EXISTS where appropriate.

Change-Id: I3d524ea2776e638683f0196c0cc342359d5d810f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-08 18:09:52 +00:00
Anas Nashif fad7e2dd8d logging: move event_logger to subsys/logging
Jira: ZEP-1337
Change-Id: If1690e19a882cf53caaa3418ccabeb49c783f63d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-25 14:34:43 -05:00
Anas Nashif a9e879e273 logging: move sys_log to subsys/logging
Move logging out of misc/ to its own subsystem. Anything related to
logging and any new logging features or backends could be added here
instead of the generic location in misc/ which is overcrowded with
options that are not related to eachother.

Jira: ZEP-1467
Change-Id: If6a3ea625c3a3562a7a61a0ba5fd7e6ca75518ba
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-19 19:58:39 +00:00