Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2748298rda; Wed, 25 Oct 2023 11:05:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENFbuMoyUHQZawb5AvMjrASFXOASP+nV78AW7XbrGvjyz6g+Z0GXM7alon+04e69jiS/Yb X-Received: by 2002:a25:d8cc:0:b0:d9a:45d7:4eae with SMTP id p195-20020a25d8cc000000b00d9a45d74eaemr19404213ybg.62.1698257155342; Wed, 25 Oct 2023 11:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698257155; cv=none; d=google.com; s=arc-20160816; b=KbcaIC/XpuyJyIm+WFY8SF6uK+kAP4BEYeAL0preoKhByde5n62FO/7NZGRHjxiIxt VH5EhQVuUlnVH1Cpnj94hpiMGr5rU0BDSfCRtZFWlBnEvL2tJrQyIGLCYo/xjKN3Fhm7 S4G2+VFTyqDgNnOI3a/cdhmAfsY43q2LJvYupH6c+C/2CaFQUcemR9a79gzHS4dPzG1x ZQMcMzrS10qe9wjjvWLBnocehd6ut52dn9YPvCFIHVEJvm+9t/AFHvgufObQQT3+kEbh DM5qGihPWZOl3AgW1cQ8I09g+hRU7NdlHhzNULIVbgAJsXYxewD4p4JRbdDRzcqo4efY XCNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eWG9pymiSYaszC9Q3qw3JpRdb95SwHJ9SQ4hZB3IINo=; fh=66J7Y+TGxNFNx8VjvpfZFFUqd7hqgnmmrifbhuLe8jE=; b=JeoRoH/k5G8ffdby8IAds2VTkpUTfHSn0N07RKu/nYwCJhBOn59F2CQSNmRZk6JcL/ 8hTaTVSz13wfzvkvgIysM30DXdgpMdVcXM+qepjkagopQ5iiPOAVRiYBBwIXCkPgfRIQ 0P7eKxdDgIhttWCmrEtbUhQt4JESQKj4hFDXXgkWXGwKlSIrOwi80PRts32kjTcO2ByM DzmVY7pHteuNh93wJdEcJxwbc9k1/RTDUIaPF3MfMvCgZQcZQH6bHmIKrNvNq55QCbQk vG6xCD6nnF8cqJeiVQx1vxdrHjRapB3iIecirYNQXFeaO6oXkHq+zSOLK7xw6gu9RBLB qCjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i13-20020a25d10d000000b00d9abe0659f4si12155394ybg.138.2023.10.25.11.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 11:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5D30F811F92F; Wed, 25 Oct 2023 11:05:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234920AbjJYSFj (ORCPT + 99 others); Wed, 25 Oct 2023 14:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234825AbjJYSFS (ORCPT ); Wed, 25 Oct 2023 14:05:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BA8110D0 for ; Wed, 25 Oct 2023 11:05:11 -0700 (PDT) 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 C2CE41480; Wed, 25 Oct 2023 11:05:52 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0A7933F738; Wed, 25 Oct 2023 11:05:07 -0700 (PDT) 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 Subject: [PATCH v7 09/24] x86/resctrl: Use __set_bit()/__clear_bit() instead of open coding Date: Wed, 25 Oct 2023 18:03:30 +0000 Message-Id: <20231025180345.28061-10-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231025180345.28061-1-james.morse@arm.com> References: <20231025180345.28061-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 25 Oct 2023 11:05:44 -0700 (PDT) The resctrl CLOSID allocator uses a single 32bit word to track which CLOSID are free. The setting and clearing of bits is open coded. A subsequent patch adds closid_allocated(), which adds more open coded bitmaps operations. These will eventually need changing to use the bitops helpers so that a CLOSID bitmap of the correct size can be allocated dynamically. 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. Tested-by: Shaopeng Tan Tested-by: Peter Newman Reviewed-by: Shaopeng Tan Signed-off-by: James Morse --- 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. --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index 9864cb49d58c..f6051a3e7262 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) @@ -131,7 +131,7 @@ 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; + __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.39.2