Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp670982lqb; Wed, 17 Apr 2024 07:42:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLcz/glQpHs8M+TwDpn1ikzLSz9obnjE5ucGl+aU8ZFP+jNPs47E+s3AMP6fgaVUa9XwaAihYff+HgMzxWAPBa2dPLAP2G/2BWOacsYA== X-Google-Smtp-Source: AGHT+IFsZr6/0cA5XHbicqPFQSwzhzJPDBfPHd23eyjm2KJjJIdYIO3t99wFkHcH23RQuCxWYXME X-Received: by 2002:a17:90a:6046:b0:2a2:c5:8b with SMTP id h6-20020a17090a604600b002a200c5008bmr13728479pjm.3.1713364949483; Wed, 17 Apr 2024 07:42:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713364949; cv=pass; d=google.com; s=arc-20160816; b=0gf3D0FoCyCMbrozhXethL/oFkzQeUfhzIweKNqWx2TQQSvQDqICvxMUkg6RN/A4Jf CPB949khZsQM/1YhbsxEKQpHueK6QO7ze8yI7FDAvBYPPFVpa7chc1x6jacJpQsiHrcx fiGL1f2fiDisH2YIqcJziQHGOuapHdO1Vl8tym1k+Lvm+q6wsH9Ow+aKh1wga1QZLqHT C8CDRieM1y6JNJSUXPOZLlTBxvXlJV9ayCTQ5rh3WqpDFLpYIP9nFO4CP8fbs85u8qIM W/E8aEb/4UTNq9ZBCxzlBDC3Jscbbae+PNo9UR4lWBgykPLmonVW6KD3H9N8DVVSnCwZ PVMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=9Md+RvMxxp2pK6O6OsuG1sh+pY18ew2WCAeDzHWFrBE=; fh=L6oQMsqStS2+GypcEamznIi2La9bk6Ty8v+876JmcVU=; b=FIG+TdwFPU95eF6owP3OyHjWSXzvQp1DvUx6VvJC2vWPF26wPg6vt/xnMD8vv+Irpq 0bvD80szy6dzpD73Su/KRv3I+QMNTFr2YWt1VhAAL+HBrnwgEjP0mb0Z+xjDaTyuRMny L6WVeYPvGENl1HyUz/t7Rcb9gFADwwH+h2Vj9r6wT9tCYHeAsqEd2ydmPId9rYCl0nKW JxT2QHWaYbzj9GdzJ3cyrVzOevmoVhfU8j5TVc85pCTCiPmNT63zbtm6BYKRjmqhF/2B xY8NIihI++aXPHjnYcnCG9yOeY9Gf3KIim8G/39FEkJWGoQeDShKCNyydT56zr/HiPR3 hSQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148692-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148692-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e13-20020a17090a9a8d00b002a63dcc38d7si1402735pjp.30.2024.04.17.07.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:42:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148692-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-148692-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148692-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 993F5283C41 for ; Wed, 17 Apr 2024 14:42:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B32A6142E8E; Wed, 17 Apr 2024 14:41:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0320A14036F for ; Wed, 17 Apr 2024 14:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364865; cv=none; b=f7uUCc2iZGoSCmFAzdOWAbjgvWoKS/8Nc11yZcdZNveFigoCIgulM/J7PUTyV+D9ukru/j40wue91PLrXjXlQjvcREwrSJ2dUMSvRZ3XnX2z3YNj8Qxynhw3TvEWHIS83PC7LwaW0YfXqZDxMwFKMDB3NhN/vFUPy2LLzXFdxqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364865; c=relaxed/simple; bh=RlK8KnFv0HJvipPZrhYVHlntbmocvkASMg4RsjBr9gs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ohkGWj5d/i01Z9IzWaGmGBZoJeA+HJJ/byGGu6tzM7BK+WFfgcC5jBNBJ8A1Fw1W+mm1PPkJHyQRmIuacbe+zHMsSMDoA1ALKP7nv25v72qXiLMcGyGFvlwN1v9Op1nVM7sYMtVDw1Gs1BrCfs71Jc/0a/9MdQicTQ4PrRLUYPg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 1282F339; Wed, 17 Apr 2024 07:41:30 -0700 (PDT) Received: from e133380.arm.com (e133380.arm.com [10.1.197.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E5A883F738; Wed, 17 Apr 2024 07:40:58 -0700 (PDT) Date: Wed, 17 Apr 2024 15:40:53 +0100 From: Dave Martin To: "Moger, Babu" Cc: James Morse , x86@kernel.org, linux-kernel@vger.kernel.org, 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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie Subject: Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list Message-ID: References: <20240321165106.31602-1-james.morse@arm.com> <20240321165106.31602-3-james.morse@arm.com> <0790c576-944a-45f8-bc43-01eb0a8f67a9@amd.com> 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-Disposition: inline In-Reply-To: On Tue, Apr 16, 2024 at 03:44:29PM -0500, Moger, Babu wrote: > Hi Dave, > > On 4/16/24 11:15, Dave Martin wrote: > > On Mon, Apr 15, 2024 at 03:28:18PM -0500, Moger, Babu wrote: > >> Hi James/Dave, > >> > >> On 3/21/24 11:50, James Morse wrote: > >>> Resctrl occasionally wants to know something about a specific resource, > >>> in these cases it reaches into the arch code's rdt_resources_all[] > >>> array. > >>> > >>> Once the filesystem parts of resctrl are moved to /fs/, this means it > >>> will need visibility of the architecture specific struct > >>> resctrl_hw_resource definition, and the array of all resources. > >>> All architectures would also need a r_resctrl member in this struct. > >>> > >>> Instead, abstract this via a helper to allow architectures to do > >>> different things here. Move the level enum to the resctrl header and > >>> add a helper to retrieve the struct rdt_resource by 'rid'. > >>> > >>> resctrl_arch_get_resource() should not return NULL for any value in > >>> the enum, it may instead return a dummy resource that is > >>> !alloc_enabled && !mon_enabled. > >> > >> Nit. > >> You may want to drop the second half of the statement. We don't have a > >> dummy resource. > > > > I guess not, but MPAM will, although I haven't fully understood the > > logic. See: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2 > > > > (Search for "dummy".) > > > > > > In any case, the statement above is part of the definition of the new > > interface: the resctrl core code is going to explicitly need to cope > > with a dummy resource being returned, and the arch code is required > > to return a pointer to something and not NULL. > > > > So I would say that it is appropriate (or, at the very least, harmless) > > to keep that statement here? > > Ok. fine. > > > >> > >>> > >>> Signed-off-by: James Morse > >>> --- > >>> arch/x86/kernel/cpu/resctrl/core.c | 10 +++++++++- > >>> arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +- > >>> arch/x86/kernel/cpu/resctrl/internal.h | 10 ---------- > >>> arch/x86/kernel/cpu/resctrl/monitor.c | 8 ++++---- > >>> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 +++++++-------- > >>> include/linux/resctrl.h | 17 +++++++++++++++++ > >>> 6 files changed, 38 insertions(+), 24 deletions(-) > >>> > > > > [...] > > > >>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > >>> index 1767c1affa60..45372b6a6215 100644 > >>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c > >>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > > > > [...] > > > >>> @@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void) > >>> > >>> static int rdt_get_tree(struct fs_context *fc) > >>> { > >>> + struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); > >> > >> Its is probably best to keep the resource name as r here to be consistent > >> with other changes. > >> > >>> struct rdt_fs_context *ctx = rdt_fc2context(fc); > >>> unsigned long flags = RFTYPE_CTRL_BASE; > >>> struct rdt_domain *dom; > >>> - struct rdt_resource *r; > >>> int ret; > >>> > >>> cpus_read_lock(); > >>> @@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc) > >>> resctrl_mounted = true; > >>> > >>> if (is_mbm_enabled()) { > >>> - r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; > >>> - list_for_each_entry(dom, &r->domains, list) > >>> + list_for_each_entry(dom, &l3->domains, list) > >>> mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL, > >>> RESCTRL_PICK_ANY_CPU); > >>> } > >>> @@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf) > > > > [...] > > > >> Thanks > >> Babu Moger > > > > [...] > > > > Yes, this does look a bit odd. > > > > This looks like a no-op change to me -- I think that > > resctrl_arch_get_resource() is supposed to be without side-effects, > > so I would have expected this to be a one-line change at the assignment > > to r, with no particular need for renaming r. > > > > Does that make sense to you, or is there some complexity I'm not > > noticing here? > > No other complexity.. Just keep the variable name as r. > > struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3); Ack; I went for the minimum-diffstat option in the end, so kept the declaration and initialiser separate. If you have a strong view on that though, please shout. Cheers ---Dave