[PATCH i-g-t v2 27/66] lib/xe_eudebug: Add mutex for log events write

Piatkowski, Dominik Karol dominik.karol.piatkowski at intel.com
Thu Aug 1 12:43:16 UTC 2024


Reviewed-by: Dominik Karol Piątkowski <dominik.karol.piatkowski at intel.com>

> -----Original Message-----
> From: Manszewski, Christoph <christoph.manszewski at intel.com>
> Sent: Tuesday, July 30, 2024 1:45 PM
> To: igt-dev at lists.freedesktop.org
> Cc: Kempczynski, Zbigniew <zbigniew.kempczynski at intel.com>; Kamil
> Konieczny <kamil.konieczny at linux.intel.com>; Grzegorzek, Dominik
> <dominik.grzegorzek at intel.com>; Patelczyk, Maciej
> <maciej.patelczyk at intel.com>; Piatkowski, Dominik Karol
> <dominik.karol.piatkowski at intel.com>; Sikora, Pawel
> <pawel.sikora at intel.com>; Hajda, Andrzej <andrzej.hajda at intel.com>;
> Kolanupaka Naveena <kolanupaka.naveena at intel.com>; Kuoppala, Mika
> <mika.kuoppala at intel.com>; Mun, Gwan-gyeong <gwan-
> gyeong.mun at intel.com>
> Subject: [PATCH i-g-t v2 27/66] lib/xe_eudebug: Add mutex for log events
> write
> 
> From: Pawel Sikora <pawel.sikora at intel.com>
> 
> Make 'xe_eudebug_event_log_write' to be thread-safe.
> 
> Signed-off-by: Pawel Sikora <pawel.sikora at intel.com>
> Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
> ---
>  lib/xe/xe_eudebug.c | 6 +++++-
>  lib/xe/xe_eudebug.h | 1 +
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/xe/xe_eudebug.c b/lib/xe/xe_eudebug.c index
> ed1e382c7..254a7261a 100644
> --- a/lib/xe/xe_eudebug.c
> +++ b/lib/xe/xe_eudebug.c
> @@ -836,6 +836,7 @@ struct xe_eudebug_event_log
> *xe_eudebug_event_log_create(const char *name, unsig
>  	igt_assert(l->log);
>  	l->max_size = max_size;
>  	strncpy(l->name, name, sizeof(l->name) - 1);
> +	pthread_mutex_init(&l->lock, NULL);
> 
>  	return l;
>  }
> @@ -848,6 +849,7 @@ struct xe_eudebug_event_log
> *xe_eudebug_event_log_create(const char *name, unsig
>   */
>  void xe_eudebug_event_log_destroy(struct xe_eudebug_event_log *l)  {
> +	pthread_mutex_destroy(&l->lock);
>  	free(l->log);
>  	free(l);
>  }
> @@ -857,7 +859,7 @@ void xe_eudebug_event_log_destroy(struct
> xe_eudebug_event_log *l)
>   * @l: event log pointer
>   * @e: event to be written to event log
>   *
> - * Writes event @e to the event log.
> + * Writes event @e to the event log, thread-safe.
>   */
>  void xe_eudebug_event_log_write(struct xe_eudebug_event_log *l, struct
> drm_xe_eudebug_event *e)  { @@ -868,6 +870,7 @@ void
> xe_eudebug_event_log_write(struct xe_eudebug_event_log *l, struct
> drm_xe_eu
>  	 */
>  	igt_assert_lt(e->seqno, 10 * 1000 * 1000);
> 
> +	pthread_mutex_lock(&l->lock);
>  	igt_assert_lt(l->head + e->len, l->max_size);
>  	memcpy(l->log + l->head, e, e->len);
>  	l->head += e->len;
> @@ -876,6 +879,7 @@ void xe_eudebug_event_log_write(struct
> xe_eudebug_event_log *l, struct drm_xe_eu
>  	igt_info("%s: wrote %u bytes to eventlog, free %u bytes\n",
>  		 l->name, e->len, l->max_size - l->head);  #endif
> +	pthread_mutex_unlock(&l->lock);
>  }
> 
>  /**
> diff --git a/lib/xe/xe_eudebug.h b/lib/xe/xe_eudebug.h index
> 81c33417f..a499cc977 100644
> --- a/lib/xe/xe_eudebug.h
> +++ b/lib/xe/xe_eudebug.h
> @@ -14,6 +14,7 @@ struct xe_eudebug_event_log {
>  	unsigned int head;
>  	unsigned int max_size;
>  	char name[80];
> +	pthread_mutex_t lock;
>  };
> 
>  struct xe_eudebug_debugger {
> --
> 2.34.1



More information about the igt-dev mailing list