Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Move Linux ww_mutex code into a .c file where it belongs.
details: https://anonhg.NetBSD.org/src/rev/df0b58195af1
branches: trunk
changeset: 335482:df0b58195af1
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Jan 08 23:35:47 2015 +0000
description:
Move Linux ww_mutex code into a .c file where it belongs.
diffstat:
sys/external/bsd/drm2/include/linux/ww_mutex.h | 695 +-----------------------
sys/external/bsd/drm2/linux/files.drmkms_linux | 3 +-
sys/external/bsd/drm2/linux/linux_ww_mutex.c | 707 +++++++++++++++++++++++++
sys/modules/drmkms_linux/Makefile | 3 +-
4 files changed, 745 insertions(+), 663 deletions(-)
diffs (truncated from 1471 to 300 lines):
diff -r 83f1d092637b -r df0b58195af1 sys/external/bsd/drm2/include/linux/ww_mutex.h
--- a/sys/external/bsd/drm2/include/linux/ww_mutex.h Thu Jan 08 22:27:17 2015 +0000
+++ b/sys/external/bsd/drm2/include/linux/ww_mutex.h Thu Jan 08 23:35:47 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ww_mutex.h,v 1.9 2015/01/01 01:15:42 mrg Exp $ */
+/* $NetBSD: ww_mutex.h,v 1.10 2015/01/08 23:35:47 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,10 +32,11 @@
#ifndef _ASM_WW_MUTEX_H_
#define _ASM_WW_MUTEX_H_
+#include <sys/types.h>
+#include <sys/condvar.h>
+#include <sys/mutex.h>
#include <sys/rbtree.h>
-#include <linux/mutex.h>
-
struct ww_class {
volatile uint64_t wwc_ticket;
};
@@ -54,74 +55,6 @@
struct rb_node wwx_rb_node;
};
-static inline int
-ww_acquire_ctx_compare(void *cookie __unused, const void *va, const void *vb)
-{
- const struct ww_acquire_ctx *const ctx_a = va;
- const struct ww_acquire_ctx *const ctx_b = vb;
-
- if (ctx_a->wwx_ticket < ctx_b->wwx_ticket)
- return -1;
- if (ctx_a->wwx_ticket > ctx_b->wwx_ticket)
- return -1;
- return 0;
-}
-
-static inline int
-ww_acquire_ctx_compare_key(void *cookie __unused, const void *vn,
- const void *vk)
-{
- const struct ww_acquire_ctx *const ctx = vn;
- const uint64_t *const ticketp = vk, ticket = *ticketp;
-
- if (ctx->wwx_ticket < ticket)
- return -1;
- if (ctx->wwx_ticket > ticket)
- return -1;
- return 0;
-}
-
-static const rb_tree_ops_t ww_acquire_ctx_rb_ops = {
- .rbto_compare_nodes = &ww_acquire_ctx_compare,
- .rbto_compare_key = &ww_acquire_ctx_compare_key,
- .rbto_node_offset = offsetof(struct ww_acquire_ctx, wwx_rb_node),
- .rbto_context = NULL,
-};
-
-static inline void
-ww_acquire_init(struct ww_acquire_ctx *ctx, struct ww_class *class)
-{
-
- ctx->wwx_class = class;
- ctx->wwx_owner = curlwp;
- ctx->wwx_ticket = atomic_inc_64_nv(&class->wwc_ticket);
- ctx->wwx_acquired = 0;
- ctx->wwx_acquire_done = false;
-}
-
-static inline void
-ww_acquire_done(struct ww_acquire_ctx *ctx)
-{
-
- KASSERTMSG((ctx->wwx_owner == curlwp),
- "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
-
- ctx->wwx_acquire_done = true;
-}
-
-static inline void
-ww_acquire_fini(struct ww_acquire_ctx *ctx)
-{
-
- KASSERTMSG((ctx->wwx_owner == curlwp),
- "ctx %p owned by %p, not self (%p)", ctx, ctx->wwx_owner, curlwp);
- KASSERTMSG((ctx->wwx_acquired == 0), "ctx %p still holds %u locks",
- ctx, ctx->wwx_acquired);
-
- ctx->wwx_acquired = ~0U; /* Fail if called again. */
- ctx->wwx_owner = NULL;
-}
-
struct ww_mutex {
kmutex_t wwm_lock;
enum ww_mutex_state {
@@ -139,601 +72,41 @@
kcondvar_t wwm_cv;
};
-static inline void
-ww_mutex_init(struct ww_mutex *mutex, struct ww_class *class)
-{
+/* XXX Make the nm output a little more greppable... */
+#define ww_acquire_done linux_ww_acquire_done
+#define ww_acquire_fini linux_ww_acquire_fini
+#define ww_acquire_init linux_ww_acquire_init
+#define ww_mutex_destroy linux_ww_mutex_destroy
+#define ww_mutex_init linux_ww_mutex_init
+#define ww_mutex_is_locked linux_ww_mutex_is_locked
+#define ww_mutex_lock linux_ww_mutex_lock
+#define ww_mutex_lock_interruptible linux_ww_mutex_lock_interruptible
+#define ww_mutex_lock_slow linux_ww_mutex_lock_slow
+#define ww_mutex_lock_slow_interruptible linux_ww_mutex_lock_slow_interruptible
+#define ww_mutex_trylock linux_ww_mutex_trylock
+#define ww_mutex_unlock linux_ww_mutex_unlock
- /*
- * XXX Apparently Linux takes these with spin locks held. That
- * strikes me as a bad idea, but so it is...
- */
- mutex_init(&mutex->wwm_lock, MUTEX_DEFAULT, IPL_VM);
- mutex->wwm_state = WW_UNLOCKED;
- mutex->wwm_class = class;
- rb_tree_init(&mutex->wwm_waiters, &ww_acquire_ctx_rb_ops);
- cv_init(&mutex->wwm_cv, "linuxwwm");
-}
+void ww_acquire_init(struct ww_acquire_ctx *, struct ww_class *);
+void ww_acquire_done(struct ww_acquire_ctx *);
+void ww_acquire_fini(struct ww_acquire_ctx *);
-static inline void
-ww_mutex_destroy(struct ww_mutex *mutex)
-{
-
- cv_destroy(&mutex->wwm_cv);
-#if 0
- rb_tree_destroy(&mutex->wwm_waiters, &ww_acquire_ctx_rb_ops);
-#endif
- KASSERT(mutex->wwm_state == WW_UNLOCKED);
- mutex_destroy(&mutex->wwm_lock);
-}
+void ww_mutex_init(struct ww_mutex *, struct ww_class *);
+void ww_mutex_destroy(struct ww_mutex *);
/*
- * XXX WARNING: This returns true if it is locked by ANYONE. Does not
- * mean `Do I hold this lock?' (answering which really requires an
- * acquire context).
+ * WARNING: ww_mutex_is_locked returns true if it is locked by ANYONE.
+ * Does NOT mean `Do I hold this lock?' (answering which really
+ * requires an acquire context).
*/
-static inline bool
-ww_mutex_is_locked(struct ww_mutex *mutex)
-{
- int locked;
-
- mutex_enter(&mutex->wwm_lock);
- switch (mutex->wwm_state) {
- case WW_UNLOCKED:
- locked = false;
- break;
- case WW_OWNED:
- case WW_CTX:
- case WW_WANTOWN:
- locked = true;
- break;
- default:
- panic("wait/wound mutex %p in bad state: %d", mutex,
- (int)mutex->wwm_state);
- }
- mutex_exit(&mutex->wwm_lock);
-
- return locked;
-}
-
-static inline void
-ww_mutex_state_wait(struct ww_mutex *mutex, enum ww_mutex_state state)
-{
-
- KASSERT(mutex->wwm_state == state);
- do cv_wait(&mutex->wwm_cv, &mutex->wwm_lock);
- while (mutex->wwm_state == state);
-}
-
-static inline int
-ww_mutex_state_wait_sig(struct ww_mutex *mutex, enum ww_mutex_state state)
-{
- int ret;
-
- KASSERT(mutex->wwm_state == state);
- do {
- /* XXX errno NetBSD->Linux */
- ret = -cv_wait_sig(&mutex->wwm_cv, &mutex->wwm_lock);
- if (ret)
- break;
- } while (mutex->wwm_state == state);
-
- return ret;
-}
-
-static inline void
-ww_mutex_lock_wait(struct ww_mutex *mutex, struct ww_acquire_ctx *ctx)
-{
- struct ww_acquire_ctx *collision __diagused;
-
- KASSERT(mutex_owned(&mutex->wwm_lock));
-
- KASSERT((mutex->wwm_state == WW_CTX) ||
- (mutex->wwm_state == WW_WANTOWN));
- KASSERT(mutex->wwm_u.ctx != ctx);
- KASSERTMSG((ctx->wwx_class == mutex->wwm_u.ctx->wwx_class),
- "ww mutex class mismatch: %p != %p",
- ctx->wwx_class, mutex->wwm_u.ctx->wwx_class);
- KASSERTMSG((mutex->wwm_u.ctx->wwx_ticket != ctx->wwx_ticket),
- "ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
- ctx->wwx_ticket, ctx,
- mutex->wwm_u.ctx->wwx_ticket, mutex->wwm_u.ctx);
-
- collision = rb_tree_insert_node(&mutex->wwm_waiters, ctx);
- KASSERTMSG((collision == ctx),
- "ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
- ctx->wwx_ticket, ctx, collision->wwx_ticket, collision);
-
- do cv_wait(&mutex->wwm_cv, &mutex->wwm_lock);
- while (!(((mutex->wwm_state == WW_CTX) ||
- (mutex->wwm_state == WW_WANTOWN)) &&
- (mutex->wwm_u.ctx == ctx)));
-
- rb_tree_remove_node(&mutex->wwm_waiters, ctx);
-}
-
-static inline int
-ww_mutex_lock_wait_sig(struct ww_mutex *mutex, struct ww_acquire_ctx *ctx)
-{
- struct ww_acquire_ctx *collision __diagused;
- int ret;
-
- KASSERT(mutex_owned(&mutex->wwm_lock));
-
- KASSERT((mutex->wwm_state == WW_CTX) ||
- (mutex->wwm_state == WW_WANTOWN));
- KASSERT(mutex->wwm_u.ctx != ctx);
- KASSERTMSG((ctx->wwx_class == mutex->wwm_u.ctx->wwx_class),
- "ww mutex class mismatch: %p != %p",
- ctx->wwx_class, mutex->wwm_u.ctx->wwx_class);
- KASSERTMSG((mutex->wwm_u.ctx->wwx_ticket != ctx->wwx_ticket),
- "ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
- ctx->wwx_ticket, ctx,
- mutex->wwm_u.ctx->wwx_ticket, mutex->wwm_u.ctx);
-
- collision = rb_tree_insert_node(&mutex->wwm_waiters, ctx);
- KASSERTMSG((collision == ctx),
- "ticket number reused: %"PRId64" (%p) %"PRId64" (%p)",
- ctx->wwx_ticket, ctx, collision->wwx_ticket, collision);
-
- do {
- /* XXX errno NetBSD->Linux */
- ret = -cv_wait_sig(&mutex->wwm_cv, &mutex->wwm_lock);
- if (ret)
- goto out;
- } while (!(((mutex->wwm_state == WW_CTX) ||
- (mutex->wwm_state == WW_WANTOWN)) &&
- (mutex->wwm_u.ctx == ctx)));
-
-out: rb_tree_remove_node(&mutex->wwm_waiters, ctx);
- return ret;
-}
-
-static inline void
-ww_mutex_lock_noctx(struct ww_mutex *mutex)
-{
-
- mutex_enter(&mutex->wwm_lock);
-retry: switch (mutex->wwm_state) {
- case WW_UNLOCKED:
- mutex->wwm_state = WW_OWNED;
- mutex->wwm_u.owner = curlwp;
- break;
- case WW_OWNED:
- KASSERTMSG((mutex->wwm_u.owner != curlwp),
- "locking %p against myself: %p", mutex, curlwp);
- ww_mutex_state_wait(mutex, WW_OWNED);
- goto retry;
- case WW_CTX:
- KASSERT(mutex->wwm_u.ctx != NULL);
- mutex->wwm_state = WW_WANTOWN;
- /* FALLTHROUGH */
- case WW_WANTOWN:
- KASSERTMSG((mutex->wwm_u.ctx->wwx_owner != curlwp),
- "locking %p against myself: %p", mutex, curlwp);
- ww_mutex_state_wait(mutex, WW_WANTOWN);
- goto retry;
- default:
- panic("wait/wound mutex %p in bad state: %d",
- mutex, (int)mutex->wwm_state);
- }
Home |
Main Index |
Thread Index |
Old Index