From patchwork Mon Jun 18 15:05:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10472155 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 13C2760532 for ; Mon, 18 Jun 2018 15:49:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01D75289DF for ; Mon, 18 Jun 2018 15:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7931289FA; Mon, 18 Jun 2018 15:49:08 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 52F7F289DF for ; Mon, 18 Jun 2018 15:49:08 +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:References: In-Reply-To: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:List-Owner; bh=FiZ5Q2zojyypzA5fpuCCV6EM6FkL5y+KR2daAwrPeHc=; b=U92kweYOZSY/NE1n5KKeQJRka6 +43HhyWhPjozxDqQkseQ4+dw9KaDVjyhcawu25FEpjj+OvHuKD6MR45mqhtisHZjQF5fG16q7fjj1 wEVWy4gRez6gmw3obyk+XuawhM5YIBJektdbtIXf9+8shyMYlXflbelt5dpPyKri14F6quqVQ4pNO fLcQb+CC1d8eOrQ32Hu2PCyIr+iY176wFeHEahpUde3haIphmcYCSPmBZCKxJIaaIsM/NLTr1SVj8 gxMmt2C2vUp0+j6X00MoXsu7Lux3O5pAMPp2g+aq08R81UxKWEhPM/hPhLIoOXXT4pw/nlnOflHJk ly11WuUA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUwOl-0001gn-84; Mon, 18 Jun 2018 15:48:55 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUvvv-0000OV-Ni for linux-arm-kernel@bombadil.infradead.org; Mon, 18 Jun 2018 15:19:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=EZFagnmCmPK0jrqUJhwS419qQ/3Q5gFAyyKlvnDaAhc=; b=YB96OQwFmNWTXBbWNyoKucCDX 2+XxBRDcUJ0KJ9Y05cMVw9JIiGSYCbPsbsIVaTF9ZzL3LBlgvI3ffLtK1rvLVF6IV0i7kBdPewD/p 5KWfY83YHc37uGfRpNGwMR9nTTp3gEWfIA+XQc+tDxcGL6wZeg+gyDEf5qLtwsLlo+ZqPRyhvSaIC 3QTxblfxf06PQJHFM7NmbnUHQ9DyEbCTGYwQs9EJZIafoRvq4595taDa3uJ9D3ZH6c3OeqHIILBGB bz4iU8aQN2HbyvzZNR8n0fPUHBiRuLm2OoVte/600pwtKmkyi5ryekaFuPeWAIvviTtu+oVszo30Z IQfVoXkdw==; Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUvkd-0000CN-0h for linux-arm-kernel@lists.infradead.org; Mon, 18 Jun 2018 15:07:27 +0000 Received: by mail-pf0-x244.google.com with SMTP id b74-v6so8319768pfl.5 for ; Mon, 18 Jun 2018 08:07:16 -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:in-reply-to:references; bh=EZFagnmCmPK0jrqUJhwS419qQ/3Q5gFAyyKlvnDaAhc=; b=MLCQr/BQaCnVGuJPlPTrde1inIyPbrwSQSqChFmPikEz6AsmTtrKv32TL/DFiNpgQB m5IRvqo2kfgJK13x3vjfBzppMv9HFTa53DDZeQoDTfDUzXylEj/f24F/oqnV39xkKxh7 qS4b3+xY94Etbi7Ky1Io4IdtOp3MmSQ2zSoVANkLUjI/70+hFpKR+qCHlrd1TFVi/dE8 m7QmHhPuF/rryS0HSziAV7pd4GrI/tG8NT4qHebfF5vn1ZMMiceBvHP7N5y5vdqszatk 60C80ix/21EbOmtcRITV9QnwTzyKR5bT3cXSe66FsQ/B9FA1P+h7p4m8cDOvZQKfMHth 4koQ== 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=EZFagnmCmPK0jrqUJhwS419qQ/3Q5gFAyyKlvnDaAhc=; b=fLdpKh8x13yQW5cdq99F60GqrGr09okh4bDnT4qROCxSZUmoIdZ7bCnJDER1AnpnUQ lPaJEkdphJIGYlV9aBU1yHYqT8NDfRCUKlHhvExIPUdalydRmnd6GB7MbByE3O1zyLAL BkgDik5dQ7wgt7WOVJCyk7K1Ipaqizj0BTjFiwUNvm7Gq3RqCIVrQ8MFjge4+oaKZoCH 1fdRxZg2n2UhVeFiD6nwYPI9ygdp/RCuxjIpN6ce7s6SOIbnzJ/1KKfggCmS/JIjxDgQ CVgDJ9Qmgxsx5huYznL62pdddllDlYIye6KBayObTM4UqF0WOM25sdLuurPfbj8Zm+0z AjEw== X-Gm-Message-State: APt69E31+pLQbjD7H6lJj7k5jQnWORLcHxQ50P5EjCfyKhraDsXB1G7X UQKZhP3WHqkd9Y9iYZrX+A196w== X-Google-Smtp-Source: ADUXVKIWYc11sW82eHt+xorGYHDiwUO9A1AjDU7VsVX2ugiQ+izmbEIMJymxw5oxwdGAQnbRGYwMrA== X-Received: by 2002:a62:8f8c:: with SMTP id n134-v6mr14052821pfd.66.1529334434735; Mon, 18 Jun 2018 08:07:14 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:0:1000:1611:6077:8eec:bc7e:d0f4]) by smtp.gmail.com with ESMTPSA id i7-v6sm54830660pfa.34.2018.06.18.08.07.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 08:07:14 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: RESEND [PATCH v6 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Date: Mon, 18 Jun 2018 08:05:51 -0700 Message-Id: <20180618150613.10322-6-salyzyn@android.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180618150613.10322-1-salyzyn@android.com> References: <20180618150613.10322-1-salyzyn@android.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180618_110727_102024_DC8C7B0D X-CRM114-Status: GOOD ( 23.35 ) 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 , "Paul E. McKenney" , Catalin Marinas , Kevin Brodsky , Will Deacon , Russell King , Jeremy Linton , Andy Lutomirski , Jinbum Park , James Morse , Andrew Pinski , Dmitry Safonov , Andy Gross , John Stultz , Thomas Gleixner , Mark Salyzyn , Ingo Molnar , 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 Cc: Jeremy Linton 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 c2c57f6b8c60..9c13a32fa5f0 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -337,9 +337,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; }