[igt-dev] [PATCH i-g-t v2 03/23] lib/igt_core: Track child process pid and tid
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Fri Oct 23 07:30:08 UTC 2020
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>
---
lib/igt_core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index b358173f..1f725d00 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -58,6 +58,7 @@
#include <glib.h>
#include "drmtest.h"
+#include "intel_allocator.h"
#include "intel_chipset.h"
#include "intel_io.h"
#include "igt_debugfs.h"
@@ -306,6 +307,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
@@ -2303,6 +2308,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 igt-dev
mailing list