All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: xenomai@xenomai.org
Subject: [PATCH 03/17] cobalt/thread: Privatize xnthread_map to map_kthread
Date: Fri, 11 Jun 2021 20:05:29 +0200	[thread overview]
Message-ID: <2d91aa1b719e834b33630693b96489e2dc4fe6e4.1623434743.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1623434743.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

No user outside of the core, no need to export it. Move the code around
so that we can easily use it without forward declarations.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 include/cobalt/kernel/thread.h |   3 -
 kernel/cobalt/thread.c         | 239 ++++++++++++++-------------------
 2 files changed, 98 insertions(+), 144 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 2d6ce9053..b79cb8429 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -514,9 +514,6 @@ void xnthread_signal(struct xnthread *thread, int sig, int arg);
 
 void xnthread_pin_initial(struct xnthread *thread);
 
-int xnthread_map(struct xnthread *thread,
-		 struct completion *done);
-
 void xnthread_call_mayday(struct xnthread *thread, int reason);
 
 static inline void xnthread_get_resource(struct xnthread *curr)
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 1f8e1119a..db68833c6 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -84,6 +84,103 @@ static inline void enlist_new_thread(struct xnthread *thread)
 	xnvfile_touch_tag(&nkthreadlist_tag);
 }
 
+struct parent_wakeup_request {
+	struct pipeline_inband_work inband_work; /* Must be first. */
+	struct completion *done;
+};
+
+static void do_parent_wakeup(struct pipeline_inband_work *inband_work)
+{
+	struct parent_wakeup_request *rq;
+
+	rq = container_of(inband_work, struct parent_wakeup_request, inband_work);
+	complete(rq->done);
+}
+
+static inline void wakeup_parent(struct completion *done)
+{
+	struct parent_wakeup_request wakework = {
+		.inband_work = PIPELINE_INBAND_WORK_INITIALIZER(wakework,
+					do_parent_wakeup),
+		.done = done,
+	};
+
+	trace_cobalt_lostage_request("wakeup", current);
+
+	pipeline_post_inband_work(&wakework);
+}
+
+static inline void init_kthread_info(struct xnthread *thread)
+{
+	struct cobalt_threadinfo *p;
+
+	p = pipeline_current();
+	p->thread = thread;
+	p->process = NULL;
+}
+
+static int map_kthread(struct xnthread *thread, struct completion *done)
+{
+	int ret;
+	spl_t s;
+
+	if (xnthread_test_state(thread, XNUSER))
+		return -EINVAL;
+
+	if (xnthread_current() || xnthread_test_state(thread, XNMAPPED))
+		return -EBUSY;
+
+	thread->u_window = NULL;
+	xnthread_pin_initial(thread);
+
+	pipeline_init_shadow_tcb(thread);
+	xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
+	init_kthread_info(thread);
+	xnthread_set_state(thread, XNMAPPED);
+	xndebug_shadow_init(thread);
+	xnthread_run_handler(thread, map_thread);
+	pipeline_enable_kevents();
+
+	/*
+	 * CAUTION: Soon after xnthread_init() has returned,
+	 * xnthread_start() is commonly invoked from the root domain,
+	 * therefore the call site may expect the started kernel
+	 * shadow to preempt immediately. As a result of such
+	 * assumption, start attributes (struct xnthread_start_attr)
+	 * are often laid on the caller's stack.
+	 *
+	 * For this reason, we raise the completion signal to wake up
+	 * the xnthread_init() caller only once the emerging thread is
+	 * hardened, and __never__ before that point. Since we run
+	 * over the Xenomai domain upon return from xnthread_harden(),
+	 * we schedule a virtual interrupt handler in the root domain
+	 * to signal the completion object.
+	 */
+	xnthread_resume(thread, XNDORMANT);
+	ret = xnthread_harden();
+	wakeup_parent(done);
+
+	xnlock_get_irqsave(&nklock, s);
+
+	enlist_new_thread(thread);
+	/*
+	 * Make sure xnthread_start() did not slip in from another CPU
+	 * while we were back from wakeup_parent().
+	 */
+	if (thread->entry == NULL)
+		xnthread_suspend(thread, XNDORMANT,
+				 XN_INFINITE, XN_RELATIVE, NULL);
+
+	xnlock_put_irqrestore(&nklock, s);
+
+	xnthread_test_cancel();
+
+	xntrace_pid(xnthread_host_pid(thread),
+		    xnthread_current_priority(thread));
+
+	return ret;
+}
+
 struct kthread_arg {
 	struct xnthread *thread;
 	struct completion *done;
@@ -113,7 +210,7 @@ static int kthread_trampoline(void *arg)
 	param.sched_priority = prio;
 	sched_setscheduler(current, policy, &param);
 
-	ret = xnthread_map(thread, ka->done);
+	ret = map_kthread(thread, ka->done);
 	if (ret) {
 		printk(XENO_WARNING "failed to create kernel shadow %s\n",
 		       thread->name);
@@ -2374,146 +2471,6 @@ void xnthread_pin_initial(struct xnthread *thread)
 	xnlock_put_irqrestore(&nklock, s);
 }
 
-struct parent_wakeup_request {
-	struct pipeline_inband_work inband_work; /* Must be first. */
-	struct completion *done;
-};
-
-static void do_parent_wakeup(struct pipeline_inband_work *inband_work)
-{
-	struct parent_wakeup_request *rq;
-
-	rq = container_of(inband_work, struct parent_wakeup_request, inband_work);
-	complete(rq->done);
-}
-
-static inline void wakeup_parent(struct completion *done)
-{
-	struct parent_wakeup_request wakework = {
-		.inband_work = PIPELINE_INBAND_WORK_INITIALIZER(wakework,
-					do_parent_wakeup),
-		.done = done,
-	};
-
-	trace_cobalt_lostage_request("wakeup", current);
-
-	pipeline_post_inband_work(&wakework);
-}
-
-static inline void init_kthread_info(struct xnthread *thread)
-{
-	struct cobalt_threadinfo *p;
-
-	p = pipeline_current();
-	p->thread = thread;
-	p->process = NULL;
-}
-
-/**
- * @fn int xnthread_map(struct xnthread *thread, struct completion *done)
- * @internal
- * @brief Create a shadow thread context over a kernel task.
- *
- * This call maps a Cobalt core thread to the "current" Linux task
- * running in kernel space.  The priority and scheduling class of the
- * underlying Linux task are not affected; it is assumed that the
- * caller did set them appropriately before issuing the shadow mapping
- * request.
- *
- * This call immediately moves the calling kernel thread to the
- * Xenomai domain.
- *
- * @param thread The descriptor address of the new shadow thread to be
- * mapped to "current". This descriptor must have been previously
- * initialized by a call to xnthread_init().
- *
- * @param done A completion object to be signaled when @a thread is
- * fully mapped over the current Linux context, waiting for
- * xnthread_start().
- *
- * @return 0 is returned on success. Otherwise:
- *
- * - -ERESTARTSYS is returned if the current Linux task has received a
- * signal, thus preventing the final migration to the Xenomai domain
- * (i.e. in order to process the signal in the Linux domain). This
- * error should not be considered as fatal.
- *
- * - -EPERM is returned if the shadow thread has been killed before
- * the current task had a chance to return to the caller. In such a
- * case, the real-time mapping operation has failed globally, and no
- * Xenomai resource remains attached to it.
- *
- * - -EINVAL is returned if the thread control block bears the XNUSER
- * bit.
- *
- * - -EBUSY is returned if either the current Linux task or the
- * associated shadow thread is already involved in a shadow mapping.
- *
- * @coretags{secondary-only, might-switch}
- */
-int xnthread_map(struct xnthread *thread, struct completion *done)
-{
-	int ret;
-	spl_t s;
-
-	if (xnthread_test_state(thread, XNUSER))
-		return -EINVAL;
-
-	if (xnthread_current() || xnthread_test_state(thread, XNMAPPED))
-		return -EBUSY;
-
-	thread->u_window = NULL;
-	xnthread_pin_initial(thread);
-
-	pipeline_init_shadow_tcb(thread);
-	xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
-	init_kthread_info(thread);
-	xnthread_set_state(thread, XNMAPPED);
-	xndebug_shadow_init(thread);
-	xnthread_run_handler(thread, map_thread);
-	pipeline_enable_kevents();
-
-	/*
-	 * CAUTION: Soon after xnthread_init() has returned,
-	 * xnthread_start() is commonly invoked from the root domain,
-	 * therefore the call site may expect the started kernel
-	 * shadow to preempt immediately. As a result of such
-	 * assumption, start attributes (struct xnthread_start_attr)
-	 * are often laid on the caller's stack.
-	 *
-	 * For this reason, we raise the completion signal to wake up
-	 * the xnthread_init() caller only once the emerging thread is
-	 * hardened, and __never__ before that point. Since we run
-	 * over the Xenomai domain upon return from xnthread_harden(),
-	 * we schedule a virtual interrupt handler in the root domain
-	 * to signal the completion object.
-	 */
-	xnthread_resume(thread, XNDORMANT);
-	ret = xnthread_harden();
-	wakeup_parent(done);
-
-	xnlock_get_irqsave(&nklock, s);
-
-	enlist_new_thread(thread);
-	/*
-	 * Make sure xnthread_start() did not slip in from another CPU
-	 * while we were back from wakeup_parent().
-	 */
-	if (thread->entry == NULL)
-		xnthread_suspend(thread, XNDORMANT,
-				 XN_INFINITE, XN_RELATIVE, NULL);
-
-	xnlock_put_irqrestore(&nklock, s);
-
-	xnthread_test_cancel();
-
-	xntrace_pid(xnthread_host_pid(thread),
-		    xnthread_current_priority(thread));
-
-	return ret;
-}
-EXPORT_SYMBOL_GPL(xnthread_map);
-
 /* nklock locked, irqs off */
 void xnthread_call_mayday(struct xnthread *thread, int reason)
 {
-- 
2.26.2



  parent reply	other threads:[~2021-06-11 18:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11 18:05 [PATCH 00/17] Dovetail integration - the finals Jan Kiszka
2021-06-11 18:05 ` [PATCH 01/17] cobalt/thread: Rework kthread check for xnthread_signal Jan Kiszka
2021-06-11 18:05 ` [PATCH 02/17] cobalt/thread: Move xnthread_signal work off the stack Jan Kiszka
2021-06-11 18:05 ` Jan Kiszka [this message]
2021-06-11 18:05 ` [PATCH 04/17] cobalt/thread: Pull kthread inband work onto creator stack Jan Kiszka
2021-06-11 18:05 ` [PATCH 05/17] cobalt/thread: Make sure relax inband work is on a stack outliving the wakeup Jan Kiszka
2021-06-11 18:05 ` [PATCH 06/17] cobalt/thread: dovetail: keep hard irqs off on transition to in-band Jan Kiszka
2022-01-24 16:15   ` Jan Kiszka
2022-01-24 16:55     ` Philippe Gerum
2022-01-24 17:00       ` Philippe Gerum
2022-01-24 17:05         ` Jan Kiszka
2021-06-11 18:05 ` [PATCH 07/17] cobalt/sched: dovetail: prevent early scheduling on uninit runqueues Jan Kiszka
2021-06-11 18:05 ` [PATCH 08/17] cobalt/arm: dovetail: add architecture bits Jan Kiszka
2021-06-11 18:05 ` [PATCH 09/17] lib/cobalt: Reorder low_init for having cobalt_use_legacy_tsc earlier available Jan Kiszka
2021-06-11 18:05 ` [PATCH 10/17] lib/cobalt/arm: dovetail: skip detection of KUSER_TSC support Jan Kiszka
2021-06-11 18:05 ` [PATCH 11/17] lib/cobalt/arm64: " Jan Kiszka
2021-06-11 18:05 ` [PATCH 12/17] cobalt/tick: dovetail: improve accuracy of the host tick delay Jan Kiszka
2021-06-11 18:05 ` [PATCH 13/17] cobalt/tick: dovetail: Drop pointless inline specifier from pipeline_must_force_program_tick Jan Kiszka
2021-06-11 18:05 ` [PATCH 14/17] cobalt/clock: dovetail: abstract interface to hardware TSC Jan Kiszka
2021-06-11 18:05 ` [PATCH 15/17] cobalt/arm64: dovetail: add architecture bits Jan Kiszka
2021-06-11 18:05 ` [PATCH 16/17] cobalt/syscall: Account for different syscall argument marshaling Jan Kiszka
2021-06-11 18:05 ` [PATCH 17/17] ci: Add arm, arm64 and x86 dovetail targets for kernel 5.10 Jan Kiszka
2021-06-13 17:07 ` [PATCH 00/17] Dovetail integration - the finals Philippe Gerum
2021-06-13 17:12   ` Jan Kiszka
2021-06-14  6:24     ` Philippe Gerum

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=2d91aa1b719e834b33630693b96489e2dc4fe6e4.1623434743.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=xenomai@xenomai.org \
    /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.