2017-02-21 13:50:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2016 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @brief dynamic-size QUEUE object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/kernel_structs.h>
|
2021-04-19 05:24:40 +02:00
|
|
|
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/toolchain.h>
|
2023-08-29 19:03:12 +02:00
|
|
|
#include <wait_q.h>
|
2017-02-21 13:50:42 +01:00
|
|
|
#include <ksched.h>
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/init.h>
|
2023-09-27 00:46:01 +02:00
|
|
|
#include <zephyr/internal/syscall_handler.h>
|
2018-09-05 19:13:38 +02:00
|
|
|
#include <kernel_internal.h>
|
2022-05-06 11:04:23 +02:00
|
|
|
#include <zephyr/sys/check.h>
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
struct alloc_node {
|
|
|
|
sys_sfnode_t node;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
void *z_queue_node_peek(sys_sfnode_t *node, bool needs_free)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
if ((node != NULL) && (sys_sfnode_flags_get(node) != (uint8_t)0)) {
|
2018-04-27 22:21:22 +02:00
|
|
|
/* If the flag is set, then the enqueue operation for this item
|
|
|
|
* did a behind-the scenes memory allocation of an alloc_node
|
|
|
|
* struct, which is what got put in the queue. Free it and pass
|
|
|
|
* back the data pointer.
|
|
|
|
*/
|
|
|
|
struct alloc_node *anode;
|
|
|
|
|
|
|
|
anode = CONTAINER_OF(node, struct alloc_node, node);
|
|
|
|
ret = anode->data;
|
|
|
|
if (needs_free) {
|
|
|
|
k_free(anode);
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-22 04:13:01 +02:00
|
|
|
/* Data was directly placed in the queue, the first word
|
2018-04-27 22:21:22 +02:00
|
|
|
* reserved for the linked list. User mode isn't allowed to
|
|
|
|
* do this, although it can get data sent this way.
|
|
|
|
*/
|
|
|
|
ret = (void *)node;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_impl_k_queue_init(struct k_queue *queue)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
2018-04-27 22:21:22 +02:00
|
|
|
sys_sflist_init(&queue->data_q);
|
2018-07-25 22:01:54 +02:00
|
|
|
queue->lock = (struct k_spinlock) {};
|
2019-03-08 22:19:05 +01:00
|
|
|
z_waitq_init(&queue->wait_q);
|
2017-08-21 09:49:29 +02:00
|
|
|
#if defined(CONFIG_POLL)
|
|
|
|
sys_dlist_init(&queue->poll_events);
|
|
|
|
#endif
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_INIT(k_queue, queue);
|
|
|
|
|
2023-09-26 23:32:13 +02:00
|
|
|
k_object_init(queue);
|
2018-04-27 22:21:22 +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_queue_init(struct k_queue *queue)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(queue, K_OBJ_QUEUE));
|
2019-03-08 22:19:05 +01:00
|
|
|
z_impl_k_queue_init(queue);
|
2017-02-21 13:50:42 +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_queue_init_mrsh.c>
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2017-02-21 13:50:42 +01:00
|
|
|
|
|
|
|
static void prepare_thread_to_run(struct k_thread *thread, void *data)
|
|
|
|
{
|
2019-09-22 01:25:56 +02:00
|
|
|
z_thread_return_value_set_with_data(thread, 0, data);
|
2020-01-17 19:43:26 +01:00
|
|
|
z_ready_thread(thread);
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline void handle_poll_events(struct k_queue *queue, uint32_t state)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
2020-06-02 17:34:12 +02:00
|
|
|
#ifdef CONFIG_POLL
|
2019-03-08 22:19:05 +01:00
|
|
|
z_handle_obj_poll_events(&queue->poll_events, state);
|
2023-08-21 15:30:26 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(queue);
|
|
|
|
ARG_UNUSED(state);
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_POLL */
|
2020-06-02 17:34:12 +02:00
|
|
|
}
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_impl_k_queue_cancel_wait(struct k_queue *queue)
|
kernel: queue, fifo: Add cancel_wait operation.
Currently, a queue/fifo getter chooses how long to wait for an
element. But there are scenarios when putter would know better,
there should be a way to expire getter's timeout to make it run
again. k_queue_cancel_wait() and k_fifo_cancel_wait() functions
do just that. They cause corresponding *_get() functions to return
with NULL value, as if timeout expired on getter's side (even
K_FOREVER).
This can be used to signal out of band conditions from putter to
getter, e.g. end of processing, error, configuration change, etc.
A specific event would be communicated to getter by other means
(e.g. using existing shared context structures).
Without this call, achieving the same effect would require e.g.
calling k_fifo_put() with a pointer to a special sentinal memory
structure - such structure would need to be allocated somewhere
and somehow, and getter would need to recognize it from a normal
data item. Having cancel_wait() functions offers an elegant
alternative. From this perspective, these calls can be seen as
an equivalent to e.g. k_fifo_put(fifo, NULL), except that such
call won't work in practice.
Change-Id: I47b7f690dc325a80943082bcf5345c41649e7024
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-25 16:54:31 +02:00
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_queue, cancel_wait, queue);
|
|
|
|
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&queue->lock);
|
kernel: queue, fifo: Add cancel_wait operation.
Currently, a queue/fifo getter chooses how long to wait for an
element. But there are scenarios when putter would know better,
there should be a way to expire getter's timeout to make it run
again. k_queue_cancel_wait() and k_fifo_cancel_wait() functions
do just that. They cause corresponding *_get() functions to return
with NULL value, as if timeout expired on getter's side (even
K_FOREVER).
This can be used to signal out of band conditions from putter to
getter, e.g. end of processing, error, configuration change, etc.
A specific event would be communicated to getter by other means
(e.g. using existing shared context structures).
Without this call, achieving the same effect would require e.g.
calling k_fifo_put() with a pointer to a special sentinal memory
structure - such structure would need to be allocated somewhere
and somehow, and getter would need to recognize it from a normal
data item. Having cancel_wait() functions offers an elegant
alternative. From this perspective, these calls can be seen as
an equivalent to e.g. k_fifo_put(fifo, NULL), except that such
call won't work in practice.
Change-Id: I47b7f690dc325a80943082bcf5345c41649e7024
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-25 16:54:31 +02:00
|
|
|
struct k_thread *first_pending_thread;
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
first_pending_thread = z_unpend_first_thread(&queue->wait_q);
|
kernel: queue, fifo: Add cancel_wait operation.
Currently, a queue/fifo getter chooses how long to wait for an
element. But there are scenarios when putter would know better,
there should be a way to expire getter's timeout to make it run
again. k_queue_cancel_wait() and k_fifo_cancel_wait() functions
do just that. They cause corresponding *_get() functions to return
with NULL value, as if timeout expired on getter's side (even
K_FOREVER).
This can be used to signal out of band conditions from putter to
getter, e.g. end of processing, error, configuration change, etc.
A specific event would be communicated to getter by other means
(e.g. using existing shared context structures).
Without this call, achieving the same effect would require e.g.
calling k_fifo_put() with a pointer to a special sentinal memory
structure - such structure would need to be allocated somewhere
and somehow, and getter would need to recognize it from a normal
data item. Having cancel_wait() functions offers an elegant
alternative. From this perspective, these calls can be seen as
an equivalent to e.g. k_fifo_put(fifo, NULL), except that such
call won't work in practice.
Change-Id: I47b7f690dc325a80943082bcf5345c41649e7024
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-25 16:54:31 +02:00
|
|
|
|
2018-09-17 18:39:51 +02:00
|
|
|
if (first_pending_thread != NULL) {
|
kernel: queue, fifo: Add cancel_wait operation.
Currently, a queue/fifo getter chooses how long to wait for an
element. But there are scenarios when putter would know better,
there should be a way to expire getter's timeout to make it run
again. k_queue_cancel_wait() and k_fifo_cancel_wait() functions
do just that. They cause corresponding *_get() functions to return
with NULL value, as if timeout expired on getter's side (even
K_FOREVER).
This can be used to signal out of band conditions from putter to
getter, e.g. end of processing, error, configuration change, etc.
A specific event would be communicated to getter by other means
(e.g. using existing shared context structures).
Without this call, achieving the same effect would require e.g.
calling k_fifo_put() with a pointer to a special sentinal memory
structure - such structure would need to be allocated somewhere
and somehow, and getter would need to recognize it from a normal
data item. Having cancel_wait() functions offers an elegant
alternative. From this perspective, these calls can be seen as
an equivalent to e.g. k_fifo_put(fifo, NULL), except that such
call won't work in practice.
Change-Id: I47b7f690dc325a80943082bcf5345c41649e7024
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-25 16:54:31 +02:00
|
|
|
prepare_thread_to_run(first_pending_thread, NULL);
|
|
|
|
}
|
|
|
|
|
2020-06-02 17:34:12 +02:00
|
|
|
handle_poll_events(queue, K_POLL_STATE_CANCELLED);
|
2019-03-08 22:19:05 +01:00
|
|
|
z_reschedule(&queue->lock, key);
|
kernel: queue, fifo: Add cancel_wait operation.
Currently, a queue/fifo getter chooses how long to wait for an
element. But there are scenarios when putter would know better,
there should be a way to expire getter's timeout to make it run
again. k_queue_cancel_wait() and k_fifo_cancel_wait() functions
do just that. They cause corresponding *_get() functions to return
with NULL value, as if timeout expired on getter's side (even
K_FOREVER).
This can be used to signal out of band conditions from putter to
getter, e.g. end of processing, error, configuration change, etc.
A specific event would be communicated to getter by other means
(e.g. using existing shared context structures).
Without this call, achieving the same effect would require e.g.
calling k_fifo_put() with a pointer to a special sentinal memory
structure - such structure would need to be allocated somewhere
and somehow, and getter would need to recognize it from a normal
data item. Having cancel_wait() functions offers an elegant
alternative. From this perspective, these calls can be seen as
an equivalent to e.g. k_fifo_put(fifo, NULL), except that such
call won't work in practice.
Change-Id: I47b7f690dc325a80943082bcf5345c41649e7024
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-04-25 16:54:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 22:21:22 +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_queue_cancel_wait(struct k_queue *queue)
|
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_cancel_wait(queue);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_queue_cancel_wait_mrsh.c>
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-04-27 22:21:22 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static int32_t queue_insert(struct k_queue *queue, void *prev, void *data,
|
2020-10-22 03:07:57 +02:00
|
|
|
bool alloc, bool is_append)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
|
|
|
struct k_thread *first_pending_thread;
|
2020-10-22 03:07:57 +02:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&queue->lock);
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, queue_insert, queue, alloc);
|
|
|
|
|
2020-10-22 03:07:57 +02:00
|
|
|
if (is_append) {
|
|
|
|
prev = sys_sflist_peek_tail(&queue->data_q);
|
|
|
|
}
|
2019-03-08 22:19:05 +01:00
|
|
|
first_pending_thread = z_unpend_first_thread(&queue->wait_q);
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2018-09-17 18:39:51 +02:00
|
|
|
if (first_pending_thread != NULL) {
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_queue, queue_insert, queue, alloc, K_FOREVER);
|
|
|
|
|
2017-02-21 13:50:42 +01:00
|
|
|
prepare_thread_to_run(first_pending_thread, data);
|
2019-03-08 22:19:05 +01:00
|
|
|
z_reschedule(&queue->lock, key);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, queue_insert, queue, alloc, 0);
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
return 0;
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
2017-07-13 11:43:59 +02:00
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
/* Only need to actually allocate if no threads are pending */
|
|
|
|
if (alloc) {
|
|
|
|
struct alloc_node *anode;
|
|
|
|
|
|
|
|
anode = z_thread_malloc(sizeof(*anode));
|
2018-09-17 18:39:51 +02:00
|
|
|
if (anode == NULL) {
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spin_unlock(&queue->lock, key);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, queue_insert, queue, alloc,
|
|
|
|
-ENOMEM);
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
anode->data = data;
|
|
|
|
sys_sfnode_init(&anode->node, 0x1);
|
|
|
|
data = anode;
|
|
|
|
} else {
|
|
|
|
sys_sfnode_init(data, 0x0);
|
|
|
|
}
|
2017-07-13 11:43:59 +02:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_queue, queue_insert, queue, alloc, K_FOREVER);
|
|
|
|
|
2020-06-02 17:34:12 +02:00
|
|
|
sys_sflist_insert(&queue->data_q, prev, data);
|
kernel: Scheduler refactoring: use _reschedule_*() always
There was a somewhat promiscuous pattern in the kernel where IPC
mechanisms would do something that might effect the current thread
choice, then check _must_switch_threads() (or occasionally
__must_switch_threads -- don't ask, the distinction is being replaced
by real English words), sometimes _is_in_isr() (but not always, even
in contexts where that looks like it would be a mistake), and then
call _Swap() if everything is OK, otherwise releasing the irq_lock().
Sometimes this was done directly, sometimes via the inverted test,
sometimes (poll, heh) by doing the test when the thread state was
modified and then needlessly passing the result up the call stack to
the point of the _Swap().
And some places were just calling _reschedule_threads(), which did all
this already.
Unify all this madness. The old _reschedule_threads() function has
split into two variants: _reschedule_yield() and
_reschedule_noyield(). The latter is the "normal" one that respects
the cooperative priority of the current thread (i.e. it won't switch
out even if there is a higher priority thread ready -- the current
thread has to pend itself first), the former is used in the handful of
places where code was doing a swap unconditionally, just to preserve
precise behavior across the refactor. I'm not at all convinced it
should exist...
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-03-26 19:54:40 +02:00
|
|
|
handle_poll_events(queue, K_POLL_STATE_DATA_AVAILABLE);
|
2019-03-08 22:19:05 +01:00
|
|
|
z_reschedule(&queue->lock, key);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, queue_insert, queue, alloc, 0);
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void k_queue_insert(struct k_queue *queue, void *prev, void *data)
|
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, insert, queue);
|
|
|
|
|
2020-10-22 03:07:57 +02:00
|
|
|
(void)queue_insert(queue, prev, data, false, false);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, insert, queue);
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void k_queue_append(struct k_queue *queue, void *data)
|
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, append, queue);
|
|
|
|
|
2020-10-22 03:07:57 +02:00
|
|
|
(void)queue_insert(queue, NULL, data, false, true);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, append, queue);
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void k_queue_prepend(struct k_queue *queue, void *data)
|
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, prepend, queue);
|
|
|
|
|
2020-10-22 03:07:57 +02:00
|
|
|
(void)queue_insert(queue, NULL, data, false, false);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, prepend, queue);
|
2018-04-27 22:21:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
int32_t z_impl_k_queue_alloc_append(struct k_queue *queue, void *data)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, alloc_append, queue);
|
|
|
|
|
|
|
|
int32_t ret = queue_insert(queue, NULL, data, true, true);
|
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, alloc_append, queue, ret);
|
|
|
|
|
|
|
|
return ret;
|
2018-04-27 22:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline int32_t z_vrfy_k_queue_alloc_append(struct k_queue *queue,
|
2020-10-22 03:07:57 +02:00
|
|
|
void *data)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_alloc_append(queue, data);
|
2018-04-27 22:21:22 +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_queue_alloc_append_mrsh.c>
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-04-27 22:21:22 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
int32_t z_impl_k_queue_alloc_prepend(struct k_queue *queue, void *data)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, alloc_prepend, queue);
|
|
|
|
|
|
|
|
int32_t ret = queue_insert(queue, NULL, data, true, false);
|
2020-10-22 03:07:57 +02:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, alloc_prepend, queue, ret);
|
|
|
|
|
|
|
|
return ret;
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline int32_t z_vrfy_k_queue_alloc_prepend(struct k_queue *queue,
|
2020-10-22 03:07:57 +02:00
|
|
|
void *data)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_alloc_prepend(queue, data);
|
2018-04-27 22:21:22 +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_queue_alloc_prepend_mrsh.c>
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2018-04-27 22:21:22 +02:00
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
int k_queue_append_list(struct k_queue *queue, void *head, void *tail)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, append_list, queue);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
/* invalid head or tail of list */
|
|
|
|
CHECKIF(head == NULL || tail == NULL) {
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, append_list, queue, -EINVAL);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&queue->lock);
|
2018-11-14 01:26:56 +01:00
|
|
|
struct k_thread *thread = NULL;
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2018-12-16 21:48:29 +01:00
|
|
|
if (head != NULL) {
|
2019-03-08 22:19:05 +01:00
|
|
|
thread = z_unpend_first_thread(&queue->wait_q);
|
2018-11-14 01:26:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((head != NULL) && (thread != NULL)) {
|
2017-02-21 13:50:42 +01:00
|
|
|
prepare_thread_to_run(thread, head);
|
|
|
|
head = *(void **)head;
|
2019-03-08 22:19:05 +01:00
|
|
|
thread = z_unpend_first_thread(&queue->wait_q);
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
2018-09-17 18:39:51 +02:00
|
|
|
if (head != NULL) {
|
2018-04-27 22:21:22 +02:00
|
|
|
sys_sflist_append_list(&queue->data_q, head, tail);
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, append_list, queue, 0);
|
|
|
|
|
kernel: Scheduler refactoring: use _reschedule_*() always
There was a somewhat promiscuous pattern in the kernel where IPC
mechanisms would do something that might effect the current thread
choice, then check _must_switch_threads() (or occasionally
__must_switch_threads -- don't ask, the distinction is being replaced
by real English words), sometimes _is_in_isr() (but not always, even
in contexts where that looks like it would be a mistake), and then
call _Swap() if everything is OK, otherwise releasing the irq_lock().
Sometimes this was done directly, sometimes via the inverted test,
sometimes (poll, heh) by doing the test when the thread state was
modified and then needlessly passing the result up the call stack to
the point of the _Swap().
And some places were just calling _reschedule_threads(), which did all
this already.
Unify all this madness. The old _reschedule_threads() function has
split into two variants: _reschedule_yield() and
_reschedule_noyield(). The latter is the "normal" one that respects
the cooperative priority of the current thread (i.e. it won't switch
out even if there is a higher priority thread ready -- the current
thread has to pend itself first), the former is used in the handful of
places where code was doing a swap unconditionally, just to preserve
precise behavior across the refactor. I'm not at all convinced it
should exist...
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-03-26 19:54:40 +02:00
|
|
|
handle_poll_events(queue, K_POLL_STATE_DATA_AVAILABLE);
|
2019-03-08 22:19:05 +01:00
|
|
|
z_reschedule(&queue->lock, key);
|
2019-06-16 15:53:55 +02:00
|
|
|
return 0;
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
2019-06-16 15:53:55 +02:00
|
|
|
int ret;
|
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, merge_slist, queue);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
/* list must not be empty */
|
|
|
|
CHECKIF(sys_slist_is_empty(list)) {
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, merge_slist, queue, -EINVAL);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-02-21 13:50:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* note: this works as long as:
|
|
|
|
* - the slist implementation keeps the next pointer as the first
|
|
|
|
* field of the node object type
|
|
|
|
* - list->tail->next = NULL.
|
2018-04-27 22:21:22 +02:00
|
|
|
* - sflist implementation only differs from slist by stuffing
|
|
|
|
* flag bytes in the lower order bits of the data pointer
|
|
|
|
* - source list is really an slist and not an sflist with flags set
|
2017-02-21 13:50:42 +01:00
|
|
|
*/
|
2019-06-16 15:53:55 +02:00
|
|
|
ret = k_queue_append_list(queue, list->head, list->tail);
|
|
|
|
CHECKIF(ret != 0) {
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, merge_slist, queue, ret);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2017-02-21 13:50:42 +01:00
|
|
|
sys_slist_init(list);
|
2019-06-16 15:53:55 +02:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, merge_slist, queue, 0);
|
|
|
|
|
2019-06-16 15:53:55 +02:00
|
|
|
return 0;
|
2017-02-21 13:50:42 +01: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
|
|
|
void *z_impl_k_queue_get(struct k_queue *queue, k_timeout_t timeout)
|
2017-02-21 13:50:42 +01:00
|
|
|
{
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spinlock_key_t key = k_spin_lock(&queue->lock);
|
2017-02-21 13:50:42 +01:00
|
|
|
void *data;
|
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, get, queue, timeout);
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
if (likely(!sys_sflist_is_empty(&queue->data_q))) {
|
|
|
|
sys_sfnode_t *node;
|
|
|
|
|
|
|
|
node = sys_sflist_get_not_empty(&queue->data_q);
|
|
|
|
data = z_queue_node_peek(node, true);
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spin_unlock(&queue->lock, key);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, get, queue, timeout, data);
|
|
|
|
|
2017-02-21 13:50:42 +01:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_queue, get, queue, timeout);
|
|
|
|
|
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(timeout, K_NO_WAIT)) {
|
2018-07-25 22:01:54 +02:00
|
|
|
k_spin_unlock(&queue->lock, key);
|
2021-03-26 11:19:35 +01:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, get, queue, timeout, NULL);
|
|
|
|
|
2017-02-21 13:50:42 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
int ret = z_pend_curr(&queue->lock, key, &queue->wait_q, timeout);
|
2017-02-21 13:50:42 +01:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, get, queue, timeout,
|
|
|
|
(ret != 0) ? NULL : _current->base.swap_data);
|
|
|
|
|
2018-10-25 08:39:04 +02:00
|
|
|
return (ret != 0) ? NULL : _current->base.swap_data;
|
2017-02-21 13:50:42 +01:00
|
|
|
}
|
2018-04-27 22:21:22 +02:00
|
|
|
|
2021-03-26 11:19:35 +01:00
|
|
|
bool k_queue_remove(struct k_queue *queue, void *data)
|
|
|
|
{
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, remove, queue);
|
|
|
|
|
|
|
|
bool ret = sys_sflist_find_and_remove(&queue->data_q, (sys_sfnode_t *)data);
|
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, remove, queue, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool k_queue_unique_append(struct k_queue *queue, void *data)
|
|
|
|
{
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, unique_append, queue);
|
|
|
|
|
|
|
|
sys_sfnode_t *test;
|
|
|
|
|
|
|
|
SYS_SFLIST_FOR_EACH_NODE(&queue->data_q, test) {
|
|
|
|
if (test == (sys_sfnode_t *) data) {
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, unique_append, queue, false);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
k_queue_append(queue, data);
|
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, unique_append, queue, true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *z_impl_k_queue_peek_head(struct k_queue *queue)
|
|
|
|
{
|
|
|
|
void *ret = z_queue_node_peek(sys_sflist_peek_head(&queue->data_q), false);
|
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_queue, peek_head, queue, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *z_impl_k_queue_peek_tail(struct k_queue *queue)
|
|
|
|
{
|
|
|
|
void *ret = z_queue_node_peek(sys_sflist_peek_tail(&queue->data_q), false);
|
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC(k_queue, peek_tail, queue, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:21:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
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 inline void *z_vrfy_k_queue_get(struct k_queue *queue,
|
|
|
|
k_timeout_t timeout)
|
2018-04-27 22:21:22 +02:00
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_get(queue, timeout);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_queue_get_mrsh.c>
|
2018-04-27 22:21:22 +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
|
|
|
static inline int z_vrfy_k_queue_is_empty(struct k_queue *queue)
|
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_is_empty(queue);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_queue_is_empty_mrsh.c>
|
|
|
|
|
|
|
|
static inline void *z_vrfy_k_queue_peek_head(struct k_queue *queue)
|
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_peek_head(queue);
|
|
|
|
}
|
|
|
|
#include <syscalls/k_queue_peek_head_mrsh.c>
|
2018-04-27 22:21:22 +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
|
|
|
static inline void *z_vrfy_k_queue_peek_tail(struct k_queue *queue)
|
|
|
|
{
|
2023-09-27 13:20:28 +02:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(queue, K_OBJ_QUEUE));
|
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_queue_peek_tail(queue);
|
2018-04-27 22:21:22 +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_queue_peek_tail_mrsh.c>
|
2018-04-27 22:21:22 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_USERSPACE */
|
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_FIFO
|
|
|
|
struct k_obj_type _obj_type_fifo;
|
|
|
|
|
|
|
|
static int init_fifo_obj_core_list(void)
|
|
|
|
{
|
|
|
|
/* Initialize fifo object type */
|
|
|
|
|
|
|
|
z_obj_type_init(&_obj_type_fifo, K_OBJ_TYPE_FIFO_ID,
|
|
|
|
offsetof(struct k_fifo, obj_core));
|
|
|
|
|
|
|
|
/* Initialize and link statically defined fifos */
|
|
|
|
|
|
|
|
STRUCT_SECTION_FOREACH(k_fifo, fifo) {
|
|
|
|
k_obj_core_init_and_link(K_OBJ_CORE(fifo), &_obj_type_fifo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(init_fifo_obj_core_list, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_OBJ_CORE_FIFO */
|
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_LIFO
|
|
|
|
struct k_obj_type _obj_type_lifo;
|
|
|
|
|
|
|
|
static int init_lifo_obj_core_list(void)
|
|
|
|
{
|
|
|
|
/* Initialize lifo object type */
|
|
|
|
|
|
|
|
z_obj_type_init(&_obj_type_lifo, K_OBJ_TYPE_LIFO_ID,
|
|
|
|
offsetof(struct k_lifo, obj_core));
|
|
|
|
|
|
|
|
/* Initialize and link statically defined lifo */
|
|
|
|
|
|
|
|
STRUCT_SECTION_FOREACH(k_lifo, lifo) {
|
|
|
|
k_obj_core_init_and_link(K_OBJ_CORE(lifo), &_obj_type_lifo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(init_lifo_obj_core_list, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
|
2024-03-08 12:00:10 +01:00
|
|
|
#endif /* CONFIG_OBJ_CORE_LIFO */
|