From patchwork Fri Aug 25 22:57:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 111042 Delivered-To: patches@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1689384qge; Fri, 25 Aug 2017 15:57:10 -0700 (PDT) X-Received: by 10.84.217.211 with SMTP id d19mr33083plj.121.1503701830182; Fri, 25 Aug 2017 15:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503701830; cv=none; d=google.com; s=arc-20160816; b=Kb6I8C4xCqQzfUzf4ZuILZNzpFqSy1hY4TpR7JuXSas9rE9XdLVos2qeM2F95AyhcL pJ29hsSP6LI6jkv/qQzDrmCNP/rB97czKeJc4yC52bc2vS0Mo3psfbsLu/N25wrPG4qN rWQFIQHRcKXA9C9BrbrChgH0Irt+PAjROLJUD2HmitzgQcercDPhhXZ4CP/NBKuDMtJ+ yv4SqiBn/EhdJOGcTZV5sNup1XghZs31/aS1hQYoUXp6Lh3ksxxN0nYgM6OPrEeo2MM3 oJU193snjE5Sm0G1+QLuw8HY297WE1BSl/pKpCIltj1YILJoR3dH6HJKHwzVR5GlRGHf 7oTA== 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=hOS06hOEqaTQMgO4iB0t7NmqJCSNnik5tuIiOMvia68=; b=FpYzMu9GL+fTy/l1aKcx9stZ0yAuqwHCKBljd8ddbt13DpL30SrB+M7g+i60sJmjAA BbJs49UvC+2/gklkWV4kaIpqDW/mtGPR3mgot4NfqGFGx5Ah8U/pKALSHNs2bdxp7aao uD95XUuQKeDirCXoABNU74WRRnFYhAHwpsDvzPAmk1lPOp5Pfr+NzsTxmSIo6h8JEdhF 9Wu+Qze0cxQQWJPLIg6XTQcL6c34o5YgpnH3pl/4fAYP/rU/g+yZichb0aJqJ2lxQHlx B7FKAdJoyg/xDhlXd875m0wjVeCkn1E316+tvvHd7yBhylYRtedea6v8/saNkweHgxMy Ij2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gGh7EuSK; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 73sor2982820pld.5.2017.08.25.15.57.10 for (Google Transport Security); Fri, 25 Aug 2017 15:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gGh7EuSK; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@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=hOS06hOEqaTQMgO4iB0t7NmqJCSNnik5tuIiOMvia68=; b=gGh7EuSKXWyuEaulo8vEzj5ra3dBP3dX8uKYU1FrZD1bGOe/GnotDcNp3tLmte8N7J nMe0W9OYnjNOa2C84y4Bqni6r/v+OG/z/qyX8m6qWWhMYnpgk4t4tIKivs0bOxf8PZz8 DXV7GhzZxJykAY1iav5rVUDI0oUmMFcqgjfPA= 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=hOS06hOEqaTQMgO4iB0t7NmqJCSNnik5tuIiOMvia68=; b=LAaGNNQ7JRN3TOGRx6Y640oRdDPGENZc5i9ziNL9oGLTAp6+e6GeyPdwfXVaR9R/m/ N0gHBNlzSmuzF4CbOVlvrtgwq8q+EhmPiGAAgXUJgHsd7UafCTy3zyr5NdWDixQ383Vy smCqmzB21jiDYLjkUC0TIWEGS4b6OQ6sgOtfP9SbXh38hniv5r7w+tu0O7XX3l4gBreU IB43JiAT4ahNSG99TkiU0hktKU6Pwa+odVY3+n4dqAbW2VOGz/OzsVEQO1rbVMbvbJLh Icl8Cza8qWwWCav6lcLhKrllv46hRwwa+Ulht7QGisqd9fKi/Pk/BAMZbMAT4+NsCzbs 3ehQ== X-Gm-Message-State: AHYfb5hPJ9xQZzMyNQtbYKL8/ZJPBu5JAHm9gdlR59vNUXpWwPcx4lMC Z/WI5kNCF4j8UkpzS7g= X-Received: by 10.84.192.1 with SMTP id b1mr28144pld.153.1503701829686; Fri, 25 Aug 2017 15:57:09 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id 3sm14192761pfj.92.2017.08.25.15.57.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Aug 2017 15:57:08 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Kevin Brodsky , Will Deacon , Daniel Mentz , Chris Wilson Subject: [RFC][PATCH] time: Fix ktime_get_raw() issues caused by incorrect base accumulation Date: Fri, 25 Aug 2017 15:57:04 -0700 Message-Id: <1503701824-1645-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <150366841319.27971.6041120504203143444@mail.alporthouse.com> References: <150366841319.27971.6041120504203143444@mail.alporthouse.com> In commit fc6eead7c1e2 ("time: Clean up CLOCK_MONOTONIC_RAW time handling"), I mistakenly added the following: /* Update the monotonic raw base */ seconds = tk->raw_sec; nsec = (u32)(tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift); tk->tkr_raw.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); Which adds the raw_sec value and the shifted down raw xtime_nsec to the base value. This is problematic as when calling ktime_get_raw(), we add the tk->tkr_raw.xtime_nsec and current offset, shift it down and add it to the raw base. This results in the shifted down tk->tkr_raw.xtime_nsec being added twice. My mistake, was that I was matching the monotonic base logic above: seconds = (u64)(tk->xtime_sec + tk->wall_to_monotonic.tv_sec); nsec = (u32) tk->wall_to_monotonic.tv_nsec; tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); Which adds the wall_to_monotonic.tv_nsec value, but not the tk->tkr_mono.xtime_nsec value to the base. The result of this is that ktime_get_raw() users (which are all internal users) see the raw time move faster then it should (the rate at which can vary with the current size of tkr_raw.xtime_nsec), which has resulted in at least problems with graphics rendering performance. To fix this, we simplify the tkr_raw.base accumulation to only accumulate the raw_sec portion, and do not include the tkr_raw.xtime_nsec portion, which will be added at read time. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Kevin Brodsky Cc: Will Deacon Cc: Daniel Mentz Cc: Chris Wilson Reported-by: Chris Wilson Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.7.4 Tested-by: Chris Wilson diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index cedafa0..7e7e61c 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -637,9 +637,7 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) tk->ktime_sec = seconds; /* Update the monotonic raw base */ - seconds = tk->raw_sec; - nsec = (u32)(tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift); - tk->tkr_raw.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); + tk->tkr_raw.base = ns_to_ktime(tk->raw_sec * NSEC_PER_SEC); } /* must hold timekeeper_lock */