From: Mathieu Desnoyers Date: Sun, 20 Sep 2009 00:05:10 +0000 (-0400) Subject: Rename liburcu-reclaim to liburcu-defer X-Git-Tag: v0.1~65 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=786ee85b1676d2a1865b2db7120c45bafdf954d6;p=userspace-rcu.git Rename liburcu-reclaim to liburcu-defer Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile.inc b/Makefile.inc index d328de1..6d83ae7 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -6,7 +6,7 @@ DIRS=tests all: checkarch liburcu.so urcu.o \ liburcu-qsbr.so urcu-qsbr.o \ liburcu-mb.so urcu-mb.o \ - liburcu-reclaim.so urcu-reclaim.o \ + liburcu-defer.so urcu-defer.o \ urcu-yield.o \ subdirs @@ -35,7 +35,7 @@ urcu-mb.o: urcu.c urcu.h urcu-qsbr.o: urcu-qsbr.c urcu-qsbr.h $(CC) -fPIC ${CFLAGS} $(LDFLAGS) -c -o $@ $(SRC_DEP) -urcu-reclaim.o: urcu-reclaim.c urcu-reclaim.h +urcu-defer.o: urcu-defer.c urcu-defer.h $(CC) -fPIC ${CFLAGS} $(LDFLAGS) -c -o $@ $(SRC_DEP) liburcu.so: urcu.o @@ -47,7 +47,7 @@ liburcu-qsbr.so: urcu-qsbr.o liburcu-mb.so: urcu-mb.o $(CC) ${LDFLAGS} -fPIC -shared -o $@ $< -liburcu-reclaim.so: urcu-reclaim.o +liburcu-defer.so: urcu-defer.o $(CC) ${LDFLAGS} -fPIC -shared -o $@ $< urcu-yield.o: urcu.c urcu.h diff --git a/tests/Makefile.inc b/tests/Makefile.inc index ddcc515..ff422a6 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -15,7 +15,7 @@ URCU_SIGNAL=${LIBDIR}/urcu.o ${LIBDIR}/urcu.h URCU_SIGNAL_YIELD=${LIBDIR}/urcu-yield.o ${LIBDIR}/urcu.h URCU_MB=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu.h URCU_QSBR=${LIBDIR}/urcu-qsbr.o ${LIBDIR}/urcu-qsbr.h -URCU_MB_RECLAIM=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu-reclaim.o ${LIBDIR}/urcu.h +URCU_MB_DEFER=${LIBDIR}/urcu-mb.o ${LIBDIR}/urcu-defer.o ${LIBDIR}/urcu.h all: test_urcu test_urcu_dynamic_link test_urcu_timing \ test_rwlock_timing test_rwlock test_perthreadlock_timing \ @@ -23,7 +23,7 @@ all: test_urcu test_urcu_dynamic_link test_urcu_timing \ urcu-asm.S test_qsbr_timing test_qsbr urcu-asm.o urcutorture \ urcutorture-yield test_mutex test_looplen test_urcu_gc \ test_urcu_gc_mb test_qsbr_gc test_qsbr_lgc test_urcu_lgc \ - test_urcu_lgc_mb test_qsbr_dynamic_link test_urcu_mb_reclaim + test_urcu_lgc_mb test_qsbr_dynamic_link test_urcu_mb_defer api.h: ${APIHEADER} cp -f ${APIHEADER} api.h @@ -51,7 +51,7 @@ test_urcu_gc_mb: test_urcu_gc.c ${URCU_MB} test_urcu_lgc_mb: test_urcu_gc.c ${URCU_MB} $(CC) -DTEST_LOCAL_GC -DURCU_MB ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) -test_urcu_mb_reclaim: test_urcu_reclaim.c ${URCU_MB_RECLAIM} +test_urcu_mb_defer: test_urcu_defer.c ${URCU_MB_DEFER} $(CC) -DURCU_MB ${CFLAGS} $(LDFLAGS) -o $@ $(SRC_DEP) diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c new file mode 100644 index 0000000..e56dffe --- /dev/null +++ b/tests/test_urcu_defer.c @@ -0,0 +1,398 @@ +/* + * test_urcu_defer.c + * + * Userspace RCU library - test program (with automatic reclamation) + * + * Copyright February 2009 - Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../arch.h" + +/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ +#define CACHE_LINE_SIZE 4096 + +/* hardcoded number of CPUs */ +#define NR_CPUS 16384 + +#if defined(_syscall0) +_syscall0(pid_t, gettid) +#elif defined(__NR_gettid) +static inline pid_t gettid(void) +{ + return syscall(__NR_gettid); +} +#else +#warning "use pid as tid" +static inline pid_t gettid(void) +{ + return getpid(); +} +#endif + +#ifndef DYNAMIC_LINK_TEST +#define _LGPL_SOURCE +#else +#define debug_yield_read() +#endif +#include "../urcu.h" +#include "../urcu-defer.h" + +struct test_array { + int a; +}; + +static volatile int test_go, test_stop; + +static unsigned long wdelay; + +static struct test_array *test_rcu_pointer; + +static unsigned long duration; + +/* read-side C.S. duration, in loops */ +static unsigned long rduration; + +static inline void loop_sleep(unsigned long l) +{ + while(l-- != 0) + cpu_relax(); +} + +static int verbose_mode; + +#define printf_verbose(fmt, args...) \ + do { \ + if (verbose_mode) \ + printf(fmt, args); \ + } while (0) + +static unsigned int cpu_affinities[NR_CPUS]; +static unsigned int next_aff = 0; +static int use_affinity = 0; + +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void set_affinity(void) +{ + cpu_set_t mask; + int cpu; + int ret; + + if (!use_affinity) + return; + + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } + cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } + CPU_ZERO(&mask); + CPU_SET(cpu, &mask); + sched_setaffinity(0, sizeof(mask), &mask); +} + +/* + * returns 0 if test should end. + */ +static int test_duration_write(void) +{ + return !test_stop; +} + +static int test_duration_read(void) +{ + return !test_stop; +} + +static unsigned long long __thread nr_writes; +static unsigned long long __thread nr_reads; + +static +unsigned long long __attribute__((aligned(CACHE_LINE_SIZE))) *tot_nr_writes; + +static unsigned int nr_readers; +static unsigned int nr_writers; + +pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; + +void rcu_copy_mutex_lock(void) +{ + int ret; + ret = pthread_mutex_lock(&rcu_copy_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } +} + +void rcu_copy_mutex_unlock(void) +{ + int ret; + + ret = pthread_mutex_unlock(&rcu_copy_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } +} + +void *thr_reader(void *_count) +{ + unsigned long long *count = _count; + struct test_array *local_ptr; + + printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", + "reader", pthread_self(), (unsigned long)gettid()); + + set_affinity(); + + rcu_register_thread(); + + while (!test_go) + { + } + smp_mb(); + + for (;;) { + rcu_read_lock(); + local_ptr = rcu_dereference(test_rcu_pointer); + debug_yield_read(); + if (local_ptr) + assert(local_ptr->a == 8); + if (unlikely(rduration)) + loop_sleep(rduration); + rcu_read_unlock(); + nr_reads++; + if (unlikely(!test_duration_read())) + break; + } + + rcu_unregister_thread(); + + *count = nr_reads; + printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", + "reader", pthread_self(), (unsigned long)gettid()); + return ((void*)1); + +} + +void *thr_writer(void *data) +{ + unsigned long wtidx = (unsigned long)data; + struct test_array *new, *old = NULL; + + printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", + "writer", pthread_self(), (unsigned long)gettid()); + + set_affinity(); + + rcu_defer_register_thread(); + + while (!test_go) + { + } + smp_mb(); + + for (;;) { + new = malloc(sizeof(*new)); + new->a = 8; + old = rcu_xchg_pointer(&test_rcu_pointer, new); + rcu_defer_queue(old); + nr_writes++; + if (unlikely(!test_duration_write())) + break; + if (unlikely(wdelay)) + loop_sleep(wdelay); + } + + rcu_defer_unregister_thread(); + + printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", + "writer", pthread_self(), (unsigned long)gettid()); + tot_nr_writes[wtidx] = nr_writes; + return ((void*)2); +} + +void show_usage(int argc, char **argv) +{ + printf("Usage : %s nr_readers nr_writers duration (s)", argv[0]); +#ifdef DEBUG_YIELD + printf(" [-r] [-w] (yield reader and/or writer)"); +#endif + printf(" [-d delay] (writer period (us))"); + printf(" [-c duration] (reader C.S. duration (in loops))"); + printf(" [-v] (verbose output)"); + printf(" [-a cpu#] [-a cpu#]... (affinity)"); + printf("\n"); +} + +int main(int argc, char **argv) +{ + int err; + pthread_t *tid_reader, *tid_writer; + void *tret; + unsigned long long *count_reader; + unsigned long long tot_reads = 0, tot_writes = 0; + int i, a; + + if (argc < 4) { + show_usage(argc, argv); + return -1; + } + + err = sscanf(argv[1], "%u", &nr_readers); + if (err != 1) { + show_usage(argc, argv); + return -1; + } + + err = sscanf(argv[2], "%u", &nr_writers); + if (err != 1) { + show_usage(argc, argv); + return -1; + } + + err = sscanf(argv[3], "%lu", &duration); + if (err != 1) { + show_usage(argc, argv); + return -1; + } + + for (i = 4; i < argc; i++) { + if (argv[i][0] != '-') + continue; + switch (argv[i][1]) { +#ifdef DEBUG_YIELD + case 'r': + yield_active |= YIELD_READ; + break; + case 'w': + yield_active |= YIELD_WRITE; + break; +#endif + case 'a': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + a = atoi(argv[++i]); + cpu_affinities[next_aff++] = a; + use_affinity = 1; + printf_verbose("Adding CPU %d affinity\n", a); + break; + case 'c': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + rduration = atol(argv[++i]); + break; + case 'd': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + wdelay = atol(argv[++i]); + break; + case 'v': + verbose_mode = 1; + break; + } + } + + printf_verbose("running test for %lu seconds, %u readers, %u writers.\n", + duration, nr_readers, nr_writers); + printf_verbose("Writer delay : %lu loops.\n", wdelay); + printf_verbose("Reader duration : %lu loops.\n", rduration); + printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", + "main", pthread_self(), (unsigned long)gettid()); + + tid_reader = malloc(sizeof(*tid_reader) * nr_readers); + tid_writer = malloc(sizeof(*tid_writer) * nr_writers); + count_reader = malloc(sizeof(*count_reader) * nr_readers); + tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); + + next_aff = 0; + + for (i = 0; i < nr_readers; i++) { + err = pthread_create(&tid_reader[i], NULL, thr_reader, + &count_reader[i]); + if (err != 0) + exit(1); + } + for (i = 0; i < nr_writers; i++) { + err = pthread_create(&tid_writer[i], NULL, thr_writer, + (void *)(long)i); + if (err != 0) + exit(1); + } + + smp_mb(); + + test_go = 1; + + sleep(duration); + + test_stop = 1; + + for (i = 0; i < nr_readers; i++) { + err = pthread_join(tid_reader[i], &tret); + if (err != 0) + exit(1); + tot_reads += count_reader[i]; + } + for (i = 0; i < nr_writers; i++) { + err = pthread_join(tid_writer[i], &tret); + if (err != 0) + exit(1); + tot_writes += tot_nr_writes[i]; + } + + printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, + tot_writes); + printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu " + "nr_writers %3u " + "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu\n", + argv[0], duration, nr_readers, rduration, + nr_writers, wdelay, tot_reads, tot_writes, + tot_reads + tot_writes); + free(tid_reader); + free(tid_writer); + free(count_reader); + free(tot_nr_writes); + + return 0; +} diff --git a/tests/test_urcu_reclaim.c b/tests/test_urcu_reclaim.c deleted file mode 100644 index 77abea0..0000000 --- a/tests/test_urcu_reclaim.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * test_urcu_reclaim.c - * - * Userspace RCU library - test program (with automatic reclamation) - * - * Copyright February 2009 - Mathieu Desnoyers - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../arch.h" - -/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ -#define CACHE_LINE_SIZE 4096 - -/* hardcoded number of CPUs */ -#define NR_CPUS 16384 - -#if defined(_syscall0) -_syscall0(pid_t, gettid) -#elif defined(__NR_gettid) -static inline pid_t gettid(void) -{ - return syscall(__NR_gettid); -} -#else -#warning "use pid as tid" -static inline pid_t gettid(void) -{ - return getpid(); -} -#endif - -#ifndef DYNAMIC_LINK_TEST -#define _LGPL_SOURCE -#else -#define debug_yield_read() -#endif -#include "../urcu.h" -#include "../urcu-reclaim.h" - -struct test_array { - int a; -}; - -static volatile int test_go, test_stop; - -static unsigned long wdelay; - -static struct test_array *test_rcu_pointer; - -static unsigned long duration; - -/* read-side C.S. duration, in loops */ -static unsigned long rduration; - -static inline void loop_sleep(unsigned long l) -{ - while(l-- != 0) - cpu_relax(); -} - -static int verbose_mode; - -#define printf_verbose(fmt, args...) \ - do { \ - if (verbose_mode) \ - printf(fmt, args); \ - } while (0) - -static unsigned int cpu_affinities[NR_CPUS]; -static unsigned int next_aff = 0; -static int use_affinity = 0; - -pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; - -static void set_affinity(void) -{ - cpu_set_t mask; - int cpu; - int ret; - - if (!use_affinity) - return; - - ret = pthread_mutex_lock(&affinity_mutex); - if (ret) { - perror("Error in pthread mutex lock"); - exit(-1); - } - cpu = cpu_affinities[next_aff++]; - ret = pthread_mutex_unlock(&affinity_mutex); - if (ret) { - perror("Error in pthread mutex unlock"); - exit(-1); - } - CPU_ZERO(&mask); - CPU_SET(cpu, &mask); - sched_setaffinity(0, sizeof(mask), &mask); -} - -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - -static unsigned long long __thread nr_writes; -static unsigned long long __thread nr_reads; - -static -unsigned long long __attribute__((aligned(CACHE_LINE_SIZE))) *tot_nr_writes; - -static unsigned int nr_readers; -static unsigned int nr_writers; - -pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; - -void rcu_copy_mutex_lock(void) -{ - int ret; - ret = pthread_mutex_lock(&rcu_copy_mutex); - if (ret) { - perror("Error in pthread mutex lock"); - exit(-1); - } -} - -void rcu_copy_mutex_unlock(void) -{ - int ret; - - ret = pthread_mutex_unlock(&rcu_copy_mutex); - if (ret) { - perror("Error in pthread mutex unlock"); - exit(-1); - } -} - -void *thr_reader(void *_count) -{ - unsigned long long *count = _count; - struct test_array *local_ptr; - - printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); - - set_affinity(); - - rcu_register_thread(); - - while (!test_go) - { - } - smp_mb(); - - for (;;) { - rcu_read_lock(); - local_ptr = rcu_dereference(test_rcu_pointer); - debug_yield_read(); - if (local_ptr) - assert(local_ptr->a == 8); - if (unlikely(rduration)) - loop_sleep(rduration); - rcu_read_unlock(); - nr_reads++; - if (unlikely(!test_duration_read())) - break; - } - - rcu_unregister_thread(); - - *count = nr_reads; - printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); - return ((void*)1); - -} - -void *thr_writer(void *data) -{ - unsigned long wtidx = (unsigned long)data; - struct test_array *new, *old = NULL; - - printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); - - set_affinity(); - - rcu_reclaim_register_thread(); - - while (!test_go) - { - } - smp_mb(); - - for (;;) { - new = malloc(sizeof(*new)); - new->a = 8; - old = rcu_xchg_pointer(&test_rcu_pointer, new); - rcu_reclaim_queue(old); - nr_writes++; - if (unlikely(!test_duration_write())) - break; - if (unlikely(wdelay)) - loop_sleep(wdelay); - } - - rcu_reclaim_unregister_thread(); - - printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); - tot_nr_writes[wtidx] = nr_writes; - return ((void*)2); -} - -void show_usage(int argc, char **argv) -{ - printf("Usage : %s nr_readers nr_writers duration (s)", argv[0]); -#ifdef DEBUG_YIELD - printf(" [-r] [-w] (yield reader and/or writer)"); -#endif - printf(" [-d delay] (writer period (us))"); - printf(" [-c duration] (reader C.S. duration (in loops))"); - printf(" [-v] (verbose output)"); - printf(" [-a cpu#] [-a cpu#]... (affinity)"); - printf("\n"); -} - -int main(int argc, char **argv) -{ - int err; - pthread_t *tid_reader, *tid_writer; - void *tret; - unsigned long long *count_reader; - unsigned long long tot_reads = 0, tot_writes = 0; - int i, a; - - if (argc < 4) { - show_usage(argc, argv); - return -1; - } - - err = sscanf(argv[1], "%u", &nr_readers); - if (err != 1) { - show_usage(argc, argv); - return -1; - } - - err = sscanf(argv[2], "%u", &nr_writers); - if (err != 1) { - show_usage(argc, argv); - return -1; - } - - err = sscanf(argv[3], "%lu", &duration); - if (err != 1) { - show_usage(argc, argv); - return -1; - } - - for (i = 4; i < argc; i++) { - if (argv[i][0] != '-') - continue; - switch (argv[i][1]) { -#ifdef DEBUG_YIELD - case 'r': - yield_active |= YIELD_READ; - break; - case 'w': - yield_active |= YIELD_WRITE; - break; -#endif - case 'a': - if (argc < i + 2) { - show_usage(argc, argv); - return -1; - } - a = atoi(argv[++i]); - cpu_affinities[next_aff++] = a; - use_affinity = 1; - printf_verbose("Adding CPU %d affinity\n", a); - break; - case 'c': - if (argc < i + 2) { - show_usage(argc, argv); - return -1; - } - rduration = atol(argv[++i]); - break; - case 'd': - if (argc < i + 2) { - show_usage(argc, argv); - return -1; - } - wdelay = atol(argv[++i]); - break; - case 'v': - verbose_mode = 1; - break; - } - } - - printf_verbose("running test for %lu seconds, %u readers, %u writers.\n", - duration, nr_readers, nr_writers); - printf_verbose("Writer delay : %lu loops.\n", wdelay); - printf_verbose("Reader duration : %lu loops.\n", rduration); - printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", - "main", pthread_self(), (unsigned long)gettid()); - - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - tot_nr_writes = malloc(sizeof(*tot_nr_writes) * nr_writers); - - next_aff = 0; - - for (i = 0; i < nr_readers; i++) { - err = pthread_create(&tid_reader[i], NULL, thr_reader, - &count_reader[i]); - if (err != 0) - exit(1); - } - for (i = 0; i < nr_writers; i++) { - err = pthread_create(&tid_writer[i], NULL, thr_writer, - (void *)(long)i); - if (err != 0) - exit(1); - } - - smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; - - for (i = 0; i < nr_readers; i++) { - err = pthread_join(tid_reader[i], &tret); - if (err != 0) - exit(1); - tot_reads += count_reader[i]; - } - for (i = 0; i < nr_writers; i++) { - err = pthread_join(tid_writer[i], &tret); - if (err != 0) - exit(1); - tot_writes += tot_nr_writes[i]; - } - - printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, - tot_writes); - printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu " - "nr_writers %3u " - "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu\n", - argv[0], duration, nr_readers, rduration, - nr_writers, wdelay, tot_reads, tot_writes, - tot_reads + tot_writes); - free(tid_reader); - free(tid_writer); - free(count_reader); - free(tot_nr_writes); - - return 0; -} diff --git a/urcu-defer-static.h b/urcu-defer-static.h new file mode 100644 index 0000000..2513769 --- /dev/null +++ b/urcu-defer-static.h @@ -0,0 +1,128 @@ +#ifndef _URCU_DEFER_STATIC_H +#define _URCU_DEFER_STATIC_H + +/* + * urcu-defer-static.h + * + * Userspace RCU header - memory reclamation. + * + * TO BE INCLUDED ONLY IN LGPL-COMPATIBLE CODE. See urcu-defer.h for linking + * dynamically with the userspace rcu reclamation library. + * + * Copyright (c) 2009 Mathieu Desnoyers + * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * IBM's contributions to this file may be relicensed under LGPLv2 or later. + */ + +#include +#include + +#include +#include + + +/* + * Number of entries in the per-thread defer queue. Must be power of 2. + */ +#define DEFER_QUEUE_SIZE (1 << 12) +#define DEFER_QUEUE_MASK (DEFER_QUEUE_SIZE - 1) + +/* + * Identify a shared load. A smp_rmc() or smp_mc() should come before the load. + */ +#define _LOAD_SHARED(p) ACCESS_ONCE(p) + +/* + * Load a data from shared memory, doing a cache flush if required. + */ +#define LOAD_SHARED(p) \ + ({ \ + smp_rmc(); \ + _LOAD_SHARED(p); \ + }) + +/* + * Identify a shared store. A smp_wmc() or smp_mc() should follow the store. + */ +#define _STORE_SHARED(x, v) ({ ACCESS_ONCE(x) = (v); }) + +/* + * Store v into x, where x is located in shared memory. Performs the required + * cache flush after writing. Returns v. + */ +#define STORE_SHARED(x, v) \ + ({ \ + _STORE_SHARED(x, v); \ + smp_wmc(); \ + (v); \ + }) + +/* + * This code section can only be included in LGPL 2.1 compatible source code. + * See below for the function call wrappers which can be used in code meant to + * be only linked with the Userspace RCU library. This comes with a small + * performance degradation on the read-side due to the added function calls. + * This is required to permit relinking with newer versions of the library. + */ + +#ifdef DEBUG_RCU +#define rcu_assert(args...) assert(args) +#else +#define rcu_assert(args...) +#endif + +struct defer_queue { + unsigned long head; /* add element at head */ + unsigned long tail; /* next element to remove at tail */ + void **q; +}; + +extern struct defer_queue __thread defer_queue; + +extern void rcu_defer_barrier_thread(void); + +/* + * not signal-safe. + */ +static inline void _rcu_defer_queue(void *p) +{ + unsigned long head, tail; + + /* + * Head is only modified by ourself. Tail can be modified by reclamation + * thread. + */ + head = defer_queue.head; + tail = LOAD_SHARED(defer_queue.tail); + + /* + * If queue is full, empty it ourself. + */ + if (unlikely(head - tail >= DEFER_QUEUE_SIZE)) { + assert(head - tail == DEFER_QUEUE_SIZE); + rcu_defer_barrier_thread(); + assert(head - LOAD_SHARED(defer_queue.tail) == 0); + } + + smp_wmb(); /* Publish new pointer before write q[] */ + _STORE_SHARED(defer_queue.q[head & DEFER_QUEUE_MASK], p); + smp_wmb(); /* Write q[] before head. */ + STORE_SHARED(defer_queue.head, head + 1); +} + +#endif /* _URCU_DEFER_STATIC_H */ diff --git a/urcu-defer.c b/urcu-defer.c new file mode 100644 index 0000000..1e5d2b6 --- /dev/null +++ b/urcu-defer.c @@ -0,0 +1,280 @@ +/* + * urcu-defer.c + * + * Userspace RCU library - batch memory reclamation + * + * Copyright (c) 2009 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "urcu-defer-static.h" +/* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */ +#include "urcu-defer.h" + +void __attribute__((destructor)) urcu_defer_exit(void); + +extern void synchronize_rcu(void); + +/* + * urcu_defer_mutex nests inside defer_thread_mutex. + */ +static pthread_mutex_t urcu_defer_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t defer_thread_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* + * Written to only by each individual deferer. Read by both the deferer and + * the reclamation tread. + */ +struct defer_queue __thread defer_queue; + +/* Thread IDs of registered deferers */ +#define INIT_NUM_THREADS 4 + +struct deferer_registry { + pthread_t tid; + struct defer_queue *defer_queue; + unsigned long last_head; +}; + +static struct deferer_registry *registry; +static int num_deferers, alloc_deferers; + +static pthread_t tid_defer; +static int exit_defer; + +static void internal_urcu_lock(pthread_mutex_t *mutex) +{ + int ret; + +#ifndef DISTRUST_SIGNALS_EXTREME + ret = pthread_mutex_lock(mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } +#else /* #ifndef DISTRUST_SIGNALS_EXTREME */ + while ((ret = pthread_mutex_trylock(mutex)) != 0) { + if (ret != EBUSY && ret != EINTR) { + printf("ret = %d, errno = %d\n", ret, errno); + perror("Error in pthread mutex lock"); + exit(-1); + } + poll(NULL,0,10); + } +#endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */ +} + +static void internal_urcu_unlock(pthread_mutex_t *mutex) +{ + int ret; + + ret = pthread_mutex_unlock(mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } +} + +/* + * Must be called after Q.S. is reached. + */ +static void rcu_defer_barrier_queue(struct defer_queue *queue, + unsigned long head) +{ + unsigned long i; + + /* + * Tail is only modified when lock is held. + * Head is only modified by owner thread. + */ + + for (i = queue->tail; i != head; i++) { + smp_rmb(); /* read head before q[]. */ + free(LOAD_SHARED(queue->q[i & DEFER_QUEUE_MASK])); + } + smp_mb(); /* push tail after having used q[] */ + STORE_SHARED(queue->tail, i); +} + +static void _rcu_defer_barrier_thread(void) +{ + unsigned long head; + + head = defer_queue.head; + synchronize_rcu(); + rcu_defer_barrier_queue(&defer_queue, head); +} + + +void rcu_defer_barrier_thread(void) +{ + internal_urcu_lock(&urcu_defer_mutex); + _rcu_defer_barrier_thread(); + internal_urcu_unlock(&urcu_defer_mutex); +} + +void rcu_defer_barrier(void) +{ + struct deferer_registry *index; + + if (!registry) + return; + + internal_urcu_lock(&urcu_defer_mutex); + for (index = registry; index < registry + num_deferers; index++) + index->last_head = LOAD_SHARED(index->defer_queue->head); + synchronize_rcu(); + for (index = registry; index < registry + num_deferers; index++) + rcu_defer_barrier_queue(index->defer_queue, + index->last_head); + internal_urcu_unlock(&urcu_defer_mutex); +} + +void *thr_defer(void *args) +{ + for (;;) { + if (LOAD_SHARED(exit_defer)) + break; + poll(NULL,0,100); /* wait for 100ms */ + rcu_defer_barrier(); + } + + return NULL; +} + +/* + * library wrappers to be used by non-LGPL compatible source code. + */ + +void rcu_defer_queue(void *p) +{ + _rcu_defer_queue(p); +} + +static void rcu_add_deferer(pthread_t id) +{ + struct deferer_registry *oldarray; + + if (!registry) { + alloc_deferers = INIT_NUM_THREADS; + num_deferers = 0; + registry = + malloc(sizeof(struct deferer_registry) * alloc_deferers); + } + if (alloc_deferers < num_deferers + 1) { + oldarray = registry; + registry = malloc(sizeof(struct deferer_registry) + * (alloc_deferers << 1)); + memcpy(registry, oldarray, + sizeof(struct deferer_registry) * alloc_deferers); + alloc_deferers <<= 1; + free(oldarray); + } + registry[num_deferers].tid = id; + /* reference to the TLS of _this_ deferer thread. */ + registry[num_deferers].defer_queue = &defer_queue; + num_deferers++; +} + +/* + * Never shrink (implementation limitation). + * This is O(nb threads). Eventually use a hash table. + */ +static void rcu_remove_deferer(pthread_t id) +{ + struct deferer_registry *index; + + assert(registry != NULL); + for (index = registry; index < registry + num_deferers; index++) { + if (pthread_equal(index->tid, id)) { + memcpy(index, ®istry[num_deferers - 1], + sizeof(struct deferer_registry)); + registry[num_deferers - 1].tid = 0; + registry[num_deferers - 1].defer_queue = NULL; + num_deferers--; + return; + } + } + /* Hrm not found, forgot to register ? */ + assert(0); +} + +static void start_defer_thread(void) +{ + int ret; + + ret = pthread_create(&tid_defer, NULL, thr_defer, + NULL); + assert(!ret); +} + +static void stop_defer_thread(void) +{ + int ret; + void *tret; + + STORE_SHARED(exit_defer, 1); + ret = pthread_join(tid_defer, &tret); + assert(!ret); +} + +void rcu_defer_register_thread(void) +{ + int deferers; + + internal_urcu_lock(&defer_thread_mutex); + internal_urcu_lock(&urcu_defer_mutex); + defer_queue.q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE); + rcu_add_deferer(pthread_self()); + deferers = num_deferers; + internal_urcu_unlock(&urcu_defer_mutex); + + if (deferers == 1) + start_defer_thread(); + internal_urcu_unlock(&defer_thread_mutex); +} + +void rcu_defer_unregister_thread(void) +{ + int deferers; + + internal_urcu_lock(&defer_thread_mutex); + internal_urcu_lock(&urcu_defer_mutex); + rcu_remove_deferer(pthread_self()); + _rcu_defer_barrier_thread(); + free(defer_queue.q); + defer_queue.q = NULL; + deferers = num_deferers; + internal_urcu_unlock(&urcu_defer_mutex); + + if (deferers == 0) + stop_defer_thread(); + internal_urcu_unlock(&defer_thread_mutex); +} + +void urcu_defer_exit(void) +{ + free(registry); +} diff --git a/urcu-defer.h b/urcu-defer.h new file mode 100644 index 0000000..456b8b7 --- /dev/null +++ b/urcu-defer.h @@ -0,0 +1,72 @@ +#ifndef _URCU_BATCH_H +#define _URCU_BATCH_H + +/* + * urcu-defer.h + * + * Userspace RCU header - deferred execution + * + * Copyright (c) 2009 Mathieu Desnoyers + * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. + * + * LGPL-compatible code should include this header with : + * + * #define _LGPL_SOURCE + * #include + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +/* + * Important ! + * + * Each thread queuing memory reclamation must be registered with + * rcu_defer_register_thread(). rcu_defer_unregister_thread() should be + * called before the thread exits. + */ + +#ifdef _LGPL_SOURCE + +#include + +/* + * Mappings for static use of the userspace RCU library. + * Should only be used in LGPL-compatible code. + */ + +#define rcu_defer_queue _rcu_defer_queue + +#else /* !_LGPL_SOURCE */ + +/* + * library wrappers to be used by non-LGPL compatible source code. + */ + +extern void rcu_defer_queue(void *p); + +#endif /* !_LGPL_SOURCE */ + +/* + * Thread registration for reclamation. + */ +extern void rcu_defer_register_thread(void); +extern void rcu_defer_unregister_thread(void); +extern void rcu_defer_barrier(void); +extern void rcu_defer_barrier_thread(void); + +#endif /* _URCU_BATCH_H */ diff --git a/urcu-reclaim-static.h b/urcu-reclaim-static.h deleted file mode 100644 index 40de6fe..0000000 --- a/urcu-reclaim-static.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef _URCU_RECLAIM_STATIC_H -#define _URCU_RECLAIM_STATIC_H - -/* - * urcu-reclaim-static.h - * - * Userspace RCU header - memory reclamation. - * - * TO BE INCLUDED ONLY IN LGPL-COMPATIBLE CODE. See urcu-reclaim.h for linking - * dynamically with the userspace rcu reclamation library. - * - * Copyright (c) 2009 Mathieu Desnoyers - * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * IBM's contributions to this file may be relicensed under LGPLv2 or later. - */ - -#include -#include - -#include -#include - - -/* - * Number of entries in the per-thread reclaim queue. Must be power of 2. - */ -#define RECLAIM_QUEUE_SIZE (1 << 12) -#define RECLAIM_QUEUE_MASK (RECLAIM_QUEUE_SIZE - 1) - -/* - * Identify a shared load. A smp_rmc() or smp_mc() should come before the load. - */ -#define _LOAD_SHARED(p) ACCESS_ONCE(p) - -/* - * Load a data from shared memory, doing a cache flush if required. - */ -#define LOAD_SHARED(p) \ - ({ \ - smp_rmc(); \ - _LOAD_SHARED(p); \ - }) - -/* - * Identify a shared store. A smp_wmc() or smp_mc() should follow the store. - */ -#define _STORE_SHARED(x, v) ({ ACCESS_ONCE(x) = (v); }) - -/* - * Store v into x, where x is located in shared memory. Performs the required - * cache flush after writing. Returns v. - */ -#define STORE_SHARED(x, v) \ - ({ \ - _STORE_SHARED(x, v); \ - smp_wmc(); \ - (v); \ - }) - -/* - * This code section can only be included in LGPL 2.1 compatible source code. - * See below for the function call wrappers which can be used in code meant to - * be only linked with the Userspace RCU library. This comes with a small - * performance degradation on the read-side due to the added function calls. - * This is required to permit relinking with newer versions of the library. - */ - -#ifdef DEBUG_RCU -#define rcu_assert(args...) assert(args) -#else -#define rcu_assert(args...) -#endif - -struct reclaim_queue { - unsigned long head; /* add element at head */ - unsigned long tail; /* next element to remove at tail */ - void **q; -}; - -extern struct reclaim_queue __thread reclaim_queue; - -extern void rcu_reclaim_barrier_thread(void); - -/* - * not signal-safe. - */ -static inline void _rcu_reclaim_queue(void *p) -{ - unsigned long head, tail; - - /* - * Head is only modified by ourself. Tail can be modified by reclamation - * thread. - */ - head = reclaim_queue.head; - tail = LOAD_SHARED(reclaim_queue.tail); - - /* - * If queue is full, empty it ourself. - */ - if (unlikely(head - tail >= RECLAIM_QUEUE_SIZE)) { - assert(head - tail == RECLAIM_QUEUE_SIZE); - rcu_reclaim_barrier_thread(); - assert(head - LOAD_SHARED(reclaim_queue.tail) == 0); - } - - smp_wmb(); /* Publish new pointer before write q[] */ - _STORE_SHARED(reclaim_queue.q[head & RECLAIM_QUEUE_MASK], p); - smp_wmb(); /* Write q[] before head. */ - STORE_SHARED(reclaim_queue.head, head + 1); -} - -#endif /* _URCU_RECLAIM_STATIC_H */ diff --git a/urcu-reclaim.c b/urcu-reclaim.c deleted file mode 100644 index ff07aee..0000000 --- a/urcu-reclaim.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * urcu-reclaim.c - * - * Userspace RCU library - batch memory reclamation - * - * Copyright (c) 2009 Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "urcu-reclaim-static.h" -/* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */ -#include "urcu-reclaim.h" - -void __attribute__((destructor)) urcu_reclaim_exit(void); - -extern void synchronize_rcu(void); - -/* - * urcu_reclaim_mutex nests inside reclaim_thread_mutex. - */ -static pthread_mutex_t urcu_reclaim_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t reclaim_thread_mutex = PTHREAD_MUTEX_INITIALIZER; - -/* - * Written to only by each individual reclaimer. Read by both the reclaimer and - * the reclamation tread. - */ -struct reclaim_queue __thread reclaim_queue; - -/* Thread IDs of registered reclaimers */ -#define INIT_NUM_THREADS 4 - -struct reclaimer_registry { - pthread_t tid; - struct reclaim_queue *reclaim_queue; - unsigned long last_head; -}; - -static struct reclaimer_registry *registry; -static int num_reclaimers, alloc_reclaimers; - -static pthread_t tid_reclaim; -static int exit_reclaim; - -static void internal_urcu_lock(pthread_mutex_t *mutex) -{ - int ret; - -#ifndef DISTRUST_SIGNALS_EXTREME - ret = pthread_mutex_lock(mutex); - if (ret) { - perror("Error in pthread mutex lock"); - exit(-1); - } -#else /* #ifndef DISTRUST_SIGNALS_EXTREME */ - while ((ret = pthread_mutex_trylock(mutex)) != 0) { - if (ret != EBUSY && ret != EINTR) { - printf("ret = %d, errno = %d\n", ret, errno); - perror("Error in pthread mutex lock"); - exit(-1); - } - poll(NULL,0,10); - } -#endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */ -} - -static void internal_urcu_unlock(pthread_mutex_t *mutex) -{ - int ret; - - ret = pthread_mutex_unlock(mutex); - if (ret) { - perror("Error in pthread mutex unlock"); - exit(-1); - } -} - -/* - * Must be called after Q.S. is reached. - */ -static void rcu_reclaim_barrier_queue(struct reclaim_queue *queue, - unsigned long head) -{ - unsigned long i; - - /* - * Tail is only modified when lock is held. - * Head is only modified by owner thread. - */ - - for (i = queue->tail; i != head; i++) { - smp_rmb(); /* read head before q[]. */ - free(LOAD_SHARED(queue->q[i & RECLAIM_QUEUE_MASK])); - } - smp_mb(); /* push tail after having used q[] */ - STORE_SHARED(queue->tail, i); -} - -static void _rcu_reclaim_barrier_thread(void) -{ - unsigned long head; - - head = reclaim_queue.head; - synchronize_rcu(); - rcu_reclaim_barrier_queue(&reclaim_queue, head); -} - - -void rcu_reclaim_barrier_thread(void) -{ - internal_urcu_lock(&urcu_reclaim_mutex); - _rcu_reclaim_barrier_thread(); - internal_urcu_unlock(&urcu_reclaim_mutex); -} - -void rcu_reclaim_barrier(void) -{ - struct reclaimer_registry *index; - - if (!registry) - return; - - internal_urcu_lock(&urcu_reclaim_mutex); - for (index = registry; index < registry + num_reclaimers; index++) - index->last_head = LOAD_SHARED(index->reclaim_queue->head); - synchronize_rcu(); - for (index = registry; index < registry + num_reclaimers; index++) - rcu_reclaim_barrier_queue(index->reclaim_queue, - index->last_head); - internal_urcu_unlock(&urcu_reclaim_mutex); -} - -void *thr_reclaim(void *args) -{ - for (;;) { - if (LOAD_SHARED(exit_reclaim)) - break; - poll(NULL,0,100); /* wait for 100ms */ - rcu_reclaim_barrier(); - } - - return NULL; -} - -/* - * library wrappers to be used by non-LGPL compatible source code. - */ - -void rcu_reclaim_queue(void *p) -{ - _rcu_reclaim_queue(p); -} - -static void rcu_add_reclaimer(pthread_t id) -{ - struct reclaimer_registry *oldarray; - - if (!registry) { - alloc_reclaimers = INIT_NUM_THREADS; - num_reclaimers = 0; - registry = - malloc(sizeof(struct reclaimer_registry) * alloc_reclaimers); - } - if (alloc_reclaimers < num_reclaimers + 1) { - oldarray = registry; - registry = malloc(sizeof(struct reclaimer_registry) - * (alloc_reclaimers << 1)); - memcpy(registry, oldarray, - sizeof(struct reclaimer_registry) * alloc_reclaimers); - alloc_reclaimers <<= 1; - free(oldarray); - } - registry[num_reclaimers].tid = id; - /* reference to the TLS of _this_ reclaimer thread. */ - registry[num_reclaimers].reclaim_queue = &reclaim_queue; - num_reclaimers++; -} - -/* - * Never shrink (implementation limitation). - * This is O(nb threads). Eventually use a hash table. - */ -static void rcu_remove_reclaimer(pthread_t id) -{ - struct reclaimer_registry *index; - - assert(registry != NULL); - for (index = registry; index < registry + num_reclaimers; index++) { - if (pthread_equal(index->tid, id)) { - memcpy(index, ®istry[num_reclaimers - 1], - sizeof(struct reclaimer_registry)); - registry[num_reclaimers - 1].tid = 0; - registry[num_reclaimers - 1].reclaim_queue = NULL; - num_reclaimers--; - return; - } - } - /* Hrm not found, forgot to register ? */ - assert(0); -} - -static void start_reclaim_thread(void) -{ - int ret; - - ret = pthread_create(&tid_reclaim, NULL, thr_reclaim, - NULL); - assert(!ret); -} - -static void stop_reclaim_thread(void) -{ - int ret; - void *tret; - - STORE_SHARED(exit_reclaim, 1); - ret = pthread_join(tid_reclaim, &tret); - assert(!ret); -} - -void rcu_reclaim_register_thread(void) -{ - int reclaimers; - - internal_urcu_lock(&reclaim_thread_mutex); - internal_urcu_lock(&urcu_reclaim_mutex); - reclaim_queue.q = malloc(sizeof(void *) * RECLAIM_QUEUE_SIZE); - rcu_add_reclaimer(pthread_self()); - reclaimers = num_reclaimers; - internal_urcu_unlock(&urcu_reclaim_mutex); - - if (reclaimers == 1) - start_reclaim_thread(); - internal_urcu_unlock(&reclaim_thread_mutex); -} - -void rcu_reclaim_unregister_thread(void) -{ - int reclaimers; - - internal_urcu_lock(&reclaim_thread_mutex); - internal_urcu_lock(&urcu_reclaim_mutex); - rcu_remove_reclaimer(pthread_self()); - _rcu_reclaim_barrier_thread(); - free(reclaim_queue.q); - reclaim_queue.q = NULL; - reclaimers = num_reclaimers; - internal_urcu_unlock(&urcu_reclaim_mutex); - - if (reclaimers == 0) - stop_reclaim_thread(); - internal_urcu_unlock(&reclaim_thread_mutex); -} - -void urcu_reclaim_exit(void) -{ - free(registry); -} diff --git a/urcu-reclaim.h b/urcu-reclaim.h deleted file mode 100644 index adca25b..0000000 --- a/urcu-reclaim.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef _URCU_RECLAIM_H -#define _URCU_RECLAIM_H - -/* - * urcu-reclaim.h - * - * Userspace RCU header - memory reclamation - * - * Copyright (c) 2009 Mathieu Desnoyers - * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. - * - * LGPL-compatible code should include this header with : - * - * #define _LGPL_SOURCE - * #include - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -/* - * Important ! - * - * Each thread queuing memory reclamation must be registered with - * rcu_reclaim_register_thread(). rcu_reclaim_unregister_thread() should be - * called before the thread exits. - */ - -#ifdef _LGPL_SOURCE - -#include - -/* - * Mappings for static use of the userspace RCU library. - * Should only be used in LGPL-compatible code. - */ - -#define rcu_reclaim_queue _rcu_reclaim_queue - -#else /* !_LGPL_SOURCE */ - -/* - * library wrappers to be used by non-LGPL compatible source code. - */ - -extern void rcu_reclaim_queue(void *p); - -#endif /* !_LGPL_SOURCE */ - -/* - * Thread registration for reclamation. - */ -extern void rcu_reclaim_register_thread(void); -extern void rcu_reclaim_unregister_thread(void); -extern void rcu_reclaim_barrier(void); -extern void rcu_reclaim_barrier_thread(void); - -#endif /* _URCU_RECLAIM_H */