Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1280987rwb; Fri, 13 Jan 2023 10:05:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXvivsLwrQNx/mQwt2g4wwCe7KjVX2yxllOdMglAYIh1t+E38bPEkm4pSDi26vGUjksQ9JC1 X-Received: by 2002:a17:90b:2384:b0:227:1745:3478 with SMTP id mr4-20020a17090b238400b0022717453478mr18753042pjb.30.1673633111236; Fri, 13 Jan 2023 10:05:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673633111; cv=none; d=google.com; s=arc-20160816; b=HzEpKt+Df64/tJSL3b5/nOhdG7VUE5mBC9hezW0odXkv/NOYYXCDTkH9ia1nZ2xhSw NJQAv/SIvpLX0qaZdVStCJhGzVPF5r7ypm2vOR00oOAGNeXeDNZO13oNhAT1blbtz4EE f81OooOHV/WI3Z/cVZ+lgZS8ekccpxiPXa+lKG/iAbHUnEAkapWH/TW2G+DBH+6aBuAm vHL6SfWRq2Fpm5MaAV7F6OOdvpaSzTKW5qF8JtoDs/TjOqeGh3pmgsVIlA/ptjWvebAR Aa49Gu4r3JQdgari6xAMOy/c+KOHxNIRN1Hug9HapXCzf0uUyygYp/ZW3nDuA+3BBzJF ncvw== 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=fGGX/x33OVrF+XN3mzQz3TCRQWLazykv/XX/VtCQaBE=; b=quMwbzdLuE8FG8KDVhPhRkoRJMi9MGLC1cxzynJOjEYSGXiG/ws/hQT9Z7fAB7nVUd IIvOIHHJ3CmZ7j3shULXgtE1RYN1PLEU82s9DrWGp6kKt2qaMX0KxorxkodR7N62yfzM ZmayQgwjmuw22XO8Ujr3GkXx73xEQLU1cBtLt6eQWMGcVqncwRB0fflUTv9gFszjiqxX f6sxFapiiLOnWzAd+b90S5NjCdldp9LYo7zF5AbRSnnShA56r1pq6O0IP6/hccJk3+Sb ym3/xu8+0gfwcn+L83NKIJNmhg3FrDCmFBeQgMGXC27TeHcKT4YbnItGZ7l1Q26DY2DW vxng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x82-20020a633155000000b004c6b35c63aasi440648pgx.476.2023.01.13.10.05.04; Fri, 13 Jan 2023 10:05:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjAMSDF (ORCPT + 51 others); Fri, 13 Jan 2023 13:03:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjAMSBi (ORCPT ); Fri, 13 Jan 2023 13:01:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6E539CE13 for ; Fri, 13 Jan 2023 09:56:05 -0800 (PST) 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 218461763; Fri, 13 Jan 2023 09:56:47 -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 8A1543F67D; Fri, 13 Jan 2023 09:56:02 -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, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com Subject: [PATCH v2 08/18] x86/resctrl: Queue mon_event_read() instead of sending an IPI Date: Fri, 13 Jan 2023 17:54:49 +0000 Message-Id: <20230113175459.14825-9-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230113175459.14825-1-james.morse@arm.com> References: <20230113175459.14825-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 x86 is blessed with an abundance of monitors, one per RMID, that can be read from any CPU in the domain. MPAMs monitors reside in the MMIO MSC, the number implemented is up to the manufacturer. This means when there are fewer monitors than needed, they need to be allocated and freed. Worse, the domain may be broken up into slices, and the MMIO accesses for each slice may need performing from different CPUs. These two details mean MPAMs monitor code needs to be able to sleep, and IPI another CPU in the domain to read from a resource that has been sliced. mon_event_read() already invokes mon_event_count() via IPI, which means this isn't possible. Change mon_event_read() to schedule mon_event_count() on a remote CPU and wait, instead of sending an IPI. This function is only used in response to a user-space filesystem request (not the timing sensitive overflow code). This allows MPAM to hide the slice behaviour from resctrl, and to keep the monitor-allocation in monitor.c. Tested-by: Shaopeng Tan Signed-off-by: James Morse --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 7 +++++-- arch/x86/kernel/cpu/resctrl/internal.h | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index 1df0e3262bca..4ee3da6dced7 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -532,8 +532,11 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_domain *d, struct rdtgroup *rdtgrp, int evtid, int first) { + /* When picking a cpu from cpu_mask, ensure it can't race with cpuhp */ + lockdep_assert_held(&rdtgroup_mutex); + /* - * setup the parameters to send to the IPI to read the data. + * setup the parameters to pass to mon_event_count() to read the data. */ rr->rgrp = rdtgrp; rr->evtid = evtid; @@ -542,7 +545,7 @@ void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, rr->val = 0; rr->first = first; - smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1); + smp_call_on_cpu(cpumask_any(&d->cpu_mask), mon_event_count, rr, false); } int rdtgroup_mondata_show(struct seq_file *m, void *arg) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index adae6231324f..1f90a10b75a1 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -514,7 +514,7 @@ void closid_free(int closid); int alloc_rmid(u32 closid); void free_rmid(u32 closid, u32 rmid); int rdt_get_mon_l3_config(struct rdt_resource *r); -void mon_event_count(void *info); +int mon_event_count(void *info); int rdtgroup_mondata_show(struct seq_file *m, void *arg); void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_domain *d, struct rdtgroup *rdtgrp, diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 190ac183139e..d309b830aeb2 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -509,10 +509,10 @@ static void mbm_bw_count(u32 closid, u32 rmid, struct rmid_read *rr) } /* - * This is called via IPI to read the CQM/MBM counters + * This is scheduled by mon_event_read() to read the CQM/MBM counters * on a domain. */ -void mon_event_count(void *info) +int mon_event_count(void *info) { struct rdtgroup *rdtgrp, *entry; struct rmid_read *rr = info; @@ -545,6 +545,8 @@ void mon_event_count(void *info) */ if (ret == 0) rr->err = 0; + + return 0; } /* -- 2.30.2