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 8817AC021A0 for ; Thu, 13 Feb 2025 22:52:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 233976B009D; Thu, 13 Feb 2025 17:52:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E3A56B009E; Thu, 13 Feb 2025 17:52:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 084006B009F; Thu, 13 Feb 2025 17:52:47 -0500 (EST) 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 DE67D6B009D for ; Thu, 13 Feb 2025 17:52:46 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 916924BA00 for ; Thu, 13 Feb 2025 22:52:46 +0000 (UTC) X-FDA: 83116422732.13.67E0BA8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf12.hostedemail.com (Postfix) with ESMTP id BCBAD40009 for ; Thu, 13 Feb 2025 22:52:43 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Vpx2KcMB; spf=pass (imf12.hostedemail.com: domain of dave.hansen@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739487164; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZwZF4hODVkkvP9kp19xuuSxDSLNe1qY1Ffmiy+5zKvo=; b=VR4M9O6Up3QoDe1OrdD8yDoYy82+wmtA8SRBDJFpYfloAcOJrHcDrlc5V9yCTnYgeL/DzR Ae66CLIC6DhSlflFJhQi93u4NIy2sbCcSd/fjvFdGAWRBSakvB+yGtrxBgmdyGJ56M7plu NEbnlwLfdFwxrdBKgT94/+boDswH704= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Vpx2KcMB; spf=pass (imf12.hostedemail.com: domain of dave.hansen@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739487164; a=rsa-sha256; cv=none; b=gcxfVgSWfvYlu9eBKRGMXX0TZjtv12YaL3hWLI8LpzChjrcgGCRo8R9xYqyGTyEy2qVU7u nGRJudvUnygs9Eby9WjEIVUaU1rfV+8I1h7zKwUvudkZPXMBFOwTudHRt4K2WgDflnpt46 mAOk9AQLq/sxrpNQcf6mlry8ppUpNz0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739487164; x=1771023164; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=ZdAaRSQBdHLvutJUD7iiNJZZ+fgTiSlLTbKntKkz7V0=; b=Vpx2KcMByx7XYjf/zMqwi6a+nEQb1tQsx/Cre+txylQS7yhc9mDFdeX0 lBmctsPsFUYxz/gSFUwPGmxqNKN2x16FhLed7nE2id5rkFLfqSPNCGbOx 0LP3DOLjuHqXq1rVvO3xqbMWgDHXHa+UNZE5ZlBJa/+dAvmD3pjuqMXeJ mH7pjwymj+02S7Y4KT9oNwbhBIVof5Cap+myw6E81qt8QDe7+u2Fa4PvX tkjblXOCXk92wNzf0+iytVpU7Mu1Oqsl6lA3XvsR9UziU7w3FnIdtnH22 O6+w5u9BrFO3raloJDB4nEBtEn2S8/lE54bX6dF1rIWIVExwPBccNdCt/ Q==; X-CSE-ConnectionGUID: nZmpCX2bT+yuSaICjghE9A== X-CSE-MsgGUID: V6ufM9o+RqiNQaT8ZGRGew== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="50842171" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="50842171" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 14:52:42 -0800 X-CSE-ConnectionGUID: nO8NP5xVRum/6p8UR7u41w== X-CSE-MsgGUID: to+9fr9RTWugbrVZwm1FDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="150459322" Received: from iherna2-mobl4.amr.corp.intel.com (HELO [10.125.108.188]) ([10.125.108.188]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 14:52:42 -0800 Message-ID: <87194c62-7e97-41d3-98bd-14288e8bde8f@intel.com> Date: Thu, 13 Feb 2025 14:52:41 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RESEND 2/2] x86/locking: Use asm_inline for {,try_}cmpxchg{64,128} emulations To: Uros Bizjak Cc: x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Dennis Zhou , Tejun Heo , Christoph Lameter , "Peter Zijlstra (Intel)" References: <20250213191457.12377-1-ubizjak@gmail.com> <20250213191457.12377-2-ubizjak@gmail.com> <62965669-bf1d-461f-9401-20e303c6d619@intel.com> From: Dave Hansen Content-Language: en-US Autocrypt: addr=dave.hansen@intel.com; keydata= xsFNBE6HMP0BEADIMA3XYkQ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NFHE5zgXGZnrmaf6resQzbvJHO0Fb0CcIohzrpPaL3YepcLDoCCgElGMGQjdCcSQ+Ci FCRl0Bvyj1YZUql+ZkptgGjikQARAQABwsFfBBgBAgAJBQJUY85qAhsMAAoJEGg1lTBwyZKw l4IQAIKHs/9po4spZDFyfDjunimEhVHqlUt7ggR1Hsl/tkvTSze8pI1P6dGp2XW6AnH1iayn yRcoyT0ZJ+Zmm4xAH1zqKjWplzqdb/dO28qk0bPso8+1oPO8oDhLm1+tY+cOvufXkBTm+whm +AyNTjaCRt6aSMnA/QHVGSJ8grrTJCoACVNhnXg/R0g90g8iV8Q+IBZyDkG0tBThaDdw1B2l asInUTeb9EiVfL/Zjdg5VWiF9LL7iS+9hTeVdR09vThQ/DhVbCNxVk+DtyBHsjOKifrVsYep WpRGBIAu3bK8eXtyvrw1igWTNs2wazJ71+0z2jMzbclKAyRHKU9JdN6Hkkgr2nPb561yjcB8 sIq1pFXKyO+nKy6SZYxOvHxCcjk2fkw6UmPU6/j/nQlj2lfOAgNVKuDLothIxzi8pndB8Jju KktE5HJqUUMXePkAYIxEQ0mMc8Po7tuXdejgPMwgP7x65xtfEqI0RuzbUioFltsp1jUaRwQZ MTsCeQDdjpgHsj+P2ZDeEKCbma4m6Ez/YWs4+zDm1X8uZDkZcfQlD9NldbKDJEXLIjYWo1PH hYepSffIWPyvBMBTW2W5FRjJ4vLRrJSUoEfJuPQ3vW9Y73foyo/qFoURHO48AinGPZ7PC7TF vUaNOTjKedrqHkaOcqB185ahG2had0xnFsDPlx5y In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: BCBAD40009 X-Stat-Signature: 697yrkmdzka93p3mt7w9q73xeuj1h66e X-Rspamd-Server: rspam03 X-HE-Tag: 1739487163-253852 X-HE-Meta: U2FsdGVkX1/dMEX4hGLUSCJLsS/HURI494q8+uW3rw5nea4XPj0Mn7Pj9xCmwsU7+E5OUEPmUVbozBvj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AQ5+/KxfG6RS2C6IIE1128P0i8rg2LTj/jdzzlVUzy0dK/9NCTekhg5nQW/A6TEbZf7dRVrzUs+4pDGWbuzcLNEp+sep9e8ve6bhypXNL7f5Re8uDsDP8JmzkMSFQryKXz37TU+qC4yeg= 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: On 2/13/25 14:13, Uros Bizjak wrote: > On Thu, Feb 13, 2025 at 9:48 PM Dave Hansen wrote: >> On 2/13/25 11:14, Uros Bizjak wrote: >>> According to [1], the usage of asm pseudo directives in the asm template >>> can confuse the compiler to wrongly estimate the size of the generated >>> code. ALTERNATIVE macro expands to several asm pseudo directives, so >>> its usage in {,try_}cmpxchg{64,128} causes instruction length estimate >>> to fail by an order of magnitude (the compiler estimates the length of >>> an asm to be more than 20 instructions). >> >> Just curious, but how did you come up with the "20 instructions" number? > > Currently, a patched GCC compiler is needed (please see > asm_insn_count() and asm_str_count() functions in gcc/final.cc on how > the asm length is calculated) to report the length. For historic > reasons, the length of asm is not printed in asm dumps, but recently a > GCC PR was filled with a request to change this). So, that's also good info to add. You can even do it in the changelog with little more space than the existing changelog: ... fail by an order of magnitude (a hacked-up gcc shows that it estimates the length of an asm to be more than 20 instructions). ... >> Is any of this measurable? Is there any objective data to support that >> this change is a good one? > > Actually, "asm inline" was added to the GCC compiler just for this > purpose by request from the linux community [1]. Wow, that's really important important information. Shouldn't the fact that this is leveraging a new feature that we asked for specifically get called out somewhere? Who asked for it? Are they on cc? Do they agree that this feature fills the gap they wanted filled? > My patch follows the > example of other similar macros (e.g. arch/x86/include/alternative.h) > and adds the same cure to asms that will undoubtedly result in a > single instruction [*]. The benefit is much more precise length > estimation, so compiler heuristic is able to correctly estimate the > benefit of inlining, not being skewed by excessive use of > __always_inline directive. OTOH, it is hard to back up compiler > decisions by objective data, as inlining decisions depend on several > factors besides function size (e.g. how hot/cold is function), so a > simple comparison of kernel sizes does not present the full picture. Yes, the world is complicated. But, honestly, one data point is a billion times better than zero. Right now, we're at zero. >> It's quite possible that someone did the "asm" on purpose because >> over-estimating the size was a good thing. > > I doubt this would be the case, and I would consider the code that > depends on this detail defective. The code that results in one asm > instruction should be accounted as such, no matter what internal > details are exposed in the instruction asm template. Yeah, but defective or not, if this causes a regression, it's either not getting applied to gets reverted. All that I'm asking here is that someone look at the kernel after the patch gets applied and sanity check it. Absolutely basic scientific method stuff. Make a hypothesis about what it will do: 1. Inline these locking functions 2. Make the kernel go faster for _something_ and if it doesn't match the hypothesis, then try and figure out why. You don't have to do every config or every compiler. Just do one config and one modern compiler. Right now, this patch is saying: 1. gcc appears to have done something that might be suboptimal 2. gcc has a new feature that might make it less suboptimal 3. here's a patch that should optimize things ... but then it leaves us hanging. There's a lot of "mights" and "shoulds" in there, but nothing that shows that this actually does anything positive in practice. Maybe I'm just a dummy and this is just an obvious improvement that I can't grasp. If so, sorry for being so dense, but I'm going to need a little more education before this gets applied.