Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2857421lqp; Mon, 25 Mar 2024 11:09:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVo/qAl4KFrd4c2pW6UA7fwC/GQ4LPopqtlVV+hKMN6RZCES+k47Hyh9Wt0L/rdBF2fO+hTHDEcaIMn8X6E/tB710OTv/qLM7yPPVRK3w== X-Google-Smtp-Source: AGHT+IE3l2baFeLcMg7PpRkUeAH6KUirB1ETTWAhILwoBlLxdUEwdJBqF2yine49XUZ3HHjkguzz X-Received: by 2002:a17:906:30d9:b0:a47:36b1:8992 with SMTP id b25-20020a17090630d900b00a4736b18992mr367462ejb.10.1711390189910; Mon, 25 Mar 2024 11:09:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711390189; cv=pass; d=google.com; s=arc-20160816; b=Bxwztb+9VMHufueS/EW/bvzJBmuO//JPcSqnOBfjojL90nTi4wZq8nd4oYK6TykT/d eo0X82z5yJV5FfLkw7NVOnv2KVZvCLewCX2APtuq4lDQF3IwbX4+5iX1dgDTjWMWKyMo pDvN75ZyC9c6jPtxas/pO+qjef9nSGPd3FFHtdGzrK5L29qacCW65BRSkENeJqZpB+95 hpLv63m6F7cTF7jhduAvmCCqpWuAwpmQEkZD65jJhe6P38bG7g1df4upQYyD/6uKjSH8 OgiqDY5sDS+2lHc1rHFdEDNZAQ+CHow5zNBIM1PNJpowAkERbXU0V3n3akvfvzHNZp60 83nA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=iYXDvPU+5s3FumCxEyHgAv7m9MtFIzgZjtXbt/l7B3E=; fh=6xv/F+7AkWSvlhZZfV3AJAB42WjzD9FrXdfisx8s10U=; b=0j8z/ouPgPKyyl6zqiX+WLgti1B4jpH9scgpVpBRKeE0cLAUmEOVL4ARIstDFQSO4p 5OugdKaLH3P9bKnoVQWtsRTZ2/5kpznjYv2JU+q4JTUnJs3pcAKn8ufC1xRLm1fDHYyb DHXCagkzJPIenBiSXhJEFQd2c7a0vsv7Sg4IuOufQ+fSc6Mqtjv3HxF9ChArbmP1wI7A IHWZHhKjmIx+rYqjIid2OCxwCdQTCYvEEjl7wpaGZxYsf2CRz+xC6++uDfsIe1JpgSz6 Yn49GxCD4OpcN74k2v5Rs42dkkr7vR5iB8Tz1ftOBdM7SE04PM4jR5vZbpPTDzUXjRFO yuMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eJo9biCV; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o18-20020a17090611d200b00a46cd44ab3esi2665431eja.950.2024.03.25.11.09.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 11:09:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eJo9biCV; arc=pass (i=1 spf=pass spfdomain=flex--peternewman.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-117601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 333FB1F66DD5 for ; Mon, 25 Mar 2024 18:08:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91CE31311B5; Mon, 25 Mar 2024 17:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eJo9biCV" Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A54C7130AD4 for ; Mon, 25 Mar 2024 17:27:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387667; cv=none; b=aqR27DWZCf3P4SbUj5DK/ZzHzHoXvolzG3TsoafM4AVr3DoJQGK7U9WODqtT91ZeA0v4X68vMpg98OgfAb32vrEm7j05WzarYPWGnddMua3zGVTyVVBQo0Otph3jeTDsFinqMa2m5zg1V8E2+8B1Lz+ZrDWmdVOxKwfyW7ZnJUc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711387667; c=relaxed/simple; bh=k78/xyNeRm+p5JTWQOob+AJOfSmYtbmPvcai3bGPDYA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f/Vy32GoTqJb6xPuSeYIS1Sbs7rbqORlpcfgx7+jsD2oPrAs53fzb4FvKV6SnBn+r5+M1WndkF7OUTgoW8sZQQzNtFDG8UU5VOK7GMyuK19qsMVpuWGUvptcq/xBKrtPAEx9fiOtP/Ahfciu/dnkosKAaudKi7eOMqAbVOwtC88= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--peternewman.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eJo9biCV; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--peternewman.bounces.google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-29b8f702cbfso3404997a91.1 for ; Mon, 25 Mar 2024 10:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711387665; x=1711992465; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iYXDvPU+5s3FumCxEyHgAv7m9MtFIzgZjtXbt/l7B3E=; b=eJo9biCVBxAzskJaWYFfuXUOwzU0Qe9xf0tWZTC7IYoEZMIbn+bOwxzLCm+lBG/c+y R3wiNurBs2SW9Dj5LNs8KRpsPyO/IH6yHeTmSREyIpCod8k1b+jn6o8tlQhc8rngIB+3 O5pQIiLuRdH0qeBszxuGfF9/AoHnEebCspuYwCKnDAnlpqpOHKKgkVJ4qFJF6kcHodqc Lsh1R6Y8rP+S0fRlg9swmsu3aC6w8qC2WgqTBBvpI3qO+ZDbniDlpR1gYzJLdtEZ9d3C eNFhEaTF/hs+hpgnQAmLmb57Ir0PUHOCE/GCw6eew1Ceyc+Wqbru0F84bKkDYl7UDm9h 2sjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711387665; x=1711992465; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iYXDvPU+5s3FumCxEyHgAv7m9MtFIzgZjtXbt/l7B3E=; b=YzKENjDGVrF/LolRnFGxNAzNTWXDj+BFV3XdXauZLZjAw19HAeDQmbCQO3GxEtRqL1 G2KbJNrnNDm7D6VUSi0qj86g2VQsJrqPRWrnD1S184nnH+Fat4hh5sqW6sfbdCsLiGUy vRFGdVKGps6BPixr0Pd0FIAA9Ly5Wehkw+cFO+lQ/Evd0rI32ucj+AXMuzlHFg4eatUc N2OIoEvyrYoNe8ijcXDiHgrq9e//GTs2WUezNZyrgMNl0Blh70QOxY9kgH8b+s+/8S8W 6M2E0iG1mAjnBcg4WqinqRh8L8+nTTkjjAjh+cDkF0gj8CMd9vJNnYu9Chco6BRSkFu1 nFBg== X-Forwarded-Encrypted: i=1; AJvYcCUMbmkF65Eha6TV+HRTXYmcVD1iQmI4ugRv4CZJaFsNBnQoBX0A89MK7+skcBS8pvvwbwnAG2LzEJGyIH56QWRhEsAgaURXv5+GGy7L X-Gm-Message-State: AOJu0Yw/GPqDTuBsG/lxZua5SRqnVMrk2yDs18aZKB9V/x+5j5APKs2S 0Hb6D52jAskp8KsAY8pyH8PabeqHXg7nl0m+ULXaHdKeuQf/WDzzZ8N7Y7NFddFyVG5Cy5jmWB9 oBQIJm660Zh+hue7fNPh4cQ== X-Received: from peternewman-us.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3dcc]) (user=peternewman job=sendgmr) by 2002:a17:90b:78a:b0:2a0:4e94:3c9 with SMTP id l10-20020a17090b078a00b002a04e9403c9mr23042pjz.4.1711387664881; Mon, 25 Mar 2024 10:27:44 -0700 (PDT) Date: Mon, 25 Mar 2024 10:27:06 -0700 In-Reply-To: <20240325172707.73966-1-peternewman@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240325172707.73966-1-peternewman@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Message-ID: <20240325172707.73966-6-peternewman@google.com> Subject: [PATCH v1 5/6] x86/resctrl: Abstract PQR_ASSOC from generic code From: Peter Newman To: Fenghua Yu , Reinette Chatre , James Morse Cc: Stephane Eranian , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Uros Bizjak , Mike Rapoport , "Kirill A. Shutemov" , Rick Edgecombe , Xin Li , Babu Moger , Shaopeng Tan , Maciej Wieczor-Retman , Jens Axboe , Christian Brauner , Oleg Nesterov , Andrew Morton , Tycho Andersen , Nicholas Piggin , Beau Belgrave , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Peter Newman Content-Type: text/plain; charset="UTF-8" While CLOSID and RMID originated in RDT, the concept applies to other architectures, as it's standard to write allocation and monitoring IDs into per-CPU registers. - Rename resctrl_pqr_state and pqr_state to be more architecturally-neutral. - Introduce resctrl_arch_update_cpu() to replace the explicit write to MSR_IA32_PQR_ASSOC in __resctrl_sched_in(). In the case of MPAM, PARTID[_I,D] and PMG are a simple function of closid, rmid, and an internal global. - Update terminology containing explicit references to the PQR_ASSOC register. Signed-off-by: Peter Newman --- arch/x86/kernel/cpu/resctrl/core.c | 11 ++++++++--- arch/x86/kernel/cpu/resctrl/internal.h | 6 +++--- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 ++-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 18 +++++++++--------- include/linux/resctrl.h | 11 +++++++++++ 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index ae5878d748fc..4cc584754f8b 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -37,12 +37,12 @@ static DEFINE_MUTEX(domain_list_lock); /* - * The cached resctrl_pqr_state is strictly per CPU and can never be + * The cached resctrl_cpu_state is strictly per CPU and can never be * updated from a remote CPU. Functions which modify the state * are called with interrupts disabled and no preemption, which * is sufficient for the protection. */ -DEFINE_PER_CPU(struct resctrl_pqr_state, pqr_state); +DEFINE_PER_CPU(struct resctrl_cpu_state, resctrl_state); /* * Used to store the max resource name width and max resource data width @@ -309,6 +309,11 @@ static void rdt_get_cdp_l2_config(void) rdt_get_cdp_config(RDT_RESOURCE_L2); } +void resctrl_arch_update_cpu(u32 ctrl_id, u32 mon_id) +{ + wrmsr(MSR_IA32_PQR_ASSOC, mon_id, ctrl_id); +} + static void mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r) { @@ -598,7 +603,7 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) static void clear_closid_rmid(int cpu) { - struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state); + struct resctrl_cpu_state *state = this_cpu_ptr(&resctrl_state); state->default_group = &rdtgroup_default; state->cur_closid = RESCTRL_RESERVED_CLOSID; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index 0ba0d2428780..e30f42744ac7 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -332,7 +332,7 @@ struct rftype { }; /** - * struct resctrl_pqr_state - State cache for the PQR MSR + * struct resctrl_cpu_state - State cache for allocation/monitoring group IDs * @cur_rmid: The cached Resource Monitoring ID * @cur_closid: The cached Class Of Service ID * @default_group: The user assigned rdtgroup @@ -340,13 +340,13 @@ struct rftype { * The cache also helps to avoid pointless updates if the value does * not change. */ -struct resctrl_pqr_state { +struct resctrl_cpu_state { u32 cur_rmid; u32 cur_closid; struct rdtgroup *default_group; }; -DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state); +DECLARE_PER_CPU(struct resctrl_cpu_state, resctrl_state); /** * struct mbm_state - status for each MBM counter in each domain diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c index 884b88e25141..ca1805a566cb 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -480,8 +480,8 @@ static int pseudo_lock_fn(void *_rdtgrp) */ saved_msr = __rdmsr(MSR_MISC_FEATURE_CONTROL); __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); - closid_p = this_cpu_read(pqr_state.cur_closid); - rmid_p = this_cpu_read(pqr_state.cur_rmid); + closid_p = this_cpu_read(resctrl_state.cur_closid); + rmid_p = this_cpu_read(resctrl_state.cur_rmid); mem_r = plr->kmem; size = plr->size; line_size = plr->line_size; diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c index badf181c8cbb..bd067f7ed5b6 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -112,7 +112,7 @@ void rdt_staged_configs_clear(void) * + We can simply set current's closid to assign a task to a resource * group. * + Context switch code can avoid extra memory references deciding which - * CLOSID to load into the PQR_ASSOC MSR + * CLOSID to load into the CPU * - We give up some options in configuring resource groups across multi-socket * systems. * - Our choices on how to configure each resource become progressively more @@ -347,7 +347,7 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of, */ void __resctrl_sched_in(struct task_struct *tsk) { - struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state); + struct resctrl_cpu_state *state = this_cpu_ptr(&resctrl_state); u32 closid = state->cur_closid; u32 rmid = state->cur_rmid; struct rdtgroup *rgrp; @@ -401,7 +401,7 @@ void __resctrl_sched_in(struct task_struct *tsk) if (closid != state->cur_closid || rmid != state->cur_rmid) { state->cur_closid = closid; state->cur_rmid = rmid; - wrmsr(MSR_IA32_PQR_ASSOC, rmid, closid); + resctrl_arch_update_cpu(closid, rmid); } } @@ -416,7 +416,7 @@ static void update_cpu_closid_rmid(void *info) struct rdtgroup *r = info; if (r) - this_cpu_write(pqr_state.default_group, r); + this_cpu_write(resctrl_state.default_group, r); /* * We cannot unconditionally write the MSR because the current @@ -635,8 +635,8 @@ static void rdtgroup_remove(struct rdtgroup *rdtgrp) static void _update_task_closid_rmid(void *task) { /* - * If the task is still current on this CPU, update PQR_ASSOC MSR. - * Otherwise, the MSR is updated when the task is scheduled in. + * If the task is still current on this CPU, update the current ctrl + * group. Otherwise, the CPU is updated when the task is scheduled in. */ if (task == current) resctrl_sched_in(task); @@ -3005,7 +3005,7 @@ static void rmdir_all_sub(void) else rdtgroup_remove(rdtgrp); } - /* Notify online CPUs to update per cpu storage and PQR_ASSOC MSR */ + /* Update online CPUs to propagate group membership changes. */ update_closid_rmid(cpu_online_mask, &rdtgroup_default); kernfs_remove(kn_info); @@ -3688,7 +3688,7 @@ static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) /* Update per cpu rmid of the moved CPUs first */ for_each_cpu(cpu, &rdtgrp->cpu_mask) - per_cpu(pqr_state.default_group, cpu) = prdtgrp; + per_cpu(resctrl_state.default_group, cpu) = prdtgrp; /* * Update the MSR on moved CPUs and CPUs which have moved * task running on them. @@ -3732,7 +3732,7 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask) /* Update per cpu closid and rmid of the moved CPUs first */ for_each_cpu(cpu, &rdtgrp->cpu_mask) - per_cpu(pqr_state.default_group, cpu) = &rdtgroup_default; + per_cpu(resctrl_state.default_group, cpu) = &rdtgroup_default; /* * Update the MSR on moved CPUs and CPUs which have moved diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index b2af1fbc7aa1..a6b1b13cc769 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -306,6 +306,17 @@ extern unsigned int resctrl_rmid_realloc_limit; DECLARE_STATIC_KEY_FALSE(rdt_enable_key); +/* + * resctrl_arch_update_cpu() - Make control and monitoring group IDs effective + * on the current CPU + * + * @ctrl_id: An identifier for the control group which is to be used on the + * current CPU. + * @mon_id: An identifier for the monitoring group which is to be used on + * the current CPU. + */ +void resctrl_arch_update_cpu(u32 ctrl_id, u32 mon_id); + void __resctrl_sched_in(struct task_struct *tsk); /* -- 2.44.0.396.g6e790dbe36-goog