From patchwork Wed Jun 21 05:21:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 106041 Delivered-To: patches@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1753649qgd; Tue, 20 Jun 2017 22:21:45 -0700 (PDT) X-Received: by 10.84.132.73 with SMTP id 67mr6371302ple.53.1498022505137; Tue, 20 Jun 2017 22:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498022505; cv=none; d=google.com; s=arc-20160816; b=ypApkut1EAcQ5zzKCNaHfbTmTBv57Kca8MdnXa08GlWc7VWOZ05NETg2BYrMclyoW7 OhtQlpScP4cb8Nnty5Js4+4Aist71owk5HIq+215OWc0w7HxDEOUd6iUszx8YFXEvIvt VORd5aUss3aEo0DQuSLVd2jeBaBcrQgnFmtYfXO+hYR2RHjl2ksiFJlLfvAny5V7BrkC B9qgb5rFEIFExkaMxKq2ThhgwPxvaJFzVojSMvuvEfFM0gjgo+oBfuFxSF6yu99Mjm40 kmy6V17uhoa895HujQYD7y9gtkpIIByxF7r5MUIS3tVG7XNhKpgh9nJt3AbjtyiY/tgd 2xcQ== 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=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=PwJfTC+HeqWgMm1jTDXQRiZFTg2BQzxv6zP39mHe3iLaDFeEztsL13fMKevkD1EPJO DMxDQg91gcwRvFqHZDyNIcpuafosiVnhKfqN38FTzN3U0XECv1lT4Sf4UlFFD+o6jtTF qPJM0VLDzQ51J+OoEfjSGXxb7WLMZshNQeCwrjlLKW2BsQbzFIhY0Fhd2xMnJih/0HRZ H79uPZoAeMUAQRQZ/eGXTjsQ+t6dmUGLu2wuXCmbCoKK08NbHw0SlMgWgvoagK1gl+fv 2p5wVy4hmIyqbSKX9/pEmWr0gjLKzp4XI6FZkhtu8BxLwOBW53DZG0KbDItyt+HNVG3v 2IQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=WkG4llf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b 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-pg0-x22b.google.com (mail-pg0-x22b.google.com. [2607:f8b0:400e:c05::22b]) by mx.google.com with ESMTPS id 2si11930696pfn.239.2017.06.20.22.21.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 22:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b as permitted sender) client-ip=2607:f8b0:400e:c05::22b; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=WkG4llf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22b.google.com with SMTP id f185so72581019pgc.0 for ; Tue, 20 Jun 2017 22:21:44 -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=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=WkG4llf6HkfjxzFZjwp3Tob1LqIKav3qBV7kbafEs6KjFsOgSGEBRvvkMIzSiExM7w FJziQWuj/C36p7EuGc9IclF2Z6AxyRgDibgmzkBNovUSH0a5yDiA7DiRvmAa0vR+Ru5I +mhx6+eskUEdL3Il9Le+hL8haHz+QExf2HXxk= 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=uMrpus7aNZATE+EKxuGLQ4WCLeLJIhHMnC+P+40H5pQ=; b=UuZ9XCwuL57IG6McE1B2xkRf4OJTZTg0LkH24OGmEtWu1jtjrC7G/CmDQkcs/RX9T8 9Klvs0ELc3RFa7Hf9UWUXmWsmUsR+WwKQ/agOrwRd8PCbBEz/vURSdMFUZb+x6ybOsjY LoSsauZD5uNNKcmRky+5reXnGHjMffiW8+X95xPA9LtZbQS8dHbLiOw7b9jV0/oWJlim LpgTl29pkIW4gsQcU2wrlSwJ5xNpe3mix+lFC6bKZyiwAqivZuo4OrYHK8huC7+3eS8u Nmnxwtrna6dN0XJrhFPDY4EhEjm7bj0KYRMD2PyglIVqIjrSnAv7nvvdgLYdfM9Om/bQ hDNw== X-Gm-Message-State: AKS2vOyuSb077GavAG1BDPiUGbKr/JSqWXvrbYpByDO3M0rAIRKfP51m /jGKkKdDRmCbxxUpJfY= X-Received: by 10.99.108.193 with SMTP id h184mr35774753pgc.166.1498022504757; Tue, 20 Jun 2017 22:21:44 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id a69sm30405992pfg.91.2017.06.20.22.21.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 22:21:43 -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 Subject: [PATCH 1/4] time: Clean up CLOCK_MONOTONIC_RAW time handling Date: Tue, 20 Jun 2017 22:21:30 -0700 Message-Id: <1498022493-20292-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> References: <1498022493-20292-1-git-send-email-john.stultz@linaro.org> Now that we fixed the sub-ns handling for CLOCK_MONOTONIC_RAW, remove the duplicitive tk->raw_time.tv_nsec, which can be stored in tk->tkr_raw.xtime_nsec (similarly to how its handled for monotonic 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 Tested-by: Daniel Mentz Signed-off-by: John Stultz --- arch/arm64/kernel/vdso.c | 6 ++--- include/linux/timekeeper_internal.h | 4 ++-- kernel/time/timekeeping.c | 45 ++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 26 deletions(-) -- 2.7.4 Acked-by: Will Deacon diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index d0cb007..7492d90 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -220,10 +220,8 @@ void update_vsyscall(struct timekeeper *tk) if (!use_syscall) { /* tkr_mono.cycle_last == tkr_raw.cycle_last */ vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; - vdso_data->raw_time_sec = tk->raw_time.tv_sec; - vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec << - tk->tkr_raw.shift) + - tk->tkr_raw.xtime_nsec; + vdso_data->raw_time_sec = tk->raw_sec; + vdso_data->raw_time_nsec = tk->tkr_raw.xtime_nsec; vdso_data->xtime_clock_sec = tk->xtime_sec; vdso_data->xtime_clock_nsec = tk->tkr_mono.xtime_nsec; vdso_data->cs_mono_mult = tk->tkr_mono.mult; diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper_internal.h index f7043cc..0a0a53d 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -51,7 +51,7 @@ struct tk_read_base { * @clock_was_set_seq: The sequence number of clock was set events * @cs_was_changed_seq: The sequence number of clocksource change events * @next_leap_ktime: CLOCK_MONOTONIC time value of a pending leap-second - * @raw_time: Monotonic raw base time in timespec64 format + * @raw_sec: CLOCK_MONOTONIC_RAW time in seconds * @cycle_interval: Number of clock cycles in one NTP interval * @xtime_interval: Number of clock shifted nano seconds in one NTP * interval. @@ -93,7 +93,7 @@ struct timekeeper { unsigned int clock_was_set_seq; u8 cs_was_changed_seq; ktime_t next_leap_ktime; - struct timespec64 raw_time; + u64 raw_sec; /* The following members are for timekeeping internal use */ u64 cycle_interval; diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index b602c48..0454bfa 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -72,6 +72,10 @@ static inline void tk_normalize_xtime(struct timekeeper *tk) tk->tkr_mono.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_mono.shift; tk->xtime_sec++; } + while (tk->tkr_raw.xtime_nsec >= ((u64)NSEC_PER_SEC << tk->tkr_raw.shift)) { + tk->tkr_raw.xtime_nsec -= (u64)NSEC_PER_SEC << tk->tkr_raw.shift; + tk->raw_sec++; + } } static inline struct timespec64 tk_xtime(struct timekeeper *tk) @@ -285,12 +289,14 @@ static void tk_setup_internals(struct timekeeper *tk, struct clocksource *clock) /* if changing clocks, convert xtime_nsec shift units */ if (old_clock) { int shift_change = clock->shift - old_clock->shift; - if (shift_change < 0) + if (shift_change < 0) { tk->tkr_mono.xtime_nsec >>= -shift_change; - else + tk->tkr_raw.xtime_nsec >>= -shift_change; + } else { tk->tkr_mono.xtime_nsec <<= shift_change; + tk->tkr_raw.xtime_nsec <<= shift_change; + } } - tk->tkr_raw.xtime_nsec = 0; tk->tkr_mono.shift = clock->shift; tk->tkr_raw.shift = clock->shift; @@ -619,9 +625,6 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) nsec = (u32) tk->wall_to_monotonic.tv_nsec; tk->tkr_mono.base = ns_to_ktime(seconds * NSEC_PER_SEC + nsec); - /* Update the monotonic raw base */ - tk->tkr_raw.base = timespec64_to_ktime(tk->raw_time); - /* * The sum of the nanoseconds portions of xtime and * wall_to_monotonic can be greater/equal one second. Take @@ -631,6 +634,11 @@ static inline void tk_update_ktime_data(struct timekeeper *tk) if (nsec >= NSEC_PER_SEC) seconds++; 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); } /* must hold timekeeper_lock */ @@ -672,7 +680,6 @@ static void timekeeping_update(struct timekeeper *tk, unsigned int action) static void timekeeping_forward_now(struct timekeeper *tk) { u64 cycle_now, delta; - u64 nsec; cycle_now = tk_clock_read(&tk->tkr_mono); delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, tk->tkr_mono.mask); @@ -684,10 +691,13 @@ static void timekeeping_forward_now(struct timekeeper *tk) /* If arch requires, add in get_arch_timeoffset() */ tk->tkr_mono.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_mono.shift; - tk_normalize_xtime(tk); - nsec = clocksource_cyc2ns(delta, tk->tkr_raw.mult, tk->tkr_raw.shift); - timespec64_add_ns(&tk->raw_time, nsec); + tk->tkr_raw.xtime_nsec += delta * tk->tkr_raw.mult; + + /* If arch requires, add in get_arch_timeoffset() */ + tk->tkr_raw.xtime_nsec += (u64)arch_gettimeoffset() << tk->tkr_raw.shift; + + tk_normalize_xtime(tk); } /** @@ -1373,19 +1383,18 @@ int timekeeping_notify(struct clocksource *clock) void getrawmonotonic64(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; - struct timespec64 ts64; unsigned long seq; u64 nsecs; do { seq = read_seqcount_begin(&tk_core.seq); + ts->tv_sec = tk->raw_sec; nsecs = timekeeping_get_ns(&tk->tkr_raw); - ts64 = tk->raw_time; } while (read_seqcount_retry(&tk_core.seq, seq)); - timespec64_add_ns(&ts64, nsecs); - *ts = ts64; + ts->tv_nsec = 0; + timespec64_add_ns(ts, nsecs); } EXPORT_SYMBOL(getrawmonotonic64); @@ -1509,8 +1518,7 @@ void __init timekeeping_init(void) tk_setup_internals(tk, clock); tk_set_xtime(tk, &now); - tk->raw_time.tv_sec = 0; - tk->raw_time.tv_nsec = 0; + tk->raw_sec = 0; if (boot.tv_sec == 0 && boot.tv_nsec == 0) boot = tk_xtime(tk); @@ -2011,15 +2019,12 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, *clock_set |= accumulate_nsecs_to_secs(tk); /* Accumulate raw time */ - tk->tkr_raw.xtime_nsec += (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; tk->tkr_raw.xtime_nsec += tk->raw_interval << shift; snsec_per_sec = (u64)NSEC_PER_SEC << tk->tkr_raw.shift; while (tk->tkr_raw.xtime_nsec >= snsec_per_sec) { tk->tkr_raw.xtime_nsec -= snsec_per_sec; - tk->raw_time.tv_sec++; + tk->raw_sec++; } - tk->raw_time.tv_nsec = tk->tkr_raw.xtime_nsec >> tk->tkr_raw.shift; - tk->tkr_raw.xtime_nsec -= (u64)tk->raw_time.tv_nsec << tk->tkr_raw.shift; /* Accumulate error between NTP and clock interval */ tk->ntp_error += tk->ntp_tick << shift;