Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2121033ybh; Sun, 15 Mar 2020 19:41:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuPtz/a2+9sbhhEmX+H53CkWeMqTZH/Ikh8YTyL2WI4GX3hMkPcS127VltKROsSaI+OtVW6 X-Received: by 2002:a9d:69c5:: with SMTP id v5mr14782538oto.228.1584326467244; Sun, 15 Mar 2020 19:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584326467; cv=none; d=google.com; s=arc-20160816; b=Wa5m0AJTTUmaBVSER+GThwjBJGHEtxPHy353ICmoq2NpaSprzwwey8OuvHHK94f7F1 Rd3lh3vlgmoATD66W59TkhRCb/dips9T3a5ogeIWC6Qh9AUWS2LCvda2FKSsmC7NZ5h8 7iwIA/QK5kKoJLgFKPt1g58fH7XYZtBqr4DJnMGl2hzhV8ioqUput0amkd+BZJ7O27e8 bEK9uLCipcxPB8CgPdWq7xyvBLZAWG8CBipX8ukBHtyxRMAiqB+GAsV8UxtqCTOTtdwX p+BNnH7tATiE/uZIlURtP7m/XkvrxubW1GhCYwF4gLMvhPCwa2SsywgMKUsXT/xsdJvn 7kQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=cH+2p7cVtn7b3/CDSyuVcyqtKo2XSY7tvfF/+90W7EQ=; b=eXLaDS4D/0sLbgBvwi3QYyIIzNVDKTBop1zs0Wfzr2Sp+GzoTYly+ZfPPg0ynHDBzB xWi00Rcz3MqJNzdST63u2petYtUb+rmkmMvpMae8hz1RvqQhCdbt13RRixvWNoXaYxgO rs3AGMPMWLwoRrza1++Osr8Mf7u2VZMgsuSZDkDTEtPM/7gDQYjSWbtsKmyal+rFnGOz h94ydxyFL1QVOy+Twr8dW5iGvUnCSehYo41PDhx4CPyQw1jFEhDuR0vJenIwuBdbAI8o YUBdui8COqiFTCKDaCY2rGVKOadnvwjoOT5YADpf6WgVRqW9+vDKHeQcz/cIJ23fCmHN nrrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=TcK3+pf3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si8103131oia.236.2020.03.15.19.40.55; Sun, 15 Mar 2020 19:41:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=TcK3+pf3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730460AbgCPCjq (ORCPT + 99 others); Sun, 15 Mar 2020 22:39:46 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:30765 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730439AbgCPCjo (ORCPT ); Sun, 15 Mar 2020 22:39:44 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1584326383; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=cH+2p7cVtn7b3/CDSyuVcyqtKo2XSY7tvfF/+90W7EQ=; b=TcK3+pf3W0la9rrvaaR9YpWCpSigpuLkFwvLWSai+q1abTYpMkwfCT+N3vjmKGriIvpXJhsD U6/legJJfuCBIFfapTWzwc45JdEHNBI8pQ8d6u22DYZgklLFins2UvKRQ5tG/60GPETddNKL L4SWerewLrFwPowMLmzQBao44pg= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e6ee6e3.7f69d5158d18-smtp-out-n01; Mon, 16 Mar 2020 02:39:31 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 24000C6473C; Mon, 16 Mar 2020 02:39:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from th-lint-038.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: psodagud) by smtp.codeaurora.org (Postfix) with ESMTPSA id D2D73C3855F; Mon, 16 Mar 2020 02:39:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D2D73C3855F Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=psodagud@codeaurora.org From: Prasad Sodagudi To: john.stultz@linaro.org, tglx@linutronix.de, sboyd@kernel.org Cc: linux-kernel@vger.kernel.org, saravanak@google.com, tsoni@codeaurora.org, tj@kernel.org, Prasad Sodagudi Subject: [PATCH 2/2] sched: Add a check for cpu unbound deferrable timers Date: Sun, 15 Mar 2020 19:39:10 -0700 Message-Id: <1584326350-30275-3-git-send-email-psodagud@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584326350-30275-1-git-send-email-psodagud@codeaurora.org> References: <1584326350-30275-1-git-send-email-psodagud@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a check for cpu unbound deferrable timer expiry and raise softirq for handling the expired timers so that the CPU can process the cpu unbound deferrable times as early as possible when a cpu tries to enter/exit idle loop. Signed-off-by: Prasad Sodagudi --- include/linux/timer.h | 3 +++ kernel/time/tick-sched.c | 6 ++++++ kernel/time/timer.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/linux/timer.h b/include/linux/timer.h index 1e6650e..25a1837 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -172,6 +172,9 @@ extern int del_timer(struct timer_list * timer); extern int mod_timer(struct timer_list *timer, unsigned long expires); extern int mod_timer_pending(struct timer_list *timer, unsigned long expires); extern int timer_reduce(struct timer_list *timer, unsigned long expires); +#ifdef CONFIG_SMP +extern bool check_pending_deferrable_timers(int cpu); +#endif /* * The jiffies value which is added to now, when there is no timer diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index a792d21..fe0836a 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -948,6 +949,11 @@ static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) ktime_t expires; int cpu = smp_processor_id(); +#ifdef CONFIG_SMP + if (check_pending_deferrable_timers(cpu)) + raise_softirq_irqoff(TIMER_SOFTIRQ); +#endif + /* * If tick_nohz_get_sleep_length() ran tick_nohz_next_event(), the * tick timer expiration time is known already. diff --git a/kernel/time/timer.c b/kernel/time/timer.c index a63ca77..3b0aac3 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -221,6 +221,7 @@ static DECLARE_WORK(timer_update_work, timer_update_keys); #ifdef CONFIG_SMP struct timer_base timer_base_deferrable; +static atomic_t deferrable_pending; unsigned int sysctl_timer_migration = 1; DEFINE_STATIC_KEY_FALSE(timers_migration_enabled); @@ -1609,6 +1610,31 @@ static u64 cmp_next_hrtimer_event(u64 basem, u64 expires) return DIV_ROUND_UP_ULL(nextevt, TICK_NSEC) * TICK_NSEC; } + +#ifdef CONFIG_SMP +/* + * check_pending_deferrable_timers - Check for unbound deferrable timer expiry + * @cpu - Current CPU + * + * The function checks whether any global deferrable pending timers + * are exipired or not. This function does not check cpu bounded + * diferrable pending timers expiry. + * + * The function returns true when a cpu unbounded deferrable timer is expired. + */ +bool check_pending_deferrable_timers(int cpu) +{ + if (cpu == tick_do_timer_cpu || + tick_do_timer_cpu == TICK_DO_TIMER_NONE) { + if (time_after_eq(jiffies, timer_base_deferrable.clk) + && !atomic_cmpxchg(&deferrable_pending, 0, 1)) { + return true; + } + } + return false; +} +#endif + /** * get_next_timer_interrupt - return the time (clock mono) of the next timer * @basej: base time jiffies @@ -1799,7 +1825,8 @@ static __latent_entropy void run_timer_softirq(struct softirq_action *h) __run_timers(base); if (IS_ENABLED(CONFIG_NO_HZ_COMMON)) { __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); - if (tick_do_timer_cpu == TICK_DO_TIMER_NONE || + if ((atomic_cmpxchg(&deferrable_pending, 1, 0) && + tick_do_timer_cpu == TICK_DO_TIMER_NONE) || tick_do_timer_cpu == smp_processor_id()) __run_timers(&timer_base_deferrable); } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project