diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-05-06 21:59:01 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-05-06 21:59:01 +0200 |
commit | f781e8ead80409cd61256d8cb8464538e4801661 (patch) | |
tree | 2ca64273b1b5762b31d85c5d1934c8a77e8081c6 | |
parent | fa85aba08e005ba948a52b7bc1ac815366c6c84f (diff) |
refresh the new lockless refcount patches
4 files changed, 61 insertions, 35 deletions
diff --git a/debian/patches/0001-include-add-lock-less-reference-counting-primitives.patch b/debian/patches/0001-include-add-lock-less-reference-counting-primitives.patch index 426813a7..0ee3897e 100644 --- a/debian/patches/0001-include-add-lock-less-reference-counting-primitives.patch +++ b/debian/patches/0001-include-add-lock-less-reference-counting-primitives.patch @@ -1,20 +1,20 @@ -From 2fdfbfae579a84a00bcca2f4888e716ef0bb7578 Mon Sep 17 00:00:00 2001 +From 6c60761119510bd019c2214eb80fd7fd244e29cd Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 6 May 2014 19:52:04 +0200 Subject: [PATCH 1/4] include: add lock-less reference counting primitives * include/refcount.h: New file. --- - include/refcount.h | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 132 insertions(+) + include/refcount.h | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 147 insertions(+) create mode 100644 include/refcount.h diff --git a/include/refcount.h b/include/refcount.h new file mode 100644 -index 0000000..6e20342 +index 0000000..b90cc5b --- /dev/null +++ b/include/refcount.h -@@ -0,0 +1,132 @@ +@@ -0,0 +1,147 @@ +/* Lock-less reference counting primitives + + Copyright (C) 2014 Free Software Foundation, Inc. @@ -47,36 +47,40 @@ index 0000000..6e20342 +typedef uint32_t refcount_t; + +/* Initialize REF with REFERENCES. */ -+extern inline void ++static inline void +refcount_init (refcount_t *ref, uint32_t references) +{ + *ref = references; +} + +/* Increment REF. Return the result of the operation. */ -+extern inline uint32_t ++static inline uint32_t +refcount_ref (refcount_t *ref) +{ + return __atomic_add_fetch (ref, 1, __ATOMIC_RELAXED); +} + +/* Decrement REF. Return the result of the operation. */ -+extern inline uint32_t ++static inline uint32_t +refcount_deref (refcount_t *ref) +{ + return __atomic_sub_fetch (ref, 1, __ATOMIC_RELAXED); +} + +/* Return REF. */ -+extern inline uint32_t ++static inline uint32_t +refcount_references (refcount_t *ref) +{ + return __atomic_load_n (ref, __ATOMIC_RELAXED); +} ++ ++/* Reference counting with weak references. */ + -+ ++/* An opaque type. You must not access these values directly. */ +typedef uint64_t refcounts_t; + ++/* Instead, the functions manipulating refcounts_t values write the ++ results into this kind of objects. */ +struct references { + uint32_t hard; + uint32_t weak; @@ -87,14 +91,17 @@ index 0000000..6e20342 + refcounts_t rc; +}; + -+extern inline void ++/* Initialize REF with HARD and WEAK references. */ ++static inline void +refcounts_init (refcounts_t *ref, uint32_t hard, uint32_t weak) +{ + ((union _references *) ref)->refs = + (struct references) { .hard = hard, .weak = weak }; +} + -+extern inline void ++/* Increment the hard reference count of REF. If RESULT is not NULL, ++ the result of the operation is written there. */ ++static inline void +refcounts_ref (refcounts_t *ref, struct references *result) +{ + const union _references op = { .refs = { .hard = 1 } }; @@ -103,7 +110,9 @@ index 0000000..6e20342 + ((union _references *) result)->rc = r; +} + -+extern inline void ++/* Decrement the hard reference count of REF. If RESULT is not NULL, ++ the result of the operation is written there. */ ++static inline void +refcounts_deref (refcounts_t *ref, struct references *result) +{ + const union _references op = { .refs = { .hard = 1 } }; @@ -112,7 +121,9 @@ index 0000000..6e20342 + ((union _references *) result)->rc = r; +} + -+extern inline void ++/* Increment the weak reference count of REF. If RESULT is not NULL, ++ the result of the operation is written there. */ ++static inline void +refcounts_ref_weak (refcounts_t *ref, struct references *result) +{ + const union _references op = { .refs = { .weak = 1 } }; @@ -121,7 +132,9 @@ index 0000000..6e20342 + ((union _references *) result)->rc = r; +} + -+extern inline void ++/* Decrement the weak reference count of REF. If RESULT is not NULL, ++ the result of the operation is written there. */ ++static inline void +refcounts_deref_weak (refcounts_t *ref, struct references *result) +{ + const union _references op = { .refs = { .weak = 1 } }; @@ -130,7 +143,8 @@ index 0000000..6e20342 + ((union _references *) result)->rc = r; +} + -+extern inline uint32_t ++/* Return the hard reference count of REF. */ ++static inline uint32_t +refcounts_hard_references (refcounts_t *ref) +{ + union _references result; @@ -138,7 +152,8 @@ index 0000000..6e20342 + return result.refs.hard; +} + -+extern inline uint32_t ++/* Return the weak reference count of REF. */ ++static inline uint32_t +refcounts_weak_references (refcounts_t *ref) +{ + union _references result; diff --git a/debian/patches/0002-libports-lock-less-reference-counting-for-port_info-.patch b/debian/patches/0002-libports-lock-less-reference-counting-for-port_info-.patch index e5afb5cf..7aadc343 100644 --- a/debian/patches/0002-libports-lock-less-reference-counting-for-port_info-.patch +++ b/debian/patches/0002-libports-lock-less-reference-counting-for-port_info-.patch @@ -1,4 +1,4 @@ -From c19e3afec65c9d36d1ed2cad8495dc8dc1799b4b Mon Sep 17 00:00:00 2001 +From acb8bb67d9c9f287a60fc61a9e5f95112697ebd8 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 3 May 2014 01:02:35 +0200 Subject: [PATCH 2/4] libports: lock-less reference counting for port_info @@ -27,14 +27,14 @@ Subject: [PATCH 2/4] libports: lock-less reference counting for port_info libports/import-port.c | 3 +-- libports/lookup-port.c | 2 +- libports/port-deref-weak.c | 10 +++------- - libports/port-deref.c | 31 +++++++++++++++---------------- + libports/port-deref.c | 34 ++++++++++++++++------------------ libports/port-ref-weak.c | 8 +++----- libports/port-ref.c | 8 +++----- libports/ports.h | 4 ++-- libports/reallocate-from-external.c | 2 +- libports/transfer-right.c | 2 +- utils/rpctrace.c | 10 ++++++++-- - 14 files changed, 43 insertions(+), 46 deletions(-) + 14 files changed, 44 insertions(+), 48 deletions(-) diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c index babc204..9230b1f 100644 @@ -137,21 +137,23 @@ index beb4842..8432660 100644 - pthread_mutex_unlock (&_ports_lock); } diff --git a/libports/port-deref.c b/libports/port-deref.c -index cf9b238..06451a2 100644 +index cf9b238..dd38f55 100644 --- a/libports/port-deref.c +++ b/libports/port-deref.c -@@ -26,25 +26,24 @@ ports_port_deref (void *portstruct) +@@ -25,26 +25,24 @@ void + ports_port_deref (void *portstruct) { struct port_info *pi = portstruct; - int trieddroppingweakrefs = 0; -+ struct references result; - +- int trieddroppingweakrefs = 0; +- - retry: - - pthread_mutex_lock (&_ports_lock); - - if (pi->refcnt == 1 && pi->weakrefcnt - && pi->class->dropweak_routine && !trieddroppingweakrefs) ++ struct references result; ++ + /* If we need to call the dropweak routine, we need to hold one + reference while doing so. We use a weak reference for this + purpose, which we acquire before we release our hard reference. diff --git a/debian/patches/0003-libdiskfs-lock-less-reference-counting-for-peropen-o.patch b/debian/patches/0003-libdiskfs-lock-less-reference-counting-for-peropen-o.patch index 04a9210c..fac34440 100644 --- a/debian/patches/0003-libdiskfs-lock-less-reference-counting-for-peropen-o.patch +++ b/debian/patches/0003-libdiskfs-lock-less-reference-counting-for-peropen-o.patch @@ -1,4 +1,4 @@ -From 124fef363dfd2326799dc884e4960a14f20b1e09 Mon Sep 17 00:00:00 2001 +From b3c7364a46a4be0871d49b3ba04bc2c7f8d2a717 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 6 May 2014 18:58:10 +0200 Subject: [PATCH 3/4] libdiskfs: lock-less reference counting for peropen @@ -13,9 +13,9 @@ node must no longer be locked, adjust comment accordingly. --- libdiskfs/diskfs.h | 7 ++++--- libdiskfs/peropen-make.c | 2 +- - libdiskfs/peropen-rele.c | 11 +++-------- + libdiskfs/peropen-rele.c | 21 ++++++++++----------- libdiskfs/protid-make.c | 8 ++++---- - 4 files changed, 12 insertions(+), 16 deletions(-) + 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h index 8151ddc..ae1a150 100644 @@ -67,7 +67,7 @@ index eba037f..6d5ca01 100644 po->np = np; po->path = NULL; diff --git a/libdiskfs/peropen-rele.c b/libdiskfs/peropen-rele.c -index d3f7492..64cea18 100644 +index d3f7492..877137b 100644 --- a/libdiskfs/peropen-rele.c +++ b/libdiskfs/peropen-rele.c @@ -22,13 +22,8 @@ @@ -86,12 +86,22 @@ index d3f7492..64cea18 100644 if (po->root_parent) mach_port_deallocate (mach_task_self (), po->root_parent); -@@ -43,7 +38,7 @@ diskfs_release_peropen (struct peropen *po) - fshelp_acquire_lock (&po->np->userlock, &po->lock_status, - &po->np->lock, LOCK_UN); +@@ -40,10 +35,14 @@ diskfs_release_peropen (struct peropen *po) + mach_port_deallocate (mach_task_self (), po->shadow_root_parent); + if (po->lock_status != LOCK_UN) +- fshelp_acquire_lock (&po->np->userlock, &po->lock_status, +- &po->np->lock, LOCK_UN); +- - diskfs_nput (po->np); -+ diskfs_nrele (po->np); ++ { ++ pthread_mutex_lock (&po->np->lock); ++ fshelp_acquire_lock (&po->np->userlock, &po->lock_status, ++ &po->np->lock, LOCK_UN); ++ diskfs_nput (po->np); ++ } ++ else ++ diskfs_nrele (po->np); free (po->path); free (po); diff --git a/debian/patches/0004-libtrivfs-lock-less-reference-counting-for-trivfs_pr.patch b/debian/patches/0004-libtrivfs-lock-less-reference-counting-for-trivfs_pr.patch index 3e76520a..40755616 100644 --- a/debian/patches/0004-libtrivfs-lock-less-reference-counting-for-trivfs_pr.patch +++ b/debian/patches/0004-libtrivfs-lock-less-reference-counting-for-trivfs_pr.patch @@ -1,4 +1,4 @@ -From fdfa3c69dd5fe5c5be89fa5e70a51dbfc6d61a88 Mon Sep 17 00:00:00 2001 +From d814cbdc92bd9e3c41bfc459ebf783a33133dcce Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 6 May 2014 19:07:13 +0200 Subject: [PATCH 4/4] libtrivfs: lock-less reference counting for trivfs_protid @@ -15,7 +15,6 @@ accordingly. * libtrivfs/protid-dup.c (trivfs_protid_dup): Likewise. * libtrivfs/cntl-create.c (trivfs_create_control): Drop the mutex initialization. - * libtrivfs/peropen-make.c (trivfs_make_peropen): Initialize refcnt. * libtrivfs/peropen-rele.c (trivfs_release_peropen): Adjust accordingly. * libtrivfs/protid-make.c (trivfs_start_protid): Likewise. Also, the |