Message ID | 20231120111340.7805-24-ilpo.jarvinen@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2127046vqn; Mon, 20 Nov 2023 03:19:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrXQ9FQMdCCV0wpUJcsX0W31rh07LgIZ/5Ay7vVJSNSHwENkOAUOkb844FIRAsjYMC/Me/ X-Received: by 2002:a05:6a00:2e1b:b0:6cb:a578:1345 with SMTP id fc27-20020a056a002e1b00b006cba5781345mr1816443pfb.12.1700479173497; Mon, 20 Nov 2023 03:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700479173; cv=none; d=google.com; s=arc-20160816; b=d5eD+w1lAa0IepD+seMviSeSwrbPIzbiYIsSM7B5BLc2yEnXYGUXD7vJsnL2lyGSFe 3kX9zS/tNhy0q7fqWOZH7uqY4uhpoizoHLpMuf3yMhQHqNEB7CxF/sURFJj2rKL1tDBH yoLYtl5qogKwDZoDWjIDlufiUnkvfx/2VeocqsqL79ygtjhtyxI03/thoz5klFV8w+vh /0koMzD9o9JOWWZJGWBL9Bpck1mRLgAXZQYA1dnZtZdhIKkwENUcjyXboJvs4l/xD0x1 eXtNeJFfhAlAxqnXzCZywV76j7NnD9grQJEN3ANnuLRCcPju0ZTINFV/olOdcrkwgszz 0hog== 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 :dkim-signature; bh=LDAQoyfSF1e4kZGIoRkbaoHGYXCfyIOrs2gpdOwmAsA=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=MQDwWpaN44y811pKWiI115vVPhI6CmrMIkfWsItRC+zoTOwrHzclUt3/mTH+Qfhnf+ uZobCfZt03N4Fh1sVMWoK5E+FfiKYumg5qkIQQqLPBPyzokuOIHcQSBd7GmKaVwpNLig /Ljfofl+/RBmnlNbbn87viW+uT5T+vE/f5zGhH8lJ/bdaTRvRzrTMww63oR6epJy6cEN EioLMI4tJytPA2WaILCX9WDrUeKdm4j7dRzAFVUgsPBd00v1ezBs2FAAQW6rmaNdqBSd EKcWectNi9giebk1AleNKzWIwSXTVH/8Jn6ZfzniB0wet7o2f2M1XnssaeJVLhJSMkqo MQvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8YPG+vT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f2-20020a631f02000000b005bd0728aeccsi7623540pgf.407.2023.11.20.03.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:19:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q8YPG+vT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7387F802573D; Mon, 20 Nov 2023 03:19:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233481AbjKTLS7 (ORCPT <rfc822;heyuhang3455@gmail.com> + 27 others); Mon, 20 Nov 2023 06:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233441AbjKTLSg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Nov 2023 06:18:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E6F12691; Mon, 20 Nov 2023 03:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700479045; x=1732015045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=22cBx10DhRppnsCIlGXNuC/WP0NGzPH27j7vhPlKXIE=; b=Q8YPG+vT++sd3+/xfjVuBRrUoIJOFlTvmrI2tr8RSKCRuZCYu7o/+kpd JJsbNVZYLQ6vXWQF8eq4WDGDY4aXoE0Wb4quG2Lg1czWiRq5/rjFbLTop iYsRU4aBe8/Y0sYPebT2+oo8kA2jGkPH04h4H2hm7OCzSKF990g8RPtR1 m97FBA8MzfTeuvoEmzknyrXeprCpSOT3iQWvL0gd2IvQHfSDmJChpfhhc rLDOnW7G7vz+QZq2vEfWsoZopEbLHMcUj70lCjqr3JDHrvZPm1jlQIDe8 nWo3BeAw6UmLQqO3u9dV3bNtNxrygb+qXXV/Eb/J982vkp5V3E+BUFp55 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="13152215" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="13152215" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:17:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="832238714" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="832238714" Received: from sc9itsct4906.amr.corp.intel.com (HELO localhost) ([10.249.46.107]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:17:04 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com> To: linux-kselftest@vger.kernel.org, Reinette Chatre <reinette.chatre@intel.com>, Shuah Khan <shuah@kernel.org>, Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>, =?utf-8?q?Maciej_Wiecz=C3=B3r-R?= =?utf-8?q?etman?= <maciej.wieczor-retman@intel.com>, Fenghua Yu <fenghua.yu@intel.com> Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com> Subject: [PATCH v2 23/26] selftests/resctrl: Add helper to convert L2/3 to integer Date: Mon, 20 Nov 2023 13:13:37 +0200 Message-Id: <20231120111340.7805-24-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> References: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:19:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783081649803288554 X-GMAIL-MSGID: 1783081649803288554 |
Series |
selftests/resctrl: CAT test improvements & generalized test framework
|
|
Commit Message
Ilpo Järvinen
Nov. 20, 2023, 11:13 a.m. UTC
"L2"/"L3" conversion to integer is embedded into get_cache_size()
which prevents reuse.
Create a helper for the cache string to integer conversion to make
it reusable.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
tools/testing/selftests/resctrl/resctrlfs.c | 28 +++++++++++++++------
1 file changed, 20 insertions(+), 8 deletions(-)
Comments
Hi Ilpo, On 11/20/2023 3:13 AM, Ilpo Järvinen wrote: > "L2"/"L3" conversion to integer is embedded into get_cache_size() > which prevents reuse. > > Create a helper for the cache string to integer conversion to make > it reusable. > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> > --- > tools/testing/selftests/resctrl/resctrlfs.c | 28 +++++++++++++++------ > 1 file changed, 20 insertions(+), 8 deletions(-) > > diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c > index fda5ad812faa..38ca3ae562e9 100644 > --- a/tools/testing/selftests/resctrl/resctrlfs.c > +++ b/tools/testing/selftests/resctrl/resctrlfs.c > @@ -94,6 +94,23 @@ int umount_resctrlfs(void) > return 0; > } > > +/* > + * get_cache_level - Convert cache level from string to integer > + * @cache_type: Cache level as string > + * > + * Return: cache level as integer or -1 if @cache_type is invalid. > + */ > +static int get_cache_level(const char *cache_type) > +{ > + if (!strcmp(cache_type, "L3")) > + return 3; > + if (!strcmp(cache_type, "L2")) > + return 2; > + > + perror("Invalid cache level"); I know that you are just copying code here but this usage of perror() does not look right. strcmp() does not set errno, it does not "fail". Reinette
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index fda5ad812faa..38ca3ae562e9 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -94,6 +94,23 @@ int umount_resctrlfs(void) return 0; } +/* + * get_cache_level - Convert cache level from string to integer + * @cache_type: Cache level as string + * + * Return: cache level as integer or -1 if @cache_type is invalid. + */ +static int get_cache_level(const char *cache_type) +{ + if (!strcmp(cache_type, "L3")) + return 3; + if (!strcmp(cache_type, "L2")) + return 2; + + perror("Invalid cache level"); + return -1; +} + /* * get_resource_id - Get socket number/l3 id for a specified CPU * @cpu_no: CPU number @@ -144,14 +161,9 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size int length, i, cache_num; FILE *fp; - if (!strcmp(cache_type, "L3")) { - cache_num = 3; - } else if (!strcmp(cache_type, "L2")) { - cache_num = 2; - } else { - perror("Invalid cache level"); - return -1; - } + cache_num = get_cache_level(cache_type); + if (cache_num < 0) + return cache_num; sprintf(cache_path, "/sys/bus/cpu/devices/cpu%d/cache/index%d/size", cpu_no, cache_num);