summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2025-10-20 09:41:27 -1000
committerLinus Torvalds <torvalds@linux-foundation.org>2025-10-20 09:41:27 -1000
commit6548d364a3e850326831799d7e3ea2d7bb97ba08 (patch)
tree9b8a6bfddf8045088e088e9f343d1925bacd2c60 /tools/testing/selftests/cgroup/lib/include/cgroup_util.h
parent380cb5d3533cddd93050d72d65f7b1fc997823f7 (diff)
parent0fbbcab7f9082cdc233da5e5e353f69830f11956 (diff)
downloadlinux-next-6548d364a3e850326831799d7e3ea2d7bb97ba08.tar.gz
linux-next-6548d364a3e850326831799d7e3ea2d7bb97ba08.zip
Merge tag 'cgroup-for-6.18-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup fixes from Tejun Heo: - Fix seqcount lockdep assertion failure in cgroup freezer on PREEMPT_RT. Plain seqcount_t expects preemption disabled, but PREEMPT_RT spinlocks don't disable preemption. Switch to seqcount_spinlock_t to properly associate css_set_lock with the freeze timing seqcount. - Misc changes including kernel-doc warning fix for misc_res_type enum and improved selftest diagnostics. * tag 'cgroup-for-6.18-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup/misc: fix misc_res_type kernel-doc warning selftests: cgroup: Use values_close_report in test_cpu selftests: cgroup: add values_close_report helper cgroup: Fix seqcount lockdep assertion in cgroup freezer
Diffstat (limited to 'tools/testing/selftests/cgroup/lib/include/cgroup_util.h')
-rw-r--r--tools/testing/selftests/cgroup/lib/include/cgroup_util.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
index 9dc90a1b386d..7ab2824ed7b5 100644
--- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
+++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
@@ -25,6 +25,26 @@ static inline int values_close(long a, long b, int err)
return labs(a - b) <= (a + b) / 100 * err;
}
+/*
+ * Checks if two given values differ by less than err% of their sum and assert
+ * with detailed debug info if not.
+ */
+static inline int values_close_report(long a, long b, int err)
+{
+ long diff = labs(a - b);
+ long limit = (a + b) / 100 * err;
+ double actual_err = (a + b) ? (100.0 * diff / (a + b)) : 0.0;
+ int close = diff <= limit;
+
+ if (!close)
+ fprintf(stderr,
+ "[FAIL] actual=%ld expected=%ld | diff=%ld | limit=%ld | "
+ "tolerance=%d%% | actual_error=%.2f%%\n",
+ a, b, diff, limit, err, actual_err);
+
+ return close;
+}
+
extern ssize_t read_text(const char *path, char *buf, size_t max_len);
extern ssize_t write_text(const char *path, char *buf, ssize_t len);