From nobody Sat May 11 18:03:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1708592838; cv=none; d=zohomail.com; s=zohoarc; b=BMtwRDq/S0A5VEUnszr/uejc+ii7i9BNhlcOfvYUN1Tf+hvsloLNFPDDySXfJ9p8ClvHosy3yoMUzF/JfA2bGJjKEELzXPRyzF0+F0fJHXGuAkVaJ/Ch1nEs5BPe1y5rz17D8op9Plq0WzyagKh70hBW1JM6ixjPGfua6GUriew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708592838; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bH2mQPDEXai+re4kmllotrxpSIRK6T6FaHn93utR0MA=; b=OCzytMRi7qK+FFwbPkTfTqqvYfxv4GWwRf1PqUROwhMiTTHm9QyttH7jJ4fSn54msEI9+ikfqz4mIFxhuIiF8S8LWXWP64/dSP45LtqC2C+k0Rn1uaY4Vvk3y8vd1oYovZfOZFKZpqJQ4kQq1aW2LYUmwitbhQS57M0SgUYwqP8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1708592838022989.8637280569036; Thu, 22 Feb 2024 01:07:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.684258.1063985 (Exim 4.92) (envelope-from ) id 1rd52a-0007hV-EM; Thu, 22 Feb 2024 09:06:52 +0000 Received: by outflank-mailman (output) from mailman id 684258.1063985; Thu, 22 Feb 2024 09:06:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rd52a-0007ge-AT; Thu, 22 Feb 2024 09:06:52 +0000 Received: by outflank-mailman (input) for mailman id 684258; Thu, 22 Feb 2024 09:06:51 +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 1rd52Z-0007eV-Li for xen-devel@lists.xenproject.org; Thu, 22 Feb 2024 09:06:51 +0000 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [2a00:1450:4864:20::134]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b73d0d3c-d161-11ee-8a55-1f161083a0e0; Thu, 22 Feb 2024 10:06:51 +0100 (CET) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-512be6fda52so4687372e87.0 for ; Thu, 22 Feb 2024 01:06:51 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id fa27-20020a05600c519b00b004128812dcb6sm1172138wmb.28.2024.02.22.01.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:06:49 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: b73d0d3c-d161-11ee-8a55-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1708592810; x=1709197610; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bH2mQPDEXai+re4kmllotrxpSIRK6T6FaHn93utR0MA=; b=Jjfj6KJsT+4Bn3V6yBgQeTeQFryg49hEUkmx70T1hp7w0ayV3tS/NWsVnu0dQ8uIfC GHJv1GsrrzWPPbD8Hu7H3KSuPQEsOOKiBQKr0eeq4nC2xKAECEr/ChcDzrlZqsBcORXq vXh8lpuot5pAz88YVQjpyIg9Qma4xrYsIuEQg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708592810; x=1709197610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bH2mQPDEXai+re4kmllotrxpSIRK6T6FaHn93utR0MA=; b=XBF7L0wK6y72Bu9Lmm1TmjtxUUMGiarpH5RQxhSH0AAgpiYVuZOnyx1ptg7jFVCXZs clLelE3hNMtdGkXQzWvFi/SgwYD8fzMjLk21xFoIo0xbvkFB0WFPM8T4k50c62PUVrXr jObQtp+z+RNKAnM3dsCN/mwbP0rp6ytSNZmjRSXAxwJpXxzxoj6Y7/novLTea3foGV6w X/bWQao1MiStUW8bRbhNGqMgnV7EHWwK8OVtRVZktxEkLY8GW+zL67d/PDuM4gIa8fzP anphTgTn5rqDLNdbRbQVfxWX/PTzcv2DeKIyiXGWiQPFJ0nK+wYDwrXvJAuAJERY7Rtu IDig== X-Gm-Message-State: AOJu0YyEWxCkxy5ZGe3lUnzPP52nhbsj6AmLcJ7rRV4pIKikQoBVI3bn v1nanrgcjD+EVzTxheX7Qvfs2uxlG8KRQT0FpajZBRULg2bld8hZimvo2BGCzldLmphnqahHUit 3 X-Google-Smtp-Source: AGHT+IEVOhWolRmh36S3w5sq/YHv1CBFSFLI/qadi605FiMuwznoTB0h/XtNqavitfnG68w/Z8bmEw== X-Received: by 2002:a05:6512:12c3:b0:511:8d49:4b4f with SMTP id p3-20020a05651212c300b005118d494b4fmr16125552lfg.6.1708592809958; Thu, 22 Feb 2024 01:06:49 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Tamas K Lengyel , Jan Beulich , Andrew Cooper , George Dunlap , Wei Liu Subject: [PATCH 1/2] x86/memsharing: use an atomic add instead of a cmpxchg loop Date: Thu, 22 Feb 2024 10:05:29 +0100 Message-ID: <20240222090530.62530-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222090530.62530-1-roger.pau@citrix.com> References: <20240222090530.62530-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1708592840016100001 The usage of a cmpxchg loop in get_next_handle() 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. The cmpxchg usage is likely a remnant of 32bit support, which didn't have an instruction to do an atomic 64bit add, and instead a cmpxchg had to be used. Suggested-by: Andrew Cooper Signed-of-by: Roger Pau Monn=C3=A9 Acked-by: Tamas K Lengyel Reviewed-by: Jan Beulich Reviewed-by: Julien Grall --- xen/arch/x86/mm/mem_sharing.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index 4f810706a315..fe299a2bf9aa 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -179,13 +179,7 @@ static void mem_sharing_page_unlock(struct page_info *= pg) =20 static shr_handle_t get_next_handle(void) { - /* Get the next handle get_page style */ - uint64_t x, y =3D next_handle; - do { - x =3D y; - } - while ( (y =3D cmpxchg(&next_handle, x, x + 1)) !=3D x ); - return x + 1; + return arch_fetch_and_add(&next_handle, 1) + 1; } =20 static atomic_t nr_saved_mfns =3D ATOMIC_INIT(0); --=20 2.43.0 From nobody Sat May 11 18:03:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1708592840; cv=none; d=zohomail.com; s=zohoarc; b=WIbN+VOm76wpBPQ4WEjb2R+uwxh+t4Q3XyPzbixgif/ti1HM4IK2DWZkg/y3T8khLPM7jD8jYieSTVlbwYvWRblu88brRPPr0wFd5KbpOk2dg045BEqhhZJY5NjHoNFQitQ67M0RvFj75/hB9HBBLofBRj7pIuzfzv+GnDzNe1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708592840; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KyY62PKoEMOxefDcZ5yAyBP77/0u5doyNW7ljPYkb9c=; b=TspvKe6tI7vRTQzuxOdfKWVTSCEt+VzGiVSjcehkIRZ2sRCK7EGbTDzXUyfUGtaAcDEZHQR/tzjEEHv9OsmlwG8kK2MT5LO8wC6FLU+3tVLmdF4W9HdSdFY5nWXNl5LOjAjAXtJOgTwMnBsMh79e9wJx4WhdDZfkYkPSBTj80p8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1708592840247660.8728639290089; Thu, 22 Feb 2024 01:07:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.684259.1064000 (Exim 4.92) (envelope-from ) id 1rd52d-00088a-QH; Thu, 22 Feb 2024 09:06:55 +0000 Received: by outflank-mailman (output) from mailman id 684259.1064000; Thu, 22 Feb 2024 09:06:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rd52d-00088P-MN; Thu, 22 Feb 2024 09:06:55 +0000 Received: by outflank-mailman (input) for mailman id 684259; Thu, 22 Feb 2024 09:06:54 +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 1rd52c-00087Q-JV for xen-devel@lists.xenproject.org; Thu, 22 Feb 2024 09:06:54 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b80a6e5c-d161-11ee-98f5-efadbce2ee36; Thu, 22 Feb 2024 10:06:52 +0100 (CET) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2d21cdbc85bso21242421fa.2 for ; Thu, 22 Feb 2024 01:06:52 -0800 (PST) Received: from localhost ([213.195.118.74]) by smtp.gmail.com with ESMTPSA id bj13-20020a0560001e0d00b0033d926bf7b5sm1243304wrb.76.2024.02.22.01.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 01:06:50 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: b80a6e5c-d161-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1708592811; x=1709197611; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KyY62PKoEMOxefDcZ5yAyBP77/0u5doyNW7ljPYkb9c=; b=FJM57vDYmMbbustH6UW/uv3X/ELhxzTk6neugH5/jwkvsUormaaJ4Y906RA/VW5aUa Vt8FzkRtiGp02/1XAMNdJrLyaCRAELkjk6i5N6Aqa45XzD1AIoLJLdYOkQuCT+EBziaY eBQrJsV6wY+4eFWF6omBkMa/AZ5PC9t8lifN8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708592811; x=1709197611; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KyY62PKoEMOxefDcZ5yAyBP77/0u5doyNW7ljPYkb9c=; b=YNDZiDjRJuk+j7n/rIEn4j5Ind1HZYlivw3QjOCXisGioZi/C6jzwP2pbYn0xpaCVK OGNFlFi4xkJljfkteYlmqlvzRUFEcOMyvSa8P4SmHQKu+WP7fGd2kUlA+8OyZksjj2kV x1MstY4pVAdkkf4swN7M6sGHJWrDN5AzR9iBZKv5wUVxhhZoBIJhTVRrydZB2kF29T/+ 5PvlpmdNI0lNZ2NXoYgt0hitiX1JKHoqxxqpuntyLM2J+6uR+gxCrRyLKQJq/Cx5vqI5 wPJYNVukQwbnG9ZzldJbu919l64h44RzzjtXxws5HAxjsRfN4vJB/cbMqWe61agFvUr1 sj4w== X-Gm-Message-State: AOJu0YxB7rRP1Mz/4wk01YMPF8Qsh2oxL1dcRqmkJgEyS/ayBLbJ3lyO 2UzBeTizOQbLNDFkI8fVskkwbcmUklABNanAfTfT/QX1waMsIUan3bH6q8/MdAgdZv1YoLoSu+H o X-Google-Smtp-Source: AGHT+IH0LcjYx+aEuc0oDfHapt2lkKd4+JT9s/wqOVAcCMosCzuSAIkK0yHnfTo1EzuGmanEP66ulg== X-Received: by 2002:a2e:300d:0:b0:2d2:39fa:822c with SMTP id w13-20020a2e300d000000b002d239fa822cmr6653432ljw.35.1708592811460; Thu, 22 Feb 2024 01:06:51 -0800 (PST) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Jan Beulich , Andrew Cooper , Wei Liu Subject: [PATCH 2/2] x86/hpet: use an atomic add instead of a cmpxchg loop Date: Thu, 22 Feb 2024 10:05:30 +0100 Message-ID: <20240222090530.62530-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240222090530.62530-1-roger.pau@citrix.com> References: <20240222090530.62530-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1708592841973100004 The usage of a cmpxchg loop in hpet_get_channel() is unnecessary, as the sa= me 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 CP= Us. This is also theoretical, as there's no system currently with 2^32 CPUs (as long as next_channel is 32bit width). Signed-of-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich Reviewed-by: Julien Grall --- 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(uns= igned int cpu) if ( num_hpets_used >=3D nr_cpu_ids ) return &hpet_events[cpu]; =20 - do { - next =3D next_channel; - if ( (i =3D next + 1) =3D=3D num_hpets_used ) - i =3D 0; - } while ( cmpxchg(&next_channel, next, i) !=3D next ); + next =3D arch_fetch_and_add(&next_channel, 1) % num_hpets_used; =20 /* try unused channel first */ for ( i =3D next; i < next + num_hpets_used; i++ ) --=20 2.43.0