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

selftests/resctrl: Call kselftest APIs to log test results



Call kselftest APIs instead of using printf() to log test results
for cleaner code and better future extension.

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 2f320911
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -52,25 +52,28 @@ static int cat_setup(int num, ...)
	return ret;
}

static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
static int show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
			   unsigned long span)
{
	unsigned long allocated_cache_lines = span / 64;
	unsigned long avg_llc_perf_miss = 0;
	float diff_percent;
	int ret;

	avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1);
	diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) /
				allocated_cache_lines * 100;

	printf("%sok CAT: cache miss rate within %d%%\n",
	       !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT ?
	       "not " : "", MAX_DIFF_PERCENT);
	tests_run++;
	printf("# Percent diff=%d\n", abs((int)diff_percent));
	printf("# Number of bits: %d\n", no_of_bits);
	printf("# Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
	printf("# Allocated cache lines: %lu\n", allocated_cache_lines);
	ret = !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT;
	ksft_print_msg("Cache miss rate %swithin %d%%\n",
		       ret ? "not " : "", MAX_DIFF_PERCENT);

	ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
	ksft_print_msg("Number of bits: %d\n", no_of_bits);
	ksft_print_msg("Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
	ksft_print_msg("Allocated cache lines: %lu\n", allocated_cache_lines);

	return ret;
}

static int check_results(struct resctrl_val_param *param)
@@ -80,7 +83,7 @@ static int check_results(struct resctrl_val_param *param)
	int runs = 0, no_of_bits = 0;
	FILE *fp;

	printf("# Checking for pass/fail\n");
	ksft_print_msg("Checking for pass/fail\n");
	fp = fopen(param->filename, "r");
	if (!fp) {
		perror("# Cannot open file");
@@ -108,9 +111,7 @@ static int check_results(struct resctrl_val_param *param)
	fclose(fp);
	no_of_bits = count_bits(param->mask);

	show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);

	return 0;
	return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);
}

void cat_test_cleanup(void)
@@ -146,14 +147,14 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
	ret = get_cache_size(cpu_no, cache_type, &cache_size);
	if (ret)
		return ret;
	printf("cache size :%lu\n", cache_size);
	ksft_print_msg("Cache size :%lu\n", cache_size);

	/* Get max number of bits from default-cabm mask */
	count_of_bits = count_bits(long_mask);

	if (n < 1 || n > count_of_bits - 1) {
		printf("Invalid input value for no_of_bits n!\n");
		printf("Please Enter value in range 1 to %d\n",
		ksft_print_msg("Invalid input value for no_of_bits n!\n");
		ksft_print_msg("Please enter value in range 1 to %d\n",
			       count_of_bits - 1);
		return -1;
	}
+19 −23
Original line number Diff line number Diff line
@@ -39,36 +39,33 @@ static int cmt_setup(int num, ...)
	return 0;
}

static void show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits,
static int show_cache_info(unsigned long sum_llc_occu_resc, int no_of_bits,
			   unsigned long span)
{
	unsigned long avg_llc_occu_resc = 0;
	float diff_percent;
	long avg_diff = 0;
	bool res;
	int ret;

	avg_llc_occu_resc = sum_llc_occu_resc / (NUM_OF_RUNS - 1);
	avg_diff = (long)abs(span - avg_llc_occu_resc);

	diff_percent = (((float)span - avg_llc_occu_resc) / span) * 100;

	if ((abs((int)diff_percent) <= MAX_DIFF_PERCENT) ||
	    (abs(avg_diff) <= MAX_DIFF))
		res = true;
	else
		res = false;
	ret = (abs((int)diff_percent) > MAX_DIFF_PERCENT) &&
	      (abs(avg_diff) > MAX_DIFF);

	printf("%sok CMT: diff within %d, %d\%%\n", res ? "" : "not",
	       MAX_DIFF, (int)MAX_DIFF_PERCENT);
	ksft_print_msg("%s cache miss diff within %d, %d\%%\n",
		       ret ? "Fail:" : "Pass:", MAX_DIFF, (int)MAX_DIFF_PERCENT);

	printf("# diff: %ld\n", avg_diff);
	printf("# percent diff=%d\n", abs((int)diff_percent));
	printf("# Results are displayed in (Bytes)\n");
	printf("# Number of bits: %d\n", no_of_bits);
	printf("# Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc);
	printf("# llc_occu_exp (span): %lu\n", span);
	ksft_print_msg("Diff: %ld\n", avg_diff);
	ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
	ksft_print_msg("Results are displayed in (Bytes)\n");
	ksft_print_msg("Number of bits: %d\n", no_of_bits);
	ksft_print_msg("Avg_llc_occu_resc: %lu\n", avg_llc_occu_resc);
	ksft_print_msg("llc_occu_exp (span): %lu\n", span);

	tests_run++;
	return ret;
}

static int check_results(struct resctrl_val_param *param, int no_of_bits)
@@ -78,7 +75,7 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits)
	int runs = 0;
	FILE *fp;

	printf("# checking for pass/fail\n");
	ksft_print_msg("Checking for pass/fail\n");
	fp = fopen(param->filename, "r");
	if (!fp) {
		perror("# Error in opening file\n");
@@ -101,9 +98,8 @@ static int check_results(struct resctrl_val_param *param, int no_of_bits)
		runs++;
	}
	fclose(fp);
	show_cache_info(sum_llc_occu_resc, no_of_bits, param->span);

	return 0;
	return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span);
}

void cmt_test_cleanup(void)
@@ -134,13 +130,13 @@ int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd)
	ret = get_cache_size(cpu_no, "L3", &cache_size);
	if (ret)
		return ret;
	printf("cache size :%lu\n", cache_size);
	ksft_print_msg("Cache size :%lu\n", cache_size);

	count_of_bits = count_bits(long_mask);

	if (n < 1 || n > count_of_bits) {
		printf("Invalid input value for numbr_of_bits n!\n");
		printf("Please Enter value in range 1 to %d\n", count_of_bits);
		ksft_print_msg("Invalid input value for numbr_of_bits n!\n");
		ksft_print_msg("Please enter value in range 1 to %d\n", count_of_bits);
		return -1;
	}

+12 −12
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
	int allocation, runs;
	bool failed = false;

	printf("# Results are displayed in (MB)\n");
	ksft_print_msg("Results are displayed in (MB)\n");
	/* Memory bandwidth from 100% down to 10% */
	for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP;
	     allocation++) {
@@ -78,21 +78,21 @@ static void show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
		avg_bw_resc = sum_bw_resc / (NUM_OF_RUNS - 1);
		avg_diff = labs((long)(avg_bw_resc - avg_bw_imc));

		printf("%sok MBA schemata percentage %u smaller than %d %%\n",
		       avg_diff > MAX_DIFF ? "not " : "",
		ksft_print_msg("%s MBA schemata percentage %u smaller than %d %%\n",
			       avg_diff > MAX_DIFF ? "Fail:" : "Pass:",
			       ALLOCATION_MAX - ALLOCATION_STEP * allocation,
			       MAX_DIFF);
		tests_run++;
		printf("# avg_diff: %lu\n", avg_diff);
		printf("# avg_bw_imc: %lu\n", avg_bw_imc);
		printf("# avg_bw_resc: %lu\n", avg_bw_resc);
		ksft_print_msg("avg_diff: %lu\n", avg_diff);
		ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);
		ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc);
		if (avg_diff > MAX_DIFF)
			failed = true;
	}

	printf("%sok schemata change using MBA%s\n", failed ? "not " : "",
	       failed ? " # at least one test failed" : "");
	tests_run++;
	ksft_print_msg("%s schemata change using MBA\n",
		       failed ? "Fail:" : "Pass:");
	if (failed)
		ksft_print_msg("At least one test failed");
}

static int check_results(void)
+15 −13
Original line number Diff line number Diff line
@@ -14,13 +14,13 @@
#define MAX_DIFF		300
#define NUM_OF_RUNS		5

static void
static int
show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
{
	unsigned long avg_bw_imc = 0, avg_bw_resc = 0;
	unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
	long avg_diff = 0;
	int runs;
	int runs, ret;

	/*
	 * Discard the first value which is inaccurate due to monitoring setup
@@ -35,13 +35,15 @@ show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, int span)
	avg_bw_resc = sum_bw_resc / 4;
	avg_diff = avg_bw_resc - avg_bw_imc;

	printf("%sok MBM: diff within %d%%\n",
	       labs(avg_diff) > MAX_DIFF ? "not " : "", MAX_DIFF);
	tests_run++;
	printf("# avg_diff: %lu\n", labs(avg_diff));
	printf("# Span (MB): %d\n", span);
	printf("# avg_bw_imc: %lu\n", avg_bw_imc);
	printf("# avg_bw_resc: %lu\n", avg_bw_resc);
	ret = labs(avg_diff) > MAX_DIFF;
	ksft_print_msg("%s MBM: diff within %d%%\n",
		       ret ? "Fail:" : "Pass:", MAX_DIFF);
	ksft_print_msg("avg_diff: %lu\n", labs(avg_diff));
	ksft_print_msg("Span (MB): %d\n", span);
	ksft_print_msg("avg_bw_imc: %lu\n", avg_bw_imc);
	ksft_print_msg("avg_bw_resc: %lu\n", avg_bw_resc);

	return ret;
}

static int check_results(int span)
@@ -49,10 +51,10 @@ static int check_results(int span)
	unsigned long bw_imc[NUM_OF_RUNS], bw_resc[NUM_OF_RUNS];
	char temp[1024], *token_array[8];
	char output[] = RESULT_FILE_NAME;
	int runs;
	int runs, ret;
	FILE *fp;

	printf("# Checking for pass/fail\n");
	ksft_print_msg("Checking for pass/fail\n");

	fp = fopen(output, "r");
	if (!fp) {
@@ -76,11 +78,11 @@ static int check_results(int span)
		runs++;
	}

	show_bw_info(bw_imc, bw_resc, span);
	ret = show_bw_info(bw_imc, bw_resc, span);

	fclose(fp);

	return 0;
	return ret;
}

static int mbm_setup(int num, ...)
+1 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <sys/eventfd.h>
#include <asm/unistd.h>
#include <linux/perf_event.h>
#include "../kselftest.h"

#define MB			(1024 * 1024)
#define RESCTRL_PATH		"/sys/fs/resctrl"
@@ -68,7 +69,6 @@ struct resctrl_val_param {
#define CAT_STR			"cat"

extern pid_t bm_pid, ppid;
extern int tests_run;

extern char llc_occup_path[1024];
extern bool is_amd;
Loading