Module: xenomai-forge Branch: next Commit: 47396bb30d3bb233bf1292c0e8729f773ee11c74 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=47396bb30d3bb233bf1292c0e8729f773ee11c74
Author: Philippe Gerum <r...@xenomai.org> Date: Thu Sep 11 10:26:50 2014 +0200 cobalt/registry, cobalt/synch: prepare for embedding more special bits in handles --- include/cobalt/kernel/registry.h | 1 + include/cobalt/kernel/synch.h | 8 -------- include/cobalt/uapi/kernel/synch.h | 26 ++++++++++++++++---------- include/cobalt/uapi/kernel/types.h | 30 ++++++++++++++++++++++++------ kernel/cobalt/registry.c | 6 ++++++ kernel/cobalt/synch.c | 11 ++++++----- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h index 383754c..25c8f48 100644 --- a/include/cobalt/kernel/registry.h +++ b/include/cobalt/kernel/registry.h @@ -138,6 +138,7 @@ static inline struct xnobject *xnregistry_validate(xnhandle_t handle) * unexported carries a NULL objaddr, so we have to check this * as well. */ + handle = xnhandle_get_index(handle); if (likely(handle && handle < CONFIG_XENO_OPT_REGISTRY_NRSLOTS)) { object = ®istry_obj_slots[handle]; return object->objaddr ? object : NULL; diff --git a/include/cobalt/kernel/synch.h b/include/cobalt/kernel/synch.h index d4df940..98d7a43 100644 --- a/include/cobalt/kernel/synch.h +++ b/include/cobalt/kernel/synch.h @@ -30,8 +30,6 @@ */ #define XNSYNCH_CLAIMED 0x10 /* Claimed by other thread(s) w/ PIP */ -#define XNSYNCH_FLCLAIM XN_HANDLE_SPARE3 /* Corresponding bit in fast lock */ - /* Spare flags usable by upper interfaces */ #define XNSYNCH_SPARE0 0x01000000 #define XNSYNCH_SPARE1 0x02000000 @@ -103,12 +101,6 @@ static inline struct xnthread *xnsynch_owner(struct xnsynch *synch) #define xnsynch_owner_check(synch, thread) \ xnsynch_fast_owner_check((synch)->fastlock, thread->handle) -#define xnsynch_fast_is_claimed(fastlock) \ - xnhandle_test_spare(fastlock, XNSYNCH_FLCLAIM) -#define xnsynch_fast_set_claimed(fastlock, enable) \ - (((fastlock) & ~XNSYNCH_FLCLAIM) | ((enable) ? XNSYNCH_FLCLAIM : 0)) -#define xnsynch_fast_mask_claimed(fastlock) ((fastlock & ~XNSYNCH_FLCLAIM)) - #if XENO_DEBUG(USER) void xnsynch_detect_relaxed_owner(struct xnsynch *synch, diff --git a/include/cobalt/uapi/kernel/synch.h b/include/cobalt/uapi/kernel/synch.h index 263213a..2a8c40c 100644 --- a/include/cobalt/uapi/kernel/synch.h +++ b/include/cobalt/uapi/kernel/synch.h @@ -29,20 +29,26 @@ #define XNSYNCH_DREORD 0x4 #define XNSYNCH_OWNER 0x8 -#define XNSYNCH_FLCLAIM XN_HANDLE_SPARE3 /* Corresponding bit in fast lock */ +/* Fast lock API */ +static inline int xnsynch_fast_is_claimed(xnhandle_t handle) +{ + return (handle & XNSYNCH_FLCLAIM) != 0; +} -#define xnhandle_mask_spare(handle) ((handle) & ~XN_HANDLE_SPARE_MASK) -#define xnhandle_test_spare(handle, bits) (!!((handle) & (bits))) -#define xnhandle_set_spare(handle, bits) \ - do { (handle) |= (bits); } while (0) -#define xnhandle_clear_spare(handle, bits) \ - do { (handle) &= ~(bits); } while (0) +static inline xnhandle_t xnsynch_fast_claimed(xnhandle_t handle) +{ + return handle | XNSYNCH_FLCLAIM; +} + +static inline xnhandle_t xnsynch_fast_not_claimed(xnhandle_t handle) +{ + return handle & ~XNSYNCH_FLCLAIM; +} -/* Fast lock API */ static inline int xnsynch_fast_owner_check(atomic_t *fastlock, xnhandle_t ownerh) { - return (xnhandle_mask_spare(atomic_read(fastlock)) == ownerh) ? + return (xnhandle_get_id(atomic_read(fastlock)) == ownerh) ? 0 : -EPERM; } @@ -53,7 +59,7 @@ int xnsynch_fast_acquire(atomic_t *fastlock, xnhandle_t new_ownerh) h = atomic_cmpxchg(fastlock, XN_NO_HANDLE, new_ownerh); if (h != XN_NO_HANDLE) { - if (xnhandle_mask_spare(h) == new_ownerh) + if (xnhandle_get_id(h) == new_ownerh) return -EBUSY; return -EAGAIN; diff --git a/include/cobalt/uapi/kernel/types.h b/include/cobalt/uapi/kernel/types.h index 0c86a62..4454536 100644 --- a/include/cobalt/uapi/kernel/types.h +++ b/include/cobalt/uapi/kernel/types.h @@ -27,12 +27,30 @@ typedef __s64 xnsticks_t; typedef __u32 xnhandle_t; -#define XN_NO_HANDLE ((xnhandle_t)0) +#define XN_NO_HANDLE ((xnhandle_t)0) +#define XN_HANDLE_INDEX_MASK ((xnhandle_t)0xf0000000) -#define XN_HANDLE_SPARE0 ((xnhandle_t)0x10000000) -#define XN_HANDLE_SPARE1 ((xnhandle_t)0x20000000) -#define XN_HANDLE_SPARE2 ((xnhandle_t)0x40000000) -#define XN_HANDLE_SPARE3 ((xnhandle_t)0x80000000) -#define XN_HANDLE_SPARE_MASK ((xnhandle_t)0xf0000000) +/* 3 spare special bits remaining. */ +#define XNSYNCH_FLCLAIM ((xnhandle_t)0x80000000) + +#define XN_HANDLE_TRANSIENT_MASK XNSYNCH_FLCLAIM + +/* + * Strip all special bits from the handle, only retaining the object + * index value in the registry. + */ +static inline xnhandle_t xnhandle_get_index(xnhandle_t handle) +{ + return handle & ~XN_HANDLE_INDEX_MASK; +} + +/* + * Strip the transient bits from the handle, only retaining the fixed + * part making the identifier. + */ +static inline xnhandle_t xnhandle_get_id(xnhandle_t handle) +{ + return handle & ~XN_HANDLE_TRANSIENT_MASK; +} #endif /* !_COBALT_UAPI_KERNEL_TYPES_H */ diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c index 6643865..30cf814 100644 --- a/kernel/cobalt/registry.c +++ b/kernel/cobalt/registry.c @@ -734,6 +734,12 @@ EXPORT_SYMBOL_GPL(xnregistry_enter); * the specified amount of time. * * @coretags{primary-only, might-switch} + * + * @note xnregistry_bind() only returns the index portion of a handle, + * which might include other fixed bits to be complete + * (e.g. XNSYNCH_PSHARED). The caller is responsible for completing + * the handle returned with those bits if applicable, depending on the + * context. */ int xnregistry_bind(const char *key, xnticks_t timeout, int timeout_mode, xnhandle_t *phandle) diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c index 89b9757..e6de7ca 100644 --- a/kernel/cobalt/synch.c +++ b/kernel/cobalt/synch.c @@ -375,7 +375,7 @@ redo: do { old = atomic_cmpxchg(lockp, fastlock, - xnsynch_fast_set_claimed(fastlock, 1)); + xnsynch_fast_claimed(fastlock)); if (likely(old == fastlock)) break; test_no_owner: @@ -387,7 +387,7 @@ redo: fastlock = old; } while (!xnsynch_fast_is_claimed(fastlock)); - owner = xnthread_lookup(xnsynch_fast_mask_claimed(fastlock)); + owner = xnthread_lookup(fastlock); if (owner == NULL) { /* * The handle is broken, therefore pretend that the @@ -464,7 +464,7 @@ block: thread->res_count++; if (xnsynch_pended_p(synch)) - threadh = xnsynch_fast_set_claimed(threadh, 1); + threadh = xnsynch_fast_claimed(threadh); /* Set new ownership for this mutex. */ atomic_set(lockp, threadh); @@ -534,8 +534,9 @@ static struct xnthread *transfer_ownership(struct xnsynch *synch, if (synch->status & XNSYNCH_CLAIMED) clear_boost(synch, lastowner); - nextownerh = xnsynch_fast_set_claimed(nextowner->handle, - xnsynch_pended_p(synch)); + nextownerh = xnsynch_pended_p(synch) ? + xnsynch_fast_claimed(nextowner->handle) : + xnsynch_fast_not_claimed(nextowner->handle); atomic_set(lockp, nextownerh); xnlock_put_irqrestore(&nklock, s); _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git