From patchwork Mon Nov 6 21:02:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10044509 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 D3AA9604D3 for ; Mon, 6 Nov 2017 21:07:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CA82A01A for ; Mon, 6 Nov 2017 21:07:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C250B2A02C; Mon, 6 Nov 2017 21:07:20 +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=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 A6BB42A01A for ; Mon, 6 Nov 2017 21:06:30 +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=BfCfNdiJMZKX/Z6R2PGmIV0ZTiAuDXVakrIGcOOaVDg=; b=qr1 99uv1UEwL6WPu+hwaEXm1aqt2Fu+On3iMjAcq19C+7tu/F5YMTdgjWTpOHoFkkM0cyPgQLOmLMJcu vS9igeTnD4zHHVEhuTUttQtdIgu+Nk7l3+rp3FsrPhbHp8IfTmndJHZqPP9XCG0923U2RK/vuPnsU KBhM8qyKTI1Rg5ah6pqmbX92tJ2QH2ULEWTR3z8/ZTACZCuFuQaRcRtQaQzfU0CdTqlfjXIw/BUkG QfRJVW9XoyNJtIGBVneNJ7vs6dQxYnaSMpUx++wXYp3ShEidX4ZA5U2rkxi+SUge9Hbqyfj41OBJH vPoHQhu65Tk+vFJnWBZoKU5ffaxdRbQ==; 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 1eBobC-0005cN-Gk; Mon, 06 Nov 2017 21:06:26 +0000 Received: from mail-it0-f65.google.com ([209.85.214.65]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eBoXU-0001jW-G5 for linux-arm-kernel@lists.infradead.org; Mon, 06 Nov 2017 21:03:10 +0000 Received: by mail-it0-f65.google.com with SMTP id n195so4806773itg.1 for ; Mon, 06 Nov 2017 13:02:16 -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=jzYxCHG9+m0xjx80Y8pJZZfvQ/kNwS7ruHPuY9RaAQE=; b=DHJeuEjsZ+s8V5r5Q/gWGnnkh02pspiHKSXmng5yHtrU+g1lhgNvRxhYb+fgjsgmK0 67QBUJvzk2xmWPPTcDQJn3Yt/KtK94w4ciouX3/czrGIS0RmdNADuUCgKPFi6gLys8jk asjgTA5GdY2QRrJd6XpFaHSqxkhqNY6YEn6RkU2dd/8JCMNyeb5hkWsIyATvhgvelIGo YiwsSuN9FSulaZbxqX/B39HqdPP0UvaqtY49D+YdEirDN8GAeiKK9Z7EHueDZ6fWT7yh i0L39sTisPnZtDhoaN3p1gRLRxesdG2HLuWNWmnkt9b01+fpRMzg1AnLuPTUfVD0iOXq /fPA== 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=jzYxCHG9+m0xjx80Y8pJZZfvQ/kNwS7ruHPuY9RaAQE=; b=t6ctd/XKmNyBuZxedYKjRQ8DbHn+pIm9Y1fyhNO3DsNGfxCFwPqkCIzWSW3TYwuopR XUlxP5Kq38+OwsnTffIA/mM/Id+EjEnor57gDZ2q1LUFcdAlkbQ4zrFehQmbAaUK8pst JqABhX6LaPkY18XDiBQdIXXnxYyYnR3NAC6JXwZpCEinHIpSbiuXh8ZH6U49o/M8k/u0 JRh/FoWVLUBHVH0aaQYavRH4GrS8HYkrnqjrTlVzRQC1B3GX+84PDl1ps4joM7CTJo66 8eCnACpnN3RSn5OUkc/YRofgzT9mo0YUH7Aox9tOxrzVWxqj2mJImj/K6CZiwmnu0yTx mw5g== X-Gm-Message-State: AJaThX7FLXgQcMoT88/I7tJm89xYWXsMy+WaEACsOqLx1DjISWRgQx5a dZbNBtcETKaBSiV9VWXL8bbHoA== X-Google-Smtp-Source: ABhQp+TCqbYxCeMna7MxOhCS24MAXfwD6bv5cmd6ismlGtbW9rniC5rvGKHnAqRnSyqjeReEmWzRTQ== X-Received: by 10.36.173.71 with SMTP id a7mr11440042itj.45.1510002135319; Mon, 06 Nov 2017 13:02:15 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id i33sm6125661ioo.64.2017.11.06.13.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Nov 2017 13:02:14 -0800 (PST) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v5 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Date: Mon, 6 Nov 2017 13:02:05 -0800 Message-Id: <20171106210211.94955-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.403.gc27cc4dac6-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171106_130237_084564_5374B549 X-CRM114-Status: GOOD ( 17.59 ) 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 --- arch/arm/include/asm/vdso_datapage.h | 11 +++++++++ arch/arm/kernel/vdso.c | 5 ++++ arch/arm/vdso/vgettimeofday.c | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 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..b7c93fce2f59 100644 --- a/arch/arm/kernel/vdso.c +++ b/arch/arm/kernel/vdso.c @@ -335,9 +335,14 @@ 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_time.tv_sec; + vdso_data->raw_time_nsec = (tk->raw_time.tv_nsec << + tk->tkr_raw.shift) + + 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; }