Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Manszewski <christoph.manszewski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
	"Dominik Grzegorzek" <dominik.grzegorzek@intel.com>,
	"Maciej Patelczyk" <maciej.patelczyk@intel.com>,
	"Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>,
	"Pawel Sikora" <pawel.sikora@intel.com>,
	"Andrzej Hajda" <andrzej.hajda@intel.com>,
	"Kolanupaka Naveena" <kolanupaka.naveena@intel.com>,
	"Mika Kuoppala" <mika.kuoppala@intel.com>,
	"Gwan-gyeong Mun" <gwan-gyeong.mun@intel.com>,
	"Karolina Stolarek" <karolina.stolarek@intel.com>,
	"Christoph Manszewski" <christoph.manszewski@intel.com>
Subject: [PATCH 14/66] tests/xe_eudebug: Race discovery against eudebug attach.
Date: Mon, 29 Jul 2024 18:01:07 +0200	[thread overview]
Message-ID: <20240729160159.37036-15-christoph.manszewski@intel.com> (raw)
In-Reply-To: <20240729160159.37036-1-christoph.manszewski@intel.com>

From: Dominik Grzegorzek <dominik.grzegorzek@intel.com>

Validate eu debug resource discovery in a pretty cruel way.
Add subtests:

1) discovery-race - spawns N client proccesses, which create
   N+N*N resources each, then it creates M debugger
   threads competing for an access to the client proccess. After
   successful attach, with probability of 0.5 read and assert
   discovered resources, immediately detach otherwise.

2) discovery-empty[|-clients] - same as 1#, but destroy
   resources in flight (explicetly or by closing the client).
   Expect the last discovery not sending any events.

Currently N = 4, M = 3.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Signed-off-by: Karolina Stolarek <karolina.stolarek@intel.com>
Cc: Christoph Manszewski <christoph.manszewski@intel.com>
---
 tests/intel/xe_eudebug.c | 244 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 244 insertions(+)

diff --git a/tests/intel/xe_eudebug.c b/tests/intel/xe_eudebug.c
index 5a11e7347..147836bd1 100644
--- a/tests/intel/xe_eudebug.c
+++ b/tests/intel/xe_eudebug.c
@@ -246,6 +246,241 @@ static void test_basic_sessions(int fd, unsigned int flags, int count)
 		xe_eudebug_session_destroy(s[i]);
 }
 
+#define RESOURCE_COUNT 16
+#define PRIMARY_THREAD			(1 << 0)
+#define DISCOVERY_CLOSE_CLIENT		(1 << 1)
+#define DISCOVERY_DESTROY_RESOURCES	(1 << 2)
+static void run_discovery_client(struct xe_eudebug_client *c)
+{
+	int fd[RESOURCE_COUNT], i;
+	bool skip_sleep = c->flags & (DISCOVERY_DESTROY_RESOURCES | DISCOVERY_CLOSE_CLIENT);
+
+	srand(getpid());
+
+	for (i = 0; i < RESOURCE_COUNT; i++) {
+		fd[i] = xe_eudebug_client_open_driver(c);
+
+		/*
+		 * Give the debugger a break in event stream after every
+		 * other client, that allows to read discovery and dettach in quiet.
+		 */
+		if (random() % 2 == 0 && !skip_sleep)
+			sleep(1);
+
+		for (int j = 0; j < RESOURCE_COUNT; j++) {
+			uint32_t vm = xe_eudebug_client_vm_create(c, fd[i], 0, 0);
+
+			if (c->flags & DISCOVERY_DESTROY_RESOURCES)
+				xe_eudebug_client_vm_destroy(c, fd[i], vm);
+		}
+
+		if (c->flags & DISCOVERY_CLOSE_CLIENT)
+			xe_eudebug_client_close_driver(c, fd[i]);
+	}
+}
+
+static void *discovery_race_thread(void *data)
+{
+	struct {
+		uint64_t client_handle;
+		int vm_count;
+	} clients[RESOURCE_COUNT];
+	struct xe_eudebug_session *s = data;
+	int expected = RESOURCE_COUNT * (1 + RESOURCE_COUNT);
+	const int tries = 100;
+	bool done = false;
+	int ret = 0;
+
+	for (int try = 0; try < tries && !done; try++) {
+
+		ret = xe_eudebug_debugger_attach(s->d, s->c);
+
+		if (ret == -EBUSY) {
+			usleep(100000);
+			continue;
+		}
+
+		igt_assert_eq(ret, 0);
+
+		if (random() % 2) {
+			struct drm_xe_eudebug_event *e = NULL;
+			int i = -1;
+
+			xe_eudebug_debugger_start_worker(s->d);
+			sleep(1);
+			xe_eudebug_debugger_stop_worker(s->d, 1);
+			igt_debug("Resources discovered: %lu\n", s->d->event_count);
+
+			xe_eudebug_for_each_event(e, s->d->log) {
+				if (e->type == DRM_XE_EUDEBUG_EVENT_OPEN) {
+					struct drm_xe_eudebug_event_client *eo = (void *)e;
+
+					if (i >= 0) {
+						igt_assert_eq(clients[i].vm_count,
+							      RESOURCE_COUNT);
+					}
+
+					igt_assert(++i < RESOURCE_COUNT);
+					clients[i].client_handle = eo->client_handle;
+					clients[i].vm_count = 0;
+				}
+
+				if (e->type == DRM_XE_EUDEBUG_EVENT_VM)
+					clients[i].vm_count++;
+			};
+
+			igt_assert_lte(0, i);
+
+			for (int j = 0; j < i; j++)
+				for (int k = 0; k < i; k++) {
+					if (k == j)
+						continue;
+
+					igt_assert_neq(clients[j].client_handle,
+						       clients[k].client_handle);
+				}
+
+			if (s->d->event_count >= expected)
+				done = true;
+		}
+
+		xe_eudebug_debugger_dettach(s->d);
+		s->d->log->head = 0;
+		s->d->event_count = 0;
+	}
+
+	/* Primary thread must read everything */
+	if (s->flags & PRIMARY_THREAD) {
+		while ((ret = xe_eudebug_debugger_attach(s->d, s->c)) == -EBUSY)
+			usleep(100000);
+
+		igt_assert_eq(ret, 0);
+
+		xe_eudebug_debugger_start_worker(s->d);
+		xe_eudebug_client_wait_done(s->c);
+
+		if (READ_ONCE(s->d->event_count) != expected)
+			sleep(5);
+
+		xe_eudebug_debugger_stop_worker(s->d, 1);
+		xe_eudebug_debugger_dettach(s->d);
+	}
+
+	return NULL;
+}
+
+static void test_race_discovery(int fd, unsigned int flags, int clients)
+{
+	const int debuggers_per_client = 3;
+	int count = clients * debuggers_per_client;
+	struct xe_eudebug_session *sessions, *s;
+	struct xe_eudebug_client *c;
+	pthread_t *threads;
+	int i, j;
+
+	sessions = calloc(count, sizeof(*sessions));
+	threads = calloc(count, sizeof(*threads));
+
+	for (i = 0; i < clients; i++) {
+		c = xe_eudebug_client_create(fd, run_discovery_client, flags, NULL);
+		for (j = 0; j < debuggers_per_client; j++) {
+			s = &sessions[i * debuggers_per_client + j];
+			s->c = c;
+			s->d = xe_eudebug_debugger_create(fd, flags, NULL);
+			s->flags = flags | (!j ? PRIMARY_THREAD : 0);
+		}
+	}
+
+	for (i = 0; i < count; i++) {
+		if (sessions[i].flags & PRIMARY_THREAD)
+			xe_eudebug_client_start(sessions[i].c);
+
+		pthread_create(&threads[i], NULL, discovery_race_thread, &sessions[i]);
+	}
+
+	for (i = 0; i < count; i++)
+		pthread_join(threads[i], NULL);
+
+	for (i = count - 1; i > 0; i--) {
+		if (sessions[i].flags & PRIMARY_THREAD) {
+			igt_assert_eq(sessions[i].c->seqno-1, sessions[i].d->event_count);
+
+			xe_eudebug_event_log_compare(sessions[0].d->log,
+						     sessions[i].d->log, 0);
+
+			xe_eudebug_client_destroy(sessions[i].c);
+		}
+		xe_eudebug_debugger_destroy(sessions[i].d);
+	}
+}
+
+static void *attach_dettach_thread(void *data)
+{
+	struct xe_eudebug_session *s = data;
+	const int tries = 100;
+	int ret = 0;
+
+	for (int try = 0; try < tries; try++) {
+
+		ret = xe_eudebug_debugger_attach(s->d, s->c);
+
+		if (ret == -EBUSY) {
+			usleep(100000);
+			continue;
+		}
+
+		igt_assert_eq(ret, 0);
+
+		if (random() % 2 == 0) {
+			xe_eudebug_debugger_start_worker(s->d);
+			xe_eudebug_debugger_stop_worker(s->d, 1);
+		}
+
+		xe_eudebug_debugger_dettach(s->d);
+		s->d->log->head = 0;
+		s->d->event_count = 0;
+	}
+
+	return NULL;
+}
+
+static void test_empty_discovery(int fd, unsigned int flags, int clients)
+{
+	struct xe_eudebug_session **s;
+	pthread_t *threads;
+	int i, expected = flags & DISCOVERY_CLOSE_CLIENT ? 0 : RESOURCE_COUNT;
+
+	igt_assert(flags & (DISCOVERY_DESTROY_RESOURCES | DISCOVERY_CLOSE_CLIENT));
+
+	s = calloc(clients, sizeof(struct xe_eudebug_session *));
+	threads = calloc(clients, sizeof(*threads));
+
+	for (i = 0; i < clients; i++)
+		s[i] = xe_eudebug_session_create(fd, run_discovery_client, flags, NULL);
+
+	for (i = 0; i < clients; i++) {
+		xe_eudebug_client_start(s[i]->c);
+
+		pthread_create(&threads[i], NULL, attach_dettach_thread, s[i]);
+	}
+
+	for (i = 0; i < clients; i++)
+		pthread_join(threads[i], NULL);
+
+	for (i = 0; i < clients; i++) {
+		xe_eudebug_client_wait_done(s[i]->c);
+		igt_assert_eq(xe_eudebug_debugger_attach(s[i]->d, s[i]->c), 0);
+
+		xe_eudebug_debugger_start_worker(s[i]->d);
+		xe_eudebug_debugger_stop_worker(s[i]->d, 5);
+		xe_eudebug_debugger_dettach(s[i]->d);
+
+		igt_assert_eq(s[i]->d->event_count, expected);
+
+		xe_eudebug_session_destroy(s[i]);
+	}
+}
+
 igt_main
 {
 	int fd;
@@ -272,6 +507,15 @@ igt_main
 	igt_subtest("basic-vms")
 		test_basic_sessions(fd, CREATE_VMS, 1);
 
+	igt_subtest("discovery-race")
+		test_race_discovery(fd, 0, 4);
+
+	igt_subtest("discovery-empty")
+		test_empty_discovery(fd, DISCOVERY_CLOSE_CLIENT, 16);
+
+	igt_subtest("discovery-empty-clients")
+		test_empty_discovery(fd, DISCOVERY_DESTROY_RESOURCES, 16);
+
 	igt_fixture
 		drm_close_driver(fd);
 }
-- 
2.34.1


  parent reply	other threads:[~2024-07-29 16:03 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 16:00 [PATCH 00/66] Test coverage for GPU debug support Christoph Manszewski
2024-07-29 16:00 ` [PATCH 01/66] tests/xe_eudebug: Test eudebug connection Christoph Manszewski
2024-07-30  7:58   ` Zbigniew Kempczyński
2024-07-30  9:42     ` Manszewski, Christoph
2024-07-29 16:00 ` [PATCH 02/66] lib/xe_eudebug: Introduce eu debug testing framework Christoph Manszewski
2024-07-29 16:00 ` [PATCH 03/66] lib/xe_eudebug: Allow client to wait for debugger Christoph Manszewski
2024-07-29 16:00 ` [PATCH 04/66] lib/xe_eudebug: Add exec_queue support Christoph Manszewski
2024-07-29 16:00 ` [PATCH 05/66] lib/xe_eudebug: Add attention events support Christoph Manszewski
2024-07-29 16:00 ` [PATCH 06/66] lib/xe_ioctl: Add wrapper with vm_bind_op extension parameter Christoph Manszewski
2024-07-29 16:01 ` [PATCH 07/66] lib/xe_eudebug: Add support for vm_bind events Christoph Manszewski
2024-07-29 16:01 ` [PATCH 08/66] lib/xe_eudebug: Add metadata support Christoph Manszewski
2024-07-29 16:01 ` [PATCH 09/66] lib/xe_eudebug: Add support for user fence acking Christoph Manszewski
2024-07-29 16:01 ` [PATCH 10/66] lib/xe_eudebug: Add support for dynamic debugger sysfs toggle Christoph Manszewski
2024-07-29 16:01 ` [PATCH 11/66] tests/xe_eudebug: Test open close events Christoph Manszewski
2024-07-29 16:01 ` [PATCH 12/66] tests/xe_eudebug: Exercise read_event ioctl Christoph Manszewski
2024-07-29 16:01 ` [PATCH 13/66] tests/xe_eudebug: Add vm events sanity check Christoph Manszewski
2024-07-29 16:01 ` Christoph Manszewski [this message]
2024-07-29 16:01 ` [PATCH 15/66] tests/xe_eudebug: Add TEST/SUBTEST documentation Christoph Manszewski
2024-07-29 16:01 ` [PATCH 16/66] tests/xe_eudebug: Introduce basic exec_queue testing Christoph Manszewski
2024-07-29 16:01 ` [PATCH 17/66] tests/xe_eudebug: Include exec queues in discovery testing Christoph Manszewski
2024-07-29 16:01 ` [PATCH 18/66] tests/xe_eudebug: Add vm open/pread/pwrite basic tests Christoph Manszewski
2024-07-29 16:01 ` [PATCH 19/66] tests/xe_eudebug: Add basic vm-bind coverage Christoph Manszewski
2024-07-29 16:01 ` [PATCH 20/66] tests/xe_eudebug: Exercise debug metadata events sent to debugger Christoph Manszewski
2024-07-29 16:01 ` [PATCH 21/66] tests/xe_eudebug: Add support for dynamic debugger sysfs toggle Christoph Manszewski
2024-07-29 16:01 ` [PATCH 22/66] tests/xe_eudebug: Add coverage for sysfs debugger toggle Christoph Manszewski
2024-07-29 16:01 ` [PATCH 23/66] lib/xe_eudebug: Allow debugger to wait for client Christoph Manszewski
2024-07-29 16:01 ` [PATCH 24/66] tests/xe_eudebug: Add vm-bind discovery tests Christoph Manszewski
2024-07-29 16:01 ` [PATCH 25/66] tests/xe_eudebug: Add basic-vm-bind-metadata-discovery Christoph Manszewski
2024-07-29 16:01 ` [PATCH 26/66] tests/xe_eudebug: Add basic-vm-access-parameters test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 27/66] lib/xe_eudebug: Add mutex for log events write Christoph Manszewski
2024-07-29 16:01 ` [PATCH 28/66] tests/xe_eudebug: Add basic-client-th test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 29/66] tests/xe_eudebug: Added connect-user test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 30/66] tests/xe_eudebug: Add discovery-race-vmbind subtest Christoph Manszewski
2024-07-29 16:01 ` [PATCH 31/66] tests/xe_eudebug: Add userptr variant of basic-vm-access test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 32/66] tests/xe_eudebug: Add basic-vm-bind-ufence Christoph Manszewski
2024-07-29 16:01 ` [PATCH 33/66] tests/xe_eudebug: Add multigpu scenarios Christoph Manszewski
2024-07-29 16:01 ` [PATCH 34/66] tests/xe_eudebug: Add vm-bind-clear test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 35/66] tests/xe_eudebug: Exercise lseek Christoph Manszewski
2024-07-29 16:01 ` [PATCH 36/66] tests/xe_eudebug: Test multiple bo sizes Christoph Manszewski
2024-07-29 16:01 ` [PATCH 37/66] lib/gpgpu_shader: Extend shader building library Christoph Manszewski
2024-07-29 16:01 ` [PATCH 38/66] tests/xe_exec_sip: Port tests for shaders and sip Christoph Manszewski
2024-07-29 16:01 ` [PATCH 39/66] tests/xe_exec_sip: Check if we reset due to unhandled attention Christoph Manszewski
2024-07-29 16:01 ` [PATCH 40/66] tests/xe_exec_sip: Check usercoredump for attentions Christoph Manszewski
2024-07-29 16:01 ` [PATCH 41/66] tests/xe_exec_sip: Add support for dynamic debugger sysfs toggle Christoph Manszewski
2024-07-29 16:01 ` [PATCH 42/66] tests/xe_exec_sip: Add breakpoint-writesip-twice test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 43/66] tests/xe_exec_sip: Add sanity-after-timeout test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 44/66] tests/xe_exec_sip: Add breakpoint-waitsip-heavy test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 45/66] tests/xe_exec_sip: Add nodebug test cases Christoph Manszewski
2024-07-29 16:01 ` [PATCH 46/66] lib/gpgpu_shader: Add write_on_exception template Christoph Manszewski
2024-07-29 16:01 ` [PATCH 47/66] lib/gpgpu_shader: Add set/clear exception register (cr0.1) helpers Christoph Manszewski
2024-07-29 16:01 ` [PATCH 48/66] lib/intel_batchbuffer: Add helper to get pointer at specified offset Christoph Manszewski
2024-07-29 16:01 ` [PATCH 49/66] lib/gpgpu_shader: Allow enabling illegal opcode exceptions in shader Christoph Manszewski
2024-07-29 16:01 ` [PATCH 50/66] tests/xe_exec_sip: Rework invalid instruction tests Christoph Manszewski
2024-07-29 16:01 ` [PATCH 51/66] lib/intel_batchbuffer: Add support for long-running mode execution Christoph Manszewski
2024-07-29 16:01 ` [PATCH 52/66] tests/xe_eudebug_online: Debug client which runs workloads on EU Christoph Manszewski
2024-07-29 16:01 ` [PATCH 53/66] tests/xe_eudebug_online: Set dynamic breakpoint on interrupt-all Christoph Manszewski
2024-07-29 16:01 ` [PATCH 54/66] tests/xe_eudebug_online: Add support for dynamic debugger sysfs toggle Christoph Manszewski
2024-07-29 16:01 ` [PATCH 55/66] tests/xe_eudebug_online: Add tdctl-parameters test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 56/66] tests/xe_eudebug_online: Add reset-with-attention test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 57/66] lib/xe_eudebug: Expose xe_eudebug_connect Christoph Manszewski
2024-07-29 16:01 ` [PATCH 58/66] tests/xe_eudebug_online: Add interrupt-reconnect test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 59/66] tests/xe_eudebug_online: Add single-step and single-step-one tests Christoph Manszewski
2024-07-29 16:01 ` [PATCH 60/66] tests/xe_eudebug_online: What if user does not set debug mode? Christoph Manszewski
2024-07-29 16:01 ` [PATCH 61/66] tests/xe_eudebug_online: Adds debugger-reopen test Christoph Manszewski
2024-07-29 16:01 ` [PATCH 62/66] tests/xe_eudebug_online: Add caching tests Christoph Manszewski
2024-07-29 16:01 ` [PATCH 63/66] tests/xe_eudebug_online: Add subtests w/o long running mode Christoph Manszewski
2024-07-29 16:01 ` [PATCH 64/66] tests/xe_eudebug_online: Add multisession test cases Christoph Manszewski
2024-07-29 16:01 ` [PATCH 65/66] tests/xe_eudebug_online: Check if eu debugger disables preemption timeout Christoph Manszewski
2024-07-29 16:01 ` [PATCH 66/66] tests/xe_live_ktest: Add xe_eudebug live test Christoph Manszewski
2024-07-29 19:18 ` ✗ Fi.CI.BUILD: failure for Test coverage for GPU debug support Patchwork
2024-07-29 19:21 ` ✗ GitLab.Pipeline: warning " Patchwork

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=20240729160159.37036-15-christoph.manszewski@intel.com \
    --to=christoph.manszewski@intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=dominik.grzegorzek@intel.com \
    --cc=dominik.karol.piatkowski@intel.com \
    --cc=gwan-gyeong.mun@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=karolina.stolarek@intel.com \
    --cc=kolanupaka.naveena@intel.com \
    --cc=maciej.patelczyk@intel.com \
    --cc=mika.kuoppala@intel.com \
    --cc=pawel.sikora@intel.com \
    --cc=zbigniew.kempczynski@intel.com \
    /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