tools/testing/selftests/resctrl/resctrl_val.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/resctrl_val.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/resctrl/resctrl_val.c- Extension
.c- Size
- 17430 bytes
- Lines
- 709
- 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
struct membw_read_formatstruct imc_counter_configfunction read_mem_bw_initialize_perf_event_attrfunction read_mem_bw_ioctl_perf_event_ioc_reset_enablefunction read_mem_bw_ioctl_perf_event_ioc_disablefunction get_read_event_and_umaskfunction open_perf_read_eventfunction parse_imc_read_bw_eventsfunction read_from_imc_dirfunction num_of_imcsfunction initialize_read_mem_bw_imcfunction perf_close_imc_read_mem_bwfunction perf_open_imc_read_mem_bwfunction do_imc_read_mem_bw_testfunction get_read_mem_bw_imcfunction initialize_mem_bw_resctrlfunction get_mem_bw_resctrlfunction ctrlc_handlerfunction signal_handler_registerfunction sigactionfunction signal_handler_unregisterfunction sigactionfunction print_results_bwfunction measure_read_mem_bwfunction resctrl_val
Annotated Snippet
struct membw_read_format {
__u64 value; /* The value of the event */
__u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */
__u64 time_running; /* if PERF_FORMAT_TOTAL_TIME_RUNNING */
__u64 id; /* if PERF_FORMAT_ID */
};
struct imc_counter_config {
__u32 type;
__u64 event;
__u64 umask;
struct perf_event_attr pe;
int fd;
};
static char mbm_total_path[1024];
static int imcs;
static struct imc_counter_config imc_counters_config[MAX_IMCS];
static const struct resctrl_test *current_test;
static void read_mem_bw_initialize_perf_event_attr(int i)
{
memset(&imc_counters_config[i].pe, 0,
sizeof(struct perf_event_attr));
imc_counters_config[i].pe.type = imc_counters_config[i].type;
imc_counters_config[i].pe.size = sizeof(struct perf_event_attr);
imc_counters_config[i].pe.disabled = 1;
imc_counters_config[i].pe.inherit = 1;
imc_counters_config[i].pe.exclude_guest = 0;
imc_counters_config[i].pe.config =
imc_counters_config[i].umask << 8 |
imc_counters_config[i].event;
imc_counters_config[i].pe.sample_type = PERF_SAMPLE_IDENTIFIER;
imc_counters_config[i].pe.read_format =
PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
}
static void read_mem_bw_ioctl_perf_event_ioc_reset_enable(int i)
{
ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_RESET, 0);
ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_ENABLE, 0);
}
static void read_mem_bw_ioctl_perf_event_ioc_disable(int i)
{
ioctl(imc_counters_config[i].fd, PERF_EVENT_IOC_DISABLE, 0);
}
/*
* get_read_event_and_umask: Parse config into event and umask
* @cas_count_cfg: Config
* @count: iMC number
*/
static void get_read_event_and_umask(char *cas_count_cfg, unsigned int count)
{
char *token[MAX_TOKENS];
int i = 0;
token[0] = strtok(cas_count_cfg, "=,");
for (i = 1; i < MAX_TOKENS; i++)
token[i] = strtok(NULL, "=,");
for (i = 0; i < MAX_TOKENS - 1; i++) {
if (!token[i])
break;
if (strcmp(token[i], "event") == 0)
imc_counters_config[count].event = strtol(token[i + 1], NULL, 16);
if (strcmp(token[i], "umask") == 0)
imc_counters_config[count].umask = strtol(token[i + 1], NULL, 16);
}
}
static int open_perf_read_event(int i, int cpu_no)
{
imc_counters_config[i].fd =
perf_event_open(&imc_counters_config[i].pe, -1, cpu_no, -1,
PERF_FLAG_FD_CLOEXEC);
if (imc_counters_config[i].fd == -1) {
fprintf(stderr, "Error opening leader %llx\n",
imc_counters_config[i].pe.config);
return -1;
}
return 0;
}
static int parse_imc_read_bw_events(char *imc_dir, unsigned int type,
Annotation
- Immediate include surface: `resctrl.h`.
- Detected declarations: `struct membw_read_format`, `struct imc_counter_config`, `function read_mem_bw_initialize_perf_event_attr`, `function read_mem_bw_ioctl_perf_event_ioc_reset_enable`, `function read_mem_bw_ioctl_perf_event_ioc_disable`, `function get_read_event_and_umask`, `function open_perf_read_event`, `function parse_imc_read_bw_events`, `function read_from_imc_dir`, `function num_of_imcs`.
- 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.