Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2647067rwi; Fri, 21 Oct 2022 06:25:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wwh/CtjHXFd7Kcmtypufae+7E0oTM0VHh4HF7v1tQCWUfckIuTpmlKsKmYFgwasRYmDaE X-Received: by 2002:a17:907:75d8:b0:78d:3c2e:9a99 with SMTP id jl24-20020a17090775d800b0078d3c2e9a99mr14916384ejc.686.1666358711447; Fri, 21 Oct 2022 06:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666358711; cv=none; d=google.com; s=arc-20160816; b=RpGHwE2A8fUH0iVTKRIwJms4ZrPnrOX28n87MUH4xInMq9aKoTwpRPIRRJSqAekHov L4xeDTq545I4YzwxuugiJMk0kHopNzjjEIgTbnxb8966bEjuwYrS4/fhTPzo2qGu0Y7L IyOHmcFPcvQ3yCGR6o0euks3hER0eUjlh4JwC5rneiBf8T3skJH/pe7+fsj4fvvd3FTG lvYTi/XlKD4IXBx6yYDUjkiXZ7CAHhJbFuh/dWSuNzefsjZ4hlpl13B2GRzqavGWpa7s 7/Sa0HX1FDsGZYcw6WutfMUrCLRiLvcQsB7pRgZ9ldgFHUh+Y7hCQ0UJ37Vja98LqBWJ xkwg== 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=jubZ6/BMxwor3XW+SLtfJj5M2z6MRQDaJ2SOiwWNeJU=; b=pcu3OWpGAAAEBlfW3BVS4qs0fqrI0LkcJOOf1a+1FJSAyK5KTJ8crjbehbIrtufyIe paby6JyUK+5qjrCk+yyR/C3BpI02QV1D2TsUG8OE1StFYwYGpqv34uTXSVo1LwnhcN+i tClWd5hyrEMUV9+eVXQ5gpAK/rtVdpXsBob2k8nrRRllO5kCA+JmFsM6brESUVzsF1IL Gut2X1vg/fdQCKuKOuKj2ZjhgfSfUiwZQNws1ZiIBOVxPyzHOLBLHVWuWsg74XrPYa38 fRMWWndGI6zQW+fy77Zsfc4pNkQBWAJwdxWfFEGx7JDnWv+QbQjSrmBS1SPHZtcC6ttT 1B2A== 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 dn15-20020a17090794cf00b007919a242731si12949425ejc.95.2022.10.21.06.24.44; Fri, 21 Oct 2022 06:25:11 -0700 (PDT) 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 S230315AbiJUNNZ (ORCPT + 99 others); Fri, 21 Oct 2022 09:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiJUNNL (ORCPT ); Fri, 21 Oct 2022 09:13:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9DA2D230A87 for ; Fri, 21 Oct 2022 06:12:52 -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 E3DB61477; Fri, 21 Oct 2022 06:12:57 -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 4556E3F792; Fri, 21 Oct 2022 06:12:49 -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, Jamie Iles , Xin Hao , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, peternewman@google.com Subject: [PATCH 08/18] x86/resctrl: Queue mon_event_read() instead of sending an IPI Date: Fri, 21 Oct 2022 13:11:54 +0000 Message-Id: <20221021131204.5581-9-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221021131204.5581-1-james.morse@arm.com> References: <20221021131204.5581-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, 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. 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 1dafbdc5ac31..842266d1d148 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -533,8 +533,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; @@ -543,7 +546,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 faec12025a58..4d2f4524fe87 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -524,7 +524,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 99854ef4dee4..2ca76cddb170 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -502,10 +502,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; @@ -538,6 +538,8 @@ void mon_event_count(void *info) */ if (ret == 0) rr->err = 0; + + return 0; } /* -- 2.30.2