Message ID | c7b66a4682829894ec72d8a1f78e324233ef0535.1702392177.git.maciej.wieczor-retman@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7774596vqy; Tue, 12 Dec 2023 06:53:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgFNsW5caLv4lE7Lzfu1SFtrWOJBgSKTChI3DaKJlQNv1k1icAb28XRK9vy9vOVVox4gEG X-Received: by 2002:a05:6a00:1704:b0:6ce:3584:b636 with SMTP id h4-20020a056a00170400b006ce3584b636mr3628936pfc.27.1702392823205; Tue, 12 Dec 2023 06:53:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702392823; cv=none; d=google.com; s=arc-20160816; b=WaVQLo04mM9rx+DbxGXrEo8qltmKGHI2GzW/kCo7HYfRJlGCOGGR6vZG3AAhLR5gVr DMC4buOyeMYTGKUlEx+iz38Ctjir/NCP7QbMXnObE9deB0iziBEatCaCWeSmgWJpg91+ AWIxZbSsz3+x0pfxFCwU8y+T80/QHPXs2liSZfKINPLuLC8qCmmyIBL/ClShDJ3zgZfZ J4ttIcPjQPL+r2cKH8MusYZEJuJ4lPdQj+cO9y8yVZWyDVerPlFA1JhTTI1O0os+sRKw je/RHuYwrZtMAXKgg1VMwd47iw8w0gH2lj4JXOVa8G/15ZmSMTHChOTD3mlIjYyrNgTp TA2w== 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=7P/aUBAzLwnIqxyJafmMKx5DpnAfqZ0Sl4o0lTQflt4=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=UMjfK/94zPHtHk34LKQ8A3U6HdgJxU/ES6rKpcTdDEt+b1qOJM8Yz9i9u+jYGSPnIB 7PcBHua/lVABx5cuf1MKacWMaAqhPlhR9eq2RaVlIUCUdt5Az8+NsNPUME5oNypItpns OXU/OrGh4hDI8IRQdjG/ygjeK5iyJEywu1y6js2Xq78JEMiJQainw5pPKU3NtP4akQ7O BElMJzNa/GSTsGO0L9I0mK+bePjizGq+7JjZ+LMdXU4655N3SFDayUQIoiB9DZYOFGbq vi3crBPbYwNqL8v4xVMuYSD6+33ru15BodmGVYAwi8L8/DGx4oSsJrmvZVNXG2mO8rDl 8gIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=APKBhwtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i3-20020a6551c3000000b005c6977f9c0dsi7862526pgq.214.2023.12.12.06.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:53:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=APKBhwtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 381B18026DB1; Tue, 12 Dec 2023 06:53:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376998AbjLLOxT (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Tue, 12 Dec 2023 09:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376969AbjLLOxS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 12 Dec 2023 09:53:18 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3784EB; Tue, 12 Dec 2023 06:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702392803; x=1733928803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qo202yzdW9FjkslWfPMmIkndsLvL+V5BLV3JStn7eyw=; b=APKBhwtqjI+K6C+Q6mkeiVnM/jaC47UDxSp3G/yoQe73ubc26YAjLRuT az7ZQTqaa9MP8EwdDtWKMssKBWT00ghyXzrbAWXnMDePFOY1gd4VUF/IW wyhLRVmQJ+plx2NFoX2DQsqkdlsdv83jhlREFAda9mZlsxv59zA5P4v8n EoTfv/Ab2BDC8F+dIIo6E7PDeU9AdYGgHxDJel7Pk6gJBiDUl2kVwxZaw Ny5XQh9qn4DAE/Wq0oqCc8g1OvE8MJ//wfLZWR9EKeOz+zxQGrioRJure oaJSehEYVZU+V+JOAEr4QNhhK/yUEHprsobLoUbev4oDn0p54AzAVvseL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="481014340" X-IronPort-AV: E=Sophos;i="6.04,270,1695711600"; d="scan'208";a="481014340" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 06:53:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,270,1695711600"; d="scan'208";a="15023957" Received: from mdabrows-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.5.65]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 06:53:21 -0800 From: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> To: Fenghua Yu <fenghua.yu@intel.com>, Reinette Chatre <reinette.chatre@intel.com>, Shuah Khan <shuah@kernel.org> Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 2/4] selftests/resctrl: Add helpers for the non-contiguous test Date: Tue, 12 Dec 2023 15:52:52 +0100 Message-ID: <c7b66a4682829894ec72d8a1f78e324233ef0535.1702392177.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <cover.1702392177.git.maciej.wieczor-retman@intel.com> References: <cover.1702392177.git.maciej.wieczor-retman@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 06:53:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785088257037350640 X-GMAIL-MSGID: 1785088257037350640 |
Series |
selftests/resctrl: Add non-contiguous CBMs in Intel CAT selftest
|
|
Commit Message
Maciej Wieczor-Retman
Dec. 12, 2023, 2:52 p.m. UTC
The CAT non-contiguous selftests have to read the file responsible for
reporting support of non-contiguous CBMs in Intel CAT. Then the test
compares if that information matches what is reported by CPUID output.
Add a generic helper function to read a chosen functionality support
information.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
---
Changelog v2:
- Added this patch.
tools/testing/selftests/resctrl/resctrl.h | 1 +
tools/testing/selftests/resctrl/resctrlfs.c | 25 +++++++++++++++++++++
2 files changed, 26 insertions(+)
Comments
Hi Maciej, On 12/12/2023 6:52 AM, Maciej Wieczor-Retman wrote: > The CAT non-contiguous selftests have to read the file responsible for > reporting support of non-contiguous CBMs in Intel CAT. Then the test "in Intel CAT" -> "in kernel (resctrl)" > compares if that information matches what is reported by CPUID output. > > Add a generic helper function to read a chosen functionality support > information. Since this is a generic function that just reads a value from a file it cannot be assumed that the value represents functionality support. > > Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> > --- > Changelog v2: > - Added this patch. > > tools/testing/selftests/resctrl/resctrl.h | 1 + > tools/testing/selftests/resctrl/resctrlfs.c | 25 +++++++++++++++++++++ > 2 files changed, 26 insertions(+) > > diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h > index 739e16d08a7b..8f72d94b9cbe 100644 > --- a/tools/testing/selftests/resctrl/resctrl.h > +++ b/tools/testing/selftests/resctrl/resctrl.h > @@ -161,6 +161,7 @@ unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); > int get_full_cbm(const char *cache_type, unsigned long *mask); > int get_mask_no_shareable(const char *cache_type, unsigned long *mask); > int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); > +int read_info_res_file(const char *resource, const char *filename); > void ctrlc_handler(int signum, siginfo_t *info, void *ptr); > int signal_handler_register(void); > void signal_handler_unregister(void); > diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c > index 0e97036a64b8..70333440ff2f 100644 > --- a/tools/testing/selftests/resctrl/resctrlfs.c > +++ b/tools/testing/selftests/resctrl/resctrlfs.c > @@ -249,6 +249,31 @@ static int get_bit_mask(const char *filename, unsigned long *mask) > return 0; > } > > +int read_info_res_file(const char *resource, const char *filename) Considering that this is intended to be a new generic utility, could you please add some function documentation? > +{ > + char file_path[PATH_MAX]; > + FILE *fp; > + int ret; > + > + snprintf(file_path, sizeof(file_path), "%s/%s/%s", INFO_PATH, resource, > + filename); > + > + fp = fopen(file_path, "r"); > + if (!fp) { > + perror("Error in opening sparse_masks file\n"); The error messages do not match the goal of this function to be generic. Also, please note the recent cleanup done by Ilpo to replace the perror() by ksft_perror(). > + return -1; > + } > + > + if (fscanf(fp, "%u", &ret) <= 0) { I find this to be potentially confusing. The function claims to be a generic utility to read a value from a resctrl file ... but hidden within is that the value is required to be unsigned, which is then cast into an int. This could be made more specific and robust with something like below: int resource_info_unsigned_get(const char *resource, const char *filename, unsigned int *val) The return value will be the result of the request. If resource_info_unsigned_get() returns 0 then @val will contain the value read. > + perror("Could not get sparse_masks contents\n"); > + fclose(fp); > + return -1; > + } > + > + fclose(fp); > + return ret; > +} > + > /* > * create_bit_mask- Create bit mask from start, len pair > * @start: LSB of the mask Reinette
Hi! On 2024-01-08 at 14:36:36 -0800, Reinette Chatre wrote: >Hi Maciej, > >On 12/12/2023 6:52 AM, Maciej Wieczor-Retman wrote: >> The CAT non-contiguous selftests have to read the file responsible for >> reporting support of non-contiguous CBMs in Intel CAT. Then the test > >"in Intel CAT" -> "in kernel (resctrl)" Sure, will fix. >> compares if that information matches what is reported by CPUID output. >> >> Add a generic helper function to read a chosen functionality support >> information. > >Since this is a generic function that just reads a value from a file it >cannot be assumed that the value represents functionality support. Right, I'll rewrite this. >> >> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> >> --- >> Changelog v2: >> - Added this patch. >> >> tools/testing/selftests/resctrl/resctrl.h | 1 + >> tools/testing/selftests/resctrl/resctrlfs.c | 25 +++++++++++++++++++++ >> 2 files changed, 26 insertions(+) >> >> diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h >> index 739e16d08a7b..8f72d94b9cbe 100644 >> --- a/tools/testing/selftests/resctrl/resctrl.h >> +++ b/tools/testing/selftests/resctrl/resctrl.h >> @@ -161,6 +161,7 @@ unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); >> int get_full_cbm(const char *cache_type, unsigned long *mask); >> int get_mask_no_shareable(const char *cache_type, unsigned long *mask); >> int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); >> +int read_info_res_file(const char *resource, const char *filename); >> void ctrlc_handler(int signum, siginfo_t *info, void *ptr); >> int signal_handler_register(void); >> void signal_handler_unregister(void); >> diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c >> index 0e97036a64b8..70333440ff2f 100644 >> --- a/tools/testing/selftests/resctrl/resctrlfs.c >> +++ b/tools/testing/selftests/resctrl/resctrlfs.c >> @@ -249,6 +249,31 @@ static int get_bit_mask(const char *filename, unsigned long *mask) >> return 0; >> } >> >> +int read_info_res_file(const char *resource, const char *filename) > >Considering that this is intended to be a new generic utility, could you >please add some function documentation? Sure >> +{ >> + char file_path[PATH_MAX]; >> + FILE *fp; >> + int ret; >> + >> + snprintf(file_path, sizeof(file_path), "%s/%s/%s", INFO_PATH, resource, >> + filename); >> + >> + fp = fopen(file_path, "r"); >> + if (!fp) { >> + perror("Error in opening sparse_masks file\n"); > >The error messages do not match the goal of this function to be generic. >Also, please note the recent cleanup done by Ilpo to replace the perror() >by ksft_perror(). Thanks for catching this, will fix. >> + return -1; >> + } >> + >> + if (fscanf(fp, "%u", &ret) <= 0) { > >I find this to be potentially confusing. The function claims to be a generic >utility to read a value from a resctrl file ... but hidden within is that the >value is required to be unsigned, which is then cast into an int. This could be >made more specific and robust with something like below: > int resource_info_unsigned_get(const char *resource, const char *filename, > unsigned int *val) > >The return value will be the result of the request. If resource_info_unsigned_get() >returns 0 then @val will contain the value read. Right, that might be confusing. Will fix according to your comment, thanks! >> + perror("Could not get sparse_masks contents\n"); >> + fclose(fp); >> + return -1; >> + } >> + >> + fclose(fp); >> + return ret; >> +} >> + >> /* >> * create_bit_mask- Create bit mask from start, len pair >> * @start: LSB of the mask > >Reinette
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 739e16d08a7b..8f72d94b9cbe 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -161,6 +161,7 @@ unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); int get_full_cbm(const char *cache_type, unsigned long *mask); int get_mask_no_shareable(const char *cache_type, unsigned long *mask); int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); +int read_info_res_file(const char *resource, const char *filename); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); void signal_handler_unregister(void); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 0e97036a64b8..70333440ff2f 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -249,6 +249,31 @@ static int get_bit_mask(const char *filename, unsigned long *mask) return 0; } +int read_info_res_file(const char *resource, const char *filename) +{ + char file_path[PATH_MAX]; + FILE *fp; + int ret; + + snprintf(file_path, sizeof(file_path), "%s/%s/%s", INFO_PATH, resource, + filename); + + fp = fopen(file_path, "r"); + if (!fp) { + perror("Error in opening sparse_masks file\n"); + return -1; + } + + if (fscanf(fp, "%u", &ret) <= 0) { + perror("Could not get sparse_masks contents\n"); + fclose(fp); + return -1; + } + + fclose(fp); + return ret; +} + /* * create_bit_mask- Create bit mask from start, len pair * @start: LSB of the mask