From patchwork Thu Nov 9 23:39:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10052099 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 613A56032D for ; Thu, 9 Nov 2017 23:40:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52DA72B1CE for ; Thu, 9 Nov 2017 23:40:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 472D72B1D7; Thu, 9 Nov 2017 23:40:49 +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 C75DA2B1CE for ; Thu, 9 Nov 2017 23:40:48 +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=a6xjaIyibMNjw0uLlpZu26w7aiYBuHrNC6AkXcSrLzY=; b=Sem miRSx1l4Nro+hsTvz9ZSFFkpbB1WQNNe8mrznfMHF3gtASuo0H6Wf21N4HOyKSZLBq1YtlmvkikHD muN2QoHn1i3cHftETeG1EUtu/iXFMg/dSfuolINPSYzHgkyvkiAqqX/ox7Idh5LHWn63qnhYMMUoL 4yM4+MJU+VSp9H6fi1/e+o0j5l4fPexsN5osWwh0ub5JJ1ql3vcL/5a4dMB7mNDjmjVqFOK1giDhB y6FEE281Li7rQK9cdt3BicVghmEYJrLAFmBU+eHDahuxijN0FCnqjdw24+TDwyI+llNT9n4Vw/hIs spKOWNbYI4md4ONqyhWoitIhCHLps9Q==; 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 1eCwR8-0007ul-MJ; Thu, 09 Nov 2017 23:40:42 +0000 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eCwR5-0007sZ-3G for linux-arm-kernel@lists.infradead.org; Thu, 09 Nov 2017 23:40:41 +0000 Received: by mail-io0-x244.google.com with SMTP id 97so11694537iok.7 for ; Thu, 09 Nov 2017 15:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5p4ZmeHSQT+s9/WsK3eborIsiNJQWWrG2hYgTJ18dUs=; b=uvNb0aCYBZwW8VP2ay4F2A4M8qhQd16ZaJZKloRDE/KpSu4eXhbOd5E8PS8iuOUR60 jpb664Zw0uZawdID6SFrVDJVz/YPWgZa0QHGs1VEyMmU6Nmz5/q+MLlelu5ySXxCl/Ov DbEBkxUEFi5yro+1rL6EBzFGu4WP7sFUEEzjJBqtagAFLA5A1GXkBi9hy+QgCg2ogaT0 pKqB80ixRjjKYk7CM45w+d5r8hwh0uKfJ6DMVoDGvQE1lq2lDI4tRQeCyMkK7Rj76ga4 pcOuWRCx9EnTHRwRpqHpL7W6r3xoXTy4ic2MhCSM7S7Vz/PAVzWUNQsup4ehpBhfkuK+ C0ow== 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=5p4ZmeHSQT+s9/WsK3eborIsiNJQWWrG2hYgTJ18dUs=; b=cUaMg57S0KA3FsFgHDt1Jj3Rv6VX4FlC4wOTZ6WyOqzavfNTFYMlw/6YHWOLrIn8su 5qpnmbbURkkP67g7hFHMR39INPmkE7siptd9jRmgfAxVpjfzzGBmitZISdUz8EHdH+BU mqcEtUEm+fJKPHnsUQrjjKhqL9Vi9z8s8JPcP8DsUdDuhvqCi6YfKB4XwOYEt7CZiiaH HyPqV8uPPyzyluE8Vn5ziPkbt14KkDOc7KTaRUDt7GdespdHTG3jaxKP1l77JWfe6iy2 2E3J9vQ6aKwWeXLrcmgt5cQTSqSBlZ3pt57qOB8ytDMj8o0iK79dk6pnIWdDPVlMaK9F hO4Q== X-Gm-Message-State: AJaThX7ldVFUPVMNoMUAjihR1E8lNOpA8HBrlf64uo36bBEkVblKt5QL xRoTMdBSfKzdN7x5tuQgMEXMAg== X-Google-Smtp-Source: ABhQp+SPX0afA/3dwqN6G2Md4pnaIh9HFxrfaq1Le4DJG+MBAYrSNK0sBmCNvkI48vyO7NVoupErmw== X-Received: by 10.107.56.68 with SMTP id f65mr2782285ioa.159.1510270816532; Thu, 09 Nov 2017 15:40:16 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id s81sm63002ita.19.2017.11.09.15.40.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 15:40:16 -0800 (PST) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v6 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Date: Thu, 9 Nov 2017 15:39:50 -0800 Message-Id: <20171109234010.31286-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171109_154039_195231_02AD65CB X-CRM114-Status: GOOD ( 17.64 ) 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 , Laura Abbott , Kees Cook , Ard Biesheuvel , Catalin Marinas , Kevin Brodsky , Will Deacon , Russell King , Andy Lutomirski , James Morse , Andrew Pinski , Dmitry Safonov , Andy Gross , John Stultz , Thomas Gleixner , Mark Salyzyn , linux-arm-kernel@lists.infradead.org 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 Take an effort to recode the arm64 vdso code from assembler to C previously submitted by Andrew Pinski , rework it for use in both arm and arm64, overlapping any optimizations for each architecture. But instead of landing it in arm64, land the result into lib/vdso and unify both implementations to simplify future maintenance. Add a case for CLOCK_MONOTONIC_RAW to match up with support that is available in arm64's vdso. Signed-off-by: Mark Salyzyn Cc: James Morse Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Andy Lutomirski Cc: Dmitry Safonov Cc: John Stultz Cc: Mark Rutland Cc: Laura Abbott Cc: Kees Cook Cc: Ard Biesheuvel Cc: Andy Gross Cc: Kevin Brodsky Cc: Andrew Pinski Cc: Thomas Gleixner Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org v2: - split first CL into 6 of 7 pieces v4: - Move out ARCH_CLOCK_FIXED_MASK to later adjustment. - update commit message to reflect overall reasoning. - replace typeof() with type vdso_raw_time_sec_t. v5: - replace erroneous tk->raw_time.shift with tk->tkr_raw.shift v6: - fixup raw_time_sec and raw_time_nsec in vdso.c --- arch/arm/include/asm/vdso_datapage.h | 11 +++++++++ arch/arm/kernel/vdso.c | 3 +++ arch/arm/vdso/vgettimeofday.c | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h index 8dd7303db4ec..1c6e6a5d5d9d 100644 --- a/arch/arm/include/asm/vdso_datapage.h +++ b/arch/arm/include/asm/vdso_datapage.h @@ -34,6 +34,11 @@ typedef u32 vdso_wtm_clock_nsec_t; typedef u32 vdso_xtime_clock_sec_t; #endif +#ifndef _VDSO_RAW_TIME_SEC_T +#define _VDSO_RAW_TIME_SEC_T +typedef u32 vdso_raw_time_sec_t; +#endif + /* Try to be cache-friendly on systems that don't implement the * generic timer: fit the unconditionally updated fields in the first * 32 bytes. @@ -58,6 +63,12 @@ struct vdso_data { u64 xtime_clock_snsec; /* CLOCK_REALTIME sub-ns base */ u32 tz_minuteswest; /* timezone info for gettimeofday(2) */ u32 tz_dsttime; + + /* Raw clocksource multipler */ + u32 cs_raw_mult; + /* Raw time */ + vdso_raw_time_sec_t raw_time_sec; + u32 raw_time_nsec; }; union vdso_data_store { diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c index aed84b659cc5..898420579ae9 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -335,9 +335,12 @@ void update_vsyscall(struct timekeeper *tk) if (!vdso_data->use_syscall) { vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last; + 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_snsec = tk->tkr_mono.xtime_nsec; vdso_data->cs_mono_mult = tk->tkr_mono.mult; + 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->cs_mask = tk->tkr_mono.mask; diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c index 59893fca03b3..a2c4db83edc4 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -194,6 +194,40 @@ static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) return 0; } +static notrace int do_monotonic_raw(const struct vdso_data *vd, + struct timespec *ts) +{ + u32 seq, mult, shift; + u64 nsec, cycle_last; + u64 mask; + vdso_raw_time_sec_t sec; + + do { + seq = vdso_read_begin(vd); + + if (vd->use_syscall) + return -1; + + cycle_last = vd->cs_cycle_last; + + mult = vd->cs_raw_mult; + shift = vd->cs_shift; + mask = vd->cs_mask; + + sec = vd->raw_time_sec; + nsec = vd->raw_time_nsec; + + } while (unlikely(vdso_read_retry(vd, seq))); + + nsec += get_clock_shifted_nsec(cycle_last, mult, mask); + nsec >>= shift; + /* open coding timespec_add_ns to save a ts->tv_nsec = 0 */ + 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, struct timespec *ts) @@ -206,6 +240,12 @@ static notrace int do_monotonic(const struct vdso_data *vd, struct timespec *ts) return -1; } +static notrace int do_monotonic_raw(const struct vdso_data *vd, + struct timespec *ts) +{ + return -1; +} + #endif /* CONFIG_ARM_ARCH_TIMER */ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) @@ -227,6 +267,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) if (do_monotonic(vd, ts)) goto fallback; break; + case CLOCK_MONOTONIC_RAW: + if (do_monotonic_raw(vd, ts)) + goto fallback; + break; default: goto fallback; }