diff --git a/samples/subsys/logging/logger/prj_rtt.conf b/samples/subsys/logging/logger/prj_rtt.conf deleted file mode 100644 index 5fa850bb084..00000000000 --- a/samples/subsys/logging/logger/prj_rtt.conf +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_LOG=y -CONFIG_LOG_RUNTIME_FILTERING=y -CONFIG_LOG_BUFFER_SIZE=2048 -CONFIG_LOG_PRINTK=y -CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=0 -CONFIG_LOG_BACKEND_RTT=y -CONFIG_USE_SEGGER_RTT=y -CONFIG_COVERAGE=n diff --git a/samples/subsys/logging/logger/sample.yaml b/samples/subsys/logging/logger/sample.yaml index c7ed7314b24..470cd0fc93f 100644 --- a/samples/subsys/logging/logger/sample.yaml +++ b/samples/subsys/logging/logger/sample.yaml @@ -21,4 +21,13 @@ tests: tags: logging filter: CONFIG_HAS_SEGGER_RTT harness: keyboard - extra_args: CONF_FILE="prj_rtt.conf" + extra_configs: + - CONFIG_LOG_BACKEND_RTT=y + - CONFIG_USE_SEGGER_RTT=y + + samples.logger.usermode: + tags: logging usermode + filter: CONFIG_ARCH_HAS_USERSPACE + harness: keyboard + extra_configs: + - CONFIG_USERSPACE=y diff --git a/samples/subsys/logging/logger/src/ext_log_system.c b/samples/subsys/logging/logger/src/ext_log_system.c index 62f4db14316..ba3b39feeb5 100644 --- a/samples/subsys/logging/logger/src/ext_log_system.c +++ b/samples/subsys/logging/logger/src/ext_log_system.c @@ -3,9 +3,10 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include #include "ext_log_system.h" -static ext_log_handler log_handler; +K_APP_BMEM(app_part) static ext_log_handler log_handler; void ext_log_handler_set(ext_log_handler handler) { diff --git a/samples/subsys/logging/logger/src/main.c b/samples/subsys/logging/logger/src/main.c index 97cb41394ba..9668b686025 100644 --- a/samples/subsys/logging/logger/src/main.c +++ b/samples/subsys/logging/logger/src/main.c @@ -7,26 +7,38 @@ #include #include #include -#include #include "sample_instance.h" #include "sample_module.h" #include "ext_log_system.h" #include "ext_log_system_adapter.h" +#include +#include #include - LOG_MODULE_REGISTER(main); +#ifdef CONFIG_USERSPACE +K_APPMEM_PARTITION_DEFINE(app_part); +static struct k_mem_domain app_domain; +static struct k_mem_partition *app_parts[] = { +#ifdef Z_LIBC_PARTITION_EXISTS + /* C library globals, stack canary storage, etc */ + &z_libc_partition, +#endif + &app_part +}; +#endif /* CONFIG_USERSPACE */ + /* size of stack area used by each thread */ #define STACKSIZE 1024 extern void sample_module_func(void); #define INST1_NAME STRINGIFY(SAMPLE_INSTANCE_NAME.inst1) -SAMPLE_INSTANCE_DEFINE(inst1); +SAMPLE_INSTANCE_DEFINE(app_part, inst1); #define INST2_NAME STRINGIFY(SAMPLE_INSTANCE_NAME.inst2) -SAMPLE_INSTANCE_DEFINE(inst2); +SAMPLE_INSTANCE_DEFINE(app_part, inst2); #if !defined(NRF_RTC1) && defined(CONFIG_SOC_FAMILY_NRF) #include @@ -235,11 +247,14 @@ static void wait_on_log_flushed(void) } } -void log_demo_thread(void *dummy1, void *dummy2, void *dummy3) +static void log_demo_thread(void *p1, void *p2, void *p3) { + bool usermode = _is_user_context(); + k_sleep(100); - (void)log_set_timestamp_func(timestamp_get, timestamp_freq()); + printk("\n\t---=< RUNNING LOGGER DEMO FROM %s THREAD >=---\n\n", + (usermode) ? "USER" : "KERNEL"); module_logging_showcase(); @@ -268,15 +283,34 @@ void log_demo_thread(void *dummy1, void *dummy2, void *dummy3) wait_on_log_flushed(); - performance_showcase(); + if (!usermode) { + /* + * Logger performance in user mode cannot be demonstrated + * as precise timing API is accessible only from the kernel. + */ + performance_showcase(); + wait_on_log_flushed(); - wait_on_log_flushed(); + } external_log_system_showcase(); - wait_on_log_flushed(); } -K_THREAD_DEFINE(log_demo_thread_id, STACKSIZE, log_demo_thread, +static void log_demo_supervisor(void *p1, void *p2, void *p3) +{ + /* Timestamp function could be set only from kernel thread. */ + (void)log_set_timestamp_func(timestamp_get, timestamp_freq()); + + log_demo_thread(p1, p2, p3); + +#ifdef CONFIG_USERSPACE + k_mem_domain_init(&app_domain, ARRAY_SIZE(app_parts), app_parts); + k_mem_domain_add_thread(&app_domain, k_current_get()); + k_thread_user_mode_enter(log_demo_thread, p1, p2, p3); +#endif +} + +K_THREAD_DEFINE(log_demo_thread_id, STACKSIZE, log_demo_supervisor, NULL, NULL, NULL, K_LOWEST_APPLICATION_THREAD_PRIO, 0, 1); diff --git a/samples/subsys/logging/logger/src/sample_instance.h b/samples/subsys/logging/logger/src/sample_instance.h index a1e11eb6e53..02e56674f49 100644 --- a/samples/subsys/logging/logger/src/sample_instance.h +++ b/samples/subsys/logging/logger/src/sample_instance.h @@ -17,9 +17,9 @@ struct sample_instance { u32_t cnt; }; -#define SAMPLE_INSTANCE_DEFINE(_name) \ +#define SAMPLE_INSTANCE_DEFINE(_part, _name) \ LOG_INSTANCE_REGISTER(SAMPLE_INSTANCE_NAME, _name, LOG_LEVEL_INF); \ - struct sample_instance _name = { \ + K_APP_DMEM(_part) struct sample_instance _name = { \ LOG_INSTANCE_PTR_INIT(log, SAMPLE_INSTANCE_NAME, _name) \ }