From: Petri Latvala <petri.latvala@intel.com>
To: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/3] lib/core: Print thred:tid with igt_log for non-main threads
Date: Thu, 18 Jun 2020 15:51:39 +0300 [thread overview]
Message-ID: <20200618125139.GJ20883@platvala-desk.ger.corp.intel.com> (raw)
In-Reply-To: <20200616141450.1181127-1-arkadiusz.hiler@intel.com>
On Tue, Jun 16, 2020 at 05:14:48PM +0300, Arkadiusz Hiler wrote:
> So that we know what's the source of messages.
>
> igt_thread.c is created to facilitate more threading-related
> functionality that will come in the following patch.
>
> Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
"lib/core: Print thred:tid with igt_log for non-main threads"
Typo, thred -> thread
Otherwise,
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
> ---
> lib/Makefile.sources | 2 ++
> lib/igt_core.c | 44 +++++++++++++++++++++++++++++++++++++-------
> lib/igt_thread.c | 39 +++++++++++++++++++++++++++++++++++++++
> lib/igt_thread.h | 24 ++++++++++++++++++++++++
> lib/meson.build | 1 +
> 5 files changed, 103 insertions(+), 7 deletions(-)
> create mode 100644 lib/igt_thread.c
> create mode 100644 lib/igt_thread.h
>
> diff --git a/lib/Makefile.sources b/lib/Makefile.sources
> index 09aedb40..00374c97 100644
> --- a/lib/Makefile.sources
> +++ b/lib/Makefile.sources
> @@ -64,6 +64,8 @@ lib_source_list = \
> igt_sysfs.h \
> igt_sysrq.c \
> igt_sysrq.h \
> + igt_thread.c \
> + igt_thread.h \
> igt_x86.h \
> igt_x86.c \
> igt_vec.c \
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index cbcc3f4d..c95295c7 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -72,6 +72,7 @@
> #include "igt_rc.h"
> #include "igt_list.h"
> #include "igt_device_scan.h"
> +#include "igt_thread.h"
>
> #define UNW_LOCAL_ONLY
> #include <libunwind.h>
> @@ -2687,6 +2688,12 @@ void igt_log(const char *domain, enum igt_log_level level, const char *format, .
> va_end(args);
> }
>
> +static pthread_key_t __vlog_line_continuation;
> +
> +igt_constructor {
> + pthread_key_create(&__vlog_line_continuation, NULL);
> +}
> +
> /**
> * igt_vlog:
> * @domain: the log domain, or NULL for no domain
> @@ -2705,6 +2712,7 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
> {
> FILE *file;
> char *line, *formatted_line;
> + char *thread_id;
> const char *program_name;
> const char *igt_log_level_str[] = {
> "DEBUG",
> @@ -2713,7 +2721,8 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
> "CRITICAL",
> "NONE"
> };
> - static bool line_continuation = false;
> +
> + static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER;
>
> assert(format);
>
> @@ -2723,23 +2732,37 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
> program_name = command_str;
> #endif
>
> +
> + if (igt_thread_is_main()) {
> + thread_id = strdup("");
> + } else {
> + if (asprintf(&thread_id, "[thread:%d] ", gettid()) == -1)
> + thread_id = NULL;
> + }
> +
> + if (!thread_id)
> + goto out;
> +
> if (list_subtests && level <= IGT_LOG_WARN)
> return;
>
> if (vasprintf(&line, format, args) == -1)
> return;
>
> - if (line_continuation) {
> + if (pthread_getspecific(__vlog_line_continuation)) {
> formatted_line = strdup(line);
> if (!formatted_line)
> goto out;
> - } else if (asprintf(&formatted_line, "(%s:%d) %s%s%s: %s", program_name,
> - getpid(), (domain) ? domain : "", (domain) ? "-" : "",
> + } else if (asprintf(&formatted_line, "(%s:%d) %s%s%s%s: %s", program_name,
> + getpid(), thread_id, (domain) ? domain : "", (domain) ? "-" : "",
> igt_log_level_str[level], line) == -1) {
> goto out;
> }
>
> - line_continuation = line[strlen(line) - 1] != '\n';
> + if (line[strlen(line) - 1] == '\n')
> + pthread_setspecific(__vlog_line_continuation, (void*) false);
> + else
> + pthread_setspecific(__vlog_line_continuation, (void*) true);
>
> /* append log buffer */
> _igt_log_buffer_append(formatted_line);
> @@ -2758,6 +2781,8 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
> goto out;
> }
>
> + pthread_mutex_lock(&print_mutex);
> +
> /* use stderr for warning messages and above */
> if (level >= IGT_LOG_WARN) {
> file = stderr;
> @@ -2768,13 +2793,18 @@ void igt_vlog(const char *domain, enum igt_log_level level, const char *format,
>
> /* prepend all except information messages with process, domain and log
> * level information */
> - if (level != IGT_LOG_INFO)
> + if (level != IGT_LOG_INFO) {
> fwrite(formatted_line, sizeof(char), strlen(formatted_line),
> file);
> - else
> + } else {
> + fwrite(thread_id, sizeof(char), strlen(thread_id), file);
> fwrite(line, sizeof(char), strlen(line), file);
> + }
> +
> + pthread_mutex_unlock(&print_mutex);
>
> out:
> + free(thread_id);
> free(line);
> }
>
> diff --git a/lib/igt_thread.c b/lib/igt_thread.c
> new file mode 100644
> index 00000000..deab6225
> --- /dev/null
> +++ b/lib/igt_thread.c
> @@ -0,0 +1,39 @@
> +/*
> + * Copyright © 2020 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include <pthread.h>
> +
> +#include "igt_core.h"
> +#include "igt_thread.h"
> +
> +static pthread_key_t __igt_is_main_thread;
> +
> +bool igt_thread_is_main(void)
> +{
> + return pthread_getspecific(__igt_is_main_thread) != NULL;
> +}
> +
> +igt_constructor {
> + pthread_key_create(&__igt_is_main_thread, NULL);
> + pthread_setspecific(__igt_is_main_thread, (void*) 0x1);
> +}
> diff --git a/lib/igt_thread.h b/lib/igt_thread.h
> new file mode 100644
> index 00000000..b16f803f
> --- /dev/null
> +++ b/lib/igt_thread.h
> @@ -0,0 +1,24 @@
> +/*
> + * Copyright © 2020 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +bool igt_thread_is_main(void);
> diff --git a/lib/meson.build b/lib/meson.build
> index 6cf78663..6c71ae3d 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -26,6 +26,7 @@ lib_sources = [
> 'igt_syncobj.c',
> 'igt_sysfs.c',
> 'igt_sysrq.c',
> + 'igt_thread.c',
> 'igt_vec.c',
> 'igt_vgem.c',
> 'igt_x86.c',
> --
> 2.25.4
>
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
prev parent reply other threads:[~2020-06-18 12:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-16 14:14 [igt-dev] [PATCH i-g-t 1/3] lib/core: Print thred:tid with igt_log for non-main threads Arkadiusz Hiler
2020-06-16 14:14 ` [igt-dev] [PATCH i-g-t 2/3] lib/core: Handle asserts in threads Arkadiusz Hiler
2020-06-18 12:59 ` Petri Latvala
2020-06-16 14:14 ` [igt-dev] [PATCH i-g-t 3/3] igt/core: Disallow igt_require/skip in non-main threads Arkadiusz Hiler
2020-06-18 12:59 ` Petri Latvala
2020-06-16 16:55 ` [igt-dev] ✗ GitLab.Pipeline: warning for series starting with [i-g-t,1/3] lib/core: Print thred:tid with igt_log for " Patchwork
2020-06-16 17:06 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2020-06-16 18:25 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2020-06-17 13:52 ` Arkadiusz Hiler
2020-06-17 14:37 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/3] lib/core: Print thred:tid with igt_log for non-main threads (rev2) Patchwork
2020-06-17 16:44 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2020-06-18 12:51 ` Petri Latvala [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200618125139.GJ20883@platvala-desk.ger.corp.intel.com \
--to=petri.latvala@intel.com \
--cc=arkadiusz.hiler@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox