All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot
@ 2021-01-22  2:12 hongzha1
  2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: hongzha1 @ 2021-01-22  2:12 UTC (permalink / raw)
  To: xenomai

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/dovetail/pipeline/clock.h b/include/cobalt/kernel/dovetail/pipeline/clock.h
index 28d89b44b..7b6ce161c 100644
--- a/include/cobalt/kernel/dovetail/pipeline/clock.h
+++ b/include/cobalt/kernel/dovetail/pipeline/clock.h
@@ -17,17 +17,7 @@ static inline u64 pipeline_read_cycle_counter(void)
 	return  ktime_get_raw_fast_ns();
 }
 
-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();
-}
+void pipeline_set_timer_shot(unsigned long cycles);
 
 static inline const char *pipeline_timer_name(void)
 {
diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
index 6a196496c..75d908bd4 100644
--- a/kernel/cobalt/dovetail/tick.c
+++ b/kernel/cobalt/dovetail/tick.c
@@ -16,6 +16,36 @@ extern struct xnintr nktimer;
 
 static DEFINE_PER_CPU(struct clock_proxy_device *, proxy_device);
 
+void pipeline_set_timer_shot(unsigned long cycles)
+{
+	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
+	struct clock_event_device *real_dev = dev->real_device;
+	int ret;
+	u64 sumcyc;
+	ktime_t t;
+
+	if (real_dev->features & CLOCK_EVT_FEAT_KTIME) {
+		t = ktime_add(cycles, xnclock_core_read_raw());
+		real_dev->set_next_ktime(t, real_dev);
+	} else {
+		if (cycles <= 0)
+			cycles = real_dev->min_delta_ns;
+		else {
+			cycles = min_t(int64_t, cycles,
+					real_dev->max_delta_ns);
+			cycles = max_t(int64_t, cycles,
+					real_dev->min_delta_ns);
+		}
+		sumcyc = ((u64)cycles * real_dev->mult) >> real_dev->shift;
+
+		ret = real_dev->set_next_event(sumcyc, real_dev);
+		if (ret) {
+			ret = real_dev->set_next_event(real_dev->min_delta_ticks,
+							real_dev);
+		}
+	}
+}
+
 static int proxy_set_next_ktime(ktime_t expires,
 				struct clock_event_device *proxy_dev)
 {
-- 
2.17.1



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

* [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name
  2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
@ 2021-01-22  2:12 ` hongzha1
  2021-01-24 17:05   ` Philippe Gerum
  2021-01-22  2:12 ` [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont hongzha1
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: hongzha1 @ 2021-01-22  2:12 UTC (permalink / raw)
  To: xenomai

Get the name of real device controlled by the proxy tick device.

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/dovetail/pipeline/clock.h b/include/cobalt/kernel/dovetail/pipeline/clock.h
index 7b6ce161c..6761ed70d 100644
--- a/include/cobalt/kernel/dovetail/pipeline/clock.h
+++ b/include/cobalt/kernel/dovetail/pipeline/clock.h
@@ -19,16 +19,7 @@ static inline u64 pipeline_read_cycle_counter(void)
 
 void pipeline_set_timer_shot(unsigned long cycles);
 
-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 "?";
-}
+const char *pipeline_timer_name(void);
 
 static inline const char *pipeline_clock_name(void)
 {
diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
index 75d908bd4..1b622defb 100644
--- a/kernel/cobalt/dovetail/tick.c
+++ b/kernel/cobalt/dovetail/tick.c
@@ -16,6 +16,18 @@ extern struct xnintr nktimer;
 
 static DEFINE_PER_CPU(struct clock_proxy_device *, proxy_device);
 
+const char *pipeline_timer_name(void)
+{
+	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
+	struct clock_event_device *real_dev = dev->real_device;
+
+	/*
+	 * Return the name of the current clock event chip, which is
+	 * the real device controlled by the proxy tick device.
+	 */
+	return real_dev->name;
+}
+
 void pipeline_set_timer_shot(unsigned long cycles)
 {
 	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
-- 
2.17.1



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

* [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont
  2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
  2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
@ 2021-01-22  2:12 ` hongzha1
  2021-01-24 17:21   ` Philippe Gerum
  2021-01-22  2:12 ` [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP hongzha1
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: hongzha1 @ 2021-01-22  2:12 UTC (permalink / raw)
  To: xenomai

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/kernel/cobalt/dovetail/kevents.c b/kernel/cobalt/dovetail/kevents.c
index 6aec170d1..0528e2938 100644
--- a/kernel/cobalt/dovetail/kevents.c
+++ b/kernel/cobalt/dovetail/kevents.c
@@ -480,7 +480,75 @@ static void handle_ptrace_cont(void)
 	 * stopped state, which is what look for in
 	 * handle_schedule_event().
 	 */
-	TODO();
+	struct task_struct *next_task;
+	struct xnthread *next;
+	sigset_t pending;
+	spl_t s;
+
+	cobalt_signal_yield();
+
+	next_task = current;
+	next = xnthread_from_task(next_task);
+	if (next == NULL)
+		return;
+
+	xnlock_get_irqsave(&nklock, s);
+
+	/*
+	 * Track tasks leaving the ptraced state.  Check both SIGSTOP
+	 * (NPTL) and SIGINT (LinuxThreads) to detect ptrace
+	 * continuation.
+	 */
+	if (xnthread_test_state(next, XNSSTEP)) {
+		if (signal_pending(next_task)) {
+			/*
+			 * Do not grab the sighand lock here: it's
+			 * useless, and we already own the runqueue
+			 * lock, so this would expose us to deadlock
+			 * situations on SMP.
+			 */
+			sigorsets(&pending,
+				  &next_task->pending.signal,
+				  &next_task->signal->shared_pending.signal);
+			if (sigismember(&pending, SIGSTOP) ||
+			    sigismember(&pending, SIGINT))
+				goto no_ptrace;
+		}
+
+		/*
+		 * Do not unregister before the thread migrated.
+		 * unregister_debugged_thread will then be called by our
+		 * resume_oob_task.
+		 */
+		if (!xnthread_test_info(next, XNCONTHI))
+			unregister_debugged_thread(next);
+
+		xnthread_set_localinfo(next, XNHICCUP);
+	}
+
+no_ptrace:
+	xnlock_put_irqrestore(&nklock, s);
+
+	/*
+	 * Do basic sanity checks on the incoming thread state.
+	 * NOTE: we allow ptraced threads to run shortly in order to
+	 * properly recover from a stopped state.
+	 */
+	if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
+		       "hardened thread %s[%d] running in Linux domain?! "
+		       "(status=0x%x, sig=%d)",
+		       next->name, task_pid_nr(next_task),
+		       xnthread_get_state(next),
+		       signal_pending(next_task)))
+		XENO_WARN(COBALT,
+			  !(next_task->ptrace & PT_PTRACED) &&
+			   !xnthread_test_state(next, XNDORMANT)
+			  && xnthread_test_state(next, XNPEND),
+			  "blocked thread %s[%d] rescheduled?! "
+			  "(status=0x%x, sig=%d)",
+			  next->name, task_pid_nr(next_task),
+			  xnthread_get_state(next),
+			  signal_pending(next_task));
 }
 
 void handle_inband_event(enum inband_event_type event, void *data)
-- 
2.17.1



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

* [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP
  2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
  2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
  2021-01-22  2:12 ` [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont hongzha1
@ 2021-01-22  2:12 ` hongzha1
  2021-01-24 17:06   ` Philippe Gerum
  2021-01-22  2:12 ` [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick hongzha1
  2021-01-24 17:05 ` [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot Philippe Gerum
  4 siblings, 1 reply; 10+ messages in thread
From: hongzha1 @ 2021-01-22  2:12 UTC (permalink / raw)
  To: xenomai

It adds a way to force the timer management code to reprogram the
hardware on option, to make the real device controlled by the proxy
tick again as it leaves the ONESHOT_STOPPED mode. The I-pipe does not
require any further action in this case, leading to a nop.

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/ipipe/pipeline/tick.h b/include/cobalt/kernel/ipipe/pipeline/tick.h
index 409581a3c..41347f7b1 100644
--- a/include/cobalt/kernel/ipipe/pipeline/tick.h
+++ b/include/cobalt/kernel/ipipe/pipeline/tick.h
@@ -9,4 +9,10 @@ int pipeline_install_tick_proxy(void);
 
 void pipeline_uninstall_tick_proxy(void);
 
+struct xnsched;
+static inline bool pipeline_must_force_program_tick(struct xnsched *sched)
+{
+	return false;
+}
+
 #endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index c13f46ff7..aa24d5442 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -48,6 +48,11 @@
 #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. */
 };
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index bf24e1693..2115b15ef 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -147,7 +147,7 @@ void xnclock_core_local_shot(struct xnsched *sched)
 	 * or a timer with an earlier timeout date is scheduled,
 	 * whichever comes first.
 	 */
-	sched->lflags &= ~(XNHDEFER|XNIDLE);
+	sched->lflags &= ~(XNHDEFER|XNIDLE|XNTSTOP);
 	timer = container_of(h, struct xntimer, aplink);
 	if (unlikely(timer == &sched->htimer)) {
 		if (xnsched_resched_p(sched) ||
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index f9aa457ce..f667a3878 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -18,6 +18,7 @@
  * 02111-1307, USA.
  */
 #include <linux/sched.h>
+#include <pipeline/tick.h>
 #include <cobalt/kernel/sched.h>
 #include <cobalt/kernel/thread.h>
 #include <cobalt/kernel/timer.h>
@@ -63,8 +64,10 @@ int xntimer_heading_p(struct xntimer *timer)
 
 void xntimer_enqueue_and_program(struct xntimer *timer, xntimerq_t *q)
 {
+	struct xnsched *sched = xntimer_sched(timer);
+
 	xntimer_enqueue(timer, q);
-	if (xntimer_heading_p(timer)) {
+	if (pipeline_must_force_program_tick(sched) || xntimer_heading_p(timer)) {
 		struct xnsched *sched = xntimer_sched(timer);
 		struct xnclock *clock = xntimer_clock(timer);
 		if (sched != xnsched_current())
-- 
2.17.1



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

* [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick
  2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
                   ` (2 preceding siblings ...)
  2021-01-22  2:12 ` [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP hongzha1
@ 2021-01-22  2:12 ` hongzha1
  2021-01-24 17:06   ` Philippe Gerum
  2021-01-24 17:05 ` [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot Philippe Gerum
  4 siblings, 1 reply; 10+ messages in thread
From: hongzha1 @ 2021-01-22  2:12 UTC (permalink / raw)
  To: xenomai

Force the next tick to be programmed in the hardware as a result of
leaving the ONESHOT_STOPPED

Signed-off-by: hongzha1 <hongzhan.chen@intel.com>

diff --git a/include/cobalt/kernel/dovetail/pipeline/tick.h b/include/cobalt/kernel/dovetail/pipeline/tick.h
index 409581a3c..8ac4760ec 100644
--- a/include/cobalt/kernel/dovetail/pipeline/tick.h
+++ b/include/cobalt/kernel/dovetail/pipeline/tick.h
@@ -9,4 +9,8 @@ int pipeline_install_tick_proxy(void);
 
 void pipeline_uninstall_tick_proxy(void);
 
+struct xnsched;
+
+inline bool pipeline_must_force_program_tick(struct xnsched *sched);
+
 #endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
index 1b622defb..fc6203667 100644
--- a/kernel/cobalt/dovetail/tick.c
+++ b/kernel/cobalt/dovetail/tick.c
@@ -89,6 +89,11 @@ void xn_core_tick(struct clock_event_device *dummy) /* hard irqs off */
 	xnintr_core_clock_handler();
 }
 
+inline bool pipeline_must_force_program_tick(struct xnsched *sched)
+{
+	return sched->lflags & XNTSTOP;
+}
+
 static int proxy_set_oneshot_stopped(struct clock_event_device *proxy_dev)
 {
 	struct clock_event_device *real_dev;
@@ -110,7 +115,7 @@ static int proxy_set_oneshot_stopped(struct clock_event_device *proxy_dev)
 	xnlock_get_irqsave(&nklock, s);
 	sched = xnsched_current();
 	xntimer_stop(&sched->htimer);
-	//sched->lflags |= XNTSTOP;
+	sched->lflags |= XNTSTOP;
 
 	if (sched->lflags & XNIDLE) {
 		real_dev = dev->real_device;
-- 
2.17.1



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

* Re: [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot
  2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
                   ` (3 preceding siblings ...)
  2021-01-22  2:12 ` [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick hongzha1
@ 2021-01-24 17:05 ` Philippe Gerum
  4 siblings, 0 replies; 10+ messages in thread
From: Philippe Gerum @ 2021-01-24 17:05 UTC (permalink / raw)
  To: hongzha1; +Cc: xenomai


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/include/cobalt/kernel/dovetail/pipeline/clock.h b/include/cobalt/kernel/dovetail/pipeline/clock.h
> index 28d89b44b..7b6ce161c 100644
> --- a/include/cobalt/kernel/dovetail/pipeline/clock.h
> +++ b/include/cobalt/kernel/dovetail/pipeline/clock.h
> @@ -17,17 +17,7 @@ static inline u64 pipeline_read_cycle_counter(void)
>  	return  ktime_get_raw_fast_ns();
>  }
>  
> -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();
> -}
> +void pipeline_set_timer_shot(unsigned long cycles);
>  
>  static inline const char *pipeline_timer_name(void)
>  {
> diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
> index 6a196496c..75d908bd4 100644
> --- a/kernel/cobalt/dovetail/tick.c
> +++ b/kernel/cobalt/dovetail/tick.c
> @@ -16,6 +16,36 @@ extern struct xnintr nktimer;
>  
>  static DEFINE_PER_CPU(struct clock_proxy_device *, proxy_device);
>  
> +void pipeline_set_timer_shot(unsigned long cycles)
> +{
> +	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
> +	struct clock_event_device *real_dev = dev->real_device;
> +	int ret;
> +	u64 sumcyc;
> +	ktime_t t;
> +
> +	if (real_dev->features & CLOCK_EVT_FEAT_KTIME) {
> +		t = ktime_add(cycles, xnclock_core_read_raw());
> +		real_dev->set_next_ktime(t, real_dev);
> +	} else {
> +		if (cycles <= 0)
> +			cycles = real_dev->min_delta_ns;
> +		else {
> +			cycles = min_t(int64_t, cycles,
> +					real_dev->max_delta_ns);
> +			cycles = max_t(int64_t, cycles,
> +					real_dev->min_delta_ns);
> +		}
> +		sumcyc = ((u64)cycles * real_dev->mult) >> real_dev->shift;
> +
> +		ret = real_dev->set_next_event(sumcyc, real_dev);
> +		if (ret) {
> +			ret = real_dev->set_next_event(real_dev->min_delta_ticks,
> +							real_dev);
> +		}
> +	}
> +}
> +
>  static int proxy_set_next_ktime(ktime_t expires,
>  				struct clock_event_device *proxy_dev)
>  {

Merged, thanks.

-- 
Philippe.


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

* Re: [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name
  2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
@ 2021-01-24 17:05   ` Philippe Gerum
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Gerum @ 2021-01-24 17:05 UTC (permalink / raw)
  To: hongzha1; +Cc: xenomai


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> Get the name of real device controlled by the proxy tick device.
>
> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/include/cobalt/kernel/dovetail/pipeline/clock.h b/include/cobalt/kernel/dovetail/pipeline/clock.h
> index 7b6ce161c..6761ed70d 100644
> --- a/include/cobalt/kernel/dovetail/pipeline/clock.h
> +++ b/include/cobalt/kernel/dovetail/pipeline/clock.h
> @@ -19,16 +19,7 @@ static inline u64 pipeline_read_cycle_counter(void)
>  
>  void pipeline_set_timer_shot(unsigned long cycles);
>  
> -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 "?";
> -}
> +const char *pipeline_timer_name(void);
>  
>  static inline const char *pipeline_clock_name(void)
>  {
> diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
> index 75d908bd4..1b622defb 100644
> --- a/kernel/cobalt/dovetail/tick.c
> +++ b/kernel/cobalt/dovetail/tick.c
> @@ -16,6 +16,18 @@ extern struct xnintr nktimer;
>  
>  static DEFINE_PER_CPU(struct clock_proxy_device *, proxy_device);
>  
> +const char *pipeline_timer_name(void)
> +{
> +	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);
> +	struct clock_event_device *real_dev = dev->real_device;
> +
> +	/*
> +	 * Return the name of the current clock event chip, which is
> +	 * the real device controlled by the proxy tick device.
> +	 */
> +	return real_dev->name;
> +}
> +
>  void pipeline_set_timer_shot(unsigned long cycles)
>  {
>  	struct clock_proxy_device *dev = __this_cpu_read(proxy_device);

Merged, thanks.

-- 
Philippe.


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

* Re: [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP
  2021-01-22  2:12 ` [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP hongzha1
@ 2021-01-24 17:06   ` Philippe Gerum
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Gerum @ 2021-01-24 17:06 UTC (permalink / raw)
  To: hongzha1; +Cc: xenomai


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> It adds a way to force the timer management code to reprogram the
> hardware on option, to make the real device controlled by the proxy
> tick again as it leaves the ONESHOT_STOPPED mode. The I-pipe does not
> require any further action in this case, leading to a nop.
>
> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/include/cobalt/kernel/ipipe/pipeline/tick.h b/include/cobalt/kernel/ipipe/pipeline/tick.h
> index 409581a3c..41347f7b1 100644
> --- a/include/cobalt/kernel/ipipe/pipeline/tick.h
> +++ b/include/cobalt/kernel/ipipe/pipeline/tick.h
> @@ -9,4 +9,10 @@ int pipeline_install_tick_proxy(void);
>  
>  void pipeline_uninstall_tick_proxy(void);
>  
> +struct xnsched;
> +static inline bool pipeline_must_force_program_tick(struct xnsched *sched)
> +{
> +	return false;
> +}
> +
>  #endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
> diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
> index c13f46ff7..aa24d5442 100644
> --- a/include/cobalt/kernel/sched.h
> +++ b/include/cobalt/kernel/sched.h
> @@ -48,6 +48,11 @@
>  #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. */
>  };
> diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
> index bf24e1693..2115b15ef 100644
> --- a/kernel/cobalt/clock.c
> +++ b/kernel/cobalt/clock.c
> @@ -147,7 +147,7 @@ void xnclock_core_local_shot(struct xnsched *sched)
>  	 * or a timer with an earlier timeout date is scheduled,
>  	 * whichever comes first.
>  	 */
> -	sched->lflags &= ~(XNHDEFER|XNIDLE);
> +	sched->lflags &= ~(XNHDEFER|XNIDLE|XNTSTOP);
>  	timer = container_of(h, struct xntimer, aplink);
>  	if (unlikely(timer == &sched->htimer)) {
>  		if (xnsched_resched_p(sched) ||
> diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
> index f9aa457ce..f667a3878 100644
> --- a/kernel/cobalt/timer.c
> +++ b/kernel/cobalt/timer.c
> @@ -18,6 +18,7 @@
>   * 02111-1307, USA.
>   */
>  #include <linux/sched.h>
> +#include <pipeline/tick.h>
>  #include <cobalt/kernel/sched.h>
>  #include <cobalt/kernel/thread.h>
>  #include <cobalt/kernel/timer.h>
> @@ -63,8 +64,10 @@ int xntimer_heading_p(struct xntimer *timer)
>  
>  void xntimer_enqueue_and_program(struct xntimer *timer, xntimerq_t *q)
>  {
> +	struct xnsched *sched = xntimer_sched(timer);
> +
>  	xntimer_enqueue(timer, q);
> -	if (xntimer_heading_p(timer)) {
> +	if (pipeline_must_force_program_tick(sched) || xntimer_heading_p(timer)) {
>  		struct xnsched *sched = xntimer_sched(timer);
>  		struct xnclock *clock = xntimer_clock(timer);
>  		if (sched != xnsched_current())

Merged, fixing up the short log. Thanks.

-- 
Philippe.


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

* Re: [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick
  2021-01-22  2:12 ` [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick hongzha1
@ 2021-01-24 17:06   ` Philippe Gerum
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Gerum @ 2021-01-24 17:06 UTC (permalink / raw)
  To: hongzha1; +Cc: xenomai


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> Force the next tick to be programmed in the hardware as a result of
> leaving the ONESHOT_STOPPED
>
> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/include/cobalt/kernel/dovetail/pipeline/tick.h b/include/cobalt/kernel/dovetail/pipeline/tick.h
> index 409581a3c..8ac4760ec 100644
> --- a/include/cobalt/kernel/dovetail/pipeline/tick.h
> +++ b/include/cobalt/kernel/dovetail/pipeline/tick.h
> @@ -9,4 +9,8 @@ int pipeline_install_tick_proxy(void);
>  
>  void pipeline_uninstall_tick_proxy(void);
>  
> +struct xnsched;
> +
> +inline bool pipeline_must_force_program_tick(struct xnsched *sched);
> +
>  #endif /* !_COBALT_KERNEL_IPIPE_TICK_H */
> diff --git a/kernel/cobalt/dovetail/tick.c b/kernel/cobalt/dovetail/tick.c
> index 1b622defb..fc6203667 100644
> --- a/kernel/cobalt/dovetail/tick.c
> +++ b/kernel/cobalt/dovetail/tick.c
> @@ -89,6 +89,11 @@ void xn_core_tick(struct clock_event_device *dummy) /* hard irqs off */
>  	xnintr_core_clock_handler();
>  }
>  
> +inline bool pipeline_must_force_program_tick(struct xnsched *sched)
> +{
> +	return sched->lflags & XNTSTOP;
> +}
> +
>  static int proxy_set_oneshot_stopped(struct clock_event_device *proxy_dev)
>  {
>  	struct clock_event_device *real_dev;
> @@ -110,7 +115,7 @@ static int proxy_set_oneshot_stopped(struct clock_event_device *proxy_dev)
>  	xnlock_get_irqsave(&nklock, s);
>  	sched = xnsched_current();
>  	xntimer_stop(&sched->htimer);
> -	//sched->lflags |= XNTSTOP;
> +	sched->lflags |= XNTSTOP;
>  
>  	if (sched->lflags & XNIDLE) {
>  		real_dev = dev->real_device;

Merged, fixing the short log. Thanks.

-- 
Philippe.


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

* Re: [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont
  2021-01-22  2:12 ` [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont hongzha1
@ 2021-01-24 17:21   ` Philippe Gerum
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Gerum @ 2021-01-24 17:21 UTC (permalink / raw)
  To: hongzha1; +Cc: xenomai


hongzha1 via Xenomai <xenomai@xenomai.org> writes:

> Signed-off-by: hongzha1 <hongzhan.chen@intel.com>
>
> diff --git a/kernel/cobalt/dovetail/kevents.c b/kernel/cobalt/dovetail/kevents.c
> index 6aec170d1..0528e2938 100644
> --- a/kernel/cobalt/dovetail/kevents.c
> +++ b/kernel/cobalt/dovetail/kevents.c
> @@ -480,7 +480,75 @@ static void handle_ptrace_cont(void)
>  	 * stopped state, which is what look for in
>  	 * handle_schedule_event().
>  	 */
> -	TODO();
> +	struct task_struct *next_task;
> +	struct xnthread *next;
> +	sigset_t pending;
> +	spl_t s;
> +
> +	cobalt_signal_yield();
> +
> +	next_task = current;
> +	next = xnthread_from_task(next_task);
> +	if (next == NULL)
> +		return;
> +
> +	xnlock_get_irqsave(&nklock, s);
> +
> +	/*
> +	 * Track tasks leaving the ptraced state.  Check both SIGSTOP
> +	 * (NPTL) and SIGINT (LinuxThreads) to detect ptrace
> +	 * continuation.
> +	 */
> +	if (xnthread_test_state(next, XNSSTEP)) {
> +		if (signal_pending(next_task)) {
> +			/*
> +			 * Do not grab the sighand lock here: it's
> +			 * useless, and we already own the runqueue
> +			 * lock, so this would expose us to deadlock
> +			 * situations on SMP.
> +			 */
> +			sigorsets(&pending,
> +				  &next_task->pending.signal,
> +				  &next_task->signal->shared_pending.signal);
> +			if (sigismember(&pending, SIGSTOP) ||
> +			    sigismember(&pending, SIGINT))
> +				goto no_ptrace;
> +		}
> +
> +		/*
> +		 * Do not unregister before the thread migrated.
> +		 * unregister_debugged_thread will then be called by our
> +		 * resume_oob_task.
> +		 */
> +		if (!xnthread_test_info(next, XNCONTHI))
> +			unregister_debugged_thread(next);
> +
> +		xnthread_set_localinfo(next, XNHICCUP);
> +	}
> +

Since we know Dovetail just called us because 'current' is about to
resume from a stopped state, we don't need the hackish code above which
was aimed at determining whether next_task was about to do so
(i.e. resuming from ptrace stop).

> +no_ptrace:
> +	xnlock_put_irqrestore(&nklock, s);
> +
> +	/*
> +	 * Do basic sanity checks on the incoming thread state.
> +	 * NOTE: we allow ptraced threads to run shortly in order to
> +	 * properly recover from a stopped state.
> +	 */
> +	if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
> +		       "hardened thread %s[%d] running in Linux domain?! "
> +		       "(status=0x%x, sig=%d)",
> +		       next->name, task_pid_nr(next_task),
> +		       xnthread_get_state(next),
> +		       signal_pending(next_task)))
> +		XENO_WARN(COBALT,
> +			  !(next_task->ptrace & PT_PTRACED) &&
> +			   !xnthread_test_state(next, XNDORMANT)
> +			  && xnthread_test_state(next, XNPEND),
> +			  "blocked thread %s[%d] rescheduled?! "
> +			  "(status=0x%x, sig=%d)",
> +			  next->name, task_pid_nr(next_task),
> +			  xnthread_get_state(next),
> +			  signal_pending(next_task));
>  }
>  
>  void handle_inband_event(enum inband_event_type event, void *data)

On second thought, we could also drop the remaining check above, since
what is being tested is a very basic Dovetail guarantee, i.e. that
'current' must be running in-band. IOW, receiving ptrace_cont should
lead to a nop when running on top of Dovetail.

-- 
Philippe.


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

end of thread, other threads:[~2021-01-24 17:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22  2:12 [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot hongzha1
2021-01-22  2:12 ` [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name hongzha1
2021-01-24 17:05   ` Philippe Gerum
2021-01-22  2:12 ` [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont hongzha1
2021-01-24 17:21   ` Philippe Gerum
2021-01-22  2:12 ` [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP hongzha1
2021-01-24 17:06   ` Philippe Gerum
2021-01-22  2:12 ` [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick hongzha1
2021-01-24 17:06   ` Philippe Gerum
2021-01-24 17:05 ` [PATCH V2 1/5] cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot 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.