[igt-dev] [i-g-t, v9, 03/29] lib/igt_core: Track child process pid and tid
Melkaveri, Arjun
arjun.melkaveri at intel.com
Tue Nov 17 19:45:19 UTC 2020
On Mon, Nov 16, 2020 at 09:51:44AM +0100, Zbigniew Kempczyński wrote:
> 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 8f9d925b..be6f8429 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();
Acked-by: Arjun Melkaveri <arjun.melkaveri at intel.com>
More information about the igt-dev
mailing list