#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
-#include <ust/kernelcompat.h>
-#include <kcompat/kref.h>
#include <stdlib.h>
+
+#include <ust/clock.h>
+
#include "buffers.h"
#include "channels.h"
#include "tracer.h"
return n_cpus;
}
-/* _ust_buffers_write()
+/**
+ * _ust_buffers_strncpy_fixup - Fix an incomplete string in a ltt_relay buffer.
+ * @buf : buffer
+ * @offset : offset within the buffer
+ * @len : length to write
+ * @copied: string actually copied
+ * @terminated: does string end with \0
*
- * @buf: destination buffer
- * @offset: offset in destination
- * @src: source buffer
- * @len: length of source
- * @cpy: already copied
+ * Fills string with "X" if incomplete.
*/
-
-void _ust_buffers_write(struct ust_buffer *buf, size_t offset,
- const void *src, size_t len, ssize_t cpy)
+void _ust_buffers_strncpy_fixup(struct ust_buffer *buf, size_t offset,
+ size_t len, size_t copied, int terminated)
{
- do {
- len -= cpy;
- src += cpy;
- offset += cpy;
+ size_t buf_offset, cpy;
- WARN_ON(offset >= buf->buf_size);
+ if (copied == len) {
+ /*
+ * Deal with non-terminated string.
+ */
+ assert(!terminated);
+ offset += copied - 1;
+ buf_offset = BUFFER_OFFSET(offset, buf->chan);
+ /*
+ * Underlying layer should never ask for writes across
+ * subbuffers.
+ */
+ assert(buf_offset
+ < buf->chan->subbuf_size*buf->chan->subbuf_cnt);
+ ust_buffers_do_memset(buf->buf_data + buf_offset, '\0', 1);
+ return;
+ }
- cpy = min_t(size_t, len, buf->buf_size - offset);
- ust_buffers_do_copy(buf->buf_data + offset, src, cpy);
- } while (unlikely(len != cpy));
+ /*
+ * Deal with incomplete string.
+ * Overwrite string's \0 with X too.
+ */
+ cpy = copied - 1;
+ assert(terminated);
+ len -= cpy;
+ offset += cpy;
+ buf_offset = BUFFER_OFFSET(offset, buf->chan);
+
+ /*
+ * Underlying layer should never ask for writes across subbuffers.
+ */
+ assert(buf_offset
+ < buf->chan->subbuf_size*buf->chan->subbuf_cnt);
+
+ ust_buffers_do_memset(buf->buf_data + buf_offset,
+ 'X', len);
+
+ /*
+ * Overwrite last 'X' with '\0'.
+ */
+ offset += len - 1;
+ buf_offset = BUFFER_OFFSET(offset, buf->chan);
+ /*
+ * Underlying layer should never ask for writes across subbuffers.
+ */
+ assert(buf_offset
+ < buf->chan->subbuf_size*buf->chan->subbuf_cnt);
+ ust_buffers_do_memset(buf->buf_data + buf_offset, '\0', 1);
}
static int ust_buffers_init_buffer(struct ust_trace *trace,
static void ust_buffers_destroy_channel(struct kref *kref)
{
- struct ust_channel *chan = container_of(kref, struct ust_channel, kref);
+ struct ust_channel *chan = _ust_container_of(kref, struct ust_channel, kref);
free(chan);
}
/* called from kref_put */
static void ust_buffers_remove_buf(struct kref *kref)
{
- struct ust_buffer *buf = container_of(kref, struct ust_buffer, kref);
+ struct ust_buffer *buf = _ust_container_of(kref, struct ust_buffer, kref);
ust_buffers_destroy_buf(buf);
}
kref_init(&chan->kref);
- mutex_lock(&ust_buffers_channels_mutex);
+ pthread_mutex_lock(&ust_buffers_channels_mutex);
for(i=0; i<chan->n_cpus; i++) {
result = ust_buffers_open_buf(chan, i);
if (result == -1)
goto error;
}
list_add(&chan->list, &ust_buffers_channels);
- mutex_unlock(&ust_buffers_channels_mutex);
+ pthread_mutex_unlock(&ust_buffers_channels_mutex);
return 0;
}
kref_put(&chan->kref, ust_buffers_destroy_channel);
- mutex_unlock(&ust_buffers_channels_mutex);
+ pthread_mutex_unlock(&ust_buffers_channels_mutex);
return -1;
}
if(!chan)
return;
- mutex_lock(&ust_buffers_channels_mutex);
+ pthread_mutex_lock(&ust_buffers_channels_mutex);
for(i=0; i<chan->n_cpus; i++) {
/* FIXME: if we make it here, then all buffers were necessarily allocated. Moreover, we don't
* initialize to NULL so we cannot use this check. Should we? */
list_del(&chan->list);
kref_put(&chan->kref, ust_buffers_destroy_channel);
- mutex_unlock(&ust_buffers_channels_mutex);
+ pthread_mutex_unlock(&ust_buffers_channels_mutex);
}
/*
static void ltt_relay_release_channel(struct kref *kref)
{
- struct ust_channel *ltt_chan = container_of(kref,
+ struct ust_channel *ltt_chan = _ust_container_of(kref,
struct ust_channel, kref);
free(ltt_chan->buf);
}
buf->data_ready_fd_read = fds[0];
buf->data_ready_fd_write = fds[1];
- /* FIXME: do we actually need this? */
- result = fcntl(fds[0], F_SETFL, O_NONBLOCK);
- if(result == -1) {
- PERROR("fcntl");
- }
-
//ust// buf->commit_seq = malloc(sizeof(buf->commit_seq) * n_subbufs);
//ust// if(!ltt_buf->commit_seq) {
//ust// return -1;
ltt_chan->commit_count_mask = (~0UL >> ltt_chan->n_subbufs_order);
ltt_chan->n_cpus = get_n_cpus();
//ust// ltt_chan->buf = percpu_alloc_mask(sizeof(struct ltt_channel_buf_struct), GFP_KERNEL, cpu_possible_map);
- ltt_chan->buf = (void *) malloc(ltt_chan->n_cpus * sizeof(void *));
+ ltt_chan->buf = (void *) zmalloc(ltt_chan->n_cpus * sizeof(void *));
if(ltt_chan->buf == NULL) {
goto error;
}
- ltt_chan->buf_struct_shmids = (int *) malloc(ltt_chan->n_cpus * sizeof(int));
+ ltt_chan->buf_struct_shmids = (int *) zmalloc(ltt_chan->n_cpus * sizeof(int));
if(ltt_chan->buf_struct_shmids == NULL)
goto free_buf;
return -1;
}
-/*
- * LTTng channel flush function.
- *
- * Must be called when no tracing is active in the channel, because of
- * accesses across CPUs.
- */
-static notrace void ltt_relay_buffer_flush(struct ust_buffer *buf)
-{
- int result;
-
-//ust// buf->finalized = 1;
- ltt_force_switch(buf, FORCE_FLUSH);
-
- result = write(buf->data_ready_fd_write, "1", 1);
- if(result == -1) {
- PERROR("write (in ltt_relay_buffer_flush)");
- ERR("this should never happen!");
- }
-}
-
static void ltt_relay_async_wakeup_chan(struct ust_channel *ltt_channel)
{
//ust// unsigned int i;
if (channel->buf[cpu]) {
struct ust_buffer *buf = channel->buf[cpu];
- ltt_relay_buffer_flush(buf);
+ ltt_force_switch(buf, FORCE_FLUSH);
//ust// ltt_relay_wake_writers(ltt_buf);
/* closing the pipe tells the consumer the buffer is finished */
* This compiler barrier is upgraded into a smp_wmb() by the IPI
* sent by get_subbuf() when it does its smp_rmb().
*/
- barrier();
+ smp_wmb();
uatomic_add(&buf->commit_count[oldidx].cc, padding_size);
commit_count = uatomic_read(&buf->commit_count[oldidx].cc);
ltt_check_deliver(chan, buf, offsets->old - 1, commit_count, oldidx);
* This compiler barrier is upgraded into a smp_wmb() by the IPI
* sent by get_subbuf() when it does its smp_rmb().
*/
- barrier();
+ smp_wmb();
uatomic_add(&buf->commit_count[beginidx].cc, ltt_subbuffer_header_size());
commit_count = uatomic_read(&buf->commit_count[beginidx].cc);
/* Check if the written buffer has to be delivered */
* This compiler barrier is upgraded into a smp_wmb() by the IPI
* sent by get_subbuf() when it does its smp_rmb().
*/
- barrier();
+ smp_wmb();
uatomic_add(&buf->commit_count[endidx].cc, padding_size);
commit_count = uatomic_read(&buf->commit_count[endidx].cc);
ltt_check_deliver(chan, buf,
* Return : -ENOSPC if not enough space, else returns 0.
* It will take care of sub-buffer switching.
*/
-int ltt_reserve_slot_lockless_slow(struct ust_trace *trace,
- struct ust_channel *chan, void **transport_data,
- size_t data_size, size_t *slot_size, long *buf_offset, u64 *tsc,
- unsigned int *rflags, int largest_align, int cpu)
+int ltt_reserve_slot_lockless_slow(struct ust_channel *chan,
+ struct ust_trace *trace, size_t data_size,
+ int largest_align, int cpu,
+ struct ust_buffer **ret_buf,
+ size_t *slot_size, long *buf_offset,
+ u64 *tsc, unsigned int *rflags)
{
- struct ust_buffer *buf = chan->buf[cpu];
+ struct ust_buffer *buf = *ret_buf = chan->buf[cpu];
struct ltt_reserve_switch_offsets offsets;
offsets.size = 0;
ltt_transport_unregister(&ust_relay_transport);
}
-size_t ltt_write_event_header_slow(struct ust_trace *trace,
- struct ust_channel *channel,
+size_t ltt_write_event_header_slow(struct ust_channel *channel,
struct ust_buffer *buf, long buf_offset,
u16 eID, u32 event_size,
u64 tsc, unsigned int rflags)