summaryrefslogtreecommitdiffstats
path: root/src/intel
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2017-10-16 18:06:49 +1100
committerTimothy Arceri <[email protected]>2017-11-09 12:07:48 +1100
commitf98a2768ca0609fb81a0ee8f30ac1e70269334c4 (patch)
tree5bb443fcdd32efee59643decae5795d6dac6bd97 /src/intel
parent6a72eba755fea15a0d97abb913a6315d9d32e274 (diff)
mesa: Add new fast mtx_t mutex type for basic use cases
While modern pthread mutexes are very fast, they still incur a call to an external DSO and overhead of the generality and features of pthread mutexes. Most mutexes in mesa only needs lock/unlock, and the idea here is that we can inline the atomic operation and make the fast case just two intructions. Mutexes are subtle and finicky to implement, so we carefully copy the implementation from Ulrich Dreppers well-written and well-reviewed paper: "Futexes Are Tricky" http://www.akkadia.org/drepper/futex.pdf We implement "mutex3", which gives us a mutex that has no syscalls on uncontended lock or unlock. Further, the uncontended case boils down to a cmpxchg and an untaken branch and the uncontended unlock is just a locked decr and an untaken branch. We use __builtin_expect() to indicate that contention is unlikely so that gcc will put the contention code out of the main code flow. A fast mutex only supports lock/unlock, can't be recursive or used with condition variables. We keep the pthread mutex implementation around as for the few places where we use condition variables or recursive locking. For platforms or compilers where futex and atomics aren't available, simple_mtx_t falls back to the pthread mutex. The pthread mutex lock/unlock overhead shows up on benchmarks for CPU bound applications. Most CPU bound cases are helped and some of our internal bind_buffer_object heavy benchmarks gain up to 10%. Signed-off-by: Kristian Høgsberg <[email protected]> Signed-off-by: Timothy Arceri <[email protected]> Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/intel')
-rw-r--r--src/intel/vulkan/anv_allocator.c24
1 files changed, 1 insertions, 23 deletions
diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 27eedb53aa7..4d8eea641a6 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -21,20 +21,17 @@
* IN THE SOFTWARE.
*/
-#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <assert.h>
-#include <linux/futex.h>
#include <linux/memfd.h>
-#include <sys/time.h>
#include <sys/mman.h>
-#include <sys/syscall.h>
#include "anv_private.h"
#include "util/hash_table.h"
+#include "util/simple_mtx.h"
#ifdef HAVE_VALGRIND
#define VG_NOACCESS_READ(__ptr) ({ \
@@ -112,25 +109,6 @@ struct anv_mmap_cleanup {
#define ANV_MMAP_CLEANUP_INIT ((struct anv_mmap_cleanup){0})
-static inline long
-sys_futex(void *addr1, int op, int val1,
- struct timespec *timeout, void *addr2, int val3)
-{
- return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
-}
-
-static inline int
-futex_wake(uint32_t *addr, int count)
-{
- return sys_futex(addr, FUTEX_WAKE, count, NULL, NULL, 0);
-}
-
-static inline int
-futex_wait(uint32_t *addr, int32_t value)
-{
- return sys_futex(addr, FUTEX_WAIT, value, NULL, NULL, 0);
-}
-
static inline int
memfd_create(const char *name, unsigned int flags)
{