Re: [PATCH RFC 02/12] entry/idle: Add a common function for activites during idle entry/exit

2020-08-16 Thread Joel Fernandes
Hello Peter,

On Sat, Aug 15, 2020 at 10:14:41AM +0200, pet...@infradead.org wrote:
> On Fri, Aug 14, 2020 at 11:18:58PM -0400, Joel Fernandes (Google) wrote:
> > Currently only RCU hooks for idle entry/exit are called. In later
> > patches, kernel-entry protection functionality will be added.
> > 
> > Signed-off-by: Joel Fernandes (Google) 
> 
> NAK, rcu_idle_enter() is broken where it is now, it needs to be pushed
> in deeper:
> 
> http://lkml.kernel.org/r/20200807193017.962482...@infradead.org

Thank you for pointing it out. Not a huge problem, a couple ways I can do it:
1. Move the calls to sched_core_unsafe_{enter,exit}() deeper into the idle loop.
2. Keep the calls to sched_core_unsafe_{enter,exit}() where they are now as
   in this patch, but leave out the rcu_idle_{enter,exit}() calls alone so
   they can be moved deeper as you mentioned.

#1 is not necessary for these patches to work and might be overkill.

I'll go the #2 route then. Let me know any other ideas you might have.

What I am trying to do here is to handle a case where task is switching to
idle (say it went to sleep) and wakes up later.

usermode -> syscall (kernel mode - so mark unsafe) -> idle (mark safe).

idle -> syscall wakes (kernel mode - so mark unsafe) -> usermode (mark safe).

Thank you,

 - Joel



[PATCH RFC 02/12] entry/idle: Add a common function for activites during idle entry/exit

2020-08-15 Thread Joel Fernandes (Google)
Currently only RCU hooks for idle entry/exit are called. In later
patches, kernel-entry protection functionality will be added.

Signed-off-by: Joel Fernandes (Google) 
---
 include/linux/entry-common.h | 16 
 kernel/sched/idle.c  | 17 +
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index efebbffcd5cc..2ea0e09b00d5 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -369,4 +369,20 @@ void irqentry_exit_cond_resched(void);
  */
 void noinstr irqentry_exit(struct pt_regs *regs, irqentry_state_t state);
 
+/**
+ * generic_idle_enter - Called during entry into idle for housekeeping.
+ */
+static inline void generic_idle_enter(void)
+{
+   rcu_idle_enter();
+}
+
+/**
+ * generic_idle_enter - Called when exiting idle for housekeeping.
+ */
+static inline void generic_idle_exit(void)
+{
+   rcu_idle_exit();
+}
+
 #endif
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 3b03bedee280..5db5a946aa3b 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -8,6 +8,7 @@
  */
 #include "sched.h"
 
+#include 
 #include 
 
 /* Linker adds these: start and end of __cpuidle functions */
@@ -54,7 +55,7 @@ __setup("hlt", cpu_idle_nopoll_setup);
 
 static noinline int __cpuidle cpu_idle_poll(void)
 {
-   rcu_idle_enter();
+   generic_idle_enter();
trace_cpu_idle_rcuidle(0, smp_processor_id());
local_irq_enable();
stop_critical_timings();
@@ -64,7 +65,7 @@ static noinline int __cpuidle cpu_idle_poll(void)
cpu_relax();
start_critical_timings();
trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
-   rcu_idle_exit();
+   generic_idle_exit();
 
return 1;
 }
@@ -158,7 +159,7 @@ static void cpuidle_idle_call(void)
 
if (cpuidle_not_available(drv, dev)) {
tick_nohz_idle_stop_tick();
-   rcu_idle_enter();
+   generic_idle_enter();
 
default_idle_call();
goto exit_idle;
@@ -178,13 +179,13 @@ static void cpuidle_idle_call(void)
u64 max_latency_ns;
 
if (idle_should_enter_s2idle()) {
-   rcu_idle_enter();
+   generic_idle_enter();
 
entered_state = call_cpuidle_s2idle(drv, dev);
if (entered_state > 0)
goto exit_idle;
 
-   rcu_idle_exit();
+   generic_idle_exit();
 
max_latency_ns = U64_MAX;
} else {
@@ -192,7 +193,7 @@ static void cpuidle_idle_call(void)
}
 
tick_nohz_idle_stop_tick();
-   rcu_idle_enter();
+   generic_idle_enter();
 
next_state = cpuidle_find_deepest_state(drv, dev, 
max_latency_ns);
call_cpuidle(drv, dev, next_state);
@@ -209,7 +210,7 @@ static void cpuidle_idle_call(void)
else
tick_nohz_idle_retain_tick();
 
-   rcu_idle_enter();
+   generic_idle_enter();
 
entered_state = call_cpuidle(drv, dev, next_state);
/*
@@ -227,7 +228,7 @@ static void cpuidle_idle_call(void)
if (WARN_ON_ONCE(irqs_disabled()))
local_irq_enable();
 
-   rcu_idle_exit();
+   generic_idle_exit();
 }
 
 /*
-- 
2.28.0.220.ged08abb693-goog



Re: [PATCH RFC 02/12] entry/idle: Add a common function for activites during idle entry/exit

2020-08-15 Thread peterz
On Fri, Aug 14, 2020 at 11:18:58PM -0400, Joel Fernandes (Google) wrote:
> Currently only RCU hooks for idle entry/exit are called. In later
> patches, kernel-entry protection functionality will be added.
> 
> Signed-off-by: Joel Fernandes (Google) 

NAK, rcu_idle_enter() is broken where it is now, it needs to be pushed
in deeper:

http://lkml.kernel.org/r/20200807193017.962482...@infradead.org