[PATCH i-g-t 04/37] lib/igt_core: Track child process pid and tid

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Mar 19 19:29:11 UTC 2021


Introduce variables which can decrease number of getpid()/gettid()
calls, especially for allocator which must be aware of method
acquiring addresses.

When child is spawned using igt_fork() we can control its initialization
and prepare child_pid implicitly. Tracking child_tid requires our
intervention in the code and do something like this:

if (child_tid == -1)
	child_tid = gettid()

Variable was created for using in TLS so each thread is created
with variable set to -1. This will give each thread it's own "copy"
and there's no risk to use other thread tid. For each forked child
we reassign -1 to child_tid to avoid using already set variable.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Petri Latvala <petri.latvala at intel.com>
Acked-by: Arjun Melkaveri <arjun.melkaveri at intel.com>
---
 lib/igt_core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index f9dfaa0dd..2b4182f16 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -306,6 +306,10 @@ int num_test_children;
 int test_children_sz;
 bool test_child;
 
+/* For allocator purposes */
+pid_t child_pid  = -1;
+__thread pid_t child_tid  = -1;
+
 enum {
 	/*
 	 * Let the first values be used by individual tests so options don't
@@ -2302,6 +2306,8 @@ bool __igt_fork(void)
 	case 0:
 		test_child = true;
 		pthread_mutex_init(&print_mutex, NULL);
+		child_pid = getpid();
+		child_tid = -1;
 		exit_handler_count = 0;
 		reset_helper_process_list();
 		oom_adjust_for_doom();
-- 
2.26.0



More information about the Intel-gfx-trybot mailing list