From nobody Sun Feb 8 12:39:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7845F82871; Mon, 10 Jun 2024 15:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032519; cv=none; b=AYo0nI17j+TABwU8e5u3KLnmY11Nmp6EuLbeXF11MX3vHqjZ/7VTMxTmBuXzy/N2Gfjl8/sERbGWxa/Pf9GZMIGT2uJku1MQmYxJ58ib48tFmJ21/1bQV1R9fxr14wK1G+dcERnoUwNXfPcP+3n0B4ymQGk/j7NKy+3/TBhPXYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032519; c=relaxed/simple; bh=4/Qp8u2h+IfawVv608B46Hfr/DmfJXUXdWM5x/4OihA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PFgnlu8tJIpKuBKNtQrCL04phfeJV+1aAiN1a9z03CqLG3dyD7lLRycRCKMW+qZBJSHllGYuNeRr4rz1g3yBbBPFGz6CTYhj1xYFrkkJEi/zMlratLzb4e1TWY2MBYH/H7znvRNlaVFX0po1j6QmvTilpVOSqjpGRlXJrqb5v34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hwopetaG; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hwopetaG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032517; x=1749568517; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4/Qp8u2h+IfawVv608B46Hfr/DmfJXUXdWM5x/4OihA=; b=hwopetaGOzKv7JVn23KdLPuLsX6LQRP4qakQziRddQX+ShLcuE0ofcDq EfUWUqSGALtvBKGrfcu7GsQovLvRnLRBGgNKEEtZFlpZ7moXLSc23tna3 d6GPy87PTEttQwNWe1EK10jbFoQe2c+qATmwhwhW1o3R6IBXNOsv/Wz1j BQEnMnZYbCgkIb0fmFDr/vBZK7o0126vAS45kLC0nzt9x7snVH4gngWZ5 f8shg3r5z1NfRefvUPkjH+Yok+FMu4hsTS5/Vsw+GbkF9hkJvZ4A9a6gZ SAD3ltKMrdBdh9G/b2Z6ikFXEEv6n2IuyZwl+/VD77wllPnhSYENv92GC A==; X-CSE-ConnectionGUID: Ylie2ry7TH+P6JTkSmZq2w== X-CSE-MsgGUID: eX8HgNhaSDu+s5lpzzs27w== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530706" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530706" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:17 -0700 X-CSE-ConnectionGUID: aAY4Qoi9REWKDOuLxbf+jA== X-CSE-MsgGUID: 2D2PanrfS0KYX7YYHvRYIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650599" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:14 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 01/16] selftests/resctrl: Fix closing IMC fds on error and open-code R+W instead of loops Date: Mon, 10 Jun 2024 18:14:42 +0300 Message-Id: <20240610151457.7305-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The imc perf fd close() calls are missing from all error paths. In addition, get_mem_bw_imc() handles fds in a for loop but close() is based on two fixed indexes READ and WRITE. Open code inner for loops to READ+WRITE entries for clarity and add a function to close() IMC fds properly in all cases. Fixes: 7f4d257e3a2a ("selftests/resctrl: Add callback to start a benchmark") Suggested-by: Reinette Chatre Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v4: - Merge with the fix close patch - Add loop to reset imc_counters_config fds to -1 to be able know which need closing - Introduce perf_close_imc_mem_bw() to close fds v3: - Rework entirely, use open coding instead of for loops for clarity --- tools/testing/selftests/resctrl/resctrl_val.c | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 445f306d4c2f..f55f5989de72 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -293,6 +293,18 @@ static int initialize_mem_bw_imc(void) return 0; } =20 +static void perf_close_imc_mem_bw(void) +{ + int mc; + + for (mc =3D 0; mc < imcs; mc++) { + if (imc_counters_config[mc][READ].fd !=3D -1) + close(imc_counters_config[mc][READ].fd); + if (imc_counters_config[mc][WRITE].fd !=3D -1) + close(imc_counters_config[mc][WRITE].fd); + } +} + /* * get_mem_bw_imc: Memory band width as reported by iMC counters * @cpu_no: CPU number that the benchmark PID is binded to @@ -306,26 +318,33 @@ static int initialize_mem_bw_imc(void) static int get_mem_bw_imc(int cpu_no, char *bw_report, float *bw_imc) { float reads, writes, of_mul_read, of_mul_write; - int imc, j, ret; + int imc, ret; + + for (imc =3D 0; imc < imcs; imc++) { + imc_counters_config[imc][READ].fd =3D -1; + imc_counters_config[imc][WRITE].fd =3D -1; + } =20 /* Start all iMC counters to log values (both read and write) */ reads =3D 0, writes =3D 0, of_mul_read =3D 1, of_mul_write =3D 1; for (imc =3D 0; imc < imcs; imc++) { - for (j =3D 0; j < 2; j++) { - ret =3D open_perf_event(imc, cpu_no, j); - if (ret) - return -1; - } - for (j =3D 0; j < 2; j++) - membw_ioctl_perf_event_ioc_reset_enable(imc, j); + ret =3D open_perf_event(imc, cpu_no, READ); + if (ret) + goto close_fds; + ret =3D open_perf_event(imc, cpu_no, WRITE); + if (ret) + goto close_fds; + + membw_ioctl_perf_event_ioc_reset_enable(imc, READ); + membw_ioctl_perf_event_ioc_reset_enable(imc, WRITE); } =20 sleep(1); =20 /* Stop counters after a second to get results (both read and write) */ for (imc =3D 0; imc < imcs; imc++) { - for (j =3D 0; j < 2; j++) - membw_ioctl_perf_event_ioc_disable(imc, j); + membw_ioctl_perf_event_ioc_disable(imc, READ); + membw_ioctl_perf_event_ioc_disable(imc, WRITE); } =20 /* @@ -341,15 +360,13 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report= , float *bw_imc) if (read(r->fd, &r->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { ksft_perror("Couldn't get read b/w through iMC"); - - return -1; + goto close_fds; } =20 if (read(w->fd, &w->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { ksft_perror("Couldn't get write bw through iMC"); - - return -1; + goto close_fds; } =20 __u64 r_time_enabled =3D r->return_value.time_enabled; @@ -369,10 +386,7 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report,= float *bw_imc) writes +=3D w->return_value.value * of_mul_write * SCALE; } =20 - for (imc =3D 0; imc < imcs; imc++) { - close(imc_counters_config[imc][READ].fd); - close(imc_counters_config[imc][WRITE].fd); - } + perf_close_imc_mem_bw(); =20 if (strcmp(bw_report, "reads") =3D=3D 0) { *bw_imc =3D reads; @@ -386,6 +400,10 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report,= float *bw_imc) =20 *bw_imc =3D reads + writes; return 0; + +close_fds: + perf_close_imc_mem_bw(); + return -1; } =20 void set_mbm_path(const char *ctrlgrp, const char *mongrp, int domain_id) --=20 2.39.2 From nobody Sun Feb 8 12:39:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 707E013DB92; Mon, 10 Jun 2024 15:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032527; cv=none; b=p6p94fMp1rt7Ers3ouQPtvruS307zIA9SI4Cdkmq3VoZM5ruvzSvCFGpyekRbsJsacR92janqj1QLIGizzrvWKwuC8YdGX8ggm2j0gF+OW6cCE3Xyhn9nrTHXOvrA4HtyCXX85/Jk1SQ3vmHnqNOG7l0peKIRb/y5wywRqro10Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032527; c=relaxed/simple; bh=umhLK9mFRJKD1wp4WBIkl9QyGbIuXkZGfix5aEMovpY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PvJOQVAVIbgKrwiX1/ia9uXL2EF+4HHu9mI3xYJWQSQzdi8X1LzGuUBkEMr3OcYvyq8SUX/Tr+z+n/NnwYx1RQy+IMtpyzAtAkACQInM6tr0SI7XX7PWrSsFIZDG06Wd8Wjl4mZgI+tpKRggR+cRLUfvdi6i90PhsWb86lBXyQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RXc4rJEi; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RXc4rJEi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032525; x=1749568525; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=umhLK9mFRJKD1wp4WBIkl9QyGbIuXkZGfix5aEMovpY=; b=RXc4rJEi5MhhrISd3MhK8fznfkq8K/eIL4iP7Me5BtMj/6nlY0ZQimaa +sK8H2dyb3xLCX856Iza8u+wV2fWLPlKsw2bfY82zR+CgHLyh98njjtbv wB//dlWZEaoPAaX+buiGADE6KtHzRbWfkJwb2o5P0p/bsChi/gGbiQ0Yp 40SQFsSntoEZAx7NK/TMjo4ajw2a0meUoHtvfLBqMkk36KsgiuNsvTuzO D+IzFKKNZUKG0CIC5i6UVH82KUj855nsPnI3wDr6L6P3ovrSPhjoV8M6v Jx+9yvEIwn96berycx3eE+9U+Tnn6nPeWimQfCbdad16xTe3pasABd9yr g==; X-CSE-ConnectionGUID: qKkvbQgIT22TR9Ncw+vZBw== X-CSE-MsgGUID: irbAAbrXSf+IKm8ACeYD7A== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530740" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530740" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:25 -0700 X-CSE-ConnectionGUID: thO4qA8sQTSU1x9HvU3g5w== X-CSE-MsgGUID: EEaRNQhiQiObT08O+U8EZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650622" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:22 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 02/16] selftests/resctrl: Calculate resctrl FS derived mem bw over sleep(1) only Date: Mon, 10 Jun 2024 18:14:43 +0300 Message-Id: <20240610151457.7305-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable For MBM/MBA tests, measure_vals() calls get_mem_bw_imc() that performs the measurement over a duration of sleep(1) call. The memory bandwidth numbers from IMC are derived over this duration. The resctrl FS derived memory bandwidth, however, is calculated inside measure_vals() and only takes delta between the previous value and the current one which besides the actual test, also samples inter-test noise. Rework the logic in measure_vals() and get_mem_bw_imc() such that the resctrl FS memory bandwidth section covers much shorter duration closely matching that of the IMC perf counters to improve measurement accuracy. For the second read after rewind() to return a fresh value, also newline has to be consumed by the fscanf(). Suggested-by: Reinette Chatre Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v7: - Truly use "bound to", not bounded to. v6: - Adjust closing/rollback of the IMC perf - Move the comment in measure_vals() to function level - Capitalize MBM - binded to -> bound to v5: - Open mem bw file once and use rewind() - Read \n from the mem bw file to allow rewind to return a new value. v4: - Open resctrl mem bw file (twice) beforehand to avoid opening it during the test v3: - Don't drop Return: entry from perf_open_imc_mem_bw() func comment --- tools/testing/selftests/resctrl/resctrl_val.c | 141 +++++++++++------- 1 file changed, 91 insertions(+), 50 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index f55f5989de72..3c7f6793c261 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -306,18 +306,13 @@ static void perf_close_imc_mem_bw(void) } =20 /* - * get_mem_bw_imc: Memory band width as reported by iMC counters - * @cpu_no: CPU number that the benchmark PID is binded to - * @bw_report: Bandwidth report type (reads, writes) - * - * Memory B/W utilized by a process on a socket can be calculated using - * iMC counters. Perf events are used to read these counters. + * perf_open_imc_mem_bw - Open perf fds for IMCs + * @cpu_no: CPU number that the benchmark PID is bound to * * Return: =3D 0 on success. < 0 on failure. */ -static int get_mem_bw_imc(int cpu_no, char *bw_report, float *bw_imc) +static int perf_open_imc_mem_bw(int cpu_no) { - float reads, writes, of_mul_read, of_mul_write; int imc, ret; =20 for (imc =3D 0; imc < imcs; imc++) { @@ -325,8 +320,6 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report, = float *bw_imc) imc_counters_config[imc][WRITE].fd =3D -1; } =20 - /* Start all iMC counters to log values (both read and write) */ - reads =3D 0, writes =3D 0, of_mul_read =3D 1, of_mul_write =3D 1; for (imc =3D 0; imc < imcs; imc++) { ret =3D open_perf_event(imc, cpu_no, READ); if (ret) @@ -334,7 +327,26 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report,= float *bw_imc) ret =3D open_perf_event(imc, cpu_no, WRITE); if (ret) goto close_fds; + } + + return 0; =20 +close_fds: + perf_close_imc_mem_bw(); + return -1; +} + +/* + * do_mem_bw_test - Perform memory bandwidth test + * + * Runs memory bandwidth test over one second period. Also, handles starti= ng + * and stopping of the IMC perf counters around the test. + */ +static void do_imc_mem_bw_test(void) +{ + int imc; + + for (imc =3D 0; imc < imcs; imc++) { membw_ioctl_perf_event_ioc_reset_enable(imc, READ); membw_ioctl_perf_event_ioc_reset_enable(imc, WRITE); } @@ -346,6 +358,24 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report,= float *bw_imc) membw_ioctl_perf_event_ioc_disable(imc, READ); membw_ioctl_perf_event_ioc_disable(imc, WRITE); } +} + +/* + * get_mem_bw_imc - Memory band width as reported by iMC counters + * @bw_report: Bandwidth report type (reads, writes) + * + * Memory B/W utilized by a process on a socket can be calculated using + * iMC counters. Perf events are used to read these counters. + * + * Return: =3D 0 on success. < 0 on failure. + */ +static int get_mem_bw_imc(char *bw_report, float *bw_imc) +{ + float reads, writes, of_mul_read, of_mul_write; + int imc; + + /* Start all iMC counters to log values (both read and write) */ + reads =3D 0, writes =3D 0, of_mul_read =3D 1, of_mul_write =3D 1; =20 /* * Get results which are stored in struct type imc_counter_config @@ -360,13 +390,13 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report= , float *bw_imc) if (read(r->fd, &r->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { ksft_perror("Couldn't get read b/w through iMC"); - goto close_fds; + return -1; } =20 if (read(w->fd, &w->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { ksft_perror("Couldn't get write bw through iMC"); - goto close_fds; + return -1; } =20 __u64 r_time_enabled =3D r->return_value.time_enabled; @@ -386,8 +416,6 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report, = float *bw_imc) writes +=3D w->return_value.value * of_mul_write * SCALE; } =20 - perf_close_imc_mem_bw(); - if (strcmp(bw_report, "reads") =3D=3D 0) { *bw_imc =3D reads; return 0; @@ -400,10 +428,6 @@ static int get_mem_bw_imc(int cpu_no, char *bw_report,= float *bw_imc) =20 *bw_imc =3D reads + writes; return 0; - -close_fds: - perf_close_imc_mem_bw(); - return -1; } =20 void set_mbm_path(const char *ctrlgrp, const char *mongrp, int domain_id) @@ -462,24 +486,23 @@ static void initialize_mem_bw_resctrl(const char *ctr= lgrp, const char *mongrp, * 1. If con_mon grp is given, then read from it * 2. If con_mon grp is not given, then read from root con_mon grp */ -static int get_mem_bw_resctrl(unsigned long *mbm_total) +static FILE *open_mem_bw_resctrl(const char *mbm_bw_file) { FILE *fp; =20 - fp =3D fopen(mbm_total_path, "r"); - if (!fp) { + fp =3D fopen(mbm_bw_file, "r"); + if (!fp) ksft_perror("Failed to open total bw file"); =20 - return -1; - } - if (fscanf(fp, "%lu", mbm_total) <=3D 0) { - ksft_perror("Could not get mbm local bytes"); - fclose(fp); + return fp; +} =20 +static int get_mem_bw_resctrl(FILE *fp, unsigned long *mbm_total) +{ + if (fscanf(fp, "%lu\n", mbm_total) <=3D 0) { + ksft_perror("Could not get MBM local bytes"); return -1; } - fclose(fp); - return 0; } =20 @@ -615,37 +638,56 @@ static void initialize_llc_occu_resctrl(const char *c= trlgrp, const char *mongrp, set_cmt_path(ctrlgrp, mongrp, domain_id); } =20 +/* + * Measure memory bandwidth from resctrl and from another source which is + * perf imc value or could be something else if perf imc event is not + * available. Compare the two values to validate resctrl value. It takes + * 1 sec to measure the data. + */ static int measure_vals(const struct user_params *uparams, - struct resctrl_val_param *param, - unsigned long *bw_resc_start) + struct resctrl_val_param *param) { - unsigned long bw_resc, bw_resc_end; + unsigned long bw_resc, bw_resc_start, bw_resc_end; + FILE *mem_bw_fp; float bw_imc; int ret; =20 - /* - * Measure memory bandwidth from resctrl and from - * another source which is perf imc value or could - * be something else if perf imc event is not available. - * Compare the two values to validate resctrl value. - * It takes 1sec to measure the data. - */ - ret =3D get_mem_bw_imc(uparams->cpu, param->bw_report, &bw_imc); + mem_bw_fp =3D open_mem_bw_resctrl(mbm_total_path); + if (!mem_bw_fp) + return -1; + + ret =3D perf_open_imc_mem_bw(uparams->cpu); if (ret < 0) - return ret; + goto close_fp; =20 - ret =3D get_mem_bw_resctrl(&bw_resc_end); + ret =3D get_mem_bw_resctrl(mem_bw_fp, &bw_resc_start); if (ret < 0) - return ret; + goto close_imc; =20 - bw_resc =3D (bw_resc_end - *bw_resc_start) / MB; - ret =3D print_results_bw(param->filename, bm_pid, bw_imc, bw_resc); - if (ret) - return ret; + rewind(mem_bw_fp); =20 - *bw_resc_start =3D bw_resc_end; + do_imc_mem_bw_test(); =20 - return 0; + ret =3D get_mem_bw_resctrl(mem_bw_fp, &bw_resc_end); + if (ret < 0) + goto close_imc; + + ret =3D get_mem_bw_imc(param->bw_report, &bw_imc); + if (ret < 0) + goto close_imc; + + perf_close_imc_mem_bw(); + fclose(mem_bw_fp); + + bw_resc =3D (bw_resc_end - bw_resc_start) / MB; + + return print_results_bw(param->filename, bm_pid, bw_imc, bw_resc); + +close_imc: + perf_close_imc_mem_bw(); +close_fp: + fclose(mem_bw_fp); + return ret; } =20 /* @@ -719,7 +761,6 @@ int resctrl_val(const struct resctrl_test *test, struct resctrl_val_param *param) { char *resctrl_val =3D param->resctrl_val; - unsigned long bw_resc_start =3D 0; struct sigaction sigact; int ret =3D 0, pipefd[2]; char pipe_message =3D 0; @@ -861,7 +902,7 @@ int resctrl_val(const struct resctrl_test *test, =20 if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret =3D measure_vals(uparams, param, &bw_resc_start); + ret =3D measure_vals(uparams, param); if (ret) break; } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { --=20 2.39.2 From nobody Sun Feb 8 12:39:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7808C13D63E; Mon, 10 Jun 2024 15:15:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032537; cv=none; b=SJfS8SLL3W+82kUdq1LiLqcj0N/hegywklIU32HV/ONNj7cvW09YfGZiEYEpJFhBkYrfr7E2bItFx+B14jnfjlGY3jib7BYSzWu737r8wYviehqk20nWW/90IVX5Q3ywWex2AId/wc2IRdP0ekEID/Pc+NiSsfqRR+KPEQL5K8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032537; c=relaxed/simple; bh=txOdnyzOZSlUtJWZAp7znb1Tmc2oa6fkNXyfq6rUxzM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=b9nbcWfEHxnICyZyixvWaA/7pJrPUqg2I+DoMYrVPmQKljSyNhgIjDsZ6Skk/OBoKFj6Z+vP0XkVBGKJMZlNiRtkKw0pdZi0IxAujmYxA3z+1JfGCtQCxzO6X4b+mQ0skNXS+bxvkSPDgQJWR1lO1dMGJnEA1SAzru7dJ5xR2pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dfZV4kER; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dfZV4kER" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032535; x=1749568535; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=txOdnyzOZSlUtJWZAp7znb1Tmc2oa6fkNXyfq6rUxzM=; b=dfZV4kERZq2GvxGuCCN81X8hKmXkDJp3AQfXZy4s5VZWS6+234BT3w09 7oBOCjl1ykgq4OD1SyQY1xbp1cViKcUEUwhPwc2EE+FVahw4HIKfNKgj5 kObGrpezo0vuDq4idl+yNgxS0Hi2+Y3PSdsXidZ0upUl+QYHgqXTVS0cJ JWhGYAPvqNJwYxpdigpS2V0uFDE+SRkWx+RvBeApdwHx5VLITmpgRCTwn jHPqPwGfx+wxc0INHauf/9OscgwZ61krDZJfpRpmax5IEIj+eOep+48zP bwdkxudDzqP/8jdbIa4cJwi2LC1cdjBdaASnj78SA5cOdhXU8lhI4P0Rl A==; X-CSE-ConnectionGUID: 4S6hxvVORmC7WRwpkf51bQ== X-CSE-MsgGUID: sivjGbmYTB2vAhNqoiqf8w== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530775" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530775" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:35 -0700 X-CSE-ConnectionGUID: U7+C+GMgQEWFZgghv240MA== X-CSE-MsgGUID: kUSsJ7ggSvylhh3XsxYO3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650649" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:31 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 03/16] selftests/resctrl: Make "bandwidth" consistent in comments & prints Date: Mon, 10 Jun 2024 18:14:44 +0300 Message-Id: <20240610151457.7305-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Resctrl selftests refer to "bandwidth" currently in two other forms in the code ("B/W" and "band width"). Use "bandwidth" consistently everywhere. While at it, fix also one "over flow" -> "overflow" on a line that is touched by the change. Suggested-by: Reinette Chatre Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v3: - New patch --- tools/testing/selftests/resctrl/resctrl_val.c | 14 +++++++------- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 3c7f6793c261..5fad7e757af3 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -361,11 +361,11 @@ static void do_imc_mem_bw_test(void) } =20 /* - * get_mem_bw_imc - Memory band width as reported by iMC counters + * get_mem_bw_imc - Memory bandwidth as reported by iMC counters * @bw_report: Bandwidth report type (reads, writes) * - * Memory B/W utilized by a process on a socket can be calculated using - * iMC counters. Perf events are used to read these counters. + * Memory bandwidth utilized by a process on a socket can be calculated + * using iMC counters. Perf events are used to read these counters. * * Return: =3D 0 on success. < 0 on failure. */ @@ -379,7 +379,7 @@ static int get_mem_bw_imc(char *bw_report, float *bw_im= c) =20 /* * Get results which are stored in struct type imc_counter_config - * Take over flow into consideration before calculating total b/w + * Take overflow into consideration before calculating total bandwidth. */ for (imc =3D 0; imc < imcs; imc++) { struct imc_counter_config *r =3D @@ -389,13 +389,13 @@ static int get_mem_bw_imc(char *bw_report, float *bw_= imc) =20 if (read(r->fd, &r->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { - ksft_perror("Couldn't get read b/w through iMC"); + ksft_perror("Couldn't get read bandwidth through iMC"); return -1; } =20 if (read(w->fd, &w->return_value, sizeof(struct membw_read_format)) =3D=3D -1) { - ksft_perror("Couldn't get write bw through iMC"); + ksft_perror("Couldn't get write bandwidth through iMC"); return -1; } =20 @@ -492,7 +492,7 @@ static FILE *open_mem_bw_resctrl(const char *mbm_bw_fil= e) =20 fp =3D fopen(mbm_bw_file, "r"); if (!fp) - ksft_perror("Failed to open total bw file"); + ksft_perror("Failed to open total memory bandwidth file"); =20 return fp; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 1cade75176eb..9b86f826a40c 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -850,7 +850,7 @@ int validate_bw_report_request(char *bw_report) if (strcmp(bw_report, "total") =3D=3D 0) return 0; =20 - fprintf(stderr, "Requested iMC B/W report type unavailable\n"); + fprintf(stderr, "Requested iMC bandwidth report type unavailable\n"); =20 return -1; } --=20 2.39.2 From nobody Sun Feb 8 12:39:01 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40D3F140E4D; Mon, 10 Jun 2024 15:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032545; cv=none; b=CR2Ugj2y5qRJJ2YrhYtSnjfPQJCL3syklVpTYG2dcyqWvN87zlADD/jRydJbCRtfgcM9oW7SRBTIkySVrZdH0fZ7+uv1TGPo7Hxk0HtRARLCy6f04OLMua5XsZxPagUlSdQEEjoWdh8ylrJc2XvgyjeFi48EQIEuMl2ISXPCNN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032545; c=relaxed/simple; bh=f0+2Hn9SdO3OSRQSm+QVherXzyhhrJ+JeHDaV/jdYXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WucR4NgfFbTd5+ANzjb1mN2T+k4CUOs3jk0bHJ9mDkOsPQFiw2itIT2l9vXPE7/4XE3bxbeWymDXljxXbrwFiXCvqgKQU0wJbVfzUMRoGx+PXY7fLXN5uB7bJfXOPCwY9OJgE/YrFu2/CDxgAcHWY0S/LChTurSXntLUNCnDcBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Agqpb/TX; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Agqpb/TX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032544; x=1749568544; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f0+2Hn9SdO3OSRQSm+QVherXzyhhrJ+JeHDaV/jdYXI=; b=Agqpb/TXAy8sOU/iPbqTYhofWOJ6QLusRbdpPpiBcpYV5w/dHxADIUkl EifjpoCh1GJx8EZieAi/GzQGZLjtFSDV1wRWrzpeEnGJOdCvjKKdlWHPP ubKwf/VkGMQRz8e1KejtiblQmHvfbRq1N20GBkNKWnXYTS9qdgRaZpKMw xgtb/tZuzlnbdH5oCH0a7ffnpsB/Baq8U9T/52oa8hzaFV39BKlzoGq5S SMtavf/4aLm+w05LYJ10F1jKVSxplK2hQuzJEI2+QIncNXpjRfTUcoodM f5tUpJCE6noNgWTCA13gW34i4g4cKuluHIYONO+ZV1RRjOOgreApZkfc3 g==; X-CSE-ConnectionGUID: nIhYp4GaTIuGlPa0DukBnw== X-CSE-MsgGUID: /HNU6eTwRL2qPS2gXhqKFg== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530804" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530804" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:44 -0700 X-CSE-ConnectionGUID: NyU76BH+Tbm9E9FZgNorSQ== X-CSE-MsgGUID: +OYHm8IWRninTprus44W/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650674" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:40 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 04/16] selftests/resctrl: Consolidate get_domain_id() into resctrl_val() Date: Mon, 10 Jun 2024 18:14:45 +0300 Message-Id: <20240610151457.7305-5-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Both initialize_mem_bw_resctrl() and initialize_llc_occu_resctrl() that are called from resctrl_val() need to determine domain ID to construct resctrl fs related paths. Both functions do it by taking CPU ID which neither needs for any other purpose than determining the domain ID. Consolidate determining the domain ID into resctrl_val() and pass the domain ID instead of CPU ID to initialize_mem_bw_resctrl() and initialize_llc_occu_resctrl(). Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/resctrl_val.c | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 5fad7e757af3..cccf6b80f3f3 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -450,19 +450,12 @@ void set_mbm_path(const char *ctrlgrp, const char *mo= ngrp, int domain_id) * initialize_mem_bw_resctrl: Appropriately populate "mbm_total_path" * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) - * @cpu_no: CPU number that the benchmark PID is binded to + * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) */ static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mon= grp, - int cpu_no, char *resctrl_val) + int domain_id, char *resctrl_val) { - int domain_id; - - if (get_domain_id("MB", cpu_no, &domain_id) < 0) { - ksft_print_msg("Could not get domain ID\n"); - return; - } - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) set_mbm_path(ctrlgrp, mongrp, domain_id); =20 @@ -621,19 +614,12 @@ static void set_cmt_path(const char *ctrlgrp, const c= har *mongrp, char sock_num) * initialize_llc_occu_resctrl: Appropriately populate "llc_occup_path" * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) - * @cpu_no: CPU number that the benchmark PID is binded to + * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) * @resctrl_val: Resctrl feature (Eg: cat, cmt.. etc) */ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *m= ongrp, - int cpu_no, char *resctrl_val) + int domain_id, char *resctrl_val) { - int domain_id; - - if (get_domain_id("L3", cpu_no, &domain_id) < 0) { - ksft_print_msg("Could not get domain ID\n"); - return; - } - if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) set_cmt_path(ctrlgrp, mongrp, domain_id); } @@ -765,10 +751,17 @@ int resctrl_val(const struct resctrl_test *test, int ret =3D 0, pipefd[2]; char pipe_message =3D 0; union sigval value; + int domain_id; =20 if (strcmp(param->filename, "") =3D=3D 0) sprintf(param->filename, "stdio"); =20 + ret =3D get_domain_id(test->resource, uparams->cpu, &domain_id); + if (ret < 0) { + ksft_print_msg("Could not get domain ID\n"); + return ret; + } + if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) { ret =3D validate_bw_report_request(param->bw_report); @@ -863,10 +856,10 @@ int resctrl_val(const struct resctrl_test *test, goto out; =20 initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, - uparams->cpu, resctrl_val); + domain_id, resctrl_val); } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp, - uparams->cpu, resctrl_val); + domain_id, resctrl_val); =20 /* Parent waits for child to be ready. */ close(pipefd[1]); --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D68A81754; Mon, 10 Jun 2024 15:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032561; cv=none; b=u7uHCNYkX1ozX95EUJEZ0tlg0ILn8HUl3cWDGq+nrnV6PVdqSac9gMdWlwV+AXLw1Vp5EiYwpETTsjTcLGKpbvJNzgxJjMfxoXYpSf40V2rRHXHW949MxnQ+YN/GvNjh25EKji3X7BTSSJfcANhQ8T8M+ilP1xXsVtCwIojft00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032561; c=relaxed/simple; bh=J8MXk2+opYTa7xZQ/Gh3p+vp6i8luDzj3u3KMCcjByM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kJQ7em0E9is4PR7upoJWOChgXnEXd/8L4Oy6JO2IZeGz20UVYrjFXAFCil0Za1LSOSVZpRQi/+TEdemDZt7GNS7gw2tLCFaO2YW0zqp0j8zHk8ARvemCnKWGO4MYb0ZJdTd9PnRt+qnojZnUHUfRxPN6NmXnG2izo71FZwdxfhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=M3CxDOK0; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="M3CxDOK0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032560; x=1749568560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J8MXk2+opYTa7xZQ/Gh3p+vp6i8luDzj3u3KMCcjByM=; b=M3CxDOK0ss7EAJuV9BL7cYnYiyZCFixr2FFgepsRQSRtNviP40f0TaCp cc7b/KNlsoCxBA48MMpGXFGtumlB4IYC3wKP4FAPbfTEbKARG44QP+9mT LoJ9h4wVkwmB/Kv4LWSieXQdjLdp9/SsUfJGPqxQJEZZnbaOTk5YoyMJB sVAqWtKWX2mC480jHiosVgDUskbzH8FhZWJbL39itBIOM6mv/WViGWY06 5DPURsgkh5LSPRUiWKtrR+mt2Fg+B05G9uraaNRJ/g/4Q4pn1c7tprJd6 rc9+jObwTINQv8qwx+kTt5Dpz1a4KfZTKmBmariS8ErSpl/aebSeGAzy4 g==; X-CSE-ConnectionGUID: 92IfzP8bSmmx4sUr1neZRw== X-CSE-MsgGUID: ovGRmyjAQj6+n0/lq9si4A== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530836" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530836" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:00 -0700 X-CSE-ConnectionGUID: HoBNmIP0SxijAJWn9TI8rg== X-CSE-MsgGUID: vK+sG1WuQImm4pGnpP4DcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650727" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:49 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 05/16] selftests/resctrl: Use correct type for pids Date: Mon, 10 Jun 2024 18:14:46 +0300 Message-Id: <20240610151457.7305-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable A few functions receive PIDs through int arguments. PIDs variables should be of type pid_t, not int. Convert pid arguments from int to pid_t. Before printing PID, match the type to %d by casting to int which is enough for Linux (standard would allow using a longer integer type but generalizing for that would complicate the code unnecessarily, the selftest code does not need to be portable). Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v5: - Cast to int before printing to match with %d. --- tools/testing/selftests/resctrl/cache.c | 10 +++++----- tools/testing/selftests/resctrl/resctrl.h | 4 ++-- tools/testing/selftests/resctrl/resctrl_val.c | 8 ++++---- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selfte= sts/resctrl/cache.c index 1b339d6bbff1..1ff1104e6575 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -101,12 +101,12 @@ static int get_llc_occu_resctrl(unsigned long *llc_oc= cupancy) * * Return: 0 on success, < 0 on error. */ -static int print_results_cache(const char *filename, int bm_pid, __u64 llc= _value) +static int print_results_cache(const char *filename, pid_t bm_pid, __u64 l= lc_value) { FILE *fp; =20 if (strcmp(filename, "stdio") =3D=3D 0 || strcmp(filename, "stderr") =3D= =3D 0) { - printf("Pid: %d \t LLC_value: %llu\n", bm_pid, llc_value); + printf("Pid: %d \t LLC_value: %llu\n", (int)bm_pid, llc_value); } else { fp =3D fopen(filename, "a"); if (!fp) { @@ -114,7 +114,7 @@ static int print_results_cache(const char *filename, in= t bm_pid, __u64 llc_value =20 return -1; } - fprintf(fp, "Pid: %d \t llc_value: %llu\n", bm_pid, llc_value); + fprintf(fp, "Pid: %d \t llc_value: %llu\n", (int)bm_pid, llc_value); fclose(fp); } =20 @@ -133,7 +133,7 @@ static int print_results_cache(const char *filename, in= t bm_pid, __u64 llc_value * Return: =3D0 on success. <0 on failure. */ int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, - const char *filename, int bm_pid) + const char *filename, pid_t bm_pid) { int ret; =20 @@ -161,7 +161,7 @@ int perf_event_measure(int pe_fd, struct perf_event_rea= d *pe_read, * * Return: =3D0 on success. <0 on failure. */ -int measure_llc_resctrl(const char *filename, int bm_pid) +int measure_llc_resctrl(const char *filename, pid_t bm_pid) { unsigned long llc_occu_resc =3D 0; int ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 00d51fa7531c..e6f221236c79 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -174,8 +174,8 @@ void perf_event_initialize_read_format(struct perf_even= t_read *pe_read); int perf_open(struct perf_event_attr *pea, pid_t pid, int cpu_no); int perf_event_reset_enable(int pe_fd); int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, - const char *filename, int bm_pid); -int measure_llc_resctrl(const char *filename, int bm_pid); + const char *filename, pid_t bm_pid); +int measure_llc_resctrl(const char *filename, pid_t bm_pid); void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span,= bool lines); =20 /* diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index cccf6b80f3f3..5704fa3ba202 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -566,14 +566,14 @@ void signal_handler_unregister(void) * * Return: 0 on success, < 0 on error. */ -static int print_results_bw(char *filename, int bm_pid, float bw_imc, +static int print_results_bw(char *filename, pid_t bm_pid, float bw_imc, unsigned long bw_resc) { unsigned long diff =3D fabs(bw_imc - bw_resc); FILE *fp; =20 if (strcmp(filename, "stdio") =3D=3D 0 || strcmp(filename, "stderr") =3D= =3D 0) { - printf("Pid: %d \t Mem_BW_iMC: %f \t ", bm_pid, bw_imc); + printf("Pid: %d \t Mem_BW_iMC: %f \t ", (int)bm_pid, bw_imc); printf("Mem_BW_resc: %lu \t Difference: %lu\n", bw_resc, diff); } else { fp =3D fopen(filename, "a"); @@ -583,7 +583,7 @@ static int print_results_bw(char *filename, int bm_pid= , float bw_imc, return -1; } if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Differ= ence: %lu\n", - bm_pid, bw_imc, bw_resc, diff) <=3D 0) { + (int)bm_pid, bw_imc, bw_resc, diff) <=3D 0) { ksft_print_msg("Could not log results\n"); fclose(fp); =20 @@ -828,7 +828,7 @@ int resctrl_val(const struct resctrl_test *test, PARENT_EXIT(); } =20 - ksft_print_msg("Benchmark PID: %d\n", bm_pid); + ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid); =20 /* * The cast removes constness but nothing mutates benchmark_cmd within diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 9b86f826a40c..917d677adbba 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -508,7 +508,7 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) =20 return -1; } - if (fprintf(fp, "%d\n", pid) < 0) { + if (fprintf(fp, "%d\n", (int)pid) < 0) { ksft_print_msg("Failed to write pid to tasks file\n"); fclose(fp); =20 --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB1DC140E30; Mon, 10 Jun 2024 15:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032564; cv=none; b=CL0nmYjpmpyqwF6OJlYbJwVyQ/b0Mu/zjrQQoh90tIPIGRD59WfuNlddMy3EptfixEGBvwq4zxMFk0APAdHAiAJWmPoe/bbDHLohLeTXqvlukgUbB4/hKONfeUS9FVos5sy60hcok8UiyBNQLlDFjQm6fbNenedzxryE2IBjKLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032564; c=relaxed/simple; bh=cfxO8qFC0DNK4cOE0EMUug/EGzpL5kwVpjyX2BnUbGM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=qc2D4hUHoktXFcGEiI3Vy1h5VteQgcpV4pUEehs0+EghvSAq5uFM5YJYDG7GWsKjsdHyYqIBfIsqfHQSvrCk5NNnazqCe7JI8EF5Bg56Tu2kJvNemFCmWbFifcZGEOwPyIDk2q5J54DB2wXFuaqex7abPFlN6eTpmhFlvA4uV6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=U6H85iAC; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="U6H85iAC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032563; x=1749568563; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cfxO8qFC0DNK4cOE0EMUug/EGzpL5kwVpjyX2BnUbGM=; b=U6H85iACDNr6gHTswGcE4Inz1DgeolEqMSMQln6f0sFbZvK3ZpwR/5K0 miOzVZxTH2NIc0Zkvq0bqqKBRM8d0kIsPiagmKhueIgCjJP1e87XFuvMV 22VbNOR0V2d01aiNdfoYpt0DOE53Za8CQPnuC+bn+Q7EwrPYRJZ5L89do NN4R10ZttT90wSJe8huXht7lySdchgav79Rk8sMh1L1jKuw+xYRs3GoLY OJDp4fRT2eyBoz0goWAwENC57zk0b0FmsGFzNoi6wVtQj7VCTNLiCcjjP VN00VOh2NGAMrc1Imqe6x5qvifAJSk/DmM5UUGDKwVxILfZXa2Hg6uNIp w==; X-CSE-ConnectionGUID: joQB8FEIRnW1SFvaWuhung== X-CSE-MsgGUID: BLeb8gXRSFO3/cYrztrXtQ== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530851" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530851" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:02 -0700 X-CSE-ConnectionGUID: SFXXgnS9SNy9ku9UUbEDeg== X-CSE-MsgGUID: adaT/t0dQq+Ycb0yfPWtCA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650748" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:15:58 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 06/16] selftests/resctrl: Cleanup bm_pid and ppid usage & limit scope Date: Mon, 10 Jun 2024 18:14:47 +0300 Message-Id: <20240610151457.7305-7-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 'bm_pid' and 'ppid' are global variables. As they are used by different processes and in signal handler, they cannot be entirely converted into local variables. The scope of those variables can still be reduced into resctrl_val.c only. As PARENT_EXIT() macro is using 'ppid', make it a function in resctrl_val.c and pass ppid to it as an argument because it is easier to understand than using the global variable directly. Pass 'bm_pid' into measure_vals() instead of relying on the global variable which helps to make the call signatures of measure_vals() and measure_llc_resctrl() more similar to each other. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/resctrl.h | 9 -------- tools/testing/selftests/resctrl/resctrl_val.c | 23 ++++++++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index e6f221236c79..e4b6dc672ecc 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -43,13 +43,6 @@ =20 #define DEFAULT_SPAN (250 * MB) =20 -#define PARENT_EXIT() \ - do { \ - kill(ppid, SIGKILL); \ - umount_resctrlfs(); \ - exit(EXIT_FAILURE); \ - } while (0) - /* * user_params: User supplied parameters * @cpu: CPU number to which the benchmark will be bound to @@ -127,8 +120,6 @@ struct perf_event_read { */ extern volatile int *value_sink; =20 -extern pid_t bm_pid, ppid; - extern char llc_occup_path[1024]; =20 int get_vendor(void); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 5704fa3ba202..3cf671cbb7a2 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -499,7 +499,7 @@ static int get_mem_bw_resctrl(FILE *fp, unsigned long *= mbm_total) return 0; } =20 -pid_t bm_pid, ppid; +static pid_t bm_pid, ppid; =20 void ctrlc_handler(int signum, siginfo_t *info, void *ptr) { @@ -557,6 +557,13 @@ void signal_handler_unregister(void) } } =20 +static void parent_exit(pid_t ppid) +{ + kill(ppid, SIGKILL); + umount_resctrlfs(); + exit(EXIT_FAILURE); +} + /* * print_results_bw: the memory bandwidth results are stored in a file * @filename: file that stores the results @@ -631,7 +638,7 @@ static void initialize_llc_occu_resctrl(const char *ctr= lgrp, const char *mongrp, * 1 sec to measure the data. */ static int measure_vals(const struct user_params *uparams, - struct resctrl_val_param *param) + struct resctrl_val_param *param, pid_t bm_pid) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; @@ -700,7 +707,7 @@ static void run_benchmark(int signum, siginfo_t *info, = void *ucontext) fp =3D freopen("/dev/null", "w", stdout); if (!fp) { ksft_perror("Unable to direct benchmark status to /dev/null"); - PARENT_EXIT(); + parent_exit(ppid); } =20 if (strcmp(benchmark_cmd[0], "fill_buf") =3D=3D 0) { @@ -714,7 +721,7 @@ static void run_benchmark(int signum, siginfo_t *info, = void *ucontext) once =3D false; } else { ksft_print_msg("Invalid once parameter\n"); - PARENT_EXIT(); + parent_exit(ppid); } =20 if (run_fill_buf(span, memflush, operation, once)) @@ -728,7 +735,7 @@ static void run_benchmark(int signum, siginfo_t *info, = void *ucontext) =20 fclose(stdout); ksft_print_msg("Unable to run specified benchmark\n"); - PARENT_EXIT(); + parent_exit(ppid); } =20 /* @@ -807,7 +814,7 @@ int resctrl_val(const struct resctrl_test *test, /* Register for "SIGUSR1" signal from parent */ if (sigaction(SIGUSR1, &sigact, NULL)) { ksft_perror("Can't register child for signal"); - PARENT_EXIT(); + parent_exit(ppid); } =20 /* Tell parent that child is ready */ @@ -825,7 +832,7 @@ int resctrl_val(const struct resctrl_test *test, sigsuspend(&sigact.sa_mask); =20 ksft_perror("Child is done"); - PARENT_EXIT(); + parent_exit(ppid); } =20 ksft_print_msg("Benchmark PID: %d\n", (int)bm_pid); @@ -895,7 +902,7 @@ int resctrl_val(const struct resctrl_test *test, =20 if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret =3D measure_vals(uparams, param); + ret =3D measure_vals(uparams, param, bm_pid); if (ret) break; } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2BF314263A; Mon, 10 Jun 2024 15:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032573; cv=none; b=IjUmKF/V8J1fVZQY75ga1dtC1hTsUaEuVQKmtaFW2hGNO0/zCdKBidVfPbXqivX3NJS2Tr+9xV1f6A0NuB8BPAGCeqCQ/bmmqLTjiizMBO6nVaUmzLgBe5CeOEYyeOqnRzQmveXY92NpZzt0cHC/9fIxKrY1qdQM5K1FwgH+Kn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032573; c=relaxed/simple; bh=ne38TgfsZETZEK25bTRdYyyCzBbg2e7X9ZaATjQ+joA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=f6i4hZIzXfMt5q6ug3Vpf6ErGB8mxE+mjXqFPehyKsHxtC/rpcpNnmYmrEilcKNvtaW7lAWpF4E44CzRqQyZpatvabBvBrmvYPmmdJVM+/SZSpeR1J7W1uaxY58TdeGp2O+SaTm6cLpOQ7PviYCMiB8K90+02yok+FiZpWSt5c8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=l46s1ewX; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l46s1ewX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032572; x=1749568572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ne38TgfsZETZEK25bTRdYyyCzBbg2e7X9ZaATjQ+joA=; b=l46s1ewXGYKTNyhytkKEJGSHQp0uTphkwZAlSPW9ZDjx6Qt2BL4cnmOm uGVkrihhiRcZbgecTxASpI+sWRo7j2hi08B3L5v8xuS9BBO+lefyCIu3/ T0+Nvv/CkdUoxaUbKc2N5mpiENBHAvc8++kcPTfKrdsJKsTHyCn5uvI3t +jVsw213MjCEl73d+moGlv+A3p3uTCOfsbWmXC7q+Mtj/9h6thdgzwR/o sgt2Z3FV/xC0zDyELLAKywfVvluDDTnr3lNSmNqCOeVyyc57zccpv4qKW hg8M8zPCeja35EFHNYIPQevvjQcRw8QE5mvJ4efAe0bCUFwKEyZReNgih Q==; X-CSE-ConnectionGUID: lbxCjn0eRUSUufKy66uF6w== X-CSE-MsgGUID: ZLxVUp9ETMyU4g0xaUpgAQ== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18530898" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18530898" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:11 -0700 X-CSE-ConnectionGUID: VGudugj8SzKT6Ha7CDZO0w== X-CSE-MsgGUID: L640lQSqRNiEbPgPMJmXvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650767" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:07 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 07/16] selftests/resctrl: Rename measure_vals() to measure_mem_bw_vals() & document Date: Mon, 10 Jun 2024 18:14:48 +0300 Message-Id: <20240610151457.7305-8-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable measure_vals() is awfully generic name so rename it to measure_mem_bw() to describe better what it does and document the function parameters. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v5: - Typo fix to commit message - Consistent caps in kerneldoc --- tools/testing/selftests/resctrl/resctrl_val.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 3cf671cbb7a2..b33cb1de295b 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -632,13 +632,18 @@ static void initialize_llc_occu_resctrl(const char *c= trlgrp, const char *mongrp, } =20 /* + * measure_mem_bw - Measures memory bandwidth numbers while benchmark runs + * @uparams: User supplied parameters + * @param: Parameters passed to resctrl_val() + * @bm_pid: PID that runs the benchmark + * * Measure memory bandwidth from resctrl and from another source which is * perf imc value or could be something else if perf imc event is not * available. Compare the two values to validate resctrl value. It takes * 1 sec to measure the data. */ -static int measure_vals(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid) +static int measure_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; @@ -902,7 +907,7 @@ int resctrl_val(const struct resctrl_test *test, =20 if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret =3D measure_vals(uparams, param, bm_pid); + ret =3D measure_mem_bw(uparams, param, bm_pid); if (ret) break; } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0A1B14A615; Mon, 10 Jun 2024 15:16:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032583; cv=none; b=TSBBB5DkHaYskmRHL2G5dtW/61ha2fzQdt+dZe5Hd765VM3gZ26Cm51eRIeie7OCmtw6m+xc+/WwMtCxUaVu8iUDX4Ybv7F08AWUTzmq0UhXNkj/eC0DMjdzfg5G+BYhp3fFU1/XV5WSOfD4H+nLw40WoBkffCZoNxoI05JGqUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032583; c=relaxed/simple; bh=LzZJorUKMfWLu+LV9cKuET0V/HPXuBpNfC2gyr750Mg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=XvycRZTUUPEFMrIAUSK69LTiT8RMhSXiX6mbFM9W++PiPLTXoI4+DP2/ZahM7Sp7lq5jK/EmnaJyAAM+5ar7dzfRdf3UPEuebrW6kpc1IjonwGd9J73rdxStc/l30o92bZTDARYbLiRjJVlPIDpUIejuYSJ3YLLhl5IvsiD8puE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AOrLsRez; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AOrLsRez" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032582; x=1749568582; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LzZJorUKMfWLu+LV9cKuET0V/HPXuBpNfC2gyr750Mg=; b=AOrLsRez9JsEsIwrpbpmZNz4taHzTyNa+/llGXqS+Q+cg2M42Y1qM0fU WJyNBtqqn96V1KagB5wAPPATGWoNNqXG2zln7ySZQ/PVkfsFEOye9Bgn6 V9q8peyfNOxc80G9wglHScqPjnur62STGs3llj9zfTeyESVl8z+EUIYPD mbeHjro7pLgkrfjzRkRjtPyWW1UorFNJwia6humtORLYDjFJ+gSuioS6L AkYXRIY9ndewC0+u973q9n2B2CaJXll+UJ0JQ1OGJPhGxFhqC2tQkukJr bnHVd0K3ybtxqDlQaE6xS6Uj3NWQ8lWjsz/HJDFmivFKylNLgNCkYd82h w==; X-CSE-ConnectionGUID: LhaHpRT4RGGBiuBMHOgHSQ== X-CSE-MsgGUID: puP2XK3QRjCmZMmRT7LOiQ== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="25807773" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="25807773" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:21 -0700 X-CSE-ConnectionGUID: TX9kdILSTzG1+rOSoYH1TA== X-CSE-MsgGUID: Exhibf6RR9OAzL0xRLmiIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39016945" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:17 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 08/16] selftests/resctrl: Simplify mem bandwidth file code for MBA & MBM tests Date: Mon, 10 Jun 2024 18:14:49 +0300 Message-Id: <20240610151457.7305-9-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable initialize_mem_bw_resctrl() and set_mbm_path() contain complicated set of conditions, each yielding different file to be opened to measure memory bandwidth through resctrl FS. In practice, only two of them are used. For MBA test, ctrlgrp is always provided, and for MBM test both ctrlgrp and mongrp are set. The file used differ between MBA/MBM test, however, MBM test unnecessarily create monitor group because resctrl FS already provides monitoring interface underneath any ctrlgrp too, which is what the MBA selftest uses. Consolidate memory bandwidth file used to the one used by the MBA selftest. Remove all unused branches opening other files to simplify the code. Suggested-by: Reinette Chatre Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v4: - Remove also MBM .mongrp setup v3: - New patch --- tools/testing/selftests/resctrl/mbm_test.c | 1 - tools/testing/selftests/resctrl/resctrl_val.c | 45 ++----------------- 2 files changed, 4 insertions(+), 42 deletions(-) diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 3059ccc51a5a..96d279b06377 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -115,7 +115,6 @@ static int mbm_run_test(const struct resctrl_test *test= , const struct user_param struct resctrl_val_param param =3D { .resctrl_val =3D MBM_STR, .ctrlgrp =3D "c1", - .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, .bw_report =3D "reads", .setup =3D mbm_setup diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index b33cb1de295b..277c13b7a4c5 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -19,18 +19,10 @@ #define MAX_TOKENS 5 #define READ 0 #define WRITE 1 -#define CON_MON_MBM_LOCAL_BYTES_PATH \ - "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/mbm_local_bytes" =20 #define CON_MBM_LOCAL_BYTES_PATH \ "%s/%s/mon_data/mon_L3_%02d/mbm_local_bytes" =20 -#define MON_MBM_LOCAL_BYTES_PATH \ - "%s/mon_groups/%s/mon_data/mon_L3_%02d/mbm_local_bytes" - -#define MBM_LOCAL_BYTES_PATH \ - "%s/mon_data/mon_L3_%02d/mbm_local_bytes" - #define CON_MON_LCC_OCCUP_PATH \ "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" =20 @@ -430,43 +422,15 @@ static int get_mem_bw_imc(char *bw_report, float *bw_= imc) return 0; } =20 -void set_mbm_path(const char *ctrlgrp, const char *mongrp, int domain_id) -{ - if (ctrlgrp && mongrp) - sprintf(mbm_total_path, CON_MON_MBM_LOCAL_BYTES_PATH, - RESCTRL_PATH, ctrlgrp, mongrp, domain_id); - else if (!ctrlgrp && mongrp) - sprintf(mbm_total_path, MON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, - mongrp, domain_id); - else if (ctrlgrp && !mongrp) - sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, - ctrlgrp, domain_id); - else if (!ctrlgrp && !mongrp) - sprintf(mbm_total_path, MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, - domain_id); -} - /* * initialize_mem_bw_resctrl: Appropriately populate "mbm_total_path" * @ctrlgrp: Name of the control monitor group (con_mon grp) - * @mongrp: Name of the monitor group (mon grp) * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) - * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) */ -static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mon= grp, - int domain_id, char *resctrl_val) +static void initialize_mem_bw_resctrl(const char *ctrlgrp, int domain_id) { - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) - set_mbm_path(ctrlgrp, mongrp, domain_id); - - if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - if (ctrlgrp) - sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, - RESCTRL_PATH, ctrlgrp, domain_id); - else - sprintf(mbm_total_path, MBM_LOCAL_BYTES_PATH, - RESCTRL_PATH, domain_id); - } + sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, + ctrlgrp, domain_id); } =20 /* @@ -867,8 +831,7 @@ int resctrl_val(const struct resctrl_test *test, if (ret) goto out; =20 - initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, - domain_id, resctrl_val); + initialize_mem_bw_resctrl(param->ctrlgrp, domain_id); } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp, domain_id, resctrl_val); --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06AEE13FD96; Mon, 10 Jun 2024 15:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032591; cv=none; b=N96OgAQrkJdBu7LMaa1pHl70hQkqpfDYS0H//S/FVKuyjVrZj7sXNRk2oDuWyTjRoxA8KKdUSOu8uI480ClCb7KhuIjkRAdaI9RPmoMbzbaKEPh7DxkVqrLs9x5JPSBlWcJbbUFQFb0EHua+N0aP/Gw7Z6V215EGmuk5Ikw6CM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032591; c=relaxed/simple; bh=m5t8MxJ+I7n35w2ToGl4YgrZ29fG4mtxJkBP0WBT/wQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AbPGqVxJKMVwG5AFR+XyQMOqJtM+jurm3ug5yANTlh2UtO3cnh3mSHSjd7wBGoKo5IpW0QLBlvoLI8Y6MCkEN//9GeZImkFxLqPWeoNQMVqiF7OtTD8jvJfItOIxztiRQ1LW7WzNAH6ctrbu/rskc7dtYhnyOE3B5Z6q3iigZNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ucs0IFwO; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ucs0IFwO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032590; x=1749568590; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m5t8MxJ+I7n35w2ToGl4YgrZ29fG4mtxJkBP0WBT/wQ=; b=Ucs0IFwOr2XIbEXywym9NNf32AWxsVA5np+dfxKt+o9gpTkCvNgnXJLa ro4OSxrCpe3lDgviZOJ4+wIy0gop9YF839ejyN80f91knj5eI0icXM/1x BbQWRqxk3VF80nkUxgq8QkrZHRsAzvSaalY8QAXSrtmhUsIf1lnNWkxp+ zC3VTdA+d0FefbOIfxNbuK0X76nXjeUytF8pG0KECXnmeHPJSqQJC6siJ N83/352BeYba/JP9N+Xb7hvkRnhJLKH81mYMSF0+HLD47GmvzKRFlFxLm vcbHRa6hh3A7WdVhO4wsZwnqqqGPggfgugOKPhwNPveg3DBgdZ169PKGd A==; X-CSE-ConnectionGUID: tJQIcZ1ZTzSXj0Acg1VNNg== X-CSE-MsgGUID: t2ByfhZ6Rkyib1ZIQmnyoA== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="25807797" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="25807797" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:30 -0700 X-CSE-ConnectionGUID: sCqeE4L0ScWRx1Layv2qwg== X-CSE-MsgGUID: FbioOfdQTNyTgXty8FV1Nw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39016959" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:26 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 09/16] selftests/resctrl: Add ->measure() callback to resctrl_val_param Date: Mon, 10 Jun 2024 18:14:50 +0300 Message-Id: <20240610151457.7305-10-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The measurement done in resctrl_val() varies depending on test type. The decision for how to measure is decided based on the string compare to test name which is quite inflexible. Add ->measure() callback into the struct resctrl_val_param to allow each test to provide necessary code as a function which simplifies what resctrl_val() has to do. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v2: - spaces -> tabs --- tools/testing/selftests/resctrl/cmt_test.c | 8 ++++++++ tools/testing/selftests/resctrl/mba_test.c | 9 ++++++++- tools/testing/selftests/resctrl/mbm_test.c | 9 ++++++++- tools/testing/selftests/resctrl/resctrl.h | 6 ++++++ tools/testing/selftests/resctrl/resctrl_val.c | 18 +++++------------- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index a44e6fcd37b7..d8521386cd18 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -29,6 +29,13 @@ static int cmt_setup(const struct resctrl_test *test, return 0; } =20 +static int cmt_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + sleep(1); + return measure_llc_resctrl(param->filename, bm_pid); +} + static int show_results_info(unsigned long sum_llc_val, int no_of_bits, unsigned long cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs, @@ -133,6 +140,7 @@ static int cmt_run_test(const struct resctrl_test *test= , const struct user_param .mask =3D ~(long_mask << n) & long_mask, .num_of_runs =3D 0, .setup =3D cmt_setup, + .measure =3D cmt_measure, }; =20 span =3D cache_portion_size(cache_total_size, param.mask, long_mask); diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 5d6af9e8afed..de6e29faf214 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -51,6 +51,12 @@ static int mba_setup(const struct resctrl_test *test, return 0; } =20 +static int mba_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + return measure_mem_bw(uparams, param, bm_pid); +} + static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) { int allocation, runs; @@ -150,7 +156,8 @@ static int mba_run_test(const struct resctrl_test *test= , const struct user_param .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, .bw_report =3D "reads", - .setup =3D mba_setup + .setup =3D mba_setup, + .measure =3D mba_measure, }; int ret; =20 diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 96d279b06377..59e26adf60bb 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -105,6 +105,12 @@ static int mbm_setup(const struct resctrl_test *test, return ret; } =20 +static int mbm_measure(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) +{ + return measure_mem_bw(uparams, param, bm_pid); +} + static void mbm_test_cleanup(void) { remove(RESULT_FILE_NAME); @@ -117,7 +123,8 @@ static int mbm_run_test(const struct resctrl_test *test= , const struct user_param .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .bw_report =3D "reads", - .setup =3D mbm_setup + .setup =3D mbm_setup, + .measure =3D mbm_measure, }; int ret; =20 diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index e4b6dc672ecc..5dc3def70669 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -87,6 +87,7 @@ struct resctrl_test { * @filename: Name of file to which the o/p should be written * @bw_report: Bandwidth report type (reads vs writes) * @setup: Call back function to setup test environment + * @measure: Callback that performs the measurement (a single test) */ struct resctrl_val_param { char *resctrl_val; @@ -99,6 +100,9 @@ struct resctrl_val_param { int (*setup)(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *param); + int (*measure)(const struct user_params *uparams, + struct resctrl_val_param *param, + pid_t bm_pid); }; =20 struct perf_event_read { @@ -145,6 +149,8 @@ unsigned char *alloc_buffer(size_t buf_size, int memflu= sh); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); int run_fill_buf(size_t buf_size, int memflush, int op, bool once); +int measure_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid); int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 277c13b7a4c5..590fc74cb88f 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -606,8 +606,8 @@ static void initialize_llc_occu_resctrl(const char *ctr= lgrp, const char *mongrp, * available. Compare the two values to validate resctrl value. It takes * 1 sec to measure the data. */ -static int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid) +int measure_mem_bw(const struct user_params *uparams, + struct resctrl_val_param *param, pid_t bm_pid) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; @@ -868,17 +868,9 @@ int resctrl_val(const struct resctrl_test *test, if (ret < 0) break; =20 - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || - !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret =3D measure_mem_bw(uparams, param, bm_pid); - if (ret) - break; - } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { - sleep(1); - ret =3D measure_llc_resctrl(param->filename, bm_pid); - if (ret) - break; - } + ret =3D param->measure(uparams, param, bm_pid); + if (ret) + break; } =20 out: --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9419713DB92; Mon, 10 Jun 2024 15:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032605; cv=none; b=V1cv8MwfZvH8EPaq61kyYCbJbD23xz4EL8bQCGjjKl1V1QLhSi4Dom2UpOWbMlQsBCKCB2I5kR705sf/0C7GEZRLf9G+jzvsUZ3I31eencA3YWWVFqxPOv8bsKJNLAP7d1RVHFyJDKydMMIBmvBUCQBS8mOM8yBy8/CNY88n/KE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032605; c=relaxed/simple; bh=OjDmuLG3NtP4ASimjypgK/BUoKaRzg8rqSESF+7C87g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=SeLXAJ0w0BBC8viAPSC0D1FRpscOC0upSPqwK6+J0+vjQ6huzowdG3mlVp9gwkV2/Jk8W7PXzQSteuZA+Mr+ovHpYX89hlS+sQZItkeQYCcm6xr9S5yFobJ7yY3LzIUy/LlbjWFNUvprXLv3IK9Z+672Cflbow6Rn5CoVgO87Xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bmCFp05C; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bmCFp05C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032604; x=1749568604; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OjDmuLG3NtP4ASimjypgK/BUoKaRzg8rqSESF+7C87g=; b=bmCFp05CqEby40jOiSnPfgW06M6IkGtA6rACtGgWyWSE6nc0sinoiAXW m1einCvVFgRajf+OSxilUOU5AmQNUmuRxpsfkwp8+IcR4RSKz68JBr82Z cLmTXTRFM110wvyZJxY/ZVZqc0UkTIzUCrDE4wvcFw7MMR66XJSK9ZVjW UbMJEHhcpbAy/ynWNL6EJw8XTXVJarQdF425acdX2ms3nxoaqBEnilfVo fiU9VxekTYU2p9vNy7cUb3dFNe8Vm1aTtga56tUGESM+16NE8HKGzE8ZB /oaYKk0wzuw7tktFmw5diPu3BTH/b5CrxWmCVWQOotapXghmnRA/fjN8x w==; X-CSE-ConnectionGUID: de0PzqjRREeUiysWV+9aqA== X-CSE-MsgGUID: me2EUUfVTRWdu8T/EnIb5A== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="25807810" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="25807810" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:38 -0700 X-CSE-ConnectionGUID: QTo49EzBSwuYzowAdbskaw== X-CSE-MsgGUID: EFIbBvVsRdGQ2WEYVR7KAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39016975" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:34 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 10/16] selftests/resctrl: Add ->init() callback into resctrl_val_param Date: Mon, 10 Jun 2024 18:14:51 +0300 Message-Id: <20240610151457.7305-11-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The struct resctrl_val_param is there to customize behavior inside resctrl_val() which is currently not used to full extent and there are number of strcmp()s for test name in resctrl_val done by resctrl_val(). Create ->init() hook into the struct resctrl_val_param to cleanly do per test initialization. Remove also unused branches to setup paths and the related #defines for CMT test. While touching kerneldoc, make the adjacent line consistent with the newly added form (callback vs call back). Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v5: - Use consistent formatting in kerneldoc v3: - Rename init functions to _init() - Removed tabs intermixed with code - Leave now common mbm bw filename setup into resctrl_val.c --- tools/testing/selftests/resctrl/cmt_test.c | 12 +++ tools/testing/selftests/resctrl/mba_test.c | 14 ++++ tools/testing/selftests/resctrl/mbm_test.c | 14 ++++ tools/testing/selftests/resctrl/resctrl.h | 8 +- tools/testing/selftests/resctrl/resctrl_val.c | 75 ++++--------------- 5 files changed, 60 insertions(+), 63 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index d8521386cd18..238f514ba7e6 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -16,6 +16,17 @@ #define MAX_DIFF 2000000 #define MAX_DIFF_PERCENT 15 =20 +#define CON_MON_LCC_OCCUP_PATH \ + "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" + +static int cmt_init(const struct resctrl_val_param *param, int domain_id) +{ + sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH, + param->ctrlgrp, param->mongrp, domain_id); + + return 0; +} + static int cmt_setup(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *p) @@ -139,6 +150,7 @@ static int cmt_run_test(const struct resctrl_test *test= , const struct user_param .filename =3D RESULT_FILE_NAME, .mask =3D ~(long_mask << n) & long_mask, .num_of_runs =3D 0, + .init =3D cmt_init, .setup =3D cmt_setup, .measure =3D cmt_measure, }; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index de6e29faf214..0a95c42f1616 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -17,6 +17,19 @@ #define ALLOCATION_MIN 10 #define ALLOCATION_STEP 10 =20 +static int mba_init(const struct resctrl_val_param *param, int domain_id) +{ + int ret; + + ret =3D initialize_mem_bw_imc(); + if (ret) + return ret; + + initialize_mem_bw_resctrl(param, domain_id); + + return 0; +} + /* * Change schemata percentage from 100 to 10%. Write schemata to specified * con_mon grp, mon_grp in resctrl FS. @@ -156,6 +169,7 @@ static int mba_run_test(const struct resctrl_test *test= , const struct user_param .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, .bw_report =3D "reads", + .init =3D mba_init, .setup =3D mba_setup, .measure =3D mba_measure, }; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 59e26adf60bb..00e60b01188a 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -86,6 +86,19 @@ static int check_results(size_t span) return ret; } =20 +static int mbm_init(const struct resctrl_val_param *param, int domain_id) +{ + int ret; + + ret =3D initialize_mem_bw_imc(); + if (ret) + return ret; + + initialize_mem_bw_resctrl(param, domain_id); + + return 0; +} + static int mbm_setup(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *p) @@ -123,6 +136,7 @@ static int mbm_run_test(const struct resctrl_test *test= , const struct user_param .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .bw_report =3D "reads", + .init =3D mbm_init, .setup =3D mbm_setup, .measure =3D mbm_measure, }; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 5dc3def70669..d3fbb957309d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -86,7 +86,8 @@ struct resctrl_test { * @mongrp: Name of the monitor group (mon grp) * @filename: Name of file to which the o/p should be written * @bw_report: Bandwidth report type (reads vs writes) - * @setup: Call back function to setup test environment + * @init: Callback function to initialize test environment + * @setup: Callback function to setup per test run environment * @measure: Callback that performs the measurement (a single test) */ struct resctrl_val_param { @@ -97,6 +98,8 @@ struct resctrl_val_param { char *bw_report; unsigned long mask; int num_of_runs; + int (*init)(const struct resctrl_val_param *param, + int domain_id); int (*setup)(const struct resctrl_test *test, const struct user_params *uparams, struct resctrl_val_param *param); @@ -149,8 +152,11 @@ unsigned char *alloc_buffer(size_t buf_size, int memfl= ush); void mem_flush(unsigned char *buf, size_t buf_size); void fill_cache_read(unsigned char *buf, size_t buf_size, bool once); int run_fill_buf(size_t buf_size, int memflush, int op, bool once); +int initialize_mem_bw_imc(void); int measure_mem_bw(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid); +void initialize_mem_bw_resctrl(const struct resctrl_val_param *param, + int domain_id); int resctrl_val(const struct resctrl_test *test, const struct user_params *uparams, const char * const *benchmark_cmd, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 590fc74cb88f..ecbf46c4f3ea 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -23,18 +23,6 @@ #define CON_MBM_LOCAL_BYTES_PATH \ "%s/%s/mon_data/mon_L3_%02d/mbm_local_bytes" =20 -#define CON_MON_LCC_OCCUP_PATH \ - "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" - -#define CON_LCC_OCCUP_PATH \ - "%s/%s/mon_data/mon_L3_%02d/llc_occupancy" - -#define MON_LCC_OCCUP_PATH \ - "%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" - -#define LCC_OCCUP_PATH \ - "%s/mon_data/mon_L3_%02d/llc_occupancy" - struct membw_read_format { __u64 value; /* The value of the event */ __u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */ @@ -268,7 +256,7 @@ static int num_of_imcs(void) return count; } =20 -static int initialize_mem_bw_imc(void) +int initialize_mem_bw_imc(void) { int imc, j; =20 @@ -424,24 +412,18 @@ static int get_mem_bw_imc(char *bw_report, float *bw_= imc) =20 /* * initialize_mem_bw_resctrl: Appropriately populate "mbm_total_path" - * @ctrlgrp: Name of the control monitor group (con_mon grp) - * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) + * @param: Parameters passed to resctrl_val() + * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) */ -static void initialize_mem_bw_resctrl(const char *ctrlgrp, int domain_id) +void initialize_mem_bw_resctrl(const struct resctrl_val_param *param, + int domain_id) { sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH, RESCTRL_PATH, - ctrlgrp, domain_id); + param->ctrlgrp, domain_id); } =20 /* - * Get MBM Local bytes as reported by resctrl FS - * For MBM, - * 1. If con_mon grp and mon grp are given, then read from con_mon grp's m= on grp - * 2. If only con_mon grp is given, then read from con_mon grp - * 3. If both are not given, then read from root con_mon grp - * For MBA, - * 1. If con_mon grp is given, then read from it - * 2. If con_mon grp is not given, then read from root con_mon grp + * Open file to read MBM local bytes from resctrl FS */ static FILE *open_mem_bw_resctrl(const char *mbm_bw_file) { @@ -454,6 +436,9 @@ static FILE *open_mem_bw_resctrl(const char *mbm_bw_fil= e) return fp; } =20 +/* + * Get MBM Local bytes as reported by resctrl FS + */ static int get_mem_bw_resctrl(FILE *fp, unsigned long *mbm_total) { if (fscanf(fp, "%lu\n", mbm_total) <=3D 0) { @@ -566,35 +551,6 @@ static int print_results_bw(char *filename, pid_t bm_p= id, float bw_imc, return 0; } =20 -static void set_cmt_path(const char *ctrlgrp, const char *mongrp, char soc= k_num) -{ - if (strlen(ctrlgrp) && strlen(mongrp)) - sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH, - ctrlgrp, mongrp, sock_num); - else if (!strlen(ctrlgrp) && strlen(mongrp)) - sprintf(llc_occup_path, MON_LCC_OCCUP_PATH, RESCTRL_PATH, - mongrp, sock_num); - else if (strlen(ctrlgrp) && !strlen(mongrp)) - sprintf(llc_occup_path, CON_LCC_OCCUP_PATH, RESCTRL_PATH, - ctrlgrp, sock_num); - else if (!strlen(ctrlgrp) && !strlen(mongrp)) - sprintf(llc_occup_path, LCC_OCCUP_PATH, RESCTRL_PATH, sock_num); -} - -/* - * initialize_llc_occu_resctrl: Appropriately populate "llc_occup_path" - * @ctrlgrp: Name of the control monitor group (con_mon grp) - * @mongrp: Name of the monitor group (mon grp) - * @domain_id: Domain ID (cache ID; for MB, L3 cache ID) - * @resctrl_val: Resctrl feature (Eg: cat, cmt.. etc) - */ -static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *m= ongrp, - int domain_id, char *resctrl_val) -{ - if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) - set_cmt_path(ctrlgrp, mongrp, domain_id); -} - /* * measure_mem_bw - Measures memory bandwidth numbers while benchmark runs * @uparams: User supplied parameters @@ -825,16 +781,11 @@ int resctrl_val(const struct resctrl_test *test, if (ret) goto out; =20 - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || - !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { - ret =3D initialize_mem_bw_imc(); + if (param->init) { + ret =3D param->init(param, domain_id); if (ret) goto out; - - initialize_mem_bw_resctrl(param->ctrlgrp, domain_id); - } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) - initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp, - domain_id, resctrl_val); + } =20 /* Parent waits for child to be ready. */ close(pipefd[1]); --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F6E1142E9F; Mon, 10 Jun 2024 15:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032609; cv=none; b=HI/wM/JCKUSDA1k7NM/DQmjyKPN6w1ecgJCIoI3BPxxKFQUDnvkEowFaUA7FJzIInEd1DGbr864b5/eSp1YqL8eXqnllvgPayyOZd+a7H7jmKw2gF4owr1lJM7dZHWpfDG1RIJ+xwi+PcpPD2sTm9HfBRLF8Q6LH1SoGfPlhy98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032609; c=relaxed/simple; bh=8fNKtFL3CtfQLyiz6ot0DC/N2nWcqlKXrNEHHl2jlBU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=CVJYOfzQ5PU/nGI1Mw3j2256PVZ7K12S/Nk/aeSwDLXwuBvkLPNN434TBj+paVrTyyiMl1ClqWgHUP2HcQg2iEYYrMH41yahY/45YkjocvHHPkK8qSUM2nsUioxSamSgLuRiKpzqa9jyif3nC277rvcm4hcoBwNUYxAwtPcJ0z8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Wz8dzEXL; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Wz8dzEXL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032607; x=1749568607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8fNKtFL3CtfQLyiz6ot0DC/N2nWcqlKXrNEHHl2jlBU=; b=Wz8dzEXL3n2nDVNWXEK2xYiZZLHaiM8SkIEAiE9mfTMcv6l8cJno2PuQ Dr0M33Xkvc9XRNItS0jlpTJAYLndRWdOofIwznSxEWtktixedtaXkZOUU omuiKXlyaVb0sSNDXl1Nx03fq6PwLp1Ocqx0lMSrvuehezR4bpoXBfaSc SYItyGj17rDGCv319bKosGbvYZwR2pd4kFh0E5lQfUaQJ0wmPPkTq3lpa IlAKU3977YXqSWDKPIcP+b5rMIwPtWuYCqcGqrboGX7vV/UI6w8wiKn+g O9CO1TrY1kX2mngV87Gvo1aQn0vXjgYWONB1KDAOws/lFU4fJiu51g3fB A==; X-CSE-ConnectionGUID: /ptQtSGFRbiSMnDoGGAOIA== X-CSE-MsgGUID: bqYoy6WOTt6AZi5tfR/plw== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="25807842" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="25807842" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:47 -0700 X-CSE-ConnectionGUID: Grf50bwiRsuzBZLBGwPfNA== X-CSE-MsgGUID: 74FbzUpDS8Wr3yIz9a8RTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39017031" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:43 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 11/16] selftests/resctrl: Simplify bandwidth report type handling Date: Mon, 10 Jun 2024 18:14:52 +0300 Message-Id: <20240610151457.7305-12-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable bw_report is only needed for selecting the correct value from the values IMC measured. It is a member in the resctrl_val_param struct and is always set to "reads". The value is then checked in resctrl_val() using validate_bw_report_request() that besides validating the input, assumes it can mutate the string which is questionable programming practice. Simplify handling bw_report: - Convert validate_bw_report_request() into get_bw_report_type() that inputs and returns const char *. Use NULL to indicate error. - Validate the report types inside measure_mem_bw(), not in resctrl_val(). - Pass bw_report to measure_mem_bw() from ->measure() hook because resctrl_val() no longer needs bw_report for anything. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v5: - Use imperative tone in commit message v2: - Rebased on top of next to resolve conflict in resctrl.h --- tools/testing/selftests/resctrl/mba_test.c | 3 +-- tools/testing/selftests/resctrl/mbm_test.c | 3 +-- tools/testing/selftests/resctrl/resctrl.h | 7 +++---- tools/testing/selftests/resctrl/resctrl_val.c | 19 +++++++++---------- tools/testing/selftests/resctrl/resctrlfs.c | 13 ++++++------- 5 files changed, 20 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 0a95c42f1616..9c9a4f22e529 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -67,7 +67,7 @@ static int mba_setup(const struct resctrl_test *test, static int mba_measure(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid) { - return measure_mem_bw(uparams, param, bm_pid); + return measure_mem_bw(uparams, param, bm_pid, "reads"); } =20 static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc) @@ -168,7 +168,6 @@ static int mba_run_test(const struct resctrl_test *test= , const struct user_param .ctrlgrp =3D "c1", .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, - .bw_report =3D "reads", .init =3D mba_init, .setup =3D mba_setup, .measure =3D mba_measure, diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 00e60b01188a..27b936fe60bc 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -121,7 +121,7 @@ static int mbm_setup(const struct resctrl_test *test, static int mbm_measure(const struct user_params *uparams, struct resctrl_val_param *param, pid_t bm_pid) { - return measure_mem_bw(uparams, param, bm_pid); + return measure_mem_bw(uparams, param, bm_pid, "reads"); } =20 static void mbm_test_cleanup(void) @@ -135,7 +135,6 @@ static int mbm_run_test(const struct resctrl_test *test= , const struct user_param .resctrl_val =3D MBM_STR, .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, - .bw_report =3D "reads", .init =3D mbm_init, .setup =3D mbm_setup, .measure =3D mbm_measure, diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index d3fbb957309d..4446a0e493ef 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -85,7 +85,6 @@ struct resctrl_test { * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) * @filename: Name of file to which the o/p should be written - * @bw_report: Bandwidth report type (reads vs writes) * @init: Callback function to initialize test environment * @setup: Callback function to setup per test run environment * @measure: Callback that performs the measurement (a single test) @@ -95,7 +94,6 @@ struct resctrl_val_param { char ctrlgrp[64]; char mongrp[64]; char filename[64]; - char *bw_report; unsigned long mask; int num_of_runs; int (*init)(const struct resctrl_val_param *param, @@ -135,7 +133,7 @@ int filter_dmesg(void); int get_domain_id(const char *resource, int cpu_no, int *domain_id); int mount_resctrlfs(void); int umount_resctrlfs(void); -int validate_bw_report_request(char *bw_report); +const char *get_bw_report_type(const char *bw_report); bool resctrl_resource_exists(const char *resource); bool resctrl_mon_feature_exists(const char *resource, const char *feature); bool resource_info_file_exists(const char *resource, const char *file); @@ -154,7 +152,8 @@ void fill_cache_read(unsigned char *buf, size_t buf_siz= e, bool once); int run_fill_buf(size_t buf_size, int memflush, int op, bool once); int initialize_mem_bw_imc(void); int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid); + struct resctrl_val_param *param, pid_t bm_pid, + const char *bw_report); void initialize_mem_bw_resctrl(const struct resctrl_val_param *param, int domain_id); int resctrl_val(const struct resctrl_test *test, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index ecbf46c4f3ea..0a0abc860a7f 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -349,7 +349,7 @@ static void do_imc_mem_bw_test(void) * * Return: =3D 0 on success. < 0 on failure. */ -static int get_mem_bw_imc(char *bw_report, float *bw_imc) +static int get_mem_bw_imc(const char *bw_report, float *bw_imc) { float reads, writes, of_mul_read, of_mul_write; int imc; @@ -556,6 +556,7 @@ static int print_results_bw(char *filename, pid_t bm_pi= d, float bw_imc, * @uparams: User supplied parameters * @param: Parameters passed to resctrl_val() * @bm_pid: PID that runs the benchmark + * @bw_report: Bandwidth report type (reads, writes) * * Measure memory bandwidth from resctrl and from another source which is * perf imc value or could be something else if perf imc event is not @@ -563,13 +564,18 @@ static int print_results_bw(char *filename, pid_t bm_= pid, float bw_imc, * 1 sec to measure the data. */ int measure_mem_bw(const struct user_params *uparams, - struct resctrl_val_param *param, pid_t bm_pid) + struct resctrl_val_param *param, pid_t bm_pid, + const char *bw_report) { unsigned long bw_resc, bw_resc_start, bw_resc_end; FILE *mem_bw_fp; float bw_imc; int ret; =20 + bw_report =3D get_bw_report_type(bw_report); + if (!bw_report) + return -1; + mem_bw_fp =3D open_mem_bw_resctrl(mbm_total_path); if (!mem_bw_fp) return -1; @@ -590,7 +596,7 @@ int measure_mem_bw(const struct user_params *uparams, if (ret < 0) goto close_imc; =20 - ret =3D get_mem_bw_imc(param->bw_report, &bw_imc); + ret =3D get_mem_bw_imc(bw_report, &bw_imc); if (ret < 0) goto close_imc; =20 @@ -694,13 +700,6 @@ int resctrl_val(const struct resctrl_test *test, return ret; } =20 - if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || - !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) { - ret =3D validate_bw_report_request(param->bw_report); - if (ret) - return ret; - } - /* * If benchmark wasn't successfully started by child, then child should * kill parent, so save parent's pid diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 917d677adbba..9e4cda154d66 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -837,22 +837,21 @@ int filter_dmesg(void) return 0; } =20 -int validate_bw_report_request(char *bw_report) +const char *get_bw_report_type(const char *bw_report) { if (strcmp(bw_report, "reads") =3D=3D 0) - return 0; + return bw_report; if (strcmp(bw_report, "writes") =3D=3D 0) - return 0; + return bw_report; if (strcmp(bw_report, "nt-writes") =3D=3D 0) { - strcpy(bw_report, "writes"); - return 0; + return "writes"; } if (strcmp(bw_report, "total") =3D=3D 0) - return 0; + return bw_report; =20 fprintf(stderr, "Requested iMC bandwidth report type unavailable\n"); =20 - return -1; + return NULL; } =20 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90EC01514C0; Mon, 10 Jun 2024 15:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032618; cv=none; b=jUZCbuKRhrNxsJ3TG9SFgaZvXIBO1a8any7ekeGPWh39Z6jKjB80+Hq83rb88eHyvhkVh9H0sCbiaYwyL6jVkn8BRQWLikPbG2guUEoEOGqGhOjzBK6a6DJbYdh1Dl7R0o7tHY/iGge6lBaqz3ff1CPaONNG22zTAJC3han+rVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032618; c=relaxed/simple; bh=4SCpVL/IeTKG53E42JHkzC4LYfnBdt41K4fBb9PzOZ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=o1pfSYs/WAnN70g3dkSYyS6rlPql58BF/AD6eS2pVyKlpNDs9RY13otsOWI/iJjtf4+oSz08HUFAbWo80+X2p5nYHokLOKzaL4eYzlJYkKS+tAbiW8Xh4Dl2ZU9nd5kqNmlvyGMo6zOX2KCH4z1EQvHPcF2DI0u16MlqOLPvsBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=avrrSabt; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="avrrSabt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032617; x=1749568617; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4SCpVL/IeTKG53E42JHkzC4LYfnBdt41K4fBb9PzOZ0=; b=avrrSabthdwbxRfk4m45xkTwth9Vodq8NXLT9+16VoWmwn9sclK+vvlU uOyZji9gIqDtkgkaCUwNEWWw7bKiqvFPGxexBEmI4ylFWJrK2sMuUls+n j8OAgG/qJBqOn0zk3vC5lb0SJxpc3SGfkBgLQ0S7JyH+FalcC4QqytfqJ HZeupE+o5Cp+lTgWwZDEEQfTCl2gL/mnJbWmnqm2kfBkmPzz1rlB9ZjI6 3axfu0HpyxASPJVjsUABkJKyOMzLpmbX83rlvzRpVVe3Jl63k1cScoY0x 9tf8dUj0n6k/WsxJ3rL3oaWXSn1NPlKSOts1/yb6ls42i387ufg2IRhlx w==; X-CSE-ConnectionGUID: zjnNCdwwScGnHaLPsslhuA== X-CSE-MsgGUID: WC1H86mPSf+bnkOTSQCi+g== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26115437" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26115437" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:56 -0700 X-CSE-ConnectionGUID: f11sEXnoQY2aZ83LSBa5cQ== X-CSE-MsgGUID: FRdxjlQKTImxo0Li8xet+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="44026524" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:16:53 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 12/16] selftests/resctrl: Make some strings passed to resctrlfs functions const Date: Mon, 10 Jun 2024 18:14:53 +0300 Message-Id: <20240610151457.7305-13-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Control group, monitor group and resctrl_val are not mutated and should not be mutated within resctrlfs.c functions. Mark this by using const char * for the arguments. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/resctrl.h | 7 ++++--- tools/testing/selftests/resctrl/resctrlfs.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 4446a0e493ef..5967389038d4 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -141,9 +141,10 @@ bool test_resource_feature_check(const struct resctrl_= test *test); char *fgrep(FILE *inf, const char *str); int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set_t *old_affinity); int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity); -int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *= resource); -int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, - char *resctrl_val); +int write_schemata(const char *ctrlgrp, char *schemata, int cpu_no, + const char *resource); +int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, + const char *mongrp, const char *resctrl_val); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); unsigned char *alloc_buffer(size_t buf_size, int memflush); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index 9e4cda154d66..f4dc8ef23a8c 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -534,8 +534,8 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) * * Return: 0 on success, < 0 on error. */ -int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, - char *resctrl_val) +int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, + const char *mongrp, const char *resctrl_val) { char controlgroup[128], monitorgroup[512], monitorgroup_p[256]; char tasks[1024]; @@ -593,7 +593,8 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp= , char *mongrp, * * Return: 0 on success, < 0 on error. */ -int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *= resource) +int write_schemata(const char *ctrlgrp, char *schemata, int cpu_no, + const char *resource) { char controlgroup[1024], reason[128], schema[1024] =3D {}; int domain_id, fd, schema_len, ret =3D 0; --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15B32142E91; Mon, 10 Jun 2024 15:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032626; cv=none; b=JRfGAo26okNg1SbPJSjqnoy4xH4Yxfp3XU7xXj8ZBe+OJYxk83WHdybJXTdjOli5QLQP8fkNsiX/D1pWwVvMr7OdOM0F/NGOK+C36NAFsnRiLkDZMYJXiJJsqT8aivZpnmhqDbIrbHoy4zFPCWBicthB/IO3OeC6C10b28tzMus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032626; c=relaxed/simple; bh=rJDe/6uAcHgDPfmW4pV89zhCso/+PEfFAWseY49GJHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=u2lWzVr4PyUBe2YMWFjDZuhSKk7/A9S0d5jJu8rXl3jL31kluZ1o2lkVcO7YK88IUoBNOhSYB2H/usZJ1Gp4yJSmKi8AoyTG6/LR5wGPRXtQs37OC423zZg3Ru4ZG6Z/aC0/Pd0ZLYb8msai+W0496o99BnzkjnmjIQ7Q02D7ow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=c+Abl7d0; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="c+Abl7d0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032625; x=1749568625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rJDe/6uAcHgDPfmW4pV89zhCso/+PEfFAWseY49GJHA=; b=c+Abl7d0L/e2G0iUoq/d5FgvIaDOVBpuBWfOnvxmWcO/uPrW2rU8pkaa zexa7omx3MIhF+QvqMH/sAgosgXFg2MLTXuv8Ks/kh9hh7EBJCI3DJt1H 7lA4Kta0+mrYxK2k7+ugNDxEXCfM9Mbk41Zzl1OLpFxxHHInO0uCt76NI tJ4oj8rIsIZ9rLNtQQYqzDHhqTDhHdLAbengKyfSFK5MPE+76emJH9L5E HXBzBy1Q5VGTChvQ+7g4FihsJ4oosSil2048Tla1mEiil7lkzVsLxkFo3 WjnSZ0p9X43eDI/TYufazUcS9w0Kb9fNvk5pw+/GKwf1Pfs4TIEWogYzK w==; X-CSE-ConnectionGUID: zEbc6zlvSKC4ErqgT8jNWw== X-CSE-MsgGUID: xGy0VrOETs6CZBwVfLNpdw== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26115450" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26115450" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:05 -0700 X-CSE-ConnectionGUID: fZuRXcRRRqamKSc+XK3PTA== X-CSE-MsgGUID: g5hFFH9pRI2h3d2YRvVAkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="44026567" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:02 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 13/16] selftests/resctrl: Convert ctrlgrp & mongrp to pointers Date: Mon, 10 Jun 2024 18:14:54 +0300 Message-Id: <20240610151457.7305-14-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The struct resctrl_val_param has control and monitor groups as char arrays but they are not supposed to be mutated within resctrl_val(). Convert the ctrlgrp and mongrp char array within resctrl_val_param to plain const char pointers and adjust the strlen() based checks to check NULL instead. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v6: - Language tweak into kerneldoc - Removed stale paragraph from commit message v5: - Return 0 if grp_name is null (restore earlier behavior) - Move the root group note from comment into kerneldoc v3: - Removed wrong comment - Changed grp_name check to return -1 on fail (internal sanity check) --- tools/testing/selftests/resctrl/resctrl.h | 4 ++-- tools/testing/selftests/resctrl/resctrlfs.c | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index 5967389038d4..a999fbc13fd3 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -91,8 +91,8 @@ struct resctrl_test { */ struct resctrl_val_param { char *resctrl_val; - char ctrlgrp[64]; - char mongrp[64]; + const char *ctrlgrp; + const char *mongrp; char filename[64]; unsigned long mask; int num_of_runs; diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index f4dc8ef23a8c..e2d1ecb55d51 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -456,6 +456,9 @@ int taskset_restore(pid_t bm_pid, cpu_set_t *old_affini= ty) * @grp: Full path and name of the group * @parent_grp: Full path and name of the parent group * + * Creates a group @grp_name if it does not exist yet. If @grp_name is NUL= L, + * it is interpreted as the root group which always results in success. + * * Return: 0 on success, < 0 on error. */ static int create_grp(const char *grp_name, char *grp, const char *parent_= grp) @@ -464,12 +467,7 @@ static int create_grp(const char *grp_name, char *grp,= const char *parent_grp) struct dirent *ep; DIR *dp; =20 - /* - * At this point, we are guaranteed to have resctrl FS mounted and if - * length of grp_name =3D=3D 0, it means, user wants to use root con_mon - * grp, so do nothing - */ - if (strlen(grp_name) =3D=3D 0) + if (!grp_name) return 0; =20 /* Check if requested grp exists or not */ @@ -541,7 +539,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, const char *c= trlgrp, char tasks[1024]; int ret =3D 0; =20 - if (strlen(ctrlgrp)) + if (ctrlgrp) sprintf(controlgroup, "%s/%s", RESCTRL_PATH, ctrlgrp); else sprintf(controlgroup, "%s", RESCTRL_PATH); @@ -558,7 +556,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, const char *c= trlgrp, /* Create mon grp and write pid into it for "mbm" and "cmt" test */ if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)) || !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) { - if (strlen(mongrp)) { + if (mongrp) { sprintf(monitorgroup_p, "%s/mon_groups", controlgroup); sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp); ret =3D create_grp(mongrp, monitorgroup, monitorgroup_p); @@ -612,7 +610,7 @@ int write_schemata(const char *ctrlgrp, char *schemata,= int cpu_no, goto out; } =20 - if (strlen(ctrlgrp) !=3D 0) + if (ctrlgrp) sprintf(controlgroup, "%s/%s/schemata", RESCTRL_PATH, ctrlgrp); else sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73762140E29; Mon, 10 Jun 2024 15:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032635; cv=none; b=kmUYCVWSaV5cMv4MukOqTCT5WFpAPWGyf5MyJ/PW+X2ZnTaBaJiYZ3oSoC8ePordSTX021+R9b0X/9zF3+c9BVCp2T8z/DX2T6VMUv/NvSgpO5COx6qwPAlmW+eO1spRma9psPtTCfBgPnUTeS1umqVnENm8QYwHfX/N8HGZKwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032635; c=relaxed/simple; bh=S9cfMwZg/9eewZmsG7lugvWNIjZBo1dQ6QGf+nuEZ0c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RbBOFEuCRSyFVcsXqawgoODGvxhgTA9fR3l8Gr8hRvHSFi9acl0w9g4AVIDEoK6kq6ZF47nA2Q64b5RampeItS8yCdtAOGjAst9zfo1haydXv6c/XSGYsGWRkHBwGmq6RszIKADcJdEC2x5jsU4Bwv8kl03DjkJ0qqfLbvjFXx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cNwy88Hg; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cNwy88Hg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032635; x=1749568635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S9cfMwZg/9eewZmsG7lugvWNIjZBo1dQ6QGf+nuEZ0c=; b=cNwy88HgaIfZsEjLopvtUtvpZZ6p0qY2I65Kyiau5Vj0mDFoUffXoQkN OmBnoKva5yoN1HDtbMbZKQxm3z6y5NGJ/OyWhM1HfsiTatm1R9WCHTh48 4Csg6CuH9IZBxJvQf8uo6cxVBLrMHkJyTgzjVdYIDU8yad6NoptTJ/Wv8 kqWtdp3snrAp9rMlLILXfi5R5bIQmGmMBWLZ/utv0iOfD7Lyp7pjbXnjN qVFsTE4FrIqfXCgl1SkpRR4VEYZ4vaw6rsdfyeC/nnHpCoROP1vHBx/Li zDBXEVk8WqFBpzql6fn7m3WNIf6XjzEwrq/tFCGr02v7UdWTJKUxaZVMN w==; X-CSE-ConnectionGUID: 2sqUSaFcS0+G+Gg/ATwkJg== X-CSE-MsgGUID: GFVWXdCkQ8OOpRNUaVDeMQ== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26115473" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26115473" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:14 -0700 X-CSE-ConnectionGUID: n8PJYbNhQdarxb979Bkc6g== X-CSE-MsgGUID: Z3Hwag50REOTRmRHMxD0xw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="44026612" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:10 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 14/16] selftests/resctrl: Remove mongrp from MBA test Date: Mon, 10 Jun 2024 18:14:55 +0300 Message-Id: <20240610151457.7305-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Nothing during MBA test uses mongrp even if it has been defined ever since the introduction of the MBA test in the commit 01fee6b4d1f9 ("selftests/resctrl: Add MBA test"). Remove the mongrp from MBA test. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/mba_test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 9c9a4f22e529..5e0b1e794295 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -166,7 +166,6 @@ static int mba_run_test(const struct resctrl_test *test= , const struct user_param struct resctrl_val_param param =3D { .resctrl_val =3D MBA_STR, .ctrlgrp =3D "c1", - .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, .init =3D mba_init, .setup =3D mba_setup, --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E4141420DD; Mon, 10 Jun 2024 15:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032644; cv=none; b=bbfKVOsv9BHPcHk9KKry//t0O86s91mbvLi5DLJbYUbLYo/jjmxjUCKNUPhrEbrEU0n9LnY228ZxmIeGBCex2L0t/3C8dadX1cA0P+WUKqlWc+mtioZCpIlnC48zbicPCKp3c3EL9ou29yRHFnPLtZOQ+L3mO4pDkWfL5WPL4Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032644; c=relaxed/simple; bh=eheohbSQURPQS0WEawrCBZbNeF43tCvxTAbYaEVSAm8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ACpUnbot17G+Zckh8XN4UIcg28Gw5tbDUOL/zg81x0Hf4g2z2MRwBYn1WCgdYAm0V4D0A918AJi3X62xN51J87YRT4T8qL2x4dbCm/uBIdLkxP3NiPghRMTbtOEmNBej/fAmZZ4r/HaHKiWRrF5dPXQRH3APOFDUAGhZHalYS6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=As0sHoW9; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="As0sHoW9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032644; x=1749568644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eheohbSQURPQS0WEawrCBZbNeF43tCvxTAbYaEVSAm8=; b=As0sHoW9+/kWnfPXRSYe74WNXKUmRPRYK4844VVLCrzH2mBp8lNZe6WO MoRYUQIAaSYJa0A5VwU4fXq2maF32kIpEzB93AvCzetiH25S8A/n4evDI QglzULCMUZSpxxAOmgKg5r4cIlUzXxk8dgo5e5n5XCT6Cs5qVawRWOJYr Vi9i3jObPAO6Xd7BOBRIwYaR2i3OFuO765dhjz/eWC7xqpNnD2mUVAdVF iNr9w1EqOoaljhEp5hREx4mn+i9Dlrt3GdXLOWqyhi7dQwllDXrH0rDyV UIIDrQM6azCZekQg/scd5WegUAk2QI3XGXpo8zob10eaerltbeTTvqoRq w==; X-CSE-ConnectionGUID: NLTR8XymQaOWyxse2p8ylg== X-CSE-MsgGUID: dVOu+rf7T0aQoZxsjCpJFg== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="26115496" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="26115496" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:23 -0700 X-CSE-ConnectionGUID: i+JHnuP/Rs+mKs2cFE9fIg== X-CSE-MsgGUID: MGaG4EiZSPW8wAfTGEH0qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="44026637" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:20 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 15/16] selftests/resctrl: Remove mongrp from CMT test Date: Mon, 10 Jun 2024 18:14:56 +0300 Message-Id: <20240610151457.7305-16-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The CMT selftest instantiates a monitor group to read LLC occupancy. Since the test also creates a control group, it is unnecessary to create another one for monitoring because control groups already provide monitoring too. Remove the unnecessary monitor group from the CMT selftest. Suggested-by: Reinette Chatre Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- v7: - Fix separator to use 3 dashes v4: - New patch --- tools/testing/selftests/resctrl/cmt_test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index 238f514ba7e6..b63fa1e93307 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -17,12 +17,12 @@ #define MAX_DIFF_PERCENT 15 =20 #define CON_MON_LCC_OCCUP_PATH \ - "%s/%s/mon_groups/%s/mon_data/mon_L3_%02d/llc_occupancy" + "%s/%s/mon_data/mon_L3_%02d/llc_occupancy" =20 static int cmt_init(const struct resctrl_val_param *param, int domain_id) { sprintf(llc_occup_path, CON_MON_LCC_OCCUP_PATH, RESCTRL_PATH, - param->ctrlgrp, param->mongrp, domain_id); + param->ctrlgrp, domain_id); =20 return 0; } @@ -146,7 +146,6 @@ static int cmt_run_test(const struct resctrl_test *test= , const struct user_param struct resctrl_val_param param =3D { .resctrl_val =3D CMT_STR, .ctrlgrp =3D "c1", - .mongrp =3D "m1", .filename =3D RESULT_FILE_NAME, .mask =3D ~(long_mask << n) & long_mask, .num_of_runs =3D 0, --=20 2.39.2 From nobody Sun Feb 8 12:39:02 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 620E51534E1; Mon, 10 Jun 2024 15:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032654; cv=none; b=C4vQF94nsTFztqkJSNRFBDgbgVlGhCPtKvzye/4sR5QmfpgQ5sFnt1+6kEH7MpFnsFVyh314dEsHMRBcaxaE/1aPHo8jQQEy6UBaLmINaoA2qrlpDPK7UYIwoQMqLC5xGWGarKA4KlGCPNKP65cUpA1IgVgNbWDdvCUrpmrfw4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032654; c=relaxed/simple; bh=tdEJvJpxvwCdxprYWxJiuGsT2mSzbkWvLQMmzdY1JwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=JRWadZNJvvammQcVvS2SnxRdHPWbbkounh021Vik+bYB7lwvm/JSjjir181LdSZ/PXDte1tXZi8hOmhSLfhtLD/y1D19VDu2eeAuwPrNBnrROMKFQfLnO7VNxnvlW2crhV3rGG0LyOv83b5KlDJ2MzfdCrMhfWaR4mPtPOfAnPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WPhPRV1R; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WPhPRV1R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718032652; x=1749568652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tdEJvJpxvwCdxprYWxJiuGsT2mSzbkWvLQMmzdY1JwU=; b=WPhPRV1RrA+3wRgENKa/D3AyU+fH/UlHBFfCjPttVCJUDk1RV9Y5vYmT tsrqrzu1xzu2NFTvTMmriYbK94yvtsHGug/WDC/9cH6PEqwrGPwxetiGk jexT4UrYabvzqP4Ywe3Up7bx/IbrD1MZvRRJwfyR9Af1F7V33lejXf+sW TTLQa9MqWTJsUQ+F8m9usFE0SK2yX4txuyyvjMliDktP/kRa7NlQgnvoW 8eXKm5M7iBUSY+McZ0L0ICJ9qEIKrv9X+W0uIO1lxCMTEHpksU6rsi+KA nqd0B+qExDb05qO9igGsQzrhDStvDXmOeBcBvOtqM5/c7fRs+gzoPXCAA w==; X-CSE-ConnectionGUID: FRULMywrRFW0q/g2i/XueA== X-CSE-MsgGUID: PESf+YeiRAe6v2jWCGdv2A== X-IronPort-AV: E=McAfee;i="6600,9927,11099"; a="18531167" X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="18531167" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:32 -0700 X-CSE-ConnectionGUID: E3owf/gvTlaAZHKP4BiGjg== X-CSE-MsgGUID: dm6NEcT1SoSojWLe8uRStg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,227,1712646000"; d="scan'208";a="39650927" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.245.247.194]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 08:17:28 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Shuah Khan , Reinette Chatre , Babu Moger , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= Cc: Fenghua Yu , linux-kernel@vger.kernel.org, Shuah Khan , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v7 16/16] selftests/resctrl: Remove test name comparing from write_bm_pid_to_resctrl() Date: Mon, 10 Jun 2024 18:14:57 +0300 Message-Id: <20240610151457.7305-17-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> References: <20240610151457.7305-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable write_bm_pid_to_resctrl() uses resctrl_val to check test name which is not a good interface generic resctrl FS functions should provide. Tests define mongrp when needed. Remove the test name check in write_bm_pid_to_resctrl() to only rely on the mongrp parameter being non-NULL. Remove write_bm_pid_to_resctrl() resctrl_val parameter and resctrl_val member from the struct resctrl_val_param that are not used anymore. Similarly, remove the test name constants that are no longer used. Signed-off-by: Ilpo J=C3=A4rvinen Tested-by: Babu Moger Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/cat_test.c | 5 +-- tools/testing/selftests/resctrl/cmt_test.c | 1 - tools/testing/selftests/resctrl/mba_test.c | 1 - tools/testing/selftests/resctrl/mbm_test.c | 1 - tools/testing/selftests/resctrl/resctrl.h | 10 +----- tools/testing/selftests/resctrl/resctrl_val.c | 4 +-- tools/testing/selftests/resctrl/resctrlfs.c | 33 ++++++++----------- 7 files changed, 17 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/sel= ftests/resctrl/cat_test.c index c7686fb6641a..d4dffc934bc3 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -158,7 +158,6 @@ static int cat_test(const struct resctrl_test *test, struct resctrl_val_param *param, size_t span, unsigned long current_mask) { - char *resctrl_val =3D param->resctrl_val; struct perf_event_read pe_read; struct perf_event_attr pea; cpu_set_t old_affinity; @@ -178,8 +177,7 @@ static int cat_test(const struct resctrl_test *test, return ret; =20 /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ - ret =3D write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, - resctrl_val); + ret =3D write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp); if (ret) goto reset_affinity; =20 @@ -272,7 +270,6 @@ static int cat_run_test(const struct resctrl_test *test= , const struct user_param start_mask =3D create_bit_mask(start, n); =20 struct resctrl_val_param param =3D { - .resctrl_val =3D CAT_STR, .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .num_of_runs =3D 0, diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/sel= ftests/resctrl/cmt_test.c index b63fa1e93307..d1c272743eb2 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -144,7 +144,6 @@ static int cmt_run_test(const struct resctrl_test *test= , const struct user_param } =20 struct resctrl_val_param param =3D { - .resctrl_val =3D CMT_STR, .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .mask =3D ~(long_mask << n) & long_mask, diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/sel= ftests/resctrl/mba_test.c index 5e0b1e794295..1f2a7dc73b62 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -164,7 +164,6 @@ static void mba_test_cleanup(void) static int mba_run_test(const struct resctrl_test *test, const struct user= _params *uparams) { struct resctrl_val_param param =3D { - .resctrl_val =3D MBA_STR, .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .init =3D mba_init, diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/sel= ftests/resctrl/mbm_test.c index 27b936fe60bc..39aa70374154 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -132,7 +132,6 @@ static void mbm_test_cleanup(void) static int mbm_run_test(const struct resctrl_test *test, const struct user= _params *uparams) { struct resctrl_val_param param =3D { - .resctrl_val =3D MBM_STR, .ctrlgrp =3D "c1", .filename =3D RESULT_FILE_NAME, .init =3D mbm_init, diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/self= tests/resctrl/resctrl.h index a999fbc13fd3..2dda56084588 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -81,7 +81,6 @@ struct resctrl_test { =20 /* * resctrl_val_param: resctrl test parameters - * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) * @filename: Name of file to which the o/p should be written @@ -90,7 +89,6 @@ struct resctrl_test { * @measure: Callback that performs the measurement (a single test) */ struct resctrl_val_param { - char *resctrl_val; const char *ctrlgrp; const char *mongrp; char filename[64]; @@ -113,11 +111,6 @@ struct perf_event_read { } values[2]; }; =20 -#define MBM_STR "mbm" -#define MBA_STR "mba" -#define CMT_STR "cmt" -#define CAT_STR "cat" - /* * Memory location that consumes values compiler must not optimize away. * Volatile ensures writes to this location cannot be optimized away by @@ -143,8 +136,7 @@ int taskset_benchmark(pid_t bm_pid, int cpu_no, cpu_set= _t *old_affinity); int taskset_restore(pid_t bm_pid, cpu_set_t *old_affinity); int write_schemata(const char *ctrlgrp, char *schemata, int cpu_no, const char *resource); -int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, - const char *mongrp, const char *resctrl_val); +int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, const char = *mongrp); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); unsigned char *alloc_buffer(size_t buf_size, int memflush); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/= selftests/resctrl/resctrl_val.c index 0a0abc860a7f..8c275f6b4dd7 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -684,7 +684,6 @@ int resctrl_val(const struct resctrl_test *test, const char * const *benchmark_cmd, struct resctrl_val_param *param) { - char *resctrl_val =3D param->resctrl_val; struct sigaction sigact; int ret =3D 0, pipefd[2]; char pipe_message =3D 0; @@ -775,8 +774,7 @@ int resctrl_val(const struct resctrl_test *test, goto out; =20 /* Write benchmark to specified control&monitoring grp in resctrl FS */ - ret =3D write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, - resctrl_val); + ret =3D write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp); if (ret) goto out; =20 diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/se= lftests/resctrl/resctrlfs.c index e2d1ecb55d51..250c320349a7 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -522,7 +522,6 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) * @bm_pid: PID that should be written * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) - * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) * * If a con_mon grp is requested, create it and write pid to it, otherwise * write pid to root con_mon grp. @@ -532,8 +531,7 @@ static int write_pid_to_tasks(char *tasks, pid_t pid) * * Return: 0 on success, < 0 on error. */ -int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, - const char *mongrp, const char *resctrl_val) +int write_bm_pid_to_resctrl(pid_t bm_pid, const char *ctrlgrp, const char = *mongrp) { char controlgroup[128], monitorgroup[512], monitorgroup_p[256]; char tasks[1024]; @@ -553,22 +551,19 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, const char = *ctrlgrp, if (ret) goto out; =20 - /* Create mon grp and write pid into it for "mbm" and "cmt" test */ - if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)) || - !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) { - if (mongrp) { - sprintf(monitorgroup_p, "%s/mon_groups", controlgroup); - sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp); - ret =3D create_grp(mongrp, monitorgroup, monitorgroup_p); - if (ret) - goto out; - - sprintf(tasks, "%s/mon_groups/%s/tasks", - controlgroup, mongrp); - ret =3D write_pid_to_tasks(tasks, bm_pid); - if (ret) - goto out; - } + /* Create monitor group and write pid into if it is used */ + if (mongrp) { + sprintf(monitorgroup_p, "%s/mon_groups", controlgroup); + sprintf(monitorgroup, "%s/%s", monitorgroup_p, mongrp); + ret =3D create_grp(mongrp, monitorgroup, monitorgroup_p); + if (ret) + goto out; + + sprintf(tasks, "%s/mon_groups/%s/tasks", + controlgroup, mongrp); + ret =3D write_pid_to_tasks(tasks, bm_pid); + if (ret) + goto out; } =20 out: --=20 2.39.2