From patchwork Sun Jun 11 21:26:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 103568 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp677187qgd; Sun, 11 Jun 2017 14:26:42 -0700 (PDT) X-Received: by 10.99.116.2 with SMTP id p2mr105669pgc.162.1497216402557; Sun, 11 Jun 2017 14:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497216402; cv=none; d=google.com; s=arc-20160816; b=oVGwHEXLZ3EVt8/Gs+jskAp4fNs0WLT898IiEiVhBni56aBmVtftW9OUgL4OCFkPkf P8K5XVFLKGDXEKXT09obeWkYai0b008Yul6EBwQdILFP4jEW+tsPp7L0t0ySsT0S1A4b bS2ppMWJt9u3A9Uqht7CUnJqn80xkRzO9wfgKhMFQkUVHSYAyFgJO5xtYAFgcx3uFwhm KEt1aMetdnkpm3zpB7N1LZwpesXxa7dR7FiKinHcPGNvnpioEV6EDPV652dOcNuikqXL MfXccM1w4SNTtgRCPd7ebvBZCXJ5/IPankR1HWMCNbZcBWaimRoK/I/kXrBcKcC+AkTi A+vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Y3yMZIXFTxKMQgz89snuMO7CHFg7xJA5BdLfW1ijhl8=; b=ymC+Q+s2EYPCblnXtLfvdyCi13U2hLP4qrWoEhfhLRVS3Sps7lrEiLF6j+cWGmeNCb UpAhTQcS77BwtTg86/tST5yOYlK+ZODXHEzR6hEUM59gIJGAqsJIWKFNA/LEEFPyBFY+ T5+8pwSQGAnILLoemNi/cXWqm8tbcKSNQLydb0KQp+2XsMIopjxf34z1tXcoVc40bmya D9tfq7mxFPkQXMSGTWt82An7Dgqt/93RzkWhDARilasv7bUwH1t/B6eLZUpWx9dqDmvi mrSqDQ8+N1AYaD90B7PbxGH+M8EuV5FVjPAtd57LK7xJmFN3IyTlG/5q4Dhv+31Cz/YX 2xFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si5571196plb.101.2017.06.11.14.26.42; Sun, 11 Jun 2017 14:26:42 -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=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbdFKV0j (ORCPT + 25 others); Sun, 11 Jun 2017 17:26:39 -0400 Received: from mail-lf0-f42.google.com ([209.85.215.42]:33688 "EHLO mail-lf0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbdFKV0i (ORCPT ); Sun, 11 Jun 2017 17:26:38 -0400 Received: by mail-lf0-f42.google.com with SMTP id m77so19915483lfe.0 for ; Sun, 11 Jun 2017 14:26:37 -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; bh=Y3yMZIXFTxKMQgz89snuMO7CHFg7xJA5BdLfW1ijhl8=; b=Vc4vFy98Cart072clBlmsrFICuPhnxwcHZSKpMAWGidAJP7x+SWWkhqQ4B4wqz088T kCKVYekT0YYtHT6oijeImkvFyI6NUbk1kJnVtLlXnkeCryuPIgxFGkc/LUsODE0iGUoc vMNRV6gFPX/T2j4avn+ojcKx07LD4zEMXIExY= 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; bh=Y3yMZIXFTxKMQgz89snuMO7CHFg7xJA5BdLfW1ijhl8=; b=apH+InhUtHYUIdTNIAJIC3Z3mk9NoltWzqMm7OCbETJqljsJoT9lPP1rxTNChICIUl 9rq/ZQmOwfBSLrIigv89NQQFvCh+Utt0XYlx3xzCmOt6U/pwG36vG4FxvO+yD+AEuDA1 c4loocDdIc9WpSSFWPrPmjX58YSTVDfhoGUtcoIMRG8RnirUImal378yZtY1XrBW5frk Utbqw4/cVhWh/JemGtbM8Ads0rG2SmktTdWKluYTSWIrvVe6IAhTKGxI87ADPlXL87wF Smw4AfBfnkAML0IHAmOIrc3+2hDsZCsmaIQw9PzhUVCknlmZo76UWbI8SZaJ/vfRi/sF U/PQ== X-Gm-Message-State: AODbwcCrD4AVRJfKl0x7Ws5nCSYvmnm6LLc9VycKse8OSx97bcGDPrzL pZZBf++wLaiXjIrb X-Received: by 10.25.20.227 with SMTP id 96mr3181153lfu.8.1497216396775; Sun, 11 Jun 2017 14:26:36 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-797771d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.119.121]) by smtp.gmail.com with ESMTPSA id 1sm2116318ljg.53.2017.06.11.14.26.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Jun 2017 14:26:35 -0700 (PDT) From: Linus Walleij To: Daniel Lezcano , Thomas Gleixner , Joel Stanley , Jonas Jensen Cc: Janos Laube , Paulius Zaleckas , linux-arm-kernel@lists.infradead.org, Hans Ulli Kroll , Florian Fainelli , linux-kernel@vger.kernel.org, Linus Walleij , Andrew Jeffery Subject: [PATCH 1/2] drivers/clocksource/fttmr010: Optimize sched_clock() Date: Sun, 11 Jun 2017 23:26:16 +0200 Message-Id: <20170611212617.6906-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sched_clock() call should be really fast so we want to avoid an extra if() clause on the read path if possible. Implement two sched_clock_read() functions, one if the timer counts up and one if it counts down. Incidentally this also mirrors how clocksource_mmio_init() works and make things simple and easy to understand. Suggested-by: Daniel Lezcano Cc: Andrew Jeffery Cc: Joel Stanley Cc: Jonas Jensen Signed-off-by: Linus Walleij --- drivers/clocksource/timer-fttmr010.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.9.4 diff --git a/drivers/clocksource/timer-fttmr010.c b/drivers/clocksource/timer-fttmr010.c index f8801507a687..5e82469995cb 100644 --- a/drivers/clocksource/timer-fttmr010.c +++ b/drivers/clocksource/timer-fttmr010.c @@ -91,13 +91,16 @@ static inline struct fttmr010 *to_fttmr010(struct clock_event_device *evt) return container_of(evt, struct fttmr010, clkevt); } -static u64 notrace fttmr010_read_sched_clock(void) +static u64 notrace fttmr010_read_sched_clock_up(void) { - if (local_fttmr->count_down) - return ~readl(local_fttmr->base + TIMER2_COUNT); return readl(local_fttmr->base + TIMER2_COUNT); } +static u64 notrace fttmr010_read_sched_clock_down(void) +{ + return ~readl(local_fttmr->base + TIMER2_COUNT); +} + static int fttmr010_timer_set_next_event(unsigned long cycles, struct clock_event_device *evt) { @@ -304,15 +307,17 @@ static int __init fttmr010_timer_init(struct device_node *np) "FTTMR010-TIMER2", fttmr010->tick_rate, 300, 32, clocksource_mmio_readl_down); + sched_clock_register(fttmr010_read_sched_clock_down, 32, + fttmr010->tick_rate); } else { writel(0, fttmr010->base + TIMER2_LOAD); clocksource_mmio_init(fttmr010->base + TIMER2_COUNT, "FTTMR010-TIMER2", fttmr010->tick_rate, 300, 32, clocksource_mmio_readl_up); + sched_clock_register(fttmr010_read_sched_clock_up, 32, + fttmr010->tick_rate); } - sched_clock_register(fttmr010_read_sched_clock, 32, - fttmr010->tick_rate); /* * Setup clockevent timer (interrupt-driven) on timer 1. From patchwork Sun Jun 11 21:26:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 103569 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp677268qgd; Sun, 11 Jun 2017 14:27:07 -0700 (PDT) X-Received: by 10.99.114.89 with SMTP id c25mr8252342pgn.14.1497216427266; Sun, 11 Jun 2017 14:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497216427; cv=none; d=google.com; s=arc-20160816; b=OnJJR78oH8QqFnSLstLcyoebHxTc1HryvKTeDkXkWgA8LJWLQutJ0rUH/IacXwOinh fy5hiyuB0aaVBRYBeBhf4EJrzaAupf5dwOm5VVBVdn77jsx9nn1/HwsxkOpE/U7gBZ4H 4+d9qTx/r/YeIWCnPQfUhPxlz6XYyrjWKRNjynCxU5voecu8L+sgWmUJVNiPw0CPZWUV /YWpSkuBUYD0gQlSBjANefB8dgIYiVR1J++fPInfyx55DiXIjg4F5M6l5jc1iUvbQIT7 hY7jgLANHsnqrrJecwLlTA1NKhfpjgIloVv9jxUdh1hKKgTaK3g6v5ZtMGVNBTmJKIsh jBCg== 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:dkim-signature:arc-authentication-results; bh=uAdHbk7ZxbO10p1PlmRh4J/GvbgYkZmbfR78+MzpD1I=; b=UQQCdsdjU5uYjwP+n0ijilxXmQCmzb1Yzuw59T/JIqi+9Z24vsQ4blVaDYPPNijMAD i6q5MvRAwFFRQ3Jl8S0hhU8wQzISl0HMEMbqaUM6DN2eepAlS+PC+bzuUM0NoKKTzcnh NNLaPydBWSbzKIg/NU3GrNVwWMbTauWIi9QYxxzjJxs2/Hs50sDxJlD3kBDw7F5dHAg0 BbF0JggaY5ud9H7ubWeEypv2ZZnhyGa16VDLEh6k+Lx32JSuJX5M3tm9CmPhu3ag6JFn vuK3UBDdtyH9O8U6fbUKmptokUgvjzm0C3hr2wqCBHRrwija9MA5cgbTmnBHXDDu0i5o RxhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si4922618pgf.98.2017.06.11.14.27.07; Sun, 11 Jun 2017 14:27: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=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752016AbdFKV0p (ORCPT + 25 others); Sun, 11 Jun 2017 17:26:45 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35086 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbdFKV0l (ORCPT ); Sun, 11 Jun 2017 17:26:41 -0400 Received: by mail-lf0-f50.google.com with SMTP id p189so44612269lfe.2 for ; Sun, 11 Jun 2017 14:26:41 -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=uAdHbk7ZxbO10p1PlmRh4J/GvbgYkZmbfR78+MzpD1I=; b=UY4oVQZLCfzGyby/IepZ5/nDocuwf3Bj0uyPHKM/BGZofuv8B5hiSjk09jCODpRfnV lweb6irqQUCUBn0v+Lrj5lU3aCz5Fl7rqSMWtzv1iDWgMolDVupMn8HLLs1yeAZUIOzX 2LPZo6Ruo4Q1o5vyZlRrbcRJhHaXLkrw9Oxz4= 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=uAdHbk7ZxbO10p1PlmRh4J/GvbgYkZmbfR78+MzpD1I=; b=Vi3aGcIlMl1fFPsHNYNzH5qKMluqX2rcjTFJToX76I7DvZJfhpBkrRrZrTyetVdZpA Sxb8k9WZCQ4fwU3t3WwHB9OVgW7r+ePgArL4ImoSUjwkuPD1NbsGrqhd1S0f4/ndms7N af9Ze35G69M7xaTdxKhjrh+IFdkay6lI0+7yKBpqVYiGG5xOKpQkOJcxx7VkA2NLz9fJ offvEgEvkFZPJBsmvGchmb9iSAvGWFkzuYHzJaCRv6d5p9KV+u74UMrs3aMaqsqtQC5E lbnMtFpZs2aWoxSKTqw/sArl32kgXPp4oXOwAqnzwobo8hd2ahPctEU+BnBH5S6kAevZ GWYQ== X-Gm-Message-State: AKS2vOwpWfTi0g4pZbRsjbOM/GSy5/SUHFMgleB9fMWiVmPkI2lKowut 1czh+A72GfKQ1ZZ+ X-Received: by 10.25.163.134 with SMTP id m128mr1296293lfe.112.1497216400334; Sun, 11 Jun 2017 14:26:40 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-797771d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.119.121]) by smtp.gmail.com with ESMTPSA id 1sm2116318ljg.53.2017.06.11.14.26.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Jun 2017 14:26:38 -0700 (PDT) From: Linus Walleij To: Daniel Lezcano , Thomas Gleixner , Joel Stanley , Jonas Jensen Cc: Janos Laube , Paulius Zaleckas , linux-arm-kernel@lists.infradead.org, Hans Ulli Kroll , Florian Fainelli , linux-kernel@vger.kernel.org, Linus Walleij , Andrew Jeffery Subject: [PATCH 2/2] drivers/clocksource/fttmr010: Implement delay timer Date: Sun, 11 Jun 2017 23:26:17 +0200 Message-Id: <20170611212617.6906-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170611212617.6906-1-linus.walleij@linaro.org> References: <20170611212617.6906-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This timer is often used on the ARM architecture, so as with so many siblings, we can implement delay timers, removing the need for the system to calibrate jiffys at boot, and potentially handling CPU frequency scaling on targets. We cannot just protect the Kconfig with a "depends on ARM" because it is already known that different architectures are using Faraday IP blocks, so it is better to make things open-ended and use Result on boot dmesg: Switching to timer-based delay loop, resolution 40n Calibrating delay loop (skipped), value calculated using timer frequency.. 50.00 BogoMIPS (lpj=250000) This is accurately the timer frequency, 250MHz on the APB bus. Cc: Andrew Jeffery Cc: Joel Stanley Cc: Jonas Jensen Signed-off-by: Linus Walleij --- drivers/clocksource/timer-fttmr010.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) -- 2.9.4 Tested-by: Jonas Jensen Tested-by: Andrew Jeffery diff --git a/drivers/clocksource/timer-fttmr010.c b/drivers/clocksource/timer-fttmr010.c index 5e82469995cb..0074d89cd2ce 100644 --- a/drivers/clocksource/timer-fttmr010.c +++ b/drivers/clocksource/timer-fttmr010.c @@ -17,6 +17,7 @@ #include #include #include +#include /* * Register definitions for the timers @@ -81,9 +82,15 @@ struct fttmr010 { bool count_down; u32 t1_enable_val; struct clock_event_device clkevt; +#ifdef CONFIG_ARM + struct delay_timer delay_timer; +#endif }; -/* A local singleton used by sched_clock, which is stateless */ +/* + * A local singleton used by sched_clock and delay timer reads, which are + * fast and stateless + */ static struct fttmr010 *local_fttmr; static inline struct fttmr010 *to_fttmr010(struct clock_event_device *evt) @@ -101,6 +108,20 @@ static u64 notrace fttmr010_read_sched_clock_down(void) return ~readl(local_fttmr->base + TIMER2_COUNT); } +#ifdef CONFIG_ARM + +static unsigned long fttmr010_read_current_timer_up(void) +{ + return readl(local_fttmr->base + TIMER2_COUNT); +} + +static unsigned long fttmr010_read_current_timer_down(void) +{ + return ~readl(local_fttmr->base + TIMER2_COUNT); +} + +#endif + static int fttmr010_timer_set_next_event(unsigned long cycles, struct clock_event_device *evt) { @@ -349,6 +370,18 @@ static int __init fttmr010_timer_init(struct device_node *np) fttmr010->tick_rate, 1, 0xffffffff); +#ifdef CONFIG_ARM + /* Also use this timer for delays */ + if (fttmr010->count_down) + fttmr010->delay_timer.read_current_timer = + fttmr010_read_current_timer_down; + else + fttmr010->delay_timer.read_current_timer = + fttmr010_read_current_timer_up; + fttmr010->delay_timer.freq = fttmr010->tick_rate; + register_current_timer_delay(&fttmr010->delay_timer); +#endif + return 0; out_unmap: