From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D536AC77B7C for ; Tue, 24 Jun 2025 21:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15F756B009E; Tue, 24 Jun 2025 17:45:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 110426B00A6; Tue, 24 Jun 2025 17:45:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F41616B00AC; Tue, 24 Jun 2025 17:45:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E0EAA6B00A6 for ; Tue, 24 Jun 2025 17:45:33 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 16CA9103A04 for ; Tue, 24 Jun 2025 21:45:33 +0000 (UTC) X-FDA: 83591626146.30.F079FD5 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by imf12.hostedemail.com (Postfix) with ESMTP id B2EB940012 for ; Tue, 24 Jun 2025 21:45:28 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; spf=pass (imf12.hostedemail.com: domain of segher@kernel.crashing.org designates 63.228.1.57 as permitted sender) smtp.mailfrom=segher@kernel.crashing.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750801531; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ddg87swFlzAfacr342BPMSmssxOzhDLpUUC2mPzRwOI=; b=SwOi8lN0GYiBWcsJOsMlokCbjQ/bn4ar/D6qdigNTCXTL2dDwRUbLtfz38rG5Goy10UgRx wjivM7RWlmduia/oCXytKd6lOS3u7EQy4HH3UTW5s1TTKVeOahlQAzgEH3v14qnEfcCW5T q/T9ViP5W09IN77nlA3aYUW4b62x4Is= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750801531; a=rsa-sha256; cv=none; b=gu0vyjLcgbSC81KLjXHJavogQpoMmqFLRjUbNWSc+Ej50jYKvqLQe/37a6AcIiggpehhQ2 h8JwWELNFEruvvT1PL2o8TNKXMhyynUx/MKawqp763bEHsXpTVXHf+ZwSOO0DO9UZiy/Cu SjTWnzc5IGE2qpr6cE4nYPgW2tM0zWE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of segher@kernel.crashing.org designates 63.228.1.57 as permitted sender) smtp.mailfrom=segher@kernel.crashing.org; dmarc=none Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 55OLbO3g015495; Tue, 24 Jun 2025 16:37:25 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 55OLbDMs015480; Tue, 24 Jun 2025 16:37:13 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 24 Jun 2025 16:37:12 -0500 From: Segher Boessenkool To: David Laight Cc: Christophe Leroy , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan , Alexander Viro , Christian Brauner , Jan Kara , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Andre Almeida , Andrew Morton , Dave Hansen , Linus Torvalds , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 0/5] powerpc: Implement masked user access Message-ID: <20250624213712.GI17294@gate.crashing.org> References: <20250622172043.3fb0e54c@pumpkin> <20250624093258.4906c0e0@pumpkin> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250624093258.4906c0e0@pumpkin> User-Agent: Mutt/1.4.2.3i X-Rspam-User: X-Stat-Signature: 8cfpncsaxjt97oogjwdw4g4kt9jjft5n X-Rspamd-Queue-Id: B2EB940012 X-Rspamd-Server: rspam08 X-HE-Tag: 1750801528-867443 X-HE-Meta: U2FsdGVkX1/HJN2Jn1tKfeGerY5fcGHTQ7hdpEDrjDvlCM0Z6srV4o/4AtO2BA+158AABclcWh2Gm/MVC8PIg/KXEzhWKVNlEuPaCpRxTNsnIN4Zt6C8a1coOq9/nNSR/o+f33N2HF1eHAEWtBYcGALjccGhLvAaIvwW6rzzgCMkUlG9OHPHJ9WKV3hUD+lqk/D63ze22lXpEK2vRkj2VoQ7u+RZtBeG/SS9HtPOu5Tlv+VP79q/oOwM47zfOwDIt10iRIknEkCLxOuL4xtKPTPY6hI5eIAqZmxc4VXGL8fWKaBzHqyInlTq863BNt6hy/VSnTaqaSAVnDJT44q0WGxrq/QExoU4K4jYQYMo5jaXP3uKW9FG9MKrqRzm7jnPSOeCJmZqGI1CueWBi//RMLYGnsMrkdCzzJ3oCrb6DyjZK1SZEN/9M45c7VWLE5QzkuLdJr4xw7umlmsKmG/+Uajg3Nrxvj1n2+iHHxh3JAAzE2l8SK0GqYZYOEtjQv6JnX1pH/gqzCrmNNlZfLqNmhI3hNXFxasTLWGtVQpqSG88rWyGxDUvDWlZwXMAsr6OJ7Q+HmhkkNLb1afyrk408bNI2gIXcvDFjkMrMkNW94N1nUDjB5icQGN75xCP+n6TcqfOC2z404Zs5qD8P9GETa4UUQtmpPtXtpDEmP1KOezG7HQVsP4LfpwSsYVyoo1Ne1/Rb6RYRBOF6o2nMFqiDTaLTshWBnLT1zoxXDs8uTTUJm0H6yGHecBytj72YXLAWRQvNpTEgtcut+uE3+wHzYKJQm3l/WSPGQGnYhgKH29bhyEoJ6LV26LTINu1Fx80G+25+s0XAao+N9P96Jutjwcxi+ROU0vPLP+hRvcUyP5KCI9EbgRddw+ovdabWfG4SdTRWIuo51xLJr3+5sDFShdjZbeVcwnaP5ucwwiS0nBmVJweHAGDmcPNzFOHQWFc156QBQ2OZdhi5FBhX7c jEPehKqy drmhQgVbompZ3U3JlTElJxWIUpKf0Er+5f++jWKBVN2PuCf0TU0IvczCziDYtfR37yqJUt/cugWZIz9/GRQQYIKsaBVuqvl4sVkyS7wZLkWzR/71NN/Not+fYJckhKPPpM/My0rgis4PPUNo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi! On Tue, Jun 24, 2025 at 09:32:58AM +0100, David Laight wrote: > > So GCC uses the 'unlikely' variant of the branch instruction to force > > the correct prediction, doesn't it ? > > Nope... > Most architectures don't have likely/unlikely variants of branches. In GCC, "likely" means 80%. "Very likely" means 99.95%. Most things get something more appropriate than such coarse things predicted. Most of the time GCC uses these predicted branch probabilities to lay out code in such a way that the fall-through path is the expected one. Target backends can do special things with it as well, but usually that isn't necessary. There are many different predictors. GCC usually can predict things not bad by just looking at the shape of the code, using various heuristics. Things like profile-guided optimisation allow to use a profile from an actual execution to optimise the code such that it will work faster (assuming that future executions of the code will execute similarly!) You also can use __builtin_expect() in the source code, to put coarse static prediction in. That is what the kernel "{un,}likely" macros do. If the compiler knows some branch is not very predictable, it can optimise the code knowing that. Like, it could use other strategies than conditional branches. On old CPUs something like "this branch is taken 50% of the time" makes it a totally unpredictable branch. But if say it branches exactly every second time, it is 100% predicted correctly by more advanced predictors, not just 50%. To properly model modern branch predictors we need to record a "how predictable is this branch" score as well for every branch, not just a "how often does it branch instead of falling through" score. We're not there yet. Segher