tools/testing/selftests/resctrl/cat_test.c

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/resctrl/cat_test.c
Extension
.c
Size
10110 bytes
Lines
384
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");
		}

		sum_llc_perf_miss += strtoull(token_array[3], NULL, 0);
		runs++;

		if (runs < NUM_OF_RUNS)
			continue;

		if (!current_mask) {
			ksft_print_msg("Unexpected empty cache mask\n");
			break;
		}

		alloc_size = cache_portion_size(cache_total_size, current_mask, full_cache_mask);

		bits = count_bits(current_mask);

		ret = show_results_info(sum_llc_perf_miss, bits,
					alloc_size / 64,
					runs, get_vendor() == ARCH_INTEL,
					&prev_avg_llc_val);
		if (ret)
			fail = 1;

		runs = 0;
		sum_llc_perf_miss = 0;
		current_mask = next_mask(current_mask);
	}

	fclose(fp);

	return fail;
}

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

/*
 * cat_test - Execute CAT benchmark and measure cache misses
 * @test:		Test information structure
 * @uparams:		User supplied parameters
 * @param:		Parameters passed to cat_test()
 * @span:		Buffer size for the benchmark
 * @current_mask	Start mask for the first iteration
 *
 * Run CAT selftest by varying the allocated cache portion and comparing the
 * impact on cache misses (the result analysis is done in check_results()
 * and show_results_info(), not in this function).
 *
 * One bit is removed from the CAT allocation bit mask (in current_mask) for
 * each subsequent test which keeps reducing the size of the allocated cache
 * portion. A single test flushes the buffer, reads it to warm up the cache,
 * and reads the buffer again. The cache misses are measured during the last
 * read pass.
 *
 * Return:		0 when the test was run, < 0 on error.
 */
static int cat_test(const struct resctrl_test *test,
		    const struct user_params *uparams,
		    struct resctrl_val_param *param,
		    size_t span, unsigned long current_mask)
{
	struct perf_event_attr pea;
	cpu_set_t old_affinity;
	unsigned char *buf;
	char schemata[64];
	int ret, i, pe_fd;
	pid_t bm_pid;

	if (strcmp(param->filename, "") == 0)
		sprintf(param->filename, "stdio");

	bm_pid = getpid();

	/* Taskset benchmark to specified cpu */
	ret = taskset_benchmark(bm_pid, uparams->cpu, &old_affinity);
	if (ret)
		return ret;

	/* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/
	ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp);
	if (ret)
		goto reset_affinity;

	ret = minimize_l2_occupancy(test, uparams, param);

Annotation

Implementation Notes