cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot
PATCH v2 1/5 cobalt/tick: dovetail: implement pipeline_set_timer_shot to trigger tick shot
include/cobalt/kernel/dovetail/pipeline/clock.h +1 -11
@@ -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 ) {
kernel/cobalt/dovetail/tick.c +30 -0
@@ -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) {
Signature · 1 line
2.17.1
PATCH v2 2/5 cobalt/tick: dovetail: implement pipeline_timer_name
Get the name of real device controlled by the proxy tick device.
include/cobalt/kernel/dovetail/pipeline/clock.h +1 -10
@@ -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 ) {
kernel/cobalt/dovetail/tick.c +12 -0
@@ -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);
Signature · 1 line
2.17.1
Philippe Gerum
AppliedRe: [PATCH V2 2/5] cobalt/tick: dovetail: implement pipeline_timer_name
Quoted 39 lines · hongzha1 via Xenomai <[email protected]> writes:
Get the name of real device controlled by the proxy tick device.
Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/dovetail/pipeline/clock.h +1
-10@@ -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 ) {kernel/cobalt/dovetail/tick.c +5
-0@@ -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; +
kernel/cobalt/dovetail/tick.c extern struct xnintr nktimer; · line 33
Quoted 10 lines
kernel/cobalt/dovetail/tick.c +7
-0+/* +* 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.
Signature · 1 line
Philippe.
PATCH v2 3/5 dovetail/kevents: dovetail: implement handle_ptrace_cont
In reply to hongzha1kernel/cobalt/dovetail/kevents.c +69 -1
@@ -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)
Signature · 1 line
2.17.1
Re: [PATCH V2 3/5] dovetail/kevents: dovetail: implement handle_ptrace_cont
Quoted 47 lines · hongzha1 via Xenomai <[email protected]> writes:
Signed-off-by hongzha1 <[email protected]>kernel/cobalt/dovetail/kevents.c +36
-1@@ -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; + } + +/*
kernel/cobalt/dovetail/kevents.c static void handle_ptrace_cont(void) · line 528
Quoted 10 lines
kernel/cobalt/dovetail/kevents.c +10
-0+* 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).
Quoted 16 lines
kernel/cobalt/dovetail/kevents.c +16
-0+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) &&
kernel/cobalt/dovetail/kevents.c static void handle_ptrace_cont(void) · line 554
Quoted 10 lines
kernel/cobalt/dovetail/kevents.c +7
-0+ !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.
Signature · 1 line
Philippe.
PATCH v2 4/5 cobalt/timer: pipeline: abstract signal test of XNTSTOP
In reply to hongzha1It 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.
include/cobalt/kernel/ipipe/pipeline/tick.h +6 -0
@@ -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 */
include/cobalt/kernel/sched.h +5 -0
@@ -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. */ };
kernel/cobalt/clock.c +1 -1
@@ -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) ||
kernel/cobalt/timer.c +4 -1
@@ -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 ())
Signature · 1 line
2.17.1
Re: [PATCH V2 4/5] cobalt/timer: pipeline: abstract signal test of XNTSTOP
Quoted 65 lines · hongzha1 via Xenomai <[email protected]> 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_STOPPEDmode. The I-pipe does not require any further action in this case, leading to a nop.Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/ipipe/pipeline/tick.h +6
-0@@ -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 */ include/cobalt/kernel/sched.h +5
-0@@ -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. */ };kernel/cobalt/clock.c +1
-1@@ -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) ||kernel/cobalt/timer.c +1
-0@@ -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)
kernel/cobalt/timer.c int xntimer_heading_p(struct xntimer *timer) · line 73
Quoted 10 lines
kernel/cobalt/timer.c +3
-1void 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.
Signature · 1 line
Philippe.
PATCH v2 5/5 dovetail/tick: pipeline: implement pipeline_must_force_program_tick
In reply to hongzha1Force the next tick to be programmed in the hardware as a result of leaving the ONESHOT_STOPPED
include/cobalt/kernel/dovetail/pipeline/tick.h +4 -0
@@ -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 */
kernel/cobalt/dovetail/tick.c +6 -1
@@ -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;
Signature · 1 line
2.17.1
Re: [PATCH V2 5/5] dovetail/tick: pipeline: implement pipeline_must_force_program_tick
Quoted 35 lines · hongzha1 via Xenomai <[email protected]> writes:
Force the next tick to be programmed in the hardware as a result of leaving the
ONESHOT_STOPPEDSigned-off-by hongzha1 <[email protected]>include/cobalt/kernel/dovetail/pipeline/tick.h +4
-0@@ -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 */ kernel/cobalt/dovetail/tick.c +5
-0@@ -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;
kernel/cobalt/dovetail/tick.c static int proxy_set_oneshot_stopped(struct clock_event_device *proxy_dev) · line 121
Quoted 8 lines
kernel/cobalt/dovetail/tick.c +1
-1@@ -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.
Signature · 1 line
Philippe.
Philippe Gerum
AppliedQuoted 56 lines · hongzha1 via Xenomai <[email protected]> writes:
Signed-off-by hongzha1 <[email protected]>include/cobalt/kernel/dovetail/pipeline/clock.h +1
-11@@ -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 ) {kernel/cobalt/dovetail/tick.c +23
-0@@ -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);
kernel/cobalt/dovetail/tick.c extern struct xnintr nktimer; · line 51
Quoted 10 lines
kernel/cobalt/dovetail/tick.c +7
-0+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.
Signature · 1 line
Philippe.