From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0827D21638D for ; Thu, 18 Dec 2025 13:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766065368; cv=none; b=RbhOs7tl3/E8+IKS93uZfgw9cylyUAqU7QhWPPYQsyZE8LGW7q3QTqnZ4M3FrkYwZQzkCc7YeBcvTRm+TAC6v8MPTAqlplBMT9+nCxheqEOG3vWkTctbQqFn+6rZtked0pI8NbLveGg1cihYGcchWoeXB5Jzk2rDth5Jy8PPTf4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766065368; c=relaxed/simple; bh=bN0IsLxyYpCoLUtppOx8knptNlSPx9CdqJ3xcREo5mU=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CiDMidZ8ozJqlQm7hXTrFhJsH+BngocG41cil6Xpqnm/2EhvG66hCILGXoOzski8rhCHEJTYSVm3NDKJ6rx12NCJaZRkekNI/HyAu0M9n8Vyk7LXwNEgvGeDcoi4p16jtJNVgwWCLKsn2ZJwO7vk/JVC22oVCOe9KtD3AmZ99d8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.224.107]) by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4dXBfr4r26zJ46Zm; Thu, 18 Dec 2025 21:42:12 +0800 (CST) Received: from dubpeml100005.china.huawei.com (unknown [7.214.146.113]) by mail.maildlp.com (Postfix) with ESMTPS id B04C540576; Thu, 18 Dec 2025 21:42:43 +0800 (CST) Received: from localhost (10.203.177.15) by dubpeml100005.china.huawei.com (7.214.146.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Thu, 18 Dec 2025 13:42:42 +0000 Date: Thu, 18 Dec 2025 13:42:40 +0000 From: Jonathan Cameron To: James Morse CC: , , D Scott Phillips OS , , , , , , Jamie Iles , "Xin Hao" , , , , David Hildenbrand , Dave Martin , Koba Ko , Shanker Donthineni , , , Gavin Shan , Ben Horgan , , , Punit Agrawal Subject: Re: [RFC PATCH 21/38] arm_mpam: resctrl: Pre-allocate assignable monitors Message-ID: <20251218134240.00000a96@huawei.com> In-Reply-To: <20251205215901.17772-22-james.morse@arm.com> References: <20251205215901.17772-1-james.morse@arm.com> <20251205215901.17772-22-james.morse@arm.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500011.china.huawei.com (7.191.174.215) To dubpeml100005.china.huawei.com (7.214.146.113) On Fri, 5 Dec 2025 21:58:44 +0000 James Morse wrote: > When there are not enough monitors, MPAM is able to emulate ABMC by making > a smaller number of monitors assignable. These monitors still need to be > allocated from the driver, and mapped to whichever control/monitor group > resctrl wants to use them with. > > Add a second array to hold the monitor values indexed by resctrl's > cntr_id. > > When CDP is in use, two monitors are needed so the available number of > counters halves. Platforms with one monitor will have zero monitors > when CDP is in use. > > Signed-off-by: James Morse > diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c > index de5220fed97d..f607feaf0126 100644 > --- a/drivers/resctrl/mpam_resctrl.c > +++ b/drivers/resctrl/mpam_resctrl.c > @@ -806,6 +863,41 @@ static int mpam_resctrl_pick_domain_id(int cpu, struct mpam_component *comp) > return comp->comp_id; > } > > +/* > + * This must run after all event counters have been picked so that any free > + * running counters have already been allocated. > + */ > +static int mpam_resctrl_monitor_init_abmc(struct mpam_resctrl_mon *mon) > +{ > + struct mpam_resctrl_res *res = &mpam_resctrl_controls[RDT_RESOURCE_L3]; > + size_t array_size = resctrl_arch_system_num_rmid_idx() * sizeof(int); > + int *rmid_array __free(kfree) = kmalloc(array_size, GFP_KERNEL); kcalloc? Given you call it an array I assume it is one. Will zero though and if you really care about optimizing that out add a comment. Move this... > + struct rdt_resource *l3 = &res->resctrl_res; > + struct mpam_class *class = mon->class; > + u16 num_mbwu_mon; > + > + if (mon->mbwu_idx_to_mon) { > + pr_debug("monitors free running\n"); > + return 0; > + } Down to here. See cleanup.h notes that summarize how much Linus doesn't want people not declaring these inline because of how much it hurts readability. > + > + if (!rmid_array) { > + pr_debug("Failed to allocate RMID array\n"); > + return -ENOMEM; > + } > + memset(rmid_array, -1, array_size); > + > + num_mbwu_mon = class->props.num_mbwu_mon; > + mon->assigned_counters = __alloc_mbwu_array(mon->class, num_mbwu_mon); > + if (IS_ERR(mon->assigned_counters)) > + return PTR_ERR(mon->assigned_counters); > + mon->mbwu_idx_to_mon = no_free_ptr(rmid_array); > + > + mpam_resctrl_monitor_sync_abmc_vals(l3); > + > + return 0; > +} > + > static void mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon, > enum resctrl_event_id type) > { > @@ -847,6 +939,16 @@ static void mpam_resctrl_monitor_init(struct mpam_resctrl_mon *mon, > * space. > */ > l3->mon.num_rmid = 1; > + > + switch (type) { > + case QOS_L3_MBM_LOCAL_EVENT_ID: > + case QOS_L3_MBM_TOTAL_EVENT_ID: > + mpam_resctrl_monitor_init_abmc(mon); > + > + return; > + default: > + return; > + } > } > } >