All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup
@ 2021-02-07 16:04 Philippe Gerum
  2021-02-07 16:04 ` [PATCH 02/18] cobalt/sirq: dovetail: add placeholders for synthetic IRQ management Philippe Gerum
                   ` (16 more replies)
  0 siblings, 17 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/machine.h | 51 ++++++++++++++++++
 kernel/cobalt/dovetail/Makefile               |  5 ++
 kernel/cobalt/dovetail/init.c                 | 52 +++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/machine.h
 create mode 100644 kernel/cobalt/dovetail/Makefile
 create mode 100644 kernel/cobalt/dovetail/init.c

diff --git a/include/cobalt/kernel/dovetail/pipeline/machine.h b/include/cobalt/kernel/dovetail/pipeline/machine.h
new file mode 100644
index 000000000..4f3dd95e0
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/machine.h
@@ -0,0 +1,51 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_MACHINE_H
+#define _COBALT_KERNEL_DOVETAIL_MACHINE_H
+
+#include <linux/percpu.h>
+
+#ifdef CONFIG_FTRACE
+#define boot_lat_trace_notice "[LTRACE]"
+#else
+#define boot_lat_trace_notice ""
+#endif
+
+struct vm_area_struct;
+
+struct cobalt_machine {
+	const char *name;
+	int (*init)(void);
+	int (*late_init)(void);
+	void (*cleanup)(void);
+	void (*prefault)(struct vm_area_struct *vma);
+	const char *const *fault_labels;
+};
+
+extern struct cobalt_machine cobalt_machine;
+
+struct cobalt_machine_cpudata {
+	unsigned int faults[32];
+};
+
+DECLARE_PER_CPU(struct cobalt_machine_cpudata, cobalt_machine_cpudata);
+
+struct cobalt_pipeline {
+#ifdef CONFIG_SMP
+	cpumask_t supported_cpus;
+#endif
+};
+
+int pipeline_init(void);
+
+int pipeline_late_init(void);
+
+void pipeline_cleanup(void);
+
+extern struct cobalt_pipeline cobalt_pipeline;
+
+#endif /* !_COBALT_KERNEL_IPIPE_MACHINE_H */
diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
new file mode 100644
index 000000000..0bde9dfdb
--- /dev/null
+++ b/kernel/cobalt/dovetail/Makefile
@@ -0,0 +1,5 @@
+ccflags-y += -Ikernel
+
+obj-y +=	pipeline.o
+
+pipeline-y :=	init.o
diff --git a/kernel/cobalt/dovetail/init.c b/kernel/cobalt/dovetail/init.c
new file mode 100644
index 000000000..983186abe
--- /dev/null
+++ b/kernel/cobalt/dovetail/init.c
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#include <linux/init.h>
+#include <pipeline/machine.h>
+#include <cobalt/kernel/clock.h>
+#include <cobalt/kernel/assert.h>
+
+int __init pipeline_init(void)
+{
+	int ret;
+
+	if (cobalt_machine.init) {
+		ret = cobalt_machine.init();
+		if (ret)
+			return ret;
+	}
+
+	/* Enable the Xenomai out-of-band stage */
+	TODO();
+
+	ret = xnclock_init();
+	if (ret)
+		goto fail_clock;
+
+	return 0;
+
+fail_clock:
+	if (cobalt_machine.cleanup)
+		cobalt_machine.cleanup();
+
+	return ret;
+}
+
+int __init pipeline_late_init(void)
+{
+	if (cobalt_machine.late_init)
+		return cobalt_machine.late_init();
+
+	return 0;
+}
+
+__init void pipeline_cleanup(void)
+{
+	/* Disable the Xenomai stage */
+	TODO();
+
+	xnclock_cleanup();
+}
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/18] cobalt/sirq: dovetail: add placeholders for synthetic IRQ management
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 03/18] cobalt/irq: dovetail: add placeholders for out-of-band " Philippe Gerum
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/sirq.h    | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/sirq.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/sirq.h b/include/cobalt/kernel/dovetail/pipeline/sirq.h
new file mode 100644
index 000000000..be9dc587f
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/sirq.h
@@ -0,0 +1,47 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_SIRQ_H
+#define _COBALT_KERNEL_DOVETAIL_SIRQ_H
+
+#include <linux/irq_pipeline.h>
+#include <cobalt/kernel/assert.h>
+
+/*
+ * Wrappers to create "synthetic IRQs" the Dovetail way. Those
+ * interrupt channels can only be trigged by software, in order to run
+ * a handler on the in-band execution stage.
+ */
+
+static inline
+int pipeline_create_inband_sirq(irqreturn_t (*handler)(int irq, void *dev_id))
+{
+	/*
+	 * Allocate an IRQ from the synthetic interrupt domain then
+	 * trap it to @handler, to be fired from the in-band stage.
+	 */
+	TODO();
+
+	return 0;
+}
+
+static inline
+void pipeline_delete_inband_sirq(int sirq)
+{
+	/*
+	 * Free the synthetic IRQ then deallocate it to its
+	 * originating domain.
+	 */
+	TODO();
+}
+
+static inline void pipeline_post_sirq(int sirq)
+{
+	/* Trigger the synthetic IRQ */
+	TODO();
+}
+
+#endif /* !_COBALT_KERNEL_IPIPE_SIRQ_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/18] cobalt/irq: dovetail: add placeholders for out-of-band IRQ management
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
  2021-02-07 16:04 ` [PATCH 02/18] cobalt/sirq: dovetail: add placeholders for synthetic IRQ management Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 04/18] cobalt/clock: dovetail: add placeholders for clock services Philippe Gerum
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../kernel/dovetail/pipeline/pipeline.h       | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/pipeline.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/pipeline.h b/include/cobalt/kernel/dovetail/pipeline/pipeline.h
new file mode 100644
index 000000000..4b8f6b259
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/pipeline.h
@@ -0,0 +1,84 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_PIPELINE_H
+#define _COBALT_KERNEL_DOVETAIL_PIPELINE_H
+
+#include <linux/irq_pipeline.h>
+#include <cobalt/kernel/assert.h>
+
+typedef unsigned long spl_t;
+
+/*
+ * We only keep the LSB when testing in SMP mode in order to strip off
+ * the recursion marker (0x2) the nklock may store there.
+ */
+#define splhigh(x)  ((x) = oob_irq_save() & 1)
+#ifdef CONFIG_SMP
+#define splexit(x)  oob_irq_restore(x & 1)
+#else /* !CONFIG_SMP */
+#define splexit(x)  oob_irq_restore(x)
+#endif /* !CONFIG_SMP */
+#define splmax()    oob_irq_disable()
+#define splnone()   oob_irq_enable()
+#define spltest()   oob_irqs_disabled()
+
+#define is_secondary_domain()	running_inband()
+#define is_primary_domain()	running_oob()
+
+#ifdef CONFIG_SMP
+
+static inline int pipeline_request_resched_ipi(void (*handler)(void))
+{
+	/* Trap the out-of-band rescheduling interrupt. */
+	TODO();
+
+	return 0;
+}
+
+static inline void pipeline_free_resched_ipi(void)
+{
+	/* Release the out-of-band rescheduling interrupt. */
+	TODO();
+}
+
+static inline void pipeline_send_resched_ipi(const struct cpumask *dest)
+{
+	/*
+	 * Trigger the out-of-band rescheduling interrupt on remote
+	 * CPU(s).
+	 */
+	TODO();
+}
+
+static inline int pipeline_request_timer_ipi(void (*handler)(void))
+{
+	/* Trap the out-of-band timer interrupt. */
+	TODO();
+
+	return 0;
+}
+
+static inline void pipeline_free_timer_ipi(void)
+{
+	/* Release the out-of-band timer interrupt. */
+	TODO();
+}
+
+static inline void pipeline_send_timer_ipi(const struct cpumask *dest)
+{
+	/*
+	 * Trigger the out-of-band timer interrupt on remote CPU(s).
+	 */
+	TODO();
+}
+
+#endif
+
+static inline void pipeline_prepare_panic(void)
+{
+	/* N/A */
+}
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_PIPELINE_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/18] cobalt/clock: dovetail: add placeholders for clock services
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
  2021-02-07 16:04 ` [PATCH 02/18] cobalt/sirq: dovetail: add placeholders for synthetic IRQ management Philippe Gerum
  2021-02-07 16:04 ` [PATCH 03/18] cobalt/irq: dovetail: add placeholders for out-of-band " Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 05/18] cobalt/inband_work: dovetail: provide for deferred in-band calls Philippe Gerum
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/clock.h   | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/clock.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/clock.h b/include/cobalt/kernel/dovetail/pipeline/clock.h
new file mode 100644
index 000000000..933e100ba
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/clock.h
@@ -0,0 +1,80 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_CLOCK_H
+#define _COBALT_KERNEL_DOVETAIL_CLOCK_H
+
+#include <cobalt/uapi/kernel/types.h>
+#include <cobalt/kernel/assert.h>
+
+struct timespec;
+
+static inline u64 pipeline_read_cycle_counter(void)
+{
+	/* Read the raw cycle counter of the core clock. */
+	TODO();
+
+	return 0;
+}
+
+static inline void pipeline_set_timer_shot(unsigned long cycles)
+{
+	/*
+	 * N/A. Revisit: xnclock_core_local_shot() should go to the
+	 * I-pipe section, we do things differently on Dovetail via
+	 * the proxy tick device. As a consequence,
+	 * pipeline_set_timer_shot() should not be part of the
+	 * pipeline interface.
+	 */
+	TODO();
+}
+
+static inline const char *pipeline_timer_name(void)
+{
+	/*
+	 * Return the name of the current clock event chip, which is
+	 * the real device controlled by the proxy tick device.
+	 */
+	TODO();
+
+	return "?";
+}
+
+static inline const char *pipeline_clock_name(void)
+{
+	/* Return the name of the current clock source. */
+	TODO();
+
+	return "?";
+}
+
+static inline int pipeline_get_host_time(struct timespec *tp)
+{
+	/* Convert ktime_get_real_fast_ns() to timespec. */
+	TODO();
+
+	return 0;
+}
+
+static inline void pipeline_init_clock(void)
+{
+	/* N/A */
+}
+
+static inline xnsticks_t xnclock_core_ticks_to_ns(xnsticks_t ticks)
+{
+	return ticks;
+}
+
+static inline xnsticks_t xnclock_core_ticks_to_ns_rounded(xnsticks_t ticks)
+{
+	return ticks;
+}
+
+static inline xnsticks_t xnclock_core_ns_to_ticks(xnsticks_t ns)
+{
+	return ns;
+}
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_CLOCK_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/18] cobalt/inband_work: dovetail: provide for deferred in-band calls
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (2 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 04/18] cobalt/clock: dovetail: add placeholders for clock services Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 06/18] cobalt/kevents: dovetail: add placeholders for kernel event handlers Philippe Gerum
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Dovetail enables irq_work for deferring the execution of a routine
until the in-band stage is active again on the current CPU, we don't
need to provide for any additional mechanism. Therefore we just need
to wrap the pipeline interface calls to the irq_work API.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../kernel/dovetail/pipeline/inband_work.h    | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/inband_work.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/inband_work.h b/include/cobalt/kernel/dovetail/pipeline/inband_work.h
new file mode 100644
index 000000000..317a31de7
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/inband_work.h
@@ -0,0 +1,32 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_INBAND_WORK_H
+#define _COBALT_KERNEL_DOVETAIL_INBAND_WORK_H
+
+#include <linux/irq_work.h>
+
+/*
+ * This field must be named inband_work and appear first in the
+ * container work struct.
+ */
+struct pipeline_inband_work {
+	struct irq_work work;
+};
+
+#define PIPELINE_INBAND_WORK_INITIALIZER(__work, __handler)		\
+	{								\
+		.work = {						\
+			.func = (void (*)(struct irq_work *))		\
+			__handler,					\
+			.flags = ATOMIC_INIT(0),			\
+		},							\
+	}
+
+#define pipeline_post_inband_work(__work)				\
+			irq_work_queue(&(__work)->inband_work.work)
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_INBAND_WORK_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/18] cobalt/kevents: dovetail: add placeholders for kernel event handlers
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (3 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 05/18] cobalt/inband_work: dovetail: provide for deferred in-band calls Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 07/18] cobalt/lock: dovetail: define hard lock type Philippe Gerum
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/kevents.h |  34 +
 kernel/cobalt/dovetail/Makefile               |   4 +-
 kernel/cobalt/dovetail/kevents.c              | 627 ++++++++++++++++++
 3 files changed, 663 insertions(+), 2 deletions(-)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/kevents.h
 create mode 100644 kernel/cobalt/dovetail/kevents.c

diff --git a/include/cobalt/kernel/dovetail/pipeline/kevents.h b/include/cobalt/kernel/dovetail/pipeline/kevents.h
new file mode 100644
index 000000000..5cc78721a
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/kevents.h
@@ -0,0 +1,34 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_KEVENTS_H
+#define _COBALT_KERNEL_DOVETAIL_KEVENTS_H
+
+#define KEVENT_PROPAGATE   0
+#define KEVENT_STOP        1
+
+struct cobalt_process;
+struct cobalt_thread;
+
+static inline
+int pipeline_attach_process(struct cobalt_process *process)
+{
+	return 0;
+}
+
+static inline
+void pipeline_detach_process(struct cobalt_process *process)
+{ }
+
+int pipeline_prepare_current(void);
+
+void pipeline_attach_current(struct xnthread *thread);
+
+int pipeline_trap_kevents(void);
+
+void pipeline_enable_kevents(void);
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_KEVENTS_H */
diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
index 0bde9dfdb..c92227f4c 100644
--- a/kernel/cobalt/dovetail/Makefile
+++ b/kernel/cobalt/dovetail/Makefile
@@ -1,5 +1,5 @@
-ccflags-y += -Ikernel
+ccflags-y += -I$(srctree)/kernel
 
 obj-y +=	pipeline.o
 
-pipeline-y :=	init.o
+pipeline-y :=	init.o kevents.o
diff --git a/kernel/cobalt/dovetail/kevents.c b/kernel/cobalt/dovetail/kevents.c
new file mode 100644
index 000000000..b5dc50ea7
--- /dev/null
+++ b/kernel/cobalt/dovetail/kevents.c
@@ -0,0 +1,627 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2001-2014 Philippe Gerum <rpm@xenomai.org>.
+ * Copyright (C) 2001-2014 The Xenomai project <http://www.xenomai.org>
+ * Copyright (C) 2006 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
+ *
+ * SMP support Copyright (C) 2004 The HYADES project <http://www.hyades-itea.org>
+ * RTAI/fusion Copyright (C) 2004 The RTAI project <http://www.rtai.org>
+ */
+
+#include <linux/ptrace.h>
+#include <pipeline/kevents.h>
+#include <cobalt/kernel/sched.h>
+#include <cobalt/kernel/thread.h>
+#include <cobalt/kernel/clock.h>
+#include <cobalt/kernel/vdso.h>
+#include <rtdm/driver.h>
+#include <trace/events/cobalt-core.h>
+#include "../posix/process.h"
+#include "../posix/thread.h"
+#include "../posix/memory.h"
+
+static void detach_current(void);
+
+static inline struct cobalt_process *
+process_from_thread(struct xnthread *thread)
+{
+	return container_of(thread, struct cobalt_thread, threadbase)->process;
+}
+
+static inline void stop_debugged_process(struct xnthread *thread)
+{
+	struct cobalt_process *process = process_from_thread(thread);
+	struct cobalt_thread *cth;
+
+	if (process->debugged_threads > 0)
+		return;
+
+	list_for_each_entry(cth, &process->thread_list, next) {
+		if (&cth->threadbase == thread)
+			continue;
+
+		xnthread_suspend(&cth->threadbase, XNDBGSTOP, XN_INFINITE,
+				 XN_RELATIVE, NULL);
+	}
+}
+
+static inline void resume_debugged_process(struct cobalt_process *process)
+{
+	struct cobalt_thread *cth;
+
+	xnsched_lock();
+
+	list_for_each_entry(cth, &process->thread_list, next)
+		if (xnthread_test_state(&cth->threadbase, XNDBGSTOP))
+			xnthread_resume(&cth->threadbase, XNDBGSTOP);
+
+	xnsched_unlock();
+}
+
+/* called with nklock held */
+static void register_debugged_thread(struct xnthread *thread)
+{
+	struct cobalt_process *process = process_from_thread(thread);
+
+	xnthread_set_state(thread, XNSSTEP);
+
+	stop_debugged_process(thread);
+	process->debugged_threads++;
+
+	if (xnthread_test_state(thread, XNRELAX))
+		xnthread_suspend(thread, XNDBGSTOP, XN_INFINITE, XN_RELATIVE,
+				 NULL);
+}
+
+/* called with nklock held */
+static void unregister_debugged_thread(struct xnthread *thread)
+{
+	struct cobalt_process *process = process_from_thread(thread);
+
+	process->debugged_threads--;
+	xnthread_clear_state(thread, XNSSTEP);
+
+	if (process->debugged_threads == 0)
+		resume_debugged_process(process);
+}
+
+void handle_oob_trap_entry(unsigned int trapnr, struct pt_regs *regs)
+{
+	struct xnthread *thread;
+	struct xnsched *sched;
+	spl_t s;
+
+	sched = xnsched_current();
+	thread = sched->curr;
+
+	/*
+	 * Enable back tracing.
+	 *
+	 * trace_cobalt_thread_fault(xnarch_fault_pc(regs), trapnr);
+	 */
+	TODO();
+
+	if (xnthread_test_state(thread, XNROOT))
+		return;
+
+	if (xnarch_fault_bp_p(trapnr) && user_mode(regs)) {
+		XENO_WARN_ON(CORE, xnthread_test_state(thread, XNRELAX));
+		xnlock_get_irqsave(&nklock, s);
+		xnthread_set_info(thread, XNCONTHI);
+		dovetail_request_ucall(current);
+		stop_debugged_process(thread);
+		xnlock_put_irqrestore(&nklock, s);
+		xnsched_run();
+	}
+
+	/*
+	 * If we experienced a trap on behalf of a shadow thread
+	 * running in primary mode, move it to the Linux domain,
+	 * leaving the kernel process the exception.
+	 */
+#if defined(CONFIG_XENO_OPT_DEBUG_COBALT) || defined(CONFIG_XENO_OPT_DEBUG_USER)
+	if (!user_mode(regs)) {
+		xntrace_panic_freeze();
+		printk(XENO_WARNING
+		       "switching %s to secondary mode after exception #%u in "
+		       "kernel-space at 0x%lx (pid %d)\n", thread->name,
+		       trapnr,
+		       xnarch_fault_pc(regs),
+		       xnthread_host_pid(thread));
+		xntrace_panic_dump();
+	} else if (xnarch_fault_notify(trapnr)) /* Don't report debug traps */
+		printk(XENO_WARNING
+		       "switching %s to secondary mode after exception #%u from "
+		       "user-space at 0x%lx (pid %d)\n", thread->name,
+		       trapnr,
+		       xnarch_fault_pc(regs),
+		       xnthread_host_pid(thread));
+#endif
+
+	if (xnarch_fault_pf_p(trapnr))
+		/*
+		 * The page fault counter is not SMP-safe, but it's a
+		 * simple indicator that something went wrong wrt
+		 * memory locking anyway.
+		 */
+		xnstat_counter_inc(&thread->stat.pf);
+
+	xnthread_relax(xnarch_fault_notify(trapnr), SIGDEBUG_MIGRATE_FAULT);
+}
+
+#ifdef CONFIG_SMP
+
+static int handle_setaffinity_event(struct dovetail_migration_data *d)
+{
+	struct task_struct *p = d->task;
+	struct xnthread *thread;
+	spl_t s;
+
+	thread = xnthread_from_task(p);
+	if (thread == NULL)
+		return KEVENT_PROPAGATE;
+
+	/*
+	 * Detect a Cobalt thread sleeping in primary mode which is
+	 * required to migrate to another CPU by the host kernel.
+	 *
+	 * We may NOT fix up thread->sched immediately using the
+	 * passive migration call, because that latter always has to
+	 * take place on behalf of the target thread itself while
+	 * running in secondary mode. Therefore, that thread needs to
+	 * go through secondary mode first, then move back to primary
+	 * mode, so that affinity_ok() does the fixup work.
+	 *
+	 * We force this by sending a SIGSHADOW signal to the migrated
+	 * thread, asking it to switch back to primary mode from the
+	 * handler, at which point the interrupted syscall may be
+	 * restarted.
+	 */
+	xnlock_get_irqsave(&nklock, s);
+
+	if (xnthread_test_state(thread, XNTHREAD_BLOCK_BITS & ~XNRELAX))
+		xnthread_signal(thread, SIGSHADOW, SIGSHADOW_ACTION_HARDEN);
+
+	xnlock_put_irqrestore(&nklock, s);
+
+	return KEVENT_PROPAGATE;
+}
+
+static inline bool affinity_ok(struct task_struct *p) /* nklocked, IRQs off */
+{
+	struct xnthread *thread = xnthread_from_task(p);
+	struct xnsched *sched;
+	int cpu = task_cpu(p);
+
+	/*
+	 * To maintain consistency between both Cobalt and host
+	 * schedulers, reflecting a thread migration to another CPU
+	 * into the Cobalt scheduler state must happen from secondary
+	 * mode only, on behalf of the migrated thread itself once it
+	 * runs on the target CPU.
+	 *
+	 * This means that the Cobalt scheduler state regarding the
+	 * CPU information lags behind the host scheduler state until
+	 * the migrated thread switches back to primary mode
+	 * (i.e. task_cpu(p) != xnsched_cpu(xnthread_from_task(p)->sched)).
+	 * This is ok since Cobalt does not schedule such thread until then.
+	 *
+	 * check_affinity() detects when a Cobalt thread switching
+	 * back to primary mode did move to another CPU earlier while
+	 * in secondary mode. If so, do the fixups to reflect the
+	 * change.
+	 */
+	if (!xnsched_threading_cpu(cpu)) {
+		/*
+		 * The thread is about to switch to primary mode on a
+		 * non-rt CPU, which is damn wrong and hopeless.
+		 * Whine and cancel that thread.
+		 */
+		printk(XENO_WARNING "thread %s[%d] switched to non-rt CPU%d, aborted.\n",
+		       thread->name, xnthread_host_pid(thread), cpu);
+		/*
+		 * Can't call xnthread_cancel() from a migration
+		 * point, that would break. Since we are on the wakeup
+		 * path to hardening, just raise XNCANCELD to catch it
+		 * in xnthread_harden().
+		 */
+		xnthread_set_info(thread, XNCANCELD);
+		return false;
+	}
+
+	sched = xnsched_struct(cpu);
+	if (sched == thread->sched)
+		return true;
+
+	/*
+	 * The current thread moved to a supported real-time CPU,
+	 * which is not part of its original affinity mask
+	 * though. Assume user wants to extend this mask.
+	 */
+	if (!cpumask_test_cpu(cpu, &thread->affinity))
+		cpumask_set_cpu(cpu, &thread->affinity);
+
+	xnthread_run_handler_stack(thread, move_thread, cpu);
+	xnthread_migrate_passive(thread, sched);
+
+	return true;
+}
+
+#else /* !CONFIG_SMP */
+
+static int handle_setaffinity_event(struct dovetail_migration_data *d)
+{
+	return KEVENT_PROPAGATE;
+}
+
+static inline bool affinity_ok(struct task_struct *p)
+{
+	return true;
+}
+
+#endif /* CONFIG_SMP */
+
+static void __handle_taskexit_event(struct task_struct *p)
+{
+	struct cobalt_ppd *sys_ppd;
+	struct xnthread *thread;
+	spl_t s;
+
+	/*
+	 * We are called for both kernel and user shadows over the
+	 * root thread.
+	 */
+	secondary_mode_only();
+
+	thread = xnthread_current();
+	XENO_BUG_ON(COBALT, thread == NULL);
+	trace_cobalt_shadow_unmap(thread);
+
+	xnlock_get_irqsave(&nklock, s);
+
+	if (xnthread_test_state(thread, XNSSTEP))
+		unregister_debugged_thread(thread);
+
+	xnsched_run();
+
+	xnlock_put_irqrestore(&nklock, s);
+
+	xnthread_run_handler_stack(thread, exit_thread);
+
+	if (xnthread_test_state(thread, XNUSER)) {
+		cobalt_umm_free(&cobalt_kernel_ppd.umm, thread->u_window);
+		thread->u_window = NULL;
+		sys_ppd = cobalt_ppd_get(0);
+		if (atomic_dec_and_test(&sys_ppd->refcnt))
+			cobalt_remove_process(cobalt_current_process());
+	}
+}
+
+static int handle_taskexit_event(struct task_struct *p) /* p == current */
+{
+	__handle_taskexit_event(p);
+
+	/*
+	 * __xnthread_cleanup() -> ... -> finalize_thread
+	 * handler. From that point, the TCB is dropped. Be careful of
+	 * not treading on stale memory within @thread.
+	 */
+	__xnthread_cleanup(xnthread_current());
+
+	detach_current();
+
+	return KEVENT_PROPAGATE;
+}
+
+static int handle_user_return(struct task_struct *task)
+{
+	struct xnthread *thread;
+	spl_t s;
+	int err;
+
+	thread = xnthread_from_task(task);
+	if (thread == NULL)
+		return KEVENT_PROPAGATE;
+
+	if (xnthread_test_info(thread, XNCONTHI)) {
+		xnlock_get_irqsave(&nklock, s);
+		xnthread_clear_info(thread, XNCONTHI);
+		xnlock_put_irqrestore(&nklock, s);
+
+		err = xnthread_harden();
+
+		/*
+		 * XNCONTHI may or may not have been re-applied if
+		 * harden bailed out due to pending signals. Make sure
+		 * it is set in that case.
+		 */
+		if (err == -ERESTARTSYS) {
+			xnlock_get_irqsave(&nklock, s);
+			xnthread_set_info(thread, XNCONTHI);
+			xnlock_put_irqrestore(&nklock, s);
+		}
+	}
+
+	return KEVENT_PROPAGATE;
+}
+
+void handle_oob_mayday(struct pt_regs *regs)
+{
+	XENO_BUG_ON(COBALT, !xnthread_test_state(xnthread_current(), XNUSER));
+
+	xnthread_relax(0, 0);
+}
+
+static int handle_sigwake_event(struct task_struct *p)
+{
+	struct xnthread *thread;
+	sigset_t pending;
+	spl_t s;
+
+	thread = xnthread_from_task(p);
+	if (thread == NULL)
+		return KEVENT_PROPAGATE;
+
+	xnlock_get_irqsave(&nklock, s);
+
+	/*
+	 * CAUTION: __TASK_TRACED is not set in p->state yet. This
+	 * state bit will be set right after we return, when the task
+	 * is woken up.
+	 */
+	if ((p->ptrace & PT_PTRACED) && !xnthread_test_state(thread, XNSSTEP)) {
+		/* We already own the siglock. */
+		sigorsets(&pending,
+			  &p->pending.signal,
+			  &p->signal->shared_pending.signal);
+
+		if (sigismember(&pending, SIGTRAP) ||
+		    sigismember(&pending, SIGSTOP)
+		    || sigismember(&pending, SIGINT))
+			register_debugged_thread(thread);
+	}
+
+	if (xnthread_test_state(thread, XNRELAX))
+		goto out;
+
+	/*
+	 * Allow a thread stopped for debugging to resume briefly in order to
+	 * migrate to secondary mode. xnthread_relax will reapply XNDBGSTOP.
+	 */
+	if (xnthread_test_state(thread, XNDBGSTOP))
+		xnthread_resume(thread, XNDBGSTOP);
+
+	__xnthread_kick(thread);
+out:
+	xnsched_run();
+
+	xnlock_put_irqrestore(&nklock, s);
+
+	return KEVENT_PROPAGATE;
+}
+
+static int handle_cleanup_event(struct mm_struct *mm)
+{
+	struct cobalt_process *old, *process;
+	struct cobalt_ppd *sys_ppd;
+	struct xnthread *curr;
+
+	/*
+	 * We are NOT called for exiting kernel shadows.
+	 * cobalt_current_process() is cleared if we get there after
+	 * handle_task_exit(), so we need to restore this context
+	 * pointer temporarily.
+	 */
+	process = cobalt_search_process(mm);
+	old = cobalt_set_process(process);
+	sys_ppd = cobalt_ppd_get(0);
+	if (sys_ppd != &cobalt_kernel_ppd) {
+		bool running_exec;
+
+		/*
+		 * Detect a userland shadow running exec(), i.e. still
+		 * attached to the current linux task (no prior
+		 * detach_current). In this case, we emulate a task
+		 * exit, since the Xenomai binding shall not survive
+		 * the exec() syscall. Since the process will keep on
+		 * running though, we have to disable the event
+		 * notifier manually for it.
+		 */
+		curr = xnthread_current();
+		running_exec = curr && (current->flags & PF_EXITING) == 0;
+		if (running_exec) {
+			__handle_taskexit_event(current);
+			dovetail_stop_altsched();
+		}
+		if (atomic_dec_and_test(&sys_ppd->refcnt))
+			cobalt_remove_process(process);
+		if (running_exec) {
+			__xnthread_cleanup(curr);
+			detach_current();
+		}
+	}
+
+	/*
+	 * CAUTION: Do not override a state change caused by
+	 * cobalt_remove_process().
+	 */
+	if (cobalt_current_process() == process)
+		cobalt_set_process(old);
+
+	return KEVENT_PROPAGATE;
+}
+
+int handle_ptrace_resume(struct task_struct *tracee)
+{
+	struct xnthread *thread;
+	spl_t s;
+
+	thread = xnthread_from_task(tracee);
+	if (thread == NULL)
+		return KEVENT_PROPAGATE;
+
+	if (xnthread_test_state(thread, XNSSTEP)) {
+		xnlock_get_irqsave(&nklock, s);
+
+		xnthread_resume(thread, XNDBGSTOP);
+		unregister_debugged_thread(thread);
+
+		xnlock_put_irqrestore(&nklock, s);
+	}
+
+	return KEVENT_PROPAGATE;
+}
+
+static void handle_ptrace_cont(void)
+{
+	/*
+	 * This is the place where the ptrace-related work which used
+	 * to happen in handle_schedule_event() should go. We are
+	 * called when current is resuming execution after a ptrace
+	 * stopped state, which is what look for in
+	 * handle_schedule_event().
+	 */
+	TODO();
+}
+
+void handle_inband_event(enum inband_event_type event, void *data)
+{
+	switch (event) {
+	case INBAND_TASK_SIGNAL:
+		handle_sigwake_event(data);
+		break;
+	case INBAND_TASK_MIGRATION:
+		handle_setaffinity_event(data);
+		break;
+	case INBAND_TASK_EXIT:
+		if (xnthread_current())
+			handle_taskexit_event(current);
+		break;
+	case INBAND_TASK_RETUSER:
+		handle_user_return(data);
+		break;
+	case INBAND_TASK_PTSTEP:
+		handle_ptrace_resume(data);
+		break;
+	case INBAND_TASK_PTCONT:
+		handle_ptrace_cont();
+		break;
+	case INBAND_TASK_PTSTOP:
+		break;
+	case INBAND_PROCESS_CLEANUP:
+		handle_cleanup_event(data);
+		break;
+	}
+}
+
+#ifdef CONFIG_MMU
+static inline int disable_ondemand_memory(void)
+{
+	struct task_struct *p = current;
+	kernel_siginfo_t si;
+
+	if ((p->mm->def_flags & VM_LOCKED) == 0) {
+		memset(&si, 0, sizeof(si));
+		si.si_signo = SIGDEBUG;
+		si.si_code = SI_QUEUE;
+		si.si_int = SIGDEBUG_NOMLOCK | sigdebug_marker;
+		send_sig_info(SIGDEBUG, &si, p);
+		return 0;
+	}
+
+	return force_commit_memory();
+}
+
+int pipeline_prepare_current(void)
+{
+	return disable_ondemand_memory();
+}
+
+static inline int get_mayday_prot(void)
+{
+	return PROT_READ|PROT_EXEC;
+}
+
+#else /* !CONFIG_MMU */
+
+int pipeline_prepare_current(void)
+{
+	return 0;
+}
+
+static inline int get_mayday_prot(void)
+{
+	/*
+	 * Until we stop backing /dev/mem with the mayday page, we
+	 * can't ask for PROT_EXEC since the former does not define
+	 * mmap capabilities, and default ones won't allow an
+	 * executable mapping with MAP_SHARED. In the NOMMU case, this
+	 * is (currently) not an issue.
+	 */
+	return PROT_READ;
+}
+
+#endif /* !CONFIG_MMU */
+
+void resume_oob_task(struct task_struct *p) /* inband, oob stage stalled */
+{
+	struct xnthread *thread = xnthread_from_task(p);
+
+	xnlock_get(&nklock);
+
+	/*
+	 * We fire the handler before the thread is migrated, so that
+	 * thread->sched does not change between paired invocations of
+	 * relax_thread/harden_thread handlers.
+	 */
+	xnthread_run_handler_stack(thread, harden_thread);
+	if (affinity_ok(p))
+		xnthread_resume(thread, XNRELAX);
+
+	/*
+	 * In case we migrated independently of the user return notifier, clear
+	 * XNCONTHI here and also disable the notifier - we are already done.
+	 */
+	if (unlikely(xnthread_test_info(thread, XNCONTHI))) {
+		xnthread_clear_info(thread, XNCONTHI);
+		dovetail_clear_ucall();
+	}
+
+	/* Unregister as debugged thread in case we postponed this. */
+	if (unlikely(xnthread_test_state(thread, XNSSTEP)))
+		unregister_debugged_thread(thread);
+
+	xnlock_put(&nklock);
+
+	xnsched_run();
+
+}
+
+void pipeline_attach_current(struct xnthread *thread)
+{
+	struct cobalt_threadinfo *p;
+
+	p = pipeline_current();
+	p->thread = thread;
+	p->process = cobalt_search_process(current->mm);
+	dovetail_init_altsched(&xnthread_archtcb(thread)->altsched);
+}
+
+static void detach_current(void)
+{
+	struct cobalt_threadinfo *p = pipeline_current();
+	p->thread = NULL;
+	p->process = NULL;
+}
+
+int pipeline_trap_kevents(void)
+{
+	dovetail_start();
+	return 0;
+}
+
+void pipeline_enable_kevents(void)
+{
+	dovetail_start_altsched();
+}
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/18] cobalt/lock: dovetail: define hard lock type
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (4 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 06/18] cobalt/kevents: dovetail: add placeholders for kernel event handlers Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 08/18] cobalt/sched: dovetail: add placeholders for context switching Philippe Gerum
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/lock.h    | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/lock.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/lock.h b/include/cobalt/kernel/dovetail/pipeline/lock.h
new file mode 100644
index 000000000..8866c92bf
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/lock.h
@@ -0,0 +1,28 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_LOCK_H
+#define _COBALT_KERNEL_DOVETAIL_LOCK_H
+
+#include <linux/spinlock.h>
+
+typedef hard_spinlock_t pipeline_spinlock_t;
+
+#define PIPELINE_SPIN_LOCK_UNLOCKED(__name)  __HARD_SPIN_LOCK_INITIALIZER(__name)
+
+#ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
+/* Disable UP-over-SMP kernel optimization in debug mode. */
+#define __locking_active__  1
+
+#else
+
+#ifdef CONFIG_SMP
+#define __locking_active__  1
+#else
+#define __locking_active__  IS_ENABLED(CONFIG_SMP)
+#endif
+
+#endif
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_LOCK_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/18] cobalt/sched: dovetail: add placeholders for context switching
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (5 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 07/18] cobalt/lock: dovetail: define hard lock type Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors Philippe Gerum
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/sched.h   | 50 ++++++++++++
 kernel/cobalt/dovetail/Makefile               |  2 +-
 kernel/cobalt/dovetail/sched.c                | 77 +++++++++++++++++++
 3 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/sched.h
 create mode 100644 kernel/cobalt/dovetail/sched.c

diff --git a/include/cobalt/kernel/dovetail/pipeline/sched.h b/include/cobalt/kernel/dovetail/pipeline/sched.h
new file mode 100644
index 000000000..b5d6c1773
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/sched.h
@@ -0,0 +1,50 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_SCHED_H
+#define _COBALT_KERNEL_DOVETAIL_SCHED_H
+
+struct xnthread;
+struct xnsched;
+struct task_struct;
+
+void pipeline_init_shadow_tcb(struct xnthread *thread);
+
+void pipeline_init_root_tcb(struct xnthread *thread);
+
+int ___xnsched_run(struct xnsched *sched);
+
+static inline int pipeline_schedule(struct xnsched *sched)
+{
+	return run_oob_call((int (*)(void *))___xnsched_run, sched);
+}
+
+static inline void pipeline_prep_switch_oob(struct xnthread *root)
+{
+	/* N/A */
+}
+
+bool pipeline_switch_to(struct xnthread *prev,
+			struct xnthread *next,
+			bool leaving_inband);
+
+int pipeline_leave_inband(void);
+
+int pipeline_leave_oob_prepare(void);
+
+void pipeline_leave_oob_finish(void);
+
+static inline
+void pipeline_finalize_thread(struct xnthread *thread)
+{
+	/* N/A */
+}
+
+void pipeline_raise_mayday(struct task_struct *tsk);
+
+void pipeline_clear_mayday(void);
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_SCHED_H */
diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
index c92227f4c..24320b3f2 100644
--- a/kernel/cobalt/dovetail/Makefile
+++ b/kernel/cobalt/dovetail/Makefile
@@ -2,4 +2,4 @@ ccflags-y += -I$(srctree)/kernel
 
 obj-y +=	pipeline.o
 
-pipeline-y :=	init.o kevents.o
+pipeline-y :=	init.o kevents.o sched.o
diff --git a/kernel/cobalt/dovetail/sched.c b/kernel/cobalt/dovetail/sched.c
new file mode 100644
index 000000000..71f763d39
--- /dev/null
+++ b/kernel/cobalt/dovetail/sched.c
@@ -0,0 +1,77 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2001-2020 Philippe Gerum <rpm@xenomai.org>.
+ */
+
+#include <linux/cpuidle.h>
+#include <cobalt/kernel/thread.h>
+#include <cobalt/kernel/sched.h>
+#include <pipeline/sched.h>
+#include <trace/events/cobalt-core.h>
+
+/* in-band stage, hard_irqs_disabled() */
+bool irq_cpuidle_control(struct cpuidle_device *dev,
+			struct cpuidle_state *state)
+{
+	/*
+	 * Deny entering sleep state if this entails stopping the
+	 * timer (i.e. C3STOP misfeature).
+	 */
+	if (state && (state->flags & CPUIDLE_FLAG_TIMER_STOP))
+		return false;
+
+	return true;
+}
+
+bool pipeline_switch_to(struct xnthread *prev, struct xnthread *next,
+			bool leaving_inband)
+{
+	return dovetail_context_switch(&xnthread_archtcb(prev)->altsched,
+			&xnthread_archtcb(next)->altsched, leaving_inband);
+}
+
+void pipeline_init_shadow_tcb(struct xnthread *thread)
+{
+	/*
+	 * Initialize the alternate scheduling control block.
+	 */
+	TODO();
+
+	trace_cobalt_shadow_map(thread);
+}
+
+void pipeline_init_root_tcb(struct xnthread *thread)
+{
+	/*
+	 * Initialize the alternate scheduling control block.
+	 */
+	TODO();
+}
+
+int pipeline_leave_inband(void)
+{
+	return dovetail_leave_inband();
+}
+
+int pipeline_leave_oob_prepare(void)
+{
+	dovetail_leave_oob();
+
+	return XNRELAX;
+}
+
+void pipeline_leave_oob_finish(void)
+{
+	dovetail_resume_inband();
+}
+
+void pipeline_raise_mayday(struct task_struct *tsk)
+{
+	dovetail_send_mayday(tsk);
+}
+
+void pipeline_clear_mayday(void) /* May solely affect current. */
+{
+	clear_thread_flag(TIF_MAYDAY);
+}
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (6 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 08/18] cobalt/sched: dovetail: add placeholders for context switching Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-08 19:03   ` Jan Kiszka
  2021-02-07 16:04 ` [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs Philippe Gerum
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/thread.h  | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/thread.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/thread.h b/include/cobalt/kernel/dovetail/pipeline/thread.h
new file mode 100644
index 000000000..1e6b0f091
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/thread.h
@@ -0,0 +1,27 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2019 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_KERNEL_DOVETAIL_THREAD_H
+#define _COBALT_KERNEL_DOVETAIL_THREAD_H
+
+#include <linux/dovetail.h>
+
+struct xnthread;
+
+#define cobalt_threadinfo oob_thread_state
+
+static inline struct cobalt_threadinfo *pipeline_current(void)
+{
+	return dovetail_current_state();
+}
+
+static inline
+struct xnthread *pipeline_thread_from_task(struct task_struct *p)
+{
+	return dovetail_task_state(p)->thread;
+}
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_THREAD_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (7 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-08 19:02   ` Jan Kiszka
  2021-02-07 16:04 ` [PATCH 11/18] cobalt/timer: remove useless wrappers to IPI management Philippe Gerum
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 kernel/cobalt/ipipe/tick.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/cobalt/ipipe/tick.c b/kernel/cobalt/ipipe/tick.c
index da1563a66..b711bedc0 100644
--- a/kernel/cobalt/ipipe/tick.c
+++ b/kernel/cobalt/ipipe/tick.c
@@ -187,7 +187,7 @@ int pipeline_install_tick_proxy(void)
 	nkclock.wallclock_offset =
 		ktime_to_ns(ktime_get_real()) - xnclock_read_monotonic(&nkclock);
 
-	ret = xntimer_setup_ipi();
+	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
 	if (ret)
 		return ret;
 
@@ -244,7 +244,7 @@ fail:
 		ipipe_timer_stop(_cpu);
 	}
 
-	xntimer_release_ipi();
+	pipeline_free_timer_ipi();
 
 	return ret;
 }
@@ -270,7 +270,7 @@ void pipeline_uninstall_tick_proxy(void)
 	for_each_realtime_cpu(cpu)
 		ipipe_timer_stop(cpu);
 
-	xntimer_release_ipi();
+	pipeline_free_timer_ipi();
 
 #ifdef CONFIG_XENO_OPT_STATS_IRQS
 	xnintr_destroy(&nktimer);
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 11/18] cobalt/timer: remove useless wrappers to IPI management
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (8 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management Philippe Gerum
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 include/cobalt/kernel/timer.h | 11 -----------
 kernel/cobalt/timer.c         | 10 ----------
 2 files changed, 21 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 691be7a3b..703a13506 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -517,10 +517,6 @@ void xntimer_migrate(struct xntimer *timer, struct xnsched *sched)
 		__xntimer_migrate(timer, sched);
 }
 
-int xntimer_setup_ipi(void);
-
-void xntimer_release_ipi(void);
-
 void __xntimer_set_affinity(struct xntimer *timer,
 			    struct xnsched *sched);
 
@@ -539,13 +535,6 @@ static inline void xntimer_migrate(struct xntimer *timer,
 	timer->sched = sched;
 }
 
-static inline int xntimer_setup_ipi(void)
-{
-	return 0;
-}
-
-static inline void xntimer_release_ipi(void) { }
-
 static inline void xntimer_set_affinity(struct xntimer *timer,
 					struct xnsched *sched)
 {
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 7f5033c87..f9aa457ce 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -574,16 +574,6 @@ void __xntimer_set_affinity(struct xntimer *timer, struct xnsched *sched)
 }
 EXPORT_SYMBOL_GPL(__xntimer_set_affinity);
 
-int xntimer_setup_ipi(void)
-{
-	return pipeline_request_timer_ipi(xnintr_core_clock_handler);
-}
-
-void xntimer_release_ipi(void)
-{
-	pipeline_free_timer_ipi();
-}
-
 #endif /* CONFIG_SMP */
 
 /**
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (9 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 11/18] cobalt/timer: remove useless wrappers to IPI management Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-08 18:59   ` Jan Kiszka
  2021-02-07 16:04 ` [PATCH 13/18] cobalt/trace: dovetail: add placeholders for trace management Philippe Gerum
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/tick.h    | 12 +++++
 kernel/cobalt/dovetail/Makefile               |  2 +-
 kernel/cobalt/dovetail/tick.c                 | 45 +++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/tick.h
 create mode 100644 kernel/cobalt/dovetail/tick.c

diff --git a/include/cobalt/kernel/dovetail/pipeline/tick.h b/include/cobalt/kernel/dovetail/pipeline/tick.h
new file mode 100644
index 000000000..409581a3c
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/tick.h
@@ -0,0 +1,12 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#ifndef _COBALT_KERNEL_IPIPE_TICK_H
+#define _COBALT_KERNEL_IPIPE_TICK_H
+
+int pipeline_install_tick_proxy(void);
+
+void pipeline_uninstall_tick_proxy(void);
+
+#endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
index 24320b3f2..84788f9ce 100644
--- a/kernel/cobalt/dovetail/Makefile
+++ b/kernel/cobalt/dovetail/Makefile
@@ -2,4 +2,4 @@ ccflags-y += -I$(srctree)/kernel
 
 obj-y +=	pipeline.o
 
-pipeline-y :=	init.o kevents.o sched.o
+pipeline-y :=	init.o kevents.o sched.o tick.o
diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
new file mode 100644
index 000000000..02cd86690
--- /dev/null
+++ b/kernel/cobalt/dovetail/tick.c
@@ -0,0 +1,45 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2001,2002,2003,2007,2012 Philippe Gerum <rpm@xenomai.org>.
+ * Copyright (C) 2004 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
+ */
+
+#include <linux/tick.h>
+#include <cobalt/kernel/intr.h>
+#include <pipeline/tick.h>
+
+extern struct xnintr nktimer;
+
+int pipeline_install_tick_proxy(void)
+{
+	int ret;
+
+	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
+	if (ret)
+		return ret;
+
+	/* Install the proxy tick device */
+	TODO();	ret = 0;
+	if (ret)
+		goto fail_proxy;
+
+	return 0;
+
+fail_proxy:
+	pipeline_free_timer_ipi();
+
+	return ret;
+}
+
+void pipeline_uninstall_tick_proxy(void)
+{
+	/* Uninstall the proxy tick device. */
+	TODO();
+
+	pipeline_free_timer_ipi();
+
+#ifdef CONFIG_XENO_OPT_STATS_IRQS
+	xnintr_destroy(&nktimer);
+#endif /* CONFIG_XENO_OPT_STATS_IRQS */
+}
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 13/18] cobalt/trace: dovetail: add placeholders for trace management
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (10 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 14/18] cobalt/wrapper: dovetail: add empty placeholder Philippe Gerum
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 .../cobalt/kernel/dovetail/pipeline/trace.h   | 123 ++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/trace.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/trace.h b/include/cobalt/kernel/dovetail/pipeline/trace.h
new file mode 100644
index 000000000..819b8a713
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/trace.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006 Jan Kiszka <jan.kiszka@web.de>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#ifndef _COBALT_KERNEL_DOVETAIL_TRACE_H
+#define _COBALT_KERNEL_DOVETAIL_TRACE_H
+
+#include <linux/types.h>
+#include <linux/kconfig.h>
+#include <cobalt/uapi/kernel/trace.h>
+
+static inline int xntrace_max_begin(unsigned long v)
+{
+//#chz: NTD
+	//ipipe_trace_begin(v);
+	return 0;
+}
+
+static inline int xntrace_max_end(unsigned long v)
+{
+//#chz: NTD
+	//ipipe_trace_end(v);
+	return 0;
+}
+
+static inline int xntrace_max_reset(void)
+{
+//#chz: NTD
+	//ipipe_trace_max_reset();
+	return 0;
+}
+
+static inline int xntrace_user_start(void)
+{
+//#chz: NTD
+	//return ipipe_trace_frozen_reset();
+	return 0;
+}
+
+static inline int xntrace_user_stop(unsigned long v)
+{
+//#chz: NTD
+	//ipipe_trace_freeze(v);
+	return 0;
+}
+
+static inline int xntrace_user_freeze(unsigned long v, int once)
+{
+	int ret = 0;
+//#chz: NTD
+/*
+	if (!once)
+		ret = ipipe_trace_frozen_reset();
+
+	ipipe_trace_freeze(v);
+*/
+	return ret;
+}
+
+static inline int xntrace_special(unsigned char id, unsigned long v)
+{
+//#chz: NTD
+//	ipipe_trace_special(id, v);
+	return 0;
+}
+
+static inline int xntrace_special_u64(unsigned char id,
+					unsigned long long v)
+{
+//#chz: NTD
+//	ipipe_trace_special(id, (unsigned long)(v >> 32));
+//	ipipe_trace_special(id, (unsigned long)(v & 0xFFFFFFFF));
+	return 0;
+}
+
+static inline int xntrace_pid(pid_t pid, short prio)
+{
+//#chz: NTD
+//	ipipe_trace_pid(pid, prio);
+	return 0;
+}
+
+static inline int xntrace_tick(unsigned long delay_ticks)
+{
+//#chz: NTD
+//	ipipe_trace_event(0, delay_ticks);
+	return 0;
+}
+
+static inline int xntrace_panic_freeze(void)
+{
+//#chz: NTD
+//	ipipe_trace_panic_freeze();
+	return 0;
+}
+
+static inline int xntrace_panic_dump(void)
+{
+//#chz: NTD
+//	ipipe_trace_panic_dump();
+	return 0;
+}
+
+static inline bool xntrace_enabled(void)
+{
+	return IS_ENABLED(CONFIG_DOVETAIL_TRACE);
+}
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_TRACE_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 14/18] cobalt/wrapper: dovetail: add empty placeholder
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (11 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 13/18] cobalt/trace: dovetail: add placeholders for trace management Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 15/18] cobalt/syscall: dovetail: implement syscall hooks Philippe Gerum
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 include/cobalt/kernel/dovetail/pipeline/wrappers.h | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 include/cobalt/kernel/dovetail/pipeline/wrappers.h

diff --git a/include/cobalt/kernel/dovetail/pipeline/wrappers.h b/include/cobalt/kernel/dovetail/pipeline/wrappers.h
new file mode 100644
index 000000000..133aacac3
--- /dev/null
+++ b/include/cobalt/kernel/dovetail/pipeline/wrappers.h
@@ -0,0 +1,9 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ */
+#ifndef _COBALT_KERNEL_DOVETAIL_WRAPPERS_H
+#define _COBALT_KERNEL_DOVETAIL_WRAPPERS_H
+
+/* No wrapper needed so far. */
+
+#endif /* !_COBALT_KERNEL_DOVETAIL_WRAPPERS_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 15/18] cobalt/syscall: dovetail: implement syscall hooks
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (12 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 14/18] cobalt/wrapper: dovetail: add empty placeholder Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 16/18] cobalt/dovetail: provide core-specific context extensions Philippe Gerum
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

Dovetail interposes on the in-band syscall entry, passing the request
on to Cobalt via different handlers depending on the calling context:

- via handle_oob_syscall() when the current thread is running
  out-of-band, and the request is not an in-band (i.e. regular Linux)
  system call, therefore shall be handled by Xenomai. This is the fast
  path.

- via handle_pipelined_syscall() in all other cases, e.g. when current
  is running in-band, and/or the system call shall be handled by the
  in-band kernel eventually (useful for relaxing the current thread in
  the process if out-of-band on entry).

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 kernel/cobalt/dovetail/Makefile  |  2 +-
 kernel/cobalt/dovetail/syscall.c | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 kernel/cobalt/dovetail/syscall.c

diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
index 84788f9ce..1ecbd97a9 100644
--- a/kernel/cobalt/dovetail/Makefile
+++ b/kernel/cobalt/dovetail/Makefile
@@ -2,4 +2,4 @@ ccflags-y += -I$(srctree)/kernel
 
 obj-y +=	pipeline.o
 
-pipeline-y :=	init.o kevents.o sched.o tick.o
+pipeline-y :=	init.o kevents.o sched.o tick.o syscall.o
diff --git a/kernel/cobalt/dovetail/syscall.c b/kernel/cobalt/dovetail/syscall.c
new file mode 100644
index 000000000..cec6c0244
--- /dev/null
+++ b/kernel/cobalt/dovetail/syscall.c
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2005 Philippe Gerum <rpm@xenomai.org>
+ * Copyright (C) 2005 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
+ */
+
+#include <linux/irqstage.h>
+#include <pipeline/pipeline.h>
+#include <pipeline/kevents.h>
+#include <cobalt/kernel/assert.h>
+#include <xenomai/posix/syscall.h>
+
+int handle_pipelined_syscall(struct irq_stage *stage, struct pt_regs *regs)
+{
+	if (unlikely(running_inband()))
+		return handle_root_syscall(regs);
+
+	return handle_head_syscall(stage == &inband_stage, regs);
+}
+
+void handle_oob_syscall(struct pt_regs *regs)
+{
+	int ret = handle_head_syscall(false, regs);
+	XENO_BUG_ON(COBALT, ret == KEVENT_PROPAGATE);
+}
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 16/18] cobalt/dovetail: provide core-specific context extensions
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (13 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 15/18] cobalt/syscall: dovetail: implement syscall hooks Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 17/18] drivers/net: Kconfig: fix help stanzas in configuration blocks Philippe Gerum
  2021-02-07 16:04 ` [PATCH 18/18] cobalt/assert: remove extraneous header inclusion Philippe Gerum
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

In order to intimately connect Cobalt to the kernel, Dovetail allows
us to extend the latter with data and procedures we need:

- we can embed our own context information into a set of critical
  kernel data structures. This information should be defined as a set
  of core-specific types, such as struct oob_thread_state which is
  going to be part of struct thread_info.

- we can define preparation and finalization handlers for out-of-band
  IRQ handling, which Dovetail should invoke right after entering the
  outer interrupt frame, then right before leaving it respectively.

Add the couple of interface headers we need to connect those elements
to the kernel.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 kernel/cobalt/include/dovetail/irq.h         | 52 ++++++++++++++++++++
 kernel/cobalt/include/dovetail/thread_info.h | 33 +++++++++++++
 2 files changed, 85 insertions(+)
 create mode 100644 kernel/cobalt/include/dovetail/irq.h
 create mode 100644 kernel/cobalt/include/dovetail/thread_info.h

diff --git a/kernel/cobalt/include/dovetail/irq.h b/kernel/cobalt/include/dovetail/irq.h
new file mode 100644
index 000000000..66d020fde
--- /dev/null
+++ b/kernel/cobalt/include/dovetail/irq.h
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2017 Philippe Gerum  <rpm@xenomai.org>
+ */
+
+#ifndef _COBALT_DOVETAIL_IRQ_H
+#define _COBALT_DOVETAIL_IRQ_H
+
+#ifdef CONFIG_XENOMAI
+
+#include <cobalt/kernel/sched.h>
+
+/* hard irqs off. */
+static inline void irq_enter_pipeline(void)
+{
+	struct xnsched *sched = xnsched_current();
+
+	sched->lflags |= XNINIRQ;
+}
+
+/* hard irqs off. */
+static inline void irq_exit_pipeline(void)
+{
+	struct xnsched *sched = xnsched_current();
+
+	sched->lflags &= ~XNINIRQ;
+
+	/*
+	 * CAUTION: Switching stages as a result of rescheduling may
+	 * re-enable irqs, shut them off before returning if so.
+	 */
+	if ((sched->status|sched->lflags) & XNRESCHED) {
+		xnsched_run();
+		if (!hard_irqs_disabled())
+			hard_local_irq_disable();
+	}
+}
+
+#else  /* !CONFIG_XENOMAI */
+
+static inline void irq_enter_pipeline(void)
+{
+}
+
+static inline void irq_exit_pipeline(void)
+{
+}
+
+#endif	/* !CONFIG_XENOMAI */
+
+#endif /* !_COBALT_DOVETAIL_IRQ_H */
diff --git a/kernel/cobalt/include/dovetail/thread_info.h b/kernel/cobalt/include/dovetail/thread_info.h
new file mode 100644
index 000000000..69b89de35
--- /dev/null
+++ b/kernel/cobalt/include/dovetail/thread_info.h
@@ -0,0 +1,33 @@
+/**
+ * Copyright (C) 2012 Philippe Gerum <rpm@xenomai.org>.
+ * Copyright (c) Siemens AG, 2020
+ *
+ * Xenomai is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
+ * USA; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifndef _COBALT_DOVETAIL_THREAD_INFO_H
+#define _COBALT_DOVETAIL_THREAD_INFO_H
+
+struct xnthread;
+struct cobalt_process;
+
+struct oob_thread_state {
+	/* Core thread backlink. */
+	struct xnthread *thread;
+	/* User process backlink. NULL for core threads. */
+	struct cobalt_process *process;
+};
+
+#endif /* !_COBALT_DOVETAIL_THREAD_INFO_H */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 17/18] drivers/net: Kconfig: fix help stanzas in configuration blocks
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (14 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 16/18] cobalt/dovetail: provide core-specific context extensions Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  2021-02-07 16:04 ` [PATCH 18/18] cobalt/assert: remove extraneous header inclusion Philippe Gerum
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

The Kconfig parser became stricter, help stanzas must be introduced by
the naked "help" keyword, period. Let's drop all decorations.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 kernel/drivers/net/Kconfig                   |  2 +-
 kernel/drivers/net/addons/Kconfig            |  6 +++---
 kernel/drivers/net/drivers/Kconfig           |  6 +++---
 kernel/drivers/net/stack/Kconfig             |  6 +++---
 kernel/drivers/net/stack/ipv4/Kconfig        | 14 +++++++-------
 kernel/drivers/net/stack/ipv4/tcp/Kconfig    |  4 ++--
 kernel/drivers/net/stack/ipv4/udp/Kconfig    |  2 +-
 kernel/drivers/net/stack/packet/Kconfig      |  2 +-
 kernel/drivers/net/stack/rtcfg/Kconfig       |  4 ++--
 kernel/drivers/net/stack/rtmac/Kconfig       |  2 +-
 kernel/drivers/net/stack/rtmac/nomac/Kconfig |  2 +-
 kernel/drivers/net/stack/rtmac/tdma/Kconfig  |  4 ++--
 12 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/kernel/drivers/net/Kconfig b/kernel/drivers/net/Kconfig
index ac3bced25..2e8032464 100644
--- a/kernel/drivers/net/Kconfig
+++ b/kernel/drivers/net/Kconfig
@@ -10,7 +10,7 @@ if XENO_DRIVERS_NET
 config XENO_DRIVERS_RTNET_CHECKED
     bool "Internal Bug Checks"
     default n
-    ---help---
+    help
     Switch on if you face crashes when RTnet is running or if you suspect
     any other RTnet-related issues. This feature will add a few sanity
     checks at critical points that will produce warnings on the kernel
diff --git a/kernel/drivers/net/addons/Kconfig b/kernel/drivers/net/addons/Kconfig
index baa6cbcb9..e92f6d8ca 100644
--- a/kernel/drivers/net/addons/Kconfig
+++ b/kernel/drivers/net/addons/Kconfig
@@ -6,7 +6,7 @@ config XENO_DRIVERS_NET_ADDON_RTCAP
     select ETHERNET
     tristate "Real-Time Capturing Support"
     default n
-    ---help---
+    help
     This feature allows to capture real-time packets traversing the RTnet
     stack. It can both be used to sniff passively on a network (in this
     case you may want to enable the promisc mode of your real-time NIC via
@@ -22,7 +22,7 @@ config XENO_DRIVERS_NET_ADDON_PROXY
     select ETHERNET
     tristate "IP protocol proxy for Linux"
     default n
-    ---help---
+    help
     Enables a forward-to-Linux module for all IP protocols that are not
     handled by the IPv4 implemenation of RTnet (TCP, UDP, etc.). Only use
     when you know what you are doing - it can easily break your real-time
@@ -34,7 +34,7 @@ config XENO_DRIVERS_NET_ADDON_PROXY_ARP
     depends on XENO_DRIVERS_NET_ADDON_PROXY
     bool "Enable ARP handling via protocol proxy"
     default n
-    ---help---
+    help
     Enables ARP support for the IP protocol proxy. Incoming ARP replies
     are then delivered to both, the RTnet and the Linux network stack,
     but only answered by Linux. The IP protocol proxy gets attached to
diff --git a/kernel/drivers/net/drivers/Kconfig b/kernel/drivers/net/drivers/Kconfig
index b2df1110f..6889a500d 100644
--- a/kernel/drivers/net/drivers/Kconfig
+++ b/kernel/drivers/net/drivers/Kconfig
@@ -24,7 +24,7 @@ config XENO_DRIVERS_NET_DRV_EEPRO100_CMDTIMEOUT
     int "Command Timeout"
     depends on XENO_DRIVERS_NET_DRV_EEPRO100
     default 20
-    ---help---
+    help
     Timeout in microseconds of transmission or configuration commands that
     are issued in real-time contexts.
 
@@ -32,7 +32,7 @@ config XENO_DRIVERS_NET_DRV_EEPRO100_DBG
     depends on XENO_DRIVERS_NET && PCI
     bool "Enable debugging and instrumentation"
     depends on XENO_DRIVERS_NET_DRV_EEPRO100
-    ---help---
+    help
     This option switches on internal debugging code of the EEPRO/100 driver.
     It also enables the collection of worst-case command delays in real-time
     contexts in order to reduce the command timeout (which, effectively, will
@@ -127,7 +127,7 @@ config XENO_DRIVERS_NET_DRV_MACB
     depends on XENO_DRIVERS_NET
     select AT91_PROGRAMMABLE_CLOCKS if ARCH_AT91
     tristate "Cadence MACB/GEM devices"
-    ---help---
+    help
     Driver for internal MAC-controller on AT91SAM926x microcontrollers.
     Porting by Cristiano Mantovani and Stefano Banzi (Marposs SpA).
 
diff --git a/kernel/drivers/net/stack/Kconfig b/kernel/drivers/net/stack/Kconfig
index 830cec5ad..996536cc5 100644
--- a/kernel/drivers/net/stack/Kconfig
+++ b/kernel/drivers/net/stack/Kconfig
@@ -7,7 +7,7 @@ config XENO_DRIVERS_NET_RX_FIFO_SIZE
     int "Size of central RX-FIFO"
     depends on XENO_DRIVERS_NET
     default 32
-    ---help---
+    help
     Size of FIFO between NICs and stack manager task. Must be power
     of two! Effectively, only CONFIG_RTNET_RX_FIFO_SIZE-1 slots will
     be usable.
@@ -15,7 +15,7 @@ config XENO_DRIVERS_NET_RX_FIFO_SIZE
 config XENO_DRIVERS_NET_ETH_P_ALL
     depends on XENO_DRIVERS_NET
     bool "Support for ETH_P_ALL"
-    ---help---
+    help
     Enables core support for registering listeners on all layer 3
     protocols (ETH_P_ALL). Internally this is currently realised by
     clone-copying incoming frames for those listners, future versions
@@ -26,7 +26,7 @@ config XENO_DRIVERS_NET_ETH_P_ALL
 config XENO_DRIVERS_NET_RTWLAN
     depends on XENO_DRIVERS_NET
     bool "Real-Time WLAN"
-    ---help---
+    help
     Enables core support for real-time wireless LAN. RT-WLAN is based
     on low-level access to 802.11-compliant adapters and is currently
     in an experimental stage.
diff --git a/kernel/drivers/net/stack/ipv4/Kconfig b/kernel/drivers/net/stack/ipv4/Kconfig
index 8fb3c1acc..d5a6cd6d7 100644
--- a/kernel/drivers/net/stack/ipv4/Kconfig
+++ b/kernel/drivers/net/stack/ipv4/Kconfig
@@ -2,7 +2,7 @@ config XENO_DRIVERS_NET_RTIPV4
     depends on XENO_DRIVERS_NET
     tristate "Real-Time IPv4"
     default y
-    ---help---
+    help
     Enables the real-time capable IPv4 support of RTnet. The protocol is
     implemented as a separate module. Supplementing tools (rtroute,
     rtping) and examples are provided as well. Moreover, RTcfg will
@@ -15,7 +15,7 @@ config XENO_DRIVERS_NET_RTIPV4_ICMP
     bool "ICMP support"
     depends on XENO_DRIVERS_NET_RTIPV4
     default y
-    ---help---
+    help
     Enables ICMP support of the RTnet Real-Time IPv4 protocol.
 
     When the RTnet-Proxy is enabled while this feature is disabled, ICMP
@@ -25,7 +25,7 @@ config XENO_DRIVERS_NET_RTIPV4_HOST_ROUTES
     int "Maximum host routing table entries"
     depends on XENO_DRIVERS_NET_RTIPV4
     default 32
-    ---help---
+    help
     Each IPv4 supporting interface and each remote host that is directly
     reachable via via some output interface requires a host routing table
     entry. If you run larger networks with may hosts per subnet, you may
@@ -34,7 +34,7 @@ config XENO_DRIVERS_NET_RTIPV4_HOST_ROUTES
 config XENO_DRIVERS_NET_RTIPV4_NETROUTING
     bool "IP Network Routing"
     depends on XENO_DRIVERS_NET_RTIPV4
-    ---help---
+    help
     Enables routing across IPv4 real-time networks. You will only require
     this feature in complex networks, while switching it off for flat,
     single-segment networks improves code size and the worst-case routing
@@ -46,7 +46,7 @@ config XENO_DRIVERS_NET_RTIPV4_NET_ROUTES
     int "Maximum network routing table entries"
     depends on XENO_DRIVERS_NET_RTIPV4_NETROUTING
     default 16
-    ---help---
+    help
     Each route describing a target network reachable via a router
     requires an entry in the network routing table. If you run very
     complex realtime networks, you may have to increase this limit. Must
@@ -55,7 +55,7 @@ config XENO_DRIVERS_NET_RTIPV4_NET_ROUTES
 config XENO_DRIVERS_NET_RTIPV4_ROUTER
     bool "IP Router"
     depends on XENO_DRIVERS_NET_RTIPV4
-    ---help---
+    help
     When switched on, the RTnet station will be able to forward IPv4
     packets that are not directed to the station itself. Typically used in
     combination with CONFIG_RTNET_RTIPV4_NETROUTING.
@@ -67,7 +67,7 @@ config XENO_DRIVERS_NET_RTIPV4_DEBUG
     depends on XENO_DRIVERS_NET_RTIPV4
     default n
     
-    ---help---
+    help
     Enables debug message output of the RTipv4 layer. Typically, you
     may want to turn this on for tracing issues in packet delivery.
 
diff --git a/kernel/drivers/net/stack/ipv4/tcp/Kconfig b/kernel/drivers/net/stack/ipv4/tcp/Kconfig
index 5b1182d72..a69d34679 100644
--- a/kernel/drivers/net/stack/ipv4/tcp/Kconfig
+++ b/kernel/drivers/net/stack/ipv4/tcp/Kconfig
@@ -1,7 +1,7 @@
 config XENO_DRIVERS_NET_RTIPV4_TCP
     tristate "TCP support"
     depends on XENO_DRIVERS_NET_RTIPV4
-    ---help---
+    help
     Enables TCP support of the RTnet Real-Time IPv4 protocol.
 
     When the RTnet IPv4 is enabled while this feature is disabled, TCP
@@ -10,7 +10,7 @@ config XENO_DRIVERS_NET_RTIPV4_TCP
 config XENO_DRIVERS_NET_RTIPV4_TCP_ERROR_INJECTION
     bool "TCP error injection"
     depends on XENO_DRIVERS_NET_RTIPV4_TCP
-    ---help---
+    help
     Enables error injection for incoming TCP packets. This can be used
     to test both protocol as well as application behavior under error
     conditions. The per-socket error rate is 0 by default and can be
diff --git a/kernel/drivers/net/stack/ipv4/udp/Kconfig b/kernel/drivers/net/stack/ipv4/udp/Kconfig
index 77779a1a1..a23279411 100644
--- a/kernel/drivers/net/stack/ipv4/udp/Kconfig
+++ b/kernel/drivers/net/stack/ipv4/udp/Kconfig
@@ -2,5 +2,5 @@ config XENO_DRIVERS_NET_RTIPV4_UDP
     tristate "UDP support"
     depends on XENO_DRIVERS_NET_RTIPV4
     default y
-    ---help---
+    help
     Enables UDP support of the RTnet Real-Time IPv4 protocol.
diff --git a/kernel/drivers/net/stack/packet/Kconfig b/kernel/drivers/net/stack/packet/Kconfig
index 1424ffb6b..4c83b73c2 100644
--- a/kernel/drivers/net/stack/packet/Kconfig
+++ b/kernel/drivers/net/stack/packet/Kconfig
@@ -2,7 +2,7 @@ config XENO_DRIVERS_NET_RTPACKET
     depends on XENO_DRIVERS_NET
     tristate "Real-Time Packet Socket Support"
     default y
-    ---help---
+    help
     Enables real-time packet sockets for RTnet. This support is
     implemented in a separate module. When loaded, application programs
     can send and received so-called "cooked" packets directly at OSI layer
diff --git a/kernel/drivers/net/stack/rtcfg/Kconfig b/kernel/drivers/net/stack/rtcfg/Kconfig
index d5af3b826..38c484046 100644
--- a/kernel/drivers/net/stack/rtcfg/Kconfig
+++ b/kernel/drivers/net/stack/rtcfg/Kconfig
@@ -2,7 +2,7 @@ config XENO_DRIVERS_NET_RTCFG
     depends on XENO_DRIVERS_NET
     tristate "RTcfg Service"
     default y
-    ---help---
+    help
     The Real-Time Configuration service configures and monitors nodes in
     a RTnet network. It works both with plain MAC as well as with IPv4
     addresses (in case CONFIG_RTNET_RTIPV4 has been switched on). RTcfg
@@ -18,6 +18,6 @@ config XENO_DRIVERS_NET_RTCFG_DEBUG
     bool "RTcfg Debugging"
     depends on XENO_DRIVERS_NET_RTCFG
     default n
-    ---help---
+    help
     Enables debug message output of the RTcfg state machines. Switch on if
     you have to trace some problem related to RTcfg.
diff --git a/kernel/drivers/net/stack/rtmac/Kconfig b/kernel/drivers/net/stack/rtmac/Kconfig
index 604cb4bc1..a97b316b0 100644
--- a/kernel/drivers/net/stack/rtmac/Kconfig
+++ b/kernel/drivers/net/stack/rtmac/Kconfig
@@ -2,7 +2,7 @@ menuconfig XENO_DRIVERS_NET_RTMAC
     depends on XENO_DRIVERS_NET
     tristate "RTmac Layer"
     default y
-    ---help---
+    help
     The Real-Time Media Access Control layer allows to extend the RTnet
     stack with software-based access control mechanisms (also called
     disciplines) for nondeterministic transport media. Disciplines can be
diff --git a/kernel/drivers/net/stack/rtmac/nomac/Kconfig b/kernel/drivers/net/stack/rtmac/nomac/Kconfig
index 868673935..e706d4a96 100644
--- a/kernel/drivers/net/stack/rtmac/nomac/Kconfig
+++ b/kernel/drivers/net/stack/rtmac/nomac/Kconfig
@@ -2,7 +2,7 @@ config XENO_DRIVERS_NET_NOMAC
     tristate "NoMAC discipline for RTmac"
     depends on XENO_DRIVERS_NET_RTMAC
     default n
-    ---help---
+    help
     This no-operation RTmac discipline is intended to act as a template
     for new implementations. However, it can be compiled and used (see
     nomaccfg management tool), but don't expect any improved determinism
diff --git a/kernel/drivers/net/stack/rtmac/tdma/Kconfig b/kernel/drivers/net/stack/rtmac/tdma/Kconfig
index b56f8251a..4444661f2 100644
--- a/kernel/drivers/net/stack/rtmac/tdma/Kconfig
+++ b/kernel/drivers/net/stack/rtmac/tdma/Kconfig
@@ -2,7 +2,7 @@ config XENO_DRIVERS_NET_TDMA
     tristate "TDMA discipline for RTmac"
     depends on XENO_DRIVERS_NET_RTMAC
     default y
-    ---help---
+    help
     The Time Division Multiple Access discipline is the default RTmac
     protocol for Ethernet networks. It consists of a master synchronising
     the access of the slaves to the media by periodically issuing frames.
@@ -16,6 +16,6 @@ config XENO_DRIVERS_NET_TDMA_MASTER
     bool "TDMA master support"
     depends on XENO_DRIVERS_NET_TDMA
     default y
-    ---help---
+    help
     Enables TDMA master and backup master support for the node. This can
     be switched of to reduce the memory footprint of pure slave nodes.
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 18/18] cobalt/assert: remove extraneous header inclusion
  2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
                   ` (15 preceding siblings ...)
  2021-02-07 16:04 ` [PATCH 17/18] drivers/net: Kconfig: fix help stanzas in configuration blocks Philippe Gerum
@ 2021-02-07 16:04 ` Philippe Gerum
  16 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-07 16:04 UTC (permalink / raw)
  To: xenomai

From: Philippe Gerum <rpm@xenomai.org>

In the same move, fix places which depend on such inclusion but fail
to pull the related headers directly.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
---
 include/cobalt/kernel/assert.h | 3 ---
 kernel/cobalt/heap.c           | 1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/cobalt/kernel/assert.h b/include/cobalt/kernel/assert.h
index 8d004476b..abe044100 100644
--- a/include/cobalt/kernel/assert.h
+++ b/include/cobalt/kernel/assert.h
@@ -20,9 +20,6 @@
 #define _COBALT_KERNEL_ASSERT_H
 
 #include <linux/kconfig.h>
-#include <pipeline/pipeline.h>
-#include <cobalt/kernel/trace.h>
-#include <cobalt/kernel/ancillaries.h>
 
 #define XENO_INFO	KERN_INFO    "[Xenomai] "
 #define XENO_WARNING	KERN_WARNING "[Xenomai] "
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 5d14a4739..9e184d4c3 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -27,6 +27,7 @@
 #include <cobalt/kernel/assert.h>
 #include <cobalt/kernel/heap.h>
 #include <cobalt/kernel/vfile.h>
+#include <cobalt/kernel/ancillaries.h>
 
 /**
  * @ingroup cobalt_core
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management
  2021-02-07 16:04 ` [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management Philippe Gerum
@ 2021-02-08 18:59   ` Jan Kiszka
  2021-02-09  9:15     ` Philippe Gerum
  0 siblings, 1 reply; 25+ messages in thread
From: Jan Kiszka @ 2021-02-08 18:59 UTC (permalink / raw)
  To: Philippe Gerum, xenomai

On 07.02.21 17:04, Philippe Gerum wrote:
> From: Philippe Gerum <rpm@xenomai.org>
> 
> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
> ---
>  .../cobalt/kernel/dovetail/pipeline/tick.h    | 12 +++++
>  kernel/cobalt/dovetail/Makefile               |  2 +-
>  kernel/cobalt/dovetail/tick.c                 | 45 +++++++++++++++++++
>  3 files changed, 58 insertions(+), 1 deletion(-)
>  create mode 100644 include/cobalt/kernel/dovetail/pipeline/tick.h
>  create mode 100644 kernel/cobalt/dovetail/tick.c
> 
> diff --git a/include/cobalt/kernel/dovetail/pipeline/tick.h b/include/cobalt/kernel/dovetail/pipeline/tick.h
> new file mode 100644
> index 000000000..409581a3c
> --- /dev/null
> +++ b/include/cobalt/kernel/dovetail/pipeline/tick.h
> @@ -0,0 +1,12 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0
> + */
> +
> +#ifndef _COBALT_KERNEL_IPIPE_TICK_H
> +#define _COBALT_KERNEL_IPIPE_TICK_H
> +
> +int pipeline_install_tick_proxy(void);
> +
> +void pipeline_uninstall_tick_proxy(void);
> +
> +#endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
> diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
> index 24320b3f2..84788f9ce 100644
> --- a/kernel/cobalt/dovetail/Makefile
> +++ b/kernel/cobalt/dovetail/Makefile
> @@ -2,4 +2,4 @@ ccflags-y += -I$(srctree)/kernel
>  
>  obj-y +=	pipeline.o
>  
> -pipeline-y :=	init.o kevents.o sched.o
> +pipeline-y :=	init.o kevents.o sched.o tick.o
> diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
> new file mode 100644
> index 000000000..02cd86690
> --- /dev/null
> +++ b/kernel/cobalt/dovetail/tick.c
> @@ -0,0 +1,45 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0
> + *
> + * Copyright (C) 2001,2002,2003,2007,2012 Philippe Gerum <rpm@xenomai.org>.
> + * Copyright (C) 2004 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
> + */
> +
> +#include <linux/tick.h>
> +#include <cobalt/kernel/intr.h>
> +#include <pipeline/tick.h>
> +
> +extern struct xnintr nktimer;
> +
> +int pipeline_install_tick_proxy(void)
> +{
> +	int ret;
> +
> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);

Why calling an abstraction here? We know that we are in dovetail land.

I know we do the same on ipipe already. But maybe fix that first and
avoid this over-abstraction here in the first place.

> +	if (ret)
> +		return ret;
> +
> +	/* Install the proxy tick device */
> +	TODO();	ret = 0;
> +	if (ret)
> +		goto fail_proxy;
> +
> +	return 0;
> +
> +fail_proxy:
> +	pipeline_free_timer_ipi();
> +
> +	return ret;
> +}
> +
> +void pipeline_uninstall_tick_proxy(void)
> +{
> +	/* Uninstall the proxy tick device. */
> +	TODO();
> +
> +	pipeline_free_timer_ipi();
> +
> +#ifdef CONFIG_XENO_OPT_STATS_IRQS
> +	xnintr_destroy(&nktimer);
> +#endif /* CONFIG_XENO_OPT_STATS_IRQS */
> +}
> 

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs
  2021-02-07 16:04 ` [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs Philippe Gerum
@ 2021-02-08 19:02   ` Jan Kiszka
  2021-02-09  9:04     ` Philippe Gerum
  0 siblings, 1 reply; 25+ messages in thread
From: Jan Kiszka @ 2021-02-08 19:02 UTC (permalink / raw)
  To: Philippe Gerum, xenomai

On 07.02.21 17:04, Philippe Gerum wrote:
> From: Philippe Gerum <rpm@xenomai.org>
> 
> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
> ---
>  kernel/cobalt/ipipe/tick.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/cobalt/ipipe/tick.c b/kernel/cobalt/ipipe/tick.c
> index da1563a66..b711bedc0 100644
> --- a/kernel/cobalt/ipipe/tick.c
> +++ b/kernel/cobalt/ipipe/tick.c
> @@ -187,7 +187,7 @@ int pipeline_install_tick_proxy(void)
>  	nkclock.wallclock_offset =
>  		ktime_to_ns(ktime_get_real()) - xnclock_read_monotonic(&nkclock);
>  
> -	ret = xntimer_setup_ipi();
> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);

Ah, here we change this to the suboptimal pattern: Just fold that
implementation in here.

We should try to reduce needless static inlines.

>  	if (ret)
>  		return ret;
>  
> @@ -244,7 +244,7 @@ fail:
>  		ipipe_timer_stop(_cpu);
>  	}
>  
> -	xntimer_release_ipi();
> +	pipeline_free_timer_ipi();
>  
>  	return ret;
>  }
> @@ -270,7 +270,7 @@ void pipeline_uninstall_tick_proxy(void)
>  	for_each_realtime_cpu(cpu)
>  		ipipe_timer_stop(cpu);
>  
> -	xntimer_release_ipi();
> +	pipeline_free_timer_ipi();
>  
>  #ifdef CONFIG_XENO_OPT_STATS_IRQS
>  	xnintr_destroy(&nktimer);
> 

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors
  2021-02-07 16:04 ` [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors Philippe Gerum
@ 2021-02-08 19:03   ` Jan Kiszka
  0 siblings, 0 replies; 25+ messages in thread
From: Jan Kiszka @ 2021-02-08 19:03 UTC (permalink / raw)
  To: Philippe Gerum, xenomai

On 07.02.21 17:04, Philippe Gerum wrote:
> From: Philippe Gerum <rpm@xenomai.org>
> 
> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
> ---
>  .../cobalt/kernel/dovetail/pipeline/thread.h  | 27 +++++++++++++++++++
>  1 file changed, 27 insertions(+)
>  create mode 100644 include/cobalt/kernel/dovetail/pipeline/thread.h
> 
> diff --git a/include/cobalt/kernel/dovetail/pipeline/thread.h b/include/cobalt/kernel/dovetail/pipeline/thread.h
> new file mode 100644
> index 000000000..1e6b0f091
> --- /dev/null
> +++ b/include/cobalt/kernel/dovetail/pipeline/thread.h
> @@ -0,0 +1,27 @@
> +/*
> + * SPDX-License-Identifier: GPL-2.0
> + *
> + * Copyright (C) 2019 Philippe Gerum  <rpm@xenomai.org>
> + */
> +
> +#ifndef _COBALT_KERNEL_DOVETAIL_THREAD_H
> +#define _COBALT_KERNEL_DOVETAIL_THREAD_H
> +
> +#include <linux/dovetail.h>
> +
> +struct xnthread;
> +
> +#define cobalt_threadinfo oob_thread_state
> +
> +static inline struct cobalt_threadinfo *pipeline_current(void)
> +{
> +	return dovetail_current_state();
> +}
> +
> +static inline
> +struct xnthread *pipeline_thread_from_task(struct task_struct *p)
> +{
> +	return dovetail_task_state(p)->thread;
> +}
> +
> +#endif /* !_COBALT_KERNEL_DOVETAIL_THREAD_H */
> 

Applied up to here to next.

Thanks,
Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs
  2021-02-08 19:02   ` Jan Kiszka
@ 2021-02-09  9:04     ` Philippe Gerum
  2021-02-09  9:10       ` Philippe Gerum
  2021-02-09 10:28       ` Jan Kiszka
  0 siblings, 2 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-09  9:04 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai


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

> On 07.02.21 17:04, Philippe Gerum wrote:
>> From: Philippe Gerum <rpm@xenomai.org>
>> 
>> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
>> ---
>>  kernel/cobalt/ipipe/tick.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/kernel/cobalt/ipipe/tick.c b/kernel/cobalt/ipipe/tick.c
>> index da1563a66..b711bedc0 100644
>> --- a/kernel/cobalt/ipipe/tick.c
>> +++ b/kernel/cobalt/ipipe/tick.c
>> @@ -187,7 +187,7 @@ int pipeline_install_tick_proxy(void)
>>  	nkclock.wallclock_offset =
>>  		ktime_to_ns(ktime_get_real()) - xnclock_read_monotonic(&nkclock);
>>  
>> -	ret = xntimer_setup_ipi();
>> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
>
> Ah, here we change this to the suboptimal pattern: Just fold that
> implementation in here.
>
> We should try to reduce needless static inlines.
>

The idea is rather to drop the xnintr layer which has zero value in this
case, because it does not abstract anything by itself, all is provided
by the pipeline-specific section. This is why the pipeline call moved
there, this is the one which brings value in, just like we directly call
the pipeline interface elsewhere from the generic section, to flatten
the call stack.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs
  2021-02-09  9:04     ` Philippe Gerum
@ 2021-02-09  9:10       ` Philippe Gerum
  2021-02-09 10:28       ` Jan Kiszka
  1 sibling, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-09  9:10 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai


Philippe Gerum <rpm@xenomai.org> writes:

> Jan Kiszka <jan.kiszka@siemens.com> writes:
>
>> On 07.02.21 17:04, Philippe Gerum wrote:
>>> From: Philippe Gerum <rpm@xenomai.org>
>>> 
>>> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
>>> ---
>>>  kernel/cobalt/ipipe/tick.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>> 
>>> diff --git a/kernel/cobalt/ipipe/tick.c b/kernel/cobalt/ipipe/tick.c
>>> index da1563a66..b711bedc0 100644
>>> --- a/kernel/cobalt/ipipe/tick.c
>>> +++ b/kernel/cobalt/ipipe/tick.c
>>> @@ -187,7 +187,7 @@ int pipeline_install_tick_proxy(void)
>>>  	nkclock.wallclock_offset =
>>>  		ktime_to_ns(ktime_get_real()) - xnclock_read_monotonic(&nkclock);
>>>  
>>> -	ret = xntimer_setup_ipi();
>>> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
>>
>> Ah, here we change this to the suboptimal pattern: Just fold that
>> implementation in here.
>>
>> We should try to reduce needless static inlines.
>>
>
> The idea is rather to drop the xnintr layer which has zero value in
> this

s,xnintr_,xntimer_,

-- 
Philippe.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management
  2021-02-08 18:59   ` Jan Kiszka
@ 2021-02-09  9:15     ` Philippe Gerum
  0 siblings, 0 replies; 25+ messages in thread
From: Philippe Gerum @ 2021-02-09  9:15 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai


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

> On 07.02.21 17:04, Philippe Gerum wrote:
>> From: Philippe Gerum <rpm@xenomai.org>
>> 
>> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
>> ---
>>  .../cobalt/kernel/dovetail/pipeline/tick.h    | 12 +++++
>>  kernel/cobalt/dovetail/Makefile               |  2 +-
>>  kernel/cobalt/dovetail/tick.c                 | 45 +++++++++++++++++++
>>  3 files changed, 58 insertions(+), 1 deletion(-)
>>  create mode 100644 include/cobalt/kernel/dovetail/pipeline/tick.h
>>  create mode 100644 kernel/cobalt/dovetail/tick.c
>> 
>> diff --git a/include/cobalt/kernel/dovetail/pipeline/tick.h b/include/cobalt/kernel/dovetail/pipeline/tick.h
>> new file mode 100644
>> index 000000000..409581a3c
>> --- /dev/null
>> +++ b/include/cobalt/kernel/dovetail/pipeline/tick.h
>> @@ -0,0 +1,12 @@
>> +/*
>> + * SPDX-License-Identifier: GPL-2.0
>> + */
>> +
>> +#ifndef _COBALT_KERNEL_IPIPE_TICK_H
>> +#define _COBALT_KERNEL_IPIPE_TICK_H
>> +
>> +int pipeline_install_tick_proxy(void);
>> +
>> +void pipeline_uninstall_tick_proxy(void);
>> +
>> +#endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
>> diff --git a/kernel/cobalt/dovetail/Makefile b/kernel/cobalt/dovetail/Makefile
>> index 24320b3f2..84788f9ce 100644
>> --- a/kernel/cobalt/dovetail/Makefile
>> +++ b/kernel/cobalt/dovetail/Makefile
>> @@ -2,4 +2,4 @@ ccflags-y += -I$(srctree)/kernel
>>  
>>  obj-y +=	pipeline.o
>>  
>> -pipeline-y :=	init.o kevents.o sched.o
>> +pipeline-y :=	init.o kevents.o sched.o tick.o
>> diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
>> new file mode 100644
>> index 000000000..02cd86690
>> --- /dev/null
>> +++ b/kernel/cobalt/dovetail/tick.c
>> @@ -0,0 +1,45 @@
>> +/*
>> + * SPDX-License-Identifier: GPL-2.0
>> + *
>> + * Copyright (C) 2001,2002,2003,2007,2012 Philippe Gerum <rpm@xenomai.org>.
>> + * Copyright (C) 2004 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
>> + */
>> +
>> +#include <linux/tick.h>
>> +#include <cobalt/kernel/intr.h>
>> +#include <pipeline/tick.h>
>> +
>> +extern struct xnintr nktimer;
>> +
>> +int pipeline_install_tick_proxy(void)
>> +{
>> +	int ret;
>> +
>> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
>
> Why calling an abstraction here? We know that we are in dovetail land.
>
> I know we do the same on ipipe already. But maybe fix that first and
> avoid this over-abstraction here in the first place.
>

Yes, we can remove that one. We need to keep the call hooking the
rescheduling IPI though, this one needs to be pulled in from the generic
scheduler core.

-- 
Philippe.


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs
  2021-02-09  9:04     ` Philippe Gerum
  2021-02-09  9:10       ` Philippe Gerum
@ 2021-02-09 10:28       ` Jan Kiszka
  1 sibling, 0 replies; 25+ messages in thread
From: Jan Kiszka @ 2021-02-09 10:28 UTC (permalink / raw)
  To: Philippe Gerum; +Cc: xenomai

On 09.02.21 10:04, Philippe Gerum wrote:
> 
> Jan Kiszka <jan.kiszka@siemens.com> writes:
> 
>> On 07.02.21 17:04, Philippe Gerum wrote:
>>> From: Philippe Gerum <rpm@xenomai.org>
>>>
>>> Signed-off-by: Philippe Gerum <rpm@xenomai.org>
>>> ---
>>>  kernel/cobalt/ipipe/tick.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/kernel/cobalt/ipipe/tick.c b/kernel/cobalt/ipipe/tick.c
>>> index da1563a66..b711bedc0 100644
>>> --- a/kernel/cobalt/ipipe/tick.c
>>> +++ b/kernel/cobalt/ipipe/tick.c
>>> @@ -187,7 +187,7 @@ int pipeline_install_tick_proxy(void)
>>>  	nkclock.wallclock_offset =
>>>  		ktime_to_ns(ktime_get_real()) - xnclock_read_monotonic(&nkclock);
>>>  
>>> -	ret = xntimer_setup_ipi();
>>> +	ret = pipeline_request_timer_ipi(xnintr_core_clock_handler);
>>
>> Ah, here we change this to the suboptimal pattern: Just fold that
>> implementation in here.
>>
>> We should try to reduce needless static inlines.
>>
> 
> The idea is rather to drop the xnintr layer which has zero value in this
> case, because it does not abstract anything by itself, all is provided
> by the pipeline-specific section. This is why the pipeline call moved
> there, this is the one which brings value in, just like we directly call
> the pipeline interface elsewhere from the generic section, to flatten
> the call stack.
> 

I don't disagree with this step, just that is stopped in the middle.
Make it complete, if you like on top, by folding
pipeline_request_timer_ipi & Co. in.

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-02-09 10:28 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 16:04 [PATCH 01/18] cobalt/init: dovetail: add placeholders for core init/cleanup Philippe Gerum
2021-02-07 16:04 ` [PATCH 02/18] cobalt/sirq: dovetail: add placeholders for synthetic IRQ management Philippe Gerum
2021-02-07 16:04 ` [PATCH 03/18] cobalt/irq: dovetail: add placeholders for out-of-band " Philippe Gerum
2021-02-07 16:04 ` [PATCH 04/18] cobalt/clock: dovetail: add placeholders for clock services Philippe Gerum
2021-02-07 16:04 ` [PATCH 05/18] cobalt/inband_work: dovetail: provide for deferred in-band calls Philippe Gerum
2021-02-07 16:04 ` [PATCH 06/18] cobalt/kevents: dovetail: add placeholders for kernel event handlers Philippe Gerum
2021-02-07 16:04 ` [PATCH 07/18] cobalt/lock: dovetail: define hard lock type Philippe Gerum
2021-02-07 16:04 ` [PATCH 08/18] cobalt/sched: dovetail: add placeholders for context switching Philippe Gerum
2021-02-07 16:04 ` [PATCH 09/18] cobalt/thread: dovetail: define out-of-band state accessors Philippe Gerum
2021-02-08 19:03   ` Jan Kiszka
2021-02-07 16:04 ` [PATCH 10/18] cobalt/timer: ipipe: directly use the abstract interface for IPIs Philippe Gerum
2021-02-08 19:02   ` Jan Kiszka
2021-02-09  9:04     ` Philippe Gerum
2021-02-09  9:10       ` Philippe Gerum
2021-02-09 10:28       ` Jan Kiszka
2021-02-07 16:04 ` [PATCH 11/18] cobalt/timer: remove useless wrappers to IPI management Philippe Gerum
2021-02-07 16:04 ` [PATCH 12/18] cobalt/tick: dovetail: add placeholders for tick management Philippe Gerum
2021-02-08 18:59   ` Jan Kiszka
2021-02-09  9:15     ` Philippe Gerum
2021-02-07 16:04 ` [PATCH 13/18] cobalt/trace: dovetail: add placeholders for trace management Philippe Gerum
2021-02-07 16:04 ` [PATCH 14/18] cobalt/wrapper: dovetail: add empty placeholder Philippe Gerum
2021-02-07 16:04 ` [PATCH 15/18] cobalt/syscall: dovetail: implement syscall hooks Philippe Gerum
2021-02-07 16:04 ` [PATCH 16/18] cobalt/dovetail: provide core-specific context extensions Philippe Gerum
2021-02-07 16:04 ` [PATCH 17/18] drivers/net: Kconfig: fix help stanzas in configuration blocks Philippe Gerum
2021-02-07 16:04 ` [PATCH 18/18] cobalt/assert: remove extraneous header inclusion Philippe Gerum

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.