tools/testing/selftests/resctrl/cmt_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/cmt_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/resctrl/cmt_test.c
Extension
.c
Size
5622 bytes
Lines
219
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

while (token) {
			token_array[fields++] = token;
			token = strtok(NULL, ":\t");
		}

		/* Field 3 is llc occ resc value */
		sum_llc_occu_resc += strtoul(token_array[3], NULL, 0);
		runs++;
	}
	fclose(fp);

	return show_results_info(sum_llc_occu_resc, no_of_bits, span,
				 MAX_DIFF, MAX_DIFF_PERCENT, runs, true);
}

static void cmt_test_cleanup(void)
{
	remove(RESULT_FILE_NAME);
}

static int cmt_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
	struct fill_buf_param fill_buf = {};
	unsigned long cache_total_size = 0;
	int n = uparams->bits ? : 5;
	unsigned long long_mask;
	int count_of_bits;
	size_t span;
	int ret;

	ret = get_full_cbm("L3", &long_mask);
	if (ret)
		return ret;

	ret = get_cache_size(uparams->cpu, "L3", &cache_total_size);
	if (ret)
		return ret;
	ksft_print_msg("Cache size :%lu\n", cache_total_size);

	count_of_bits = count_bits(long_mask);

	if (n < 1 || 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;
	}

	struct resctrl_val_param param = {
		.ctrlgrp	= "c1",
		.filename	= RESULT_FILE_NAME,
		.mask		= ~(long_mask << n) & long_mask,
		.num_of_runs	= 0,
		.init		= cmt_init,
		.setup		= cmt_setup,
		.measure	= cmt_measure,
	};

	span = cache_portion_size(cache_total_size, param.mask, long_mask);

	if (uparams->fill_buf) {
		fill_buf.buf_size = span * 2;
		fill_buf.memflush = uparams->fill_buf->memflush;
		param.fill_buf = &fill_buf;
	} else if (!uparams->benchmark_cmd[0]) {
		fill_buf.buf_size = span * 2;
		fill_buf.memflush = true;
		param.fill_buf = &fill_buf;
	}

	remove(RESULT_FILE_NAME);

	ret = resctrl_val(test, uparams, &param);
	if (ret)
		return ret;

	ret = check_results(&param, span, n);
	if (ret && (get_vendor() == ARCH_INTEL) && !snc_kernel_support())
		ksft_print_msg("Kernel doesn't support Sub-NUMA Clustering but it is enabled on the system.\n");

	return ret;
}

static bool cmt_feature_check(const struct resctrl_test *test)
{
	return test_resource_feature_check(test) &&
	       resctrl_mon_feature_exists("L3_MON", "llc_occupancy");
}

struct resctrl_test cmt_test = {
	.name = "CMT",

Annotation

Implementation Notes