Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2742244rda; Wed, 25 Oct 2023 10:57:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcqPQusnwDOjdszfVb03ZxETjGTTB3YGkvCRrLASNe7oOq/9KXilTviuyqNAXib80P0/xl X-Received: by 2002:a25:8585:0:b0:d9a:4870:7943 with SMTP id x5-20020a258585000000b00d9a48707943mr15806711ybk.28.1698256622695; Wed, 25 Oct 2023 10:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698256622; cv=none; d=google.com; s=arc-20160816; b=XAVjrr0Z7pj2MME5F3FBkB7H1RwgXBtDZ5r0Z+YX7CV2R4b6PY1zHtbGTvY91xLpXy +QWDI4M5y23sJGRlu7mrQI+2MYontGId78Gajl3E52q2Y0oRuFIiDKIBageBYg1rdJgb D8vD2wytGzDHrkV1RAdMhaCOUwfG847gumr+xt29pPKJHi/lrzyw07qoB9Pj+sIlPRqO +nKzXzNvhS7ODAKQVAyzFCs99crhxvcUOTGhf4jB2YdRqJMSdkGBhNavqPEt0nVAHpG7 vPtVtaN+nHIfL/FcD1YAkULoy7kNLcB1pytkl6IZzANfbTcRuEmSoqRjzL7yyIhbg5GR 4Nkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Wpp+B7ZuFJ0dQyQ17dQzBiPv3iItnH+/TO8JZ4QkD0I=; fh=9O97hdzEezSdAQ/hEUF6K6/7TfN/3Uf0QBPpPtoaJ2Y=; b=s1jrjeAhllb4ARuCVZqloJj3EfKMOw39rbUou9IlW16AGl7EezMDeyIAz3dhkF4uPk 8nLUSaY4GL3teoDdmjms+LUhWMrhNw8FLdbV9IsBS5gMfFcJQO9vgJ4t7lsWNJQMixS0 ZpFCVjkqVJ7BNoKQTKglPcg4Wdx3wXP/HM/5eIIbeJMkGLS3vMhmaZpFf/+8TDpWdkq0 RnlBeIn1l9TTLcIhE3Vd/9GEZze9+q4UlVJvKeNie0MNaY+buR9wnco8m9sR6DB4r2Yn P2ZiyAATV/FEd9x07LWDP4HtFoie+NNyAYa+k7kYX2e1Cgh6m+UrCWFzp2k3pOCK3i/B x2xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id e65-20020a251e44000000b00d8d3b231a75si11554375ybe.733.2023.10.25.10.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 52B9A8023A0C; Wed, 25 Oct 2023 10:56:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbjJYR41 (ORCPT + 99 others); Wed, 25 Oct 2023 13:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbjJYR4Z (ORCPT ); Wed, 25 Oct 2023 13:56:25 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 48AC418C for ; Wed, 25 Oct 2023 10:56:23 -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 9A3BFC15; Wed, 25 Oct 2023 10:57:04 -0700 (PDT) Received: from [10.1.197.60] (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 677EE3F738; Wed, 25 Oct 2023 10:56:20 -0700 (PDT) Message-ID: <890b7d07-575d-c18c-bd65-ea71c3472000@arm.com> Date: Wed, 25 Oct 2023 18:56:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v6 10/24] x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid Content-Language: en-GB To: babu.moger@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com References: <20230914172138.11977-1-james.morse@arm.com> <20230914172138.11977-11-james.morse@arm.com> <2b5e62a3-3b5c-c98a-6b5e-909a021a8d4e@amd.com> From: James Morse In-Reply-To: <2b5e62a3-3b5c-c98a-6b5e-909a021a8d4e@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 10:56:37 -0700 (PDT) Hi Babu, On 05/10/2023 21:13, Moger, Babu wrote: > On 9/14/2023 12:21 PM, James Morse wrote: >> MPAM's PMG bits extend its PARTID space, meaning the same PMG value can be >> used for different control groups. >> >> This means once a CLOSID is allocated, all its monitoring ids may still be >> dirty, and held in limbo. >> >> Instead of allocating the first free CLOSID, on architectures where >> CONFIG_RESCTRL_RMID_DEPENDS_ON_COSID is enabled, search >> closid_num_dirty_rmid[] to find the cleanest CLOSID. >> >> The CLOSID found is returned to closid_alloc() for the free list >> to be updated. >> diff --git a/arch/x86/kernel/cpu/resctrl/internal.h >> b/arch/x86/kernel/cpu/resctrl/internal.h >> index ad6e874d9ed2..f06d3d3e0808 100644 >> --- a/arch/x86/kernel/cpu/resctrl/internal.h >> +++ b/arch/x86/kernel/cpu/resctrl/internal.h >> @@ -558,5 +558,7 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource *r); >>   void __init thread_throttle_mode_init(void); >>   void __init mbm_config_rftype_init(const char *config); >>   void rdt_staged_configs_clear(void); >> +bool closid_allocated(unsigned int closid); >> +int resctrl_find_cleanest_closid(void); >>     #endif /* _ASM_X86_RESCTRL_INTERNAL_H */ >> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c >> index 0c783301d106..0bbed8c62d42 100644 >> --- a/arch/x86/kernel/cpu/resctrl/monitor.c >> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c >> @@ -388,6 +388,48 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 closid) >>       return ERR_PTR(-ENOSPC); >>   } >>   +/** >> + * resctrl_find_cleanest_closid() - Find a CLOSID where all the associated >> + *                                  RMID are clean, or the CLOSID that has >> + *                                  the most clean RMID. >> + * >> + * MPAM's equivalent of RMID are per-CLOSID, meaning a freshly allocated CLOSID >> + * may not be able to allocate clean RMID. To avoid this the allocator will >> + * choose the CLOSID with the most clean RMID. >> + * >> + * When the CLOSID and RMID are independent numbers, the first free CLOSID will >> + * be returned. >> + */ >> +int resctrl_find_cleanest_closid(void) >> +{ >> +    u32 cleanest_closid = ~0, iter_num_dirty; > > Just naming num_dirty should have been fine.  I will leave it you. That was to make it obvious its something to do with the loop, so the value can't be relied on outside that. I'll rename it and move the declaration into the loop, that way its out of scope if someone tries to use it later. >> +    int i = 0; >> + >> +    lockdep_assert_held(&rdtgroup_mutex); >> + >> +    if (!IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) >> +        return -EIO; >> + >> +    for (i = 0; i < closids_supported(); i++) { >> +        if (closid_allocated(i)) >> +            continue; >> + >> +        iter_num_dirty = closid_num_dirty_rmid[i]; >> +        if (iter_num_dirty == 0) >> +            return i; >> + >> +        if (cleanest_closid == ~0) >> +            cleanest_closid = i; >> + >> +        if (iter_num_dirty < closid_num_dirty_rmid[cleanest_closid]) >> +            cleanest_closid = i; >> +    } >> + >> +    if (cleanest_closid == ~0) >> +        return -ENOSPC; >> +    return cleanest_closid; > > Line before the return looks clean. > > *       if (cleanest_closid == ~0) > +        return -ENOSPC; > + > +    return cleanest_closid; Sure, Thanks, James