tools/testing/selftests/resctrl/resctrlfs.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/resctrl/resctrlfs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/resctrl/resctrlfs.c- Extension
.c- Size
- 22030 bytes
- Lines
- 1002
- 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
fcntl.hlimits.hresctrl.h
Detected Declarations
function find_resctrl_mountfunction mount_resctrlfsfunction umount_resctrlfsfunction get_cache_levelfunction get_resource_cache_levelfunction get_domain_idfunction count_sys_bitmap_bitsfunction cpus_offline_emptyfunction snc_nodes_per_l3_cachefunction get_cache_sizefunction get_bit_maskfunction resource_info_unsigned_getfunction create_bit_maskfunction count_contiguous_bitsfunction get_full_cbmfunction get_shareable_maskfunction get_mask_no_shareablefunction taskset_benchmarkfunction taskset_restorefunction create_grpfunction write_pid_to_tasksfunction write_bm_pid_to_resctrlfunction write_schematafunction check_resctrlfs_supportfunction resctrl_resource_existsfunction resctrl_mon_feature_existsfunction resource_info_file_existsfunction test_resource_feature_checkfunction filter_dmesgfunction perf_event_openfunction count_bitsfunction snc_kernel_support
Annotated Snippet
switch (c) {
case 'f':
count++;
fallthrough;
case '7': case 'b': case 'd': case 'e':
count++;
fallthrough;
case '3': case '5': case '6': case '9': case 'a': case 'c':
count++;
fallthrough;
case '1': case '2': case '4': case '8':
count++;
break;
}
}
fclose(fp);
return count;
}
static bool cpus_offline_empty(void)
{
char offline_cpus_str[64];
FILE *fp;
fp = fopen("/sys/devices/system/cpu/offline", "r");
if (!fp) {
ksft_perror("Could not open /sys/devices/system/cpu/offline");
return 0;
}
if (fscanf(fp, "%63s", offline_cpus_str) < 0) {
if (!errno) {
fclose(fp);
return 1;
}
ksft_perror("Could not read /sys/devices/system/cpu/offline");
}
fclose(fp);
return 0;
}
/*
* Detect SNC by comparing #CPUs in node0 with #CPUs sharing LLC with CPU0.
* If any CPUs are offline declare the detection as unreliable.
*/
int snc_nodes_per_l3_cache(void)
{
int node_cpus, cache_cpus;
static int snc_mode;
if (!snc_mode) {
snc_mode = 1;
if (!cpus_offline_empty()) {
ksft_print_msg("Runtime SNC detection unreliable due to offline CPUs.\n");
ksft_print_msg("Setting SNC mode to disabled.\n");
snc_unreliable = 1;
return snc_mode;
}
node_cpus = count_sys_bitmap_bits("/sys/devices/system/node/node0/cpumap");
cache_cpus = count_sys_bitmap_bits("/sys/devices/system/cpu/cpu0/cache/index3/shared_cpu_map");
if (!node_cpus || !cache_cpus) {
ksft_print_msg("Could not determine Sub-NUMA Cluster mode.\n");
snc_unreliable = 1;
return snc_mode;
}
snc_mode = cache_cpus / node_cpus;
/*
* On some platforms (e.g. Hygon),
* cache_cpus < node_cpus, the calculated snc_mode is 0.
*
* Set snc_mode = 1 to indicate that SNC mode is not
* supported on the platform.
*/
if (!snc_mode)
snc_mode = 1;
if (snc_mode > 1)
ksft_print_msg("SNC-%d mode discovered.\n", snc_mode);
}
return snc_mode;
}
/*
* get_cache_size - Get cache size for a specified CPU
Annotation
- Immediate include surface: `fcntl.h`, `limits.h`, `resctrl.h`.
- Detected declarations: `function find_resctrl_mount`, `function mount_resctrlfs`, `function umount_resctrlfs`, `function get_cache_level`, `function get_resource_cache_level`, `function get_domain_id`, `function count_sys_bitmap_bits`, `function cpus_offline_empty`, `function snc_nodes_per_l3_cache`, `function get_cache_size`.
- 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.