Skip to contentSkip to conversation

selftests/cgroup: Adjust cpu test duration based on HZ

PATCH RESEND Superseded Joe Simmons-Talbott 3 participants 3 messages Jun 25 – Jun 26

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v4 1/1 selftests/cgroup: Adjust cpu test duration based on HZ

For lower HZ values a quota of 1000us is much lower than the amount of microseconds per tick which makes the tests test_cpucg_max and test_cpugc_max_nested fail. Increase the test duration to accommodate for lower HZ values.

---
CC: [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 call pclose() if popen() fails.
- check return value of fscanf().

v1 -> v2:
- Try checking /proc/config.gz to 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
index febc1723d090..8ebb2b4d4ec0 100644
@@ -8,6 +8,7 @@
 
 #define MB(x) (x << 20)
 
+#define NSEC_PER_USEC	1000L
 #define USEC_PER_SEC	1000000L
 #define NSEC_PER_SEC	1000000000L
 
tools/testing/selftests/cgroup/test_cpu.c +41 -6

93 lines not on this page · raw message

Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 7 lines · Joe Simmons-Talbott

static int test_cpucg_max_nested(const char *root) {

tools/testing/selftests/cgroup/test_cpu.c +1 -0
 	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;

tools/testing/selftests/cgroup/test_cpu.c static int test_cpucg_max(const char *root) · line 755

Quoted 10 lines
tools/testing/selftests/cgroup/test_cpu.c +4 -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;

Oh, that's duration in so many units and the seconds is there twice. (I understand why you did that for the rescale but) could you pick more descriptive/distinctive names then and ideally keep it simple :-p

Thanks,
Michal

#2 lore raw
Quoted 15 lines · Michal Koutný
Quoted 14 lines · Joe Simmons-Talbott

static int test_cpucg_max_nested(const char *root) {

tools/testing/selftests/cgroup/test_cpu.c +2 -1
 	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];
Quoted 7 lines

tools/testing/selftests/cgroup/test_cpu.c test_cpucg_nested_weight_underprovisioned(const char *root) · line 686

Quoted 3 lines
tools/testing/selftests/cgroup/test_cpu.c +3 -0
+	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;

Oh, that's duration in so many units and the seconds is there twice. (I understand why you did that for the rescale but) could you pick more descriptive/distinctive names then and ideally keep it simple :-p

Thanks for the feedback. I'll send a v5 with those intermediate variables removed and do the calculatons where they are used to setup the cpu hog's time values.

Thanks,
Joe