From patchwork Mon Feb 19 18:37:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 203209 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1467839dyc; Mon, 19 Feb 2024 10:40:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0tMZyNgeO6+BasPdoJe6KRqiaWrdhMzSa0kknRup/yOyIJdV3LyBQMux98sZJZxniH3pC3JEq1+Sp7YQADE1WTFO2kw== X-Google-Smtp-Source: AGHT+IEvSDlXr77aUgLRCpNkPR09LSSKWcVgoYYIss7OvlwtDb3e6Fop4y1TeShceUIGOH9JKKfU X-Received: by 2002:a17:90a:dd41:b0:296:6a37:c528 with SMTP id u1-20020a17090add4100b002966a37c528mr9035298pjv.24.1708368046724; Mon, 19 Feb 2024 10:40:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708368046; cv=pass; d=google.com; s=arc-20160816; b=rr2p2onF7gymWeFHO+SR+I/voduienBwUa88jxuxA9uHgKsLhsup1TUeVdy5ZLzDsC ZpKUyI/hov0j6OLwHURCaLCRW/NO5yjyCrpBeKFG51QyPn4rMb3/8w1b4sPbRoHJe+5S uZmwY3knHVX83LlMR5lzkr1IDyhXSUDAzPkUfVFq2qfQFkxblq4QvgIasB5P+Wd3vp7o iEZSDdfZUfzctqyAdAhKw3NPsRdQg5n32UedxSNr8JG0cgmbp8wdKJp5FFXZxl05zvYV yEZVIgt/VpO2BZE3VcPdA2a8RM1suK9BtnHArfaC5kSUtuc9U7fqBFg9pQQFberzgiBa O5eg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=J81Dhws8oKIj4m/kQnRvgedlbXL8PWp0Nqu7A9Vp3e0=; fh=aoXmHruCmQx3Q2XQFDmVUCNXKkr6qxKwF4QAl5nXV1U=; b=nQMtSae1jMGc01vmqvsR1ArDblI9pbfB8ECpBvPLBsXltzJgD3XiVJVj55KXPIs/sZ D11mMHNt4foOvO/HICsOYro6cdyokWat7F2LqGrAs3qmcLgRoDMFcZ9eLMWp7AQy5mEC CeeZrCMkCKLck6/L3rHFLsDg1xUC21Rc9t5QlWt90AiO12SF4M8qK/TR8E2OQMFsX96/ m6XdzyYkjtsFWpaJP29bwLWXOQQxZUf9EvBHpMDiowsUiU12Ha+Wx9wVBp89M7+kPsoL OBYdS110t1qh7oNFm4WfydimHCaMsJrKyoAktG3gdJxyIu9Gn4Iu4ytM7+3zxOMPzcjC inXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ojrk2NUF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71823-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id me4-20020a17090b17c400b00299d1854c85si437810pjb.41.2024.02.19.10.40.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 10:40:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71823-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ojrk2NUF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-71823-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71823-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 2463B284229 for ; Mon, 19 Feb 2024 18:40:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D666F481B5; Mon, 19 Feb 2024 18:37:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ojrk2NUF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aTPzUfBa" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 96B224E1CD; Mon, 19 Feb 2024 18:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367856; cv=none; b=IEJSkkV1NkFdNxLQByEfg5RigOSba+DjLRM7y3B87RxhRwbKQpf74VzIgoojJRWHQhIxPFk1mBrEgc0ne/9osxVnHf2fRCD7Ut/gtQ/G1fIRsbSDxrfviHOyu9torbQFVIyrJYVl6C797RvxgDf32/bXotbsRFek8LH2XyKml80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367856; c=relaxed/simple; bh=WAcpIo++xdW6mUgmCOPJgAqn1tr1nX4+wsLRGBJtWT4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=TRdMTsznQ8BLeCiTbxxVuLCJxGsEAo9uTIll7RGdJYEus5DU1IXnoqxLtfyMcSPFrdh+ih/f1s9M3hcLvb0Z2Oofl5mtCn9fdm6mTcZz3nVGjvavqvpKJLkpiv9YM/7m4EoB1M0Hyun0rWuHKvE+zuaZWj2atzncEz5rm4D9mWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ojrk2NUF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aTPzUfBa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Mon, 19 Feb 2024 18:37:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708367851; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J81Dhws8oKIj4m/kQnRvgedlbXL8PWp0Nqu7A9Vp3e0=; b=Ojrk2NUFmlUqtJbBlspgeXYneSYExZBjHc3YzLGp5f3Bo6g/XjTsU2VkLTlrpi+7LHyApP buXqHs9mH1z6bGFec/hX5pfjz0TEiupD3lD1ejW8y+6nE0nrVErgR2wSFSZwCCKei9rjMa EHregrbCASu8DpIe4kI0ww0cStTL9g909zeWkLa529UscZxwijOEVrCtVOObJcj6yR9jTB qKFuk/nFDd75UdVwj8kP4iCDWjPCG3PgSo2jA0k3VuqGQmZgFnc8nVd2z9dwCWv4GJySpb FWqZ08s+MOPH9m588V0zQ2mp9Z1cN2cKE1P63Px1QRverwrhnDp90S6FJzbbiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708367851; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J81Dhws8oKIj4m/kQnRvgedlbXL8PWp0Nqu7A9Vp3e0=; b=aTPzUfBa3nBSwoPUGdO+P++XOZarw0YNs4SxzwnEZZWOn1zaXUVIhTweB3zuhezvIdCXaF B1l+Dqswr5V0WtBg== From: "tip-bot2 for James Morse" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/cache] x86/resctrl: Queue mon_event_read() instead of sending an IPI Cc: James Morse , "Borislav Petkov (AMD)" , Shaopeng Tan , Peter Newman , Reinette Chatre , Babu Moger , Carl Worth , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240213184438.16675-14-james.morse@arm.com> References: <20240213184438.16675-14-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170836785117.398.9171723521136729207.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790810638028029377 X-GMAIL-MSGID: 1791353733024040944 The following commit has been merged into the x86/cache branch of tip: Commit-ID: 09909e098113bed99c9f63e1df89073e92c69891 Gitweb: https://git.kernel.org/tip/09909e098113bed99c9f63e1df89073e92c69891 Author: James Morse AuthorDate: Tue, 13 Feb 2024 18:44:27 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 16 Feb 2024 19:18:32 +01:00 x86/resctrl: Queue mon_event_read() instead of sending an IPI 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. Signed-off-by: James Morse Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Shaopeng Tan Reviewed-by: Peter Newman Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Link: https://lore.kernel.org/r/20240213184438.16675-14-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 26 ++++++++++++++++++++-- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index beccb0e..e933e1c 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -19,6 +19,8 @@ #include #include #include +#include + #include "internal.h" /* @@ -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; +} + void mon_event_read(struct rmid_read *rr, struct rdt_resource *r, struct rdt_domain *d, struct rdtgroup *rdtgrp, int evtid, int first) { + int cpu; + /* - * 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; @@ -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); } int rdtgroup_mondata_show(struct seq_file *m, void *arg) diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c index 38f85e5..fd060ef 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -585,7 +585,7 @@ 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)