From patchwork Tue Oct 31 18:31: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: 10035191 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 8A5DF60327 for ; Tue, 31 Oct 2017 18:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A91522F3E for ; Tue, 31 Oct 2017 18:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CA5925404; Tue, 31 Oct 2017 18:49:30 +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 CFEDD22F3E for ; Tue, 31 Oct 2017 18:49:29 +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=DwoI4+qmT+vfr2pVdg2CwwsZhjZrkCF8lt/8MOjA1Do=; b=O7S ecnYVh/QkDjYZpWjbARBpFMtxtBeOefW7unjtqKlvvW9D/b6RgZj6uXKJfWOohiGDxSvYIDrOyq+Y gsI2FMa4UHxEEIcRoG4LJzQl9A6ColTFttKAUE2YaqX9lMef101b6rbkNCDV1k+az5clkHQPopkNN QoV+OsYcp8ZzOepd6ms2c4cb8URGPwL+lVBYVEJjihE5p/mzSPX3hDRlJaIIebO00IjNHQij3rC1P PnBptjnOvlKYxJCfvPV0dToTiNujRZSjBtynH+Y+d2es2ttdzDBj7dSMiYFpJulZlGOoYob5RvsLa 5T/QF6B4KUhj+U2zZC+7mGDys4HYnlQ==; 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 1e9bb3-00016W-VD; Tue, 31 Oct 2017 18:49:09 +0000 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e9bKX-000642-Mk for linux-arm-kernel@lists.infradead.org; Tue, 31 Oct 2017 18:32:38 +0000 Received: by mail-io0-x241.google.com with SMTP id j17so866689iod.5 for ; Tue, 31 Oct 2017 11:31:45 -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=/HndcBd1y+du6XoDw5g3xbcICJp/46/59o+QSDsY2Ds=; b=IItFyQXo99SEKbLhjXyW5p9hlRrLmwxYIEQI5WtbuRkh1wlImMw6KlaKTOy1s8WL3c FQoB7zGbBMTFS7AREgCEjB7wZdtCd7NEwEnq7UeJETP7ikshZP4HqzxOUEgThmiWDf2k PSL24B+VOoHLaKNAscsf214IcRKCChpy5NCNzkaY834RwVV9YtHU5FWGQOnrza37J23w Bbu2eylIM16GG3SxkZ2eKe9mzTAiSDn5bJMkhjHaCRnzDbLwdHu4Nl1/niu9VHRe1woz zWlUKK+RSaedLhHREfVVPWkz9L1Qnm183MnODOqcVr3ssw6KWglNS0kjZt9tFkhwFbFQ QVdA== 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=/HndcBd1y+du6XoDw5g3xbcICJp/46/59o+QSDsY2Ds=; b=E5dAK97xRn1QTJrFLiZ6FQ87YxrjbrZ167I0dACLptJBAw8qizhH+xsfIATm0wqG/X SnGwG1fsmviqipMTezSycElu8utyD8ZiUAWFBHpHcEWPhT46G79gdGPSoxlrLqY4bihz B4chb3U9K4ZGEsS3psm/spxQDo7Qfc9VrijroyoL03gcysRdVEBj6tyRoCefgklszW6K LUzBjDla0+g5DpF7jSRqt+D2Xo7LDIqL+ZSRI0J5C2PsiPbHWJPgky+HqXrJxb1KIcRJ Yz7uhXHg6D53yzzVj16Q9/J4DORLRmEd+1v6FICs0fbk9TaXQPgjcIrNl1NJoXHqEa/L ALIw== X-Gm-Message-State: AMCzsaXQ9lM/QmVCq8X3l71hEUqJaOQxnKlT/hOebGrxs8S9Klr75gOt dsJpv8FDsaCWeoKCIvZuTikX3w== X-Google-Smtp-Source: ABhQp+Tc4naDNtnCbBV2PpxhFziERvuSL5qbMhM7RDBRCpLXnpMNxE4CJpQoVJF+BW4beDUAxXtAWw== X-Received: by 10.36.50.140 with SMTP id j134mr4333366ita.98.1509474705046; Tue, 31 Oct 2017 11:31:45 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id k86sm984624ioi.23.2017.10.31.11.31.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Oct 2017 11:31:44 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v4 05/12] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Date: Tue, 31 Oct 2017 11:31:36 -0700 Message-Id: <20171031183141.81075-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.rc2.357.g7e34df9404-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171031_113206_781356_0BFEC836 X-CRM114-Status: GOOD ( 17.79 ) 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. - remove forced inline. --- 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..7377638a3b00 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->raw_time.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 3ae96d236e48..2b9fce92904e 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -189,6 +189,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) @@ -201,6 +235,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) @@ -222,6 +262,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; }