Module: xenomai-3
Branch: stable-3.0.x
Commit: 595606457ff7e77133946cea165288f3e449be56
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=595606457ff7e77133946cea165288f3e449be56

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Mar 20 12:01:34 2018 +0100

cobalt/sched, clock: provide ipipe_enter_idle_hook()

Since kernel 4.9, the pipeline code may ask us whether it would be
fine to enter the idle state on the current CPU, by mean of a probing
hook called ipipe_enter_idle_hook().

Provide this hook, considering that absence of outstanding timers
means idleness to us.

---

 include/cobalt/kernel/sched.h |    1 +
 kernel/cobalt/clock.c         |    6 ++++--
 kernel/cobalt/posix/process.c |    6 ++++++
 kernel/cobalt/sched.c         |    2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index fe1df7d..d525fb2 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -42,6 +42,7 @@
 #define XNINTCK                0x40000000      /* In master tick handler 
context */
 
 /* Sched local flags */
+#define XNIDLE         0x00010000      /* Idle (no outstanding timer) */
 #define XNHTICK                0x00008000      /* Host tick pending  */
 #define XNINIRQ                0x00004000      /* In IRQ handling context */
 #define XNHDEFER       0x00002000      /* Host tick deferred */
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 5bc46b3..1c8ef27 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -143,8 +143,10 @@ void xnclock_core_local_shot(struct xnsched *sched)
         */
        tmd = xnclock_this_timerdata(&nkclock);
        h = xntimerq_head(&tmd->q);
-       if (h == NULL)
+       if (h == NULL) {
+               sched->lflags |= XNIDLE;
                return;
+       }
 
        /*
         * Here we try to defer the host tick heading the timer queue,
@@ -166,7 +168,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;
+       sched->lflags &= ~(XNHDEFER|XNIDLE);
        timer = container_of(h, struct xntimer, aplink);
        if (unlikely(timer == &sched->htimer)) {
                if (xnsched_resched_p(sched) ||
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 387690f..684e7e3 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -822,6 +822,12 @@ int ipipe_trap_hook(struct ipipe_trap_data *data)
        return KEVENT_PROPAGATE;
 }
 
+bool ipipe_enter_idle_hook(void) /* hw IRQs off */
+{
+       struct xnsched *sched = xnsched_current();
+       return !!(sched->lflags & XNIDLE);
+}
+
 #ifdef CONFIG_SMP
 
 static int handle_setaffinity_event(struct ipipe_cpu_migration_data *d)
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index a2dae20..db7bb11 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -175,7 +175,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
        }
 
        sched->status = 0;
-       sched->lflags = 0;
+       sched->lflags = XNIDLE;
        sched->inesting = 0;
        sched->curr = &sched->rootcb;
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to