selftests/resctrl: Close perf value read fd on errors
[ Upstream commit 51a0c3b7f028169e40db930575dd01fe81c3e765 ]
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: 790bf585b0
("selftests/resctrl: Add Cache Allocation Technology (CAT) selftest")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Shaopeng Tan (Fujitsu) <tan.shaopeng@fujitsu.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
f399938a91
commit
0682fc175c
@@ -89,21 +89,19 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no)
|
|||||||
static int get_llc_perf(unsigned long *llc_perf_miss)
|
static int get_llc_perf(unsigned long *llc_perf_miss)
|
||||||
{
|
{
|
||||||
__u64 total_misses;
|
__u64 total_misses;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Stop counters after one span to get miss rate */
|
/* Stop counters after one span to get miss rate */
|
||||||
|
|
||||||
ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0);
|
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");
|
perror("Could not get llc misses through perf");
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_misses = rf_cqm.values[0].value;
|
total_misses = rf_cqm.values[0].value;
|
||||||
|
|
||||||
close(fd_lm);
|
|
||||||
|
|
||||||
*llc_perf_miss = total_misses;
|
*llc_perf_miss = total_misses;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -256,17 +254,23 @@ int cat_val(struct resctrl_val_param *param)
|
|||||||
memflush, operation, resctrl_val)) {
|
memflush, operation, resctrl_val)) {
|
||||||
fprintf(stderr, "Error-running fill buffer\n");
|
fprintf(stderr, "Error-running fill buffer\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
goto pe_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
ret = measure_cache_vals(param, bm_pid);
|
ret = measure_cache_vals(param, bm_pid);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
goto pe_close;
|
||||||
|
|
||||||
|
close(fd_lm);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
pe_close:
|
||||||
|
close(fd_lm);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user