Add wakeup on subbuffer delivery
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 20 Aug 2011 00:44:21 +0000 (20:44 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 20 Aug 2011 00:44:21 +0000 (20:44 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/frontend_internal.h
libringbuffer/frontend_types.h
libringbuffer/ring_buffer_backend.c
libringbuffer/shm.c
libringbuffer/shm.h
libust/ltt-ring-buffer-client.h
libust/ltt-ring-buffer-metadata-client.h

index 73b44726df2fe9f1c4baaee731418e8fcead28f0..c60affe07d94dd4e549af3c4abc1dbcfc6eb6c3e 100644 (file)
@@ -378,8 +378,19 @@ void lib_ring_buffer_check_deliver(const struct lib_ring_buffer_config *config,
                        if (config->wakeup == RING_BUFFER_WAKEUP_BY_WRITER
                            && uatomic_read(&buf->active_readers)
                            && lib_ring_buffer_poll_deliver(config, buf, chan, handle)) {
-                               //wake_up_interruptible(&buf->read_wait);
-                               //wake_up_interruptible(&chan->read_wait);
+                               int wakeup_fd = shm_get_wakeup_fd(handle, &buf->self._ref);
+
+                               if (wakeup_fd >= 0) {
+                                       int ret;
+                                       /*
+                                        * Wake-up the other end by
+                                        * writing a null byte in the
+                                        * pipe (non-blocking).
+                                        */
+                                       do {
+                                               ret = write(wakeup_fd, "", 1);
+                                       } while (ret == -1L && errno == EINTR);
+                               }
                        }
 
                }
index 974f782e0dc86b3ed3903ec861ede6754504fbd9..ad7848c831627cd87a009db5a1c9e29c41a1f841 100644 (file)
@@ -103,6 +103,8 @@ struct lib_ring_buffer {
        int get_subbuf:1;               /* Sub-buffer being held by reader */
        int switch_timer_enabled:1;     /* Protected by ring_buffer_nohz_lock */
        int read_timer_enabled:1;       /* Protected by ring_buffer_nohz_lock */
+       /* shmp pointer to self */
+       DECLARE_SHMP(struct lib_ring_buffer, self);
 } ____cacheline_aligned;
 
 static inline
index badde80f0b4c40cea03ec04a63e99e201fd0a65d..18dd1b01073027efc9219bf01d905b1f3049c5a3 100644 (file)
@@ -283,6 +283,7 @@ int channel_backend_init(struct channel_backend *chanb,
                        buf = shmp(handle, chanb->buf[i].shmp);
                        if (!buf)
                                goto end;
+                       set_shmp(buf->self, chanb->buf[i].shmp._ref);
                        ret = lib_ring_buffer_create(buf, chanb, i,
                                        handle, shmobj);
                        if (ret)
index 8f158e2f0507feeb8d05e000f08241a0e356b9e9..6a77af6462a61d93a3c5c1bfb8fff214f546de62 100644 (file)
@@ -49,6 +49,12 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table,
                        goto error_fcntl;
                }
        }
+       /* The write end of the pipe needs to be non-blocking */
+       ret = fcntl(waitfd[1], F_SETFL, O_NONBLOCK);
+       if (ret < 0) {
+               PERROR("fcntl");
+               goto error_fcntl;
+       }
        *obj->wait_fd = *waitfd;
 
        /* shm_fd: create shm */
index d370375b6929cf913ed568e3e665ead996f515ec..008c5c415f3d8d9c383fdcaa3620cb36a06bc46d 100644 (file)
@@ -68,4 +68,33 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table,
 struct shm_ref zalloc_shm(struct shm_object *obj, size_t len);
 void align_shm(struct shm_object *obj, size_t align);
 
+static inline
+int shm_get_wakeup_fd(struct shm_handle *handle, struct shm_ref *ref)
+{
+       struct shm_object_table *table = handle->table;
+       struct shm_object *obj;
+       size_t index;
+
+       index = (size_t) ref->index;
+       if (unlikely(index >= table->allocated_len))
+               return -EPERM;
+       obj = &table->objects[index];
+       return obj->wait_fd[1];
+
+}
+
+static inline
+int shm_get_wait_fd(struct shm_handle *handle, struct shm_ref *ref)
+{
+       struct shm_object_table *table = handle->table;
+       struct shm_object *obj;
+       size_t index;
+
+       index = (size_t) ref->index;
+       if (unlikely(index >= table->allocated_len))
+               return -EPERM;
+       obj = &table->objects[index];
+       return obj->wait_fd[0];
+}
+
 #endif /* _LIBRINGBUFFER_SHM_H */
index d71d38616fe0fa3d52f0f2952ba8d32264b40e11..e4845642fcfacc5e78ccc8086bbfe7dcd5a2a1f5 100644 (file)
@@ -362,13 +362,13 @@ static const struct lib_ring_buffer_config client_config = {
 
        .tsc_bits = 32,
        .alloc = RING_BUFFER_ALLOC_PER_CPU,
-       .sync = RING_BUFFER_SYNC_PER_CPU,
+       .sync = RING_BUFFER_SYNC_GLOBAL,
        .mode = RING_BUFFER_MODE_TEMPLATE,
        .backend = RING_BUFFER_PAGE,
-       .output = RING_BUFFER_SPLICE,
+       .output = RING_BUFFER_MMAP,
        .oops = RING_BUFFER_OOPS_CONSISTENCY,
-       .ipi = RING_BUFFER_IPI_BARRIER,
-       .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
+       .ipi = RING_BUFFER_NO_IPI_BARRIER,
+       .wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
 };
 
 static
index 88716a26f6b7d36548a50d96fafcb4790be2376a..ef70a9f0cac0086f44dda015c867fe9499727729 100644 (file)
@@ -149,10 +149,10 @@ static const struct lib_ring_buffer_config client_config = {
        .sync = RING_BUFFER_SYNC_GLOBAL,
        .mode = RING_BUFFER_MODE_TEMPLATE,
        .backend = RING_BUFFER_PAGE,
-       .output = RING_BUFFER_SPLICE,
+       .output = RING_BUFFER_MMAP,
        .oops = RING_BUFFER_OOPS_CONSISTENCY,
-       .ipi = RING_BUFFER_IPI_BARRIER,
-       .wakeup = RING_BUFFER_WAKEUP_BY_TIMER,
+       .ipi = RING_BUFFER_NO_IPI_BARRIER,
+       .wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
 };
 
 static
This page took 0.027793 seconds and 4 git commands to generate.