[PATCH 27/66] lib/xe_eudebug: Add mutex for log events write
Christoph Manszewski
christoph.manszewski at intel.com
Mon Jul 29 16:01:20 UTC 2024
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 919dd1d49..41809429d 100644
--- a/lib/xe/xe_eudebug.c
+++ b/lib/xe/xe_eudebug.c
@@ -830,6 +830,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;
}
@@ -842,6 +843,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);
}
@@ -851,7 +853,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)
{
@@ -862,6 +864,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;
@@ -870,6 +873,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