aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian König2015-04-30 07:13:28 -0500
committerAlex Deucher2015-08-05 12:47:49 -0500
commitc68d58aa14b7f737812a35f92af3caf315f20d8a (patch)
tree39d31c30c16bb7599584a537dfa2f1064261abb9 /amdgpu/amdgpu_device.c
parent6dc2eaf2cc8428d11498a57bbe72cdf0df4a3306 (diff)
downloadexternal-libdrm-c68d58aa14b7f737812a35f92af3caf315f20d8a.tar.gz
external-libdrm-c68d58aa14b7f737812a35f92af3caf315f20d8a.tar.xz
external-libdrm-c68d58aa14b7f737812a35f92af3caf315f20d8a.zip
amdgpu: compare the primary device names instead
Instead of taking a look at the device major/minor we just compare the primary device name to figure out if two fds are pointing to the same device. Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Christian König <christian.koenig@amd.com>
Diffstat (limited to 'amdgpu/amdgpu_device.c')
-rw-r--r--amdgpu/amdgpu_device.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index c610fd38..b50ce26a 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -42,7 +42,6 @@
42 42
43#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x))) 43#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
44#define UINT_TO_PTR(x) ((void *)((intptr_t)(x))) 44#define UINT_TO_PTR(x) ((void *)((intptr_t)(x)))
45#define RENDERNODE_MINOR_MASK 0xff7f
46 45
47pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER; 46pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
48static struct util_hash_table *fd_tab; 47static struct util_hash_table *fd_tab;
@@ -60,30 +59,40 @@ static int handle_compare(void *key1, void *key2)
60static unsigned fd_hash(void *key) 59static unsigned fd_hash(void *key)
61{ 60{
62 int fd = PTR_TO_UINT(key); 61 int fd = PTR_TO_UINT(key);
63 struct stat stat; 62 char *name = drmGetPrimaryDeviceNameFromFd(fd);
64 fstat(fd, &stat); 63 unsigned result = 0;
64 char *c;
65 65
66 if (!S_ISCHR(stat.st_mode)) 66 if (name == NULL)
67 return stat.st_dev ^ stat.st_ino; 67 return 0;
68 else 68
69 return stat.st_dev ^ (stat.st_rdev & RENDERNODE_MINOR_MASK); 69 for (c = name; *c; ++c)
70 result += *c;
71
72 free(name);
73
74 return result;
70} 75}
71 76
72static int fd_compare(void *key1, void *key2) 77static int fd_compare(void *key1, void *key2)
73{ 78{
74 int fd1 = PTR_TO_UINT(key1); 79 int fd1 = PTR_TO_UINT(key1);
75 int fd2 = PTR_TO_UINT(key2); 80 int fd2 = PTR_TO_UINT(key2);
76 struct stat stat1, stat2; 81 char *name1 = drmGetPrimaryDeviceNameFromFd(fd1);
77 fstat(fd1, &stat1); 82 char *name2 = drmGetPrimaryDeviceNameFromFd(fd2);
78 fstat(fd2, &stat2); 83 int result;
79 84
80 if (!S_ISCHR(stat1.st_mode) || !S_ISCHR(stat2.st_mode)) 85 if (name1 == NULL || name2 == NULL) {
81 return stat1.st_dev != stat2.st_dev || 86 free(name1);
82 stat1.st_ino != stat2.st_ino; 87 free(name2);
83 else 88 return 0;
84 return major(stat1.st_rdev) != major(stat2.st_rdev) || 89 }
85 (minor(stat1.st_rdev) & RENDERNODE_MINOR_MASK) != 90
86 (minor(stat2.st_rdev) & RENDERNODE_MINOR_MASK); 91 result = strcmp(name1, name2);
92 free(name1);
93 free(name2);
94
95 return result;
87} 96}
88 97
89/** 98/**