Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1374878rwd; Thu, 1 Jun 2023 14:49:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6l7ViV1XkpUD5vdMAngw/ksOQbNp0mm6ws4Ertk03ygL6NiOZMujPKFwX0tnBp9SfZjNzs X-Received: by 2002:ac8:5ac7:0:b0:3f4:e11b:d19c with SMTP id d7-20020ac85ac7000000b003f4e11bd19cmr13519199qtd.5.1685656148247; Thu, 01 Jun 2023 14:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685656148; cv=none; d=google.com; s=arc-20160816; b=xvX72g0cPk+2Sbawo/9IeM6n7FAp11BXMzAVeAmwpjJC65q/U+Yne0oKE3g0XAPigF k8m/D9qcyr/BaN2AvtfImcMTLXAEA5z7gCyVViAEnywg7P+b0gp3sdUVzMg134p1dOp6 kB2qqghT9w/kHIx+16Wy6gps77uZeZYsnL1iclOkTFHBxQuvy7bmGONeenCM++MLNO0F wN67zSAANrbuD8fFcUepuJh49kSABazBMJtQDKn90jvaIs0LxQ5Yik+HXDBP0B3h6u7J 2Kcq4vtXgq0T5fiwtc6DWaK93CoUNEd8NxOXq9816A2wt1B0Qg+k0mW3jGPSaHY/EwmQ DGlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:feedback-id:references:in-reply-to :message-id:subject:cc:from:to:dkim-signature:date; bh=ncMVbNCtSXe0DvnH0neUKu6XvupvEmA5tfm8tyhtji0=; b=rG01fjTxDTLFXkf8EbcD84Ig+CdKG+QR72vVdFBN33Dd8qahGBar5nu1IxayZLw1U9 s/xkVWFShcEpg0IbnoUK0eEfI2AiCItPJkoG2dJTtXle3B/OLTM6crnNQanQlOxqh2Gi cl2TGDezHjjrraA94wiyqFQpPQlzvDKCbSJAdctPefkZzePR3qGql3V68BOBOl8YBx9u BikE2YFQHaVpHRkHKW9DilKcD7vVTua2Eauu0jVnLHZuJ3WlmENgUuYLyKAdkgdwsXcc 2vtpaq/dgyBrn9X2hxPXmkIwGfP4Zlg2Z6o6omoMhjy5inZdTn/B0GJktPMhC5eSAfB0 eF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@uplinklabs.net header.s=protonmail header.b=eJT6VUtd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=uplinklabs.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r207-20020a632bd8000000b0053faf462e4dsi3426163pgr.500.2023.06.01.14.48.54; Thu, 01 Jun 2023 14:49:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@uplinklabs.net header.s=protonmail header.b=eJT6VUtd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=uplinklabs.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232935AbjFAVlq (ORCPT + 99 others); Thu, 1 Jun 2023 17:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233252AbjFAVlo (ORCPT ); Thu, 1 Jun 2023 17:41:44 -0400 Received: from mail-4022.proton.ch (mail-4022.proton.ch [185.70.40.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0249C1AB for ; Thu, 1 Jun 2023 14:41:31 -0700 (PDT) Date: Thu, 01 Jun 2023 21:41:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uplinklabs.net; s=protonmail; t=1685655688; x=1685914888; bh=ncMVbNCtSXe0DvnH0neUKu6XvupvEmA5tfm8tyhtji0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=eJT6VUtdeyED77CihDB3HvGSY7PsZ4IPKLgt9ikls1HSxZTKlFIp9OMj3I6vFkKxj 4Q71uP1dDu5e0AAfR00kGQzYyd9pXSmddw5sQRauaSOJA9sAp5OaLAOIpkG6rtAgGH KVD6304oI6a9XDO5F6QEIuzuAdhybaj39Ig5o/j8er5E1bO5H5JoqGinzU8/MAaHr0 c6Nd/jJEyJdO3gJGNTR5/xKU21N05VT3CY57yJhzWW5hbBPzAXMMB775/55VXc3UXi XBeijehgmVeXjGlpUG6dmy2kxrlRZIUoJvUy6nMs3XgtgDzmcoRPkUADILlJ6ngXCo Ia9c9jgUvPonQ== To: Peter Zijlstra From: Steven Noonan Cc: Thomas Gleixner , Muhammad Usama Anjum , Jonathan Corbet , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "open list:DOCUMENTATION" , open list , "Guilherme G. Piccoli" , kernel@collabora.com Subject: Re: Direct rdtsc call side-effect Message-ID: In-Reply-To: <20230601203127.GY4253@hirez.programming.kicks-ass.net> References: <6719fb05-382c-8ec4-ccda-72798906a54b@collabora.com> <87mt1jeax1.ffs@tglx> <87h6rrdoy0.ffs@tglx> <20230601203127.GY4253@hirez.programming.kicks-ass.net> Feedback-ID: 10620438:user:proton MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha512; boundary="------66abe1e2681810bd2ab224c8c40637c46d62c8a8760c5753c9d567431424fd5c"; charset=utf-8 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------66abe1e2681810bd2ab224c8c40637c46d62c8a8760c5753c9d567431424fd5c Content-Type: multipart/mixed;boundary=---------------------b7acdc7d3b503f22c0cb7da76c5decd3 -----------------------b7acdc7d3b503f22c0cb7da76c5decd3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 On Thursday, June 1st, 2023 at 1:31 PM, Peter Zijlstra wrote: > What about kernel based emulation? You could tie it into user_dispatch > and have a user_dispatch tsc offset. > = > So regular kernel emulation simply returns the native value (keeps the > VDSO working for one), but then from a user_dispatch range, it returns > +offset. > = > That is; how slow is the below? It's around 1800-1900 clock cycles on this system (modified patch attached= , compile fix + rdtscp support). It's definitely better than the userspace signal handler (20x vs 100x). Al= so compared to reading one of the clock_gettime() clocks when current_cloc= ksource is 'hpet', it's about twice as fast. So that's at least in the rea= lm of being usable. Since faulting would still make the vDSO clocks go through this path we'd = have to be careful that whatever offsets we throw into this path don't aff= ect the correctness of the other clocks. -----------------------b7acdc7d3b503f22c0cb7da76c5decd3 Content-Type: application/octet-stream; filename="tsc-test.patch"; name="tsc-test.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="tsc-test.patch"; name="tsc-test.patch" ZGlmZiAtLWdpdCBhL2FyY2gveDg2L2tlcm5lbC90cmFwcy5jIGIvYXJjaC94ODYva2VybmVsL3Ry YXBzLmMKaW5kZXggZDMxN2RjM2QwNmEzLi5hNjA3MmM0ZTBhOTcgMTAwNjQ0Ci0tLSBhL2FyY2gv eDg2L2tlcm5lbC90cmFwcy5jCisrKyBiL2FyY2gveDg2L2tlcm5lbC90cmFwcy5jCkBAIC02NDUs NiArNjQ1LDM2IEBAIHN0YX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wdWxhdGVkLiAgSWYgcG9zc2libGUs IHBvcHVsYXRlCkBAIC03NTIsNiArNzgyLDkgQEAgREVGSU5FX0lEVEVOVFJZX0VSUk9SQ09ERShl eGNfZ2VuZXJhbF9wcm90ZWN0aW9uKQogCQlpZiAoZml4dXBfaW9wbF9leGNlcHRpb24ocmVncykp CiAJCQlnb3RvIGV4aXQ7CiAKKwkJaWYgKGZpeHVwX3JkdHNjX2V4Y2VwdGlvbihyZWdzKSkKKwkJ CWdvdG8gZXhpdDsKKwogCQlpZiAoZml4dXBfdmRzb19leGNlcHRpb24ocmVncywgWDg2X1RSQVBf R1AsIGVycm9yX2NvZGUsIDApKQogCQkJZ290byBleGl0OwogCg== -----------------------b7acdc7d3b503f22c0cb7da76c5decd3-- --------66abe1e2681810bd2ab224c8c40637c46d62c8a8760c5753c9d567431424fd5c Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wnUEARYKACcFgmR5EGIJkAi2TYeeRSZQFiEE707zOy6TKdatSeTPCLZNh55F JlAAAPDAAP4uwiUg9w+2pjjQun/Or7s8ILn75ADZ364ArYdpgetOHgEAhFh6 nfHKyAB9fLR/4Mgs/2KZvBGrn/lHGzzSy9IlNQs= =Y+zl -----END PGP SIGNATURE----- --------66abe1e2681810bd2ab224c8c40637c46d62c8a8760c5753c9d567431424fd5c--