unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2016-10-24 19:41:43 +02:00
|
|
|
* @brief Kernel thread support
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*
|
2016-10-24 19:41:43 +02:00
|
|
|
* This module provides general purpose thread support.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*/
|
|
|
|
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/spinlock.h>
|
|
|
|
#include <zephyr/sys/math_extras.h>
|
|
|
|
#include <zephyr/sys_clock.h>
|
2016-10-13 16:31:48 +02:00
|
|
|
#include <ksched.h>
|
2023-08-29 19:03:12 +02:00
|
|
|
#include <wait_q.h>
|
2023-09-27 00:46:01 +02:00
|
|
|
#include <zephyr/internal/syscall_handler.h>
|
2018-02-08 18:10:46 +01:00
|
|
|
#include <kernel_internal.h>
|
2018-01-26 00:24:15 +01:00
|
|
|
#include <kswap.h>
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/init.h>
|
|
|
|
#include <zephyr/tracing/tracing.h>
|
2019-10-24 17:08:21 +02:00
|
|
|
#include <string.h>
|
2018-12-17 21:34:05 +01:00
|
|
|
#include <stdbool.h>
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/irq_offload.h>
|
|
|
|
#include <zephyr/sys/check.h>
|
2023-10-07 00:38:53 +02:00
|
|
|
#include <zephyr/random/random.h>
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/sys/atomic.h>
|
|
|
|
#include <zephyr/logging/log.h>
|
2023-05-15 15:50:28 +02:00
|
|
|
#include <zephyr/sys/iterable_sections.h>
|
|
|
|
|
2020-11-26 19:32:34 +01:00
|
|
|
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
2020-04-25 01:24:46 +02:00
|
|
|
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-11 20:06:46 +02:00
|
|
|
#ifdef CONFIG_OBJ_CORE_THREAD
|
|
|
|
static struct k_obj_type obj_type_thread;
|
|
|
|
|
2023-06-01 18:16:40 +02:00
|
|
|
#ifdef CONFIG_OBJ_CORE_STATS_THREAD
|
|
|
|
static struct k_obj_core_stats_desc thread_stats_desc = {
|
|
|
|
.raw_size = sizeof(struct k_cycle_stats),
|
|
|
|
.query_size = sizeof(struct k_thread_runtime_stats),
|
|
|
|
.raw = z_thread_stats_raw,
|
|
|
|
.query = z_thread_stats_query,
|
|
|
|
.reset = z_thread_stats_reset,
|
|
|
|
.disable = z_thread_stats_disable,
|
|
|
|
.enable = z_thread_stats_enable,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-11 20:06:46 +02:00
|
|
|
static int init_thread_obj_core_list(void)
|
|
|
|
{
|
|
|
|
/* Initialize mem_slab object type */
|
|
|
|
|
|
|
|
#ifdef CONFIG_OBJ_CORE_THREAD
|
|
|
|
z_obj_type_init(&obj_type_thread, K_OBJ_TYPE_THREAD_ID,
|
|
|
|
offsetof(struct k_thread, obj_core));
|
|
|
|
#endif
|
|
|
|
|
2023-06-01 18:16:40 +02:00
|
|
|
#ifdef CONFIG_OBJ_CORE_STATS_THREAD
|
|
|
|
k_obj_type_stats_init(&obj_type_thread, &thread_stats_desc);
|
|
|
|
#endif
|
|
|
|
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-11 20:06:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(init_thread_obj_core_list, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
|
|
|
|
#endif
|
|
|
|
|
2020-02-14 19:52:49 +01:00
|
|
|
#ifdef CONFIG_THREAD_MONITOR
|
2020-02-14 19:11:35 +01:00
|
|
|
/* This lock protects the linked list of active threads; i.e. the
|
|
|
|
* initial _kernel.threads pointer and the linked list made up of
|
|
|
|
* thread->next_thread (until NULL)
|
|
|
|
*/
|
|
|
|
static struct k_spinlock z_thread_monitor_lock;
|
|
|
|
#endif /* CONFIG_THREAD_MONITOR */
|
2018-07-25 19:46:38 +02:00
|
|
|
|
2016-10-19 23:10:46 +02:00
|
|
|
#define _FOREACH_STATIC_THREAD(thread_data) \
|
2021-08-05 00:05:54 +02:00
|
|
|
STRUCT_SECTION_FOREACH(_static_thread_data, thread_data)
|
2016-09-29 01:18:09 +02:00
|
|
|
|
2018-04-27 09:25:43 +02:00
|
|
|
void k_thread_foreach(k_thread_user_cb_t user_cb, void *user_data)
|
|
|
|
{
|
2018-07-18 10:20:52 +02:00
|
|
|
#if defined(CONFIG_THREAD_MONITOR)
|
2018-04-27 09:25:43 +02:00
|
|
|
struct k_thread *thread;
|
2018-07-25 19:46:38 +02:00
|
|
|
k_spinlock_key_t key;
|
2018-04-27 09:25:43 +02:00
|
|
|
|
2018-09-18 21:40:54 +02:00
|
|
|
__ASSERT(user_cb != NULL, "user_cb can not be NULL");
|
2018-04-27 09:25:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock is needed to make sure that the _kernel.threads is not being
|
2018-09-26 12:54:09 +02:00
|
|
|
* modified by the user_cb either directly or indirectly.
|
|
|
|
* The indirect ways are through calling k_thread_create and
|
2018-04-27 09:25:43 +02:00
|
|
|
* k_thread_abort from user_cb.
|
|
|
|
*/
|
2020-02-14 19:11:35 +01:00
|
|
|
key = k_spin_lock(&z_thread_monitor_lock);
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_FUNC_ENTER(k_thread, foreach);
|
|
|
|
|
2018-04-27 09:25:43 +02:00
|
|
|
for (thread = _kernel.threads; thread; thread = thread->next_thread) {
|
|
|
|
user_cb(thread, user_data);
|
|
|
|
}
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_FUNC_EXIT(k_thread, foreach);
|
|
|
|
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spin_unlock(&z_thread_monitor_lock, key);
|
2023-08-21 15:30:26 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(user_cb);
|
|
|
|
ARG_UNUSED(user_data);
|
2018-04-27 09:25:43 +02:00
|
|
|
#endif
|
2018-07-18 10:20:52 +02:00
|
|
|
}
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2019-11-27 14:20:37 +01:00
|
|
|
void k_thread_foreach_unlocked(k_thread_user_cb_t user_cb, void *user_data)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_THREAD_MONITOR)
|
|
|
|
struct k_thread *thread;
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
|
|
|
|
__ASSERT(user_cb != NULL, "user_cb can not be NULL");
|
|
|
|
|
2020-02-14 19:11:35 +01:00
|
|
|
key = k_spin_lock(&z_thread_monitor_lock);
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_FUNC_ENTER(k_thread, foreach_unlocked);
|
|
|
|
|
2019-11-27 14:20:37 +01:00
|
|
|
for (thread = _kernel.threads; thread; thread = thread->next_thread) {
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spin_unlock(&z_thread_monitor_lock, key);
|
2019-11-27 14:20:37 +01:00
|
|
|
user_cb(thread, user_data);
|
2020-02-14 19:11:35 +01:00
|
|
|
key = k_spin_lock(&z_thread_monitor_lock);
|
2019-11-27 14:20:37 +01:00
|
|
|
}
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_FUNC_EXIT(k_thread, foreach_unlocked);
|
|
|
|
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spin_unlock(&z_thread_monitor_lock, key);
|
2023-08-21 15:30:26 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(user_cb);
|
|
|
|
ARG_UNUSED(user_data);
|
2019-11-27 14:20:37 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:40:22 +01:00
|
|
|
bool k_is_in_isr(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2019-11-07 21:43:29 +01:00
|
|
|
return arch_is_in_isr();
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 19:41:43 +02:00
|
|
|
/*
|
|
|
|
* This function tags the current thread as essential to system operation.
|
|
|
|
* Exceptions raised by this thread will be treated as a fatal system error.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_thread_essential_set(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2017-01-22 19:05:08 +01:00
|
|
|
_current->base.user_options |= K_ESSENTIAL;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 19:41:43 +02:00
|
|
|
/*
|
|
|
|
* This function tags the current thread as not essential to system operation.
|
|
|
|
* Exceptions raised by this thread may be recoverable.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
* (This is the default tag for a thread.)
|
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_thread_essential_clear(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2017-01-22 19:05:08 +01:00
|
|
|
_current->base.user_options &= ~K_ESSENTIAL;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 19:41:43 +02:00
|
|
|
/*
|
|
|
|
* This routine indicates if the current thread is an essential system thread.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*
|
2018-12-17 21:34:05 +01:00
|
|
|
* Returns true if current thread is essential, false if it is not.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
bool z_is_thread_essential(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2018-12-17 21:34:05 +01:00
|
|
|
return (_current->base.user_options & K_ESSENTIAL) == K_ESSENTIAL;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_impl_k_thread_custom_data_set(void *value)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
|
|
|
_current->custom_data = value;
|
|
|
|
}
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
static inline void z_vrfy_k_thread_custom_data_set(void *data)
|
2019-06-25 17:54:37 +02:00
|
|
|
{
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
z_impl_k_thread_custom_data_set(data);
|
2019-06-25 17:54:37 +02:00
|
|
|
}
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
#include <syscalls/k_thread_custom_data_set_mrsh.c>
|
2019-06-25 17:54:37 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void *z_impl_k_thread_custom_data_get(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
|
|
|
return _current->custom_data;
|
|
|
|
}
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
static inline void *z_vrfy_k_thread_custom_data_get(void)
|
|
|
|
{
|
|
|
|
return z_impl_k_thread_custom_data_get();
|
|
|
|
}
|
|
|
|
#include <syscalls/k_thread_custom_data_get_mrsh.c>
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
#endif /* CONFIG_THREAD_CUSTOM_DATA */
|
|
|
|
|
|
|
|
#if defined(CONFIG_THREAD_MONITOR)
|
2016-10-25 16:52:39 +02:00
|
|
|
/*
|
|
|
|
* Remove a thread from the kernel's list of active threads.
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_thread_monitor_exit(struct k_thread *thread)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&z_thread_monitor_lock);
|
2016-10-25 17:57:52 +02:00
|
|
|
|
2016-11-08 16:36:50 +01:00
|
|
|
if (thread == _kernel.threads) {
|
|
|
|
_kernel.threads = _kernel.threads->next_thread;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
} else {
|
2016-10-05 23:32:01 +02:00
|
|
|
struct k_thread *prev_thread;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2016-11-08 16:36:50 +01:00
|
|
|
prev_thread = _kernel.threads;
|
2018-09-18 01:03:52 +02:00
|
|
|
while ((prev_thread != NULL) &&
|
|
|
|
(thread != prev_thread->next_thread)) {
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
prev_thread = prev_thread->next_thread;
|
|
|
|
}
|
2018-01-23 11:03:11 +01:00
|
|
|
if (prev_thread != NULL) {
|
|
|
|
prev_thread->next_thread = thread->next_thread;
|
|
|
|
}
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
2016-10-25 17:57:52 +02:00
|
|
|
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spin_unlock(&z_thread_monitor_lock, key);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
2018-03-03 09:31:05 +01:00
|
|
|
#endif
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
int z_impl_k_thread_name_set(struct k_thread *thread, const char *value)
|
2018-03-03 09:31:05 +01:00
|
|
|
{
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
2018-03-03 09:31:05 +01:00
|
|
|
if (thread == NULL) {
|
2019-06-25 17:54:37 +02:00
|
|
|
thread = _current;
|
2018-03-03 09:31:05 +01:00
|
|
|
}
|
2019-06-25 17:54:37 +02:00
|
|
|
|
2022-03-09 18:08:21 +01:00
|
|
|
strncpy(thread->name, value, CONFIG_THREAD_MAX_NAME_LEN - 1);
|
2019-06-25 17:54:37 +02:00
|
|
|
thread->name[CONFIG_THREAD_MAX_NAME_LEN - 1] = '\0';
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_thread, name_set, thread, 0);
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
ARG_UNUSED(thread);
|
|
|
|
ARG_UNUSED(value);
|
2021-03-26 10:59:08 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_thread, name_set, thread, -ENOSYS);
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
return -ENOSYS;
|
|
|
|
#endif /* CONFIG_THREAD_NAME */
|
2018-03-03 09:31:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2021-03-29 16:54:23 +02:00
|
|
|
static inline int z_vrfy_k_thread_name_set(struct k_thread *thread, const char *str)
|
2018-03-03 09:31:05 +01:00
|
|
|
{
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
2021-03-08 18:23:49 +01:00
|
|
|
char name[CONFIG_THREAD_MAX_NAME_LEN];
|
2019-06-25 17:54:37 +02:00
|
|
|
|
2021-03-29 16:54:23 +02:00
|
|
|
if (thread != NULL) {
|
2023-09-27 13:09:45 +02:00
|
|
|
if (K_SYSCALL_OBJ(thread, K_OBJ_THREAD) != 0) {
|
2019-06-25 17:54:37 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2018-03-03 09:31:05 +01:00
|
|
|
|
2021-03-08 18:23:49 +01:00
|
|
|
/* In theory we could copy directly into thread->name, but
|
|
|
|
* the current z_vrfy / z_impl split does not provide a
|
|
|
|
* means of doing so.
|
|
|
|
*/
|
2023-09-27 12:56:59 +02:00
|
|
|
if (k_usermode_string_copy(name, (char *)str, sizeof(name)) != 0) {
|
2019-06-25 17:54:37 +02:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2021-03-29 16:54:23 +02:00
|
|
|
return z_impl_k_thread_name_set(thread, name);
|
2018-03-03 09:31:05 +01:00
|
|
|
#else
|
2019-06-25 17:54:37 +02:00
|
|
|
return -ENOSYS;
|
|
|
|
#endif /* CONFIG_THREAD_NAME */
|
2018-03-03 09:31:05 +01:00
|
|
|
}
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
#include <syscalls/k_thread_name_set_mrsh.c>
|
2019-06-25 17:54:37 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-03-03 09:31:05 +01:00
|
|
|
|
2023-10-27 19:36:17 +02:00
|
|
|
const char *k_thread_name_get(k_tid_t thread)
|
2018-03-03 09:31:05 +01:00
|
|
|
{
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
|
|
|
return (const char *)thread->name;
|
|
|
|
#else
|
|
|
|
ARG_UNUSED(thread);
|
2018-03-03 09:31:05 +01:00
|
|
|
return NULL;
|
|
|
|
#endif /* CONFIG_THREAD_NAME */
|
2019-06-25 17:54:37 +02:00
|
|
|
}
|
2018-03-03 09:31:05 +01:00
|
|
|
|
2021-03-29 16:54:23 +02:00
|
|
|
int z_impl_k_thread_name_copy(k_tid_t thread, char *buf, size_t size)
|
2018-03-03 09:31:05 +01:00
|
|
|
{
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
2021-03-29 16:54:23 +02:00
|
|
|
strncpy(buf, thread->name, size);
|
2018-03-03 09:31:05 +01:00
|
|
|
return 0;
|
2019-06-25 17:54:37 +02:00
|
|
|
#else
|
2021-03-29 16:54:23 +02:00
|
|
|
ARG_UNUSED(thread);
|
2019-06-25 17:54:37 +02:00
|
|
|
ARG_UNUSED(buf);
|
|
|
|
ARG_UNUSED(size);
|
|
|
|
return -ENOSYS;
|
|
|
|
#endif /* CONFIG_THREAD_NAME */
|
2018-03-03 09:31:05 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 01:54:23 +02:00
|
|
|
static size_t copy_bytes(char *dest, size_t dest_size, const char *src, size_t src_size)
|
2019-07-31 11:43:54 +02:00
|
|
|
{
|
2022-04-12 01:54:23 +02:00
|
|
|
size_t bytes_to_copy;
|
|
|
|
|
|
|
|
bytes_to_copy = MIN(dest_size, src_size);
|
|
|
|
memcpy(dest, src, bytes_to_copy);
|
|
|
|
|
|
|
|
return bytes_to_copy;
|
|
|
|
}
|
|
|
|
|
2023-08-15 16:43:59 +02:00
|
|
|
#define Z_STATE_STR_DUMMY "dummy"
|
|
|
|
#define Z_STATE_STR_PENDING "pending"
|
|
|
|
#define Z_STATE_STR_PRESTART "prestart"
|
|
|
|
#define Z_STATE_STR_DEAD "dead"
|
|
|
|
#define Z_STATE_STR_SUSPENDED "suspended"
|
|
|
|
#define Z_STATE_STR_ABORTING "aborting"
|
|
|
|
#define Z_STATE_STR_SUSPENDING "suspending"
|
|
|
|
#define Z_STATE_STR_QUEUED "queued"
|
|
|
|
|
2022-04-12 01:54:23 +02:00
|
|
|
const char *k_thread_state_str(k_tid_t thread_id, char *buf, size_t buf_size)
|
|
|
|
{
|
|
|
|
size_t off = 0;
|
|
|
|
uint8_t bit;
|
|
|
|
uint8_t thread_state = thread_id->base.thread_state;
|
2023-08-15 16:43:59 +02:00
|
|
|
static const struct {
|
|
|
|
const char *str;
|
|
|
|
size_t len;
|
|
|
|
} state_string[] = {
|
|
|
|
{ Z_STATE_STR_DUMMY, sizeof(Z_STATE_STR_DUMMY) - 1},
|
|
|
|
{ Z_STATE_STR_PENDING, sizeof(Z_STATE_STR_PENDING) - 1},
|
|
|
|
{ Z_STATE_STR_PRESTART, sizeof(Z_STATE_STR_PRESTART) - 1},
|
|
|
|
{ Z_STATE_STR_DEAD, sizeof(Z_STATE_STR_DEAD) - 1},
|
|
|
|
{ Z_STATE_STR_SUSPENDED, sizeof(Z_STATE_STR_SUSPENDED) - 1},
|
|
|
|
{ Z_STATE_STR_ABORTING, sizeof(Z_STATE_STR_ABORTING) - 1},
|
|
|
|
{ Z_STATE_STR_SUSPENDING, sizeof(Z_STATE_STR_SUSPENDING) - 1},
|
|
|
|
{ Z_STATE_STR_QUEUED, sizeof(Z_STATE_STR_QUEUED) - 1},
|
|
|
|
};
|
2022-04-12 01:54:23 +02:00
|
|
|
|
|
|
|
if ((buf == NULL) || (buf_size == 0)) {
|
2019-07-31 11:43:54 +02:00
|
|
|
return "";
|
2022-04-12 01:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buf_size--; /* Reserve 1 byte for end-of-string character */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through each bit in the thread_state. Stop once all have
|
|
|
|
* been processed. If more than one thread_state bit is set, then
|
|
|
|
* separate the descriptive strings with a '+'.
|
2021-06-02 11:00:17 +02:00
|
|
|
*/
|
2022-04-12 01:54:23 +02:00
|
|
|
|
2023-08-15 16:43:59 +02:00
|
|
|
|
|
|
|
for (unsigned int index = 0; thread_state != 0; index++) {
|
2022-04-12 01:54:23 +02:00
|
|
|
bit = BIT(index);
|
|
|
|
if ((thread_state & bit) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
off += copy_bytes(buf + off, buf_size - off,
|
2023-08-15 16:43:59 +02:00
|
|
|
state_string[index].str,
|
|
|
|
state_string[index].len);
|
2022-04-12 01:54:23 +02:00
|
|
|
|
|
|
|
thread_state &= ~bit;
|
|
|
|
|
|
|
|
if (thread_state != 0) {
|
|
|
|
off += copy_bytes(buf + off, buf_size - off, "+", 1);
|
|
|
|
}
|
2019-07-31 11:43:54 +02:00
|
|
|
}
|
2022-04-12 01:54:23 +02:00
|
|
|
|
|
|
|
buf[off] = '\0';
|
|
|
|
|
|
|
|
return (const char *)buf;
|
2019-07-31 11:43:54 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2019-12-19 14:19:45 +01:00
|
|
|
static inline int z_vrfy_k_thread_name_copy(k_tid_t thread,
|
|
|
|
char *buf, size_t size)
|
2018-03-03 09:31:05 +01:00
|
|
|
{
|
2019-06-25 17:54:37 +02:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
|
|
|
size_t len;
|
2023-09-27 12:49:28 +02:00
|
|
|
struct k_object *ko = k_object_find(thread);
|
2018-03-03 09:31:05 +01:00
|
|
|
|
2019-06-25 17:54:37 +02:00
|
|
|
/* Special case: we allow reading the names of initialized threads
|
|
|
|
* even if we don't have permission on them
|
|
|
|
*/
|
2019-12-19 14:19:45 +01:00
|
|
|
if (thread == NULL || ko->type != K_OBJ_THREAD ||
|
2019-06-25 17:54:37 +02:00
|
|
|
(ko->flags & K_OBJ_FLAG_INITIALIZED) == 0) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2023-09-27 13:09:45 +02:00
|
|
|
if (K_SYSCALL_MEMORY_WRITE(buf, size) != 0) {
|
2019-06-25 17:54:37 +02:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
2019-12-19 14:19:45 +01:00
|
|
|
len = strlen(thread->name);
|
2019-06-25 17:54:37 +02:00
|
|
|
if (len + 1 > size) {
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2023-09-27 12:56:59 +02:00
|
|
|
return k_usermode_to_copy((void *)buf, thread->name, len + 1);
|
2019-06-25 17:54:37 +02:00
|
|
|
#else
|
2019-12-19 14:19:45 +01:00
|
|
|
ARG_UNUSED(thread);
|
2019-06-25 17:54:37 +02:00
|
|
|
ARG_UNUSED(buf);
|
|
|
|
ARG_UNUSED(size);
|
|
|
|
return -ENOSYS;
|
|
|
|
#endif /* CONFIG_THREAD_NAME */
|
|
|
|
}
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
#include <syscalls/k_thread_name_copy_mrsh.c>
|
2019-06-25 17:54:37 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-03-03 09:31:05 +01:00
|
|
|
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2021-05-28 14:17:37 +02:00
|
|
|
#ifdef CONFIG_MULTITHREADING
|
2017-05-11 22:29:15 +02:00
|
|
|
#ifdef CONFIG_STACK_SENTINEL
|
|
|
|
/* Check that the stack sentinel is still present
|
|
|
|
*
|
|
|
|
* The stack sentinel feature writes a magic value to the lowest 4 bytes of
|
|
|
|
* the thread's stack when the thread is initialized. This value gets checked
|
|
|
|
* in a few places:
|
|
|
|
*
|
|
|
|
* 1) In k_yield() if the current thread is not swapped out
|
2017-06-07 18:33:16 +02:00
|
|
|
* 2) After servicing a non-nested interrupt
|
2019-03-08 22:19:05 +01:00
|
|
|
* 3) In z_swap(), check the sentinel in the outgoing thread
|
2017-05-11 22:29:15 +02:00
|
|
|
*
|
2017-06-07 18:33:16 +02:00
|
|
|
* Item 2 requires support in arch/ code.
|
2017-05-11 22:29:15 +02:00
|
|
|
*
|
|
|
|
* If the check fails, the thread will be terminated appropriately through
|
|
|
|
* the system fatal error handler.
|
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_check_stack_sentinel(void)
|
2017-05-11 22:29:15 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t *stack;
|
2017-05-11 22:29:15 +02:00
|
|
|
|
2018-12-16 21:48:29 +01:00
|
|
|
if ((_current->base.thread_state & _THREAD_DUMMY) != 0) {
|
2017-05-11 22:29:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
stack = (uint32_t *)_current->stack_info.start;
|
2017-05-11 22:29:15 +02:00
|
|
|
if (*stack != STACK_SENTINEL) {
|
|
|
|
/* Restore it so further checks don't trigger this same error */
|
|
|
|
*stack = STACK_SENTINEL;
|
2019-07-11 23:18:28 +02:00
|
|
|
z_except_reason(K_ERR_STACK_CHK_FAIL);
|
2017-05-11 22:29:15 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-28 14:17:37 +02:00
|
|
|
#endif /* CONFIG_STACK_SENTINEL */
|
2017-05-11 22:29:15 +02:00
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_impl_k_thread_start(struct k_thread *thread)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2021-03-26 10:59:08 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_thread, start, thread);
|
|
|
|
|
2020-01-23 22:28:30 +01:00
|
|
|
z_sched_start(thread);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
2017-09-29 23:00:48 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
static inline void z_vrfy_k_thread_start(struct k_thread *thread)
|
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(thread, K_OBJ_THREAD));
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
return z_impl_k_thread_start(thread);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_thread_start_mrsh.c>
|
2017-09-29 23:00:48 +02:00
|
|
|
#endif
|
2016-12-16 22:45:05 +01:00
|
|
|
#endif
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2016-12-16 22:45:05 +01:00
|
|
|
#ifdef CONFIG_MULTITHREADING
|
kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-06 00:18:14 +01:00
|
|
|
static void schedule_new_thread(struct k_thread *thread, k_timeout_t delay)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2016-10-06 21:04:23 +02:00
|
|
|
#ifdef CONFIG_SYS_CLOCK_EXISTS
|
kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-06 00:18:14 +01:00
|
|
|
if (K_TIMEOUT_EQ(delay, K_NO_WAIT)) {
|
2017-08-30 20:01:56 +02:00
|
|
|
k_thread_start(thread);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
} else {
|
kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-06 00:18:14 +01:00
|
|
|
z_add_thread_timeout(thread, delay);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
ARG_UNUSED(delay);
|
2017-08-30 20:01:56 +02:00
|
|
|
k_thread_start(thread);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
#endif
|
|
|
|
}
|
2016-12-16 22:45:05 +01:00
|
|
|
#endif
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2020-04-23 22:55:56 +02:00
|
|
|
#if CONFIG_STACK_POINTER_RANDOM
|
2018-05-24 00:25:23 +02:00
|
|
|
int z_stack_adjust_initialized;
|
|
|
|
|
2020-04-23 22:55:56 +02:00
|
|
|
static size_t random_offset(size_t stack_size)
|
2017-08-30 23:31:03 +02:00
|
|
|
{
|
2018-05-24 00:25:23 +02:00
|
|
|
size_t random_val;
|
|
|
|
|
|
|
|
if (!z_stack_adjust_initialized) {
|
2023-10-10 00:22:18 +02:00
|
|
|
z_early_rand_get((uint8_t *)&random_val, sizeof(random_val));
|
2018-05-24 00:25:23 +02:00
|
|
|
} else {
|
2020-05-27 18:26:57 +02:00
|
|
|
sys_rand_get((uint8_t *)&random_val, sizeof(random_val));
|
2018-05-24 00:25:23 +02:00
|
|
|
}
|
|
|
|
|
2019-09-22 00:36:52 +02:00
|
|
|
/* Don't need to worry about alignment of the size here,
|
2019-11-07 21:43:29 +01:00
|
|
|
* arch_new_thread() is required to do it.
|
2018-03-02 16:54:13 +01:00
|
|
|
*
|
|
|
|
* FIXME: Not the best way to get a random number in a range.
|
|
|
|
* See #6493
|
|
|
|
*/
|
2018-05-24 00:25:23 +02:00
|
|
|
const size_t fuzz = random_val % CONFIG_STACK_POINTER_RANDOM;
|
2018-04-03 18:47:41 +02:00
|
|
|
|
|
|
|
if (unlikely(fuzz * 2 > stack_size)) {
|
2020-04-23 22:55:56 +02:00
|
|
|
return 0;
|
2018-04-03 18:47:41 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 22:55:56 +02:00
|
|
|
return fuzz;
|
2018-04-03 18:47:41 +02:00
|
|
|
}
|
|
|
|
#if defined(CONFIG_STACK_GROWS_UP)
|
|
|
|
/* This is so rare not bothering for now */
|
|
|
|
#error "Stack pointer randomization not implemented for upward growing stacks"
|
|
|
|
#endif /* CONFIG_STACK_GROWS_UP */
|
2018-03-02 16:54:13 +01:00
|
|
|
#endif /* CONFIG_STACK_POINTER_RANDOM */
|
2018-04-03 18:47:41 +02:00
|
|
|
|
2020-04-23 22:55:56 +02:00
|
|
|
static char *setup_thread_stack(struct k_thread *new_thread,
|
|
|
|
k_thread_stack_t *stack, size_t stack_size)
|
|
|
|
{
|
2020-04-25 01:24:46 +02:00
|
|
|
size_t stack_obj_size, stack_buf_size;
|
|
|
|
char *stack_ptr, *stack_buf_start;
|
2020-04-23 22:55:56 +02:00
|
|
|
size_t delta = 0;
|
|
|
|
|
2020-04-25 01:24:46 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
if (z_stack_is_user_capable(stack)) {
|
|
|
|
stack_obj_size = Z_THREAD_STACK_SIZE_ADJUST(stack_size);
|
|
|
|
stack_buf_start = Z_THREAD_STACK_BUFFER(stack);
|
|
|
|
stack_buf_size = stack_obj_size - K_THREAD_STACK_RESERVED;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Object cannot host a user mode thread */
|
|
|
|
stack_obj_size = Z_KERNEL_STACK_SIZE_ADJUST(stack_size);
|
|
|
|
stack_buf_start = Z_KERNEL_STACK_BUFFER(stack);
|
|
|
|
stack_buf_size = stack_obj_size - K_KERNEL_STACK_RESERVED;
|
|
|
|
}
|
2020-04-23 22:55:56 +02:00
|
|
|
|
2020-04-25 01:24:46 +02:00
|
|
|
/* Initial stack pointer at the high end of the stack object, may
|
|
|
|
* be reduced later in this function by TLS or random offset
|
|
|
|
*/
|
|
|
|
stack_ptr = (char *)stack + stack_obj_size;
|
2020-04-23 22:55:56 +02:00
|
|
|
|
2020-04-25 01:24:46 +02:00
|
|
|
LOG_DBG("stack %p for thread %p: obj_size=%zu buf_start=%p "
|
|
|
|
" buf_size %zu stack_ptr=%p",
|
2022-10-12 11:49:41 +02:00
|
|
|
stack, new_thread, stack_obj_size, (void *)stack_buf_start,
|
|
|
|
stack_buf_size, (void *)stack_ptr);
|
2020-04-23 22:55:56 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_INIT_STACKS
|
|
|
|
memset(stack_buf_start, 0xaa, stack_buf_size);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_STACK_SENTINEL
|
|
|
|
/* Put the stack sentinel at the lowest 4 bytes of the stack area.
|
|
|
|
* We periodically check that it's still present and kill the thread
|
|
|
|
* if it isn't.
|
|
|
|
*/
|
|
|
|
*((uint32_t *)stack_buf_start) = STACK_SENTINEL;
|
|
|
|
#endif /* CONFIG_STACK_SENTINEL */
|
2020-09-28 20:27:11 +02:00
|
|
|
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
2020-10-24 22:04:04 +02:00
|
|
|
/* TLS is always last within the stack buffer */
|
|
|
|
delta += arch_tls_stack_setup(new_thread, stack_ptr);
|
2020-09-28 20:27:11 +02:00
|
|
|
#endif /* CONFIG_THREAD_LOCAL_STORAGE */
|
2020-04-23 22:55:56 +02:00
|
|
|
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
|
|
|
|
size_t tls_size = sizeof(struct _thread_userspace_local_data);
|
|
|
|
|
|
|
|
/* reserve space on highest memory of stack buffer for local data */
|
|
|
|
delta += tls_size;
|
|
|
|
new_thread->userspace_local_data =
|
|
|
|
(struct _thread_userspace_local_data *)(stack_ptr - delta);
|
|
|
|
#endif
|
|
|
|
#if CONFIG_STACK_POINTER_RANDOM
|
|
|
|
delta += random_offset(stack_buf_size);
|
|
|
|
#endif
|
|
|
|
delta = ROUND_UP(delta, ARCH_STACK_PTR_ALIGN);
|
|
|
|
#ifdef CONFIG_THREAD_STACK_INFO
|
|
|
|
/* Initial values. Arches which implement MPU guards that "borrow"
|
|
|
|
* memory from the stack buffer (not tracked in K_THREAD_STACK_RESERVED)
|
|
|
|
* will need to appropriately update this.
|
|
|
|
*
|
|
|
|
* The bounds tracked here correspond to the area of the stack object
|
|
|
|
* that the thread can access, which includes TLS.
|
|
|
|
*/
|
|
|
|
new_thread->stack_info.start = (uintptr_t)stack_buf_start;
|
|
|
|
new_thread->stack_info.size = stack_buf_size;
|
|
|
|
new_thread->stack_info.delta = delta;
|
|
|
|
#endif
|
|
|
|
stack_ptr -= delta;
|
|
|
|
|
|
|
|
return stack_ptr;
|
|
|
|
}
|
|
|
|
|
2019-03-08 13:02:37 +01:00
|
|
|
/*
|
2020-04-23 22:55:56 +02:00
|
|
|
* The provided stack_size value is presumed to be either the result of
|
|
|
|
* K_THREAD_STACK_SIZEOF(stack), or the size value passed to the instance
|
|
|
|
* of K_THREAD_STACK_DEFINE() which defined 'stack'.
|
2019-03-08 13:02:37 +01:00
|
|
|
*/
|
2020-04-24 20:29:47 +02:00
|
|
|
char *z_setup_new_thread(struct k_thread *new_thread,
|
|
|
|
k_thread_stack_t *stack, size_t stack_size,
|
|
|
|
k_thread_entry_t entry,
|
|
|
|
void *p1, void *p2, void *p3,
|
|
|
|
int prio, uint32_t options, const char *name)
|
2018-04-03 18:47:41 +02:00
|
|
|
{
|
2020-04-23 22:55:56 +02:00
|
|
|
char *stack_ptr;
|
|
|
|
|
2020-04-19 23:31:27 +02:00
|
|
|
Z_ASSERT_VALID_PRIO(prio, entry);
|
|
|
|
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-11 20:06:46 +02:00
|
|
|
#ifdef CONFIG_OBJ_CORE_THREAD
|
|
|
|
k_obj_core_init_and_link(K_OBJ_CORE(new_thread), &obj_type_thread);
|
2023-06-01 18:16:40 +02:00
|
|
|
#ifdef CONFIG_OBJ_CORE_STATS_THREAD
|
|
|
|
k_obj_core_stats_register(K_OBJ_CORE(new_thread),
|
|
|
|
&new_thread->base.usage,
|
|
|
|
sizeof(new_thread->base.usage));
|
|
|
|
#endif
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-11 20:06:46 +02:00
|
|
|
#endif
|
|
|
|
|
2019-07-30 23:02:54 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2021-04-03 08:06:00 +02:00
|
|
|
__ASSERT((options & K_USER) == 0U || z_stack_is_user_capable(stack),
|
2020-04-25 01:24:46 +02:00
|
|
|
"user thread %p with kernel-only stack %p",
|
|
|
|
new_thread, stack);
|
2023-09-26 23:32:13 +02:00
|
|
|
k_object_init(new_thread);
|
|
|
|
k_object_init(stack);
|
2019-07-30 23:02:54 +02:00
|
|
|
new_thread->stack_obj = stack;
|
2020-05-28 20:48:54 +02:00
|
|
|
new_thread->syscall_frame = NULL;
|
2019-07-30 23:02:54 +02:00
|
|
|
|
|
|
|
/* Any given thread has access to itself */
|
|
|
|
k_object_access_grant(new_thread, new_thread);
|
|
|
|
#endif
|
2021-02-20 00:32:19 +01:00
|
|
|
z_waitq_init(&new_thread->join_queue);
|
2020-02-21 01:33:06 +01:00
|
|
|
|
2020-04-19 23:28:15 +02:00
|
|
|
/* Initialize various struct k_thread members */
|
|
|
|
z_init_thread_base(&new_thread->base, prio, _THREAD_PRESTART, options);
|
2020-04-23 22:55:56 +02:00
|
|
|
stack_ptr = setup_thread_stack(new_thread, stack, stack_size);
|
|
|
|
|
2020-12-07 19:15:42 +01:00
|
|
|
#ifdef CONFIG_KERNEL_COHERENCE
|
2020-10-06 20:39:48 +02:00
|
|
|
/* Check that the thread object is safe, but that the stack is
|
|
|
|
* still cached!
|
|
|
|
*/
|
kernel: Add cache coherence management framework
Zephyr SMP kernels need to be able to run on architectures with
incoherent caches. Naive implementation of synchronization on such
architectures requires extensive cache flushing (e.g. flush+invalidate
everything on every spin lock operation, flush on every unlock!) and
is a performance problem.
Instead, many of these systems will have access to separate "coherent"
(usually uncached) and "incoherent" regions of memory. Where this is
available, place all writable data sections by default into the
coherent region. An "__incoherent" attribute flag is defined for data
regions that are known to be CPU-local and which should use the cache.
By default, this is used for stack memory.
Stack memory will be incoherent by default, as by definition it is
local to its current thread. This requires special cache management
on context switch, so an arch API has been added for that.
Also, when enabled, add assertions to strategic places to ensure that
shared kernel data is indeed coherent. We check thread objects, the
_kernel struct, waitq's, timeouts and spinlocks. In practice almost
all kernel synchronization is built on top of these structures, and
any shared data structs will contain at least one of them.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-05-13 17:34:04 +02:00
|
|
|
__ASSERT_NO_MSG(arch_mem_coherent(new_thread));
|
|
|
|
__ASSERT_NO_MSG(!arch_mem_coherent(stack));
|
|
|
|
#endif
|
|
|
|
|
2020-04-23 22:55:56 +02:00
|
|
|
arch_new_thread(new_thread, stack, stack_ptr, entry, p1, p2, p3);
|
2018-08-17 00:42:28 +02:00
|
|
|
|
2020-04-19 23:28:15 +02:00
|
|
|
/* static threads overwrite it afterwards with real value */
|
|
|
|
new_thread->init_data = NULL;
|
2018-08-17 00:42:28 +02:00
|
|
|
|
2020-02-18 21:23:53 +01:00
|
|
|
#ifdef CONFIG_USE_SWITCH
|
|
|
|
/* switch_handle must be non-null except when inside z_swap()
|
|
|
|
* for synchronization reasons. Historically some notional
|
|
|
|
* USE_SWITCH architectures have actually ignored the field
|
|
|
|
*/
|
|
|
|
__ASSERT(new_thread->switch_handle != NULL,
|
|
|
|
"arch layer failed to initialize switch_handle");
|
2020-01-17 18:32:36 +01:00
|
|
|
#endif
|
2020-04-19 23:28:15 +02:00
|
|
|
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
|
|
|
/* Initialize custom data field (value is opaque to kernel) */
|
|
|
|
new_thread->custom_data = NULL;
|
|
|
|
#endif
|
2023-03-08 22:56:31 +01:00
|
|
|
#ifdef CONFIG_EVENTS
|
|
|
|
new_thread->no_wake_on_timeout = false;
|
|
|
|
#endif
|
2018-06-06 17:45:01 +02:00
|
|
|
#ifdef CONFIG_THREAD_MONITOR
|
|
|
|
new_thread->entry.pEntry = entry;
|
|
|
|
new_thread->entry.parameter1 = p1;
|
|
|
|
new_thread->entry.parameter2 = p2;
|
|
|
|
new_thread->entry.parameter3 = p3;
|
|
|
|
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&z_thread_monitor_lock);
|
2018-06-06 17:45:01 +02:00
|
|
|
|
|
|
|
new_thread->next_thread = _kernel.threads;
|
|
|
|
_kernel.threads = new_thread;
|
2020-02-14 19:11:35 +01:00
|
|
|
k_spin_unlock(&z_thread_monitor_lock, key);
|
2018-06-06 17:45:01 +02:00
|
|
|
#endif
|
2018-03-03 09:31:05 +01:00
|
|
|
#ifdef CONFIG_THREAD_NAME
|
2019-06-25 17:54:37 +02:00
|
|
|
if (name != NULL) {
|
|
|
|
strncpy(new_thread->name, name,
|
|
|
|
CONFIG_THREAD_MAX_NAME_LEN - 1);
|
|
|
|
/* Ensure NULL termination, truncate if longer */
|
|
|
|
new_thread->name[CONFIG_THREAD_MAX_NAME_LEN - 1] = '\0';
|
2020-04-19 23:28:15 +02:00
|
|
|
} else {
|
|
|
|
new_thread->name[0] = '\0';
|
2019-06-25 17:54:37 +02:00
|
|
|
}
|
2018-03-03 09:31:05 +01:00
|
|
|
#endif
|
2019-01-31 00:00:42 +01:00
|
|
|
#ifdef CONFIG_SCHED_CPU_MASK
|
2021-09-24 19:57:39 +02:00
|
|
|
if (IS_ENABLED(CONFIG_SCHED_CPU_MASK_PIN_ONLY)) {
|
|
|
|
new_thread->base.cpu_mask = 1; /* must specify only one cpu */
|
|
|
|
} else {
|
|
|
|
new_thread->base.cpu_mask = -1; /* allow all cpus */
|
|
|
|
}
|
2019-01-31 00:00:42 +01:00
|
|
|
#endif
|
2017-11-13 23:12:23 +01:00
|
|
|
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
|
|
|
|
/* _current may be null if the dummy thread is not used */
|
|
|
|
if (!_current) {
|
2018-04-13 02:12:15 +02:00
|
|
|
new_thread->resource_pool = NULL;
|
2020-04-24 20:29:47 +02:00
|
|
|
return stack_ptr;
|
2017-11-13 23:12:23 +01:00
|
|
|
}
|
|
|
|
#endif
|
2018-04-13 02:12:15 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-10-06 22:39:29 +02:00
|
|
|
z_mem_domain_init_thread(new_thread);
|
2017-10-16 18:12:47 +02:00
|
|
|
|
2019-03-27 02:57:45 +01:00
|
|
|
if ((options & K_INHERIT_PERMS) != 0U) {
|
2023-09-27 12:47:50 +02:00
|
|
|
k_thread_perms_inherit(_current, new_thread);
|
2017-10-05 20:11:02 +02:00
|
|
|
}
|
2018-05-15 20:06:25 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_DEADLINE
|
|
|
|
new_thread->base.prio_deadline = 0;
|
2017-08-30 23:31:03 +02:00
|
|
|
#endif
|
2018-04-13 02:12:15 +02:00
|
|
|
new_thread->resource_pool = _current->resource_pool;
|
2021-03-26 10:59:08 +01:00
|
|
|
|
2023-08-08 16:20:59 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
z_waitq_init(&new_thread->halt_queue);
|
|
|
|
#endif
|
|
|
|
|
2021-12-15 15:46:52 +01:00
|
|
|
#ifdef CONFIG_SCHED_THREAD_USAGE
|
|
|
|
new_thread->base.usage = (struct k_cycle_stats) {};
|
|
|
|
new_thread->base.usage.track_usage =
|
|
|
|
CONFIG_SCHED_THREAD_USAGE_AUTO_ENABLE;
|
|
|
|
#endif
|
|
|
|
|
2021-03-26 10:59:08 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_thread, create, new_thread);
|
2020-04-24 20:29:47 +02:00
|
|
|
|
|
|
|
return stack_ptr;
|
2017-08-30 23:31:03 +02:00
|
|
|
}
|
2017-03-30 22:07:02 +02:00
|
|
|
|
2017-08-30 23:31:03 +02:00
|
|
|
#ifdef CONFIG_MULTITHREADING
|
2019-03-08 22:19:05 +01:00
|
|
|
k_tid_t z_impl_k_thread_create(struct k_thread *new_thread,
|
2017-10-16 23:46:34 +02:00
|
|
|
k_thread_stack_t *stack,
|
2017-10-02 19:51:18 +02:00
|
|
|
size_t stack_size, k_thread_entry_t entry,
|
|
|
|
void *p1, void *p2, void *p3,
|
2020-05-27 18:26:57 +02:00
|
|
|
int prio, uint32_t options, k_timeout_t delay)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2019-11-07 21:43:29 +01:00
|
|
|
__ASSERT(!arch_is_in_isr(), "Threads may not be created in ISRs");
|
2018-07-04 15:03:03 +02:00
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
z_setup_new_thread(new_thread, stack, stack_size, entry, p1, p2, p3,
|
2018-03-03 09:31:05 +01:00
|
|
|
prio, options, NULL);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-06 00:18:14 +01:00
|
|
|
if (!K_TIMEOUT_EQ(delay, K_FOREVER)) {
|
2017-08-30 20:01:56 +02:00
|
|
|
schedule_new_thread(new_thread, delay);
|
|
|
|
}
|
2018-07-04 15:03:03 +02:00
|
|
|
|
2017-03-30 22:07:02 +02:00
|
|
|
return new_thread;
|
|
|
|
}
|
2017-10-02 19:51:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-04-25 01:24:46 +02:00
|
|
|
bool z_stack_is_user_capable(k_thread_stack_t *stack)
|
|
|
|
{
|
2023-09-27 12:49:28 +02:00
|
|
|
return k_object_find(stack) != NULL;
|
2020-04-25 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread,
|
|
|
|
k_thread_stack_t *stack,
|
|
|
|
size_t stack_size, k_thread_entry_t entry,
|
|
|
|
void *p1, void *p2, void *p3,
|
2020-05-27 18:26:57 +02:00
|
|
|
int prio, uint32_t options, k_timeout_t delay)
|
2017-10-02 19:51:18 +02:00
|
|
|
{
|
2020-03-11 18:56:19 +01:00
|
|
|
size_t total_size, stack_obj_size;
|
2023-09-26 23:37:25 +02:00
|
|
|
struct k_object *stack_object;
|
2017-10-02 19:51:18 +02:00
|
|
|
|
|
|
|
/* The thread and stack objects *must* be in an uninitialized state */
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(new_thread, K_OBJ_THREAD));
|
2020-04-25 01:24:46 +02:00
|
|
|
|
|
|
|
/* No need to check z_stack_is_user_capable(), it won't be in the
|
|
|
|
* object table if it isn't
|
|
|
|
*/
|
2023-09-27 12:49:28 +02:00
|
|
|
stack_object = k_object_find(stack);
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_VERIFY_MSG(k_object_validation_check(stack_object, stack,
|
2020-03-11 14:56:58 +01:00
|
|
|
K_OBJ_THREAD_STACK_ELEMENT,
|
2018-09-21 01:14:57 +02:00
|
|
|
_OBJ_INIT_FALSE) == 0,
|
2018-05-05 00:57:57 +02:00
|
|
|
"bad stack object"));
|
2017-10-02 19:51:18 +02:00
|
|
|
|
|
|
|
/* Verify that the stack size passed in is OK by computing the total
|
|
|
|
* size and comparing it with the size value in the object metadata
|
|
|
|
*/
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_VERIFY_MSG(!size_add_overflow(K_THREAD_STACK_RESERVED,
|
2019-11-22 02:38:17 +01:00
|
|
|
stack_size, &total_size),
|
|
|
|
"stack size overflow (%zu+%zu)",
|
|
|
|
stack_size,
|
2019-03-19 18:43:06 +01:00
|
|
|
K_THREAD_STACK_RESERVED));
|
|
|
|
|
2019-03-19 18:48:09 +01:00
|
|
|
/* Testing less-than-or-equal since additional room may have been
|
|
|
|
* allocated for alignment constraints
|
|
|
|
*/
|
2020-03-11 18:56:19 +01:00
|
|
|
#ifdef CONFIG_GEN_PRIV_STACKS
|
|
|
|
stack_obj_size = stack_object->data.stack_data->size;
|
|
|
|
#else
|
|
|
|
stack_obj_size = stack_object->data.stack_size;
|
|
|
|
#endif
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_VERIFY_MSG(total_size <= stack_obj_size,
|
2020-03-11 14:37:42 +01:00
|
|
|
"stack size %zu is too big, max is %zu",
|
2020-03-11 18:56:19 +01:00
|
|
|
total_size, stack_obj_size));
|
2017-10-02 19:51:18 +02:00
|
|
|
|
|
|
|
/* User threads may only create other user threads and they can't
|
|
|
|
* be marked as essential
|
|
|
|
*/
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_VERIFY(options & K_USER));
|
|
|
|
K_OOPS(K_SYSCALL_VERIFY(!(options & K_ESSENTIAL)));
|
2017-10-02 19:51:18 +02:00
|
|
|
|
|
|
|
/* Check validity of prio argument; must be the same or worse priority
|
|
|
|
* than the caller
|
|
|
|
*/
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_VERIFY(_is_valid_prio(prio, NULL)));
|
|
|
|
K_OOPS(K_SYSCALL_VERIFY(z_is_prio_lower_or_equal(prio,
|
2018-05-05 00:57:57 +02:00
|
|
|
_current->base.prio)));
|
2017-10-02 19:51:18 +02:00
|
|
|
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
z_setup_new_thread(new_thread, stack, stack_size,
|
|
|
|
entry, p1, p2, p3, prio, options, NULL);
|
2017-10-02 19:51:18 +02:00
|
|
|
|
kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument. Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created. This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.
The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.
The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.
Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.
For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.
Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions. These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.
k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.
Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure. But k_poll() does not fail
spuriously, so the loop was removed.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-06 00:18:14 +01:00
|
|
|
if (!K_TIMEOUT_EQ(delay, K_FOREVER)) {
|
2017-10-02 19:51:18 +02:00
|
|
|
schedule_new_thread(new_thread, delay);
|
|
|
|
}
|
|
|
|
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
return new_thread;
|
2017-10-02 19:51:18 +02:00
|
|
|
}
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
#include <syscalls/k_thread_create_mrsh.c>
|
2017-10-02 19:51:18 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
|
|
|
#endif /* CONFIG_MULTITHREADING */
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2016-12-14 21:24:12 +01:00
|
|
|
#ifdef CONFIG_MULTITHREADING
|
userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER,
but these threads can't do much since they start with permissions on
no kernel objects other than their own thread object.
Rather than do some run-time synchronization to have some other thread
grant the necessary permissions, we introduce macros
to conveniently assign object permissions to these threads when they
are brought up at boot by the kernel. The tables generated here
are constant and live in ROM when possible.
Example usage:
K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry,
NULL, NULL, NULL, 0, K_USER, K_NO_WAIT);
K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe);
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 20:20:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
|
|
|
|
static void grant_static_access(void)
|
|
|
|
{
|
2023-09-26 23:37:25 +02:00
|
|
|
STRUCT_SECTION_FOREACH(k_object_assignment, pos) {
|
userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER,
but these threads can't do much since they start with permissions on
no kernel objects other than their own thread object.
Rather than do some run-time synchronization to have some other thread
grant the necessary permissions, we introduce macros
to conveniently assign object permissions to these threads when they
are brought up at boot by the kernel. The tables generated here
are constant and live in ROM when possible.
Example usage:
K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry,
NULL, NULL, NULL, 0, K_USER, K_NO_WAIT);
K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe);
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 20:20:22 +02:00
|
|
|
for (int i = 0; pos->objects[i] != NULL; i++) {
|
|
|
|
k_object_access_grant(pos->objects[i],
|
|
|
|
pos->thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_USERSPACE */
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_init_static_threads(void)
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
{
|
2016-09-29 01:26:00 +02:00
|
|
|
_FOREACH_STATIC_THREAD(thread_data) {
|
2019-03-08 22:19:05 +01:00
|
|
|
z_setup_new_thread(
|
2017-03-30 22:07:02 +02:00
|
|
|
thread_data->init_thread,
|
2016-09-29 01:26:00 +02:00
|
|
|
thread_data->init_stack,
|
|
|
|
thread_data->init_stack_size,
|
|
|
|
thread_data->init_entry,
|
|
|
|
thread_data->init_p1,
|
|
|
|
thread_data->init_p2,
|
|
|
|
thread_data->init_p3,
|
|
|
|
thread_data->init_prio,
|
2018-03-03 09:31:05 +01:00
|
|
|
thread_data->init_options,
|
|
|
|
thread_data->init_name);
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2017-03-30 22:07:02 +02:00
|
|
|
thread_data->init_thread->init_data = thread_data;
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
2016-10-11 18:06:25 +02:00
|
|
|
|
userspace: add K_THREAD_ACCCESS_GRANT()
It's possible to declare static threads that start up as K_USER,
but these threads can't do much since they start with permissions on
no kernel objects other than their own thread object.
Rather than do some run-time synchronization to have some other thread
grant the necessary permissions, we introduce macros
to conveniently assign object permissions to these threads when they
are brought up at boot by the kernel. The tables generated here
are constant and live in ROM when possible.
Example usage:
K_THREAD_DEFINE(my_thread, STACK_SIZE, my_thread_entry,
NULL, NULL, NULL, 0, K_USER, K_NO_WAIT);
K_THREAD_ACCESS_GRANT(my_thread, &my_sem, &my_mutex, &my_pipe);
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-17 20:20:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
grant_static_access();
|
|
|
|
#endif
|
2016-10-11 18:06:25 +02:00
|
|
|
|
|
|
|
/*
|
2018-07-25 19:46:38 +02:00
|
|
|
* Non-legacy static threads may be started immediately or
|
|
|
|
* after a previously specified delay. Even though the
|
|
|
|
* scheduler is locked, ticks can still be delivered and
|
|
|
|
* processed. Take a sched lock to prevent them from running
|
|
|
|
* until they are all started.
|
2016-10-11 18:06:25 +02:00
|
|
|
*
|
|
|
|
* Note that static threads defined using the legacy API have a
|
|
|
|
* delay of K_FOREVER.
|
|
|
|
*/
|
2018-07-25 19:46:38 +02:00
|
|
|
k_sched_lock();
|
2016-10-11 18:06:25 +02:00
|
|
|
_FOREACH_STATIC_THREAD(thread_data) {
|
2023-10-06 01:47:57 +02:00
|
|
|
k_timeout_t init_delay = Z_THREAD_INIT_DELAY(thread_data);
|
|
|
|
|
|
|
|
if (!K_TIMEOUT_EQ(init_delay, K_FOREVER)) {
|
2017-03-30 22:07:02 +02:00
|
|
|
schedule_new_thread(thread_data->init_thread,
|
2023-10-06 01:47:57 +02:00
|
|
|
init_delay);
|
2016-10-11 18:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
k_sched_unlock();
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
}
|
2016-12-14 21:24:12 +01:00
|
|
|
#endif
|
unified: initial unified kernel implementation
Summary of what this includes:
initialization:
Copy from nano_init.c, with the following changes:
- the main thread is the continuation of the init thread, but an idle
thread is created as well
- _main() initializes threads in groups and starts the EXE group
- the ready queues are initialized
- the main thread is marked as non-essential once the system init is
done
- a weak main() symbol is provided if the application does not provide a
main() function
scheduler:
Not an exhaustive list, but basically provide primitives for:
- adding/removing a thread to/from a wait queue
- adding/removing a thread to/from the ready queue
- marking thread as ready
- locking/unlocking the scheduler
- instead of locking interrupts
- getting/setting thread priority
- checking what state (coop/preempt) a thread is currenlty running in
- rescheduling threads
- finding what thread is the next to run
- yielding/sleeping/aborting sleep
- finding the current thread
threads:
- Add operationns on threads, such as creating and starting them.
standardized handling of kernel object return codes:
- Kernel objects now cause _Swap() to return the following values:
0 => operation successful
-EAGAIN => operation timed out
-Exxxxx => operation failed for another reason
- The thread's swap_data field can be used to return any additional
information required to complete the operation, such as the actual
result of a successful operation.
timeouts:
- same as nano timeouts, renamed to simply 'timeouts'
- the kernel is still tick-based, but objects take timeout values in
ms for forward compatibility with a tickless kernel.
semaphores:
- Port of the nanokernel semaphores, which have the same basic behaviour
as the microkernel ones. Semaphore groups are not yet implemented.
- These semaphores are enhanced in that they accept an initial count and a
count limit. This allows configuring them as binary semaphores, and also
provisioning them without having to "give" the semaphore multiple times
before using them.
mutexes:
- Straight port of the microkernel mutexes. An init function is added to
allow defining them at runtime.
pipes:
- straight port
timers:
- amalgamation of nano and micro timers, with all functionalities
intact.
events:
- re-implementation, using semaphores and workqueues.
mailboxes:
- straight port
message queues:
- straight port of microkernel FIFOs
memory maps:
- straight port
workqueues:
- Basically, have all APIs follow the k_ naming rule, and use the _timeout
subsystem from the unified kernel directory, and not the _nano_timeout
one.
stacks:
- Port of the nanokernel stacks. They can now have multiple threads
pending on them and threads can wait with a timeout.
LIFOs:
- Straight port of the nanokernel LIFOs.
FIFOs:
- Straight port of the nanokernel FIFOs.
Work by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Peter Mitsis <peter.mitsis@windriver.com>
Allan Stephens <allan.stephens@windriver.com>
Benjamin Walsh <benjamin.walsh@windriver.com>
Change-Id: Id3cadb3694484ab2ca467889cfb029be3cd3a7d6
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-09-03 00:55:39 +02:00
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_init_thread_base(struct _thread_base *thread_base, int priority,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t initial_state, unsigned int options)
|
2016-11-22 23:48:13 +01:00
|
|
|
{
|
|
|
|
/* k_q_node is initialized upon first insertion in a list */
|
2021-02-19 02:38:07 +01:00
|
|
|
thread_base->pended_on = NULL;
|
2020-05-27 18:26:57 +02:00
|
|
|
thread_base->user_options = (uint8_t)options;
|
|
|
|
thread_base->thread_state = (uint8_t)initial_state;
|
2016-11-22 23:48:13 +01:00
|
|
|
|
|
|
|
thread_base->prio = priority;
|
|
|
|
|
2019-03-27 02:57:45 +01:00
|
|
|
thread_base->sched_locked = 0U;
|
2016-11-22 23:48:13 +01:00
|
|
|
|
2019-08-17 07:09:30 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
thread_base->is_idle = 0;
|
|
|
|
#endif
|
|
|
|
|
2021-12-01 03:26:26 +01:00
|
|
|
#ifdef CONFIG_TIMESLICE_PER_THREAD
|
|
|
|
thread_base->slice_ticks = 0;
|
|
|
|
thread_base->slice_expired = NULL;
|
|
|
|
#endif
|
|
|
|
|
2016-11-22 23:48:13 +01:00
|
|
|
/* swap_data does not need to be initialized */
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
z_init_thread_timeout(thread_base);
|
2016-11-22 23:48:13 +01:00
|
|
|
}
|
|
|
|
|
2017-08-30 23:34:14 +02:00
|
|
|
FUNC_NORETURN void k_thread_user_mode_enter(k_thread_entry_t entry,
|
|
|
|
void *p1, void *p2, void *p3)
|
|
|
|
{
|
2021-03-26 10:59:08 +01:00
|
|
|
SYS_PORT_TRACING_FUNC(k_thread, user_mode_enter);
|
|
|
|
|
2017-08-30 23:34:14 +02:00
|
|
|
_current->base.user_options |= K_USER;
|
2019-03-08 22:19:05 +01:00
|
|
|
z_thread_essential_clear();
|
2018-06-06 17:45:01 +02:00
|
|
|
#ifdef CONFIG_THREAD_MONITOR
|
|
|
|
_current->entry.pEntry = entry;
|
|
|
|
_current->entry.parameter1 = p1;
|
|
|
|
_current->entry.parameter2 = p2;
|
|
|
|
_current->entry.parameter3 = p3;
|
|
|
|
#endif
|
2017-09-29 13:42:30 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-04-25 01:24:46 +02:00
|
|
|
__ASSERT(z_stack_is_user_capable(_current->stack_obj),
|
|
|
|
"dropping to user mode with kernel-only stack object");
|
2020-10-05 23:54:45 +02:00
|
|
|
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
|
2020-05-08 23:52:12 +02:00
|
|
|
memset(_current->userspace_local_data, 0,
|
|
|
|
sizeof(struct _thread_userspace_local_data));
|
2020-10-24 22:04:04 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
|
|
|
arch_tls_stack_setup(_current,
|
|
|
|
(char *)(_current->stack_info.start +
|
|
|
|
_current->stack_info.size));
|
2020-10-05 23:54:45 +02:00
|
|
|
#endif
|
2019-11-07 21:43:29 +01:00
|
|
|
arch_user_mode_enter(entry, p1, p2, p3);
|
2017-09-29 13:42:30 +02:00
|
|
|
#else
|
|
|
|
/* XXX In this case we do not reset the stack */
|
2019-03-08 22:19:05 +01:00
|
|
|
z_thread_entry(entry, p1, p2, p3);
|
2017-09-29 13:42:30 +02:00
|
|
|
#endif
|
2017-08-30 23:34:14 +02:00
|
|
|
}
|
2019-02-05 18:35:57 +01:00
|
|
|
|
|
|
|
/* These spinlock assertion predicates are defined here because having
|
|
|
|
* them in spinlock.h is a giant header ordering headache.
|
|
|
|
*/
|
2019-12-13 11:24:56 +01:00
|
|
|
#ifdef CONFIG_SPIN_VALIDATE
|
2019-03-14 19:41:21 +01:00
|
|
|
bool z_spin_lock_valid(struct k_spinlock *l)
|
2019-02-05 18:35:57 +01:00
|
|
|
{
|
2019-09-17 07:39:17 +02:00
|
|
|
uintptr_t thread_cpu = l->thread_cpu;
|
|
|
|
|
2021-03-29 23:13:47 +02:00
|
|
|
if (thread_cpu != 0U) {
|
2020-08-21 01:47:11 +02:00
|
|
|
if ((thread_cpu & 3U) == _current_cpu->id) {
|
2019-03-14 19:41:21 +01:00
|
|
|
return false;
|
2019-02-05 18:35:57 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-14 19:41:21 +01:00
|
|
|
return true;
|
2019-02-05 18:35:57 +01:00
|
|
|
}
|
|
|
|
|
2019-03-14 19:41:21 +01:00
|
|
|
bool z_spin_unlock_valid(struct k_spinlock *l)
|
2019-02-05 18:35:57 +01:00
|
|
|
{
|
2019-05-21 05:41:27 +02:00
|
|
|
if (l->thread_cpu != (_current_cpu->id | (uintptr_t)_current)) {
|
2019-03-14 19:41:21 +01:00
|
|
|
return false;
|
2019-02-05 18:35:57 +01:00
|
|
|
}
|
|
|
|
l->thread_cpu = 0;
|
2019-03-14 19:41:21 +01:00
|
|
|
return true;
|
2019-02-05 18:35:57 +01:00
|
|
|
}
|
2019-02-20 19:11:24 +01:00
|
|
|
|
|
|
|
void z_spin_lock_set_owner(struct k_spinlock *l)
|
|
|
|
{
|
2019-05-21 05:41:27 +02:00
|
|
|
l->thread_cpu = _current_cpu->id | (uintptr_t)_current;
|
2019-02-20 19:11:24 +01:00
|
|
|
}
|
2021-02-03 01:35:15 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_KERNEL_COHERENCE
|
|
|
|
bool z_spin_lock_mem_coherent(struct k_spinlock *l)
|
|
|
|
{
|
|
|
|
return arch_mem_coherent((void *)l);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_KERNEL_COHERENCE */
|
|
|
|
|
2019-12-13 11:24:56 +01:00
|
|
|
#endif /* CONFIG_SPIN_VALIDATE */
|
2019-07-10 05:25:39 +02:00
|
|
|
|
2019-05-09 21:55:10 +02:00
|
|
|
int z_impl_k_float_disable(struct k_thread *thread)
|
|
|
|
{
|
2020-05-03 11:03:19 +02:00
|
|
|
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
|
2019-11-07 21:43:29 +01:00
|
|
|
return arch_float_disable(thread);
|
2019-05-09 21:55:10 +02:00
|
|
|
#else
|
2023-08-21 15:30:26 +02:00
|
|
|
ARG_UNUSED(thread);
|
2021-03-23 17:54:15 +01:00
|
|
|
return -ENOTSUP;
|
2020-05-03 11:03:19 +02:00
|
|
|
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
|
2019-05-09 21:55:10 +02:00
|
|
|
}
|
|
|
|
|
2021-02-01 07:16:53 +01:00
|
|
|
int z_impl_k_float_enable(struct k_thread *thread, unsigned int options)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_FPU) && defined(CONFIG_FPU_SHARING)
|
|
|
|
return arch_float_enable(thread, options);
|
|
|
|
#else
|
2023-08-21 15:30:26 +02:00
|
|
|
ARG_UNUSED(thread);
|
|
|
|
ARG_UNUSED(options);
|
2021-02-01 07:16:53 +01:00
|
|
|
return -ENOTSUP;
|
|
|
|
#endif /* CONFIG_FPU && CONFIG_FPU_SHARING */
|
|
|
|
}
|
|
|
|
|
2019-05-09 21:55:10 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
static inline int z_vrfy_k_float_disable(struct k_thread *thread)
|
2019-05-09 21:55:10 +02:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(thread, K_OBJ_THREAD));
|
userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words. So
passing wider values requires splitting them into two registers at
call time. This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.
Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths. So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.
Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types. So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*(). The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function. It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.
This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs. Future commits will port the less testable code.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-06 22:34:31 +02:00
|
|
|
return z_impl_k_float_disable(thread);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_float_disable_mrsh.c>
|
2019-05-09 21:55:10 +02:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2019-11-06 23:17:17 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_IRQ_OFFLOAD
|
2020-12-09 04:08:34 +01:00
|
|
|
/* Make offload_sem visible outside under testing, in order to release
|
|
|
|
* it outside when error happened.
|
|
|
|
*/
|
|
|
|
K_SEM_DEFINE(offload_sem, 1, 1);
|
2019-11-06 23:17:17 +01:00
|
|
|
|
2020-07-10 11:38:48 +02:00
|
|
|
void irq_offload(irq_offload_routine_t routine, const void *parameter)
|
2019-11-06 23:17:17 +01:00
|
|
|
{
|
2022-02-14 23:30:34 +01:00
|
|
|
#ifdef CONFIG_IRQ_OFFLOAD_NESTED
|
|
|
|
arch_irq_offload(routine, parameter);
|
|
|
|
#else
|
2019-11-06 23:17:17 +01:00
|
|
|
k_sem_take(&offload_sem, K_FOREVER);
|
|
|
|
arch_irq_offload(routine, parameter);
|
|
|
|
k_sem_give(&offload_sem);
|
2022-02-14 23:30:34 +01:00
|
|
|
#endif
|
2019-11-06 23:17:17 +01:00
|
|
|
}
|
|
|
|
#endif
|
2020-02-05 19:41:58 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_INIT_STACKS) && defined(CONFIG_THREAD_STACK_INFO)
|
|
|
|
#ifdef CONFIG_STACK_GROWS_UP
|
|
|
|
#error "Unsupported configuration for stack analysis"
|
|
|
|
#endif
|
|
|
|
|
2022-01-28 15:40:37 +01:00
|
|
|
int z_stack_space_get(const uint8_t *stack_start, size_t size, size_t *unused_ptr)
|
2020-02-05 19:41:58 +01:00
|
|
|
{
|
|
|
|
size_t unused = 0;
|
2022-01-28 15:40:37 +01:00
|
|
|
const uint8_t *checked_stack = stack_start;
|
2020-02-05 19:41:58 +01:00
|
|
|
/* Take the address of any local variable as a shallow bound for the
|
|
|
|
* stack pointer. Addresses above it are guaranteed to be
|
|
|
|
* accessible.
|
|
|
|
*/
|
2022-01-28 15:40:37 +01:00
|
|
|
const uint8_t *stack_pointer = (const uint8_t *)&stack_start;
|
2020-02-05 19:41:58 +01:00
|
|
|
|
|
|
|
/* If we are currently running on the stack being analyzed, some
|
|
|
|
* memory management hardware will generate an exception if we
|
|
|
|
* read unused stack memory.
|
|
|
|
*
|
|
|
|
* This never happens when invoked from user mode, as user mode
|
|
|
|
* will always run this function on the privilege elevation stack.
|
|
|
|
*/
|
2022-01-28 15:40:37 +01:00
|
|
|
if ((stack_pointer > stack_start) && (stack_pointer <= (stack_start + size)) &&
|
2020-02-05 19:41:58 +01:00
|
|
|
IS_ENABLED(CONFIG_NO_UNUSED_STACK_INSPECTION)) {
|
|
|
|
/* TODO: We could add an arch_ API call to temporarily
|
|
|
|
* disable the stack checking in the CPU, but this would
|
|
|
|
* need to be properly managed wrt context switches/interrupts
|
|
|
|
*/
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_STACK_SENTINEL)) {
|
|
|
|
/* First 4 bytes of the stack buffer reserved for the
|
|
|
|
* sentinel value, it won't be 0xAAAAAAAA for thread
|
|
|
|
* stacks.
|
|
|
|
*
|
|
|
|
* FIXME: thread->stack_info.start ought to reflect
|
|
|
|
* this!
|
|
|
|
*/
|
|
|
|
checked_stack += 4;
|
|
|
|
size -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
if ((checked_stack[i]) == 0xaaU) {
|
|
|
|
unused++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*unused_ptr = unused;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-28 15:40:37 +01:00
|
|
|
int z_impl_k_thread_stack_space_get(const struct k_thread *thread,
|
|
|
|
size_t *unused_ptr)
|
|
|
|
{
|
|
|
|
return z_stack_space_get((const uint8_t *)thread->stack_info.start,
|
|
|
|
thread->stack_info.size, unused_ptr);
|
|
|
|
}
|
|
|
|
|
2020-02-05 19:41:58 +01:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
int z_vrfy_k_thread_stack_space_get(const struct k_thread *thread,
|
|
|
|
size_t *unused_ptr)
|
|
|
|
{
|
|
|
|
size_t unused;
|
|
|
|
int ret;
|
|
|
|
|
2023-09-27 13:09:45 +02:00
|
|
|
ret = K_SYSCALL_OBJ(thread, K_OBJ_THREAD);
|
2020-02-05 19:41:58 +01:00
|
|
|
CHECKIF(ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = z_impl_k_thread_stack_space_get(thread, &unused);
|
|
|
|
CHECKIF(ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-09-27 12:56:59 +02:00
|
|
|
ret = k_usermode_to_copy(unused_ptr, &unused, sizeof(size_t));
|
2020-02-05 19:41:58 +01:00
|
|
|
CHECKIF(ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#include <syscalls/k_thread_stack_space_get_mrsh.c>
|
|
|
|
#endif /* CONFIG_USERSPACE */
|
|
|
|
#endif /* CONFIG_INIT_STACKS && CONFIG_THREAD_STACK_INFO */
|
2020-03-09 21:59:15 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
static inline k_ticks_t z_vrfy_k_thread_timeout_remaining_ticks(
|
2020-11-16 22:28:59 +01:00
|
|
|
const struct k_thread *t)
|
2020-03-09 21:59:15 +01:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(t, K_OBJ_THREAD));
|
2020-03-09 21:59:15 +01:00
|
|
|
return z_impl_k_thread_timeout_remaining_ticks(t);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_thread_timeout_remaining_ticks_mrsh.c>
|
|
|
|
|
|
|
|
static inline k_ticks_t z_vrfy_k_thread_timeout_expires_ticks(
|
2020-11-16 22:28:59 +01:00
|
|
|
const struct k_thread *t)
|
2020-03-09 21:59:15 +01:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(t, K_OBJ_THREAD));
|
2020-03-09 21:59:15 +01:00
|
|
|
return z_impl_k_thread_timeout_expires_ticks(t);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_thread_timeout_expires_ticks_mrsh.c>
|
|
|
|
#endif
|
2020-08-27 22:54:14 +02:00
|
|
|
|
2020-08-28 01:12:01 +02:00
|
|
|
#ifdef CONFIG_INSTRUMENT_THREAD_SWITCHING
|
2020-08-27 22:54:14 +02:00
|
|
|
void z_thread_mark_switched_in(void)
|
|
|
|
{
|
2021-09-28 16:59:42 +02:00
|
|
|
#if defined(CONFIG_SCHED_THREAD_USAGE) && !defined(CONFIG_USE_SWITCH)
|
|
|
|
z_sched_usage_start(_current);
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 01:12:01 +02:00
|
|
|
#ifdef CONFIG_TRACING
|
2021-03-26 10:59:08 +01:00
|
|
|
SYS_PORT_TRACING_FUNC(k_thread, switched_in);
|
2020-08-28 01:12:01 +02:00
|
|
|
#endif
|
2020-08-27 22:54:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void z_thread_mark_switched_out(void)
|
|
|
|
{
|
2021-09-28 16:59:42 +02:00
|
|
|
#if defined(CONFIG_SCHED_THREAD_USAGE) && !defined(CONFIG_USE_SWITCH)
|
|
|
|
z_sched_usage_stop();
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 01:12:01 +02:00
|
|
|
#ifdef CONFIG_TRACING
|
2022-10-19 00:38:21 +02:00
|
|
|
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
|
|
|
/* Dummy thread won't have TLS set up to run arbitrary code */
|
|
|
|
if (!_current_cpu->current ||
|
|
|
|
(_current_cpu->current->base.thread_state & _THREAD_DUMMY) != 0)
|
|
|
|
return;
|
|
|
|
#endif
|
2021-03-26 10:59:08 +01:00
|
|
|
SYS_PORT_TRACING_FUNC(k_thread, switched_out);
|
2020-08-28 01:12:01 +02:00
|
|
|
#endif
|
2020-08-27 22:54:14 +02:00
|
|
|
}
|
2021-09-28 19:01:06 +02:00
|
|
|
#endif /* CONFIG_INSTRUMENT_THREAD_SWITCHING */
|
2020-08-27 22:54:14 +02:00
|
|
|
|
|
|
|
int k_thread_runtime_stats_get(k_tid_t thread,
|
|
|
|
k_thread_runtime_stats_t *stats)
|
|
|
|
{
|
|
|
|
if ((thread == NULL) || (stats == NULL)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-09-28 19:01:06 +02:00
|
|
|
#ifdef CONFIG_SCHED_THREAD_USAGE
|
2021-12-14 16:56:14 +01:00
|
|
|
z_sched_thread_usage(thread, stats);
|
|
|
|
#else
|
|
|
|
*stats = (k_thread_runtime_stats_t) {};
|
2021-09-28 19:01:06 +02:00
|
|
|
#endif
|
2020-08-27 22:54:14 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int k_thread_runtime_stats_all_get(k_thread_runtime_stats_t *stats)
|
|
|
|
{
|
2021-12-15 04:26:22 +01:00
|
|
|
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
|
|
|
|
k_thread_runtime_stats_t tmp_stats;
|
|
|
|
#endif
|
|
|
|
|
2020-08-27 22:54:14 +02:00
|
|
|
if (stats == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-09-28 19:01:06 +02:00
|
|
|
*stats = (k_thread_runtime_stats_t) {};
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_THREAD_USAGE_ALL
|
2021-12-15 04:26:22 +01:00
|
|
|
/* Retrieve the usage stats for each core and amalgamate them. */
|
|
|
|
|
2022-10-18 16:45:13 +02:00
|
|
|
unsigned int num_cpus = arch_num_cpus();
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < num_cpus; i++) {
|
2021-12-15 04:26:22 +01:00
|
|
|
z_sched_cpu_usage(i, &tmp_stats);
|
|
|
|
|
|
|
|
stats->execution_cycles += tmp_stats.execution_cycles;
|
|
|
|
stats->total_cycles += tmp_stats.total_cycles;
|
|
|
|
#ifdef CONFIG_SCHED_THREAD_USAGE_ANALYSIS
|
2022-05-03 17:39:39 +02:00
|
|
|
stats->current_cycles += tmp_stats.current_cycles;
|
2021-12-15 04:26:22 +01:00
|
|
|
stats->peak_cycles += tmp_stats.peak_cycles;
|
|
|
|
stats->average_cycles += tmp_stats.average_cycles;
|
|
|
|
#endif
|
|
|
|
stats->idle_cycles += tmp_stats.idle_cycles;
|
|
|
|
}
|
2021-09-28 19:01:06 +02:00
|
|
|
#endif
|
2020-08-27 22:54:14 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|