diff options
Diffstat (limited to 'tools/testing/selftests/resctrl/resctrl_val.c')
| -rw-r--r-- | tools/testing/selftests/resctrl/resctrl_val.c | 95 | 
1 files changed, 59 insertions, 36 deletions
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 520fea3606d1..95224345c78e 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -221,8 +221,8 @@ static int read_from_imc_dir(char *imc_dir, int count)   */  static int num_of_imcs(void)  { +	char imc_dir[512], *temp;  	unsigned int count = 0; -	char imc_dir[512];  	struct dirent *ep;  	int ret;  	DIR *dp; @@ -230,7 +230,25 @@ static int num_of_imcs(void)  	dp = opendir(DYN_PMU_PATH);  	if (dp) {  		while ((ep = readdir(dp))) { -			if (strstr(ep->d_name, UNCORE_IMC)) { +			temp = strstr(ep->d_name, UNCORE_IMC); +			if (!temp) +				continue; + +			/* +			 * imc counters are named as "uncore_imc_<n>", hence +			 * increment the pointer to point to <n>. Note that +			 * sizeof(UNCORE_IMC) would count for null character as +			 * well and hence the last underscore character in +			 * uncore_imc'_' need not be counted. +			 */ +			temp = temp + sizeof(UNCORE_IMC); + +			/* +			 * Some directories under "DYN_PMU_PATH" could have +			 * names like "uncore_imc_free_running", hence, check if +			 * first character is a numerical digit or not. +			 */ +			if (temp[0] >= '0' && temp[0] <= '9') {  				sprintf(imc_dir, "%s/%s/", DYN_PMU_PATH,  					ep->d_name);  				ret = read_from_imc_dir(imc_dir, count); @@ -282,9 +300,9 @@ static int initialize_mem_bw_imc(void)   * 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: >= 0 on success. < 0 on failure. + * Return: = 0 on success. < 0 on failure.   */ -static float get_mem_bw_imc(int cpu_no, char *bw_report) +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; @@ -355,13 +373,18 @@ static float get_mem_bw_imc(int cpu_no, char *bw_report)  		close(imc_counters_config[imc][WRITE].fd);  	} -	if (strcmp(bw_report, "reads") == 0) -		return reads; +	if (strcmp(bw_report, "reads") == 0) { +		*bw_imc = reads; +		return 0; +	} -	if (strcmp(bw_report, "writes") == 0) -		return writes; +	if (strcmp(bw_report, "writes") == 0) { +		*bw_imc = writes; +		return 0; +	} -	return (reads + writes); +	*bw_imc = reads + writes; +	return 0;  }  void set_mbm_path(const char *ctrlgrp, const char *mongrp, int resource_id) @@ -397,10 +420,10 @@ static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mongrp,  		return;  	} -	if (strcmp(resctrl_val, "mbm") == 0) +	if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)))  		set_mbm_path(ctrlgrp, mongrp, resource_id); -	if ((strcmp(resctrl_val, "mba") == 0)) { +	if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {  		if (ctrlgrp)  			sprintf(mbm_total_path, CON_MBM_LOCAL_BYTES_PATH,  				RESCTRL_PATH, ctrlgrp, resource_id); @@ -420,9 +443,8 @@ static void initialize_mem_bw_resctrl(const char *ctrlgrp, 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 unsigned long get_mem_bw_resctrl(void) +static int get_mem_bw_resctrl(unsigned long *mbm_total)  { -	unsigned long mbm_total = 0;  	FILE *fp;  	fp = fopen(mbm_total_path, "r"); @@ -431,7 +453,7 @@ static unsigned long get_mem_bw_resctrl(void)  		return -1;  	} -	if (fscanf(fp, "%lu", &mbm_total) <= 0) { +	if (fscanf(fp, "%lu", mbm_total) <= 0) {  		perror("Could not get mbm local bytes");  		fclose(fp); @@ -439,7 +461,7 @@ static unsigned long get_mem_bw_resctrl(void)  	}  	fclose(fp); -	return mbm_total; +	return 0;  }  pid_t bm_pid, ppid; @@ -449,7 +471,7 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)  	kill(bm_pid, SIGKILL);  	umount_resctrlfs();  	tests_cleanup(); -	printf("Ending\n\n"); +	ksft_print_msg("Ending\n\n");  	exit(EXIT_SUCCESS);  } @@ -492,7 +514,7 @@ static int print_results_bw(char *filename,  int bm_pid, float bw_imc,  	return 0;  } -static void set_cqm_path(const char *ctrlgrp, const char *mongrp, char sock_num) +static void set_cmt_path(const char *ctrlgrp, const char *mongrp, char sock_num)  {  	if (strlen(ctrlgrp) && strlen(mongrp))  		sprintf(llc_occup_path,	CON_MON_LCC_OCCUP_PATH,	RESCTRL_PATH, @@ -512,7 +534,7 @@ static void set_cqm_path(const char *ctrlgrp, const char *mongrp, char sock_num)   * @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 - * @resctrl_val:		Resctrl feature (Eg: cat, cqm.. etc) + * @resctrl_val:		Resctrl feature (Eg: cat, cmt.. etc)   */  static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,  					int cpu_no, char *resctrl_val) @@ -524,14 +546,15 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp,  		return;  	} -	if (strcmp(resctrl_val, "cqm") == 0) -		set_cqm_path(ctrlgrp, mongrp, resource_id); +	if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) +		set_cmt_path(ctrlgrp, mongrp, resource_id);  }  static int  measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start)  { -	unsigned long bw_imc, bw_resc, bw_resc_end; +	unsigned long bw_resc, bw_resc_end; +	float bw_imc;  	int ret;  	/* @@ -541,13 +564,13 @@ measure_vals(struct resctrl_val_param *param, unsigned long *bw_resc_start)  	 * Compare the two values to validate resctrl value.  	 * It takes 1sec to measure the data.  	 */ -	bw_imc = get_mem_bw_imc(param->cpu_no, param->bw_report); -	if (bw_imc <= 0) -		return bw_imc; +	ret = get_mem_bw_imc(param->cpu_no, param->bw_report, &bw_imc); +	if (ret < 0) +		return ret; -	bw_resc_end = get_mem_bw_resctrl(); -	if (bw_resc_end <= 0) -		return bw_resc_end; +	ret = get_mem_bw_resctrl(&bw_resc_end); +	if (ret < 0) +		return ret;  	bw_resc = (bw_resc_end - *bw_resc_start) / MB;  	ret = print_results_bw(param->filename, bm_pid, bw_imc, bw_resc); @@ -579,8 +602,8 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)  	if (strcmp(param->filename, "") == 0)  		sprintf(param->filename, "stdio"); -	if ((strcmp(resctrl_val, "mba")) == 0 || -	    (strcmp(resctrl_val, "mbm")) == 0) { +	if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || +	    !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) {  		ret = validate_bw_report_request(param->bw_report);  		if (ret)  			return ret; @@ -645,7 +668,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)  		PARENT_EXIT("Child is done");  	} -	printf("# benchmark PID: %d\n", bm_pid); +	ksft_print_msg("Benchmark PID: %d\n", bm_pid);  	/*  	 * Register CTRL-C handler for parent, as it has to kill benchmark @@ -674,15 +697,15 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)  	if (ret)  		goto out; -	if ((strcmp(resctrl_val, "mbm") == 0) || -	    (strcmp(resctrl_val, "mba") == 0)) { +	if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || +	    !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {  		ret = initialize_mem_bw_imc();  		if (ret)  			goto out;  		initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp,  					  param->cpu_no, resctrl_val); -	} else if (strcmp(resctrl_val, "cqm") == 0) +	} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR)))  		initialize_llc_occu_resctrl(param->ctrlgrp, param->mongrp,  					    param->cpu_no, resctrl_val); @@ -710,8 +733,8 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)  	/* Test runs until the callback setup() tells the test to stop. */  	while (1) { -		if ((strcmp(resctrl_val, "mbm") == 0) || -		    (strcmp(resctrl_val, "mba") == 0)) { +		if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || +		    !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) {  			ret = param->setup(1, param);  			if (ret) {  				ret = 0; @@ -721,7 +744,7 @@ int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param)  			ret = measure_vals(param, &bw_resc_start);  			if (ret)  				break; -		} else if (strcmp(resctrl_val, "cqm") == 0) { +		} else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) {  			ret = param->setup(1, param);  			if (ret) {  				ret = 0;  |