tools/testing/selftests/resctrl/cache.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/cache.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/resctrl/cache.c- Extension
.c- Size
- 4761 bytes
- Lines
- 196
- 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
stdint.hresctrl.h
Detected Declarations
function perf_event_attr_initializefunction perf_event_reset_enablefunction perf_openfunction get_llc_occu_resctrlfunction print_results_cachefunction eventsfunction measure_llc_resctrlfunction minimize_l2_occupancyfunction show_cache_info
Annotated Snippet
if (!fp) {
ksft_perror("Cannot open results file");
return -1;
}
fprintf(fp, "Pid: %d \t llc_value: %llu\n", (int)bm_pid, llc_value);
fclose(fp);
}
return 0;
}
/*
* perf_event_measure - Measure perf events
* @filename: Filename for writing the results
* @bm_pid: PID that runs the benchmark
*
* Measures perf events (e.g., cache misses) and writes the results into
* @filename. @bm_pid is written to the results file along with the measured
* value.
*
* Return: =0 on success. <0 on failure.
*/
int perf_event_measure(int pe_fd, const char *filename, pid_t bm_pid)
{
__u64 value;
int ret;
/* Stop counters after one span to get miss rate */
ret = ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);
if (ret < 0)
return ret;
ret = read(pe_fd, &value, sizeof(value));
if (ret == -1) {
ksft_perror("Could not get perf value");
return -1;
}
return print_results_cache(filename, bm_pid, value);
}
/*
* measure_llc_resctrl - Measure resctrl LLC value from resctrl
* @filename: Filename for writing the results
* @bm_pid: PID that runs the benchmark
*
* Measures LLC occupancy from resctrl and writes the results into @filename.
* @bm_pid is written to the results file along with the measured value.
*
* Return: =0 on success. <0 on failure.
*/
int measure_llc_resctrl(const char *filename, pid_t bm_pid)
{
unsigned long llc_occu_resc = 0;
int ret;
ret = get_llc_occu_resctrl(&llc_occu_resc);
if (ret < 0)
return ret;
return print_results_cache(filename, bm_pid, llc_occu_resc);
}
/*
* Reduce L2 allocation to minimum when testing L3 cache allocation.
*/
int minimize_l2_occupancy(const struct resctrl_test *test,
const struct user_params *uparams,
const struct resctrl_val_param *param)
{
if (!strcmp(test->resource, "L3") && resctrl_resource_exists("L2"))
return write_schemata(param->ctrlgrp, "0x1", uparams->cpu, "L2");
return 0;
}
/*
* show_cache_info - Show generic cache test information
* @no_of_bits: Number of bits
* @avg_llc_val: Average of LLC cache result data
* @cache_span: Cache span
* @lines: @cache_span in lines or bytes
*/
void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines)
{
ksft_print_msg("Number of bits: %d\n", no_of_bits);
ksft_print_msg("Average LLC val: %llu\n", avg_llc_val);
ksft_print_msg("Cache span (%s): %zu\n", lines ? "lines" : "bytes",
cache_span);
Annotation
- Immediate include surface: `stdint.h`, `resctrl.h`.
- Detected declarations: `function perf_event_attr_initialize`, `function perf_event_reset_enable`, `function perf_open`, `function get_llc_occu_resctrl`, `function print_results_cache`, `function events`, `function measure_llc_resctrl`, `function minimize_l2_occupancy`, `function show_cache_info`.
- 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.