tools/testing/selftests/resctrl/mba_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/mba_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/resctrl/mba_test.c- Extension
.c- Size
- 5720 bytes
- Lines
- 226
- 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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
resctrl.h
Detected Declarations
function Allocationfunction mba_setupfunction mba_measurefunction show_mba_infofunction check_resultsfunction mba_test_cleanupfunction mba_run_testfunction mba_feature_check
Annotated Snippet
if (avg_bw_imc < THROTTLE_THRESHOLD || avg_bw_resc < THROTTLE_THRESHOLD) {
ksft_print_msg("Bandwidth below threshold (%d MiB). Dropping results from MBA schemata %u.\n",
THROTTLE_THRESHOLD,
ALLOCATION_MIN + ALLOCATION_STEP * allocation);
continue;
}
avg_diff = (float)labs(avg_bw_resc - avg_bw_imc) / avg_bw_imc;
avg_diff_per = (int)(avg_diff * 100);
ksft_print_msg("%s Check MBA diff within %d%% for schemata %u\n",
avg_diff_per > MAX_DIFF_PERCENT ?
"Fail:" : "Pass:",
MAX_DIFF_PERCENT,
ALLOCATION_MIN + ALLOCATION_STEP * allocation);
ksft_print_msg("avg_diff_per: %d%%\n", avg_diff_per);
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_per > MAX_DIFF_PERCENT)
ret = true;
}
ksft_print_msg("%s Check schemata change using MBA\n",
ret ? "Fail:" : "Pass:");
if (ret)
ksft_print_msg("At least one test failed\n");
return ret;
}
static int check_results(void)
{
unsigned long bw_resc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP];
unsigned long bw_imc[NUM_OF_RUNS * ALLOCATION_MAX / ALLOCATION_STEP];
char *token_array[8], output[] = RESULT_FILE_NAME, temp[512];
int runs;
FILE *fp;
fp = fopen(output, "r");
if (!fp) {
ksft_perror(output);
return -1;
}
runs = 0;
while (fgets(temp, sizeof(temp), fp)) {
char *token = strtok(temp, ":\t");
int fields = 0;
while (token) {
token_array[fields++] = token;
token = strtok(NULL, ":\t");
}
/* Field 3 is perf imc value */
bw_imc[runs] = strtoul(token_array[3], NULL, 0);
/* Field 5 is resctrl value */
bw_resc[runs] = strtoul(token_array[5], NULL, 0);
runs++;
}
fclose(fp);
return show_mba_info(bw_imc, bw_resc);
}
static void mba_test_cleanup(void)
{
remove(RESULT_FILE_NAME);
}
static int mba_run_test(const struct resctrl_test *test, const struct user_params *uparams)
{
struct resctrl_val_param param = {
.ctrlgrp = "c1",
.filename = RESULT_FILE_NAME,
.init = mba_init,
.setup = mba_setup,
.measure = mba_measure,
};
struct fill_buf_param fill_buf = {};
int ret;
remove(RESULT_FILE_NAME);
if (uparams->fill_buf) {
fill_buf.buf_size = uparams->fill_buf->buf_size;
fill_buf.memflush = uparams->fill_buf->memflush;
Annotation
- Immediate include surface: `resctrl.h`.
- Detected declarations: `function Allocation`, `function mba_setup`, `function mba_measure`, `function show_mba_info`, `function check_results`, `function mba_test_cleanup`, `function mba_run_test`, `function mba_feature_check`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.