Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp4056064ybd; Tue, 25 Jun 2019 13:16:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIXwPja3J4jgf1mYWFQyKnCXCxThyd1A203xqDCC81Mx0fPcV5jX3R+RjnMch1Buz6FOHr X-Received: by 2002:a17:90a:cb01:: with SMTP id z1mr700858pjt.93.1561493765225; Tue, 25 Jun 2019 13:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561493765; cv=none; d=google.com; s=arc-20160816; b=Dh+JEzNJfWZThc1BDe8cUCyqu1hbe4B3mROuUFjRa2VZeKTyj2tqiRMlQewPXdt44i P5QxtMrAFNH5GUGCfwO5cI6mYgilZAQB8ObxRkYk/5Djxpq8PGRapxJBgJTQvAaBXuZ7 7YZk+AiRaH6ArVPj+5lMBCvL5gArAEqITbFOV/Eh3zsc/F3+2zeA6wrr7gM6fMtHOf6n 2gLdPgFB8zM1O2td1aM38fUzElXfOPPqEdmS+B1P8zK3C0uAOMPiAiPimK9jUxxho+ye XNlcM01Ag7SerW+Yve2UEQSJ9/xjKC5x/20QySSb+oxjMsYrl9i23Sx8ro2xl2czLQQu Wz6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PTZ6DdYTrqMZ0Dxkww6xdkX5ghxhcPxQ7sTS8iE88us=; b=EoGzv/3OcmfCEgSCCkPWyD0CIVdQ2jzb35XBVU1CNUibTsw+cqj977ijg2GEZv2w0Q 7DfcJ7ldPZOYNHRIDKh2sQyQH4kYxxL/NmZkSdRdS3iELka6ruAqKU2+06fAy7kD9myN 5FhkX4z/aR/sCa45WotA/NuHmHwrgvrC3i7bNoNxsIMEF1N9Vlf/mdlRMXj8Vf9ftPrZ JkPDlPChButuV93Qp78B/MEWyfbznNZo5lymhyRzJz15lCK0AaIG0LqdZC8joCDy9JT2 aXIgb4sn3264+5n3tV9oTdPp0FTdVQYLBbBtZZnN4NEU5EiISm3BNa/WJD8V3fqtF1nn isKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lLPnssPR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18si14936252pfr.65.2019.06.25.13.15.49; Tue, 25 Jun 2019 13:16:05 -0700 (PDT) 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=@kernel.org header.s=default header.b=lLPnssPR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726934AbfFYUPd (ORCPT + 99 others); Tue, 25 Jun 2019 16:15:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:44066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbfFYUPd (ORCPT ); Tue, 25 Jun 2019 16:15:33 -0400 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 208DF216E3 for ; Tue, 25 Jun 2019 20:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561493732; bh=Non/zwPybF2AGuhmjwFgxmMCpYW8ogfnhbNrhDKk/vc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lLPnssPRCinSZhMedXFl4IX9MsXTNhVSxFwL4KFntKi0pXjqZtp295xgMzrg8LGbO mOUGpRdpbB/L63NxLJu57zUIKU8V40nkRaOVFZ6w0Dr1RtDyGNFekX200zDZun+Q1n hwMQ4fQRt/bJqYXOD6mBo2LKulD7skPGobAZzDmU= Received: by mail-wr1-f47.google.com with SMTP id n4so73090wrs.3 for ; Tue, 25 Jun 2019 13:15:32 -0700 (PDT) X-Gm-Message-State: APjAAAWYLeOVhVybsUR2qojRV1378sjHfofXns6VNbKUYuLERvBKslhY JwfOQtQkz6Zl0O+fTSeNkjSckFiLA1Au2Vq8VxtgIg== X-Received: by 2002:adf:cc85:: with SMTP id p5mr17560wrj.47.1561493730555; Tue, 25 Jun 2019 13:15:30 -0700 (PDT) MIME-Version: 1.0 References: <20190624133607.GI29497@fuggles.cambridge.arm.com> <20190625161804.38713-1-vincenzo.frascino@arm.com> In-Reply-To: From: Andy Lutomirski Date: Tue, 25 Jun 2019 13:15:19 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] lib/vdso: Delay mask application in do_hres() To: Thomas Gleixner Cc: Vincenzo Frascino , linux-arch , LAK , LKML , linux-mips@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , Catalin Marinas , Will Deacon , Arnd Bergmann , Russell King , Ralf Baechle , Paul Burton , Daniel Lezcano , Mark Salyzyn , Peter Collingbourne , Shuah Khan , Dmitry Safonov <0x7f454c46@gmail.com>, Rasmus Villemoes , Huw Davies , Shijith Thotton , Andre Przywara , Andy Lutomirski , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 25, 2019 at 11:27 AM Thomas Gleixner wrote: > > On Tue, 25 Jun 2019, Thomas Gleixner wrote: > > > On Tue, 25 Jun 2019, Vincenzo Frascino wrote: > > > > CC+ Andy > > > > > do_hres() in the vDSO generic library masks the hw counter value > > > immediately after reading it. > > > > > > Postpone the mask application after checking if the syscall fallback is > > > enabled, in order to be able to detect a possible fallback for the > > > architectures that have masks smaller than ULLONG_MAX. > > > > Right. This only worked on x86 because the mask is there ULLONG_MAX for all > > VDSO capable clocksources, i.e. that ever worked just by chance. > > > > As we talked about that already yesterday, I tested this on a couple of > > machines and as expected the outcome is uarch dependent. Minimal deviations > > to both sides and some machines do not show any change at all. I doubt it's > > possible to come up with a solution which makes all uarchs go faster > > magically. > > > > Though, thinking about it, we could remove the mask operation completely on > > X86. /me runs tests > > Unsurprisingly the results vary. Two uarchs do not care, but they did not > care about moving the mask either. The other two gain performance and the > last one falls back to the state before moving the mask. So in general it > looks like a worthwhile optimization. > At one point, I contemplated a different approach: have the "get the counter" routine return 0 and then do if (unlikely(cycles <= last)) goto fallback. This will remove one branch from the hot path. I got dubious results when I tried benchmarking it, probably because the branch in question was always correctly predicted.