From patchwork Tue Feb 13 18:44:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 200561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp740696dyb; Tue, 13 Feb 2024 10:50:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUrS1rEhflSk6j4CEDv3k7jFRYCOI8LARg+FeUIn+yfs2aV2wup0U6jnAY2ISDdYMIKujYHy63BDcJEWF+Ko/9I/pReNg== X-Google-Smtp-Source: AGHT+IEfAJ8W+IYPzNSoKVxVsF3B/fwm3dOuyCv2hgvG9Q9NEGDUWIqtwdkBnvy2slVOA8QWa9yv X-Received: by 2002:a05:6830:1b63:b0:6df:b685:84b9 with SMTP id d3-20020a0568301b6300b006dfb68584b9mr505878ote.32.1707850242479; Tue, 13 Feb 2024 10:50:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707850242; cv=pass; d=google.com; s=arc-20160816; b=ODZ1nzeXn9buRHk3tIc9dP3+GoNfkgfZXltzInwctRaASQhXZWgIJmmX6jc1jQ6Tfe GgE3gjdHVH7dM01WiPVUE05MaGhGmMagxfZYGbHXKOykI1VU6ayK/gHEjzs1CDaEZ/Nl dJ91EqsrGLbdWLDmiiHXYT9iP+W96E1nkqUO3dR1mZ8dQziBy2ElJuXILs9TXXWGNMGz 7qWqLHmmKzFKKkNlAM+i152ysSII7skw5YZ5Np/9NCePlYx/wGPqG4QxBWX0RpYTIGBG AJQO+kMnAbO1khsw2yhvaLkLWdu8DIr1muvIs7jTW/4nI6UBhoLr0izIOQ/GL7pmVMyD cZQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Bjp/kM0pwgfnsnvfEvpgsjKtodmxi49LEm2hNwZluXY=; fh=TNr15Cc4ZCIZJVPrLskO4e2yEOS9MSgT4tyALxMaFzI=; b=F8lTuhOs3MXMnVnk9MhYTQKaw6DX8P7fmqXTy7Z32c1RicnIL+sUuVh+QjC4cvqH8s jzzM5nwyJRf6UQnSqQo6ct5KREYI8OODbACMy+tcXv1rB40WFuvHlIISW7vHGDCyra/w u0MfQrrFm573Lnf189BGICZMBe+CFf2+DsWJ3kXwOl3vqv15KPRHYMzXPNYKnHVV+H3c hl4+ODy95nwzXG5QdlJp0XV63h4CI7ThN4C24vLmhYfH54K6KG1e7EuVDPdy9+Qi8Uak jLKZoVgsxNS26W/MYmlxHJ7HZAzV6Knjqc0BTb2MidOwTCzZnE+YkL2XBOK1X5WHbDQK usYQ==; 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-64113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64113-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWqsaZrabRv8a6BdD5KgURWW937mUfMJ1Dh+xnObnoscF5HX2Dw4i1EnyPG9OO7DFayC2eqAoXAmnzly2wEXl0ju9Y6tA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l66-20020a633e45000000b005dc19ac7173si2350815pga.21.2024.02.13.10.50.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:50:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64113-ouuuleilei=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-64113-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64113-ouuuleilei=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 3D9F0290591 for ; Tue, 13 Feb 2024 18:50:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36DF360894; Tue, 13 Feb 2024 18:46:19 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03D4D626C9 for ; Tue, 13 Feb 2024 18:46:15 +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=1707849977; cv=none; b=fxQMFBnAMDc2bxRS+FqCp+9ut53dZE7V51A1QyeAYojV1XyrB68WD2MwGldPyXFWjmByHDMhNtqdjyRwvLSMdtxHJ/HHxSiOJYX8uIGH+8PTz9zGorPkgpz5clZiOjpY0PVltGMEEhbVguynmehaoOJZ3GMwEZxkmTBTGvQ1ukc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707849977; c=relaxed/simple; bh=R72bTUh1j2/iRl0BP2jxva1B3BK/NOYi0JFQYorCmiI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JNVztWokUMwwK6GJlGKEfHUw2ORFs26t+AVBoitEikULS7Z48TYfQ+QBFL53T5TM84x/PeP9k7EoRQwZKwD6r06BgFw27SOSssBY/CaORDcfv5yJyV8NuOeEYB8ol0b+o4iTfqpcMcCec595Y9Hl7ONGaPVxpCD9pkyvIz3J56k= 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 C3B7E1595; Tue, 13 Feb 2024 10:46:56 -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 6587A3F766; Tue, 13 Feb 2024 10:46:12 -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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Babu Moger Subject: [PATCH v9 22/24] x86/resctrl: Add CPU offline callback for resctrl work Date: Tue, 13 Feb 2024 18:44:36 +0000 Message-Id: <20240213184438.16675-23-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240213184438.16675-1-james.morse@arm.com> References: <20240213184438.16675-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790810775887414856 X-GMAIL-MSGID: 1790810775887414856 The resctrl architecture specific code may need to free a domain when a CPU goes offline, it also needs to reset the CPUs PQR_ASSOC register. Amongst other things, the resctrl filesystem code needs to clear this CPU from the cpu_mask of any control and monitor groups. Currently this is all done in core.c and called from resctrl_offline_cpu(), making the split between architecture and filesystem code unclear. Move the filesystem work to remove the CPU from the control and monitor groups into a filesystem helper called resctrl_offline_cpu(), and rename the one in core.c resctrl_arch_offline_cpu(). Signed-off-by: James Morse Tested-by: Shaopeng Tan Tested-by: Peter Newman Tested-by: Babu Moger Tested-by: Carl Worth # arm64 Reviewed-by: Shaopeng Tan Reviewed-by: Reinette Chatre Reviewed-by: Babu Moger --- arch/x86/kernel/cpu/resctrl/core.c | 25 +++++-------------------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 24 ++++++++++++++++++++++++ include/linux/resctrl.h | 1 + 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 55322ba629da..4aedefa22f61 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -625,31 +625,15 @@ static int resctrl_arch_online_cpu(unsigned int cpu) return 0; } -static void clear_childcpus(struct rdtgroup *r, unsigned int cpu) +static int resctrl_arch_offline_cpu(unsigned int cpu) { - struct rdtgroup *cr; - - list_for_each_entry(cr, &r->mon.crdtgrp_list, mon.crdtgrp_list) { - if (cpumask_test_and_clear_cpu(cpu, &cr->cpu_mask)) { - break; - } - } -} - -static int resctrl_offline_cpu(unsigned int cpu) -{ - struct rdtgroup *rdtgrp; struct rdt_resource *r; mutex_lock(&rdtgroup_mutex); + resctrl_offline_cpu(cpu); + for_each_capable_rdt_resource(r) domain_remove_cpu(cpu, r); - list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) { - if (cpumask_test_and_clear_cpu(cpu, &rdtgrp->cpu_mask)) { - clear_childcpus(rdtgrp, cpu); - break; - } - } clear_closid_rmid(cpu); mutex_unlock(&rdtgroup_mutex); @@ -971,7 +955,8 @@ static int __init resctrl_late_init(void) state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/resctrl/cat:online:", - resctrl_arch_online_cpu, resctrl_offline_cpu); + resctrl_arch_online_cpu, + resctrl_arch_offline_cpu); if (state < 0) return state; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index f5688c79d94f..5bd3d8fb3f67 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -4017,6 +4017,30 @@ void resctrl_online_cpu(unsigned int cpu) cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); } +static void clear_childcpus(struct rdtgroup *r, unsigned int cpu) +{ + struct rdtgroup *cr; + + list_for_each_entry(cr, &r->mon.crdtgrp_list, mon.crdtgrp_list) { + if (cpumask_test_and_clear_cpu(cpu, &cr->cpu_mask)) + break; + } +} + +void resctrl_offline_cpu(unsigned int cpu) +{ + struct rdtgroup *rdtgrp; + + lockdep_assert_held(&rdtgroup_mutex); + + list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) { + if (cpumask_test_and_clear_cpu(cpu, &rdtgrp->cpu_mask)) { + clear_childcpus(rdtgrp, cpu); + break; + } + } +} + /* * rdtgroup_init - rdtgroup initialization * diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index ccbbbe5d18d3..270ff1d5c051 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -226,6 +226,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d); void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d); void resctrl_online_cpu(unsigned int cpu); +void resctrl_offline_cpu(unsigned int cpu); /** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid