From f5b90ccf9cd19bf3f7cb4418bd6324d9ec7abda3 Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Wed, 28 Jun 2017 12:00:31 +0530 Subject: [PATCH] Revert "Revert "ANDROID: softirq: defer softirq processing to ksoftirqd if CPU is busy with RT"" This reverts commit 28768780d4c486e546201ac2c30051fe412a3be9, as the merge conflicts have been resolved. Bug: 168521633 Change-Id: I9828d641e92e40a798e899b60aba83dbc59675bb Signed-off-by: Pavankumar Kondeti [satyap@codeaurora.org: trivial merge conflict resolution.] Signed-off-by: Satya Durga Srinivasu Prabhala [elavila: Port to mainline, squash with bugfix] Signed-off-by: J. Avila [ashayj@codeaurora.org: trivial merge conflict resolution.] Signed-off-by: Ashay Jaiswal Signed-off-by: Shaleen Agrawal --- include/linux/sched.h | 10 ++++++++++ kernel/sched/cpupri.c | 13 +++++++++++++ kernel/softirq.c | 22 +++++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 2f832fbae8c1..d48dd4df44fa 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1798,6 +1798,16 @@ current_restore_flags(unsigned long orig_flags, unsigned long flags) extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial); extern int task_can_attach(struct task_struct *p, const struct cpumask *cs_cpus_allowed); + +#ifdef CONFIG_RT_SOFTINT_OPTIMIZATION +extern bool cpupri_check_rt(void); +#else +static inline bool cpupri_check_rt(void) +{ + return false; +} +#endif + #ifdef CONFIG_SMP extern void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask); extern int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask); diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c index b464cbdf1589..65ccb44155de 100644 --- a/kernel/sched/cpupri.c +++ b/kernel/sched/cpupri.c @@ -355,3 +355,16 @@ void cpupri_cleanup(struct cpupri *cp) for (i = 0; i < CPUPRI_NR_PRIORITIES; i++) free_cpumask_var(cp->pri_to_cpu[i].mask); } + +#ifdef CONFIG_RT_SOFTINT_OPTIMIZATION +/* + * cpupri_check_rt - check if CPU has a RT task + * should be called from rcu-sched read section. + */ +bool cpupri_check_rt(void) +{ + int cpu = raw_smp_processor_id(); + + return cpu_rq(cpu)->rd->cpupri.cpu_to_pri[cpu] > CPUPRI_NORMAL; +} +#endif diff --git a/kernel/softirq.c b/kernel/softirq.c index a8bee4813294..f45fed9fbd57 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c @@ -522,6 +522,17 @@ static inline bool lockdep_softirq_start(void) { return false; } static inline void lockdep_softirq_end(bool in_hardirq) { } #endif +static inline __u32 softirq_deferred_for_rt(__u32 *pending) +{ + __u32 deferred = 0; + + if (cpupri_check_rt()) { + deferred = *pending & LONG_SOFTIRQ_MASK; + *pending &= ~LONG_SOFTIRQ_MASK; + } + return deferred; +} + asmlinkage __visible void __softirq_entry __do_softirq(void) { unsigned long end = jiffies + MAX_SOFTIRQ_TIME; @@ -529,6 +540,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) int max_restart = MAX_SOFTIRQ_RESTART; struct softirq_action *h; bool in_hardirq; + __u32 deferred; __u32 pending; int softirq_bit; @@ -541,13 +553,14 @@ asmlinkage __visible void __softirq_entry __do_softirq(void) pending = local_softirq_pending(); + deferred = softirq_deferred_for_rt(&pending); softirq_handle_begin(); in_hardirq = lockdep_softirq_start(); account_softirq_enter(current); restart: /* Reset the pending bitmask before enabling irqs */ - set_softirq_pending(0); + set_softirq_pending(deferred); __this_cpu_write(active_softirqs, pending); local_irq_enable(); @@ -586,14 +599,17 @@ restart: local_irq_disable(); pending = local_softirq_pending(); + deferred = softirq_deferred_for_rt(&pending); + if (pending) { if (time_before(jiffies, end) && !need_resched() && --max_restart) goto restart; - - wakeup_softirqd(); } + if (pending | deferred) + wakeup_softirqd(); + account_softirq_exit(current); lockdep_softirq_end(in_hardirq); softirq_handle_end();