From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-kselftest@vger.kernel.org,
Reinette Chatre <reinette.chatre@intel.com>,
Shuah Khan <shuah@kernel.org>,
Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Babu Moger <babu.moger@amd.com>,
Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>,
linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH v5 04/19] selftests/resctrl: Close perf value read fd on errors
Date: Mon, 17 Jul 2023 16:14:52 +0300 [thread overview]
Message-ID: <20230717131507.32420-5-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20230717131507.32420-1-ilpo.jarvinen@linux.intel.com>
Perf event fd (fd_lm) is not closed when run_fill_buf() returns error.
Close fd_lm only in cat_val() to make it easier to track it is always
closed.
Fixes: 790bf585b0ee ("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
tools/testing/selftests/resctrl/cache.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c
index 8a4fe8693be6..289b619116fe 100644
--- a/tools/testing/selftests/resctrl/cache.c
+++ b/tools/testing/selftests/resctrl/cache.c
@@ -87,21 +87,19 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no)
static int get_llc_perf(unsigned long *llc_perf_miss)
{
__u64 total_misses;
+ int ret;
/* Stop counters after one span to get miss rate */
ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0);
- if (read(fd_lm, &rf_cqm, sizeof(struct read_format)) == -1) {
+ ret = read(fd_lm, &rf_cqm, sizeof(struct read_format));
+ if (ret == -1) {
perror("Could not get llc misses through perf");
-
return -1;
}
total_misses = rf_cqm.values[0].value;
-
- close(fd_lm);
-
*llc_perf_miss = total_misses;
return 0;
@@ -253,19 +251,25 @@ int cat_val(struct resctrl_val_param *param)
memflush, operation, resctrl_val)) {
fprintf(stderr, "Error-running fill buffer\n");
ret = -1;
- break;
+ goto pe_close;
}
sleep(1);
ret = measure_cache_vals(param, bm_pid);
if (ret)
- break;
+ goto pe_close;
+
+ close(fd_lm);
} else {
break;
}
}
return ret;
+
+pe_close:
+ close(fd_lm);
+ return ret;
}
/*
--
2.30.2
next prev parent reply other threads:[~2023-07-17 13:15 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 13:14 [PATCH v5 00/19] selftests/resctrl: Fixes and cleanups Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 01/19] selftests/resctrl: Add resctrl.h into build deps Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 02/19] selftests/resctrl: Don't leak buffer in fill_cache() Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 03/19] selftests/resctrl: Unmount resctrl FS if child fails to run benchmark Ilpo Järvinen
2023-07-17 13:14 ` Ilpo Järvinen [this message]
2023-07-25 15:26 ` [PATCH v5 04/19] selftests/resctrl: Close perf value read fd on errors Reinette Chatre
2023-07-17 13:14 ` [PATCH v5 05/19] selftests/resctrl: Unmount resctrl FS before starting the first test Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 06/19] selftests/resctrl: Move resctrl FS mount/umount to higher level Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 07/19] selftests/resctrl: Refactor remount_resctrl(bool mum_resctrlfs) to mount_resctrl() Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 08/19] selftests/resctrl: Remove mum_resctrlfs from struct resctrl_val_param Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 09/19] selftests/resctrl: Convert span to size_t Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 10/19] selftests/resctrl: Express span internally in bytes Ilpo Järvinen
2023-07-17 13:14 ` [PATCH v5 11/19] selftests/resctrl: Remove duplicated preparation for span arg Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 12/19] selftests/resctrl: Remove "malloc_and_init_memory" param from run_fill_buf() Ilpo Järvinen
2023-07-25 14:49 ` Shuah Khan
2023-07-25 15:26 ` Reinette Chatre
2023-08-07 10:21 ` Ilpo Järvinen
2023-08-07 18:47 ` Shuah Khan
2023-08-07 19:02 ` Reinette Chatre
2023-07-17 13:15 ` [PATCH v5 13/19] selftests/resctrl: Remove unnecessary startptr global from fill_buf Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 14/19] selftests/resctrl: Improve parameter consistency in fill_buf Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 15/19] selftests/resctrl: Don't pass test name to fill_buf Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 16/19] selftests/resctrl: Don't use variable argument list for ->setup() Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 17/19] selftests/resctrl: Move CAT/CMT test global vars to function they are used in Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 18/19] selftests/resctrl: Pass the real number of tests to show_cache_info() Ilpo Järvinen
2023-07-17 13:15 ` [PATCH v5 19/19] selftests/resctrl: Remove test type checks from cat_val() Ilpo Järvinen
2023-07-17 15:11 ` [PATCH v5 00/19] selftests/resctrl: Fixes and cleanups Babu Moger
2023-07-18 6:47 ` Shaopeng Tan (Fujitsu)
2023-07-25 14:55 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230717131507.32420-5-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=babu.moger@amd.com \
--cc=fenghua.yu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=reinette.chatre@intel.com \
--cc=sai.praneeth.prakhya@intel.com \
--cc=shuah@kernel.org \
--cc=tan.shaopeng@jp.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox