Merge branch 'master' into benchmark
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 27 Sep 2011 00:42:26 +0000 (20:42 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 27 Sep 2011 00:42:26 +0000 (20:42 -0400)
20 files changed:
hashtable/rculfhash.c [new file with mode: 0644]
hashtable/rculfhash.h [new file with mode: 0644]
include/lttng-sessiond-comm.h
include/lttng-share.h
include/lttng-ust.h
liblttng-sessiond-comm/lttng-sessiond-comm.c
liblttngkconsumerd/lttngkconsumerd.c
ltt-sessiond/Makefile.am
ltt-sessiond/channel.c
ltt-sessiond/channel.h
ltt-sessiond/main.c
ltt-sessiond/trace-ust.c
ltt-sessiond/trace-ust.h
ltt-sessiond/traceable-app.c
ltt-sessiond/traceable-app.h
ltt-sessiond/ust-comm.c
ltt-sessiond/ust-ctl.c
ltt-sessiond/ust-ctl.h
lttng/commands/enable_channels.c
tests/lttng/kernel_all_events_basic.c

diff --git a/hashtable/rculfhash.c b/hashtable/rculfhash.c
new file mode 100644 (file)
index 0000000..2bb26e5
--- /dev/null
@@ -0,0 +1,1713 @@
+/*
+ * rculfhash.c
+ *
+ * Userspace RCU library - Lock-Free Resizable RCU Hash Table
+ *
+ * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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
+ */
+
+/*
+ * Based on the following articles:
+ * - Ori Shalev and Nir Shavit. Split-ordered lists: Lock-free
+ *   extensible hash tables. J. ACM 53, 3 (May 2006), 379-405.
+ * - Michael, M. M. High performance dynamic lock-free hash tables
+ *   and list-based sets. In Proceedings of the fourteenth annual ACM
+ *   symposium on Parallel algorithms and architectures, ACM Press,
+ *   (2002), 73-82.
+ *
+ * Some specificities of this Lock-Free Resizable RCU Hash Table
+ * implementation:
+ *
+ * - RCU read-side critical section allows readers to perform hash
+ *   table lookups and use the returned objects safely by delaying
+ *   memory reclaim of a grace period.
+ * - Add and remove operations are lock-free, and do not need to
+ *   allocate memory. They need to be executed within RCU read-side
+ *   critical section to ensure the objects they read are valid and to
+ *   deal with the cmpxchg ABA problem.
+ * - add and add_unique operations are supported. add_unique checks if
+ *   the node key already exists in the hash table. It ensures no key
+ *   duplicata exists.
+ * - The resize operation executes concurrently with add/remove/lookup.
+ * - Hash table nodes are contained within a split-ordered list. This
+ *   list is ordered by incrementing reversed-bits-hash value.
+ * - An index of dummy nodes is kept. These dummy nodes are the hash
+ *   table "buckets", and they are also chained together in the
+ *   split-ordered list, which allows recursive expansion.
+ * - The resize operation for small tables only allows expanding the hash table.
+ *   It is triggered automatically by detecting long chains in the add
+ *   operation.
+ * - The resize operation for larger tables (and available through an
+ *   API) allows both expanding and shrinking the hash table.
+ * - Per-CPU Split-counters are used to keep track of the number of
+ *   nodes within the hash table for automatic resize triggering.
+ * - Resize operation initiated by long chain detection is executed by a
+ *   call_rcu thread, which keeps lock-freedom of add and remove.
+ * - Resize operations are protected by a mutex.
+ * - The removal operation is split in two parts: first, a "removed"
+ *   flag is set in the next pointer within the node to remove. Then,
+ *   a "garbage collection" is performed in the bucket containing the
+ *   removed node (from the start of the bucket up to the removed node).
+ *   All encountered nodes with "removed" flag set in their next
+ *   pointers are removed from the linked-list. If the cmpxchg used for
+ *   removal fails (due to concurrent garbage-collection or concurrent
+ *   add), we retry from the beginning of the bucket. This ensures that
+ *   the node with "removed" flag set is removed from the hash table
+ *   (not visible to lookups anymore) before the RCU read-side critical
+ *   section held across removal ends. Furthermore, this ensures that
+ *   the node with "removed" flag set is removed from the linked-list
+ *   before its memory is reclaimed. Only the thread which removal
+ *   successfully set the "removed" flag (with a cmpxchg) into a node's
+ *   next pointer is considered to have succeeded its removal (and thus
+ *   owns the node to reclaim). Because we garbage-collect starting from
+ *   an invariant node (the start-of-bucket dummy node) up to the
+ *   "removed" node (or find a reverse-hash that is higher), we are sure
+ *   that a successful traversal of the chain leads to a chain that is
+ *   present in the linked-list (the start node is never removed) and
+ *   that is does not contain the "removed" node anymore, even if
+ *   concurrent delete/add operations are changing the structure of the
+ *   list concurrently.
+ * - The add operation performs gargage collection of buckets if it
+ *   encounters nodes with removed flag set in the bucket where it wants
+ *   to add its new node. This ensures lock-freedom of add operation by
+ *   helping the remover unlink nodes from the list rather than to wait
+ *   for it do to so.
+ * - A RCU "order table" indexed by log2(hash index) is copied and
+ *   expanded by the resize operation. This order table allows finding
+ *   the "dummy node" tables.
+ * - There is one dummy node table per hash index order. The size of
+ *   each dummy node table is half the number of hashes contained in
+ *   this order.
+ * - call_rcu is used to garbage-collect the old order table.
+ * - The per-order dummy node tables contain a compact version of the
+ *   hash table nodes. These tables are invariant after they are
+ *   populated into the hash table.
+ * 
+ * A bit of ascii art explanation:
+ * 
+ * Order index is the off-by-one compare to the actual power of 2 because 
+ * we use index 0 to deal with the 0 special-case.
+ * 
+ * This shows the nodes for a small table ordered by reversed bits:
+ * 
+ *    bits   reverse
+ * 0  000        000
+ * 4  100        001
+ * 2  010        010
+ * 6  110        011
+ * 1  001        100
+ * 5  101        101
+ * 3  011        110
+ * 7  111        111
+ * 
+ * This shows the nodes in order of non-reversed bits, linked by 
+ * reversed-bit order.
+ * 
+ * order              bits       reverse
+ * 0               0  000        000
+ *                 |
+ * 1               |  1  001        100       <-    <-
+ *                 |  |                        |     |
+ * 2               |  |  2  010        010     |     |
+ *                 |  |  |  3  011        110  | <-  |
+ *                 |  |  |  |                  |  |  |
+ * 3               -> |  |  |  4  100        001  |  |
+ *                    -> |  |     5  101        101  |
+ *                       -> |        6  110        011
+ *                          ->          7  111        111
+ */
+
+#define _LGPL_SOURCE
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <urcu/config.h>
+#include <urcu.h>
+#include <urcu-call-rcu.h>
+#include <urcu/arch.h>
+#include <urcu/uatomic.h>
+#include <urcu/compiler.h>
+#include "rculfhash.h"
+#include <stdio.h>
+#include <pthread.h>
+
+#ifdef DEBUG
+#define dbg_printf(fmt, args...)     printf("[debug rculfhash] " fmt, ## args)
+#else
+#define dbg_printf(fmt, args...)
+#endif
+
+/*
+ * Per-CPU split-counters lazily update the global counter each 1024
+ * addition/removal. It automatically keeps track of resize required.
+ * We use the bucket length as indicator for need to expand for small
+ * tables and machines lacking per-cpu data suppport.
+ */
+#define COUNT_COMMIT_ORDER             10
+#define CHAIN_LEN_TARGET               1
+#define CHAIN_LEN_RESIZE_THRESHOLD     3
+
+/*
+ * Define the minimum table size.
+ */
+#define MIN_TABLE_SIZE                 1
+
+#if (CAA_BITS_PER_LONG == 32)
+#define MAX_TABLE_ORDER                        32
+#else
+#define MAX_TABLE_ORDER                        64
+#endif
+
+/*
+ * Minimum number of dummy nodes to touch per thread to parallelize grow/shrink.
+ */
+#define MIN_PARTITION_PER_THREAD_ORDER 12
+#define MIN_PARTITION_PER_THREAD       (1UL << MIN_PARTITION_PER_THREAD_ORDER)
+
+#ifndef min
+#define min(a, b)      ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef max
+#define max(a, b)      ((a) > (b) ? (a) : (b))
+#endif
+
+/*
+ * The removed flag needs to be updated atomically with the pointer.
+ * It indicates that no node must attach to the node scheduled for
+ * removal, and that node garbage collection must be performed.
+ * The dummy flag does not require to be updated atomically with the
+ * pointer, but it is added as a pointer low bit flag to save space.
+ */
+#define REMOVED_FLAG           (1UL << 0)
+#define DUMMY_FLAG             (1UL << 1)
+#define FLAGS_MASK             ((1UL << 2) - 1)
+
+/* Value of the end pointer. Should not interact with flags. */
+#define END_VALUE              NULL
+
+struct ht_items_count {
+       unsigned long add, del;
+} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
+
+struct rcu_level {
+       struct rcu_head head;
+       struct _cds_lfht_node nodes[0];
+};
+
+struct rcu_table {
+       unsigned long size;     /* always a power of 2, shared (RCU) */
+       unsigned long resize_target;
+       int resize_initiated;
+       struct rcu_level *tbl[MAX_TABLE_ORDER];
+};
+
+struct cds_lfht {
+       struct rcu_table t;
+       cds_lfht_hash_fct hash_fct;
+       cds_lfht_compare_fct compare_fct;
+       unsigned long hash_seed;
+       int flags;
+       /*
+        * We need to put the work threads offline (QSBR) when taking this
+        * mutex, because we use synchronize_rcu within this mutex critical
+        * section, which waits on read-side critical sections, and could
+        * therefore cause grace-period deadlock if we hold off RCU G.P.
+        * completion.
+        */
+       pthread_mutex_t resize_mutex;   /* resize mutex: add/del mutex */
+       unsigned int in_progress_resize, in_progress_destroy;
+       void (*cds_lfht_call_rcu)(struct rcu_head *head,
+                     void (*func)(struct rcu_head *head));
+       void (*cds_lfht_synchronize_rcu)(void);
+       void (*cds_lfht_rcu_read_lock)(void);
+       void (*cds_lfht_rcu_read_unlock)(void);
+       void (*cds_lfht_rcu_thread_offline)(void);
+       void (*cds_lfht_rcu_thread_online)(void);
+       void (*cds_lfht_rcu_register_thread)(void);
+       void (*cds_lfht_rcu_unregister_thread)(void);
+       pthread_attr_t *resize_attr;    /* Resize threads attributes */
+       long count;                     /* global approximate item count */
+       struct ht_items_count *percpu_count;    /* per-cpu item count */
+};
+
+struct rcu_resize_work {
+       struct rcu_head head;
+       struct cds_lfht *ht;
+};
+
+struct partition_resize_work {
+       struct rcu_head head;
+       struct cds_lfht *ht;
+       unsigned long i, start, len;
+       void (*fct)(struct cds_lfht *ht, unsigned long i,
+                   unsigned long start, unsigned long len);
+};
+
+enum add_mode {
+       ADD_DEFAULT = 0,
+       ADD_UNIQUE = 1,
+       ADD_REPLACE = 2,
+};
+
+static
+struct cds_lfht_node *_cds_lfht_add(struct cds_lfht *ht,
+                               unsigned long size,
+                               struct cds_lfht_node *node,
+                               enum add_mode mode, int dummy);
+
+/*
+ * Algorithm to reverse bits in a word by lookup table, extended to
+ * 64-bit words.
+ * Source:
+ * http://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
+ * Originally from Public Domain.
+ */
+
+static const uint8_t BitReverseTable256[256] = 
+{
+#define R2(n) (n),   (n) + 2*64,     (n) + 1*64,     (n) + 3*64
+#define R4(n) R2(n), R2((n) + 2*16), R2((n) + 1*16), R2((n) + 3*16)
+#define R6(n) R4(n), R4((n) + 2*4 ), R4((n) + 1*4 ), R4((n) + 3*4 )
+       R6(0), R6(2), R6(1), R6(3)
+};
+#undef R2
+#undef R4
+#undef R6
+
+static
+uint8_t bit_reverse_u8(uint8_t v)
+{
+       return BitReverseTable256[v];
+}
+
+static __attribute__((unused))
+uint32_t bit_reverse_u32(uint32_t v)
+{
+       return ((uint32_t) bit_reverse_u8(v) << 24) | 
+               ((uint32_t) bit_reverse_u8(v >> 8) << 16) | 
+               ((uint32_t) bit_reverse_u8(v >> 16) << 8) | 
+               ((uint32_t) bit_reverse_u8(v >> 24));
+}
+
+static __attribute__((unused))
+uint64_t bit_reverse_u64(uint64_t v)
+{
+       return ((uint64_t) bit_reverse_u8(v) << 56) | 
+               ((uint64_t) bit_reverse_u8(v >> 8)  << 48) | 
+               ((uint64_t) bit_reverse_u8(v >> 16) << 40) |
+               ((uint64_t) bit_reverse_u8(v >> 24) << 32) |
+               ((uint64_t) bit_reverse_u8(v >> 32) << 24) | 
+               ((uint64_t) bit_reverse_u8(v >> 40) << 16) | 
+               ((uint64_t) bit_reverse_u8(v >> 48) << 8) |
+               ((uint64_t) bit_reverse_u8(v >> 56));
+}
+
+static
+unsigned long bit_reverse_ulong(unsigned long v)
+{
+#if (CAA_BITS_PER_LONG == 32)
+       return bit_reverse_u32(v);
+#else
+       return bit_reverse_u64(v);
+#endif
+}
+
+/*
+ * fls: returns the position of the most significant bit.
+ * Returns 0 if no bit is set, else returns the position of the most
+ * significant bit (from 1 to 32 on 32-bit, from 1 to 64 on 64-bit).
+ */
+#if defined(__i386) || defined(__x86_64)
+static inline
+unsigned int fls_u32(uint32_t x)
+{
+       int r;
+
+       asm("bsrl %1,%0\n\t"
+           "jnz 1f\n\t"
+           "movl $-1,%0\n\t"
+           "1:\n\t"
+           : "=r" (r) : "rm" (x));
+       return r + 1;
+}
+#define HAS_FLS_U32
+#endif
+
+#if defined(__x86_64)
+static inline
+unsigned int fls_u64(uint64_t x)
+{
+       long r;
+
+       asm("bsrq %1,%0\n\t"
+           "jnz 1f\n\t"
+           "movq $-1,%0\n\t"
+           "1:\n\t"
+           : "=r" (r) : "rm" (x));
+       return r + 1;
+}
+#define HAS_FLS_U64
+#endif
+
+#ifndef HAS_FLS_U64
+static __attribute__((unused))
+unsigned int fls_u64(uint64_t x)
+{
+       unsigned int r = 64;
+
+       if (!x)
+               return 0;
+
+       if (!(x & 0xFFFFFFFF00000000ULL)) {
+               x <<= 32;
+               r -= 32;
+       }
+       if (!(x & 0xFFFF000000000000ULL)) {
+               x <<= 16;
+               r -= 16;
+       }
+       if (!(x & 0xFF00000000000000ULL)) {
+               x <<= 8;
+               r -= 8;
+       }
+       if (!(x & 0xF000000000000000ULL)) {
+               x <<= 4;
+               r -= 4;
+       }
+       if (!(x & 0xC000000000000000ULL)) {
+               x <<= 2;
+               r -= 2;
+       }
+       if (!(x & 0x8000000000000000ULL)) {
+               x <<= 1;
+               r -= 1;
+       }
+       return r;
+}
+#endif
+
+#ifndef HAS_FLS_U32
+static __attribute__((unused))
+unsigned int fls_u32(uint32_t x)
+{
+       unsigned int r = 32;
+
+       if (!x)
+               return 0;
+       if (!(x & 0xFFFF0000U)) {
+               x <<= 16;
+               r -= 16;
+       }
+       if (!(x & 0xFF000000U)) {
+               x <<= 8;
+               r -= 8;
+       }
+       if (!(x & 0xF0000000U)) {
+               x <<= 4;
+               r -= 4;
+       }
+       if (!(x & 0xC0000000U)) {
+               x <<= 2;
+               r -= 2;
+       }
+       if (!(x & 0x80000000U)) {
+               x <<= 1;
+               r -= 1;
+       }
+       return r;
+}
+#endif
+
+unsigned int fls_ulong(unsigned long x)
+{
+#if (CAA_BITS_PER_lONG == 32)
+       return fls_u32(x);
+#else
+       return fls_u64(x);
+#endif
+}
+
+int get_count_order_u32(uint32_t x)
+{
+       int order;
+
+       order = fls_u32(x) - 1;
+       if (x & (x - 1))
+               order++;
+       return order;
+}
+
+int get_count_order_ulong(unsigned long x)
+{
+       int order;
+
+       order = fls_ulong(x) - 1;
+       if (x & (x - 1))
+               order++;
+       return order;
+}
+
+#ifdef POISON_FREE
+#define poison_free(ptr)                               \
+       do {                                            \
+               memset(ptr, 0x42, sizeof(*(ptr)));      \
+               free(ptr);                              \
+       } while (0)
+#else
+#define poison_free(ptr)       free(ptr)
+#endif
+
+static
+void cds_lfht_resize_lazy(struct cds_lfht *ht, unsigned long size, int growth);
+
+/*
+ * If the sched_getcpu() and sysconf(_SC_NPROCESSORS_CONF) calls are
+ * available, then we support hash table item accounting.
+ * In the unfortunate event the number of CPUs reported would be
+ * inaccurate, we use modulo arithmetic on the number of CPUs we got.
+ */
+#if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF)
+
+static
+void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
+                               unsigned long count);
+
+static long nr_cpus_mask = -1;
+
+static
+struct ht_items_count *alloc_per_cpu_items_count(void)
+{
+       struct ht_items_count *count;
+
+       switch (nr_cpus_mask) {
+       case -2:
+               return NULL;
+       case -1:
+       {
+               long maxcpus;
+
+               maxcpus = sysconf(_SC_NPROCESSORS_CONF);
+               if (maxcpus <= 0) {
+                       nr_cpus_mask = -2;
+                       return NULL;
+               }
+               /*
+                * round up number of CPUs to next power of two, so we
+                * can use & for modulo.
+                */
+               maxcpus = 1UL << get_count_order_ulong(maxcpus);
+               nr_cpus_mask = maxcpus - 1;
+       }
+               /* Fall-through */
+       default:
+               return calloc(nr_cpus_mask + 1, sizeof(*count));
+       }
+}
+
+static
+void free_per_cpu_items_count(struct ht_items_count *count)
+{
+       poison_free(count);
+}
+
+static
+int ht_get_cpu(void)
+{
+       int cpu;
+
+       assert(nr_cpus_mask >= 0);
+       cpu = sched_getcpu();
+       if (unlikely(cpu < 0))
+               return cpu;
+       else
+               return cpu & nr_cpus_mask;
+}
+
+static
+void ht_count_add(struct cds_lfht *ht, unsigned long size)
+{
+       unsigned long percpu_count;
+       int cpu;
+
+       if (unlikely(!ht->percpu_count))
+               return;
+       cpu = ht_get_cpu();
+       if (unlikely(cpu < 0))
+               return;
+       percpu_count = uatomic_add_return(&ht->percpu_count[cpu].add, 1);
+       if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 1)))) {
+               long count;
+
+               dbg_printf("add percpu %lu\n", percpu_count);
+               count = uatomic_add_return(&ht->count,
+                                          1UL << COUNT_COMMIT_ORDER);
+               /* If power of 2 */
+               if (!(count & (count - 1))) {
+                       if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) < size)
+                               return;
+                       dbg_printf("add set global %ld\n", count);
+                       cds_lfht_resize_lazy_count(ht, size,
+                               count >> (CHAIN_LEN_TARGET - 1));
+               }
+       }
+}
+
+static
+void ht_count_del(struct cds_lfht *ht, unsigned long size)
+{
+       unsigned long percpu_count;
+       int cpu;
+
+       if (unlikely(!ht->percpu_count))
+               return;
+       cpu = ht_get_cpu();
+       if (unlikely(cpu < 0))
+               return;
+       percpu_count = uatomic_add_return(&ht->percpu_count[cpu].del, 1);
+       if (unlikely(!(percpu_count & ((1UL << COUNT_COMMIT_ORDER) - 1)))) {
+               long count;
+
+               dbg_printf("del percpu %lu\n", percpu_count);
+               count = uatomic_add_return(&ht->count,
+                                          -(1UL << COUNT_COMMIT_ORDER));
+               /* If power of 2 */
+               if (!(count & (count - 1))) {
+                       if ((count >> CHAIN_LEN_RESIZE_THRESHOLD) >= size)
+                               return;
+                       dbg_printf("del set global %ld\n", count);
+                       /*
+                        * Don't shrink table if the number of nodes is below a
+                        * certain threshold.
+                        */
+                       if (count < (1UL << COUNT_COMMIT_ORDER) * (nr_cpus_mask + 1))
+                               return;
+                       cds_lfht_resize_lazy_count(ht, size,
+                               count >> (CHAIN_LEN_TARGET - 1));
+               }
+       }
+}
+
+#else /* #if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF) */
+
+static const long nr_cpus_mask = -1;
+
+static
+struct ht_items_count *alloc_per_cpu_items_count(void)
+{
+       return NULL;
+}
+
+static
+void free_per_cpu_items_count(struct ht_items_count *count)
+{
+}
+
+static
+void ht_count_add(struct cds_lfht *ht, unsigned long size)
+{
+}
+
+static
+void ht_count_del(struct cds_lfht *ht, unsigned long size)
+{
+}
+
+#endif /* #else #if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF) */
+
+
+static
+void check_resize(struct cds_lfht *ht, unsigned long size, uint32_t chain_len)
+{
+       unsigned long count;
+
+       if (!(ht->flags & CDS_LFHT_AUTO_RESIZE))
+               return;
+       count = uatomic_read(&ht->count);
+       /*
+        * Use bucket-local length for small table expand and for
+        * environments lacking per-cpu data support.
+        */
+       if (count >= (1UL << COUNT_COMMIT_ORDER))
+               return;
+       if (chain_len > 100)
+               dbg_printf("WARNING: large chain length: %u.\n",
+                          chain_len);
+       if (chain_len >= CHAIN_LEN_RESIZE_THRESHOLD)
+               cds_lfht_resize_lazy(ht, size,
+                       get_count_order_u32(chain_len - (CHAIN_LEN_TARGET - 1)));
+}
+
+static
+struct cds_lfht_node *clear_flag(struct cds_lfht_node *node)
+{
+       return (struct cds_lfht_node *) (((unsigned long) node) & ~FLAGS_MASK);
+}
+
+static
+int is_removed(struct cds_lfht_node *node)
+{
+       return ((unsigned long) node) & REMOVED_FLAG;
+}
+
+static
+struct cds_lfht_node *flag_removed(struct cds_lfht_node *node)
+{
+       return (struct cds_lfht_node *) (((unsigned long) node) | REMOVED_FLAG);
+}
+
+static
+int is_dummy(struct cds_lfht_node *node)
+{
+       return ((unsigned long) node) & DUMMY_FLAG;
+}
+
+static
+struct cds_lfht_node *flag_dummy(struct cds_lfht_node *node)
+{
+       return (struct cds_lfht_node *) (((unsigned long) node) | DUMMY_FLAG);
+}
+
+static
+struct cds_lfht_node *get_end(void)
+{
+       return (struct cds_lfht_node *) END_VALUE;
+}
+
+static
+int is_end(struct cds_lfht_node *node)
+{
+       return clear_flag(node) == (struct cds_lfht_node *) END_VALUE;
+}
+
+static
+unsigned long _uatomic_max(unsigned long *ptr, unsigned long v)
+{
+       unsigned long old1, old2;
+
+       old1 = uatomic_read(ptr);
+       do {
+               old2 = old1;
+               if (old2 >= v)
+                       return old2;
+       } while ((old1 = uatomic_cmpxchg(ptr, old2, v)) != old2);
+       return v;
+}
+
+static
+void cds_lfht_free_level(struct rcu_head *head)
+{
+       struct rcu_level *l =
+               caa_container_of(head, struct rcu_level, head);
+       poison_free(l);
+}
+
+/*
+ * Remove all logically deleted nodes from a bucket up to a certain node key.
+ */
+static
+void _cds_lfht_gc_bucket(struct cds_lfht_node *dummy, struct cds_lfht_node *node)
+{
+       struct cds_lfht_node *iter_prev, *iter, *next, *new_next;
+
+       assert(!is_dummy(dummy));
+       assert(!is_removed(dummy));
+       assert(!is_dummy(node));
+       assert(!is_removed(node));
+       for (;;) {
+               iter_prev = dummy;
+               /* We can always skip the dummy node initially */
+               iter = rcu_dereference(iter_prev->p.next);
+               assert(iter_prev->p.reverse_hash <= node->p.reverse_hash);
+               /*
+                * We should never be called with dummy (start of chain)
+                * and logically removed node (end of path compression
+                * marker) being the actual same node. This would be a
+                * bug in the algorithm implementation.
+                */
+               assert(dummy != node);
+               for (;;) {
+                       if (unlikely(is_end(iter)))
+                               return;
+                       if (likely(clear_flag(iter)->p.reverse_hash > node->p.reverse_hash))
+                               return;
+                       next = rcu_dereference(clear_flag(iter)->p.next);
+                       if (likely(is_removed(next)))
+                               break;
+                       iter_prev = clear_flag(iter);
+                       iter = next;
+               }
+               assert(!is_removed(iter));
+               if (is_dummy(iter))
+                       new_next = flag_dummy(clear_flag(next));
+               else
+                       new_next = clear_flag(next);
+               if (is_removed(iter))
+                       new_next = flag_removed(new_next);
+               (void) uatomic_cmpxchg(&iter_prev->p.next, iter, new_next);
+       }
+       return;
+}
+
+static
+int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size,
+               struct cds_lfht_node *old_node,
+               struct cds_lfht_node *ret_next,
+               struct cds_lfht_node *new_node)
+{
+       struct cds_lfht_node *dummy, *old_next;
+       struct _cds_lfht_node *lookup;
+       int flagged = 0;
+       unsigned long hash, index, order;
+
+       if (!old_node)  /* Return -ENOENT if asked to replace NULL node */
+               goto end;
+
+       assert(!is_removed(old_node));
+       assert(!is_dummy(old_node));
+       assert(!is_removed(new_node));
+       assert(!is_dummy(new_node));
+       assert(new_node != old_node);
+       do {
+               /* Insert after node to be replaced */
+               old_next = ret_next;
+               if (is_removed(old_next)) {
+                       /*
+                        * Too late, the old node has been removed under us
+                        * between lookup and replace. Fail.
+                        */
+                       goto end;
+               }
+               assert(!is_dummy(old_next));
+               assert(new_node != clear_flag(old_next));
+               new_node->p.next = clear_flag(old_next);
+               /*
+                * Here is the whole trick for lock-free replace: we add
+                * the replacement node _after_ the node we want to
+                * replace by atomically setting its next pointer at the
+                * same time we set its removal flag. Given that
+                * the lookups/get next use an iterator aware of the
+                * next pointer, they will either skip the old node due
+                * to the removal flag and see the new node, or use
+                * the old node, but will not see the new one.
+                */
+               ret_next = uatomic_cmpxchg(&old_node->p.next,
+                             old_next, flag_removed(new_node));
+       } while (ret_next != old_next);
+
+       /* We performed the replacement. */
+       flagged = 1;
+
+       /*
+        * Ensure that the old node is not visible to readers anymore:
+        * lookup for the node, and remove it (along with any other
+        * logically removed node) if found.
+        */
+       hash = bit_reverse_ulong(old_node->p.reverse_hash);
+       assert(size > 0);
+       index = hash & (size - 1);
+       order = get_count_order_ulong(index + 1);
+       lookup = &ht->t.tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
+       dummy = (struct cds_lfht_node *) lookup;
+       _cds_lfht_gc_bucket(dummy, new_node);
+end:
+       /*
+        * Only the flagging action indicated that we (and no other)
+        * replaced the node from the hash table.
+        */
+       if (flagged) {
+               assert(is_removed(rcu_dereference(old_node->p.next)));
+               return 0;
+       } else {
+               return -ENOENT;
+       }
+}
+
+static
+struct cds_lfht_node *_cds_lfht_add(struct cds_lfht *ht,
+                               unsigned long size,
+                               struct cds_lfht_node *node,
+                               enum add_mode mode, int dummy)
+{
+       struct cds_lfht_node *iter_prev, *iter, *next, *new_node, *new_next,
+                       *dummy_node, *return_node;
+       struct _cds_lfht_node *lookup;
+       unsigned long hash, index, order;
+
+       assert(!is_dummy(node));
+       assert(!is_removed(node));
+       if (!size) {
+               assert(dummy);
+               node->p.next = flag_dummy(get_end());
+               return node;    /* Initial first add (head) */
+       }
+       hash = bit_reverse_ulong(node->p.reverse_hash);
+       for (;;) {
+               uint32_t chain_len = 0;
+
+               /*
+                * iter_prev points to the non-removed node prior to the
+                * insert location.
+                */
+               index = hash & (size - 1);
+               order = get_count_order_ulong(index + 1);
+               lookup = &ht->t.tbl[order]->nodes[index & ((!order ? 0 : (1UL << (order - 1))) - 1)];
+               iter_prev = (struct cds_lfht_node *) lookup;
+               /* We can always skip the dummy node initially */
+               iter = rcu_dereference(iter_prev->p.next);
+               assert(iter_prev->p.reverse_hash <= node->p.reverse_hash);
+               for (;;) {
+                       if (unlikely(is_end(iter)))
+                               goto insert;
+                       if (likely(clear_flag(iter)->p.reverse_hash > node->p.reverse_hash))
+                               goto insert;
+                       next = rcu_dereference(clear_flag(iter)->p.next);
+                       if (unlikely(is_removed(next)))
+                               goto gc_node;
+                       if ((mode == ADD_UNIQUE || mode == ADD_REPLACE)
+                           && !is_dummy(next)
+                           && !ht->compare_fct(node->key, node->key_len,
+                                               clear_flag(iter)->key,
+                                               clear_flag(iter)->key_len)) {
+                               if (mode == ADD_UNIQUE)
+                                       return clear_flag(iter);
+                               else /* mode == ADD_REPLACE */
+                                       goto replace;
+                       }
+                       /* Only account for identical reverse hash once */
+                       if (iter_prev->p.reverse_hash != clear_flag(iter)->p.reverse_hash
+                           && !is_dummy(next))
+                               check_resize(ht, size, ++chain_len);
+                       iter_prev = clear_flag(iter);
+                       iter = next;
+               }
+
+       insert:
+               assert(node != clear_flag(iter));
+               assert(!is_removed(iter_prev));
+               assert(!is_removed(iter));
+               assert(iter_prev != node);
+               if (!dummy)
+                       node->p.next = clear_flag(iter);
+               else
+                       node->p.next = flag_dummy(clear_flag(iter));
+               if (is_dummy(iter))
+                       new_node = flag_dummy(node);
+               else
+                       new_node = node;
+               if (uatomic_cmpxchg(&iter_prev->p.next, iter,
+                                   new_node) != iter) {
+                       continue;       /* retry */
+               } else {
+                       if (mode == ADD_REPLACE)
+                               return_node = NULL;
+                       else    /* ADD_DEFAULT and ADD_UNIQUE */
+                               return_node = node;
+                       goto gc_end;
+               }
+
+       replace:
+
+               if (!_cds_lfht_replace(ht, size, clear_flag(iter), next,
+                                   node)) {
+                       return_node = clear_flag(iter);
+                       goto end;       /* gc already done */
+               } else {
+                       continue;       /* retry */
+               }
+
+       gc_node:
+               assert(!is_removed(iter));
+               if (is_dummy(iter))
+                       new_next = flag_dummy(clear_flag(next));
+               else
+                       new_next = clear_flag(next);
+               (void) uatomic_cmpxchg(&iter_prev->p.next, iter, new_next);
+               /* retry */
+       }
+gc_end:
+       /* Garbage collect logically removed nodes in the bucket */
+       index = hash & (size - 1);
+       order = get_count_order_ulong(index + 1);
+       lookup = &ht->t.tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
+       dummy_node = (struct cds_lfht_node *) lookup;
+       _cds_lfht_gc_bucket(dummy_node, node);
+end:
+       return return_node;
+}
+
+static
+int _cds_lfht_del(struct cds_lfht *ht, unsigned long size,
+               struct cds_lfht_node *node,
+               int dummy_removal)
+{
+       struct cds_lfht_node *dummy, *next, *old;
+       struct _cds_lfht_node *lookup;
+       int flagged = 0;
+       unsigned long hash, index, order;
+
+       if (!node)      /* Return -ENOENT if asked to delete NULL node */
+               goto end;
+
+       /* logically delete the node */
+       assert(!is_dummy(node));
+       assert(!is_removed(node));
+       old = rcu_dereference(node->p.next);
+       do {
+               struct cds_lfht_node *new_next;
+
+               next = old;
+               if (unlikely(is_removed(next)))
+                       goto end;
+               if (dummy_removal)
+                       assert(is_dummy(next));
+               else
+                       assert(!is_dummy(next));
+               new_next = flag_removed(next);
+               old = uatomic_cmpxchg(&node->p.next, next, new_next);
+       } while (old != next);
+
+       /* We performed the (logical) deletion. */
+       flagged = 1;
+
+       /*
+        * Ensure that the node is not visible to readers anymore: lookup for
+        * the node, and remove it (along with any other logically removed node)
+        * if found.
+        */
+       hash = bit_reverse_ulong(node->p.reverse_hash);
+       assert(size > 0);
+       index = hash & (size - 1);
+       order = get_count_order_ulong(index + 1);
+       lookup = &ht->t.tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1)) - 1))];
+       dummy = (struct cds_lfht_node *) lookup;
+       _cds_lfht_gc_bucket(dummy, node);
+end:
+       /*
+        * Only the flagging action indicated that we (and no other)
+        * removed the node from the hash.
+        */
+       if (flagged) {
+               assert(is_removed(rcu_dereference(node->p.next)));
+               return 0;
+       } else {
+               return -ENOENT;
+       }
+}
+
+static
+void *partition_resize_thread(void *arg)
+{
+       struct partition_resize_work *work = arg;
+
+       work->ht->cds_lfht_rcu_register_thread();
+       work->fct(work->ht, work->i, work->start, work->len);
+       work->ht->cds_lfht_rcu_unregister_thread();
+       return NULL;
+}
+
+static
+void partition_resize_helper(struct cds_lfht *ht, unsigned long i,
+               unsigned long len,
+               void (*fct)(struct cds_lfht *ht, unsigned long i,
+                       unsigned long start, unsigned long len))
+{
+       unsigned long partition_len;
+       struct partition_resize_work *work;
+       int thread, ret;
+       unsigned long nr_threads;
+       pthread_t *thread_id;
+
+       /*
+        * Note: nr_cpus_mask + 1 is always power of 2.
+        * We spawn just the number of threads we need to satisfy the minimum
+        * partition size, up to the number of CPUs in the system.
+        */
+       nr_threads = min(nr_cpus_mask + 1,
+                        len >> MIN_PARTITION_PER_THREAD_ORDER);
+       partition_len = len >> get_count_order_ulong(nr_threads);
+       work = calloc(nr_threads, sizeof(*work));
+       thread_id = calloc(nr_threads, sizeof(*thread_id));
+       assert(work);
+       for (thread = 0; thread < nr_threads; thread++) {
+               work[thread].ht = ht;
+               work[thread].i = i;
+               work[thread].len = partition_len;
+               work[thread].start = thread * partition_len;
+               work[thread].fct = fct;
+               ret = pthread_create(&thread_id[thread], ht->resize_attr,
+                       partition_resize_thread, &work[thread]);
+               assert(!ret);
+       }
+       for (thread = 0; thread < nr_threads; thread++) {
+               ret = pthread_join(thread_id[thread], NULL);
+               assert(!ret);
+       }
+       free(work);
+       free(thread_id);
+}
+
+/*
+ * Holding RCU read lock to protect _cds_lfht_add against memory
+ * reclaim that could be performed by other call_rcu worker threads (ABA
+ * problem).
+ *
+ * When we reach a certain length, we can split this population phase over
+ * many worker threads, based on the number of CPUs available in the system.
+ * This should therefore take care of not having the expand lagging behind too
+ * many concurrent insertion threads by using the scheduler's ability to
+ * schedule dummy node population fairly with insertions.
+ */
+static
+void init_table_populate_partition(struct cds_lfht *ht, unsigned long i,
+                                  unsigned long start, unsigned long len)
+{
+       unsigned long j;
+
+       ht->cds_lfht_rcu_read_lock();
+       for (j = start; j < start + len; j++) {
+               struct cds_lfht_node *new_node =
+                       (struct cds_lfht_node *) &ht->t.tbl[i]->nodes[j];
+
+               dbg_printf("init populate: i %lu j %lu hash %lu\n",
+                          i, j, !i ? 0 : (1UL << (i - 1)) + j);
+               new_node->p.reverse_hash =
+                       bit_reverse_ulong(!i ? 0 : (1UL << (i - 1)) + j);
+               (void) _cds_lfht_add(ht, !i ? 0 : (1UL << (i - 1)),
+                               new_node, ADD_DEFAULT, 1);
+               if (CMM_LOAD_SHARED(ht->in_progress_destroy))
+                       break;
+       }
+       ht->cds_lfht_rcu_read_unlock();
+}
+
+static
+void init_table_populate(struct cds_lfht *ht, unsigned long i,
+                        unsigned long len)
+{
+       assert(nr_cpus_mask != -1);
+       if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD) {
+               ht->cds_lfht_rcu_thread_online();
+               init_table_populate_partition(ht, i, 0, len);
+               ht->cds_lfht_rcu_thread_offline();
+               return;
+       }
+       partition_resize_helper(ht, i, len, init_table_populate_partition);
+}
+
+static
+void init_table(struct cds_lfht *ht,
+               unsigned long first_order, unsigned long len_order)
+{
+       unsigned long i, end_order;
+
+       dbg_printf("init table: first_order %lu end_order %lu\n",
+                  first_order, first_order + len_order);
+       end_order = first_order + len_order;
+       for (i = first_order; i < end_order; i++) {
+               unsigned long len;
+
+               len = !i ? 1 : 1UL << (i - 1);
+               dbg_printf("init order %lu len: %lu\n", i, len);
+
+               /* Stop expand if the resize target changes under us */
+               if (CMM_LOAD_SHARED(ht->t.resize_target) < (!i ? 1 : (1UL << i)))
+                       break;
+
+               ht->t.tbl[i] = calloc(1, sizeof(struct rcu_level)
+                               + (len * sizeof(struct _cds_lfht_node)));
+               assert(ht->t.tbl[i]);
+
+               /*
+                * Set all dummy nodes reverse hash values for a level and
+                * link all dummy nodes into the table.
+                */
+               init_table_populate(ht, i, len);
+
+               /*
+                * Update table size.
+                */
+               cmm_smp_wmb();  /* populate data before RCU size */
+               CMM_STORE_SHARED(ht->t.size, !i ? 1 : (1UL << i));
+
+               dbg_printf("init new size: %lu\n", !i ? 1 : (1UL << i));
+               if (CMM_LOAD_SHARED(ht->in_progress_destroy))
+                       break;
+       }
+}
+
+/*
+ * Holding RCU read lock to protect _cds_lfht_remove against memory
+ * reclaim that could be performed by other call_rcu worker threads (ABA
+ * problem).
+ * For a single level, we logically remove and garbage collect each node.
+ *
+ * As a design choice, we perform logical removal and garbage collection on a
+ * node-per-node basis to simplify this algorithm. We also assume keeping good
+ * cache locality of the operation would overweight possible performance gain
+ * that could be achieved by batching garbage collection for multiple levels.
+ * However, this would have to be justified by benchmarks.
+ *
+ * Concurrent removal and add operations are helping us perform garbage
+ * collection of logically removed nodes. We guarantee that all logically
+ * removed nodes have been garbage-collected (unlinked) before call_rcu is
+ * invoked to free a hole level of dummy nodes (after a grace period).
+ *
+ * Logical removal and garbage collection can therefore be done in batch or on a
+ * node-per-node basis, as long as the guarantee above holds.
+ *
+ * When we reach a certain length, we can split this removal over many worker
+ * threads, based on the number of CPUs available in the system. This should
+ * take care of not letting resize process lag behind too many concurrent
+ * updater threads actively inserting into the hash table.
+ */
+static
+void remove_table_partition(struct cds_lfht *ht, unsigned long i,
+                           unsigned long start, unsigned long len)
+{
+       unsigned long j;
+
+       ht->cds_lfht_rcu_read_lock();
+       for (j = start; j < start + len; j++) {
+               struct cds_lfht_node *fini_node =
+                       (struct cds_lfht_node *) &ht->t.tbl[i]->nodes[j];
+
+               dbg_printf("remove entry: i %lu j %lu hash %lu\n",
+                          i, j, !i ? 0 : (1UL << (i - 1)) + j);
+               fini_node->p.reverse_hash =
+                       bit_reverse_ulong(!i ? 0 : (1UL << (i - 1)) + j);
+               (void) _cds_lfht_del(ht, !i ? 0 : (1UL << (i - 1)),
+                               fini_node, 1);
+               if (CMM_LOAD_SHARED(ht->in_progress_destroy))
+                       break;
+       }
+       ht->cds_lfht_rcu_read_unlock();
+}
+
+static
+void remove_table(struct cds_lfht *ht, unsigned long i, unsigned long len)
+{
+
+       assert(nr_cpus_mask != -1);
+       if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD) {
+               ht->cds_lfht_rcu_thread_online();
+               remove_table_partition(ht, i, 0, len);
+               ht->cds_lfht_rcu_thread_offline();
+               return;
+       }
+       partition_resize_helper(ht, i, len, remove_table_partition);
+}
+
+static
+void fini_table(struct cds_lfht *ht,
+               unsigned long first_order, unsigned long len_order)
+{
+       long i, end_order;
+
+       dbg_printf("fini table: first_order %lu end_order %lu\n",
+                  first_order, first_order + len_order);
+       end_order = first_order + len_order;
+       assert(first_order > 0);
+       for (i = end_order - 1; i >= first_order; i--) {
+               unsigned long len;
+
+               len = !i ? 1 : 1UL << (i - 1);
+               dbg_printf("fini order %lu len: %lu\n", i, len);
+
+               /* Stop shrink if the resize target changes under us */
+               if (CMM_LOAD_SHARED(ht->t.resize_target) > (1UL << (i - 1)))
+                       break;
+
+               cmm_smp_wmb();  /* populate data before RCU size */
+               CMM_STORE_SHARED(ht->t.size, 1UL << (i - 1));
+
+               /*
+                * We need to wait for all add operations to reach Q.S. (and
+                * thus use the new table for lookups) before we can start
+                * releasing the old dummy nodes. Otherwise their lookup will
+                * return a logically removed node as insert position.
+                */
+               ht->cds_lfht_synchronize_rcu();
+
+               /*
+                * Set "removed" flag in dummy nodes about to be removed.
+                * Unlink all now-logically-removed dummy node pointers.
+                * Concurrent add/remove operation are helping us doing
+                * the gc.
+                */
+               remove_table(ht, i, len);
+
+               ht->cds_lfht_call_rcu(&ht->t.tbl[i]->head, cds_lfht_free_level);
+
+               dbg_printf("fini new size: %lu\n", 1UL << i);
+               if (CMM_LOAD_SHARED(ht->in_progress_destroy))
+                       break;
+       }
+}
+
+struct cds_lfht *_cds_lfht_new(cds_lfht_hash_fct hash_fct,
+                       cds_lfht_compare_fct compare_fct,
+                       unsigned long hash_seed,
+                       unsigned long init_size,
+                       int flags,
+                       void (*cds_lfht_call_rcu)(struct rcu_head *head,
+                                       void (*func)(struct rcu_head *head)),
+                       void (*cds_lfht_synchronize_rcu)(void),
+                       void (*cds_lfht_rcu_read_lock)(void),
+                       void (*cds_lfht_rcu_read_unlock)(void),
+                       void (*cds_lfht_rcu_thread_offline)(void),
+                       void (*cds_lfht_rcu_thread_online)(void),
+                       void (*cds_lfht_rcu_register_thread)(void),
+                       void (*cds_lfht_rcu_unregister_thread)(void),
+                       pthread_attr_t *attr)
+{
+       struct cds_lfht *ht;
+       unsigned long order;
+
+       /* init_size must be power of two */
+       if (init_size && (init_size & (init_size - 1)))
+               return NULL;
+       ht = calloc(1, sizeof(struct cds_lfht));
+       assert(ht);
+       ht->hash_fct = hash_fct;
+       ht->compare_fct = compare_fct;
+       ht->hash_seed = hash_seed;
+       ht->cds_lfht_call_rcu = cds_lfht_call_rcu;
+       ht->cds_lfht_synchronize_rcu = cds_lfht_synchronize_rcu;
+       ht->cds_lfht_rcu_read_lock = cds_lfht_rcu_read_lock;
+       ht->cds_lfht_rcu_read_unlock = cds_lfht_rcu_read_unlock;
+       ht->cds_lfht_rcu_thread_offline = cds_lfht_rcu_thread_offline;
+       ht->cds_lfht_rcu_thread_online = cds_lfht_rcu_thread_online;
+       ht->cds_lfht_rcu_register_thread = cds_lfht_rcu_register_thread;
+       ht->cds_lfht_rcu_unregister_thread = cds_lfht_rcu_unregister_thread;
+       ht->resize_attr = attr;
+       ht->percpu_count = alloc_per_cpu_items_count();
+       /* this mutex should not nest in read-side C.S. */
+       pthread_mutex_init(&ht->resize_mutex, NULL);
+       order = get_count_order_ulong(max(init_size, MIN_TABLE_SIZE)) + 1;
+       ht->flags = flags;
+       ht->cds_lfht_rcu_thread_offline();
+       pthread_mutex_lock(&ht->resize_mutex);
+       ht->t.resize_target = 1UL << (order - 1);
+       init_table(ht, 0, order);
+       pthread_mutex_unlock(&ht->resize_mutex);
+       ht->cds_lfht_rcu_thread_online();
+       return ht;
+}
+
+void cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key_len,
+               struct cds_lfht_iter *iter)
+{
+       struct cds_lfht_node *node, *next, *dummy_node;
+       struct _cds_lfht_node *lookup;
+       unsigned long hash, reverse_hash, index, order, size;
+
+       hash = ht->hash_fct(key, key_len, ht->hash_seed);
+       reverse_hash = bit_reverse_ulong(hash);
+
+       size = rcu_dereference(ht->t.size);
+       index = hash & (size - 1);
+       order = get_count_order_ulong(index + 1);
+       lookup = &ht->t.tbl[order]->nodes[index & (!order ? 0 : ((1UL << (order - 1))) - 1)];
+       dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n",
+                  hash, index, order, index & (!order ? 0 : ((1UL << (order - 1)) - 1)));
+       dummy_node = (struct cds_lfht_node *) lookup;
+       /* We can always skip the dummy node initially */
+       node = rcu_dereference(dummy_node->p.next);
+       node = clear_flag(node);
+       for (;;) {
+               if (unlikely(is_end(node))) {
+                       node = next = NULL;
+                       break;
+               }
+               if (unlikely(node->p.reverse_hash > reverse_hash)) {
+                       node = next = NULL;
+                       break;
+               }
+               next = rcu_dereference(node->p.next);
+               if (likely(!is_removed(next))
+                   && !is_dummy(next)
+                   && likely(!ht->compare_fct(node->key, node->key_len, key, key_len))) {
+                               break;
+               }
+               node = clear_flag(next);
+       }
+       assert(!node || !is_dummy(rcu_dereference(node->p.next)));
+       iter->node = node;
+       iter->next = next;
+}
+
+void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+{
+       struct cds_lfht_node *node, *next;
+       unsigned long reverse_hash;
+       void *key;
+       size_t key_len;
+
+       node = iter->node;
+       reverse_hash = node->p.reverse_hash;
+       key = node->key;
+       key_len = node->key_len;
+       next = iter->next;
+       node = clear_flag(next);
+
+       for (;;) {
+               if (unlikely(is_end(node))) {
+                       node = next = NULL;
+                       break;
+               }
+               if (unlikely(node->p.reverse_hash > reverse_hash)) {
+                       node = next = NULL;
+                       break;
+               }
+               next = rcu_dereference(node->p.next);
+               if (likely(!is_removed(next))
+                   && !is_dummy(next)
+                   && likely(!ht->compare_fct(node->key, node->key_len, key, key_len))) {
+                               break;
+               }
+               node = clear_flag(next);
+       }
+       assert(!node || !is_dummy(rcu_dereference(node->p.next)));
+       iter->node = node;
+       iter->next = next;
+}
+
+void cds_lfht_add(struct cds_lfht *ht, struct cds_lfht_node *node)
+{
+       unsigned long hash, size;
+
+       hash = ht->hash_fct(node->key, node->key_len, ht->hash_seed);
+       node->p.reverse_hash = bit_reverse_ulong((unsigned long) hash);
+
+       size = rcu_dereference(ht->t.size);
+       (void) _cds_lfht_add(ht, size, node, ADD_DEFAULT, 0);
+       ht_count_add(ht, size);
+}
+
+struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
+                               struct cds_lfht_node *node)
+{
+       unsigned long hash, size;
+       struct cds_lfht_node *ret;
+
+       hash = ht->hash_fct(node->key, node->key_len, ht->hash_seed);
+       node->p.reverse_hash = bit_reverse_ulong((unsigned long) hash);
+
+       size = rcu_dereference(ht->t.size);
+       ret = _cds_lfht_add(ht, size, node, ADD_UNIQUE, 0);
+       if (ret == node)
+               ht_count_add(ht, size);
+       return ret;
+}
+
+struct cds_lfht_node *cds_lfht_add_replace(struct cds_lfht *ht,
+                               struct cds_lfht_node *node)
+{
+       unsigned long hash, size;
+       struct cds_lfht_node *ret;
+
+       hash = ht->hash_fct(node->key, node->key_len, ht->hash_seed);
+       node->p.reverse_hash = bit_reverse_ulong((unsigned long) hash);
+
+       size = rcu_dereference(ht->t.size);
+       ret = _cds_lfht_add(ht, size, node, ADD_REPLACE, 0);
+       if (ret == NULL)
+               ht_count_add(ht, size);
+       return ret;
+}
+
+int cds_lfht_replace(struct cds_lfht *ht, struct cds_lfht_iter *old_iter,
+               struct cds_lfht_node *new_node)
+{
+       unsigned long size;
+
+       size = rcu_dereference(ht->t.size);
+       return _cds_lfht_replace(ht, size, old_iter->node, old_iter->next,
+                       new_node);
+}
+
+int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_iter *iter)
+{
+       unsigned long size;
+       int ret;
+
+       size = rcu_dereference(ht->t.size);
+       ret = _cds_lfht_del(ht, size, iter->node, 0);
+       if (!ret)
+               ht_count_del(ht, size);
+       return ret;
+}
+
+static
+int cds_lfht_delete_dummy(struct cds_lfht *ht)
+{
+       struct cds_lfht_node *node;
+       struct _cds_lfht_node *lookup;
+       unsigned long order, i, size;
+
+       /* Check that the table is empty */
+       lookup = &ht->t.tbl[0]->nodes[0];
+       node = (struct cds_lfht_node *) lookup;
+       do {
+               node = clear_flag(node)->p.next;
+               if (!is_dummy(node))
+                       return -EPERM;
+               assert(!is_removed(node));
+       } while (!is_end(node));
+       /*
+        * size accessed without rcu_dereference because hash table is
+        * being destroyed.
+        */
+       size = ht->t.size;
+       /* Internal sanity check: all nodes left should be dummy */
+       for (order = 0; order < get_count_order_ulong(size) + 1; order++) {
+               unsigned long len;
+
+               len = !order ? 1 : 1UL << (order - 1);
+               for (i = 0; i < len; i++) {
+                       dbg_printf("delete order %lu i %lu hash %lu\n",
+                               order, i,
+                               bit_reverse_ulong(ht->t.tbl[order]->nodes[i].reverse_hash));
+                       assert(is_dummy(ht->t.tbl[order]->nodes[i].next));
+               }
+               poison_free(ht->t.tbl[order]);
+       }
+       return 0;
+}
+
+/*
+ * Should only be called when no more concurrent readers nor writers can
+ * possibly access the table.
+ */
+int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr)
+{
+       int ret;
+
+       /* Wait for in-flight resize operations to complete */
+       CMM_STORE_SHARED(ht->in_progress_destroy, 1);
+       while (uatomic_read(&ht->in_progress_resize))
+               poll(NULL, 0, 100);     /* wait for 100ms */
+       ret = cds_lfht_delete_dummy(ht);
+       if (ret)
+               return ret;
+       free_per_cpu_items_count(ht->percpu_count);
+       if (attr)
+               *attr = ht->resize_attr;
+       poison_free(ht);
+       return ret;
+}
+
+void cds_lfht_count_nodes(struct cds_lfht *ht,
+               long *approx_before,
+               unsigned long *count,
+               unsigned long *removed,
+               long *approx_after)
+{
+       struct cds_lfht_node *node, *next;
+       struct _cds_lfht_node *lookup;
+       unsigned long nr_dummy = 0;
+
+       *approx_before = 0;
+       if (nr_cpus_mask >= 0) {
+               int i;
+
+               for (i = 0; i < nr_cpus_mask + 1; i++) {
+                       *approx_before += uatomic_read(&ht->percpu_count[i].add);
+                       *approx_before -= uatomic_read(&ht->percpu_count[i].del);
+               }
+       }
+
+       *count = 0;
+       *removed = 0;
+
+       /* Count non-dummy nodes in the table */
+       lookup = &ht->t.tbl[0]->nodes[0];
+       node = (struct cds_lfht_node *) lookup;
+       do {
+               next = rcu_dereference(node->p.next);
+               if (is_removed(next)) {
+                       if (!is_dummy(next))
+                               (*removed)++;
+                       else
+                               (nr_dummy)++;
+               } else if (!is_dummy(next))
+                       (*count)++;
+               else
+                       (nr_dummy)++;
+               node = clear_flag(next);
+       } while (!is_end(node));
+       dbg_printf("number of dummy nodes: %lu\n", nr_dummy);
+       *approx_after = 0;
+       if (nr_cpus_mask >= 0) {
+               int i;
+
+               for (i = 0; i < nr_cpus_mask + 1; i++) {
+                       *approx_after += uatomic_read(&ht->percpu_count[i].add);
+                       *approx_after -= uatomic_read(&ht->percpu_count[i].del);
+               }
+       }
+}
+
+/* called with resize mutex held */
+static
+void _do_cds_lfht_grow(struct cds_lfht *ht,
+               unsigned long old_size, unsigned long new_size)
+{
+       unsigned long old_order, new_order;
+
+       old_order = get_count_order_ulong(old_size) + 1;
+       new_order = get_count_order_ulong(new_size) + 1;
+       printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n",
+              old_size, old_order, new_size, new_order);
+       assert(new_size > old_size);
+       init_table(ht, old_order, new_order - old_order);
+}
+
+/* called with resize mutex held */
+static
+void _do_cds_lfht_shrink(struct cds_lfht *ht,
+               unsigned long old_size, unsigned long new_size)
+{
+       unsigned long old_order, new_order;
+
+       new_size = max(new_size, MIN_TABLE_SIZE);
+       old_order = get_count_order_ulong(old_size) + 1;
+       new_order = get_count_order_ulong(new_size) + 1;
+       printf("resize from %lu (order %lu) to %lu (order %lu) buckets\n",
+              old_size, old_order, new_size, new_order);
+       assert(new_size < old_size);
+
+       /* Remove and unlink all dummy nodes to remove. */
+       fini_table(ht, new_order, old_order - new_order);
+}
+
+
+/* called with resize mutex held */
+static
+void _do_cds_lfht_resize(struct cds_lfht *ht)
+{
+       unsigned long new_size, old_size;
+
+       /*
+        * Resize table, re-do if the target size has changed under us.
+        */
+       do {
+               ht->t.resize_initiated = 1;
+               old_size = ht->t.size;
+               new_size = CMM_LOAD_SHARED(ht->t.resize_target);
+               if (old_size < new_size)
+                       _do_cds_lfht_grow(ht, old_size, new_size);
+               else if (old_size > new_size)
+                       _do_cds_lfht_shrink(ht, old_size, new_size);
+               ht->t.resize_initiated = 0;
+               /* write resize_initiated before read resize_target */
+               cmm_smp_mb();
+       } while (ht->t.size != CMM_LOAD_SHARED(ht->t.resize_target));
+}
+
+static
+unsigned long resize_target_update(struct cds_lfht *ht, unsigned long size,
+                                  int growth_order)
+{
+       return _uatomic_max(&ht->t.resize_target,
+                           size << growth_order);
+}
+
+static
+void resize_target_update_count(struct cds_lfht *ht,
+                               unsigned long count)
+{
+       count = max(count, MIN_TABLE_SIZE);
+       uatomic_set(&ht->t.resize_target, count);
+}
+
+void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size)
+{
+       resize_target_update_count(ht, new_size);
+       CMM_STORE_SHARED(ht->t.resize_initiated, 1);
+       ht->cds_lfht_rcu_thread_offline();
+       pthread_mutex_lock(&ht->resize_mutex);
+       _do_cds_lfht_resize(ht);
+       pthread_mutex_unlock(&ht->resize_mutex);
+       ht->cds_lfht_rcu_thread_online();
+}
+
+static
+void do_resize_cb(struct rcu_head *head)
+{
+       struct rcu_resize_work *work =
+               caa_container_of(head, struct rcu_resize_work, head);
+       struct cds_lfht *ht = work->ht;
+
+       ht->cds_lfht_rcu_thread_offline();
+       pthread_mutex_lock(&ht->resize_mutex);
+       _do_cds_lfht_resize(ht);
+       pthread_mutex_unlock(&ht->resize_mutex);
+       ht->cds_lfht_rcu_thread_online();
+       poison_free(work);
+       cmm_smp_mb();   /* finish resize before decrement */
+       uatomic_dec(&ht->in_progress_resize);
+}
+
+static
+void cds_lfht_resize_lazy(struct cds_lfht *ht, unsigned long size, int growth)
+{
+       struct rcu_resize_work *work;
+       unsigned long target_size;
+
+       target_size = resize_target_update(ht, size, growth);
+       /* Store resize_target before read resize_initiated */
+       cmm_smp_mb();
+       if (!CMM_LOAD_SHARED(ht->t.resize_initiated) && size < target_size) {
+               uatomic_inc(&ht->in_progress_resize);
+               cmm_smp_mb();   /* increment resize count before calling it */
+               work = malloc(sizeof(*work));
+               work->ht = ht;
+               ht->cds_lfht_call_rcu(&work->head, do_resize_cb);
+               CMM_STORE_SHARED(ht->t.resize_initiated, 1);
+       }
+}
+
+#if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF)
+
+static
+void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
+                               unsigned long count)
+{
+       struct rcu_resize_work *work;
+
+       if (!(ht->flags & CDS_LFHT_AUTO_RESIZE))
+               return;
+       resize_target_update_count(ht, count);
+       /* Store resize_target before read resize_initiated */
+       cmm_smp_mb();
+       if (!CMM_LOAD_SHARED(ht->t.resize_initiated)) {
+               uatomic_inc(&ht->in_progress_resize);
+               cmm_smp_mb();   /* increment resize count before calling it */
+               work = malloc(sizeof(*work));
+               work->ht = ht;
+               ht->cds_lfht_call_rcu(&work->head, do_resize_cb);
+               CMM_STORE_SHARED(ht->t.resize_initiated, 1);
+       }
+}
+
+#endif
diff --git a/hashtable/rculfhash.h b/hashtable/rculfhash.h
new file mode 100644 (file)
index 0000000..860ef3d
--- /dev/null
@@ -0,0 +1,296 @@
+#ifndef _URCU_RCULFHASH_H
+#define _URCU_RCULFHASH_H
+
+/*
+ * urcu/rculfhash.h
+ *
+ * Userspace RCU library - Lock-Free RCU Hash Table
+ *
+ * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 this file _after_ including your URCU flavor.
+ */
+
+#include <stdint.h>
+#include <urcu-call-rcu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * struct cds_lfht_node and struct _cds_lfht_node should be aligned on
+ * 4-bytes boundaries because the two lower bits are used as flags.
+ */
+
+struct _cds_lfht_node {
+       struct cds_lfht_node *next;     /* ptr | DUMMY_FLAG | REMOVED_FLAG */
+       unsigned long reverse_hash;
+} __attribute__((aligned(4)));
+
+struct cds_lfht_node {
+       /* cache-hot for iteration */
+       struct _cds_lfht_node p;          /* needs to be first field */
+       void *key;
+       unsigned int key_len;
+       /* cache-cold for iteration */
+       struct rcu_head head;
+};
+
+struct cds_lfht_iter {
+       struct cds_lfht_node *node, *next;
+};
+
+static inline
+struct cds_lfht_node *cds_lfht_iter_get_node(struct cds_lfht_iter *iter)
+{
+       return iter->node;
+}
+
+struct cds_lfht;
+
+/*
+ * Caution !
+ * Ensure reader and writer threads are registered as urcu readers.
+ */
+
+typedef unsigned long (*cds_lfht_hash_fct)(void *key, size_t length,
+                                       unsigned long seed);
+typedef unsigned long (*cds_lfht_compare_fct)(void *key1, size_t key1_len,
+                                       void *key2, size_t key2_len);
+
+/*
+ * cds_lfht_node_init - initialize a hash table node
+ */
+static inline
+void cds_lfht_node_init(struct cds_lfht_node *node, void *key,
+                       size_t key_len)
+{
+       node->key = key;
+       node->key_len = key_len;
+}
+
+/*
+ * Hash table creation flags.
+ */
+enum {
+       CDS_LFHT_AUTO_RESIZE = (1U << 0),
+};
+
+/*
+ * _cds_lfht_new - API used by cds_lfht_new wrapper. Do not use directly.
+ */
+struct cds_lfht *_cds_lfht_new(cds_lfht_hash_fct hash_fct,
+                       cds_lfht_compare_fct compare_fct,
+                       unsigned long hash_seed,
+                       unsigned long init_size,
+                       int flags,
+                       void (*cds_lfht_call_rcu)(struct rcu_head *head,
+                               void (*func)(struct rcu_head *head)),
+                       void (*cds_lfht_synchronize_rcu)(void),
+                       void (*cds_lfht_rcu_read_lock)(void),
+                       void (*cds_lfht_rcu_read_unlock)(void),
+                       void (*cds_lfht_rcu_thread_offline)(void),
+                       void (*cds_lfht_rcu_thread_online)(void),
+                       void (*cds_lfht_rcu_register_thread)(void),
+                       void (*cds_lfht_rcu_unregister_thread)(void),
+                       pthread_attr_t *attr);
+
+/*
+ * cds_lfht_new - allocate a hash table.
+ * @hash_fct: the hashing function.
+ * @compare_fct: the key comparison function.
+ * @hash_seed: the seed for hash function.
+ * @init_size: number of nodes to allocate initially. Must be power of two.
+ * @flags: hash table creation flags (can be combined with bitwise or: '|').
+ *           0: no flags.
+ *           CDS_LFHT_AUTO_RESIZE: automatically resize hash table.
+ * @attr: optional resize worker thread attributes. NULL for default.
+ *
+ * Return NULL on error.
+ * Note: the RCU flavor must be already included before the hash table header.
+ *
+ * The programmer is responsible for ensuring that resize operation has a
+ * priority equal to hash table updater threads. It should be performed by
+ * specifying the appropriate priority in the pthread "attr" argument, and,
+ * for CDS_LFHT_AUTO_RESIZE, by ensuring that call_rcu worker threads also have
+ * this priority level. Having lower priority for call_rcu and resize threads
+ * does not pose any correctness issue, but the resize operations could be
+ * starved by updates, thus leading to long hash table bucket chains.
+ */
+static inline
+struct cds_lfht *cds_lfht_new(cds_lfht_hash_fct hash_fct,
+                       cds_lfht_compare_fct compare_fct,
+                       unsigned long hash_seed,
+                       unsigned long init_size,
+                       int flags,
+                       pthread_attr_t *attr)
+{
+       return _cds_lfht_new(hash_fct, compare_fct, hash_seed,
+                       init_size, flags,
+                       call_rcu, synchronize_rcu, rcu_read_lock,
+                       rcu_read_unlock, rcu_thread_offline,
+                       rcu_thread_online, rcu_register_thread,
+                       rcu_unregister_thread, attr);
+}
+
+/*
+ * cds_lfht_destroy - destroy a hash table.
+ * @ht: the hash table to destroy.
+ * @attr: (output) resize worker thread attributes, as received by cds_lfht_new.
+ *        The caller will typically want to free this pointer if dynamically
+ *        allocated.
+ *
+ * Return 0 on success, negative error value on error.
+ */
+int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr);
+
+/*
+ * cds_lfht_count_nodes - count the number of nodes in the hash table.
+ *
+ * Call with rcu_read_lock held.
+ */
+void cds_lfht_count_nodes(struct cds_lfht *ht,
+               long *approx_before,
+               unsigned long *count,
+               unsigned long *removed,
+               long *approx_after);
+
+/*
+ * cds_lfht_lookup - lookup a node by key.
+ *
+ * Output in "*iter". *iter->node set to NULL if not found.
+ * Call with rcu_read_lock held.
+ */
+void cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key_len,
+               struct cds_lfht_iter *iter);
+
+/*
+ * cds_lfht_next - get the next item with same key (after a lookup).
+ *
+ * Uses an iterator initialized by a lookup.
+ * Sets *iter-node to the following node with same key.
+ * Sets *iter->node to NULL if no following node exists with same key.
+ * RCU read-side lock must be held across cds_lfht_lookup and
+ * cds_lfht_next calls, and also between cds_lfht_next calls using the
+ * node returned by a previous cds_lfht_next.
+ * Call with rcu_read_lock held.
+ */
+void cds_lfht_next(struct cds_lfht *ht, struct cds_lfht_iter *iter);
+
+/*
+ * cds_lfht_add - add a node to the hash table.
+ *
+ * Call with rcu_read_lock held.
+ * This function supports adding redundant keys into the table.
+ */
+void cds_lfht_add(struct cds_lfht *ht, struct cds_lfht_node *node);
+
+/*
+ * cds_lfht_add_unique - add a node to hash table, if key is not present.
+ *
+ * Return the node added upon success.
+ * Return the unique node already present upon failure. If
+ * cds_lfht_add_unique fails, the node passed as parameter should be
+ * freed by the caller.
+ * Call with rcu_read_lock held.
+ *
+ * The semantic of this function is that if only this function is used
+ * to add keys into the table, no duplicated keys should ever be
+ * observable in the table. The same guarantee apply for combination of
+ * add_unique and add_replace (see below).
+ */
+struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
+               struct cds_lfht_node *node);
+
+/*
+ * cds_lfht_add_replace - replace or add a node within hash table.
+ *
+ * Return the node replaced upon success. If no node matching the key
+ * was present, return NULL, which also means the operation succeeded.
+ * This replacement operation should never fail.
+ * Call with rcu_read_lock held.
+ * After successful replacement, a grace period must be waited for before
+ * freeing the memory reserved for the returned node.
+ *
+ * The semantic of replacement vs lookups is the following: if lookups
+ * are performed between a key unique insertion and its removal, we
+ * guarantee that the lookups and get next will always find exactly one
+ * instance of the key if it is replaced concurrently with the lookups.
+ *
+ * Providing this semantic allows us to ensure that replacement-only
+ * schemes will never generate duplicated keys. It also allows us to
+ * guarantee that a combination of add_replace and add_unique updates
+ * will never generate duplicated keys.
+ */
+struct cds_lfht_node *cds_lfht_add_replace(struct cds_lfht *ht,
+               struct cds_lfht_node *node);
+
+/*
+ * cds_lfht_replace - replace a node pointer to by iter within hash table.
+ *
+ * Return 0 if replacement is successful, negative value otherwise.
+ * Replacing a NULL old node or an already removed node will fail with a
+ * negative value.
+ * Old node can be looked up with cds_lfht_lookup and cds_lfht_next.
+ * RCU read-side lock must be held between lookup and replacement.
+ * Call with rcu_read_lock held.
+ * After successful replacement, a grace period must be waited for before
+ * freeing the memory reserved for the old node (which can be accessed
+ * with cds_lfht_iter_get_node).
+ *
+ * The semantic of replacement vs lookups is the following: if lookups
+ * are performed between a key unique insertion and its removal, we
+ * guarantee that the lookups and get next will always find exactly one
+ * instance of the key if it is replaced concurrently with the lookups.
+ *
+ * Providing this semantic allows us to ensure that replacement-only
+ * schemes will never generate duplicated keys. It also allows us to
+ * guarantee that a combination of add_replace and add_unique updates
+ * will never generate duplicated keys.
+ */
+int cds_lfht_replace(struct cds_lfht *ht, struct cds_lfht_iter *old_iter,
+               struct cds_lfht_node *new_node);
+
+/*
+ * cds_lfht_del - remove node pointed to by iterator from hash table.
+ *
+ * Return 0 if the node is successfully removed, negative value
+ * otherwise.
+ * Replacing a NULL node or an already removed node will fail with a
+ * negative value.
+ * Node can be looked up with cds_lfht_lookup and cds_lfht_next.
+ * cds_lfht_iter_get_node.
+ * RCU read-side lock must be held between lookup and removal.
+ * Call with rcu_read_lock held.
+ * After successful removal, a grace period must be waited for before
+ * freeing the memory reserved for old node (which can be accessed with
+ * cds_lfht_iter_get_node).
+ */
+int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_iter *iter);
+
+/*
+ * cds_lfht_resize - Force a hash table resize
+ * @new_size: update to this hash table size.
+ */
+void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _URCU_RCULFHASH_H */
index e27f4ed6fac50b027febe3297a79684deba15f29..f8308505c712c915f3a2e17119ec2dea5c3c15c6 100644 (file)
@@ -94,6 +94,7 @@ enum lttcomm_return_code {
        LTTCOMM_EXIST_SESS,                             /* Session name already exist */
        LTTCOMM_NO_EVENT,                               /* No event found */
        LTTCOMM_CONNECT_FAIL,           /* Unable to connect to unix socket */
+       LTTCOMM_APP_NOT_FOUND,          /* App not found in traceable app list */
        LTTCOMM_KERN_NA,                                /* Kernel tracer unavalable */
        LTTCOMM_KERN_EVENT_EXIST,       /* Kernel event already exists */
        LTTCOMM_KERN_SESS_FAIL,                 /* Kernel create session failed */
@@ -114,6 +115,8 @@ enum lttcomm_return_code {
        LTTCOMM_KERN_NO_SESSION,                /* No kernel session found */
        LTTCOMM_KERN_LIST_FAIL,                 /* Kernel listing events failed */
        LTTCOMM_UST_SESS_FAIL,                  /* UST create session failed */
+       LTTCOMM_UST_CHAN_NOT_FOUND,     /* UST channel not found */
+       LTTCOMM_UST_CHAN_FAIL,          /* UST create channel failed */
        KCONSUMERD_COMMAND_SOCK_READY,  /* when kconsumerd command socket ready */
        KCONSUMERD_SUCCESS_RECV_FD,             /* success on receiving fds */
        KCONSUMERD_ERROR_RECV_FD,               /* error on receiving fds */
@@ -228,6 +231,12 @@ struct lttcomm_ust_reply {
        uint32_t ret_code;      /* enum lttcomm_return_code */
        uint32_t ret_val;       /* return value */
        union {
+               struct {
+                       uint64_t memory_map_size;
+               } channel;
+               struct {
+                       uint64_t memory_map_size;
+               } stream;
        } u;
 };
 
index 5154b90a559c33e1c07dbecc90c0e02041ba4bf2..78abff6ae7c2e34b4f515b0be09385fc5507a9b6 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <stdlib.h>
 
+#include <lttng/lttng.h>
+
 /* Default channel attributes */
 #define DEFAULT_CHANNEL_NAME            "channel0"
 #define DEFAULT_CHANNEL_OVERWRITE       0       /* usec */
 /* See lttng-kernel.h enum lttng_kernel_output for channel output */
 #define DEFAULT_KERNEL_CHANNEL_OUTPUT       LTTNG_EVENT_SPLICE
 
+/* User space defaults */
+
+/* Must be a power of 2 */
+#define DEFAULT_UST_CHANNEL_SUBBUF_SIZE     4096    /* bytes */
+/* Must be a power of 2 */
+#define DEFAULT_UST_CHANNEL_SUBBUF_NUM      4
+/* See lttng-ust.h enum lttng_ust_output */
+#define DEFAULT_UST_CHANNEL_OUTPUT          LTTNG_UST_MMAP
+
 /*
  * Takes a pointer x and transform it so we can use it to access members
  * without a function call. Here an example:
index abfd613b9b982c297bb186c455eab94e7b5cd9bc..b7143f871ba1510d94191e412ffe6b95ad82ccd4 100644 (file)
@@ -19,9 +19,6 @@
 #define LTTNG_UST_COMM_VERSION_MAJOR   0
 #define LTTNG_UST_COMM_VERSION_MINOR   1
 
-/* See lttng-ust.h enum lttng_ust_output */
-#define DEFAULT_UST_CHANNEL_OUTPUT     LTTNG_UST_MMAP
-
 enum lttng_ust_instrumentation {
        LTTNG_UST_TRACEPOINT    = 0,
        LTTNG_UST_PROBE         = 1,
@@ -45,6 +42,10 @@ struct lttng_ust_channel {
        unsigned int switch_timer_interval;     /* usecs */
        unsigned int read_timer_interval;       /* usecs */
        enum lttng_ust_output output;           /* output mode */
+       /* The following fields are used internally within UST. */
+       int shm_fd;
+       int wait_fd;
+       uint64_t memory_map_size;
 };
 
 struct lttng_ust_event {
index 06a4b77f08c809c56c6cee4b4f45e670ffa1586a..3c066cd3b9d5c01eb0b7b3d5f84a81feca4982cf 100644 (file)
@@ -52,6 +52,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_SELECT_SESS) ] = "A session MUST be selected",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_EXIST_SESS) ] = "Session name already exist",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_CONNECT_FAIL) ] = "Unable to connect to Unix socket",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_APP_NOT_FOUND) ] = "Application not found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NA) ] = "Kernel tracer not available",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_EVENT_EXIST) ] = "Kernel event already exists",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
@@ -72,6 +73,8 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NO_SESSION) ] = "No kernel session found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_LIST_FAIL) ] = "Listing kernel events failed",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_SESS_FAIL) ] = "UST create session failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CHAN_NOT_FOUND) ] = "UST channel not found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CHAN_FAIL) ] = "UST create channel failed",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds",
        [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds",
index 2e53f9a2dc00b5a123641e0a2314ec0418c78c87..1893e0ae66a2f110150b7e6aa219d32771c0b0c6 100644 (file)
@@ -245,12 +245,16 @@ static int kconsumerd_consumerd_recv_fd(
                enum lttng_kconsumerd_command cmd_type)
 {
        struct iovec iov[1];
-       int ret = 0, i, tmp2;
+       int ret = 0, i, j, tmp2;
        struct cmsghdr *cmsg;
        int nb_fd;
        char recv_fd[CMSG_SPACE(sizeof(int))];
        struct lttcomm_kconsumerd_msg lkm;
        struct lttng_kconsumerd_fd *new_fd;
+       union {
+               unsigned char vc[4];
+               int vi;
+       } tmp;
 
        /* the number of fds we are about to receive */
        nb_fd = size / sizeof(struct lttcomm_kconsumerd_msg);
@@ -298,10 +302,10 @@ static int kconsumerd_consumerd_recv_fd(
                if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
                        switch (cmd_type) {
                                case ADD_STREAM:
-                                       DBG("kconsumerd_add_fd %s (%d)", lkm.path_name,
-                                                       ((int *) CMSG_DATA(cmsg))[0]);
-
-                                       new_fd = kconsumerd_allocate_fd(&lkm, ((int *) CMSG_DATA(cmsg))[0]);
+                                       for (j = 0; j < sizeof(int); j++)
+                                               tmp.vc[j] = CMSG_DATA(cmsg)[j];
+                                       DBG("kconsumerd_add_fd %s (%d)", lkm.path_name, tmp.vi);
+                                       new_fd = kconsumerd_allocate_fd(&lkm, tmp.vi);
                                        if (new_fd == NULL) {
                                                lttng_kconsumerd_send_error(ctx, KCONSUMERD_OUTFD_ERROR);
                                                goto end;
index 03354d5f6fca02eec7920c84a85aa416ead70a31..3f2430fd50036c3d82522550c66e294d6f25064e 100644 (file)
@@ -25,7 +25,9 @@ ltt_sessiond_SOURCES = utils.c utils.h \
                        futex.c futex.h \
                        shm.c shm.h \
                        session.c session.h \
-                       ltt-sessiond.h main.c
+                       ltt-sessiond.h main.c \
+                       ../hashtable/rculfhash.c \
+                       ../hashtable/rculfhash.h
 
 # link on liblttngctl for check if sessiond is already alive.
 ltt_sessiond_LDADD = -lrt \
index ab9bf6c6d4fcbafbbe48d085b0143de0949e76f4..818f6dcfd476d7d586a480da6ebd2219d7709729 100644 (file)
 
 #include "channel.h"
 #include "kernel-ctl.h"
+#include "ust-ctl.h"
 #include "utils.h"
 
 /*
  * Return allocated channel attributes.
  */
-static struct lttng_channel *init_default_attr(int dom, char *name)
+static struct lttng_channel *init_default_attr(int dom)
 {
        struct lttng_channel *chan;
 
@@ -38,8 +39,9 @@ static struct lttng_channel *init_default_attr(int dom, char *name)
                goto error_alloc;
        }
 
-       if (snprintf(chan->name, sizeof(chan->name), "%s", name) < 0) {
-               perror("snprintf channel name");
+       if (snprintf(chan->name, sizeof(chan->name), "%s",
+                               DEFAULT_CHANNEL_NAME) < 0) {
+               perror("snprintf default channel name");
                goto error;
        }
 
@@ -53,7 +55,11 @@ static struct lttng_channel *init_default_attr(int dom, char *name)
                        chan->attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
                        chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
                        break;
-                       /* TODO: add UST */
+               case LTTNG_DOMAIN_UST_PID:
+                       chan->attr.subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
+                       chan->attr.num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
+                       chan->attr.output = DEFAULT_UST_CHANNEL_OUTPUT;
+                       break;
                default:
                        goto error;     /* Not implemented */
        }
@@ -121,14 +127,14 @@ error:
  * Create kernel channel of the kernel session and notify kernel thread.
  */
 int channel_kernel_create(struct ltt_kernel_session *ksession,
-               char *channel_name, struct lttng_channel *chan, int kernel_pipe)
+               struct lttng_channel *chan, int kernel_pipe)
 {
        int ret;
        struct lttng_channel *attr = chan;
 
        /* Creating channel attributes if needed */
        if (attr == NULL) {
-               attr = init_default_attr(LTTNG_DOMAIN_KERNEL, channel_name);
+               attr = init_default_attr(LTTNG_DOMAIN_KERNEL);
                if (attr == NULL) {
                        ret = LTTCOMM_FATAL;
                        goto error;
@@ -154,3 +160,77 @@ int channel_kernel_create(struct ltt_kernel_session *ksession,
 error:
        return ret;
 }
+
+/*
+ * Create UST channel and enable it on the tracer.
+ */
+int channel_ust_create(struct ltt_ust_session *usession,
+               struct lttng_channel *chan, int sock)
+{
+       int ret;
+       struct lttng_channel *attr = chan;
+
+       /* Creating channel attributes if needed */
+       if (attr == NULL) {
+               attr = init_default_attr(LTTNG_DOMAIN_UST_PID);
+               if (attr == NULL) {
+                       ret = LTTCOMM_FATAL;
+                       goto error;
+               }
+       }
+
+       ret = ustctl_create_channel(sock, usession, attr);
+       if (ret < 0) {
+               ret = LTTCOMM_UST_CHAN_FAIL;
+               goto error;
+       }
+
+       DBG2("Channel %s UST create successfully for sock:%d", attr->name, sock);
+
+       ret = LTTCOMM_OK;
+
+error:
+       return ret;
+}
+
+/*
+ * Enable UST channel on the tracer.
+ */
+int channel_ust_enable(struct ltt_ust_session *usession,
+               struct ltt_ust_channel *uchan, int sock)
+{
+       int ret;
+       ret = LTTCOMM_OK;
+
+       ret = ustctl_enable_channel(sock, usession, uchan);
+       if (ret < 0) {
+               ret = LTTCOMM_UST_CHAN_FAIL;
+               goto error;
+       }
+
+       ret = LTTCOMM_OK;
+
+error:
+       return ret;
+}
+
+/*
+ * Disable UST channel on the tracer.
+ */
+int channel_ust_disable(struct ltt_ust_session *usession,
+               struct ltt_ust_channel *uchan, int sock)
+{
+       int ret;
+       ret = LTTCOMM_OK;
+
+       ret = ustctl_disable_channel(sock, usession, uchan);
+       if (ret < 0) {
+               ret = LTTCOMM_UST_CHAN_FAIL;
+               goto error;
+       }
+
+       ret = LTTCOMM_OK;
+
+error:
+       return ret;
+}
index 271721a973d434e24b6de953696c60872d62c6d5..f9a6fbd85a1de8c245de138f604cd48890d41148 100644 (file)
 #include <lttng/lttng.h>
 
 #include "trace-kernel.h"
+#include "trace-ust.h"
 
 int channel_kernel_disable(struct ltt_kernel_session *ksession,
                char *channel_name);
 int channel_kernel_enable(struct ltt_kernel_session *ksession,
                struct ltt_kernel_channel *kchan);
 int channel_kernel_create(struct ltt_kernel_session *ksession,
-               char *channel_name, struct lttng_channel *chan, int kernel_pipe);
+               struct lttng_channel *chan, int kernel_pipe);
+
+int channel_ust_create(struct ltt_ust_session *usession,
+               struct lttng_channel *chan, int sock);
+int channel_ust_disable(struct ltt_ust_session *usession,
+               struct ltt_ust_channel *uchan, int sock);
+int channel_ust_enable(struct ltt_ust_session *usession,
+               struct ltt_ust_channel *uchan, int sock);
 
 #endif /* _LTT_CHANNEL_H */
index fb4b7db2c778c3891a714e591c96f8d88a6265ad..16067d354b7581d408b2bc2b9f08f804ed3911ee 100644 (file)
@@ -1620,15 +1620,30 @@ error:
 /*
  * Create an UST session and add it to the session ust list.
  */
-static int create_ust_session(pid_t pid, struct ltt_session *session)
+static int create_ust_session(struct ltt_session *session,
+               struct lttng_domain *domain)
 {
-       int ret = -1;
+       int ret;
        struct ltt_ust_session *lus;
+       struct ltt_traceable_app *app;
+
+       switch (domain->type) {
+       case LTTNG_DOMAIN_UST_PID:
+               app = traceable_app_get_by_pid(domain->attr.pid);
+               if (app == NULL) {
+                       ret = LTTCOMM_APP_NOT_FOUND;
+                       goto error;
+               }
+               break;
+       default:
+               goto error;
+       }
 
        DBG("Creating UST session");
 
-       lus = trace_ust_create_session(session->path, pid);
+       lus = trace_ust_create_session(session->path, domain->attr.pid, domain);
        if (lus == NULL) {
+               ret = LTTCOMM_UST_SESS_FAIL;
                goto error;
        }
 
@@ -1637,17 +1652,22 @@ static int create_ust_session(pid_t pid, struct ltt_session *session)
        if (ret < 0) {
                if (ret != -EEXIST) {
                        ERR("Trace directory creation error");
+                       ret = LTTCOMM_UST_SESS_FAIL;
                        goto error;
                }
        }
 
        /* Create session on the UST tracer */
-       ret = ustctl_create_session(lus);
+       ret = ustctl_create_session(app->sock, lus);
        if (ret < 0) {
+               ret = LTTCOMM_UST_SESS_FAIL;
                goto error;
        }
 
-       return 0;
+       cds_list_add(&lus->list, &session->ust_session_list.head);
+       session->ust_session_list.count++;
+
+       return LTTCOMM_OK;
 
 error:
        free(lus);
@@ -1801,9 +1821,10 @@ static int cmd_disable_channel(struct ltt_session *session,
 
                        kernel_wait_quiescent(kernel_tracer_fd);
                        break;
+               case LTTNG_DOMAIN_UST_PID:
+                       break;
                default:
-                       /* TODO: Userspace tracing */
-                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       ret = LTTCOMM_UNKNOWN_DOMAIN;
                        goto error;
        }
 
@@ -1816,33 +1837,106 @@ error:
 /*
  * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
  */
-static int cmd_enable_channel(struct ltt_session *session, int domain,
-               char *channel_name, struct lttng_channel *attr)
+static int cmd_enable_channel(struct ltt_session *session,
+               struct lttng_domain *domain, struct lttng_channel *attr)
 {
        int ret;
-       struct ltt_kernel_channel *kchan;
 
-       switch (domain) {
-               case LTTNG_DOMAIN_KERNEL:
-                       kchan = trace_kernel_get_channel_by_name(channel_name,
-                                       session->kernel_session);
-                       if (kchan == NULL) {
-                               ret = channel_kernel_create(session->kernel_session,
-                                               channel_name, attr, kernel_poll_pipe[1]);
-                       } else {
-                               ret = channel_kernel_enable(session->kernel_session, kchan);
-                       }
+       switch (domain->type) {
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               struct ltt_kernel_channel *kchan;
 
-                       if (ret != LTTCOMM_OK) {
+               kchan = trace_kernel_get_channel_by_name(attr->name,
+                               session->kernel_session);
+               if (kchan == NULL) {
+                       ret = channel_kernel_create(session->kernel_session,
+                                       attr, kernel_poll_pipe[1]);
+               } else {
+                       ret = channel_kernel_enable(session->kernel_session, kchan);
+               }
+
+               if (ret != LTTCOMM_OK) {
+                       goto error;
+               }
+
+               kernel_wait_quiescent(kernel_tracer_fd);
+               break;
+       }
+       case LTTNG_DOMAIN_UST_PID:
+       {
+               struct ltt_ust_event *uevent, *new_uevent;
+               struct ltt_ust_session *usess;
+               struct ltt_ust_channel *uchan, *app_chan;
+               struct ltt_traceable_app *app;
+
+               usess = trace_ust_get_session_by_pid(&session->ust_session_list,
+                               domain->attr.pid);
+               if (usess == NULL) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+                       goto error;
+               }
+
+               app = traceable_app_get_by_pid(domain->attr.pid);
+               if (app == NULL) {
+                       ret = LTTCOMM_APP_NOT_FOUND;
+                       goto error;
+               }
+
+               uchan = trace_ust_get_channel_by_name(attr->name, usess);
+               if (uchan == NULL) {
+                       ret = channel_ust_create(usess, attr, app->sock);
+               } else {
+                       ret = channel_ust_enable(usess, uchan, app->sock);
+               }
+
+               if (ret != LTTCOMM_OK) {
+                       goto error;
+               }
+
+               /*TODO: This should be put in an external function */
+
+               /* Copy UST channel to add to the traceable app */
+               uchan = trace_ust_get_channel_by_name(attr->name, usess);
+               if (uchan == NULL) {
+                       ret = LTTCOMM_FATAL;
+                       goto error;
+               }
+
+               app_chan = trace_ust_create_channel(attr, session->path);
+               if (app_chan == NULL) {
+                       PERROR("malloc ltt_ust_channel");
+                       ret = LTTCOMM_FATAL;
+                       goto error;
+               }
+
+               memcpy(app_chan, uchan, sizeof(struct ltt_ust_channel));
+               CDS_INIT_LIST_HEAD(&app_chan->events.head);
+
+               cds_list_for_each_entry(uevent, &uchan->events.head, list) {
+                       new_uevent = malloc(sizeof(struct ltt_ust_event));
+                       if (new_uevent == NULL) {
+                               PERROR("malloc ltt_ust_event");
+                               ret = LTTCOMM_FATAL;
                                goto error;
                        }
 
-                       kernel_wait_quiescent(kernel_tracer_fd);
-                       break;
-               default:
-                       /* TODO: Userspace tracing */
-                       ret = LTTCOMM_NOT_IMPLEMENTED;
-                       goto error;
+                       memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
+                       cds_list_add(&new_uevent->list, &app_chan->events.head);
+                       app_chan->events.count++;
+               }
+
+               /* Add channel to traceable_app */
+               cds_list_add(&app_chan->list, &app->channels.head);
+               app->channels.count++;
+
+               DBG("UST channel %s created for app sock %d with pid %d",
+                               attr->name, app->sock, domain->attr.pid);
+               break;
+       }
+       default:
+               ret = LTTCOMM_UNKNOWN_DOMAIN;
+               goto error;
        }
 
        ret = LTTCOMM_OK;
@@ -1970,7 +2064,7 @@ static int cmd_enable_event(struct ltt_session *session, int domain,
                                session->kernel_session);
                if (kchan == NULL) {
                        /* This call will notify the kernel thread */
-                       ret = channel_kernel_create(session->kernel_session, channel_name,
+                       ret = channel_kernel_create(session->kernel_session,
                                        NULL, kernel_poll_pipe[1]);
                        if (ret != LTTCOMM_OK) {
                                goto error;
@@ -2020,8 +2114,8 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain,
                                session->kernel_session);
                if (kchan == NULL) {
                        /* This call will notify the kernel thread */
-                       ret = channel_kernel_create(session->kernel_session, channel_name,
-                                       NULL, kernel_poll_pipe[1]);
+                       ret = channel_kernel_create(session->kernel_session, NULL,
+                                       kernel_poll_pipe[1]);
                        if (ret != LTTCOMM_OK) {
                                goto error;
                        }
@@ -2427,13 +2521,13 @@ error:
 static int process_client_msg(struct command_ctx *cmd_ctx)
 {
        int ret = LTTCOMM_OK;
-       int need_kernel_session = 1;
+       int need_tracing_session = 1;
 
        DBG("Processing client command %d", cmd_ctx->lsm->cmd_type);
 
        /*
         * Check for command that don't needs to allocate a returned payload. We do
-        * this here so we don't have to make the call for no payload" at each
+        * this here so we don't have to make the call for no payload at each
         * command.
         */
        switch(cmd_ctx->lsm->cmd_type) {
@@ -2458,7 +2552,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        case LTTNG_CREATE_SESSION:
        case LTTNG_LIST_SESSIONS:
        case LTTNG_LIST_TRACEPOINTS:
-               need_kernel_session = 0;
+               need_tracing_session = 0;
                break;
        default:
                DBG("Getting session %s by name", cmd_ctx->lsm->session.name);
@@ -2494,7 +2588,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                }
 
                /* Need a session for kernel command */
-               if (need_kernel_session) {
+               if (need_tracing_session) {
                        if (cmd_ctx->session->kernel_session == NULL) {
                                ret = create_kernel_session(cmd_ctx->session);
                                if (ret < 0) {
@@ -2514,6 +2608,24 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                        }
                }
                break;
+       case LTTNG_DOMAIN_UST_PID:
+       {
+               struct ltt_ust_session *usess;
+
+               if (need_tracing_session) {
+                       usess = trace_ust_get_session_by_pid(
+                                       &cmd_ctx->session->ust_session_list,
+                                       cmd_ctx->lsm->domain.attr.pid);
+                       if (usess == NULL) {
+                               ret = create_ust_session(cmd_ctx->session,
+                                               &cmd_ctx->lsm->domain);
+                               if (ret != LTTCOMM_OK) {
+                                       goto error;
+                               }
+                       }
+               }
+               break;
+       }
        default:
                /* TODO Userspace tracer */
                break;
@@ -2553,8 +2665,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        }
        case LTTNG_ENABLE_CHANNEL:
        {
-               ret = cmd_enable_channel(cmd_ctx->session, cmd_ctx->lsm->domain.type,
-                               cmd_ctx->lsm->u.enable.channel_name,
+               ret = cmd_enable_channel(cmd_ctx->session, &cmd_ctx->lsm->domain,
                                &cmd_ctx->lsm->u.channel.chan);
                break;
        }
index a9aa1abceb8cf3779ec7e02ab4f96eb9dc7613f3..fe007141e90c0c4d09bd9e2f481e1066c63bef50 100644 (file)
 
 #include <lttngerr.h>
 #include <lttng-share.h>
+#include <lttng-ust.h>
 
 #include "trace-ust.h"
 
 /*
- * Return an UST session by traceable app PID.
+ * Using a ust session list, it will return the session corresponding to the
+ * pid. Must be a session of domain LTTNG_DOMAIN_UST_PID.
  */
-struct ltt_ust_session *trace_ust_get_session_by_pid(pid_t pid,
-               struct ltt_ust_session_list *session_list)
+struct ltt_ust_session *trace_ust_get_session_by_pid(
+               struct ltt_ust_session_list *session_list, pid_t pid)
 {
-       struct ltt_ust_session *lus;
+       struct ltt_ust_session *sess;
 
-       cds_list_for_each_entry(lus, &session_list->head, list) {
-               if (lus->app->pid == pid) {
-                       DBG("Found UST session by pid %d", pid);
-                       return lus;
+       if (session_list == NULL) {
+               ERR("Session list is NULL");
+               goto error;
+       }
+
+       cds_list_for_each_entry(sess, &session_list->head, list) {
+               if (sess->domain.type == LTTNG_DOMAIN_UST_PID &&
+                               sess->domain.attr.pid == pid) {
+                       DBG2("Trace UST session found by pid %d", pid);
+                       return sess;
                }
        }
 
+error:
        return NULL;
 }
 
@@ -59,7 +68,7 @@ struct ltt_ust_channel *trace_ust_get_channel_by_name(
 
        cds_list_for_each_entry(chan, &session->channels.head, list) {
                if (strcmp(name, chan->name) == 0) {
-                       DBG("Found UST channel by name %s", name);
+                       DBG2("Found UST channel by name %s", name);
                        return chan;
                }
        }
@@ -82,7 +91,7 @@ struct ltt_ust_event *trace_ust_get_event_by_name(
        }
 
        cds_list_for_each_entry(ev, &channel->events.head, list) {
-               if (strcmp(name, ev->event->name) == 0) {
+               if (strcmp(name, ev->attr.name) == 0) {
                        DBG("Found UST event by name %s for channel %s", name,
                                        channel->name);
                        return ev;
@@ -98,7 +107,8 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid)
+struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid,
+               struct lttng_domain *domain)
 {
        int ret;
        struct ltt_ust_session *lus;
@@ -114,19 +124,22 @@ struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid)
        lus->handle = -1;
        lus->enabled = 1;
        lus->uconsumer_fds_sent = 0;
-       lus->path = NULL;
        lus->metadata = NULL;
-       lus->app = NULL;        /* TODO: Search app by PID */
        lus->channels.count = 0;
        CDS_INIT_LIST_HEAD(&lus->channels.head);
 
+       /* Copy lttng_domain */
+       memcpy(&lus->domain, domain, sizeof(struct lttng_domain));
+
        /* Set session path */
-       ret = asprintf(&lus->path, "%s/ust_%d", path, pid);
+       ret = snprintf(lus->path, PATH_MAX, "%s/ust_%d", path, pid);
        if (ret < 0) {
-               perror("asprintf kernel traces path");
+               PERROR("snprintf kernel traces path");
                goto error;
        }
 
+       DBG2("UST trace session create successful");
+
        return lus;
 
 error:
@@ -138,8 +151,8 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_ust_channel *trace_ust_create_channel(char *name, char *path,
-               struct lttng_ust_channel *chan)
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
+               char *path)
 {
        int ret;
        struct ltt_ust_channel *luc;
@@ -150,25 +163,29 @@ struct ltt_ust_channel *trace_ust_create_channel(char *name, char *path,
                goto error;
        }
 
-       luc->attr = malloc(sizeof(struct lttng_ust_channel));
-       if (luc->attr == NULL) {
-               perror("lttng_ust_channel malloc");
-               goto error;
+       /* Copy UST channel attributes */
+       memcpy(&luc->attr, &chan->attr, sizeof(struct lttng_ust_channel));
+
+       /* Translate to UST output enum */
+       switch (luc->attr.output) {
+       default:
+               luc->attr.output = LTTNG_UST_MMAP;
+               break;
        }
-       memcpy(luc->attr, chan, sizeof(struct lttng_ust_channel));
 
        luc->handle = -1;
        luc->enabled = 1;
-       luc->ctx = NULL;
        luc->events.count = 0;
        CDS_INIT_LIST_HEAD(&luc->events.head);
 
+       memset(&luc->ctx, 0, sizeof(struct lttng_ust_context));
+
        /* Copy channel name */
-       strncpy(luc->name, name, LTTNG_UST_SYM_NAME_LEN);
+       strncpy(luc->name, chan->name, sizeof(&luc->name));
        luc->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
 
        /* Set trace output path */
-       ret = asprintf(&luc->trace_path, "%s", path);
+       ret = snprintf(luc->trace_path, PATH_MAX, "%s", path);
        if (ret < 0) {
                perror("asprintf ust create channel");
                goto error;
@@ -188,27 +205,25 @@ error:
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev)
 {
        struct ltt_ust_event *lue;
-       struct lttng_ust_event *event;
 
        lue = malloc(sizeof(struct ltt_ust_event));
-       event = malloc(sizeof(struct lttng_ust_event));
-       if (lue == NULL || event == NULL) {
-               perror("ust event malloc");
+       if (lue == NULL) {
+               PERROR("ust event malloc");
                goto error;
        }
 
        switch (ev->type) {
        case LTTNG_EVENT_PROBE:
-               event->instrumentation = LTTNG_UST_PROBE;
+               lue->attr.instrumentation = LTTNG_UST_PROBE;
                break;
        case LTTNG_EVENT_FUNCTION:
-               event->instrumentation = LTTNG_UST_FUNCTION;
+               lue->attr.instrumentation = LTTNG_UST_FUNCTION;
                break;
        case LTTNG_EVENT_FUNCTION_ENTRY:
-               event->instrumentation = LTTNG_UST_FUNCTION;
+               lue->attr.instrumentation = LTTNG_UST_FUNCTION;
                break;
        case LTTNG_EVENT_TRACEPOINT:
-               event->instrumentation = LTTNG_UST_TRACEPOINT;
+               lue->attr.instrumentation = LTTNG_UST_TRACEPOINT;
                break;
        default:
                ERR("Unknown ust instrumentation type (%d)", ev->type);
@@ -216,14 +231,13 @@ struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev)
        }
 
        /* Copy event name */
-       strncpy(event->name, ev->name, LTTNG_UST_SYM_NAME_LEN);
-       event->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+       strncpy(lue->attr.name, ev->name, LTTNG_UST_SYM_NAME_LEN);
+       lue->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
 
        /* Setting up a ust event */
        lue->handle = -1;
-       lue->event = event;
        lue->enabled = 1;
-       lue->ctx = NULL;
+       memset(&lue->ctx, 0, sizeof(struct lttng_ust_context));
 
        return lue;
 
@@ -240,24 +254,21 @@ struct ltt_ust_metadata *trace_ust_create_metadata(char *path)
 {
        int ret;
        struct ltt_ust_metadata *lum;
-       struct lttng_ust_channel *attr;
 
        lum = malloc(sizeof(struct ltt_ust_metadata));
-       attr = malloc(sizeof(struct lttng_ust_channel));
-       if (lum == NULL || attr == NULL) {
+       if (lum == NULL) {
                perror("ust metadata malloc");
                goto error;
        }
 
        /* Set default attributes */
-       attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
-       attr->subbuf_size = DEFAULT_METADATA_SUBBUF_SIZE;
-       attr->num_subbuf = DEFAULT_METADATA_SUBBUF_NUM;
-       attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
-       attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
-       attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
-
-       lum->attr = attr;
+       lum->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
+       lum->attr.subbuf_size = DEFAULT_METADATA_SUBBUF_SIZE;
+       lum->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM;
+       lum->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+       lum->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+       lum->attr.output = DEFAULT_UST_CHANNEL_OUTPUT;
+
        lum->handle = -1;
        /* Set metadata trace path */
        ret = asprintf(&lum->trace_path, "%s/metadata", path);
@@ -277,11 +288,7 @@ error:
  */
 void trace_ust_destroy_event(struct ltt_ust_event *event)
 {
-       DBG("[trace] Destroy ust event %s", event->event->name);
-
-       /* Free attributes */
-       free(event->event);
-       free(event->ctx);
+       DBG("[trace] Destroy ust event %s", event->attr.name);
 
        /* Remove from event list */
        cds_list_del(&event->list);
@@ -297,11 +304,6 @@ void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
 
        DBG("[trace] Destroy ust channel %d", channel->handle);
 
-       free(channel->trace_path);
-       /* Free attributes structure */
-       free(channel->attr);
-       free(channel->ctx);
-
        /* For each event in the channel list */
        cds_list_for_each_entry_safe(event, etmp, &channel->events.head, list) {
                trace_ust_destroy_event(event);
@@ -320,7 +322,6 @@ void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata)
        DBG("[trace] Destroy ust metadata %d", metadata->handle);
 
        /* Free attributes */
-       free(metadata->attr);
        free(metadata->trace_path);
 
        free(metadata);
@@ -348,6 +349,9 @@ void trace_ust_destroy_session(struct ltt_ust_session *session)
                trace_ust_destroy_channel(channel);
        }
 
-       free(session->path);
+       if (session->path) {
+               free(session->path);
+       }
+
        free(session);
 }
index 55a452c6092ea6cbd81669671def2c88b0e42951..9a236626931f58fbe566cd1b5a3fe301c9a85e2d 100644 (file)
@@ -25,8 +25,6 @@
 #include <lttng/lttng.h>
 #include <lttng-ust.h>
 
-#include "traceable-app.h"
-
 /*
  * UST session list.
  */
@@ -51,8 +49,8 @@ struct ltt_ust_channel_list {
 struct ltt_ust_event {
        int handle;
        int enabled;
-       struct lttng_ust_context *ctx;
-       struct lttng_ust_event *event;
+       struct lttng_ust_context ctx;
+       struct lttng_ust_event attr;
        struct cds_list_head list;
 };
 
@@ -60,10 +58,10 @@ struct ltt_ust_event {
 struct ltt_ust_channel {
        int handle;
        int enabled;
-       char *name;
-       char *trace_path;                   /* Trace file path name */
-       struct lttng_ust_context *ctx;
-       struct lttng_ust_channel *attr;
+       char name[LTTNG_UST_SYM_NAME_LEN];
+       char trace_path[PATH_MAX];    /* Trace file path name */
+       struct lttng_ust_context ctx;
+       struct lttng_ust_channel attr;
        struct ltt_ust_event_list events;
        struct cds_list_head list;
 };
@@ -72,7 +70,7 @@ struct ltt_ust_channel {
 struct ltt_ust_metadata {
        int handle;
        char *trace_path;             /* Trace file path name */
-       struct lttng_ust_channel *attr;
+       struct lttng_ust_channel attr;
 };
 
 /* UST session */
@@ -80,8 +78,8 @@ struct ltt_ust_session {
        int handle;
        int enabled;
        int uconsumer_fds_sent;
-       char *path;
-       struct ltt_traceable_app *app;
+       char path[PATH_MAX];
+       struct lttng_domain domain;
        struct ltt_ust_metadata *metadata;
        struct ltt_ust_channel_list channels;
        struct cds_list_head list;
@@ -94,15 +92,16 @@ struct ltt_ust_event *trace_ust_get_event_by_name(
                char *name, struct ltt_ust_channel *channel);
 struct ltt_ust_channel *trace_ust_get_channel_by_name(
                char *name, struct ltt_ust_session *session);
-struct ltt_ust_session *trace_ust_get_session_by_pid(pid_t pid,
-               struct ltt_ust_session_list *session_list);
+struct ltt_ust_session *trace_ust_get_session_by_pid(
+               struct ltt_ust_session_list *session_list, pid_t pid);
 
 /*
  * Create functions malloc() the data structure.
  */
-struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid);
-struct ltt_ust_channel *trace_ust_create_channel(char *name, char *path,
-               struct lttng_ust_channel *attr);
+struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid,
+               struct lttng_domain *domain);
+struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
+               char *path);
 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev);
 struct ltt_ust_metadata *trace_ust_create_metadata(char *path);
 
index 653d86b3fe3cbf675d25428a446b9be6b672e79a..41dc51111dd3de0d12f9a58dde3d5aa07a5e4df4 100644 (file)
@@ -49,11 +49,17 @@ static void add_traceable_app(struct ltt_traceable_app *lta)
  */
 static void del_traceable_app(struct ltt_traceable_app *lta)
 {
+       struct ltt_ust_channel *chan;
+
        cds_list_del(&lta->list);
        /* Sanity check */
        if (ltt_traceable_app_list.count > 0) {
                ltt_traceable_app_list.count--;
        }
+
+       cds_list_for_each_entry(chan, &lta->channels.head, list) {
+               trace_ust_destroy_channel(chan);
+       }
 }
 
 /*
@@ -109,10 +115,13 @@ struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid)
        cds_list_for_each_entry(iter, &ltt_traceable_app_list.head, list) {
                if (iter->pid == pid) {
                        /* Found */
+                       DBG2("Found traceable app by pid %d", pid);
                        return iter;
                }
        }
 
+       DBG2("Traceable app with pid %d not found", pid);
+
        return NULL;
 }
 
@@ -141,6 +150,7 @@ int register_traceable_app(struct ust_register_msg *msg, int sock)
        lta->sock = sock;
        strncpy(lta->name, msg->name, sizeof(lta->name));
        lta->name[16] = '\0';
+       CDS_INIT_LIST_HEAD(&lta->channels.head);
 
        lock_apps_list();
        add_traceable_app(lta);
@@ -167,8 +177,8 @@ void unregister_traceable_app(int sock)
        lta = find_app_by_sock(sock);
        if (lta) {
                DBG("PID %d unregistered with sock %d", lta->pid, sock);
-               close(lta->sock);
                del_traceable_app(lta);
+               close(lta->sock);
                free(lta);
        }
        unlock_apps_list();
@@ -200,6 +210,7 @@ void clean_traceable_apps_list(void)
         * cleanup() functions meaning that the program will exit.
         */
        cds_list_for_each_entry_safe(iter, tmp, &ltt_traceable_app_list.head, list) {
+               del_traceable_app(iter);
                close(iter->sock);
                free(iter);
        }
index 4d5e56a66d9763153eb1afb1440ce513abfe34d8..39f97f2a2b3968cd091053f1df5d90684b59ae25 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdint.h>
 #include <urcu/list.h>
 
+#include "trace-ust.h"
+
 /*
  * Application registration data structure.
  */
@@ -70,6 +72,7 @@ struct ltt_traceable_app {
        uint32_t v_major;    /* Verion major number */
        uint32_t v_minor;    /* Verion minor number */
        char name[17];       /* Process name (short) */
+       struct ltt_ust_channel_list channels;
        struct cds_list_head list;
 };
 
@@ -82,4 +85,6 @@ void unlock_apps_list(void);
 void clean_traceable_apps_list(void);
 struct ltt_traceable_app_list *get_traceable_apps_list(void);
 
+struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid);
+
 #endif /* _TRACEABLE_APP_H */
index 31c40070e92758b94779ef6b58e27f7b5ce39a23..455d40c0af68cedb941120b5759d05fb5e4e75be 100644 (file)
@@ -24,7 +24,7 @@
 
 /*
  * Send msg containing a command to an UST application via sock and wait for
- * the reply.
+ * the reply. Caller must free() the reply structure sent back.
  *
  * Return the replied structure or NULL.
  */
@@ -39,7 +39,7 @@ struct lttcomm_ust_reply *ustcomm_send_command(int sock,
                goto error;
        }
 
-       DBG("Sending UST command %d to sock %d", msg->cmd, sock);
+       DBG2("Sending UST command %d to sock %d", msg->cmd, sock);
 
        /* Send UST msg */
        len = lttcomm_send_unix_sock(sock, msg, sizeof(*msg));
@@ -53,7 +53,7 @@ struct lttcomm_ust_reply *ustcomm_send_command(int sock,
                goto error;
        }
 
-       DBG("Receiving UST reply on sock %d", sock);
+       DBG2("Receiving UST reply on sock %d", sock);
 
        /* Get UST reply */
        len = lttcomm_recv_unix_sock(sock, reply, sizeof(*reply));
index 5f4e8a9fcefe09dda5fecef4335de708b35b85a2..2753b6f5ab639b593692c62292a5740cd08c653f 100644 (file)
@@ -60,17 +60,15 @@ error:
 /*
  * Create an UST session on the tracer.
  */
-int ustctl_create_session(struct ltt_ust_session *session)
+int ustctl_create_session(int sock, struct ltt_ust_session *session)
 {
        struct lttcomm_ust_msg command;
-       struct lttcomm_ust_reply *reply;
-
-       DBG("Creating UST session for app pid:%d", session->app->pid);
+       struct lttcomm_ust_reply *reply = NULL;
 
        command.cmd = LTTNG_UST_SESSION;
        command.handle = LTTNG_UST_ROOT_HANDLE;
 
-       reply = ustcomm_send_command(session->app->sock, &command);
+       reply = ustcomm_send_command(sock, &command);
        if (reply == NULL) {
                goto error;
        }
@@ -81,10 +79,140 @@ int ustctl_create_session(struct ltt_ust_session *session)
        }
 
        /* Save session handle */
-       session->handle = reply->handle;
+       session->handle = reply->ret_val;
+       free(reply);
+
+       DBG2("ustctl create session command successful");
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Create UST channel to the tracer.
+ */
+int ustctl_create_channel(int sock, struct ltt_ust_session *session,
+               struct lttng_channel *channel)
+{
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply = NULL;
+       struct ltt_ust_channel *uchan;
+
+       uchan = trace_ust_create_channel(channel, session->path);
+       if (uchan == NULL) {
+               goto error;
+       }
+
+       memset(&command, 0, sizeof(command));
+
+       command.cmd = LTTNG_UST_CHANNEL;
+       command.handle = session->handle;
+
+       /* Copy channel attributes to command */
+       memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel));
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       }
+
+       uchan->handle = reply->ret_val;
+
+       /* Add channel to session */
+       cds_list_add(&uchan->list, &session->channels.head);
+       session->channels.count++;
+
+       free(reply);
+
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Enable UST channel.
+ */
+int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan)
+{
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply = NULL;
+
+       memset(&command, 0, sizeof(command));
+
+       command.cmd = LTTNG_UST_ENABLE;
+       command.handle = chan->handle;
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       } else if (reply->handle != chan->handle) {
+               ERR("Receive wrong handle from UST reply on enable channel");
+               goto error;
+       }
+
+       chan->enabled = 1;
+       free(reply);
+
+       DBG2("ustctl enable channel successful for sock %d", sock);
+       return 0;
+
+error:
+       free(reply);
+       return -1;
+}
+
+/*
+ * Disable UST channel.
+ */
+int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan)
+{
+       struct lttcomm_ust_msg command;
+       struct lttcomm_ust_reply *reply = NULL;
+
+       memset(&command, 0, sizeof(command));
+
+       command.cmd = LTTNG_UST_DISABLE;
+       command.handle = chan->handle;
+
+       reply = ustcomm_send_command(sock, &command);
+       if (reply == NULL) {
+               goto error;
+       }
+
+       if (reply->ret_code != LTTCOMM_OK) {
+               DBG("Return code (%d): %s", reply->ret_code,
+                               lttcomm_get_readable_code(reply->ret_code));
+               goto error;
+       } else if (reply->handle != chan->handle) {
+               ERR("Receive wrong handle from UST reply on enable channel");
+               goto error;
+       }
+
+       chan->enabled = 1;
+       free(reply);
 
+       DBG2("ustctl disable channel successful for sock %d", sock);
        return 0;
 
 error:
+       free(reply);
        return -1;
 }
index 8f8bebc99590e74c7994ba8a57f8904493f83ecf..c4d754ecaf290a69fae840efbad5b99ea850d6c8 100644 (file)
 #ifndef _LTT_UST_CTL_H
 #define _LTT_UST_CTL_H
 
+#include <lttng/lttng.h>
+
 #include "trace-ust.h"
 
 int ustctl_register_done(int sock);
-int ustctl_create_session(struct ltt_ust_session *session);
-int ustctl_destroy_session(struct ltt_ust_session *session);
+int ustctl_create_channel(int sock, struct ltt_ust_session *session,
+               struct lttng_channel *channel);
+int ustctl_create_session(int sock, struct ltt_ust_session *session);
+int ustctl_destroy_session(int sock, struct ltt_ust_session *session);
+int ustctl_disable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan);
+int ustctl_enable_channel(int sock, struct ltt_ust_session *session,
+               struct ltt_ust_channel *chan);
 
 #endif /* _LTT_UST_CTL_H */
index 13511cc869803097edff9bc2542a35218b38e870..c5887d07bf17ac10688e3dbb3b74bc6d57564ddc 100644 (file)
@@ -177,8 +177,8 @@ static void init_channel_config(void)
                chan.attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
                chan.attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
 
-               chan.attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE;
-               chan.attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM;
+               chan.attr.subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
+               chan.attr.num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
                chan.attr.output = DEFAULT_CHANNEL_OUTPUT;
        }
 }
index 215fa6837e600be04ce5bcab4a1610494aaa7111..14a9c7f45d719b224a39a5b73faa89aa5f600b4f 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char **argv)
     struct lttng_handle *handle = NULL;
     struct lttng_domain dom;
        struct lttng_event event;
-    char *channel_name = "mychan";
+    char *channel_name = "channel0";
     int ret = 0;
 
     dom.type = LTTNG_DOMAIN_KERNEL;
This page took 0.065775 seconds and 4 git commands to generate.