From patchwork Wed Mar 14 16:58:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 131675 Delivered-To: patches@linaro.org Received: by 10.80.210.197 with SMTP id q5csp410344edg; Wed, 14 Mar 2018 09:59:13 -0700 (PDT) X-Received: by 2002:a19:5789:: with SMTP id l131-v6mr2876369lfb.135.1521046753553; Wed, 14 Mar 2018 09:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521046753; cv=none; d=google.com; s=arc-20160816; b=lforj6fvwJ+nQyDDgXLTc3H7l6ojGZgjb/GyNjwE8RYDdMjVYbULSKlfofZdRulMRH RwjXNhYfgKx7nPkfvGvZxfG5ly1AhG9reCN9iTcIozmZamkfnAtWCqcAkm378DPlBVnP UHTWlxHckgbjS/r5df1XrAzTVwo9ZM3HWIC92O2DmpCxvCBtuDVy6/fJN8qAVC9tYK4h KmesmQn58MtARjL/N1QMAU6OTUbv+DHwIAmIJG5fP332KvJVsg5nlGiPXnXb/1A8R1gk EjO4rywYZhpy4I+iytuRX0W6m8Ooq92LTKUQB3bF4WbLOzIA+CQSDjh2dOtylfR8WkPv yxpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=8UBUtn8CbnkSkAYxAysp6BLgCShK7n+FPP5Gf9WxSFY=; b=qblA4YlWWh28kxJYgBcCKT4voi9HmcRaj+tbKnP/4fTY3JA7S7EaM3RkwX1wdwq17f E8s5wvlU4jYO6/ynxNRNF0q3o9a8QuuI8bHoAKAVye04pw3CidHQjaTbvZDhuaoaKth9 r9as3DGQCChBuYXBHqCs4TTVBMSAD7iLSG4i/bkfazok6u/a2F+J4YZabdhMMfIIaECv B4NoznllANYlfpIxHYn+QAlODieNObjfaPxO/4jvcPKHZldTh/CWcf9fs3d3X6FrgCcx xrQWR+VtQbBqiYUD1v+puZgdg0iOx3L/3olcaYFAlINWcUr78f06I5RhbNGDK+92ZZPG jjVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MlAVsbGl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w21-v6sor65911lfd.86.2018.03.14.09.59.13 for (Google Transport Security); Wed, 14 Mar 2018 09:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MlAVsbGl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=8UBUtn8CbnkSkAYxAysp6BLgCShK7n+FPP5Gf9WxSFY=; b=MlAVsbGlspSKYxylbRnZrgNpygb0RAeARjinzHmTVmXz8Wkhn37/EMdXiUGEKBa1D0 AH3RfrBYspPr2CN8sIdi97fUONChoDR+Zoman3O2rLneegu9n4dksD3naUvWvTB5Ua4X KOBJejRVpMEygQKvKKx2iY+KU7Y94WBDDZn0A= 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=8UBUtn8CbnkSkAYxAysp6BLgCShK7n+FPP5Gf9WxSFY=; b=XRZZPO5+HOBT9PMBmcP/q8r5cdfKY32ki2hhz6vWDIgGIhoRaV9Rb1WMceI1Pbdlmd GFjbwHpQ7hqiqiQD+Eu53G2lNeRnPlksc4JCu9TClkYstPjF96PyZtzcYUMd1aID12Tm lpZTCzzvQ+koNN+9JcMlz3SZJElAz52djOzhrBCnsElU81pehjaxj0tIDNMWXhrnTU76 TC7KovxFi+YVniB7H1SfHUnGGh5zyipWYA7y9voqBr+6Ib6QzYy8wNmwPVOMaCFKJ3pV 5EvJZDKu+CLDB8j8OWG37TrCcKD435xrhHbtc7LulxF2OjPBoazEjTryoM0u2jw7qSG5 elJA== X-Gm-Message-State: AElRT7FKHYu/hw3k/gRyKoUT20aTDCSEtTXskpJTC0eccPkgWB2A/0vO 54kpkxKJ7p619HlWqR6HQ0zrGuFh X-Google-Smtp-Source: AG47ELta2xPQQqOJ4ft2qVMM/qrfsr9FGkw9wauIscYNQrkxUVDFxvnwmS4WS3QxkP0Jby2ISTjrwQ== X-Received: by 2002:a19:5317:: with SMTP id h23-v6mr3524615lfb.6.1521046753203; Wed, 14 Mar 2018 09:59:13 -0700 (PDT) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t24-v6sm724849lfi.30.2018.03.14.09.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Mar 2018 09:59:12 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Kevin Hilman , Lina Iyer , Lina Iyer , Ulf Hansson , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 06/25] timer: Export next wakeup time of a CPU Date: Wed, 14 Mar 2018 17:58:16 +0100 Message-Id: <1521046715-30683-7-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> References: <1521046715-30683-1-git-send-email-ulf.hansson@linaro.org> 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 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(+) -- 2.7.4 diff --git a/include/linux/tick.h b/include/linux/tick.h index 7cc3592..e51cf2c 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -120,6 +120,7 @@ extern void tick_nohz_irq_exit(void); extern ktime_t tick_nohz_get_sleep_length(void); 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); #else /* !CONFIG_NO_HZ_COMMON */ @@ -132,6 +133,15 @@ static inline ktime_t tick_nohz_get_sleep_length(void) { return NSEC_PER_SEC / HZ; } + +static inline ktime_t tick_nohz_get_next_wakeup(int cpu) +{ + ktime_t len = NSEC_PER_SEC/HZ; + + /* Next wake up is the tick period, assume it starts now */ + return ktime_add(len, 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; } #endif /* !CONFIG_NO_HZ_COMMON */ diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 29a5733..da1bff3 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1025,6 +1025,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