All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe  Gerum <rpm@xenomai.org>
To: xenomai@xenomai.org
Subject: [PATCH Dovetail 04/13] cobalt/lock: pipeline: abstract hard lock API
Date: Sat,  2 Jan 2021 10:33:44 +0100	[thread overview]
Message-ID: <20210102093353.3195090-5-rpm@xenomai.org> (raw)
In-Reply-To: <20210102093353.3195090-1-rpm@xenomai.org>

From: Philippe Gerum <rpm@xenomai.org>

Dovetail implements two types of locks: hard, and hybrid ones.  See
https://evlproject.org/dovetail/pipeline/locking/ for details.

Cobalt is interested in using Dovetail's hard_spinlock_t locks, which
are strictly equivalent to the ipipe_spinlock_t locks. Provide a
wrapper mapping a generic hard lock to the proper implementation
depending on the underlying pipeline flavour.

No functional change is introduced.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 include/cobalt/kernel/ipipe/pipeline/lock.h   | 21 +++++++++
 .../cobalt/kernel/ipipe/pipeline/pipeline.h   | 25 +++++++++++
 include/cobalt/kernel/lock.h                  | 44 +------------------
 include/cobalt/kernel/rtdm/driver.h           |  9 ++--
 4 files changed, 53 insertions(+), 46 deletions(-)
 create mode 100644 include/cobalt/kernel/ipipe/pipeline/lock.h
 create mode 100644 include/cobalt/kernel/ipipe/pipeline/pipeline.h

diff --git a/include/cobalt/kernel/ipipe/pipeline/lock.h b/include/cobalt/kernel/ipipe/pipeline/lock.h
new file mode 100644
index 000000000..f33b041c7
--- /dev/null
+++ b/include/cobalt/kernel/ipipe/pipeline/lock.h
@@ -0,0 +1,21 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_IPIPE_LOCK_H
+#define _COBALT_KERNEL_IPIPE_LOCK_H
+
+#include <pipeline/pipeline.h>
+
+typedef ipipe_spinlock_t pipeline_spinlock_t;
+
+#define PIPELINE_SPIN_LOCK_UNLOCKED(__name)  IPIPE_SPIN_LOCK_UNLOCKED
+
+#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
+/* Disable UP-over-SMP kernel optimization in debug mode. */
+#define __locking_active__  1
+#else
+#define __locking_active__  ipipe_smp_p
+#endif
+
+#endif /* !_COBALT_KERNEL_IPIPE_LOCK_H */
diff --git a/include/cobalt/kernel/ipipe/pipeline/pipeline.h b/include/cobalt/kernel/ipipe/pipeline/pipeline.h
new file mode 100644
index 000000000..317fa62d7
--- /dev/null
+++ b/include/cobalt/kernel/ipipe/pipeline/pipeline.h
@@ -0,0 +1,25 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_IPIPE_PIPELINE_H
+#define _COBALT_KERNEL_IPIPE_PIPELINE_H
+
+#include <linux/ipipe.h>
+
+typedef unsigned long spl_t;
+
+#define splhigh(x)  ((x) = ipipe_test_and_stall_head() & 1)
+#ifdef CONFIG_SMP
+#define splexit(x)  ipipe_restore_head(x & 1)
+#else /* !CONFIG_SMP */
+#define splexit(x)  ipipe_restore_head(x)
+#endif /* !CONFIG_SMP */
+#define splmax()    ipipe_stall_head()
+#define splnone()   ipipe_unstall_head()
+#define spltest()   ipipe_test_head()
+
+#define is_secondary_domain()	ipipe_root_p
+#define is_primary_domain()	(!ipipe_root_p)
+
+#endif /* !_COBALT_KERNEL_IPIPE_PIPELINE_H */
diff --git a/include/cobalt/kernel/lock.h b/include/cobalt/kernel/lock.h
index bae047524..185f6e785 100644
--- a/include/cobalt/kernel/lock.h
+++ b/include/cobalt/kernel/lock.h
@@ -20,49 +20,16 @@
 #ifndef _COBALT_KERNEL_LOCK_H
 #define _COBALT_KERNEL_LOCK_H
 
-#include <linux/ipipe.h>
+#include <pipeline/lock.h>
 #include <linux/percpu.h>
 #include <cobalt/kernel/assert.h>
+#include <pipeline/pipeline.h>
 
 /**
  * @addtogroup cobalt_core_lock
  *
  * @{
  */
-typedef unsigned long spl_t;
-
-/**
- * Hard disable interrupts on the local processor, saving previous state.
- *
- * @param[out] x An unsigned long integer context variable
- */
-#define splhigh(x)  ((x) = ipipe_test_and_stall_head() & 1)
-#ifdef CONFIG_SMP
-/**
- * Restore the saved hard interrupt state on the local processor.
- *
- * @param[in] x The context variable previously updated by splhigh()
- */
-#define splexit(x)  ipipe_restore_head(x & 1)
-#else /* !CONFIG_SMP */
-#define splexit(x)  ipipe_restore_head(x)
-#endif /* !CONFIG_SMP */
-/**
- * Hard disable interrupts on the local processor.
- */
-#define splmax()    ipipe_stall_head()
-/**
- * Hard enable interrupts on the local processor.
- */
-#define splnone()   ipipe_unstall_head()
-/**
- * Test hard interrupt state on the local processor.
- *
- * @return Zero if the local processor currently accepts interrupts,
- * non-zero otherwise.
- */
-#define spltest()   ipipe_test_head()
-
 #ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
 
 struct xnlock {
@@ -209,13 +176,6 @@ int ___xnlock_get(struct xnlock *lock /*, */ XNLOCK_DBG_CONTEXT_ARGS);
 void ___xnlock_put(struct xnlock *lock /*, */ XNLOCK_DBG_CONTEXT_ARGS);
 #endif /* out of line xnlock */
 
-#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
-/* Disable UP-over-SMP kernel optimization in debug mode. */
-#define __locking_active__  1
-#else
-#define __locking_active__  ipipe_smp_p
-#endif
-
 static inline spl_t
 __xnlock_get_irqsave(struct xnlock *lock /*, */ XNLOCK_DBG_CONTEXT_ARGS)
 {
diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
index 894e6f67e..84309d0b1 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -32,6 +32,7 @@
 #include <linux/cdev.h>
 #include <linux/wait.h>
 #include <linux/notifier.h>
+#include <pipeline/lock.h>
 #include <xenomai/version.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/sched.h>
@@ -541,13 +542,13 @@ rtdm_execute_atomically(void) { }
 /**
  * Static lock initialisation
  */
-#define RTDM_LOCK_UNLOCKED(__name)	IPIPE_SPIN_LOCK_UNLOCKED
+#define RTDM_LOCK_UNLOCKED(__name)	PIPELINE_SPIN_LOCK_UNLOCKED(__name)
 
 #define DEFINE_RTDM_LOCK(__name)		\
 	rtdm_lock_t __name = RTDM_LOCK_UNLOCKED(__name)
 
 /** Lock variable */
-typedef ipipe_spinlock_t rtdm_lock_t;
+typedef pipeline_spinlock_t rtdm_lock_t;
 
 /** Variable to save the context while holding a lock */
 typedef unsigned long rtdm_lockctx_t;
@@ -606,7 +607,7 @@ static inline rtdm_lockctx_t __rtdm_lock_get_irqsave(rtdm_lock_t *lock)
 {
 	rtdm_lockctx_t context;
 
-	context = ipipe_test_and_stall_head();
+	splhigh(context);
 	raw_spin_lock(lock);
 	xnsched_lock();
 
@@ -626,7 +627,7 @@ void rtdm_lock_put_irqrestore(rtdm_lock_t *lock, rtdm_lockctx_t context)
 {
 	raw_spin_unlock(lock);
 	xnsched_unlock();
-	ipipe_restore_head(context);
+	splexit(context);
 }
 
 /**
-- 
2.26.2



  parent reply	other threads:[~2021-01-02  9:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02  9:33 [PATCH Dovetail 00/13] Keep on abstracting the pipeline interface Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 01/13] cobalt/thread: pipeline: abstract threadinfo accessor Philippe Gerum
2021-01-08  9:02   ` Jan Kiszka
2021-01-02  9:33 ` [PATCH Dovetail 02/13] cobalt/apc: pipeline: abstract interface for deferred routine calls Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 03/13] cobalt/trace: pipeline: abstract trace calls Philippe Gerum
2021-01-02  9:33 ` Philippe Gerum [this message]
2021-01-02  9:33 ` [PATCH Dovetail 05/13] cobalt/kernel: pipeline: abstract execution stage predicates Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 06/13] cobalt/sched, clock: pipeline: abstract IPI management Philippe Gerum
2021-01-08  9:40   ` Jan Kiszka
2021-01-02  9:33 ` [PATCH Dovetail 07/13] cobalt/clock: pipeline: make HOSTRT depend on IPIPE Philippe Gerum
2021-01-07 13:52   ` Jan Kiszka
2021-01-09 10:45     ` Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 08/13] cobalt/build: pipeline: select IPIPE layer only if present Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 09/13] cobalt/clock: pipeline: abstract clock, timer access services Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 10/13] cobalt/wrappers: pipeline: abstract pipeline-related bits Philippe Gerum
2021-01-07 13:56   ` Jan Kiszka
2021-01-11 12:59   ` Jan Kiszka
2021-01-02  9:33 ` [PATCH Dovetail 11/13] cobalt/timer: pipeline: abstract tick management Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 12/13] cobalt/debug: pipeline: abstract panic prep call Philippe Gerum
2021-01-02  9:33 ` [PATCH Dovetail 13/13] cobalt/syscall: pipeline: abstract syscall entry points Philippe Gerum
2021-01-07 14:08   ` Jan Kiszka
2021-01-09 10:58     ` Philippe Gerum
2021-01-11 12:11       ` Jan Kiszka

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=20210102093353.3195090-5-rpm@xenomai.org \
    --to=rpm@xenomai.org \
    --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.