selftests/cgroup: Adjust cpu test duration based on HZ
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 1 line · Joe Simmons-Talbott
+mailing lists
+Tao Cui
Quoted 144 lines
For lower HZ values a quota of 1000us is much lower than the amount of microseconds per tick which makes the tests
test_cpucg_maxandtest_cpugc_max_nestedfail. Increase the test duration to accommodate for lower HZ values.Signed-off-by Joe Simmons-Talbott <[email protected]>---
v3 -> v4:
- Use usec for adjusting test duration for better accuracy.
- Remove underscore from static function
- Use 1000 as the fallback value for hz since it's the default.v2 -> v3:
- Instead of changing cpu.max quota extend the test duration based on the HZ value.
- don't callpclose()ifpopen()fails.
- check return value offscanf().v1 -> v2:
- Try checking/proc/config.gzto get the actual kernel HZ value and fallback to 1000 if the value cannot be determined..../cgroup/lib/include/cgroup_util.h | 1 + tools/testing/selftests/cgroup/test_cpu.c | 47 ++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-)tools/testing/selftests/cgroup/lib/include/cgroup_util.h +1
-0@@ -8,6 +8,7 @@#define MB (x) (x << 20) +#define NSEC_PER_USEC 1000L#define USEC_PER_SEC 1000000L#define NSEC_PER_SEC 1000000000Ltools/testing/selftests/cgroup/test_cpu.c +41
-7@@ -639,6 +639,31 @@ test_cpucg_nested_weight_underprovisioned(const char *root)return run_cpucg_nested_weight_test (root, false); } +/* +* Best effort attempt to get the kernel's HZ value from the config. +* Return the HZ value if found otherwise return 1000 (the default) to +* indicate failure. +*/ +static long +get_config_hz (void ) +{ +long hz =1000 ; +FILE *f; +char cmd[256 ] ="zcat /proc/config.gz 2>/dev/null | grep '^CONFIG_HZ='" ; + + f =popen (cmd,"r" ); + +if (!f) +return hz; + +if (fscanf (f,"CONFIG_HZ=%ld" , &hz) ==EOF ) + goto out; + +out: +pclose (f); +return hz; +} +/* * This test creates a cgroup with some maximum value within a period, and * verifies that a process in the cgroup is not overscheduled. @@ -646,15 +671,20 @@ test_cpucg_nested_weight_underprovisioned(const char *root)static int test_cpucg_max (const char *root) {int ret =KSFT_FAIL ; +long hz =get_config_hz ();long quota_usec =1000 ;long default_period_usec =100000 ;/* cpu.max's default period */ long duration_seconds =1 ; -long duration_usec = duration_seconds *USEC_PER_SEC ; +long duration_usec, duration_sec, duration_nsec;long usage_usec, n_periods, remainder_usec, expected_usage_usec;char *cpucg;char quota_buf[32 ]; + duration_usec = duration_seconds *USEC_PER_SEC *1000 / hz; + duration_sec = duration_usec /USEC_PER_SEC ; + duration_nsec = duration_usec %USEC_PER_SEC *NSEC_PER_USEC ; +snprintf (quota_buf,sizeof (quota_buf),"%ld" , quota_usec); cpucg =cg_name (root,"cpucg_test" );@@ -670,8 +700,8 @@ static int test_cpucg_max(const char *root)struct cpu_hog_func_param param = { .nprocs =1 , .ts = { - .tv_sec = duration_seconds, - .tv_nsec =0 , + .tv_sec = duration_sec, + .tv_nsec = duration_nsec, }, .clock_type =CPU_HOG_CLOCK_WALL , };@@ -710,15 +740,20 @@ static int test_cpucg_max(const char *root)static int test_cpucg_max_nested (const char *root) {int ret =KSFT_FAIL ; +long hz =get_config_hz ();long quota_usec =1000 ;long default_period_usec =100000 ;/* cpu.max's default period */ long duration_seconds =1 ; -long duration_usec = duration_seconds *USEC_PER_SEC ; +long duration_usec, duration_sec, duration_nsec;long usage_usec, n_periods, remainder_usec, expected_usage_usec;char *parent, *child;char quota_buf[32 ]; + duration_usec = duration_seconds *USEC_PER_SEC *1000 / hz; + duration_sec = duration_usec /USEC_PER_SEC ; + duration_nsec = duration_usec %USEC_PER_SEC *NSEC_PER_USEC ; +snprintf (quota_buf,sizeof (quota_buf),"%ld" , quota_usec); parent =cg_name (root,"cpucg_parent" );@@ -741,8 +776,8 @@ static int test_cpucg_max_nested(const char *root)struct cpu_hog_func_param param = { .nprocs =1 , .ts = { - .tv_sec = duration_seconds, - .tv_nsec =0 , + .tv_sec = duration_sec, + .tv_nsec = duration_nsec, }, .clock_type =CPU_HOG_CLOCK_WALL , }; --2.54.0
Review
Quoted 5 lines · Joe Simmons-Talbott
Quoted 1 line · Joe Simmons-Talbott
(quoted diff) +2
-0+mailing lists +Tao Cui
I messed this up. Please ignore this patch. I will resend.
Thanks,
Joe
Quoted 147 lines
Quoted 147 lines
For lower HZ values a quota of 1000us is much lower than the amount of microseconds per tick which makes the tests
test_cpucg_maxandtest_cpugc_max_nestedfail. Increase the test duration to accommodate for lower HZ values.Signed-off-by Joe Simmons-Talbott <[email protected]>---
v3 -> v4:
- Use usec for adjusting test duration for better accuracy.
- Remove underscore from static function
- Use 1000 as the fallback value for hz since it's the default.v2 -> v3:
- Instead of changing cpu.max quota extend the test duration based on the HZ value.
- don't callpclose()ifpopen()fails.
- check return value offscanf().v1 -> v2:
- Try checking/proc/config.gzto get the actual kernel HZ value and fallback to 1000 if the value cannot be determined..../cgroup/lib/include/cgroup_util.h | 1 + tools/testing/selftests/cgroup/test_cpu.c | 47 ++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-)tools/testing/selftests/cgroup/lib/include/cgroup_util.h +1
-0@@ -8,6 +8,7 @@#define MB (x) (x << 20) +#define NSEC_PER_USEC 1000L#define USEC_PER_SEC 1000000L#define NSEC_PER_SEC 1000000000Ltools/testing/selftests/cgroup/test_cpu.c +41
-7@@ -639,6 +639,31 @@ test_cpucg_nested_weight_underprovisioned(const char *root)return run_cpucg_nested_weight_test (root, false); } +/* +* Best effort attempt to get the kernel's HZ value from the config. +* Return the HZ value if found otherwise return 1000 (the default) to +* indicate failure. +*/ +static long +get_config_hz (void ) +{ +long hz =1000 ; +FILE *f; +char cmd[256 ] ="zcat /proc/config.gz 2>/dev/null | grep '^CONFIG_HZ='" ; + + f =popen (cmd,"r" ); + +if (!f) +return hz; + +if (fscanf (f,"CONFIG_HZ=%ld" , &hz) ==EOF ) + goto out; + +out: +pclose (f); +return hz; +} +/* * This test creates a cgroup with some maximum value within a period, and * verifies that a process in the cgroup is not overscheduled. @@ -646,15 +671,20 @@ test_cpucg_nested_weight_underprovisioned(const char *root)static int test_cpucg_max (const char *root) {int ret =KSFT_FAIL ; +long hz =get_config_hz ();long quota_usec =1000 ;long default_period_usec =100000 ;/* cpu.max's default period */ long duration_seconds =1 ; -long duration_usec = duration_seconds *USEC_PER_SEC ; +long duration_usec, duration_sec, duration_nsec;long usage_usec, n_periods, remainder_usec, expected_usage_usec;char *cpucg;char quota_buf[32 ]; + duration_usec = duration_seconds *USEC_PER_SEC *1000 / hz; + duration_sec = duration_usec /USEC_PER_SEC ; + duration_nsec = duration_usec %USEC_PER_SEC *NSEC_PER_USEC ; +snprintf (quota_buf,sizeof (quota_buf),"%ld" , quota_usec); cpucg =cg_name (root,"cpucg_test" );@@ -670,8 +700,8 @@ static int test_cpucg_max(const char *root)struct cpu_hog_func_param param = { .nprocs =1 , .ts = { - .tv_sec = duration_seconds, - .tv_nsec =0 , + .tv_sec = duration_sec, + .tv_nsec = duration_nsec, }, .clock_type =CPU_HOG_CLOCK_WALL , };@@ -710,15 +740,20 @@ static int test_cpucg_max(const char *root)static int test_cpucg_max_nested (const char *root) {int ret =KSFT_FAIL ; +long hz =get_config_hz ();long quota_usec =1000 ;long default_period_usec =100000 ;/* cpu.max's default period */ long duration_seconds =1 ; -long duration_usec = duration_seconds *USEC_PER_SEC ; +long duration_usec, duration_sec, duration_nsec;long usage_usec, n_periods, remainder_usec, expected_usage_usec;char *parent, *child;char quota_buf[32 ]; + duration_usec = duration_seconds *USEC_PER_SEC *1000 / hz; + duration_sec = duration_usec /USEC_PER_SEC ; + duration_nsec = duration_usec %USEC_PER_SEC *NSEC_PER_USEC ; +snprintf (quota_buf,sizeof (quota_buf),"%ld" , quota_usec); parent =cg_name (root,"cpucg_parent" );@@ -741,8 +776,8 @@ static int test_cpucg_max_nested(const char *root)struct cpu_hog_func_param param = { .nprocs =1 , .ts = { - .tv_sec = duration_seconds, - .tv_nsec =0 , + .tv_sec = duration_sec, + .tv_nsec = duration_nsec, }, .clock_type =CPU_HOG_CLOCK_WALL , }; --2.54.0