From patchwork Thu Mar 26 19:23:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 46377 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 729E721585 for ; Thu, 26 Mar 2015 19:23:43 +0000 (UTC) Received: by wibgr10 with SMTP id gr10sf247808wib.2 for ; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Ro2nJIhvQ3KyKOsXgizDOuN/DtP0UDZKQE2MfGcLghg=; b=A+Rvj7IwNWyfcudHSzgRAZvLcmEWOResYwOFt5c+CQZvMhq7wvBUIeAleN/jBHbED/ AxAU8Wjd8h0LTmKlFAQVEjySz2cfQgjw4ESRcATNO3f8w45AqyppnDAPv5FiDqBu9Bi2 vEKs7YYC9kMrGVi7wMu6JJBrToGpHl2psIHPN5dnpztREaY2MayUsahjzoWzMhiiZCAg omFSQ6kDnkH15OrumSjTUppuHa/IM/O13GEoVSd/oYzTBPuPLq0l3rlmZcrrrqf4ZJa2 E+p63QXmmPHqdWOT80XVmpStr20hc9NIQyhFJRXIOLFoSY/L3lwYIGSfPt+plFSIcswN kKGw== X-Gm-Message-State: ALoCoQln1EGJY67eh4uPtc4JPPDIUPa73WnhTqbdfDI/wYPK/N7VF6QlBIg14Z27aU/LEjLafJwm X-Received: by 10.112.98.38 with SMTP id ef6mr3687102lbb.3.1427397822725; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.202.133 with SMTP id ki5ls294475lac.90.gmail; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr14789185lba.19.1427397822571; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id yg3si5298841lbb.150.2015.03.26.12.23.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2015 12:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbcgn8 with SMTP id gn8so48386695lbc.2 for ; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) X-Received: by 10.112.150.39 with SMTP id uf7mr14539782lbb.72.1427397822287; Thu, 26 Mar 2015 12:23:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.57.201 with SMTP id k9csp813246lbq; Thu, 26 Mar 2015 12:23:41 -0700 (PDT) X-Received: by 10.66.129.198 with SMTP id ny6mr29672825pab.67.1427397816731; Thu, 26 Mar 2015 12:23:36 -0700 (PDT) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com. [209.85.220.54]) by mx.google.com with ESMTPS id oe14si9590177pdb.205.2015.03.26.12.23.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2015 12:23:36 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.54 as permitted sender) client-ip=209.85.220.54; Received: by pacwz10 with SMTP id wz10so20821751pac.2 for ; Thu, 26 Mar 2015 12:23:35 -0700 (PDT) X-Received: by 10.66.66.75 with SMTP id d11mr28991626pat.132.1427397815810; Thu, 26 Mar 2015 12:23:35 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id pv4sm6365753pbb.17.2015.03.26.12.23.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 12:23:35 -0700 (PDT) From: John Stultz To: lkml Cc: Daniel Thompson , Russell King , Will Deacon , Catalin Marinas , Thomas Gleixner , Stephen Boyd , Peter Zijlstra , Ingo Molnar , John Stultz Subject: [PATCH 3/5] sched_clock: Remove suspend from clock_read_data Date: Thu, 26 Mar 2015 12:23:24 -0700 Message-Id: <1427397806-20889-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427397806-20889-1-git-send-email-john.stultz@linaro.org> References: <1427397806-20889-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Daniel Thompson Currently cd.read_data.suspended is read by the hotpath function sched_clock(). This variable need not be accessed on the hotpath. In fact, once it is removed, we can remove the conditional branches from sched_clock() and install a dummy read_sched_clock function to suspend the clock. The new master copy of the function pointer (actual_read_sched_clock) is introduced and is used for all reads of the clock hardware except those within sched_clock itself. Cc: Russell King Cc: Will Deacon Cc: Catalin Marinas Cc: Daniel Thompson Cc: Thomas Gleixner Cc: Stephen Boyd Cc: Peter Zijlstra Cc: Ingo Molnar Suggested-by: Thomas Gleixner Reviewed-by: Stephen Boyd Acked-by: Peter Zijlstra (Intel) Signed-off-by: Daniel Thompson Signed-off-by: John Stultz --- kernel/time/sched_clock.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 872e068..52ea5d9 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -28,10 +28,9 @@ * @read_sched_clock: Current clock source (or dummy source when suspended) * @mult: Multipler for scaled math conversion * @shift: Shift value for scaled math conversion - * @suspended: Flag to indicate if the clock is suspended (stopped) * * Care must be taken when updating this structure; it is read by - * some very hot code paths. It occupies <=48 bytes and, when combined + * some very hot code paths. It occupies <=40 bytes and, when combined * with the seqcount used to synchronize access, comfortably fits into * a 64 byte cache line. */ @@ -42,7 +41,6 @@ struct clock_read_data { u64 (*read_sched_clock)(void); u32 mult; u32 shift; - bool suspended; }; /** @@ -64,6 +62,7 @@ struct clock_data { struct clock_read_data read_data; ktime_t wrap_kt; unsigned long rate; + u64 (*actual_read_sched_clock)(void); }; static struct hrtimer sched_clock_timer; @@ -83,6 +82,8 @@ static u64 notrace jiffy_sched_clock_read(void) static struct clock_data cd ____cacheline_aligned = { .read_data = { .mult = NSEC_PER_SEC / HZ, .read_sched_clock = jiffy_sched_clock_read, }, + .actual_read_sched_clock = jiffy_sched_clock_read, + }; static inline u64 notrace cyc_to_ns(u64 cyc, u32 mult, u32 shift) @@ -99,12 +100,9 @@ unsigned long long notrace sched_clock(void) do { seq = raw_read_seqcount_begin(&cd.seq); - res = rd->epoch_ns; - if (!rd->suspended) { - cyc = rd->read_sched_clock(); - cyc = (cyc - rd->epoch_cyc) & rd->sched_clock_mask; - res += cyc_to_ns(cyc, rd->mult, rd->shift); - } + cyc = (rd->read_sched_clock() - rd->epoch_cyc) & + rd->sched_clock_mask; + res = rd->epoch_ns + cyc_to_ns(cyc, rd->mult, rd->shift); } while (read_seqcount_retry(&cd.seq, seq)); return res; @@ -120,7 +118,7 @@ static void notrace update_sched_clock(void) u64 ns; struct clock_read_data *rd = &cd.read_data; - cyc = rd->read_sched_clock(); + cyc = cd.actual_read_sched_clock(); ns = rd->epoch_ns + cyc_to_ns((cyc - rd->epoch_cyc) & rd->sched_clock_mask, rd->mult, rd->shift); @@ -166,10 +164,11 @@ void __init sched_clock_register(u64 (*read)(void), int bits, /* update epoch for new counter and update epoch_ns from old counter*/ new_epoch = read(); - cyc = rd->read_sched_clock(); + cyc = cd.actual_read_sched_clock(); ns = rd->epoch_ns + cyc_to_ns((cyc - rd->epoch_cyc) & rd->sched_clock_mask, rd->mult, rd->shift); + cd.actual_read_sched_clock = read; raw_write_seqcount_begin(&cd.seq); rd->read_sched_clock = read; @@ -209,7 +208,7 @@ void __init sched_clock_postinit(void) * If no sched_clock function has been provided at that point, * make it the final one one. */ - if (cd.read_data.read_sched_clock == jiffy_sched_clock_read) + if (cd.actual_read_sched_clock == jiffy_sched_clock_read) sched_clock_register(jiffy_sched_clock_read, BITS_PER_LONG, HZ); update_sched_clock(); @@ -223,13 +222,24 @@ void __init sched_clock_postinit(void) hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); } +/* + * Clock read function for use when the clock is suspended. + * + * This function makes it appear to sched_clock() as if the clock + * stopped counting at its last update. + */ +static u64 notrace suspended_sched_clock_read(void) +{ + return cd.read_data.epoch_cyc; +} + static int sched_clock_suspend(void) { struct clock_read_data *rd = &cd.read_data; update_sched_clock(); hrtimer_cancel(&sched_clock_timer); - rd->suspended = true; + rd->read_sched_clock = suspended_sched_clock_read; return 0; } @@ -237,9 +247,9 @@ static void sched_clock_resume(void) { struct clock_read_data *rd = &cd.read_data; - rd->epoch_cyc = rd->read_sched_clock(); + rd->epoch_cyc = cd.actual_read_sched_clock(); hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL); - rd->suspended = false; + rd->read_sched_clock = cd.actual_read_sched_clock; } static struct syscore_ops sched_clock_ops = {