Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cgroup: Add test_cpucg_max() testcase

The cgroup cpu controller test suite has a number of testcases that
validate the expected behavior of the cpu.weight knob, but none for
cpu.max. This testcase fixes that by adding a testcase for cpu.max as well.

Signed-off-by: David Vernet <void@manifault.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

David Vernet and committed by
Tejun Heo
889ab811 89ca0efa

+54
+54
tools/testing/selftests/cgroup/test_cpu.c
··· 564 564 return run_cpucg_nested_weight_test(root, false); 565 565 } 566 566 567 + /* 568 + * This test creates a cgroup with some maximum value within a period, and 569 + * verifies that a process in the cgroup is not overscheduled. 570 + */ 571 + static int test_cpucg_max(const char *root) 572 + { 573 + int ret = KSFT_FAIL; 574 + long usage_usec, user_usec; 575 + long usage_seconds = 1; 576 + long expected_usage_usec = usage_seconds * USEC_PER_SEC; 577 + char *cpucg; 578 + 579 + cpucg = cg_name(root, "cpucg_test"); 580 + if (!cpucg) 581 + goto cleanup; 582 + 583 + if (cg_create(cpucg)) 584 + goto cleanup; 585 + 586 + if (cg_write(cpucg, "cpu.max", "1000")) 587 + goto cleanup; 588 + 589 + struct cpu_hog_func_param param = { 590 + .nprocs = 1, 591 + .ts = { 592 + .tv_sec = usage_seconds, 593 + .tv_nsec = 0, 594 + }, 595 + .clock_type = CPU_HOG_CLOCK_WALL, 596 + }; 597 + if (cg_run(cpucg, hog_cpus_timed, (void *)&param)) 598 + goto cleanup; 599 + 600 + usage_usec = cg_read_key_long(cpucg, "cpu.stat", "usage_usec"); 601 + user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec"); 602 + if (user_usec <= 0) 603 + goto cleanup; 604 + 605 + if (user_usec >= expected_usage_usec) 606 + goto cleanup; 607 + 608 + if (values_close(usage_usec, expected_usage_usec, 95)) 609 + goto cleanup; 610 + 611 + ret = KSFT_PASS; 612 + 613 + cleanup: 614 + cg_destroy(cpucg); 615 + free(cpucg); 616 + 617 + return ret; 618 + } 619 + 567 620 #define T(x) { x, #x } 568 621 struct cpucg_test { 569 622 int (*fn)(const char *root); ··· 628 575 T(test_cpucg_weight_underprovisioned), 629 576 T(test_cpucg_nested_weight_overprovisioned), 630 577 T(test_cpucg_nested_weight_underprovisioned), 578 + T(test_cpucg_max), 631 579 }; 632 580 #undef T 633 581