From patchwork Mon Sep 11 16:19:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 9947689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E50B1602C9 for ; Mon, 11 Sep 2017 16:20:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D470128C60 for ; Mon, 11 Sep 2017 16:20:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8CEC28CBF; Mon, 11 Sep 2017 16:20:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5317E28CC4 for ; Mon, 11 Sep 2017 16:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=3LjXw+91LH9Y16eG0HpdZOForZkv/TqwBR5pAzKYrLw=; b=qkR 6Yhosd7geBzexnm+me882JcxG5KQEskGYsy1y4uifDGnJ2FbjYhYCWo54J2Qn1M2JR+Ls3pxwBXBG m20CuhciQj5xJxGw4LY0tDewACc37S5ZAZ4z4Z+G3TIIMruA3zLUU68lJgLgVOImsHknMdHLJOkZ5 yk1/Jr80XDX1kfOqxOPPBHMkQtmxvQGGn0ZgU/5bHbBvXYgchbDkNYy1GR54rrV5tKDXAYSnZXZ/c jkYMKCTwxmJs2DuTCVU5s3Tlj5B8cme8cr1QIH0VsDM0z0Lee5z/ZrFx6YueLPWTdB2m5X/LLpNei zuZxl5+AYzDrI8RF6493V/u3YzbqBdQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1drRRl-0000qP-C2; Mon, 11 Sep 2017 16:20:29 +0000 Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1drRRb-0007pv-BT for linux-arm-kernel@lists.infradead.org; Mon, 11 Sep 2017 16:20:27 +0000 Received: by mail-pg0-x234.google.com with SMTP id v66so16069769pgb.5 for ; Mon, 11 Sep 2017 09:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=So9PNO0RE2l/y1cx5gwA/AdKplPoNnFR+etpjU8RSAY=; b=XNgq20UymRCP45tSl3Mr8083FcgZcq4461DghQjeZscr//WRD6AIY2wSkLYJLUOVJp fD/qyE2wArT+G5YtPbBdn50Cgx1SikN1CDT5oiZEAQYwKtP8tWACU1cjx2Qfyl5f7k87 MMSRgF9JwuZ5p2InpjDimBpCmzRFxh05fhmLKlkTfjJ6cefciXDmxd8jW79BdKBYsm9m YyzwDjiDOKtGboyE5eGvyy+ypfL533KfBjAeXrdrPkKWpBKyHZam4Avla6YI8PPec/M1 kw8s9VNQ7w6tI7I+wfB88PF8iX9cY4FFdwJ6LOUfoYue8xrEAYjz4E0oLPem5YLF4y6Y 6rnw== 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=So9PNO0RE2l/y1cx5gwA/AdKplPoNnFR+etpjU8RSAY=; b=pzcNQiv1RBOTgAmYl8pV4fiAik6rAtf4wo1si12oibb+IfKVzrKWJd0pxGwwwTkGtt yLYTfvw6bCAA4wOgdCyFW6PHj7Be0Q0FfVIysl4odtQZtVfTTrEy6YVwF4NIuUPTaxNl RhTZ6h7yBi/dKc/a0qpl1KlT+NW7PHDXeNRjx250dMFy8rj27eEuC5Ia2shLiQvEtqu+ UZkGxI6fiyewksfaV3FQZabRMSO8CBAkm9rPXR+nSxjpRYa4MXp8rH9XVbmiT0wByg6L Ovb/twWLB+8w7jaSSuNgwMaUc/QLqqsJxME0MvRtRwaCEEDJ2GCzIsr5sEApwKHCi7cU XeUg== X-Gm-Message-State: AHPjjUiAwCYGEPUrjnhAQejE6mWeBf8RzX+WWkK1B9gPsHyn4urMxI7H ugw4/UlJPDasSOY1 X-Google-Smtp-Source: ADKCNb5DLlWMxafz0CrteOOqf821rfYbMD5EL7ugwyo6Mq4cfYz6tfU40OaZVIRCdjUwejDuQpRB6A== X-Received: by 10.84.137.169 with SMTP id 38mr14563879pln.429.1505146798431; Mon, 11 Sep 2017 09:19:58 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id f24sm16765922pfk.137.2017.09.11.09.19.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Sep 2017 09:19:57 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH 3/3] arm+arm64: vdso: Add support for CLOCK_BOOTTIME Date: Mon, 11 Sep 2017 09:19:36 -0700 Message-Id: <20170911161947.112946-1-salyzyn@android.com> X-Mailer: git-send-email 2.14.1.581.gf28d330327-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170911_092019_644464_B076BE92 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peterz@infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, Andy Lutomirski , mingo@kernel.org, zijun_hu@htc.com, jszhang@marvell.com, borntraeger@de.ibm.com, Russell King , takahiro.akashi@linaro.org, labbott@redhat.com, Dave.Martin@arm.com, Mark Salyzyn , keescook@chromium.org, Marc Zyngier , kevin.brodsky@arm.com, Scott Wood , mmarek@suse.com, john.stultz@linaro.org, linux-arm-kernel@lists.infradead.org, ard.biesheuvel@linaro.org, Dmitry Safonov , Mark Salyzyn , james.morse@arm.com, credmonster@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Mark Salyzyn --- arch/arm/include/asm/vdso_datapage.h | 1 + arch/arm/kernel/vdso.c | 1 + arch/arm/vdso/vgettimeofday.c | 56 ++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/vdso_datapage.h | 1 + arch/arm64/kernel/vdso.c | 1 + 5 files changed, 60 insertions(+) diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h index d57c296f7f52..d2c8e0807f06 100644 --- a/arch/arm/include/asm/vdso_datapage.h +++ b/arch/arm/include/asm/vdso_datapage.h @@ -47,6 +47,7 @@ struct vdso_data { u32 tz_minuteswest; /* timezone info for gettimeofday(2) */ u32 tz_dsttime; + u64 btm_nsec; /* monotonic to boot time */ u32 cs_raw_mult; /* Raw clocksource multipler */ u32 raw_time_sec; /* Raw time */ u32 raw_time_nsec; diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index 74bede343ffc..d55b2b217700 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -347,6 +347,7 @@ void update_vsyscall(struct timekeeper *tk) /* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; vdso_data->cs_mask = tk->tkr_mono.mask; + vdso_data->btm_nsec = ktime_to_ns(tk->offs_boot); } vdso_write_end(vdso_data); diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c index 786ff319aead..be65da32e838 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -209,6 +209,51 @@ static __always_inline notrace int do_monotonic_raw(const struct vdso_data *vd, return 0; } +static __always_inline notrace int do_boottime(const struct vdso_data *vd, + struct timespec *ts) +{ + u32 seq, mult, shift; + u64 nsec, cycle_last, wtm_nsec; +#ifdef ARCH_CLOCK_FIXED_MASK + static const u64 mask = ARCH_CLOCK_FIXED_MASK; +#else + u64 mask; +#endif + + typeof(ts->tv_sec) sec; + + do { + seq = vdso_read_begin(vd); + + if (vd->use_syscall) + return -1; + + cycle_last = vd->cs_cycle_last; + + mult = vd->cs_mono_mult; + shift = vd->cs_shift; +#ifndef ARCH_CLOCK_FIXED_MASK + mask = vd->cs_mask; +#endif + + sec = vd->xtime_clock_sec; + nsec = vd->xtime_clock_snsec; + + sec += vd->wtm_clock_sec; + wtm_nsec = vd->wtm_clock_nsec + vd->btm_nsec; + + } while (unlikely(vdso_read_retry(vd, seq))); + + nsec += get_clock_shifted_nsec(cycle_last, mult, mask); + nsec >>= shift; + nsec += wtm_nsec; + + ts->tv_sec = sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); + ts->tv_nsec = nsec; + + return 0; +} + #else /* CONFIG_ARM_ARCH_TIMER */ static notrace int do_realtime(const struct vdso_data *vd, @@ -229,6 +274,12 @@ static notrace int do_monotonic_raw(const struct vdso_data *vd, return -1; } +static notrace int do_boottime(const struct vdso_data *vd, + struct timespec *ts) +{ + return -1; +} + #endif /* CONFIG_ARM_ARCH_TIMER */ static notrace void do_realtime_coarse(const struct vdso_data *vd, @@ -301,6 +352,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) case CLOCK_MONOTONIC_COARSE: do_monotonic_coarse(vd, ts); break; + case CLOCK_BOOTTIME: + if (do_boottime(vd, ts)) + goto fallback; + break; default: goto fallback; } @@ -337,6 +392,7 @@ int __vdso_clock_getres(clockid_t clock_id, struct timespec *res) typeof(res->tv_nsec) nsec; if (clock_id == CLOCK_REALTIME || + clock_id == CLOCK_BOOTTIME || clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_MONOTONIC_RAW) nsec = MONOTONIC_RES_NSEC; diff --git a/arch/arm64/include/asm/vdso_datapage.h b/arch/arm64/include/asm/vdso_datapage.h index c9e30226cdbc..1e115b0f373d 100644 --- a/arch/arm64/include/asm/vdso_datapage.h +++ b/arch/arm64/include/asm/vdso_datapage.h @@ -30,6 +30,7 @@ struct vdso_data { __u64 xtime_coarse_nsec; __u64 wtm_clock_sec; /* Wall to monotonic time */ __u64 wtm_clock_nsec; + __u64 btm_nsec; /* monotonic to boot time */ __u32 tb_seq_count; /* Timebase sequence counter */ /* cs_* members must be adjacent and in this order (ldp accesses) */ __u32 cs_mono_mult; /* NTP-adjusted clocksource multiplier */ diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 59f150c25889..0710edd8bedc 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -243,6 +243,7 @@ void update_vsyscall(struct timekeeper *tk) vdso_data->cs_raw_mult = tk->tkr_raw.mult; /* tkr_mono.shift == tkr_raw.shift */ vdso_data->cs_shift = tk->tkr_mono.shift; + vdso_data->btm_nsec = ktime_to_ns(tk->offs_boot); } smp_wmb();