Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp872390lqs; Fri, 14 Jun 2024 08:04:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8NoMedqz5j+AReJJGN6blT5KwhSgZAmpPeUcu3D+Vkp41JwKvVWq0w2OqPcDIZTDjtoNKySM3icjVmkNCqN7pLKpPzUZPSlHnA0Irig== X-Google-Smtp-Source: AGHT+IEK9jnmNRJv3qPOLH6Rvv6wFWk7K2h5/sUDFTQGNUwrgpJSsObdiIXl6gLkKavH5AZdi9vB X-Received: by 2002:a05:6830:1bdc:b0:6ef:8860:b329 with SMTP id 46e09a7af769-6fb939fb39cmr3533133a34.25.1718377443082; Fri, 14 Jun 2024 08:04:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718377443; cv=pass; d=google.com; s=arc-20160816; b=IkE6fMY5OtaL6NG5yzPdLYSG77h2OO+cBfNenVcadvIf9zdfZKNntR5cSMhi4YUGYP CFtlypLcLEf2Yq/pFT+9dz2UqwQjr6xVemCR9393b9AifhUcHP3bLpS8fh5I8NXay364 QAOK8fePh05Q1oLhda/7jLO2R5N2tTmZ+Jspe6XFlawup359FKl+Xe7JhYjwpEaJjQkF QkRl0adXoSvpiiGU57dh1Z+QTxw13bWiL0WCJhcxz6cORH3MEU5lv6rV/fzW2fg/ijfx /IOcQHjiZv0eUfGzUUwFV/3F5yhAtIy8mrchxwVColVTjcdCrG/t7D+gTAGGFMtxCv3O PJlA== 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=1jSzOtdqyLhTzdJdUr1GaYtY/XOKRUPr4x4idkFlgow=; fh=knouHfhWmUABu+sT2q0nnGKUzC7/WRiZH1KSpGv7uFs=; b=Clq6YUnQ2SPpdD0ogqJrZi/N9E0w3yl2OCW7aJogMUUHTyyk3L11DCSrtTWRBkMOtg sN7ry6c2BerBVW2CTHn9bBuVRgqB1YDOM7vGMhK6TI/DUJRk5umzGkmsUCh+AI/ZyOs1 VUifp9uKoSsmk3C9S/Q2nKpawu/6iullgXOzZad93pX7N1qAP8LMh0FBz7AwNtWuaM5s TUrg+YdrWloxxDkj8qmO+z7OcAxM7hvhJLnrdSR9ThE/vLnTQ8pkaIcb5LwMaWMrFT+n 3VsPwd1BhsAC7HyXSMLwxndwtiUE4FcJPdM6IXNGT01giAtXUFGJ20P1ArSwC4G+bNKF 4fNw==; 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-215070-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215070-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 46e09a7af769-6fb5b63bdb6si1417800a34.162.2024.06.14.08.04.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 08:04:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215070-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-215070-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215070-linux.lists.archive=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 39A45284A90 for ; Fri, 14 Jun 2024 15:02:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E913316C45F; Fri, 14 Jun 2024 15:01:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A004916A38B for ; Fri, 14 Jun 2024 15:01:22 +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=1718377284; cv=none; b=oVag9CvOvx9d3iWX7arLWHYkGQuSfq2s4Sfx++5AruP072Ai4QHS5CCXzux1FrYtZfd2QxqCN/UBDTMGuHdwlkKH6u9xLunUyJBIZLGSrvuGbW20pJxpuUGZaiABfQ0odra/IsLiqw8Ic7UHrXjj6KZ8xHUzmN8azSIFHGPvMDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718377284; c=relaxed/simple; bh=/MPyOVlBkzzGQdipxmMsNdOA3t+WXYsCkizTFAOzw28=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=giwdlYjdL/y0czkUsE2tebZei3+iHeZ46Chrs/yhDlni1maR33Ja2+w9UHo1miQAbPFtBLuZv+kD8VdmsyCPglVZu9y64EBR0829DK96TBYIrmyim9Sv3jE/CHsHAu0OzNI/s9XL6Oso574PB55CrXJxsxEPfMxMr3tmtLsbVvY= 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 9907DFEC; Fri, 14 Jun 2024 08:01:46 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 070733F5A1; Fri, 14 Jun 2024 08:01:18 -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, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin Subject: [PATCH v3 04/38] x86/resctrl: Use schema type to determine how to parse schema values Date: Fri, 14 Jun 2024 14:59:59 +0000 Message-Id: <20240614150033.10454-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240614150033.10454-1-james.morse@arm.com> References: <20240614150033.10454-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 Content-Transfer-Encoding: 8bit Resctrl's architecture code gets to specify a function pointer that is used when parsing schema entries. This is expected to be one of two helpers from the filesystem code. Setting this function pointer allows the architecture code to change the ABI resctrl presents to user-space, and forces resctrl to expose these helpers. Instead, use the schema format enum to choose which schema parser to use. This allows the helpers to be made static and the structs used for passing arguments moved out of shared headers. Signed-off-by: James Morse --- Changes since v2: * This patch is new --- arch/x86/kernel/cpu/resctrl/core.c | 4 --- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 33 +++++++++++++++++++---- arch/x86/kernel/cpu/resctrl/internal.h | 10 ------- include/linux/resctrl.h | 5 ---- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index a72fd53e0ffe..02a51cce380f 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -71,7 +71,6 @@ struct rdt_hw_resource rdt_resources_all[] = { .schema_fmt = RESCTRL_SCHEMA_BITMAP, .cache_level = 3, .domains = domain_init(RDT_RESOURCE_L3), - .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", }, .msr_base = MSR_IA32_L3_CBM_BASE, @@ -85,7 +84,6 @@ struct rdt_hw_resource rdt_resources_all[] = { .schema_fmt = RESCTRL_SCHEMA_BITMAP, .cache_level = 2, .domains = domain_init(RDT_RESOURCE_L2), - .parse_ctrlval = parse_cbm, .format_str = "%d=%0*x", }, .msr_base = MSR_IA32_L2_CBM_BASE, @@ -103,7 +101,6 @@ struct rdt_hw_resource rdt_resources_all[] = { .schema_fmt = RESCTRL_SCHEMA_PERCENTAGE, .cache_level = 3, .domains = domain_init(RDT_RESOURCE_MBA), - .parse_ctrlval = parse_bw, .format_str = "%d=%*u", }, }, @@ -115,7 +112,6 @@ struct rdt_hw_resource rdt_resources_all[] = { .schema_fmt = RESCTRL_SCHEMA_MBPS, .cache_level = 3, .domains = domain_init(RDT_RESOURCE_SMBA), - .parse_ctrlval = parse_bw, .format_str = "%d=%*u", }, }, diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c index 9f1ed26b9d83..30a4ff2b6392 100644 --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c @@ -23,6 +23,15 @@ #include "internal.h" +struct rdt_parse_data { + struct rdtgroup *rdtgrp; + char *buf; +}; + +typedef int (ctrlval_parser_t)(struct rdt_parse_data *data, + struct resctrl_schema *s, + struct rdt_domain *d); + /* * Check whether MBA bandwidth percentage value is correct. The value is * checked against the minimum and max bandwidth values specified by the @@ -59,8 +68,8 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) return true; } -int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d) +static int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, + struct rdt_domain *d) { struct resctrl_staged_config *cfg; u32 closid = data->rdtgrp->closid; @@ -138,8 +147,8 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r) * Read one cache bit mask (hex). Check that it is valid for the current * resource type. */ -int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d) +static int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, + struct rdt_domain *d) { struct rdtgroup *rdtgrp = data->rdtgrp; struct resctrl_staged_config *cfg; @@ -195,6 +204,19 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, return 0; } +static ctrlval_parser_t *get_parser(struct rdt_resource *r) +{ + switch (r->schema_fmt) { + case RESCTRL_SCHEMA_BITMAP: + return &parse_cbm; + case RESCTRL_SCHEMA_PERCENTAGE: + case RESCTRL_SCHEMA_MBPS: + return &parse_bw; + }; + + return NULL; +} + /* * For each domain in this resource we expect to find a series of: * id=mask @@ -204,6 +226,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, static int parse_line(char *line, struct resctrl_schema *s, struct rdtgroup *rdtgrp) { + ctrlval_parser_t *parse_ctrlval = get_parser(s->res); enum resctrl_conf_type t = s->conf_type; struct resctrl_staged_config *cfg; struct rdt_resource *r = s->res; @@ -235,7 +258,7 @@ static int parse_line(char *line, struct resctrl_schema *s, if (d->id == dom_id) { data.buf = dom; data.rdtgrp = rdtgrp; - if (r->parse_ctrlval(&data, s, d)) + if (parse_ctrlval(&data, s, d)) return -EINVAL; if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { cfg = &d->staged_config[t]; diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index e11abefcfd31..7e0b0b5f3530 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -416,11 +416,6 @@ static inline bool is_mbm_event(int e) e <= QOS_L3_MBM_LOCAL_EVENT_ID); } -struct rdt_parse_data { - struct rdtgroup *rdtgrp; - char *buf; -}; - /** * struct rdt_hw_resource - arch private attributes of a resctrl resource * @r_resctrl: Attributes of the resource used directly by resctrl. @@ -457,11 +452,6 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r return container_of(r, struct rdt_hw_resource, r_resctrl); } -int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d); -int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s, - struct rdt_domain *d); - extern struct mutex rdtgroup_mutex; extern struct rdt_hw_resource rdt_resources_all[]; diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 4822abbc08c8..975345f3cd0a 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -157,7 +157,6 @@ struct resctrl_membw { u32 *mb_map; }; -struct rdt_parse_data; struct resctrl_schema; /** @@ -186,7 +185,6 @@ enum resctrl_schema_fmt { * @data_width: Character width of data when displaying * @default_ctrl: Specifies default cache cbm or memory B/W percent. * @format_str: Per resource format string to show domain value - * @parse_ctrlval: Per resource function pointer to parse control values * @schema_fmt: Which format string and parser is used for this schema. * @evt_list: List of monitoring events * @cdp_capable: Is the CDP feature available on this resource @@ -204,9 +202,6 @@ struct rdt_resource { int data_width; u32 default_ctrl; const char *format_str; - int (*parse_ctrlval)(struct rdt_parse_data *data, - struct resctrl_schema *s, - struct rdt_domain *d); enum resctrl_schema_fmt schema_fmt; struct list_head evt_list; bool cdp_capable; -- 2.39.2