Commit 24286736 authored by Fenghua Yu's avatar Fenghua Yu Committed by Shuah Khan
Browse files

selftests/resctrl: Clean up resctrl features check



Checking resctrl features call strcmp() to compare feature strings
(e.g. "mba", "cat" etc). The checkings are error prone and don't have
good coding style. Define the constant strings in macros and call
strncmp() to solve the potential issues.

Suggested-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Tested-by: default avatarBabu Moger <babu.moger@amd.com>
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 896016d2
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
	/*
	 * Measure cache miss from perf.
	 */
	if (!strcmp(param->resctrl_val, "cat")) {
	if (!strncmp(param->resctrl_val, CAT_STR, sizeof(CAT_STR))) {
		ret = get_llc_perf(&llc_perf_miss);
		if (ret < 0)
			return ret;
@@ -192,7 +192,7 @@ int measure_cache_vals(struct resctrl_val_param *param, int bm_pid)
	/*
	 * Measure llc occupancy from resctrl.
	 */
	if (!strcmp(param->resctrl_val, "cqm")) {
	if (!strncmp(param->resctrl_val, CQM_STR, sizeof(CQM_STR))) {
		ret = get_llc_occu_resctrl(&llc_occu_resc);
		if (ret < 0)
			return ret;
@@ -234,7 +234,7 @@ int cat_val(struct resctrl_val_param *param)
	if (ret)
		return ret;

	if ((strcmp(resctrl_val, "cat") == 0)) {
	if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
		ret = initialize_llc_perf();
		if (ret)
			return ret;
@@ -242,7 +242,7 @@ int cat_val(struct resctrl_val_param *param)

	/* Test runs until the callback setup() tells the test to stop. */
	while (1) {
		if (strcmp(resctrl_val, "cat") == 0) {
		if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) {
			ret = param->setup(1, param);
			if (ret) {
				ret = 0;
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
		return -1;

	struct resctrl_val_param param = {
		.resctrl_val	= "cat",
		.resctrl_val	= CAT_STR,
		.cpu_no		= cpu_no,
		.mum_resctrlfs	= 0,
		.setup		= cat_setup,
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ int cqm_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
	}

	struct resctrl_val_param param = {
		.resctrl_val	= "cqm",
		.resctrl_val	= CQM_STR,
		.ctrlgrp	= "c1",
		.mongrp		= "m1",
		.cpu_no		= cpu_no,
+2 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr,

	while (1) {
		ret = fill_one_span_read(start_ptr, end_ptr);
		if (!strcmp(resctrl_val, "cat"))
		if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)))
			break;
	}

@@ -134,7 +134,7 @@ static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_ptr,
{
	while (1) {
		fill_one_span_write(start_ptr, end_ptr);
		if (!strcmp(resctrl_val, "cat"))
		if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)))
			break;
	}

+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ void mba_test_cleanup(void)
int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd)
{
	struct resctrl_val_param param = {
		.resctrl_val	= "mba",
		.resctrl_val	= MBA_STR,
		.ctrlgrp	= "c1",
		.mongrp		= "m1",
		.cpu_no		= cpu_no,
Loading