[lttng-dev] [RFC PATCH liburcu 1/2] Implement urcu workqueues internal API

2017-05-30 Thread Mathieu Desnoyers
Signed-off-by: Mathieu Desnoyers 
---
 src/Makefile.am |   2 +-
 src/workqueue.c | 507 
 src/workqueue.h | 104 
 3 files changed, 612 insertions(+), 1 deletion(-)
 create mode 100644 src/workqueue.c
 create mode 100644 src/workqueue.h

diff --git a/src/Makefile.am b/src/Makefile.am
index a801020..60b833d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,7 @@ liburcu_bp_la_SOURCES = urcu-bp.c urcu-pointer.c $(COMPAT)
 liburcu_bp_la_LIBADD = liburcu-common.la
 
 liburcu_cds_la_SOURCES = rculfqueue.c rculfstack.c lfstack.c \
-   $(RCULFHASH) $(COMPAT)
+   workqueue.c workqueue.h $(RCULFHASH) $(COMPAT)
 liburcu_cds_la_LIBADD = liburcu-common.la
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/src/workqueue.c b/src/workqueue.c
new file mode 100644
index 000..891a8fc
--- /dev/null
+++ b/src/workqueue.c
@@ -0,0 +1,507 @@
+/*
+ * workqueue.c
+ *
+ * Userspace RCU library - Userspace workqeues
+ *
+ * Copyright (c) 2010 Paul E. McKenney 
+ * Copyright (c) 2017 Mathieu Desnoyers 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _LGPL_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "compat-getcpu.h"
+#include "urcu/wfcqueue.h"
+#include "urcu-call-rcu.h"
+#include "urcu-pointer.h"
+#include "urcu/list.h"
+#include "urcu/futex.h"
+#include "urcu/tls-compat.h"
+#include "urcu/ref.h"
+#include "urcu-die.h"
+
+#include "workqueue.h"
+
+#define SET_AFFINITY_CHECK_PERIOD  (1U << 8)   /* 256 */
+#define SET_AFFINITY_CHECK_PERIOD_MASK (SET_AFFINITY_CHECK_PERIOD - 1)
+
+/* Data structure that identifies a workqueue. */
+
+struct urcu_workqueue {
+   /*
+* We do not align head on a different cache-line than tail
+* mainly because call_rcu callback-invocation threads use
+* batching ("splice") to get an entire list of callbacks, which
+* effectively empties the queue, and requires to touch the tail
+* anyway.
+*/
+   struct cds_wfcq_tail cbs_tail;
+   struct cds_wfcq_head cbs_head;
+   unsigned long flags;
+   int32_t futex;
+   unsigned long qlen; /* maintained for debugging. */
+   pthread_t tid;
+   int cpu_affinity;
+   unsigned long loop_count;
+   void *priv;
+   void (*grace_period_fct)(struct urcu_workqueue *workqueue, void *priv);
+   void (*initialize_worker_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+   void (*finalize_worker_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+   void (*worker_before_pause_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+   void (*worker_after_resume_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+   void (*worker_before_wait_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+   void (*worker_after_wake_up_fct)(struct urcu_workqueue *workqueue, void 
*priv);
+} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
+
+struct urcu_workqueue_completion {
+   int barrier_count;
+   int32_t futex;
+   struct urcu_ref ref;
+};
+
+struct urcu_workqueue_completion_work {
+   struct urcu_work work;
+   struct urcu_workqueue_completion *completion;
+};
+
+/*
+ * Periodically retry setting CPU affinity if we migrate.
+ * Losing affinity can be caused by CPU hotunplug/hotplug, or by
+ * cpuset(7).
+ */
+#if HAVE_SCHED_SETAFFINITY
+static int set_thread_cpu_affinity(struct urcu_workqueue *workqueue)
+{
+   cpu_set_t mask;
+   int ret;
+
+   if (workqueue->cpu_affinity < 0)
+   return 0;
+   if (++workqueue->loop_count & SET_AFFINITY_CHECK_PERIOD_MASK)
+   return 0;
+   if (urcu_sched_getcpu() == workqueue->cpu_affinity)
+   return 0;
+
+   CPU_ZERO();
+   CPU_SET(workqueue->cpu_affinity, );
+#if SCHED_SETAFFINITY_ARGS == 2
+   ret = sched_setaffinity(0, );
+#else
+   ret = sched_setaffinity(0, sizeof(mask), );
+#endif
+   /*
+* EINVAL is fine: can be caused by hotunplugged CPUs, or by
+* cpuset(7). This is why we should always retry if 

[lttng-dev] [RCU PATCH liburcu 2/2] Use workqueue in rculfhash

2017-05-30 Thread Mathieu Desnoyers
Signed-off-by: Mathieu Desnoyers 
---
 include/urcu/rculfhash.h |  15 --
 src/rculfhash-internal.h |   2 +-
 src/rculfhash.c  | 124 +++
 3 files changed, 74 insertions(+), 67 deletions(-)

diff --git a/include/urcu/rculfhash.h b/include/urcu/rculfhash.h
index 9934422..0789aa5 100644
--- a/include/urcu/rculfhash.h
+++ b/include/urcu/rculfhash.h
@@ -176,10 +176,17 @@ struct cds_lfht *cds_lfht_new(unsigned long init_size,
  *need to be informed of the value passed to cds_lfht_new().
  *
  * Return 0 on success, negative error value on error.
- * Threads calling this API need to be registered RCU read-side threads.
- * cds_lfht_destroy should *not* be called from a RCU read-side critical
- * section. It should *not* be called from a call_rcu thread context
- * neither.
+
+ * Prior to liburcu 0.10:
+ * - Threads calling this API need to be registered RCU read-side
+ *   threads.
+ * - cds_lfht_destroy should *not* be called from a RCU read-side
+ *   critical section. It should *not* be called from a call_rcu thread
+ *   context neither.
+ *
+ * Starting from liburcu 0.10, rculfhash implements its own worker
+ * thread to handle resize operations, which removes RCU requirements on
+ * cds_lfht_destroy.
  */
 extern
 int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr);
diff --git a/src/rculfhash-internal.h b/src/rculfhash-internal.h
index d7cec95..0f8df97 100644
--- a/src/rculfhash-internal.h
+++ b/src/rculfhash-internal.h
@@ -82,7 +82,7 @@ struct cds_lfht {
 */
pthread_mutex_t resize_mutex;   /* resize mutex: add/del mutex */
pthread_attr_t *resize_attr;/* Resize threads attributes */
-   unsigned int in_progress_resize, in_progress_destroy;
+   unsigned int in_progress_destroy;
unsigned long resize_target;
int resize_initiated;
 
diff --git a/src/rculfhash.c b/src/rculfhash.c
index d7a1f23..b7b8f95 100644
--- a/src/rculfhash.c
+++ b/src/rculfhash.c
@@ -64,7 +64,7 @@
  * - 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.
+ *   worker 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,
@@ -276,6 +276,8 @@
 #include 
 #include 
 #include 
+#include "workqueue.h"
+#include "urcu-die.h"
 
 /*
  * Split-counters lazily update the global counter each 1024
@@ -335,11 +337,11 @@ struct ht_items_count {
 } __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
 /*
- * rcu_resize_work: Contains arguments passed to RCU worker thread
+ * resize_work: Contains arguments passed to worker thread
  * responsible for performing lazy resize.
  */
-struct rcu_resize_work {
-   struct rcu_head head;
+struct resize_work {
+   struct urcu_work work;
struct cds_lfht *ht;
 };
 
@@ -356,6 +358,8 @@ struct partition_resize_work {
unsigned long start, unsigned long len);
 };
 
+static struct urcu_workqueue *cds_lfht_workqueue;
+
 /*
  * Algorithm to reverse bits in a word by lookup table, extended to
  * 64-bit words.
@@ -1224,14 +1228,12 @@ void partition_resize_helper(struct cds_lfht *ht, 
unsigned long i,
if (start == 0 && nr_threads > 0)
return;
 fallback:
-   ht->flavor->thread_online();
fct(ht, i, start, len);
-   ht->flavor->thread_offline();
 }
 
 /*
  * Holding RCU read lock to protect _cds_lfht_add against memory
- * reclaim that could be performed by other call_rcu worker threads (ABA
+ * reclaim that could be performed by other worker threads (ABA
  * problem).
  *
  * When we reach a certain length, we can split this population phase over
@@ -1308,7 +1310,7 @@ void init_table(struct cds_lfht *ht,
 
 /*
  * Holding RCU read lock to protect _cds_lfht_remove against memory
- * reclaim that could be performed by other call_rcu worker threads (ABA
+ * reclaim that could be performed by other worker threads (ABA
  * problem).
  * For a single level, we logically remove and garbage collect each node.
  *
@@ -1320,8 +1322,9 @@ void init_table(struct cds_lfht *ht,
  *
  * 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 bucket nodes (after a grace period).
+ * removed nodes have been garbage-collected (unlinked) before work
+ * enqueue is invoked to free a hole level of bucket nodes (after a
+ * grace period).
  *
  * Logical removal and garbage collection can therefore be done in batch
  * or on a 

[lttng-dev] [RFC PATCH liburcu 0/2] Remove RCU requirements on hash table destroy

2017-05-30 Thread Mathieu Desnoyers
The RCU lock-free hash table currently requires that the destroy
function should not be called from within RCU read-side critical
sections. This is caused by the lazy resize, which uses the call_rcu
worker thread, even though all it really needs is a workqueue/worker
thread scheme.

Implement an internal workqueue API in liburcu, and use it instead of
call_rcu in rculfhash to overcome this limitation.

Mathieu Desnoyers (2):
  Implement urcu workqueues internal API
  Use workqueue in rculfhash

 include/urcu/rculfhash.h |  15 +-
 src/Makefile.am  |   2 +-
 src/rculfhash-internal.h |   2 +-
 src/rculfhash.c  | 124 ++--
 src/workqueue.c  | 507 +++
 src/workqueue.h  | 104 ++
 6 files changed, 686 insertions(+), 68 deletions(-)
 create mode 100644 src/workqueue.c
 create mode 100644 src/workqueue.h

-- 
2.1.4

___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


[lttng-dev] Error: Kernel create channel failed

2017-05-30 Thread Deneau, Tom
I seem to have gotten my lttng into a state where kernel tracing does not work.
I have tried uninstalling and reinstalling packages with no luck and also 
building from source.
Any suggestions welcome.

My distro is Ubuntu 16.04 but the kernel is 4.10.0-20-generic.

I have installed 2.9 using
apt install linux-tools-generic dkms
apt-add-repository ppa:lttng/stable-2.9
apt-get update
apt install -y lttng-tools liblttng-ust-dev  liblttng-ust-agent-java  
python3-lttngust lttng-modules-dkms
wget 
http://ftp.us.debian.org/debian/pool/main/l/lttng-modules/lttng-modules-dkms_2.9.1-1_all.deb
dpkg -i lttng-modules-dkms_2.9.1-1_all.deb
apt install -y babeltrace python3-babeltrace

After lttng create test, I then try

# lttng -vvv enable-channel k -k --num-subbuf 64 --subbuf-size 512k
DEBUG1 - 08:27:54.415995 [13972/13972]: Channel subbuf num set to 64 (in 
cmd_enable_channels() at commands/enable_channels.c:420)
DEBUG1 - 08:27:54.416045 [13972/13972]: Channel subbuf size set to 524288 (in 
cmd_enable_channels() at commands/enable_channels.c:384)
DEBUG2 - 08:27:54.416080 [13972/13972]: Config file path found: /root (in 
_get_session_name() at utils.c:63)
DEBUG1 - 08:27:54.416087 [13972/13972]: Session name found: test (in 
_get_session_name() at utils.c:64)
DEBUG1 - 08:27:54.416099 [13972/13972]: Enabling channel k (in enable_channel() 
at commands/enable_channels.c:225)
DEBUG1 - 08:27:54.416129 [13972/13972]: LSM cmd type : 5 (in send_session_msg() 
at lttng-ctl.c:135)
Error: Channel k: Kernel create channel failed (session test)
Error: Command error
DEBUG1 - 08:27:54.416479 [13972/13972]: Clean exit (in clean_exit() at 
lttng.c:149)


___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


Re: [lttng-dev] [PATCH lttng-modules] Fix: Build ftrace probe on kernels prior to 4.12

2017-05-30 Thread Mathieu Desnoyers
Merged in master, 2.10, 2.9, 2.8, thanks!

Mathieu

- On May 30, 2017, at 9:36 AM, Francis Deslauriers 
francis.deslauri...@efficios.com wrote:

> Signed-off-by: Francis Deslauriers 
> ---
> probes/Kbuild | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/probes/Kbuild b/probes/Kbuild
> index fe869d0..78bf3fb 100644
> --- a/probes/Kbuild
> +++ b/probes/Kbuild
> @@ -267,8 +267,9 @@ ifneq ($(CONFIG_DYNAMIC_FTRACE),)
> echo "warn" ; \
> exit ; \
>   fi; \
> -  echo "lttng-ftrace.o" ; \
> -fi;)
> +fi; \
> +echo "lttng-ftrace.o" ; \
> +)
>   ifeq ($(ftrace),warn)
> $(warning Files $(ftrace_dep) not found. Probe "ftrace" is disabled. Use 
> full
> kernel source tree to enable it.)
> ftrace =
> --
> 2.7.4

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev


[lttng-dev] [PATCH lttng-modules] Fix: Build ftrace probe on kernels prior to 4.12

2017-05-30 Thread Francis Deslauriers
Signed-off-by: Francis Deslauriers 
---
 probes/Kbuild | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/probes/Kbuild b/probes/Kbuild
index fe869d0..78bf3fb 100644
--- a/probes/Kbuild
+++ b/probes/Kbuild
@@ -267,8 +267,9 @@ ifneq ($(CONFIG_DYNAMIC_FTRACE),)
 echo "warn" ; \
 exit ; \
   fi; \
-  echo "lttng-ftrace.o" ; \
-fi;)
+fi; \
+echo "lttng-ftrace.o" ; \
+)
   ifeq ($(ftrace),warn)
 $(warning Files $(ftrace_dep) not found. Probe "ftrace" is disabled. Use 
full kernel source tree to enable it.)
 ftrace =
-- 
2.7.4

___
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev