tools/testing/selftests/cgroup/test_cpu.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/cgroup/test_cpu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/cgroup/test_cpu.c- Extension
.c- Size
- 18800 bytes
- Lines
- 826
- 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
linux/limits.hsys/param.hsys/sysinfo.hsys/wait.herrno.hpthread.hstdio.htime.hunistd.hkselftest.hcgroup_util.h
Detected Declarations
struct cpu_hoggerstruct cpu_hog_func_paramstruct cpucg_testenum hog_clock_typefunction test_cpucg_subtree_controlfunction timespec_subfunction hog_cpus_timedfunction test_cpucg_statsfunction test_cpucg_nicefunction run_cpucg_weight_testfunction weight_hog_ncpusfunction weight_hog_all_cpusfunction overprovision_validatefunction test_cpucg_weight_overprovisionedfunction weight_hog_one_cpufunction underprovision_validatefunction test_cpucg_weight_underprovisionedfunction run_cpucg_nested_weight_testfunction test_cpucg_nested_weight_overprovisionedfunction test_cpucg_nested_weight_underprovisionedfunction test_cpucg_maxfunction test_cpucg_max_nestedfunction main
Annotated Snippet
struct cpu_hogger {
char *cgroup;
pid_t pid;
long usage;
};
struct cpu_hog_func_param {
int nprocs;
struct timespec ts;
enum hog_clock_type clock_type;
};
/*
* This test creates two nested cgroups with and without enabling
* the cpu controller.
*/
static int test_cpucg_subtree_control(const char *root)
{
char *parent = NULL, *child = NULL, *parent2 = NULL, *child2 = NULL;
int ret = KSFT_FAIL;
// Create two nested cgroups with the cpu controller enabled.
parent = cg_name(root, "cpucg_test_0");
if (!parent)
goto cleanup;
if (cg_create(parent))
goto cleanup;
if (cg_write(parent, "cgroup.subtree_control", "+cpu"))
goto cleanup;
child = cg_name(parent, "cpucg_test_child");
if (!child)
goto cleanup;
if (cg_create(child))
goto cleanup;
if (cg_read_strstr(child, "cgroup.controllers", "cpu"))
goto cleanup;
// Create two nested cgroups without enabling the cpu controller.
parent2 = cg_name(root, "cpucg_test_1");
if (!parent2)
goto cleanup;
if (cg_create(parent2))
goto cleanup;
child2 = cg_name(parent2, "cpucg_test_child");
if (!child2)
goto cleanup;
if (cg_create(child2))
goto cleanup;
if (!cg_read_strstr(child2, "cgroup.controllers", "cpu"))
goto cleanup;
ret = KSFT_PASS;
cleanup:
cg_destroy(child);
free(child);
cg_destroy(child2);
free(child2);
cg_destroy(parent);
free(parent);
cg_destroy(parent2);
free(parent2);
return ret;
}
static void *hog_cpu_thread_func(void *arg)
{
while (1)
;
return NULL;
}
static struct timespec
timespec_sub(const struct timespec *lhs, const struct timespec *rhs)
{
struct timespec zero = {
.tv_sec = 0,
.tv_nsec = 0,
};
Annotation
- Immediate include surface: `linux/limits.h`, `sys/param.h`, `sys/sysinfo.h`, `sys/wait.h`, `errno.h`, `pthread.h`, `stdio.h`, `time.h`.
- Detected declarations: `struct cpu_hogger`, `struct cpu_hog_func_param`, `struct cpucg_test`, `enum hog_clock_type`, `function test_cpucg_subtree_control`, `function timespec_sub`, `function hog_cpus_timed`, `function test_cpucg_stats`, `function test_cpucg_nice`, `function run_cpucg_weight_test`.
- 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.