[PATCH] lib/amdgpu: improve pci_unplug test

Zhang, Jesse(Jie) Jesse.Zhang at amd.com
Thu Jan 9 04:13:53 UTC 2025


[AMD Official Use Only - AMD Internal Distribution Only]

This patch is good for me, and
Reviewed-by: "Jesse.zhang at amd.com"

-----Original Message-----
From: vitaly.prosyak at amd.com <vitaly.prosyak at amd.com>
Sent: Thursday, January 9, 2025 11:32 AM
To: igt-dev at lists.freedesktop.org
Cc: Prosyak, Vitaly <Vitaly.Prosyak at amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang at amd.com>; Koenig, Christian <Christian.Koenig at amd.com>; Deucher, Alexander <Alexander.Deucher at amd.com>
Subject: [PATCH] lib/amdgpu: improve pci_unplug test

From: Vitaly Prosyak <vitaly.prosyak at amd.com>

Replace the 1-second sleep with a semaphore for synchronization, using wait and post operations from the worker and main threads. This change results in cleaner code and ensures precise timing, so PCI unplug event is triggered as expected during job submissions.

Cc: Jesse Zhang  <jesse.zhang at amd.com>
Cc: Christian Koenig <christian.koenig at amd.com>
Cc: Alexander Deucher <alexander.deucher at amd.com>

Signed-off-by: Vitaly Prosyak <vitaly.prosyak at amd.com>
---
 lib/amdgpu/amd_pci_unplug.c | 10 +++++++---  lib/amdgpu/amd_pci_unplug.h |  3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/amdgpu/amd_pci_unplug.c b/lib/amdgpu/amd_pci_unplug.c index 107e1cbbd..5155c9474 100644
--- a/lib/amdgpu/amd_pci_unplug.c
+++ b/lib/amdgpu/amd_pci_unplug.c
@@ -238,6 +238,8 @@ amdgpu_nop_cs(void *handle)
        ibs_request.ibs = &ib_info;
        ibs_request.resources = bo_list;

+       sem_post(&unplug->semaphore);
+
        while (unplug->do_cs)
                amdgpu_cs_submit(context, 0, &ibs_request, 1);

@@ -263,11 +265,12 @@ amdgpu_create_cs_thread(struct amd_pci_unplug *unplug)

        unplug->do_cs = true;

-       r = pthread_create(thread, NULL, &amdgpu_nop_cs, unplug);
+       r = sem_init(&unplug->semaphore, 0, 0);
        igt_assert_eq(r, 0);

-       /* Give thread enough time to start*/
-       usleep(1000000);
+       r = pthread_create(thread, NULL, &amdgpu_nop_cs, unplug);
+       igt_assert_eq(r, 0);
+       sem_wait(&unplug->semaphore);
        return thread;
 }

@@ -277,6 +280,7 @@ amdgpu_wait_cs_thread(struct amd_pci_unplug *unplug, pthread_t *thread)
        unplug->do_cs = false;

        pthread_join(*thread, NULL);
+       sem_destroy(&unplug->semaphore);
        free(thread);
 }

diff --git a/lib/amdgpu/amd_pci_unplug.h b/lib/amdgpu/amd_pci_unplug.h index 35d4dce3a..3799a6ec9 100644
--- a/lib/amdgpu/amd_pci_unplug.h
+++ b/lib/amdgpu/amd_pci_unplug.h
@@ -24,6 +24,8 @@
 #ifndef AMD_PCI_UNPLUG_H
 #define AMD_PCI_UNPLUG_H

+#include <semaphore.h>
+
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
 #include "amd_ip_blocks.h"
@@ -42,6 +44,7 @@ struct amd_pci_unplug {
        amdgpu_device_handle device_handle;
        amdgpu_device_handle device_handle2;
        volatile bool do_cs;
+       sem_t           semaphore;
 };

 void
--
2.34.1



More information about the igt-dev mailing list