Skip to contentSkip to conversation

lib: tst_has_slow_kconfig() cache the result

PATCH In review Cyril Hrubis 3 participants 4 messages Jan 20, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: tst_has_slow_kconfig() cache the result

The result from the tst_has_slow_kconfig() is not going to change so we can cache the result as there are several cases where the function may end up being called. For instance any test that calls SAFE_CLONE() will call the function repeatedly. This change makes the tests slightly faster and also avoids repeated messages in the test output.

For example before:

tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' tst_test.c:1722: TINFO: Overall timeout per run is 0h 00m 30s tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:94: TPASS: find_cinit_pids(pids) returned 5
pidns05.c:112: TPASS: No children left after sending SIGKILL to the first child

And after:

tst_kconfig.c:88: TINFO: Parsing kernel config '/lib/modules/6.12.3/build/.config' tst_test.c:1722: TINFO: Overall timeout per run is 0h 00m 30s pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:34: TPASS: cpid == 1 (1)
pidns05.c:35: TPASS: ppid == 0 (0)
pidns05.c:94: TPASS: find_cinit_pids(pids) returned 5
pidns05.c:112: TPASS: No children left after sending SIGKILL to the first child

---
 lib/tst_kconfig.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
lib/tst_kconfig.c +13 -1
index e83de3dcd..66402e370 100644
@@ -652,13 +652,23 @@ static struct tst_kconfig_var slow_kconfigs[] = {
 	TST_KCONFIG_INIT("CONFIG_DEBUG_OBJECTS")
 };
 
+static bool slow_kconfig_cached;
+static bool slow_kconfig_result;
+
 int tst_has_slow_kconfig(void)
 {
 	unsigned int i;
 	char path_buf[1024];
 
-	if (!kconfig_path(path_buf, sizeof(path_buf)))
+	if (slow_kconfig_cached)
+		return slow_kconfig_result;
+
+	slow_kconfig_cached = 1;
+
+	if (!kconfig_path(path_buf, sizeof(path_buf))) {
+		slow_kconfig_result = 0;
 		return 0;
+	}
 
 	tst_kconfig_read(slow_kconfigs, ARRAY_SIZE(slow_kconfigs));
 
@@ -667,9 +677,11 @@ int tst_has_slow_kconfig(void)
 			tst_res(TINFO,
 				"%s kernel option detected which might slow the execution",
 				slow_kconfigs[i].id);
+			slow_kconfig_result = 1;
 			return 1;
 		}
 	}
 
+	slow_kconfig_result = 0;
 	return 0;
 }
Signature · 5 lines
2.45.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#2 lore raw
In reply to Cyril Hrubis

Hi Cyril, Li,

Quoted 5 lines

The result from the tst_has_slow_kconfig() is not going to change so we can cache the result as there are several cases where the function may end up being called. For instance any test that calls SAFE_CLONE() will call the function repeatedly. This change makes the tests slightly faster and also avoids repeated messages in the test output.

Thanks, elegant solution, thanks!

Kind regards,
Petr

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

Hi!
Thanks for the reviews, pushed.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp