From patchwork Thu Oct 12 23:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 10003163 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 A872E602BF for ; Thu, 12 Oct 2017 23:01:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 973B32876B for ; Thu, 12 Oct 2017 23:01:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AF1828869; Thu, 12 Oct 2017 23:01:59 +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 2E4CA2876B for ; Thu, 12 Oct 2017 23:01:59 +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=XRc4VcE+g45HZvzj/OoFIDkMKbMJSUrBVcQCSQKXwUE=; b=nsW /8NoPqo4lXpo1ybZJOayP4HX0RFm5sVnAMK/6hmOVPJwfCwyoXfVNh0sLcd4aBA1LQFnDVhE7a2VS HZ2FtF+zLj/FytiGRoq+cJSD7XjiXwjA4c/BTiuwsd9u7LS+mcqzast8haJzgglCDkG2dxC0PSGKM G/TvIO04j/0fLB/0/Xny1YgMlleSByHURKWYOzqjL7gAqWx/YiCYzB5u0Nc8RRkeIGEP83AvQIll3 3Ekmi1v2S3cUN5TWBT3coX/cDDz+Q4Cu3RKZU0bcA6ftmYAPf6aInp52mtsUO5pQMoZ4zwdtbp6p5 FKTRa+crj9xCSPcYLRwiAW9f8ft1luA==; 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 1e2mUD-0006c8-G1; Thu, 12 Oct 2017 23:01:53 +0000 Received: from mail-pf0-x22d.google.com ([2607:f8b0:400e:c00::22d]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2mTI-0005Uv-FK for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 23:01:24 +0000 Received: by mail-pf0-x22d.google.com with SMTP id x7so7054281pfa.1 for ; Thu, 12 Oct 2017 16:00:36 -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=9yS9xINqeSQmYdwgE+j0BItL3qUOXuDdmp0wQ2C6MAk=; b=GAfCf+UdUmax0z1bk2TDU29lV5k3jQUgIHwzDdjPYufmh3Q51c5s1OFU5dlsYbNav1 uFGVjWeAUJIVPWz2AAiuk4V7/HJxW3qXUFwyGQaHF7xMhSlUfyQc1RRIahbGhz1Lr4PX sMFoMZOidLyoL6bnoCro3buxs+CD+1weyZuffBcH/szPQnD1WuYK3oJ/Yyy8FLOAitpk NJx2qTIrg8ZOzMhlj8OecbCMWiPQFyPrpfMKVVbkmTpbCYztZJhfQCmEcqEBx5+nq8Es VTXetpQD+Q1w47ymZEZkNJe1anc9IOtqZX42Ug1TigYsfdtFERz5gefPTQG3PwQP450t xgSw== 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=9yS9xINqeSQmYdwgE+j0BItL3qUOXuDdmp0wQ2C6MAk=; b=DP6S3RkzfelHxxB0/Ry5bF4H1uEU9xLTqVtxBCcittkXcLIvzj264KcSIQZqq05+JB kHZ6B8ma1OoJDLbXqBAvLZbntLeMd2KnhfR0pFd4H64hPSvM/vDUN3vyWCIzOSWQQDCN GJe/1v7XNPRCfN2DehHEIwbDrvFQdRFFn/QdJ5FTQBZabGP+cYOCop/R95btZhD50+SN G/a2S3SAb79EDZPY6gTFQ3r8oBD9KcZmkBMgvKDjXJ1P24oof0vs5QDZik+Tct+KgLrI 9t+FTNODnSTB1lekdOstP/kCRG6jg8K/ovERUgOPiq2WhY3YcNMgrjsZClmgpwI58jbM 4mrg== X-Gm-Message-State: AMCzsaV/fDLYfUH65RFHoRXiN15Qegmh4EJc+MYISZQGpvx40GgwTeXk GACUVgLcUPvDgwJF13T/t1l03w== X-Google-Smtp-Source: AOwi7QBBwsYQxwmTLP/hgzpWhgWiKS2z7Aj4JR/mGUCFgkOym98LyIpcydqbR+o4ZWm48jB8f/HZsA== X-Received: by 10.99.178.15 with SMTP id x15mr1375622pge.243.1507849235569; Thu, 12 Oct 2017 16:00:35 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id s86sm32677946pfi.74.2017.10.12.16.00.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 16:00:35 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Subject: [PATCH v2 6/10] arm: vdso: Add support for CLOCK_MONOTONIC_RAW Date: Thu, 12 Oct 2017 16:00:23 -0700 Message-Id: <20171012230029.86865-1-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171012_160056_896635_10AB5D55 X-CRM114-Status: GOOD ( 15.67 ) 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: Dmitry Safonov , Russell King , Andy Lutomirski , james.morse@arm.com, linux-arm-kernel@lists.infradead.org, Mark Salyzyn , Mark Salyzyn 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 Add a case for CLOCK_MONOTONIC_RAW to match up with support that is available in arm64's vdso. Signed-off-by: Mark Salyzyn v2: split first CL into 6 of 7 pieces --- arch/arm/include/asm/vdso_datapage.h | 4 +++ arch/arm/kernel/vdso.c | 5 ++++ arch/arm/vdso/vgettimeofday.c | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/arch/arm/include/asm/vdso_datapage.h b/arch/arm/include/asm/vdso_datapage.h index fa3e1856244d..d57c296f7f52 100644 --- a/arch/arm/include/asm/vdso_datapage.h +++ b/arch/arm/include/asm/vdso_datapage.h @@ -46,6 +46,10 @@ struct vdso_data { u64 xtime_clock_snsec; /* CLOCK_REALTIME sub-ns base */ u32 tz_minuteswest; /* timezone info for gettimeofday(2) */ u32 tz_dsttime; + + u32 cs_raw_mult; /* Raw clocksource multipler */ + u32 raw_time_sec; /* Raw time */ + 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 7fcc8cfcb7df..b374c143d53e 100644 --- a/arch/arm/vdso/vgettimeofday.c +++ b/arch/arm/vdso/vgettimeofday.c @@ -206,6 +206,47 @@ static __always_inline notrace int do_monotonic(const struct vdso_data *vd, return 0; } +static __always_inline notrace int do_monotonic_raw(const struct vdso_data *vd, + struct timespec *ts) +{ + u32 seq, mult, shift; + u64 nsec, cycle_last; +#ifdef ARCH_CLOCK_FIXED_MASK + static const u64 mask = ARCH_CLOCK_FIXED_MASK; +#else + u64 mask; +#endif + + typeof(((struct vdso_data *)vd)->raw_time_sec) 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; +#ifndef ARCH_CLOCK_FIXED_MASK + mask = vd->cs_mask; +#endif + + 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) @@ -218,6 +259,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) @@ -239,6 +286,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; }