Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4179377ybl; Mon, 13 Jan 2020 09:10:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxIPwxs9fozlG0C+0U0f7fA9p3GKV293bnqlnN0wy7xnECbJS8nkisfZwUGr2KdDfiS1WWa X-Received: by 2002:aca:4ec5:: with SMTP id c188mr13805979oib.1.1578935426253; Mon, 13 Jan 2020 09:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578935426; cv=none; d=google.com; s=arc-20160816; b=i8JXeJe6/VRID0659pRjQSehUQXkl1WYU1cTh6GgjlLnl/F8hQQp3lpTMlhTQY+SMZ cGnOz5FDm0CpHNSyyr+Q083UNTTIyBFIuAQ8gKC/HzKin/SFwSpk0pBq17EfaYuxX5jx JAgZEsgPkRJ0ejujHJV8gotf64R+CYpA7FwAD7QSC3gha9dcASC2QzzRFhbUTzuK+yK5 LIe6QR/HMPBqPzG8y7WpzBT6h0/lFnKj6A+2LuVGZzrKOpYBfuDvHol/3qp76DYZDFh/ hrQTqIJ3JOq3b/so+uD5IeeioGP/7UPevgH2sAK1FJtjapgq5qAm1AYOdtoXApVFnftj /OKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=XLnzIcQo2gdn6/h4SDeOO8peJAxsTTmgC8iXnixatHk=; b=QYRSCK58dXi/WlFyjY55soG0eTI2/JjPW4g/cFdDCnpNPRf2kZ0/ZRS2Qg1lgn+ZGd tJZo20oeYHCzGcJ3aEXCSa7XwrzEa/TC5VYWn0jliDhae1pOTZZyiSnYVWqNx7/PhPP5 dzKvXqLTOy4yAhoi1rhfyA2Xwjc1MMvgWrPgdIES0nn4ux8BHEm/q9/jL/Cj9HEqtkC8 /OFv2Ng37a0Bj3yu1WIPexay2Tdn870snJvCFrxVGVOqJanXN0IY3dDjp3MbLDC004fD uewVDzj6K3S923ySAs9TgB5NPLI//hx5OS90s3ExljXS6ZY67iEah40/ptvDHEsMxIYI DsWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ltBD6+si; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h20si7390540otn.253.2020.01.13.09.10.13; Mon, 13 Jan 2020 09:10:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ltBD6+si; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728911AbgAMRJD (ORCPT + 99 others); Mon, 13 Jan 2020 12:09:03 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:40965 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728848AbgAMRIv (ORCPT ); Mon, 13 Jan 2020 12:08:51 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 47xKms1KbYz9v0Y0; Mon, 13 Jan 2020 18:08:45 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=ltBD6+si; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 2grE1wQ3VL1l; Mon, 13 Jan 2020 18:08:45 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 47xKms0BhPz9v0Xy; Mon, 13 Jan 2020 18:08:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1578935325; bh=XLnzIcQo2gdn6/h4SDeOO8peJAxsTTmgC8iXnixatHk=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=ltBD6+siFYlWWG5dz6TSocWL3jpuQkzoWPC3xPxE01ZHvMRMiVv8yn+46Fn1vDAQs 162dR8qUJMY1/1TefqinYBAAfHQyr5UsbSxiugQLjDb7t5oItKvK/H3exuotlqfipX mp3zxCOe4hj+Y66sTj0SUCkp01MdjmZBIT0gxDk4= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 563FC8B7C9; Mon, 13 Jan 2020 18:08:50 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id nXhUeUXxlMgG; Mon, 13 Jan 2020 18:08:50 +0100 (CET) Received: from po14934vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 249F18B7BE; Mon, 13 Jan 2020 18:08:50 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 0) id E5E5D64A1D; Mon, 13 Jan 2020 17:08:49 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v3 11/12] lib: vdso: split clock verification out of __arch_get_hw_counter() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , arnd@arndb.de, tglx@linutronix.de, vincenzo.frascino@arm.com, luto@kernel.org Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, x86@kernel.org Date: Mon, 13 Jan 2020 17:08:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __arch_get_hw_counter() returns the current value of the counter if the counter is valid or a negative number if the counter is not valid. This is suboptimal because the validity is checked twice: once before reading the counter and once after reading the counter. Optionaly split the verification out of __arch_get_hw_counter() by providing an optional __arch_is_hw_counter_valid() function. Signed-off-by: Christophe Leroy --- lib/vdso/gettimeofday.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index ea1a55507af5..001f6329e846 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -67,11 +67,18 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk, do { seq = vdso_read_begin(vd); +#ifdef __arch_is_hw_counter_valid + if (unlikely(!__arch_is_hw_counter_valid(vd->clock_mode))) + return -1; +#endif + cycles = __arch_get_hw_counter(vd->clock_mode); ns = vdso_ts->nsec; last = vd->cycle_last; +#ifndef __arch_is_hw_counter_valid if (unlikely((s64)cycles < 0)) return -1; +#endif ns += vdso_calc_delta(cycles, last, vd->mask, vd->mult); nsec = ns >> vd->shift; -- 2.13.3