History

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

Linus Torvalds committed 1 year ago

Commit 6548d362 parents 380cb5d 0fbbcab5 files · +32 −12Browse files

Unified · Split

5 files
  1. include/linux/cgroup-defs.h +1 −1
  2. include/linux/misc_cgroup.h +1 −1
  3. kernel/cgroup/cgroup.c +1 −1
  4. tools/testing/selftests/cgroup/lib/include/cgroup_util.h +20 −0
  5. tools/testing/selftests/cgroup/test_cpu.c +9 −9
include/linux/cgroup-defs.h+1−1
@@ -452,7 +452,7 @@ struct cgroup_freezer_state { · 451 unmodified lines
452 int nr_frozen_tasks;452 int nr_frozen_tasks;
453 453
454 /* Freeze time data consistency protection */454 /* Freeze time data consistency protection */
455 seqcount_t freeze_seq;455 seqcount_spinlock_t freeze_seq;
456 456
457 /*457 /*
458 * Most recent time the cgroup was requested to freeze.458 * Most recent time the cgroup was requested to freeze.
include/linux/misc_cgroup.h+1−1
@@ -19,7 +19,7 @@ enum misc_res_type { · 18 unmodified lines
19 MISC_CG_RES_SEV_ES,19 MISC_CG_RES_SEV_ES,
20#endif20#endif
21#ifdef CONFIG_INTEL_TDX_HOST21#ifdef CONFIG_INTEL_TDX_HOST
22 /* Intel TDX HKIDs resource */22 /** @MISC_CG_RES_TDX: Intel TDX HKIDs resource */
23 MISC_CG_RES_TDX,23 MISC_CG_RES_TDX,
24#endif24#endif
25 /** @MISC_CG_RES_TYPES: count of enum misc_res_type constants */25 /** @MISC_CG_RES_TYPES: count of enum misc_res_type constants */
kernel/cgroup/cgroup.c+1−1
@@ -5892,7 +5892,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, · 5891 unmodified lines
5892 * if the parent has to be frozen, the child has too.5892 * if the parent has to be frozen, the child has too.
5893 */5893 */
5894 cgrp->freezer.e_freeze = parent->freezer.e_freeze;5894 cgrp->freezer.e_freeze = parent->freezer.e_freeze;
5895 seqcount_init(&cgrp->freezer.freeze_seq);5895 seqcount_spinlock_init(&cgrp->freezer.freeze_seq, &css_set_lock);
5896 if (cgrp->freezer.e_freeze) {5896 if (cgrp->freezer.e_freeze) {
5897 /*5897 /*
5898 * Set the CGRP_FREEZE flag, so when a process will be5898 * Set the CGRP_FREEZE flag, so when a process will be
tools/testing/selftests/cgroup/lib/include/cgroup_util.h+20−0
@@ -25,6 +25,26 @@ static inline int values_close(long a, long b, int err) · 24 unmodified lines
25 return labs(a - b) <= (a + b) / 100 * err;25 return labs(a - b) <= (a + b) / 100 * err;
26}26}
27 27
28/*
29 * Checks if two given values differ by less than err% of their sum and assert
30 * with detailed debug info if not.
31 */
32static inline int values_close_report(long a, long b, int err)
33{
34 long diff = labs(a - b);
35 long limit = (a + b) / 100 * err;
36 double actual_err = (a + b) ? (100.0 * diff / (a + b)) : 0.0;
37 int close = diff <= limit;
38
39 if (!close)
40 fprintf(stderr,
41 "[FAIL] actual=%ld expected=%ld | diff=%ld | limit=%ld | "
42 "tolerance=%d%% | actual_error=%.2f%%\n",
43 a, b, diff, limit, err, actual_err);
44
45 return close;
46}
47
28extern ssize_t read_text(const char *path, char *buf, size_t max_len);48extern ssize_t read_text(const char *path, char *buf, size_t max_len);
29extern ssize_t write_text(const char *path, char *buf, ssize_t len);49extern ssize_t write_text(const char *path, char *buf, ssize_t len);
30 50
tools/testing/selftests/cgroup/test_cpu.c+9−9
@@ -219,7 +219,7 @@ static int test_cpucg_stats(const char *root) · 218 unmodified lines
219 if (user_usec <= 0)219 if (user_usec <= 0)
220 goto cleanup;220 goto cleanup;
221 221
222 if (!values_close(usage_usec, expected_usage_usec, 1))222 if (!values_close_report(usage_usec, expected_usage_usec, 1))
223 goto cleanup;223 goto cleanup;
224 224
225 ret = KSFT_PASS;225 ret = KSFT_PASS;
@@ -291,7 +291,7 @@ static int test_cpucg_nice(const char *root) · 65 unmodified lines
291 291
292 user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec");292 user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec");
293 nice_usec = cg_read_key_long(cpucg, "cpu.stat", "nice_usec");293 nice_usec = cg_read_key_long(cpucg, "cpu.stat", "nice_usec");
294 if (!values_close(nice_usec, expected_nice_usec, 1))294 if (!values_close_report(nice_usec, expected_nice_usec, 1))
295 goto cleanup;295 goto cleanup;
296 296
297 ret = KSFT_PASS;297 ret = KSFT_PASS;
@@ -404,7 +404,7 @@ overprovision_validate(const struct cpu_hogger *children, int num_children) · 106 unmodified lines
404 goto cleanup;404 goto cleanup;
405 405
406 delta = children[i + 1].usage - children[i].usage;406 delta = children[i + 1].usage - children[i].usage;
407 if (!values_close(delta, children[0].usage, 35))407 if (!values_close_report(delta, children[0].usage, 35))
408 goto cleanup;408 goto cleanup;
409 }409 }
410 410
@@ -444,7 +444,7 @@ underprovision_validate(const struct cpu_hogger *children, int num_children) · 33 unmodified lines
444 int ret = KSFT_FAIL, i;444 int ret = KSFT_FAIL, i;
445 445
446 for (i = 0; i < num_children - 1; i++) {446 for (i = 0; i < num_children - 1; i++) {
447 if (!values_close(children[i + 1].usage, children[0].usage, 15))447 if (!values_close_report(children[i + 1].usage, children[0].usage, 15))
448 goto cleanup;448 goto cleanup;
449 }449 }
450 450
@@ -573,16 +573,16 @@ run_cpucg_nested_weight_test(const char *root, bool overprovisioned) · 122 unmodified lines
573 573
574 nested_leaf_usage = leaf[1].usage + leaf[2].usage;574 nested_leaf_usage = leaf[1].usage + leaf[2].usage;
575 if (overprovisioned) {575 if (overprovisioned) {
576 if (!values_close(leaf[0].usage, nested_leaf_usage, 15))576 if (!values_close_report(leaf[0].usage, nested_leaf_usage, 15))
577 goto cleanup;577 goto cleanup;
578 } else if (!values_close(leaf[0].usage * 2, nested_leaf_usage, 15))578 } else if (!values_close_report(leaf[0].usage * 2, nested_leaf_usage, 15))
579 goto cleanup;579 goto cleanup;
580 580
581 581
582 child_usage = cg_read_key_long(child, "cpu.stat", "usage_usec");582 child_usage = cg_read_key_long(child, "cpu.stat", "usage_usec");
583 if (child_usage <= 0)583 if (child_usage <= 0)
584 goto cleanup;584 goto cleanup;
585 if (!values_close(child_usage, nested_leaf_usage, 1))585 if (!values_close_report(child_usage, nested_leaf_usage, 1))
586 goto cleanup;586 goto cleanup;
587 587
588 ret = KSFT_PASS;588 ret = KSFT_PASS;
@@ -691,7 +691,7 @@ static int test_cpucg_max(const char *root) · 102 unmodified lines
691 expected_usage_usec691 expected_usage_usec
692 = n_periods * quota_usec + MIN(remainder_usec, quota_usec);692 = n_periods * quota_usec + MIN(remainder_usec, quota_usec);
693 693
694 if (!values_close(usage_usec, expected_usage_usec, 10))694 if (!values_close_report(usage_usec, expected_usage_usec, 10))
695 goto cleanup;695 goto cleanup;
696 696
697 ret = KSFT_PASS;697 ret = KSFT_PASS;
@@ -762,7 +762,7 @@ static int test_cpucg_max_nested(const char *root) · 64 unmodified lines
762 expected_usage_usec762 expected_usage_usec
763 = n_periods * quota_usec + MIN(remainder_usec, quota_usec);763 = n_periods * quota_usec + MIN(remainder_usec, quota_usec);
764 764
765 if (!values_close(usage_usec, expected_usage_usec, 10))765 if (!values_close_report(usage_usec, expected_usage_usec, 10))
766 goto cleanup;766 goto cleanup;
767 767
768 ret = KSFT_PASS;768 ret = KSFT_PASS;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t