From patchwork Thu May 25 18:02:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 99168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp564715vqr; Thu, 25 May 2023 11:15:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uStjhAWZbnNdNf/pJa49wXUq28/OUumjEFWL84s0YpNtDfUy19guSgiuQn/McXN1lHX/s X-Received: by 2002:a05:6a00:1988:b0:64d:1185:243c with SMTP id d8-20020a056a00198800b0064d1185243cmr9555064pfl.5.1685038540197; Thu, 25 May 2023 11:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685038540; cv=none; d=google.com; s=arc-20160816; b=Vvg9Vzc4kyeKhCWBNh5WXy+c/vYUth0OvJhiHla50bEDAZJ0ye8nDgPk7C5P6vc6dT /6lI9ev+ob4hem+v8q+sVzSynnSuntVEoKvGA3oaxRU9r7gk5Pw3WRJnueawIwVMGODd iZHRZlMC0U2V1XOl79jYKn3IKGuj9CEg4b4s6A0cedO9zueiyRu8VSdxQ2UW5of9syA/ WcJ0gG9EYHKOQHh9qXnKjeSnS0IxjDi2WiblZb8QOw6erMfX/IFlDu767r/jZo+IuyzH iZzZ0g8fr7gMLeh6+gMNKEFLm6toIChkXVhaqFWVvXPJGilvPNlm9EAn4dr/F1Dpi8sG /XTw== 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=MCcJ6UTgKqTvtlYTQKzshDxnUUmw1sV/MGxcthoQXXU=; b=d95mfo1hvd8CDYbycNEgTekDNwzxFBHsW51+GjA+vupaBpUv7Pc9XV3hbn48VSnZrd lcUS6P4s3TE95LV8v3Dt0SYlAyxLl3s9wvzC3kQ7n9tj0iuQH6DvtGGs2Atsonu1wQ6G lRYsTt3rKE1CrHQNz7mM+3zYSLZnHCl8nnbOkIn7XYcMJcdw3ULurKvVD1Olu0w/ZgUQ BHtP/+VBIP8YNZamdZibZfSLuH9WQw1qx74AjeknGG/zIgeWc77N88HjuuaWZe35E/xg m5Ok2DbTmaWiX8sxzsqiIoeJr3aqoEvpHga2d7/i//aI5o/zttbEo+bBK6iksX4jgYBf /4Zg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 125-20020a620683000000b0064f78c32b85si1928460pfg.390.2023.05.25.11.15.25; Thu, 25 May 2023 11:15:40 -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 S241362AbjEYSEh (ORCPT + 99 others); Thu, 25 May 2023 14:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbjEYSEG (ORCPT ); Thu, 25 May 2023 14:04:06 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C8F231707 for ; Thu, 25 May 2023 11:03:44 -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 8A6301655; Thu, 25 May 2023 11:04:14 -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 C0D7C3F6C4; Thu, 25 May 2023 11:03:26 -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, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com Subject: [PATCH v4 20/24] x86/resctrl: Add cpu online callback for resctrl work Date: Thu, 25 May 2023 18:02:05 +0000 Message-Id: <20230525180209.19497-21-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230525180209.19497-1-james.morse@arm.com> References: <20230525180209.19497-1-james.morse@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766890972326423345?= X-GMAIL-MSGID: =?utf-8?q?1766890972326423345?= The resctrl architecture specific code may need to create a domain when a CPU comes online, it also needs to reset the CPUs PQR_ASSOC register. The resctrl filesystem code needs to update the rdtgroup_default cpu mask when cpus are brought online. Currently this is all done in one function, resctrl_online_cpu(). This will need to be split into architecture and filesystem parts before resctrl can be moved to /fs/. Pull the rdtgroup_default update work out as a filesystem specific cpu_online helper. resctrl_online_cpu() is the obvious name for this, which means the version in core.c needs renaming. resctrl_online_cpu() is called by the arch code once it has done the work to add the new cpu to any domains. In future patches, resctrl_online_cpu() will take the rdtgroup_mutex itself. Tested-by: Shaopeng Tan Signed-off-by: James Morse --- Changes since v3: * Renamed err to ret --- arch/x86/kernel/cpu/resctrl/core.c | 11 ++++++----- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 10 ++++++++++ include/linux/resctrl.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 4bea032d072e..e00f3542e60e 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -603,19 +603,20 @@ static void clear_closid_rmid(int cpu) wrmsr(MSR_IA32_PQR_ASSOC, 0, RESCTRL_RESERVED_CLOSID); } -static int resctrl_online_cpu(unsigned int cpu) +static int resctrl_arch_online_cpu(unsigned int cpu) { struct rdt_resource *r; + int ret; mutex_lock(&rdtgroup_mutex); for_each_capable_rdt_resource(r) domain_add_cpu(cpu, r); - /* The cpu is set in default rdtgroup after online. */ - cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); clear_closid_rmid(cpu); + + ret = resctrl_online_cpu(cpu); mutex_unlock(&rdtgroup_mutex); - return 0; + return ret; } static void clear_childcpus(struct rdtgroup *r, unsigned int cpu) @@ -965,7 +966,7 @@ static int __init resctrl_late_init(void) state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/resctrl/cat:online:", - resctrl_online_cpu, resctrl_offline_cpu); + resctrl_arch_online_cpu, resctrl_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 5330c0bdeffc..7c3de5ea0482 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -3725,6 +3725,16 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d) return 0; } +int resctrl_online_cpu(unsigned int cpu) +{ + lockdep_assert_held(&rdtgroup_mutex); + + /* The cpu is set in default rdtgroup after online. */ + cpumask_set_cpu(cpu, &rdtgroup_default.cpu_mask); + + return 0; +} + /* * rdtgroup_init - rdtgroup initialization * diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 0dcb5cfde609..ecd41762d61a 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -222,6 +222,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, u32 closid, enum resctrl_conf_type type); int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d); void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d); +int resctrl_online_cpu(unsigned int cpu); /** * resctrl_arch_rmid_read() - Read the eventid counter corresponding to rmid