Skip to contentSkip to conversation

cobalt/sched: init RESCHEDULE_OOB_IPI and register interrupt handler

PATCH New hongzha1 1 participant 15 messages Nov 9, 2020

lore
Share & tools
lore

hongzha1

author
#0 lore raw

PATCH 1/15 cobalt/sched: init RESCHEDULE_OOB_IPI and register interrupt handler

create and register RESCHEDULE_OOB_IPI interrupt handler

---
 kernel/cobalt/sched.c | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)
kernel/cobalt/sched.c +31 -7
index f39becb90..36eff09d4 100644
@@ -30,6 +30,13 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/cobalt-core.h>
 
+struct xn_machine_cpudata {
+};
+
+DEFINE_PER_CPU(struct xn_machine_cpudata, xn_machine_cpudata);
+
+static void xnsched_destroy(struct xnsched *sched);
+
 /**
  * @ingroup cobalt_core
  * @defgroup cobalt_core_sched Thread scheduling control
@@ -224,10 +231,18 @@ static void xnsched_init(struct xnsched *sched, int cpu)
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
 }
 
+static irqreturn_t reschedule_interrupt(int irq, void *dev_id)
+{
+	__xnsched_run_handler();
+
+	return IRQ_HANDLED;
+}
+
 void xnsched_init_all(void)
 {
 	struct xnsched *sched;
 	int cpu;
+	int ret;
 
 	for_each_online_cpu(cpu) {
 		sched = &per_cpu(nksched, cpu);
@@ -235,12 +250,22 @@ void xnsched_init_all(void)
 	}
 
 #ifdef CONFIG_SMP
-#warning TODO
-/*	ipipe_request_irq(&xnsched_realtime_domain,
-			  IPIPE_RESCHEDULE_IPI,
-			  (ipipe_irq_handler_t)__xnsched_run_handler,
-			  NULL, NULL);*/
+	ret = __request_percpu_irq(RESCHEDULE_OOB_IPI,
+			reschedule_interrupt,
+			IRQF_OOB,
+			"Xenomai reschedule",
+			&xn_machine_cpudata);
+	if (ret)
+		goto cleanup_sched;
 #endif
+	return;
+
+cleanup_sched:
+	for_each_online_cpu(cpu) {
+		sched = xnsched_struct(cpu);
+		xnsched_destroy(sched);
+	}
+
 }
 
 static void xnsched_destroy(struct xnsched *sched)
@@ -262,8 +287,7 @@ void xnsched_destroy_all(void)
 	spl_t s;
 
 #ifdef CONFIG_SMP
-#warning TODO
-//	ipipe_free_irq(&xnsched_realtime_domain, IPIPE_RESCHEDULE_IPI);
+	free_percpu_irq(RESCHEDULE_OOB_IPI, &xn_machine_cpudata);
 #endif
 
 	xnlock_get_irqsave(&nklock, s);
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/15 cobalt/sched: call irq_pipeline_send_remote to send RESCHEDULE_OOB_IPI

call irq_pipeline_send_remote to send RESCHEDULE_OOB_IPI instead of ipipe_send_ipi

---
 kernel/cobalt/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/sched.c +2 -2
index 36eff09d4..5f090ec79 100644
@@ -937,8 +937,8 @@ static inline int test_resched(struct xnsched *sched)
 	/* Send resched IPI to remote CPU(s). */
 	if (unlikely(!cpumask_empty(&sched->resched))) {
 		smp_mb();
-#warning TODO
-		//ipipe_send_ipi(IPIPE_RESCHEDULE_IPI, sched->resched);
+		irq_pipeline_send_remote(RESCHEDULE_OOB_IPI,
+				&sched->resched);
 		cpumask_clear(&sched->resched);
 	}
 #endif
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 3/15 cobalt/timer: create and register TIMER_OOB_IPI handler

In reply to hongzha1

1.create and register TIMER_OOB_IPI handler.
2.declare global xn_machine_cpudata so that it can be shared with other irq request.

---
 include/cobalt/kernel/sched.h |  6 ++++++
 kernel/cobalt/init.c          |  2 ++
 kernel/cobalt/sched.c         |  5 -----
 kernel/cobalt/timer.c         | 20 +++++++++++++-------
 4 files changed, 21 insertions(+), 12 deletions(-)
include/cobalt/kernel/sched.h +6 -0
index 1f5714fe0..d4f449e4a 100644
@@ -31,6 +31,12 @@
 #include <cobalt/kernel/assert.h>
 #include <asm/xenomai/machine.h>
 
+
+struct xn_machine_cpudata {
+};
+
+DECLARE_PER_CPU(struct xn_machine_cpudata, xn_machine_cpudata);
+
 /**
  * @addtogroup cobalt_core_sched
  * @{
kernel/cobalt/init.c +2 -0
index 9b1651528..563832738 100644
@@ -37,6 +37,8 @@
 #include "posix/internal.h"
 #include "procfs.h"
 
+DEFINE_PER_CPU(struct xn_machine_cpudata, xn_machine_cpudata);
+EXPORT_PER_CPU_SYMBOL_GPL(xn_machine_cpudata);
 
 static DEFINE_PER_CPU(int, cobalt_escalate_devid);
 /**
kernel/cobalt/sched.c +0 -5
index 5f090ec79..f54c411a0 100644
@@ -30,11 +30,6 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/cobalt-core.h>
 
-struct xn_machine_cpudata {
-};
-
-DEFINE_PER_CPU(struct xn_machine_cpudata, xn_machine_cpudata);
-
 static void xnsched_destroy(struct xnsched *sched);
 
 /**
kernel/cobalt/timer.c +13 -7
index bcfe832d1..9da2c6143 100644
@@ -576,19 +576,25 @@ void __xntimer_set_affinity(struct xntimer *timer, struct xnsched *sched)
 }
 EXPORT_SYMBOL_GPL(__xntimer_set_affinity);
 
+static irqreturn_t clock_ipi_handler(int irq, void *dev_id)
+{
+	xnintr_core_clock_handler();
+
+	return IRQ_HANDLED;
+}
+
 int xntimer_setup_ipi(void)
 {
-#warning TODO
-/*	return ipipe_request_irq(&xnsched_realtime_domain,
-				 IPIPE_HRTIMER_IPI,
-				 (ipipe_irq_handler_t)xnintr_core_clock_handler,
-				 NULL, NULL);*/
+	return __request_percpu_irq(TIMER_OOB_IPI,
+			clock_ipi_handler,
+			IRQF_OOB, "Xenomai timer IPI",
+			&xn_machine_cpudata);
 }
 
 void xntimer_release_ipi(void)
 {
-#warning TODO
-	//ipipe_free_irq(&xnsched_realtime_domain, IPIPE_HRTIMER_IPI);
+	free_percpu_irq(TIMER_OOB_IPI,
+			&xn_machine_cpudata);
 }
 
 #endif /* CONFIG_SMP */
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 4/15 cobalt/clock: call irq_pipeline_send_remote to trigger interrupt TIMER_OOB_IPI

In reply to hongzha1

call irq_pipeline_send_remote to trigger interrupt TIMER_OOB_IPI

---
 kernel/cobalt/clock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/cobalt/clock.c +2 -1
index 9716a0391..ab9fa394d 100644
@@ -235,7 +235,8 @@ void xnclock_core_remote_shot(struct xnsched *sched)
 #ifdef CONFIG_IPIPE
 	ipipe_send_ipi(IPIPE_HRTIMER_IPI, *cpumask_of(xnsched_cpu(sched)));
 #else
-#warning TODO
+	irq_pipeline_send_remote(TIMER_OOB_IPI,
+			cpumask_of(xnsched_cpu(sched)));
 #endif
 }
 #endif
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 5/15 cobalt/timer: make use of tick-proxy instead of original host tick

In reply to hongzha1

make use of tick-proxy which is base infastructure of pipeline to replace host tick of ipipeline.

---
 include/cobalt/kernel/sched.h |  5 ++
 kernel/cobalt/timer.c         | 88 +++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)
include/cobalt/kernel/sched.h +5 -0
index d4f449e4a..d0a291f9a 100644
@@ -53,6 +53,11 @@ DECLARE_PER_CPU(struct xn_machine_cpudata, xn_machine_cpudata);
 #define XNINIRQ		0x00004000	/* In IRQ handling context */
 #define XNHDEFER	0x00002000	/* Host tick deferred */
 
+/*
+ * Hardware timer is stopped.
+ */
+#define XNTSTOP		0x00000800
+
 struct xnsched_rt {
 	xnsched_queue_t runnable;	/*!< Runnable thread queue. */
 };
kernel/cobalt/timer.c +88 -0

118 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#5 lore raw

PATCH 6/15 cobalt/intr: post proxy tick irq instead of host tick irq

In reply to hongzha1

make use of dovetail proxy tick infastructure in place of host tick

---
 kernel/cobalt/intr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/cobalt/intr.c +4 -4
index 8ffe7f2b6..36eb6c93c 100644
@@ -21,6 +21,7 @@
 #include <linux/mutex.h>
 /*#include <linux/ipipe.h>
 #include <linux/ipipe_tickdev.h>*/
+#include <linux/clockchips.h>
 #include <cobalt/kernel/sched.h>
 #include <cobalt/kernel/intr.h>
 #include <cobalt/kernel/stat.h>
@@ -188,8 +189,8 @@ void xnintr_host_tick(struct xnsched *sched) /* Interrupts off. */
 {
 	sched->lflags &= ~XNHTICK;
 #ifdef XNARCH_HOST_TICK_IRQ
-	//ipipe_post_irq_root(XNARCH_HOST_TICK_IRQ);
-#warning TODO
+	/* use proxy tick to replace host tick */
+	tick_notify_proxy();
 #endif
 }
 
@@ -205,8 +206,7 @@ void xnintr_core_clock_handler(void)
 
 	if (!xnsched_supported_cpu(cpu)) {
 #ifdef XNARCH_HOST_TICK_IRQ
-		//ipipe_post_irq_root(XNARCH_HOST_TICK_IRQ);
-#warning TODO
+		tick_notify_proxy();
 #endif
 		return;
 	}
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH 7/15 cobalt/timer: implement xnproxy_timer_set to substitute ipipe

In reply to hongzha1

implement xnproxy_timer_set to substitute ipipe_timer_set to set next timer event via real_dev

---
 include/cobalt/kernel/timer.h |  2 ++
 kernel/cobalt/clock.c         |  3 ++-
 kernel/cobalt/timer.c         | 28 ++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
include/cobalt/kernel/timer.h +2 -0
index 711388188..f00c490a9 100644
@@ -370,6 +370,8 @@ void __xntimer_init(struct xntimer *timer,
 		    struct xnsched *sched,
 		    int flags);
 
+void xnproxy_timer_set(unsigned long delta, ktime_t tdata);
+
 void xntimer_set_gravity(struct xntimer *timer,
 			 int gravity);
 
kernel/cobalt/clock.c +2 -1
index ab9fa394d..94db7a6fa 100644
@@ -18,6 +18,7 @@
  */
 #include <linux/percpu.h>
 #include <linux/errno.h>
+#include <linux/irq_pipeline.h>
 //#include <linux/ipipe_tickdev.h>
 #include <cobalt/kernel/sched.h>
 #include <cobalt/kernel/timer.h>
@@ -225,7 +226,7 @@ void xnclock_core_local_shot(struct xnsched *sched)
 #ifdef CONFIG_IPIPE
 	ipipe_timer_set(delay);
 #else
-#warning TODO
+	xnproxy_timer_set(delay, xntimerh_date(&timer->aplink));
 #endif
 }
 
kernel/cobalt/timer.c +28 -0
index 646166b87..03425e581 100644
@@ -373,6 +373,34 @@ void __xntimer_init(struct xntimer *timer,
 }
 EXPORT_SYMBOL_GPL(__xntimer_init);
 
+void xnproxy_timer_set(unsigned long delta, ktime_t tdata)
+{
+	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
+	struct clock_event_device *real_dev = dev->real_device;
+	int ret;
+	u64 cycles;
+	/* these code are ported from evl_program_proxy_tick */
+	if (real_dev->features & CLOCK_EVT_FEAT_KTIME) {
+		real_dev->set_next_ktime(tdata, real_dev);
+	} else {
+		if (delta <= 0)
+			delta = real_dev->min_delta_ns;
+		else {
+			delta = min_t(int64_t, delta,
+					(int64_t)real_dev->max_delta_ns);
+			delta = max_t(int64_t, delta,
+					(int64_t)real_dev->min_delta_ns);
+		}
+		cycles = ((u64)delta * real_dev->mult) >> real_dev->shift;
+		ret = real_dev->set_next_event(cycles, real_dev);
+		if (ret) {
+			real_dev->set_next_event(real_dev->min_delta_ticks,
+					real_dev);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(xnproxy_timer_set);
+
 void xntimer_set_gravity(struct xntimer *timer, int gravity)
 {
 	spl_t s;
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH 8/15 cobalt/thread: call dovetail_leave_inband to replace __ipipe_migrate_head

In reply to hongzha1

leave inband on dovetail

---
 kernel/cobalt/thread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/thread.c +2 -2
index 7a6139142..e2a215703 100644
@@ -1950,8 +1950,8 @@ int xnthread_harden(void)
 
 	xnthread_clear_sync_window(thread, XNRELAX);
 
-#warning TODO
-	ret = 0;//__ipipe_migrate_head();
+	/* Please refer to evl_switch_oob */
+	ret = dovetail_leave_inband();
 	if (ret) {
 		xnthread_test_cancel();
 		xnthread_set_sync_window(thread, XNRELAX);
Signature · 1 line
2.17.1
author
#8 lore raw

PATCH 9/15 cobalt/thread: call dovetail_resume_inband instead of __ipipe_reenter_root

In reply to hongzha1

resume inband on dovetail

---
 kernel/cobalt/thread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/thread.c +2 -2
index e2a215703..fc29cc521 100644
@@ -2140,8 +2140,8 @@ void xnthread_relax(int notify, int reason)
 		  "xnthread_relax() failed for thread %s[%d]",
 		  thread->name, xnthread_host_pid(thread));
 
-#warning TODO: nothing to be done?
-	//__ipipe_reenter_root();
+	/* Please refer to evl_switch_inband */
+	dovetail_resume_inband();
 
 	/* Account for secondary mode switch. */
 	xnstat_counter_inc(&thread->stat.ssw);
Signature · 1 line
2.17.1
author
#9 lore raw

PATCH 10/15 cobalt/thread: add new member done and irq_work to do wakeup parent

In reply to hongzha1

add new member done and irq_work in struct xnthread and make use of them to do wakeup and wait

---
 include/cobalt/kernel/thread.h |  8 ++++--
 kernel/cobalt/thread.c         | 52 ++++++++++++++--------------------
 2 files changed, 27 insertions(+), 33 deletions(-)
include/cobalt/kernel/thread.h +6 -2
index 2ab5ac28e..88fd6e3c7 100644
@@ -33,6 +33,7 @@
 #include <cobalt/uapi/signal.h>
 #include <asm/xenomai/machine.h>
 #include <asm/xenomai/thread.h>
+#include <linux/irq_work.h>
 
 /**
  * @addtogroup cobalt_core_thread
@@ -200,6 +201,10 @@ struct xnthread {
 #endif
 
 	struct dovetail_altsched_context altsched;
+
+	struct completion *done;
+
+	struct irq_work irq_work;
 };
 
 static inline int xnthread_get_state(const struct xnthread *thread)
@@ -502,8 +507,7 @@ void xnthread_signal(struct xnthread *thread,
 
 void xnthread_pin_initial(struct xnthread *thread);
 
-int xnthread_map(struct xnthread *thread,
-		 struct completion *done);
+int xnthread_map(struct xnthread *thread);
 
 void xnthread_call_mayday(struct xnthread *thread, int reason);
 
kernel/cobalt/thread.c +21 -31

111 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#10 lore raw

PATCH 11/15 cobalt/thread: dovetail_init_altsched and then dovetail_start_altsched

In reply to hongzha1

call dovetail_init_altsched and then dovetail_start_altsched to enable Dovetail notifier

---
 kernel/cobalt/thread.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/cobalt/thread.c +3 -2
index 944840d4d..6ac949e99 100644
@@ -2542,6 +2542,7 @@ int xnthread_map(struct xnthread *thread)
 
 	thread->u_window = NULL;
 	xnthread_pin_initial(thread);
+	dovetail_init_altsched(&thread->altsched);
 
 	xnthread_init_shadow_tcb(thread);
 	xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
@@ -2549,8 +2550,8 @@ int xnthread_map(struct xnthread *thread)
 	xnthread_set_state(thread, XNMAPPED);
 	xndebug_shadow_init(thread);
 	xnthread_run_handler(thread, map_thread);
-#warning TODO
-	//ipipe_enable_notifier(p);
+
+	dovetail_start_altsched();
 
 	/*
 	 * CAUTION: Soon after xnthread_init() has returned,
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH 12/15 cobalt/thread: call dovetail_leave_oob to allow to be waked up

In reply to hongzha1

call dovetail_leave_oob to allow current to be waked up and dovetail_leave_oob would clean TIF_MAYDAY

---
 kernel/cobalt/thread.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
kernel/cobalt/thread.c +9 -5
index 6ac949e99..5943d3b94 100644
@@ -2119,8 +2119,15 @@ void xnthread_relax(int notify, int reason)
 		suspension |= XNDBGSTOP;
 	}
 #endif
-#warning TODO
-	//set_current_state(p->state & ~TASK_NOWAKEUP);
+	/*
+	 * CAVEAT: dovetail_leave_oob() must run _before_ the in-band
+	 * kernel is allowed to take interrupts again, so that
+	 * try_to_wake_up() does not block the wake up request for the
+	 * switching thread as a result of testing
+	 * task_is_off_stage().
+	 */
+	dovetail_leave_oob();
+
 	xnthread_run_handler_stack(thread, relax_thread);
 	xnthread_suspend(thread, suspension, XN_INFINITE, XN_RELATIVE, NULL);
 	splnone();
@@ -2186,9 +2193,6 @@ void xnthread_relax(int notify, int reason)
 	 */
 	xnthread_clear_localinfo(thread, XNSYSRST);
 
-#warning TODO: nothing to do here?
-//	ipipe_clear_thread_flag(TIP_MAYDAY);
-
 	trace_cobalt_shadow_relaxed(thread);
 }
 EXPORT_SYMBOL_GPL(xnthread_relax);
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH 13/15 cobalt/thread: wake up current with raising irq_work

In reply to hongzha1

wake up current with raising irq_work instead of calling ipipe interface

---
 include/cobalt/kernel/thread.h |  2 ++
 kernel/cobalt/thread.c         | 30 +++++++++++++-----------------
 2 files changed, 15 insertions(+), 17 deletions(-)
include/cobalt/kernel/thread.h +2 -0
index 88fd6e3c7..3283400be 100644
@@ -205,6 +205,8 @@ struct xnthread {
 	struct completion *done;
 
 	struct irq_work irq_work;
+
+	struct irq_work inband_work;
 };
 
 static inline int xnthread_get_state(const struct xnthread *thread)
kernel/cobalt/thread.c +13 -17
index 5943d3b94..f3168d75f 100644
@@ -137,6 +137,16 @@ static inline int spawn_kthread(struct xnthread *thread)
 	return 0;
 }
 
+static void inband_task_wakeup(struct irq_work *work)
+{
+	struct xnthread *thread;
+	struct task_struct *p;
+
+	thread = container_of(work, struct xnthread, inband_work);
+	p = thread->altsched.task;
+	wake_up_process(p);
+}
+
 int __xnthread_init(struct xnthread *thread,
 		    const struct xnthread_init_attr *attr,
 		    struct xnsched *sched,
@@ -187,6 +197,7 @@ int __xnthread_init(struct xnthread *thread,
 	thread->selector = NULL;
 	INIT_LIST_HEAD(&thread->glink);
 	INIT_LIST_HEAD(&thread->boosters);
+	init_irq_work(&thread->inband_work, inband_task_wakeup);
 	/* These will be filled by xnthread_start() */
 	thread->entry = NULL;
 	thread->cookie = NULL;
@@ -1998,22 +2009,6 @@ static void lostage_task_wakeup(struct ipipe_work_header *work)
 }
 #endif
 
-static void post_wakeup(struct task_struct *p)
-{
-#warning TODO
-/*	struct lostage_wakeup wakework = {
-		.work = {
-			.size = sizeof(wakework),
-			.handler = lostage_task_wakeup,
-		},
-		.task = p,
-	};
-
-	trace_cobalt_lostage_request("wakeup", wakework.task);
-
-	ipipe_post_work_root(&wakework, work);*/
-}
-
 void __xnthread_propagate_schedparam(struct xnthread *curr)
 {
 	int kpolicy = SCHED_FIFO, kprio = curr->bprio, ret;
@@ -2099,7 +2094,8 @@ void xnthread_relax(int notify, int reason)
 	 * xnthread_suspend() has an interrupts-on section built in.
 	 */
 	splmax();
-	post_wakeup(p);
+	/*please refer to evl_switch_inband */
+	irq_work_queue(&thread->inband_work);
 	/*
 	 * Grab the nklock to synchronize the Linux task state
 	 * manipulation with handle_sigwake_event. This lock will be
Signature · 1 line
2.17.1
author
#13 lore raw

PATCH 14/15 cobalt/thread: re-implement xnthread_signal with making use of irq_work to replace ipipe related interface

In reply to hongzha1

re-implement xnthread_signal with making use of irq_work to replace ipipe related interface.

---
 kernel/cobalt/thread.c | 85 ++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 49 deletions(-)
kernel/cobalt/thread.c +36 -49
index f3168d75f..cb8c01f5d 100644
@@ -2193,53 +2193,36 @@ void xnthread_relax(int notify, int reason)
 }
 EXPORT_SYMBOL_GPL(xnthread_relax);
 
-#if 0
-struct lostage_signal {
-	struct ipipe_work_header work; /* Must be first. */
-	struct task_struct *task;
-	int signo, sigval;
-};
-
-static inline void do_kthread_signal(struct task_struct *p,
-				     struct xnthread *thread,
-				     struct lostage_signal *rq)
-{
-	printk(XENO_WARNING
-	       "kernel shadow %s received unhandled signal %d (action=0x%x)\n",
-	       thread->name, rq->signo, rq->sigval);
-}
-
-static void lostage_task_signal(struct ipipe_work_header *work)
+static void do_inband_signal(struct xnthread *thread, int signo, int sigval)
 {
-	struct lostage_signal *rq;
-	struct xnthread *thread;
-	struct task_struct *p;
-	kernel_siginfo_t si;
-	int signo;
-
-	rq = container_of(work, struct lostage_signal, work);
-	p = rq->task;
-
-	thread = xnthread_from_task(p);
-	if (thread && !xnthread_test_state(thread, XNUSER)) {
-		do_kthread_signal(p, thread, rq);
-		return;
-	}
-
-	signo = rq->signo;
-
-	trace_cobalt_lostage_signal(p, signo);
+	struct task_struct *p = thread->altsched.task;
+	struct kernel_siginfo si;
 
 	if (signo == SIGSHADOW || signo == SIGDEBUG) {
 		memset(&si, '\0', sizeof(si));
 		si.si_signo = signo;
 		si.si_code = SI_QUEUE;
-		si.si_int = rq->sigval;
+		si.si_int = sigval;
 		send_sig_info(signo, &si, p);
 	} else
 		send_sig(signo, p, 1);
 }
-#endif
+
+struct sig_irqwork_data {
+	struct xnthread *thread;
+	int signo, sigval;
+	struct irq_work work;
+};
+
+static void sig_irqwork(struct irq_work *work)
+{
+	struct sig_irqwork_data *sigd;
+
+	sigd = container_of(work, struct sig_irqwork_data, work);
+	do_inband_signal(sigd->thread, sigd->signo, sigd->sigval);
+	xnfree(sigd);
+
+}
 
 static int force_wakeup(struct xnthread *thread) /* nklock locked, irqs off */
 {
@@ -2402,20 +2385,24 @@ EXPORT_SYMBOL_GPL(xnthread_demote);
 
 void xnthread_signal(struct xnthread *thread, int sig, int arg)
 {
-#warning TODO
-/*	struct lostage_signal sigwork = {
-		.work = {
-			.size = sizeof(sigwork),
-			.handler = lostage_task_signal,
-		},
-		.task = xnthread_host_task(thread),
-		.signo = sig,
-		.sigval = sig == SIGDEBUG ? arg | sigdebug_marker : arg,
-	};
+	struct sig_irqwork_data *sigd;
+
+	if (thread && !xnthread_test_state(thread, XNUSER))
+		return;
+
+	if (running_inband()) {
+		do_inband_signal(thread, sig, arg);
+		return;
+	}
 
-	trace_cobalt_lostage_request("signal", sigwork.task);
+	sigd = xnmalloc(sizeof(*sigd));
+	init_irq_work(&sigd->work, sig_irqwork);
+	sigd->thread = thread;
+	sigd->signo = sig;
+	sigd->sigval = arg;
 
-	ipipe_post_work_root(&sigwork, work);*/
+	/* Cannot fail, irq_work is local to this call. */
+	irq_work_queue(&sigd->work);
 }
 EXPORT_SYMBOL_GPL(xnthread_signal);
 
Signature · 1 line
2.17.1
author
#14 lore raw

PATCH 15/15 cobalt/thread: drop xnthread_init_shadow_tcb and xnthread_init_root_tcb and xnthread_switch_fpu

In reply to hongzha1

drop xnthread_init_shadow_tcb and xnthread_init_root_tcb and xnthread_switch_fpu because dovetail alternate scheduling will handle related context switch including fpu switch.

---
 include/cobalt/kernel/thread.h |  8 -----
 kernel/cobalt/posix/process.c  |  1 -
 kernel/cobalt/sched.c          |  2 --
 kernel/cobalt/thread.c         | 55 ----------------------------------
 4 files changed, 66 deletions(-)
include/cobalt/kernel/thread.h +0 -8
index 3283400be..4e6d305ce 100644
@@ -429,16 +429,8 @@ int xnthread_wait_complete_p(struct xnthread_wait_context *wc)
 	return wc->posted;
 }
 
-#ifdef CONFIG_XENO_ARCH_FPU
-void xnthread_switch_fpu(struct xnsched *sched);
-#else
-static inline void xnthread_switch_fpu(struct xnsched *sched) { }
-#endif /* CONFIG_XENO_ARCH_FPU */
-
 void xnthread_init_shadow_tcb(struct xnthread *thread);
 
-void xnthread_init_root_tcb(struct xnthread *thread);
-
 void xnthread_deregister(struct xnthread *thread);
 
 char *xnthread_format_status(unsigned long status,
kernel/cobalt/posix/process.c +0 -1
index 366e5889e..97e3319d8 100644
@@ -694,7 +694,6 @@ int cobalt_map_user(struct xnthread *thread, __u32 __user *u_winoff)
 	 * positive in debug code from handle_schedule_event() and
 	 * friends.
 	 */
-	xnthread_init_shadow_tcb(thread);
 	xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
 	init_uthread_info(thread);
 	xnthread_set_state(thread, XNMAPPED);
kernel/cobalt/sched.c +0 -2
index f54c411a0..70679b035 100644
@@ -214,7 +214,6 @@ static void xnsched_init(struct xnsched *sched, int cpu)
 	sched->fpuholder = &sched->rootcb;
 #endif /* CONFIG_XENO_ARCH_FPU */
 
-	xnthread_init_root_tcb(&sched->rootcb);
 	list_add_tail(&sched->rootcb.glink, &nkthreadq);
 	cobalt_nrthreads++;
 
@@ -1075,7 +1074,6 @@ reschedule:
 	 * because of relaxed/hardened transitions.
 	 */
 	curr = sched->curr;
-	xnthread_switch_fpu(sched);
 	xntrace_pid(task_pid_nr(current), xnthread_current_priority(curr));
 out:
 	if (switched &&
kernel/cobalt/thread.c +0 -55

79 lines not on this page · raw message

Signature · 1 line
2.17.1