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 2A9CDC48BF8 for ; Thu, 22 Feb 2024 10:11:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.684305.1064060 (Exim 4.92) (envelope-from ) id 1rd62c-0004AF-Jg; Thu, 22 Feb 2024 10:10:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 684305.1064060; Thu, 22 Feb 2024 10:10:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rd62c-0004A8-GH; Thu, 22 Feb 2024 10:10:58 +0000 Received: by outflank-mailman (input) for mailman id 684305; Thu, 22 Feb 2024 10:10:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rd62b-0004A2-Do for xen-devel@lists.xenproject.org; Thu, 22 Feb 2024 10:10:57 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ab3218bf-d16a-11ee-8a55-1f161083a0e0; Thu, 22 Feb 2024 11:10:56 +0100 (CET) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a3e550ef31cso165303366b.3 for ; Thu, 22 Feb 2024 02:10:56 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id m12-20020a170906160c00b00a3d0a094574sm5776908ejd.66.2024.02.22.02.10.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 02:10:55 -0800 (PST) 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: ab3218bf-d16a-11ee-8a55-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1708596656; x=1709201456; 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=nqfegFgQFplvZynzmmWeCSQTM2EV90XkHsxyRQ1eDf0=; b=TkRGuabBYq0zUVPOziQhkmz6VBpUu849Yh8+cmq999F2DeKxcYGTwB/pflIEmXFH6X 1LV55TbICWuv8F4hcncTyurRE4+xR2RkPNm/xCp/xa6BYCflDdfIzFG8IzVZ4VgpKmkI /HoNGn9z48+7cmUtHxSofR5rQ5po4o+tKeJr0bUhBbGlt3Pz685Y7ZI0nUfLbNtLasMo 5d0iggW23lVtH8dvC6UYkWzHYB0Rtg/ChzHdyMj+Hhvb9axUlUhS48ZGQvqAhD/IaZwj l6LUg2eE4COaxEbQfO6RsOGUkCvQBMPJYhGSfmuXfYN+0nJ1b1z0iM2ZqWvfH6EmKTDO Od8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708596656; x=1709201456; 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=nqfegFgQFplvZynzmmWeCSQTM2EV90XkHsxyRQ1eDf0=; b=GtR8uV8H64BLjoVFpelvWvE83qGPt7q3oIsa1PjuYsBElfJ6COLMphVFblzza2nBGw wBGlx2tE0wKrkWcfjqs1+W7NcrJvzc12UbCT7TmkV5Q5Ml72zJwnIC+C2l++tNqyVUld auMU9BqsEkATZBoYNmN4/bmsfcrfuIJ4bWh3CPxgDgE311Q41nG5ATwzjM3jzf7t/Izi vcZhEWB8Kw37NE3KHy+I6BCsuydfz3EozFGRNOHJafBN8JoAT4jaB0nb4PyxJ2wzGpyV Gf16Rlh7UnmBlQT8fctujJVYyUuX8MUckPzZmFvzhueNuLLX8PZWQ8CaWhevQEfZ9cCB zO2A== X-Forwarded-Encrypted: i=1; AJvYcCV1JMB/PE2v97TxcdiXWKpqZ/j7z2mtOtN/j7AtNqgz5Vvyfosi2tlpiQLsC2XL+xpTs7AnvC+t3L2Hs4z/v9qcXP5evx9WnaNocZg8ekw= X-Gm-Message-State: AOJu0Yz2R8vFwLVOoUv+kIpiNsRm3JCgyJkXzVb8WRUTTD/gCD96GUKy +Y9yF3+B8jrgsk4PrySb0tYtXPv8G2pyjJM9h89YINSemtY5m0VZZcdO0FJWzg== X-Google-Smtp-Source: AGHT+IFYPi2B9ry2vTe6Wv7cu8R4GmHVtb7g/vMCNahOOCm26CiN6dbX+LS62/w/Z3ZQ+GeixxcI5g== X-Received: by 2002:a17:906:46ce:b0:a3e:42cf:f6ae with SMTP id k14-20020a17090646ce00b00a3e42cff6aemr7289413ejs.19.1708596656056; Thu, 22 Feb 2024 02:10:56 -0800 (PST) Message-ID: Date: Thu, 22 Feb 2024 11:10:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] x86/hpet: use an atomic add instead of a cmpxchg loop Content-Language: en-US To: Roger Pau Monne Cc: Andrew Cooper , Wei Liu , xen-devel@lists.xenproject.org References: <20240222090530.62530-1-roger.pau@citrix.com> <20240222090530.62530-3-roger.pau@citrix.com> From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR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ujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <20240222090530.62530-3-roger.pau@citrix.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 22.02.2024 10:05, Roger Pau Monne wrote: > The usage of a cmpxchg loop in hpet_get_channel() is unnecessary, as the same > can be achieved with an atomic increment, which is both simpler to read, and > avoid any need for a loop. > > Note there can be a small divergence in the channel returned if next_channel > overflows, but returned channel will always be in the [0, num_hpets_used) > range, and that's fine for the purpose of balancing HPET channels across CPUs. > This is also theoretical, as there's no system currently with 2^32 CPUs (as > long as next_channel is 32bit width). The code change looks good to me, but I fail to see the connection to 2^32 CPUs. So it feels like I'm missing something, in which case I'd rather not offer any R-b. Jan > Signed-of-by: Roger Pau Monné > --- > xen/arch/x86/hpet.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c > index d982b0f6b2c9..4777dc859d96 100644 > --- a/xen/arch/x86/hpet.c > +++ b/xen/arch/x86/hpet.c > @@ -458,11 +458,7 @@ static struct hpet_event_channel *hpet_get_channel(unsigned int cpu) > if ( num_hpets_used >= nr_cpu_ids ) > return &hpet_events[cpu]; > > - do { > - next = next_channel; > - if ( (i = next + 1) == num_hpets_used ) > - i = 0; > - } while ( cmpxchg(&next_channel, next, i) != next ); > + next = arch_fetch_and_add(&next_channel, 1) % num_hpets_used; > > /* try unused channel first */ > for ( i = next; i < next + num_hpets_used; i++ )