From patchwork Thu Apr 12 11:14:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 10338327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2EA6F60153 for ; Thu, 12 Apr 2018 11:19:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20548287D4 for ; Thu, 12 Apr 2018 11:19:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14C84287D1; Thu, 12 Apr 2018 11:19:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C612287D1 for ; Thu, 12 Apr 2018 11:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B0W6hENTl38kVo72HioJQPJwr4x+lAW1LyYnrBQfvts=; b=bNjfdJHQ+IMw3G+7klHvtvOt2j woTQyMTTXTK3x7MSpRl+okhWE915xZIgV6qEwwuYACkFc1c+YZouHyQcBjCdJyIXD8EarlcqhqwPB CPy7PUK8OXUoYMl9QWncL38JZJjUCEY4t/JrA6cqsX9yxhLmSeOCInQaOFHTurJu3OWBjFPknYcZE bTetr/0AKgQ04qjPW7Gb1l0lsySswMKUnR+oD9ZRWmH5oew/LdCGLg/ZrpnNqiYT7OVpBHM42zD+S 2j+E5jwl8eDlZkpMUQhWwPsD3d9Sp8IWEvnKJE5HdmuTAjNu03YKawPmhXd2aqj1m2+F+XrRgzA/E o99+h0Rg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6aFk-00006X-93; Thu, 12 Apr 2018 11:18:56 +0000 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6aBr-0005LS-9i for linux-arm-kernel@lists.infradead.org; Thu, 12 Apr 2018 11:14:57 +0000 Received: by mail-lf0-x242.google.com with SMTP id e5-v6so7125252lfb.7 for ; Thu, 12 Apr 2018 04:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VN7v+B4AGDaJ9ZxTUGLB9zWuv/2axGua2g5DbB4+qJo=; b=LrECZnYdgZ/2TmHf7jVrqc/fy5ZNRPebc9lVJniSXt3y4ekCcN3sD8U5b9q0xVxGyn KXALMYR1RfD0xwQFJXvIZzvcvs2W+0BV0cbGOawdtrONqYT0OcQVKXotAlOci/XmzH+A SZTOB/R51ax7CMsrvSjQulMt6fABENzAjDry4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VN7v+B4AGDaJ9ZxTUGLB9zWuv/2axGua2g5DbB4+qJo=; b=PD+Y/75Wk4HBeWBlfNkP1+m1/zD6tOvrwVfYavgJkxjP9h03SlwT40c3Jx/y/JEhkR WgUmKK8pXDB0walbjREO9n1V+i6M+MqK46ulrjFeu1CAIViCMzkM3QU4YKiJPYon3Oke gvEsfCMuN6Tn4LjG1TAtFqpA1SJEizxNi8fhJZqzbWewR0migMaNAGOH9iTweLdZmfa+ iGyf7XttI++IPYQSPBxbLR2n82c1cNadSvmwq1C3PRSSzPfynSlKxATYaQli0MjTzRrh q+SdPtjq3q2sxkqH5nTCvWDT2pz0ewsjkclAK4qOifOYt0nsY9GcVC3stlR5egxlZ5sj I0YQ== X-Gm-Message-State: ALQs6tD6dJgcekPBYHfWH5YAEpNa5y/CTCIozf4r1rMSfJDhw/Bf0UUE 5FAxFoC47nRrmtgcCefGYsWSkA== X-Google-Smtp-Source: AIpwx4+tslMe9H1Owe/SLKdwUAGqpACQFO7hh60OKOG8TltPrcb7bNklVj/aRKOUyLZmDNM34b3KOg== X-Received: by 10.46.32.154 with SMTP id g26mr365887lji.71.1523531688934; Thu, 12 Apr 2018 04:14:48 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id r29sm543187lje.72.2018.04.12.04.14.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 04:14:48 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-pm@vger.kernel.org Subject: [PATCH v7 06/26] timer: Export next wakeup time of a CPU Date: Thu, 12 Apr 2018 13:14:11 +0200 Message-Id: <1523531671-27491-7-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.org> References: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180412_041455_389423_D50A086C X-CRM114-Status: GOOD ( 16.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Vincent Guittot , Juri Lelli , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Rob Herring , linux-arm-kernel@lists.infradead.org, Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Lina Iyer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lina Iyer Knowing the sleep duration of CPUs, is known to be needed while selecting the most energy efficient idle state for a CPU or a group of CPUs. However, to be able to compute the sleep duration, we need to know at what time the next expected wakeup is for the CPU. Therefore, let's export this information via a new function, tick_nohz_get_next_wakeup(). Following changes make use of it. Cc: Thomas Gleixner Cc: Daniel Lezcano Cc: Lina Iyer Cc: Frederic Weisbecker Cc: Ingo Molnar Signed-off-by: Lina Iyer Co-developed-by: Ulf Hansson Signed-off-by: Ulf Hansson --- include/linux/tick.h | 10 ++++++++++ kernel/time/tick-sched.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/tick.h b/include/linux/tick.h index 389aa25..d341811 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -125,6 +125,7 @@ extern bool tick_nohz_idle_got_tick(void); extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next); extern unsigned long tick_nohz_get_idle_calls(void); extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu); +extern ktime_t tick_nohz_get_next_wakeup(int cpu); extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time); extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time); @@ -151,6 +152,15 @@ static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next) *delta_next = TICK_NSEC; return *delta_next; } + +static inline ktime_t tick_nohz_get_next_wakeup(int cpu) +{ + ktime_t t; + + /* Next wake up is the tick period, assume it starts now */ + return ktime_add(tick_nohz_get_sleep_length(&t), ktime_get()); +} + static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; } static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 646645e..08db7f3 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1098,6 +1098,17 @@ unsigned long tick_nohz_get_idle_calls(void) return ts->idle_calls; } +/** + * tick_nohz_get_next_wakeup - return the next wake up of the CPU + */ +ktime_t tick_nohz_get_next_wakeup(int cpu) +{ + struct clock_event_device *dev = + per_cpu(tick_cpu_device.evtdev, cpu); + + return dev->next_event; +} + static void tick_nohz_account_idle_ticks(struct tick_sched *ts) { #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE