Skip to contentSkip to conversation

keyctl02: Add delay between main loop iterations for RT kernels

PATCH In review Martin Doucha 2 participants 2 messages Nov 3, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 keyctl02: Add delay between main loop iterations for RT kernels

Realtime kernels have deferred thread cleanup which means that exited and joined threads can still pile up and trigger cgroup thread limits. Add 100us delay on RT kernels to limit the maximum number of stale threads.

---

The extra delay adds ~3 seconds to total test runtime. Tested on SLERT-12SP5, SLERT-15SP4 and SLES-12SP5.

 testcases/kernel/syscalls/keyctl/keyctl02.c | 24 +++++++++++++++++++++
 1 file changed, 24 insertions(+)
testcases/kernel/syscalls/keyctl/keyctl02.c +24 -0
index 35cc2838d..2a81ce9e6 100644
@@ -29,13 +29,17 @@
 
 #include "tst_safe_pthread.h"
 #include "tst_test.h"
+#include "tst_kconfig.h"
 #include "lapi/keyctl.h"
 
 #define LOOPS	20000
 #define MAX_WAIT_FOR_GC_MS 5000
 #define PATH_KEY_COUNT_QUOTA	"/proc/sys/kernel/keys/root_maxkeys"
 
+#define KCONFIG_INIT(confname) { .id = confname, .id_len = strlen(confname) }
+
 static int orig_maxkeys;
+static int realtime_kernel;
 
 static void *do_read(void *arg)
 {
@@ -86,6 +90,15 @@ static void do_test(void)
 			tst_res(TINFO, "Runtime exhausted, exiting after %d loops", i);
 			break;
 		}
+
+		/*
+		 * Realtime kernel has deferred post-join thread cleanup which
+		 * may result in exhaustion of cgroup thread limit. Add delay
+		 * to limit the maximum number of stale threads to 4000
+		 * even with CONFIG_HZ=100.
+		 */
+		if (realtime_kernel)
+			usleep(100);
 	}
 
 	/*
@@ -126,8 +139,19 @@ static void do_test(void)
 
 static void setup(void)
 {
+	int i;
+	struct tst_kconfig_var rt_kconfigs[] = {
+		KCONFIG_INIT("CONFIG_PREEMPT_RT"),
+		KCONFIG_INIT("CONFIG_PREEMPT_RT_FULL")
+	};
+
 	SAFE_FILE_SCANF(PATH_KEY_COUNT_QUOTA, "%d", &orig_maxkeys);
 	SAFE_FILE_PRINTF(PATH_KEY_COUNT_QUOTA, "%d", orig_maxkeys + LOOPS + 1);
+
+	tst_kconfig_read(rt_kconfigs, ARRAY_SIZE(rt_kconfigs));
+
+	for (i = 0; i < ARRAY_SIZE(rt_kconfigs); i++)
+		realtime_kernel |= rt_kconfigs[i].choice == 'y';
 }
 
 static void cleanup(void)
Signature · 5 lines
2.42.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Martin,

...

testcases/kernel/syscalls/keyctl/keyctl02.c line 39

Quoted 13 lines

+++ b/testcases/kernel/syscalls/keyctl/keyctl02.c

testcases/kernel/syscalls/keyctl/keyctl02.c +2 -0
@@ -29,13 +29,17 @@
 
 #include "tst_safe_pthread.h"
 #include "tst_test.h"
+#include "tst_kconfig.h"
 #include "lapi/keyctl.h"
 
 #define LOOPS	20000
 #define MAX_WAIT_FOR_GC_MS 5000
 #define PATH_KEY_COUNT_QUOTA	"/proc/sys/kernel/keys/root_maxkeys"
 
+#define KCONFIG_INIT(confname) { .id = confname, .id_len = strlen(confname) }

BTW this could be added (as separate effort) somewhere in the library (include/tst_common.h) and reused in other tests (well, there are only 3 tests).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp