summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Skidanov <Alexey.Skidanov@amd.com>2014-12-08 17:05:56 +0200
committerOded Gabbay <oded.gabbay@amd.com>2014-12-29 10:13:32 +0200
commit0ecaa965238131e0d91a356d81d757fb002e7924 (patch)
treee19f82c9342adb372bbce950276a257d6eb7e224
parent4a16f41259f83b7b16e1fa3a41538588ccef18d1 (diff)
Add exclusive trace access
Signed-off-by: Alexey Skidanov <Alexey.Skidanov@amd.com>
-rw-r--r--src/openclose.c13
-rw-r--r--src/perfctr.c24
2 files changed, 35 insertions, 2 deletions
diff --git a/src/openclose.c b/src/openclose.c
index dad0cb9..8290d00 100644
--- a/src/openclose.c
+++ b/src/openclose.c
@@ -33,6 +33,8 @@
#include "fmm.h"
static const char kfd_device_name[] = "/dev/kfd";
+static const char tmp_file[] = "/var/lock/.amd_hsa_thunk_lock";
+int amd_hsa_thunk_lock_fd = 0;
HSAKMT_STATUS
HSAKMTAPI
@@ -59,6 +61,11 @@ hsaKmtOpenKFD(void)
{
result = HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED;
}
+
+ amd_hsa_thunk_lock_fd = open(tmp_file,
+ O_CREAT | //create the file if it's not present.
+ O_RDWR, //only need write access for the internal locking semantics.
+ S_IRUSR | S_IWUSR); //permissions on the file, 600 here.
}
else
{
@@ -84,6 +91,12 @@ hsaKmtCloseKFD(void)
if (--kfd_open_count == 0)
{
close(kfd_fd);
+
+ if (amd_hsa_thunk_lock_fd > 0) {
+ close(amd_hsa_thunk_lock_fd);
+ unlink(tmp_file);
+ }
+
}
result = HSAKMT_STATUS_SUCCESS;
diff --git a/src/perfctr.c b/src/perfctr.c
index e0d6ad0..64ab168 100644
--- a/src/perfctr.c
+++ b/src/perfctr.c
@@ -27,6 +27,7 @@
#include "libhsakmt.h"
#include "pmc_table.h"
#include "linux/kfd_ioctl.h"
+#include <unistd.h>
#define BITS_PER_BYTE CHAR_BIT
@@ -43,6 +44,8 @@ struct perf_trace {
enum perf_trace_state state;
};
+extern int amd_hsa_thunk_lock_fd;
+
static HsaCounterProperties *counter_props[MAX_NODES] = {NULL};
static int blockid2uuid(enum perf_block_id block_id, HSA_UUID *uuid)
@@ -248,7 +251,15 @@ hsaKmtPmcAcquireTraceAccess(
if (trace->magic4cc != HSA_PERF_MAGIC4CC)
return HSAKMT_STATUS_INVALID_HANDLE;
- return HSAKMT_STATUS_SUCCESS;
+ if (amd_hsa_thunk_lock_fd > 0) {
+ if (lockf( amd_hsa_thunk_lock_fd, F_TLOCK, 0 ) != 0)
+ return HSAKMT_STATUS_ERROR;
+ else
+ return HSAKMT_STATUS_SUCCESS;
+ }
+ else {
+ return HSAKMT_STATUS_ERROR;
+ }
}
@@ -274,7 +285,16 @@ hsaKmtPmcReleaseTraceAccess(
if (trace->magic4cc != HSA_PERF_MAGIC4CC)
return HSAKMT_STATUS_INVALID_HANDLE;
- return HSAKMT_STATUS_SUCCESS;
+ if (amd_hsa_thunk_lock_fd > 0) {
+ if (lockf( amd_hsa_thunk_lock_fd, F_ULOCK, 0 ) != 0)
+ return HSAKMT_STATUS_ERROR;
+ else
+ return HSAKMT_STATUS_SUCCESS;
+ }
+ else {
+ return HSAKMT_STATUS_ERROR;
+ }
+
}