[CRIU] [PATCH 17/22] compel: Move in lock engine
Cyrill Gorcunov
gorcunov at openvz.org
Wed Oct 19 12:21:32 PDT 2016
We need locking for parasite engine so move in
atomic types and futex locking. The CRIU refer
into approrpiate uapi where needed.
Again we can easily "grep -r -n "include <compel\/" criu/"
if one day we decide to move out generic types.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
compel/Makefile | 12 ++
.../aarch64/src/lib/include/compel}/asm/atomic.h | 6 +-
.../aarch64/src/lib/include/compel/asm/cmpxchg.h | 4 +
.../arch/arm/src/lib/include/compel}/asm/atomic.h | 8 +-
.../arch/arm/src/lib/include/compel/asm/cmpxchg.h | 4 +
.../ppc64/src/lib/include/compel}/asm/atomic.h | 8 +-
.../ppc64/src/lib/include/compel}/asm/cmpxchg.h | 6 +-
.../arch/x86/src/lib/include/compel}/asm/atomic.h | 8 +-
.../arch/x86/src/lib/include/compel}/asm/cmpxchg.h | 16 +-
compel/include/uapi/compel/lock.h | 161 +++++++++++++++++++++
criu/cr-restore.c | 2 +-
criu/files-reg.c | 3 +-
criu/include/lock.h | 154 +-------------------
criu/stats.c | 2 +-
14 files changed, 212 insertions(+), 182 deletions(-)
rename {criu/arch/aarch64/include => compel/arch/aarch64/src/lib/include/compel}/asm/atomic.h (94%)
create mode 100644 compel/arch/aarch64/src/lib/include/compel/asm/cmpxchg.h
rename {criu/arch/arm/include => compel/arch/arm/src/lib/include/compel}/asm/atomic.h (94%)
create mode 100644 compel/arch/arm/src/lib/include/compel/asm/cmpxchg.h
rename {criu/arch/ppc64/include => compel/arch/ppc64/src/lib/include/compel}/asm/atomic.h (93%)
rename {criu/arch/ppc64/include => compel/arch/ppc64/src/lib/include/compel}/asm/cmpxchg.h (94%)
rename {criu/arch/x86/include => compel/arch/x86/src/lib/include/compel}/asm/atomic.h (90%)
rename {criu/arch/x86/include => compel/arch/x86/src/lib/include/compel}/asm/cmpxchg.h (88%)
create mode 100644 compel/include/uapi/compel/lock.h
diff --git a/compel/Makefile b/compel/Makefile
index a0aa0b5b47aa..bab15489deff 100644
--- a/compel/Makefile
+++ b/compel/Makefile
@@ -59,6 +59,18 @@ $(obj)/include/uapi/compel/asm/types.h: $(obj)/arch/$(ARCH)/src/lib/include/comp
cleanup-y += $(obj)/include/uapi/compel/asm/types.h
headers-y += $(obj)/include/uapi/compel/asm/types.h
+$(obj)/include/uapi/compel/asm/atomic.h: $(obj)/arch/$(ARCH)/src/lib/include/compel/asm/atomic.h
+ $(call msg-gen, $@)
+ $(Q) cp $^ $@
+cleanup-y += $(obj)/include/uapi/compel/asm/atomic.h
+headers-y += $(obj)/include/uapi/compel/asm/atomic.h
+
+$(obj)/include/uapi/compel/asm/cmpxchg.h: $(obj)/arch/$(ARCH)/src/lib/include/compel/asm/cmpxchg.h
+ $(call msg-gen, $@)
+ $(Q) cp $^ $@
+cleanup-y += $(obj)/include/uapi/compel/asm/cmpxchg.h
+headers-y += $(obj)/include/uapi/compel/asm/cmpxchg.h
+
lib-y += src/lib/log.o
host-lib-y += src/lib/log.o
lib-y += src/lib/pack.o
diff --git a/criu/arch/aarch64/include/asm/atomic.h b/compel/arch/aarch64/src/lib/include/compel/asm/atomic.h
similarity index 94%
rename from criu/arch/aarch64/include/asm/atomic.h
rename to compel/arch/aarch64/src/lib/include/compel/asm/atomic.h
index 0e1c04f5a714..f788587d824d 100644
--- a/criu/arch/aarch64/include/asm/atomic.h
+++ b/compel/arch/aarch64/src/lib/include/compel/asm/atomic.h
@@ -1,5 +1,5 @@
-#ifndef __CR_ATOMIC_H__
-#define __CR_ATOMIC_H__
+#ifndef UAPI_COMPEL_ASM_ATOMIC_H__
+#define UAPI_COMPEL_ASM_ATOMIC_H__
typedef struct {
int counter;
@@ -95,4 +95,4 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
return oldval;
}
-#endif /* __CR_ATOMIC_H__ */
+#endif /* UAPI_COMPEL_ASM_ATOMIC_H__ */
diff --git a/compel/arch/aarch64/src/lib/include/compel/asm/cmpxchg.h b/compel/arch/aarch64/src/lib/include/compel/asm/cmpxchg.h
new file mode 100644
index 000000000000..d3569668381c
--- /dev/null
+++ b/compel/arch/aarch64/src/lib/include/compel/asm/cmpxchg.h
@@ -0,0 +1,4 @@
+#ifndef UAPI_COMPEL_ASM_CMPXCHG_H__
+#define UAPI_COMPEL_ASM_CMPXCHG_H__
+
+#endif /* UAPI_COMPEL_ASM_CMPXCHG_H__ */
diff --git a/criu/arch/arm/include/asm/atomic.h b/compel/arch/arm/src/lib/include/compel/asm/atomic.h
similarity index 94%
rename from criu/arch/arm/include/asm/atomic.h
rename to compel/arch/arm/src/lib/include/compel/asm/atomic.h
index cd0df377245c..f8a8ecdd456d 100644
--- a/criu/arch/arm/include/asm/atomic.h
+++ b/compel/arch/arm/src/lib/include/compel/asm/atomic.h
@@ -1,7 +1,7 @@
-#ifndef __CR_ATOMIC_H__
-#define __CR_ATOMIC_H__
+#ifndef UAPI_COMPEL_ASM_ATOMIC_H__
+#define UAPI_COMPEL_ASM_ATOMIC_H__
-#include "asm/processor.h"
+#include <compel/asm/processor.h>
typedef struct {
int counter;
@@ -128,4 +128,4 @@ static inline int atomic_dec(atomic_t *v) { return atomic_sub_return(1, v) + 1;
#define atomic_inc_return(v) (atomic_add_return(1, v))
-#endif /* __CR_ATOMIC_H__ */
+#endif /* UAPI_COMPEL_ASM_ATOMIC_H__ */
diff --git a/compel/arch/arm/src/lib/include/compel/asm/cmpxchg.h b/compel/arch/arm/src/lib/include/compel/asm/cmpxchg.h
new file mode 100644
index 000000000000..d3569668381c
--- /dev/null
+++ b/compel/arch/arm/src/lib/include/compel/asm/cmpxchg.h
@@ -0,0 +1,4 @@
+#ifndef UAPI_COMPEL_ASM_CMPXCHG_H__
+#define UAPI_COMPEL_ASM_CMPXCHG_H__
+
+#endif /* UAPI_COMPEL_ASM_CMPXCHG_H__ */
diff --git a/criu/arch/ppc64/include/asm/atomic.h b/compel/arch/ppc64/src/lib/include/compel/asm/atomic.h
similarity index 93%
rename from criu/arch/ppc64/include/asm/atomic.h
rename to compel/arch/ppc64/src/lib/include/compel/asm/atomic.h
index 4fa33b1c7005..434dbe6c69bb 100644
--- a/criu/arch/ppc64/include/asm/atomic.h
+++ b/compel/arch/ppc64/src/lib/include/compel/asm/atomic.h
@@ -1,5 +1,5 @@
-#ifndef __CR_ATOMIC_H__
-#define __CR_ATOMIC_H__
+#ifndef UAPI_COMPEL_ASM_ATOMIC_H__
+#define UAPI_COMPEL_ASM_ATOMIC_H__
/*
* PowerPC atomic operations
@@ -11,7 +11,7 @@ typedef struct {
int counter;
} atomic_t;
-#include "asm/cmpxchg.h"
+#include "compel/asm/cmpxchg.h"
#define PPC_ATOMIC_ENTRY_BARRIER "lwsync \n"
#define PPC_ATOMIC_EXIT_BARRIER "sync \n"
@@ -109,4 +109,4 @@ static __inline__ void atomic_dec(atomic_t *v)
#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
-#endif /* __CR_ATOMIC_H__ */
+#endif /* UAPI_COMPEL_ASM_ATOMIC_H__ */
diff --git a/criu/arch/ppc64/include/asm/cmpxchg.h b/compel/arch/ppc64/src/lib/include/compel/asm/cmpxchg.h
similarity index 94%
rename from criu/arch/ppc64/include/asm/cmpxchg.h
rename to compel/arch/ppc64/src/lib/include/compel/asm/cmpxchg.h
index b93fbdef06c7..9819f3cd6019 100644
--- a/criu/arch/ppc64/include/asm/cmpxchg.h
+++ b/compel/arch/ppc64/src/lib/include/compel/asm/cmpxchg.h
@@ -1,5 +1,5 @@
-#ifndef __CR_CMPXCHG_H__
-#define __CR_CMPXCHG_H__
+#ifndef UAPI_COMPEL_ASM_CMPXCHG_H__
+#define UAPI_COMPEL_ASM_CMPXCHG_H__
/*
* Copied from kernel header file arch/powerpc/include/asm/cmpxchg.h
@@ -93,4 +93,4 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
(unsigned long)_n_, sizeof(*(ptr))); \
})
-#endif /* __CR_CMPXCHG_H__ */
+#endif /* UAPI_COMPEL_ASM_CMPXCHG_H__ */
diff --git a/criu/arch/x86/include/asm/atomic.h b/compel/arch/x86/src/lib/include/compel/asm/atomic.h
similarity index 90%
rename from criu/arch/x86/include/asm/atomic.h
rename to compel/arch/x86/src/lib/include/compel/asm/atomic.h
index d447b65cb4c6..1d2b1f720d01 100644
--- a/criu/arch/x86/include/asm/atomic.h
+++ b/compel/arch/x86/src/lib/include/compel/asm/atomic.h
@@ -1,7 +1,7 @@
-#ifndef __CR_ATOMIC_H__
-#define __CR_ATOMIC_H__
+#ifndef UAPI_COMPEL_ASM_ATOMIC_H__
+#define UAPI_COMPEL_ASM_ATOMIC_H__
-#include "asm/cmpxchg.h"
+#include <compel/asm/cmpxchg.h>
#define LOCK_PREFIX "\n\tlock; "
@@ -75,4 +75,4 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
return cmpxchg(&v->counter, old, new);
}
-#endif /* __CR_ATOMIC_H__ */
+#endif /* UAPI_COMPEL_ASM_ATOMIC_H__ */
diff --git a/criu/arch/x86/include/asm/cmpxchg.h b/compel/arch/x86/src/lib/include/compel/asm/cmpxchg.h
similarity index 88%
rename from criu/arch/x86/include/asm/cmpxchg.h
rename to compel/arch/x86/src/lib/include/compel/asm/cmpxchg.h
index 600d0a7fff84..9fc8a5881a1e 100644
--- a/criu/arch/x86/include/asm/cmpxchg.h
+++ b/compel/arch/x86/src/lib/include/compel/asm/cmpxchg.h
@@ -1,7 +1,7 @@
-#ifndef __CR_CMPXCHG_H__
-#define __CR_CMPXCHG_H__
+#ifndef UAPI_COMPEL_ASM_CMPXCHG_H__
+#define UAPI_COMPEL_ASM_CMPXCHG_H__
-#include "asm/int.h"
+#include <stdint.h>
#define __X86_CASE_B 1
#define __X86_CASE_W 2
@@ -59,7 +59,7 @@
switch (size) { \
case __X86_CASE_B: \
{ \
- volatile u8 *__ptr = (volatile u8 *)(ptr); \
+ volatile uint8_t *__ptr = (volatile uint8_t *)(ptr); \
asm volatile(lock "cmpxchgb %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "q" (__new), "0" (__old) \
@@ -68,7 +68,7 @@
} \
case __X86_CASE_W: \
{ \
- volatile u16 *__ptr = (volatile u16 *)(ptr); \
+ volatile uint16_t *__ptr = (volatile uint16_t *)(ptr); \
asm volatile(lock "cmpxchgw %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
@@ -77,7 +77,7 @@
} \
case __X86_CASE_L: \
{ \
- volatile u32 *__ptr = (volatile u32 *)(ptr); \
+ volatile uint32_t *__ptr = (volatile uint32_t *)(ptr); \
asm volatile(lock "cmpxchgl %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
@@ -86,7 +86,7 @@
} \
case __X86_CASE_Q: \
{ \
- volatile u64 *__ptr = (volatile u64 *)(ptr); \
+ volatile uint64_t *__ptr = (volatile uint64_t *)(ptr); \
asm volatile(lock "cmpxchgq %2,%1" \
: "=a" (__ret), "+m" (*__ptr) \
: "r" (__new), "0" (__old) \
@@ -102,4 +102,4 @@
#define cmpxchg(ptr, old, new) \
__cmpxchg(ptr, old, new, sizeof(*(ptr)))
-#endif /* __CR_CMPXCHG_H__ */
+#endif /* UAPI_COMPEL_ASM_CMPXCHG_H__ */
diff --git a/compel/include/uapi/compel/lock.h b/compel/include/uapi/compel/lock.h
new file mode 100644
index 000000000000..2f2558b832ff
--- /dev/null
+++ b/compel/include/uapi/compel/lock.h
@@ -0,0 +1,161 @@
+#ifndef UAPI_COMPEL_LOCK_H__
+#define UAPI_COMPEL_LOCK_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <linux/futex.h>
+#include <sys/time.h>
+#include <limits.h>
+#include <errno.h>
+
+#include <compel/asm/atomic.h>
+
+#define COMPEL_LOCK_BUG_ON(condition) \
+ do { \
+ if ((condition)) \
+ *(volatile unsigned long *)NULL = 0xdead0000 + __LINE__; \
+ } while (0)
+#define COMPEL_LOCK_BUG() COMPEL_LOCK_BUG_ON(true)
+
+#ifdef CR_NOGLIBC
+# include <compel/plugins/std/syscall.h>
+#else
+# include <unistd.h>
+# include <sys/syscall.h>
+static inline long sys_futex(void *addr1, int op, int val1,
+ struct timespec *timeout, void *addr2, int val3)
+{
+ int rc = syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
+ if (rc == -1) rc = -errno;
+ return rc;
+}
+#endif
+
+typedef struct {
+ atomic_t raw;
+} futex_t;
+
+#define FUTEX_ABORT_FLAG (0x80000000)
+#define FUTEX_ABORT_RAW (-1U)
+
+/* Get current futex @f value */
+static inline uint32_t futex_get(futex_t *f)
+{
+ return atomic_read(&f->raw);
+}
+
+/* Set futex @f value to @v */
+static inline void futex_set(futex_t *f, uint32_t v)
+{
+ atomic_set(&f->raw, (int)v);
+}
+
+#define futex_init(f) futex_set(f, 0)
+
+/* Wait on futex @__f value @__v become in condition @__c */
+#define futex_wait_if_cond(__f, __v, __cond) \
+ do { \
+ int ret; \
+ uint32_t tmp; \
+ \
+ while (1) { \
+ struct timespec to = {.tv_sec = 120}; \
+ tmp = futex_get(__f); \
+ if ((tmp & FUTEX_ABORT_FLAG) || \
+ (tmp __cond (__v))) \
+ break; \
+ ret = sys_futex((uint32_t *)&(__f)->raw.counter, FUTEX_WAIT, \
+ tmp, &to, NULL, 0); \
+ if (ret == -ETIMEDOUT) \
+ continue; \
+ if (ret == -EINTR || ret == -EWOULDBLOCK) \
+ continue; \
+ if (ret < 0) \
+ COMPEL_LOCK_BUG(); \
+ } \
+ } while (0)
+
+/* Set futex @f to @v and wake up all waiters */
+static inline void futex_set_and_wake(futex_t *f, uint32_t v)
+{
+ atomic_set(&f->raw, (int)v);
+ COMPEL_LOCK_BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+}
+
+/* Mark futex @f as wait abort needed and wake up all waiters */
+static inline void futex_abort_and_wake(futex_t *f)
+{
+ COMPEL_LOCK_BUG_ON(!(FUTEX_ABORT_RAW & FUTEX_ABORT_FLAG));
+ futex_set_and_wake(f, FUTEX_ABORT_RAW);
+}
+
+/* Decrement futex @f value and wake up all waiters */
+static inline void futex_dec_and_wake(futex_t *f)
+{
+ atomic_dec(&f->raw);
+ COMPEL_LOCK_BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+}
+
+/* Increment futex @f value and wake up all waiters */
+static inline void futex_inc_and_wake(futex_t *f)
+{
+ atomic_inc(&f->raw);
+ COMPEL_LOCK_BUG_ON(sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
+}
+
+/* Plain increment futex @f value */
+static inline void futex_inc(futex_t *f) { atomic_inc(&f->raw); }
+
+/* Plain decrement futex @f value */
+static inline void futex_dec(futex_t *f) { atomic_dec(&f->raw); }
+
+/* Wait until futex @f value become @v */
+#define futex_wait_until(f, v) futex_wait_if_cond(f, v, ==)
+
+/* Wait while futex @f value is greater than @v */
+#define futex_wait_while_gt(f, v) futex_wait_if_cond(f, v, <=)
+
+/* Wait while futex @f value is less than @v */
+#define futex_wait_while_lt(f, v) futex_wait_if_cond(f, v, >=)
+
+/* Wait while futex @f value is equal to @v */
+#define futex_wait_while_eq(f, v) futex_wait_if_cond(f, v, !=)
+
+/* Wait while futex @f value is @v */
+static inline void futex_wait_while(futex_t *f, uint32_t v)
+{
+ while ((uint32_t)atomic_read(&f->raw) == v) {
+ int ret = sys_futex((uint32_t *)&f->raw.counter, FUTEX_WAIT, v, NULL, NULL, 0);
+ COMPEL_LOCK_BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
+ }
+}
+
+typedef struct {
+ atomic_t raw;
+} mutex_t;
+
+static inline void mutex_init(mutex_t *m)
+{
+ uint32_t c = 0;
+ atomic_set(&m->raw, (int)c);
+}
+
+static inline void mutex_lock(mutex_t *m)
+{
+ uint32_t c;
+ int ret;
+
+ while ((c = (uint32_t)atomic_inc_return(&m->raw)) != 1) {
+ ret = sys_futex((uint32_t *)&m->raw.counter, FUTEX_WAIT, c, NULL, NULL, 0);
+ COMPEL_LOCK_BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
+ }
+}
+
+static inline void mutex_unlock(mutex_t *m)
+{
+ uint32_t c = 0;
+ atomic_set(&m->raw, (int)c);
+ COMPEL_LOCK_BUG_ON(sys_futex((uint32_t *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
+}
+
+#endif /* UAPI_COMPEL_LOCK_H__ */
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c527a4af204c..4a9a58f41df1 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -26,6 +26,7 @@
#include <compel/plugins/std/syscall-codes.h>
#include <compel/asm/bitops.h>
+#include <compel/asm/atomic.h>
#include "ptrace.h"
#include "compiler.h"
@@ -94,7 +95,6 @@
#include "images/siginfo.pb-c.h"
#include "asm/restore.h"
-#include "asm/atomic.h"
#include "asm/parasite-syscall.h"
#include "cr-errno.h"
diff --git a/criu/files-reg.c b/criu/files-reg.c
index 7817fb4a7940..9dbff8632f20 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -15,6 +15,8 @@
#define SILLYNAME_PREF ".nfs"
#define SILLYNAME_SUFF_LEN (((unsigned)sizeof(u64) << 1) + ((unsigned)sizeof(unsigned int) << 1))
+#include <compel/asm/atomic.h>
+
#include "cr_options.h"
#include "imgset.h"
#include "file-ids.h"
@@ -23,7 +25,6 @@
#include "list.h"
#include "rst-malloc.h"
#include "fs-magic.h"
-#include "asm/atomic.h"
#include "namespaces.h"
#include "proc_parse.h"
#include "pstree.h"
diff --git a/criu/include/lock.h b/criu/include/lock.h
index a1cf08cc8de4..95c041d219aa 100644
--- a/criu/include/lock.h
+++ b/criu/include/lock.h
@@ -1,158 +1,6 @@
#ifndef __CR_LOCK_H__
#define __CR_LOCK_H__
-#include <linux/futex.h>
-#include <sys/time.h>
-#include <limits.h>
-#include <errno.h>
-
-#include "asm/types.h"
-#include "asm/atomic.h"
-#include "bug.h"
-
-#ifdef CR_NOGLIBC
-# include <compel/plugins/std/syscall-codes.h>
-#else
-# include <unistd.h>
-# include <sys/syscall.h>
-static inline long sys_futex(void *addr1, int op, int val1,
- struct timespec *timeout, void *addr2, int val3)
-{
- int rc = syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
- if (rc == -1) rc = -errno;
- return rc;
-}
-#endif
-
-typedef struct {
- atomic_t raw;
-} futex_t;
-
-#define FUTEX_ABORT_FLAG (0x80000000)
-#define FUTEX_ABORT_RAW (-1U)
-
-/* Get current futex @f value */
-static inline u32 futex_get(futex_t *f)
-{
- return atomic_read(&f->raw);
-}
-
-/* Set futex @f value to @v */
-static inline void futex_set(futex_t *f, u32 v)
-{
- atomic_set(&f->raw, (int)v);
-}
-
-#define futex_init(f) futex_set(f, 0)
-
-/* Wait on futex @__f value @__v become in condition @__c */
-#define futex_wait_if_cond(__f, __v, __cond) \
- do { \
- int ret; \
- u32 tmp; \
- \
- while (1) { \
- struct timespec to = {.tv_sec = 120}; \
- tmp = futex_get(__f); \
- if ((tmp & FUTEX_ABORT_FLAG) || \
- (tmp __cond (__v))) \
- break; \
- ret = sys_futex((u32 *)&(__f)->raw.counter, FUTEX_WAIT,\
- tmp, &to, NULL, 0); \
- if (ret == -ETIMEDOUT) { \
- pr_warn("blocked for more than 120 seconds\n"); \
- continue; \
- } \
- if (ret == -EINTR || ret == -EWOULDBLOCK) \
- continue; \
- if (ret < 0) { \
- pr_err("futex() returned an unexpected error: %d\n", ret); \
- BUG(); \
- } \
- } \
- } while (0)
-
-/* Set futex @f to @v and wake up all waiters */
-static inline void futex_set_and_wake(futex_t *f, u32 v)
-{
- atomic_set(&f->raw, (int)v);
- BUG_ON(sys_futex((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
-}
-
-/* Mark futex @f as wait abort needed and wake up all waiters */
-static inline void futex_abort_and_wake(futex_t *f)
-{
- BUILD_BUG_ON(!(FUTEX_ABORT_RAW & FUTEX_ABORT_FLAG));
- futex_set_and_wake(f, FUTEX_ABORT_RAW);
-}
-
-/* Decrement futex @f value and wake up all waiters */
-static inline void futex_dec_and_wake(futex_t *f)
-{
- atomic_dec(&f->raw);
- BUG_ON(sys_futex((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
-}
-
-/* Increment futex @f value and wake up all waiters */
-static inline void futex_inc_and_wake(futex_t *f)
-{
- atomic_inc(&f->raw);
- BUG_ON(sys_futex((u32 *)&f->raw.counter, FUTEX_WAKE, INT_MAX, NULL, NULL, 0) < 0);
-}
-
-/* Plain increment futex @f value */
-static inline void futex_inc(futex_t *f) { atomic_inc(&f->raw); }
-
-/* Plain decrement futex @f value */
-static inline void futex_dec(futex_t *f) { atomic_dec(&f->raw); }
-
-/* Wait until futex @f value become @v */
-#define futex_wait_until(f, v) futex_wait_if_cond(f, v, ==)
-
-/* Wait while futex @f value is greater than @v */
-#define futex_wait_while_gt(f, v) futex_wait_if_cond(f, v, <=)
-
-/* Wait while futex @f value is less than @v */
-#define futex_wait_while_lt(f, v) futex_wait_if_cond(f, v, >=)
-
-/* Wait while futex @f value is equal to @v */
-#define futex_wait_while_eq(f, v) futex_wait_if_cond(f, v, !=)
-
-/* Wait while futex @f value is @v */
-static inline void futex_wait_while(futex_t *f, u32 v)
-{
- while ((u32)atomic_read(&f->raw) == v) {
- int ret = sys_futex((u32 *)&f->raw.counter, FUTEX_WAIT, v, NULL, NULL, 0);
- BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
- }
-}
-
-typedef struct {
- atomic_t raw;
-} mutex_t;
-
-static inline void mutex_init(mutex_t *m)
-{
- u32 c = 0;
- atomic_set(&m->raw, (int)c);
-}
-
-static inline void mutex_lock(mutex_t *m)
-{
- u32 c;
- int ret;
-
- while ((c = (u32)atomic_inc_return(&m->raw)) != 1) {
- ret = sys_futex((u32 *)&m->raw.counter, FUTEX_WAIT, c, NULL, NULL, 0);
- BUG_ON(ret < 0 && ret != -EWOULDBLOCK);
- }
-}
-
-static inline void mutex_unlock(mutex_t *m)
-{
- u32 c = 0;
- atomic_set(&m->raw, (int)c);
- BUG_ON(sys_futex((u32 *)&m->raw.counter, FUTEX_WAKE, 1, NULL, NULL, 0) < 0);
-}
+#include <compel/lock.h>
#endif /* __CR_LOCK_H__ */
diff --git a/criu/stats.c b/criu/stats.c
index 661c2e080da6..46257d859477 100644
--- a/criu/stats.c
+++ b/criu/stats.c
@@ -1,7 +1,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
-#include "asm/atomic.h"
+#include <compel/asm/atomic.h>
#include "cr_options.h"
#include "rst-malloc.h"
#include "protobuf.h"
--
2.7.4
More information about the CRIU
mailing list