Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6848064rdb; Fri, 15 Dec 2023 09:47:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWFpe3APlZODol20yltJ4MX/wFTWyyGq7Z0KbvePn72rS2+VYdXcNHOpbNa0F4uvz2siQC X-Received: by 2002:a05:6e02:1986:b0:35d:6121:3794 with SMTP id g6-20020a056e02198600b0035d61213794mr19470836ilf.54.1702662475498; Fri, 15 Dec 2023 09:47:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662475; cv=none; d=google.com; s=arc-20160816; b=cA4iyw2AZRnRq03qH1Yjs8kXDfQw8zqThDHwUsT2zNd2Ef2g1Ucpqzg+2SSBfkMQdJ KPCIzP2whYm2RR7yRl4ydjJhImyyEowrLXWScLl/Dmzuwc/35lpXDFwksBd8pT7LNw+a TIMEJrbroY0ZLSzngtxLG5dBe9qCzxsTNkc5UkaXp5V77MhEZSt4nhapa2ukqto2cE0W PrXQnlI73Yt14UiqvPM7Bhx0wd9+bQno/mwG1kbMnTPsInVk8BDQYWlARV19keUKgIRx WeM2i0S5Eo22ihJg+tCuGCSZkP591Yd4oXVKYQ+A/AMN33ppUTuRcxccw4xoIpi/DyEY mHxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=zUALBSM4ZeCOl8uEFeqXcjWj4PEF6lLp+utpoWOXGn4=; fh=B41BSS80/g48MVbql1jW7CCXTAGMSWslnmHIfPLpVL4=; b=z4a+xjybfxjPCkB+cyR/H230jSEinQA4VVp7vjiHf16Jcf1IR3Z8i6S0e1It91cEpE Da9bmDYRbFheHkHkQxf/3QW8/qOjX5YHXq8mMDcS9OgRsnl1E2YqiFF1BFI5xL95ksvj OWbg6i7xTvmqTuBGpQQgBscYsYVB6+G8ZpFqmhtN2OH1NTHDNBc5pgzKmRXt1MnNh7pK UEDOs3QNvB6WA/wD+yvsSYas/8VIo27l5/eRfSAKKwsh8ZylxtacV12WFgyXVc4toaWR vHDkxPG6N49VbJoVsWVLfqZS6YfjfnCOWL/P+YDo29WN2uymbk+zc98U6CtrNKULuvsb q1UA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z12-20020a65610c000000b005c21538543esi12925770pgu.433.2023.12.15.09.47.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:47:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D756FB223D2 for ; Fri, 15 Dec 2023 17:46:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E4B6495D6; Fri, 15 Dec 2023 17:44:32 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A00F147F71 for ; Fri, 15 Dec 2023 17:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3D7A4C15; Fri, 15 Dec 2023 09:45:15 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D9783F5A1; Fri, 15 Dec 2023 09:44:27 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, Babu Moger Subject: [PATCH v8 09/24] x86/resctrl: Use __set_bit()/__clear_bit() instead of open coding Date: Fri, 15 Dec 2023 17:43:28 +0000 Message-Id: <20231215174343.13872-10-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231215174343.13872-1-james.morse@arm.com> References: <20231215174343.13872-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The resctrl CLOSID allocator uses a single 32bit word to track which CLOSID are free. The setting and clearing of bits is open coded. Convert the existing open coded bit manipulations of closid_free_map to use __set_bit() and friends. These don't need to be atomic as this list is protected by the mutex. Signed-off-by: James Morse Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- Changes since v6: * Use the __ inatomic helpers and add lockdep_assert_held() annotations to document how this is safe. * Fixed a resctrl_closid_is_free()/closid_allocated() rename in the commit message. * Use RESCTRL_RESERVED_CLOSID to improve readability. Changes since v7: * Removed paragraph explaining why this should be done now due to badword 'subsequent'. * Changed a comment to refer to RESCTRL_RESERVED_CLOSID. --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 12a557c96100..f6b52415ca3d 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -111,7 +111,7 @@ void rdt_staged_configs_clear(void) * - Our choices on how to configure each resource become progressively more * limited as the number of resources grows. */ -static int closid_free_map; +static unsigned long closid_free_map; static int closid_free_map_len; int closids_supported(void) @@ -130,8 +130,8 @@ static void closid_init(void) closid_free_map = BIT_MASK(rdt_min_closid) - 1; - /* CLOSID 0 is always reserved for the default group */ - closid_free_map &= ~1; + /* RESCTRL_RESERVED_CLOSID is always reserved for the default group */ + __clear_bit(RESCTRL_RESERVED_CLOSID, &closid_free_map); closid_free_map_len = rdt_min_closid; } @@ -139,17 +139,21 @@ static int closid_alloc(void) { u32 closid = ffs(closid_free_map); + lockdep_assert_held(&rdtgroup_mutex); + if (closid == 0) return -ENOSPC; closid--; - closid_free_map &= ~(1 << closid); + __clear_bit(closid, &closid_free_map); return closid; } void closid_free(int closid) { - closid_free_map |= 1 << closid; + lockdep_assert_held(&rdtgroup_mutex); + + __set_bit(closid, &closid_free_map); } /** @@ -161,7 +165,9 @@ void closid_free(int closid) */ static bool closid_allocated(unsigned int closid) { - return (closid_free_map & (1 << closid)) == 0; + lockdep_assert_held(&rdtgroup_mutex); + + return !test_bit(closid, &closid_free_map); } /** -- 2.20.1