From: "Richard Weinberger (sigma star gmbh)" <rw@kernel.org>
To: xenomai@lists.linux.dev
Cc: upstream+xenomai@sigma-star.at, Richard Weinberger <richard@nod.at>
Subject: [PATCH 6/7] lib/alchemy: Require a Xenomai task only when actually waiting
Date: Wed, 25 Nov 2026 22:34:18 +0100 [thread overview]
Message-ID: <20261125213419.2363742-7-rw@kernel.org> (raw)
In-Reply-To: <20261125213419.2363742-1-rw@kernel.org>
From: Richard Weinberger <richard@nod.at>
The queue, buffer and heap services refuse non-polling calls from
threads without a Copperplate TCB upfront, even if the request can be
satisfied immediately. The TCB is only needed to wait, so check for it
there.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
lib/alchemy/buffer.c | 24 ++++++++++++++----------
lib/alchemy/heap.c | 12 +++++++-----
lib/alchemy/queue.c | 24 ++++++++++++++----------
3 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index 4f826fb27..66e37413c 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -424,8 +424,8 @@ out:
* waiting for data. In such event, @a bf is no more valid upon return
* of this service.
*
- * - -EPERM is returned if this service was not called from a Xenomai
- * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
+ * - -EPERM is returned if this service should block, but was not
+ * called from a Xenomai task.
*
* @note A short read (i.e. fewer bytes returned than requested by @a
* len) may happen whenever a pathological use of the buffer is
@@ -468,9 +468,6 @@ ssize_t rt_buffer_read_timed(RT_BUFFER *bf,
if (len == 0)
return 0;
- if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
- return -EPERM;
-
CANCEL_DEFER(svc);
bcb = get_alchemy_buffer(bf, &syns, &ret);
@@ -547,6 +544,11 @@ redo:
goto redo;
}
+ if (!threadobj_current_p()) {
+ ret = -EPERM;
+ goto done;
+ }
+
if (wait == NULL)
wait = threadobj_prepare_wait(struct alchemy_buffer_wait);
@@ -664,8 +666,8 @@ out:
* waiting for buffer space. In such event, @a bf is no more valid
* upon return of this service.
*
- * - -EPERM is returned if this service was not called from a Xenomai
- * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
+ * - -EPERM is returned if this service should block, but was not
+ * called from a Xenomai task.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -687,9 +689,6 @@ ssize_t rt_buffer_write_timed(RT_BUFFER *bf,
if (len == 0)
return 0;
- if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
- return -EPERM;
-
CANCEL_DEFER(svc);
bcb = get_alchemy_buffer(bf, &syns, &ret);
@@ -754,6 +753,11 @@ ssize_t rt_buffer_write_timed(RT_BUFFER *bf,
goto done;
}
+ if (!threadobj_current_p()) {
+ ret = -EPERM;
+ goto done;
+ }
+
if (wait == NULL)
wait = threadobj_prepare_wait(struct alchemy_buffer_wait);
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index fb3424f5f..06f2598ef 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -408,8 +408,8 @@ out:
* waiting for a block. In such event, @a heap is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service was not called from a Xenomai
- * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
+ * - -EPERM is returned if this service should block, but was not
+ * called from a Xenomai task.
*
* @apitags{xthread-nowait, switch-primary}
*
@@ -431,9 +431,6 @@ int rt_heap_alloc_timed(RT_HEAP *heap,
void *p = NULL;
int ret = 0;
- if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
- return -EPERM;
-
CANCEL_DEFER(svc);
hcb = get_alchemy_heap(heap, &syns, &ret);
@@ -468,6 +465,11 @@ int rt_heap_alloc_timed(RT_HEAP *heap,
goto done;
}
+ if (!threadobj_current_p()) {
+ ret = -EPERM;
+ goto done;
+ }
+
wait = threadobj_prepare_wait(struct alchemy_heap_wait);
wait->size = size;
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index e91973920..18ef51f39 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -792,8 +792,8 @@ out:
* waiting for a message. In such event, @a q is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service was not called from a Xenomai
- * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
+ * - -EPERM is returned if this service should block, but was not
+ * called from a Xenomai task.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -808,9 +808,6 @@ ssize_t rt_queue_receive_timed(RT_QUEUE *queue, void **bufp,
ssize_t ret;
int err = 0;
- if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
- return -EPERM;
-
CANCEL_DEFER(svc);
qcb = get_alchemy_queue(queue, &syns, &err);
@@ -834,6 +831,11 @@ wait:
goto done;
}
+ if (!threadobj_current_p()) {
+ ret = -EPERM;
+ goto done;
+ }
+
wait = threadobj_prepare_wait(struct alchemy_queue_wait);
wait->local_bufsz = 0;
@@ -952,8 +954,8 @@ out:
* waiting for a message. In such event, @a q is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service was not called from a Xenomai
- * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
+ * - -EPERM is returned if this service should block, but was not
+ * called from a Xenomai task.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -969,9 +971,6 @@ ssize_t rt_queue_read_timed(RT_QUEUE *queue,
ssize_t ret;
int err = 0;
- if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
- return -EPERM;
-
if (size == 0)
return 0;
@@ -995,6 +994,11 @@ wait:
goto done;
}
+ if (!threadobj_current_p()) {
+ ret = -EPERM;
+ goto done;
+ }
+
wait = threadobj_prepare_wait(struct alchemy_queue_wait);
wait->local_buf = buf;
wait->local_bufsz = size;
--
2.55.0
next prev parent reply other threads:[~2026-11-25 21:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:34 [PATCH 0/7] Alchemy: Fix calling context checks and documentation Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 1/7] lib/alchemy/mutex: Allow any Xenomai thread to acquire a mutex Richard Weinberger (sigma star gmbh)
2026-11-26 6:14 ` Jan Kiszka
2026-11-26 7:53 ` Richard Weinberger
2026-11-25 21:34 ` [PATCH 2/7] lib/alchemy/task: Allow rt_task_yield() from any thread Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 3/7] lib/alchemy: Document the actual calling context requirements Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 4/7] lib/alchemy/pipe: Do not require a Xenomai task for blocking reads Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 5/7] lib/alchemy/event: Require a Xenomai task only for waiting over Mercury Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` Richard Weinberger (sigma star gmbh) [this message]
2026-11-26 6:09 ` [PATCH 6/7] lib/alchemy: Require a Xenomai task only when actually waiting Jan Kiszka
2026-11-25 21:34 ` [PATCH 7/7] testsuite/smokey/alchemytests: Test Alchemy services from POSIX threads Richard Weinberger (sigma star gmbh)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125213419.2363742-7-rw@kernel.org \
--to=rw@kernel.org \
--cc=richard@nod.at \
--cc=upstream+xenomai@sigma-star.at \
--cc=xenomai@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.