Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5918826rdb; Thu, 14 Dec 2023 03:37:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWcN+w26w2RRa8a61aug5t1eVnmFHpUdzH4EW3If8Ig/yq0qBp0Eq6+DFffAbKonnj7Ird X-Received: by 2002:a05:6a20:29a5:b0:18f:97c:977a with SMTP id f37-20020a056a2029a500b0018f097c977amr9804156pzh.98.1702553871760; Thu, 14 Dec 2023 03:37:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702553871; cv=none; d=google.com; s=arc-20160816; b=wDWku2nJCXVWbTTKHWSJARpSkKPKY3oPeB/QFHtzbW8mmjPtkWgb87frmq8dL3Vudd GVjpKyGQvHNp4XFEOaZF6XEnhxpNuPJCj23HhLMFIPXS3KiVXccEmOxL6gds3W2oIfDn Y7MDNOS4wRmNvp11EuMh4wHpw3LYRvj0hGrFNMjbwAi9/PaXTTzrpE4gd2vsefymKD5S Wokq2Pj1/6R8LCDKvuvYkB9cBa5Xk53tVHvI702P3UyhSDAejQxq+JJm5YE+O32gl8Sf cBsvVOY8tblw9EiiGLFBhDcTObI7RleQBhaXvHJI97xxQ49bq36WTVacHiDyDHmlAocL YhMg== 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=ad+9PvcQL85xG6R0UCLOzG+nkGgVb7QEjfj5bhNjeMY=; fh=HBNJCb1O5m4cQgWGcwqoKY3KTbKsr5rANYvH6uVWzvA=; b=czE53YgWOp8fVN8f4g6xxCKk9+l+i0gRgCL+Re5umCsk2KAKGHbD1/7af1AkE/SJEH 1nPLHq2geVSBSdbhBzyouNfpL2uzzN8rxwggXTVOtZeXN4y1lMpPCcjU+CMj/BseDNlQ vjQooK5lS71AnNEmeU90KfAvgj1yTeQfag9b858jjSAxnZsOznK3W5guv6RtbTi8bqFH d8//cOOos8LZrUnY9x/YCd9DWeBjPeCa36jXFl6l3JsEBrHe+JzuTM1g+I8/pYKzXZmg CkAX9gt4fna5JyTlTqrPIWlbFz7KNuioIebakWYjV/CfHYqSNLY3cVNqYRpTyjOFbjJq zDrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e4-20020a63e004000000b005b902b61cbcsi11327965pgh.723.2023.12.14.03.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 03:37:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id DF67783294C7; Thu, 14 Dec 2023 03:37:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444088AbjLNLhe (ORCPT + 99 others); Thu, 14 Dec 2023 06:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443993AbjLNLhZ (ORCPT ); Thu, 14 Dec 2023 06:37:25 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 437E4132 for ; Thu, 14 Dec 2023 03:37:31 -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 8DAAD11FB; Thu, 14 Dec 2023 03:38:16 -0800 (PST) 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 72AE53F738; Thu, 14 Dec 2023 03:37:28 -0800 (PST) Message-ID: <7c9b0656-fb09-1adf-664b-e2cbcc04b1db@arm.com> Date: Thu, 14 Dec 2023 11:37:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v7 13/24] x86/resctrl: Queue mon_event_read() instead of sending an IPI 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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com References: <20231025180345.28061-1-james.morse@arm.com> <20231025180345.28061-14-james.morse@arm.com> From: James Morse In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 03:37:49 -0800 (PST) Hi Babu, On 09/11/2023 20:40, Moger, Babu wrote: > On 10/25/23 13:03, James Morse wrote: >> Intel 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. >> >> MPAM's CSU monitors are used to back the 'llc_occupancy' monitor file. The >> CSU counter is allowed to return 'not ready' for a small number of >> micro-seconds after programming. To allow one CSU hardware monitor to be >> used for multiple control or monitor groups, the CPU accessing the >> monitor needs to be able to block when configuring and reading the >> counter. >> >> 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. On systems using nohz-full, some CPUs need to be >> interrupted to run kernel work as they otherwise stay in user-space >> running realtime workloads. Interrupting these CPUs should be avoided, >> and scheduling work on them may never complete. >> >> Change mon_event_read() to pick a housekeeping CPU, (one that is not using >> nohz_full) and schedule mon_event_count() and wait. If all the CPUs >> in a domain are using nohz-full, then an IPI is used as the fallback. >> >> 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. When the IPI fallback is used on >> machines where MPAM needs to make an access on multiple CPUs, the counter >> read will always fail. >> diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c >> index beccb0e87ba7..d07f99245851 100644 >> --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c >> +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c >> @@ -522,12 +524,21 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of, >> return ret; >> } >> >> +static int smp_mon_event_count(void *arg) >> +{ >> + mon_event_count(arg); >> + >> + return 0; >> +} > > Shouldn't this function defined as "void" similar to mon_event_count? > Return code is not used anywhere. smp_call_on_cpu() requires it to return an int, even if the value is not used. This wrapper only exists because smp_call_on_cpu() takes a different prototype to smp_call_function_any(). Thanks, James >> @@ -536,7 +547,18 @@ 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); >> + cpu = cpumask_any_housekeeping(&d->cpu_mask); >> + >> + /* >> + * cpumask_any_housekeeping() prefers housekeeping CPUs, but >> + * are all the CPUs nohz_full? If yes, pick a CPU to IPI. >> + * MPAM's resctrl_arch_rmid_read() is unable to read the >> + * counters on some platforms if its called in irq context. >> + */ >> + if (tick_nohz_full_cpu(cpu)) >> + smp_call_function_any(&d->cpu_mask, mon_event_count, rr, 1); >> + else >> + smp_call_on_cpu(cpu, smp_mon_event_count, rr, false); >> } >>