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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6BA8C54E5D for ; Thu, 14 Mar 2024 18:47:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.693447.1081524 (Exim 4.92) (envelope-from ) id 1rkq6v-0007JM-Qw; Thu, 14 Mar 2024 18:47:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 693447.1081524; Thu, 14 Mar 2024 18:47:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkq6v-0007JF-O4; Thu, 14 Mar 2024 18:47:25 +0000 Received: by outflank-mailman (input) for mailman id 693447; Thu, 14 Mar 2024 18:47:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkq6v-0007J9-0B for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 18:47:25 +0000 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [2607:f8b0:4864:20::833]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4adbbe54-e233-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 19:47:22 +0100 (CET) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-430acf667afso1014611cf.1 for ; Thu, 14 Mar 2024 11:47:22 -0700 (PDT) Received: from [10.80.67.149] (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id l1-20020ac84cc1000000b0042f04e421d2sm1067472qtv.24.2024.03.14.11.47.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 11:47:21 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4adbbe54-e233-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710442042; x=1711046842; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=edk6fdaxLwF/Pq30+zYWxTrKfjAUS/7mmdROmeeEAcE=; b=R+Q38khTa71kq+DYN9A8oEo+0RPDH5C3dCmmfTo5upXnF3iHtqLjSInLpO3kgtCT12 YEcYDqNfIHP91T9+re43JmyC3ozE+A65aa1yhLOU4pQuQy+FQVh6lSCVTyoGK2m5H86z mCf3b6685ixqONnX4KXx/XFy7BNpohfO72+VU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710442042; x=1711046842; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=edk6fdaxLwF/Pq30+zYWxTrKfjAUS/7mmdROmeeEAcE=; b=K/bhUb1NVnbUfuj6+An9Vkmnh+7RxhOiMwyhoY0XNXXzixgF6CG/j9BdJwmSQ5lo3V xeDgAMQ1Lu+BBvXhLaazR+jlfKSI1obfKeJYoqS4ibtYONp6bE18/DnBUx9dUD3Ory+c qOF5/y1Me814lKHDZcPfj/am0vu/DHNSElUYNorBXfKQgmPeQ47rOq4smt5i206DhHTs gTpvQd+Qe/H2QMCXJyR6eSG48szOP7zgaa+87Khuc+3648faQd9jBa59/Prnt8yCHxos +heA6Sgtth+qd2RMmrz+NqxdHSlQwygmnR+YzU+09Nx60bGkhOFTFyAIgBONM2gyzhir zPwg== X-Forwarded-Encrypted: i=1; AJvYcCV2PwYU4tzQWBKl4sSqguwjj0T4ZbwVjtufB0BSOpQNdoR4xujNCQhbV9cqCw8mnrmAsNdTeJ0Z6eO02+lQCzJJ6kBRN6Kuh5FLFMq5Ijc= X-Gm-Message-State: AOJu0Yxjn0icpAsdue3CnLkpKIUsfT6zYVqnjs97b9RaT8I/c3QMEWEQ Ns60ktUKVinTaD53T8RPTYS2KPi+Jz1lh0vH9+0kCYKfWoLlrsaZwQ5ghAx3xxY= X-Google-Smtp-Source: AGHT+IFEAur5dlDVikexYq4s8x/G5TPcC91b0437JkcY65Hhw+TbZGEu4+aWv+UI7GGv7JFFrzCB9w== X-Received: by 2002:a05:622a:5cf:b0:42e:f660:8067 with SMTP id d15-20020a05622a05cf00b0042ef6608067mr2758444qtb.36.1710442041721; Thu, 14 Mar 2024 11:47:21 -0700 (PDT) Message-ID: <1356dd16-03e1-4c01-9aac-597a127dea85@citrix.com> Date: Thu, 14 Mar 2024 18:47:18 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 6/7] xen: Swap find_first_set_bit() for ffsl() - 1 Content-Language: en-GB To: Jan Beulich Cc: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini , Xen-devel References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> <20240313172716.2325427-7-andrew.cooper3@citrix.com> From: Andrew Cooper Autocrypt: addr=andrew.cooper3@citrix.com; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYzn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UuE2fwIbDAAKCRBlw/kGpdefoG4XEACD1Qf/er8EA7g23HMxYWd3FXHThrVQ HgiGdk5Yh632vjOm9L4sd/GCEACVQKjsu98e8o3ysitFlznEns5EAAXEbITrgKWXDDUWGYxd pnjj2u+GkVdsOAGk0kxczX6s+VRBhpbBI2PWnOsRJgU2n10PZ3mZD4Xu9kU2IXYmuW+e5KCA vTArRUdCrAtIa1k01sPipPPw6dfxx2e5asy21YOytzxuWFfJTGnVxZZSCyLUO83sh6OZhJkk b9rxL9wPmpN/t2IPaEKoAc0FTQZS36wAMOXkBh24PQ9gaLJvfPKpNzGD8XWR5HHF0NLIJhgg 4ZlEXQ2fVp3XrtocHqhu4UZR4koCijgB8sB7Tb0GCpwK+C4UePdFLfhKyRdSXuvY3AHJd4CP 4JzW0Bzq/WXY3XMOzUTYApGQpnUpdOmuQSfpV9MQO+/jo7r6yPbxT7CwRS5dcQPzUiuHLK9i nvjREdh84qycnx0/6dDroYhp0DFv4udxuAvt1h4wGwTPRQZerSm4xaYegEFusyhbZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 14/03/2024 2:30 pm, Jan Beulich wrote: > On 13.03.2024 18:27, Andrew Cooper wrote: >> --- a/xen/drivers/passthrough/x86/iommu.c >> +++ b/xen/drivers/passthrough/x86/iommu.c >> @@ -641,7 +641,7 @@ struct page_info *iommu_alloc_pgtable(struct domain_iommu *hd, >> if ( contig_mask ) >> { >> /* See pt-contig-markers.h for a description of the marker scheme. */ >> - unsigned int i, shift = find_first_set_bit(contig_mask); >> + unsigned int i, shift = ffsl(contig_mask) - 1; > The need for subtracting 1 is why personally I dislike ffs() / ffsl() (and > why I think find_first_set_bit() and __ffs() (but no __ffsl()) were > introduced). It's sad that there are competing APIs with different bit-labelling, but the optimiser does cancel the -1 with arch_ffs() (for at least x86 and ARM that I studied in detail). I firmly believe that fewer APIs which are fully well defined (and can optimise based on the compiler's idea of safety) is still better than a maze of APIs with different behaviours. > But what I first of all would like to have clarification on is what your > (perhaps just abstract at this point) plans are wrt ffz() / ffzl(). > Potential side-by-side uses would be odd now, and would continue to be odd > if the difference in bit labeling was retained. Since we're switching to > a consolidated set of basic helpers, such an anomaly would better not > survive imo. I honestly hadn't got that far yet.  I was mainly trying to dis-entangle the existing mess so RISC-V wasn't making it yet-worse. But yes - it warrants thinking about. I was intending to do the fls() next then popcnt().   The latter has quite a lot of cleanup wanting to come with it, and is more architecturally invasive, and I know I've got a years-old outstanding piece of work to try and do popcnt more nicely on x86. I have wanted ffz() in the past.  I think I just went with explicit ~ because I didn't want to continue this debate at the time. However, I (very much more) do not want a situation where ffs() and ffz() have different bit-labellings. There are no builtins, and having now studied the architectures we care about... https://godbolt.org/z/KasP41n1e ...not even x86 has a "count leading/trailing zeros" instruction. So using ffs(~val) really will get you the best code generation available, and seeing as it halves the number of bitops to maintain, I think this is the best tradeoff overall. I intend to put ffz() and __ffs() into linux-compat.h and leave them there to discourage their use generally. ~Andrew