ust: first try at blocking support for consumer
[ust.git] / libtracing / relay.c
CommitLineData
bb07823d
PMF
1/*
2 * Public API and common code for kernel->userspace relay file support.
3 *
4 * Copyright (C) 2002-2005 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp
5 * Copyright (C) 1999-2005 - Karim Yaghmour (karim@opersys.com)
6 * Copyright (C) 2008 - Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
7 *
8 * Moved to kernel/relay.c by Paul Mundt, 2006.
9 * November 2006 - CPU hotplug support by Mathieu Desnoyers
10 * (mathieu.desnoyers@polymtl.ca)
11 *
12 * This file is released under the GPL.
13 */
14//ust// #include <linux/errno.h>
15//ust// #include <linux/stddef.h>
16//ust// #include <linux/slab.h>
17//ust// #include <linux/module.h>
18//ust// #include <linux/string.h>
19//ust// #include <linux/ltt-relay.h>
20//ust// #include <linux/vmalloc.h>
21//ust// #include <linux/mm.h>
22//ust// #include <linux/cpu.h>
23//ust// #include <linux/splice.h>
24//ust// #include <linux/bitops.h>
1ae7f074 25#include "kernelcompat.h"
bb07823d 26#include <sys/mman.h>
aafb1650
PMF
27#include <sys/ipc.h>
28#include <sys/shm.h>
bb07823d
PMF
29#include "list.h"
30#include "relay.h"
31#include "channels.h"
32#include "kref.h"
33#include "tracer.h"
34#include "tracercore.h"
35#include "usterr.h"
36
37/* list of open channels, for cpu hotplug */
38static DEFINE_MUTEX(relay_channels_mutex);
39static LIST_HEAD(relay_channels);
40
c1dea0b3
PMF
41
42static struct dentry *ltt_create_buf_file_callback(struct rchan_buf *buf);
43
bb07823d
PMF
44/**
45 * relay_alloc_buf - allocate a channel buffer
46 * @buf: the buffer struct
47 * @size: total size of the buffer
48 */
49//ust// static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
50//ust//{
51//ust// unsigned int i, n_pages;
52//ust// struct buf_page *buf_page, *n;
53//ust//
54//ust// *size = PAGE_ALIGN(*size);
55//ust// n_pages = *size >> PAGE_SHIFT;
56//ust//
57//ust// INIT_LIST_HEAD(&buf->pages);
58//ust//
59//ust// for (i = 0; i < n_pages; i++) {
60//ust// buf_page = kmalloc_node(sizeof(*buf_page), GFP_KERNEL,
61//ust// cpu_to_node(buf->cpu));
62//ust// if (unlikely(!buf_page))
63//ust// goto depopulate;
64//ust// buf_page->page = alloc_pages_node(cpu_to_node(buf->cpu),
65//ust// GFP_KERNEL | __GFP_ZERO, 0);
66//ust// if (unlikely(!buf_page->page)) {
67//ust// kfree(buf_page);
68//ust// goto depopulate;
69//ust// }
70//ust// list_add_tail(&buf_page->list, &buf->pages);
71//ust// buf_page->offset = (size_t)i << PAGE_SHIFT;
72//ust// buf_page->buf = buf;
73//ust// set_page_private(buf_page->page, (unsigned long)buf_page);
74//ust// if (i == 0) {
75//ust// buf->wpage = buf_page;
76//ust// buf->hpage[0] = buf_page;
77//ust// buf->hpage[1] = buf_page;
78//ust// buf->rpage = buf_page;
79//ust// }
80//ust// }
81//ust// buf->page_count = n_pages;
82//ust// return 0;
83//ust//
84//ust//depopulate:
85//ust// list_for_each_entry_safe(buf_page, n, &buf->pages, list) {
86//ust// list_del_init(&buf_page->list);
87//ust// __free_page(buf_page->page);
88//ust// kfree(buf_page);
89//ust// }
90//ust// return -ENOMEM;
91//ust//}
92
93static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
94{
95 unsigned int n_pages;
96 struct buf_page *buf_page, *n;
97
aafb1650
PMF
98 void *ptr;
99 int result;
bb07823d
PMF
100
101 *size = PAGE_ALIGN(*size);
102
3847c3ba
PMF
103 result = buf->shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
104 if(buf->shmid == -1) {
aafb1650 105 PERROR("shmget");
bb07823d
PMF
106 return -1;
107 }
108
3847c3ba 109 ptr = shmat(buf->shmid, NULL, 0);
aafb1650
PMF
110 if(ptr == (void *) -1) {
111 perror("shmat");
112 goto destroy_shmem;
113 }
114
115 /* Already mark the shared memory for destruction. This will occur only
116 * when all users have detached.
117 */
3847c3ba 118 result = shmctl(buf->shmid, IPC_RMID, NULL);
aafb1650
PMF
119 if(result == -1) {
120 perror("shmctl");
121 return -1;
122 }
123
124 buf->buf_data = ptr;
bb07823d
PMF
125 buf->buf_size = *size;
126
127 return 0;
aafb1650
PMF
128
129 destroy_shmem:
3847c3ba 130 result = shmctl(buf->shmid, IPC_RMID, NULL);
aafb1650
PMF
131 if(result == -1) {
132 perror("shmctl");
133 }
134
135 return -1;
bb07823d
PMF
136}
137
138/**
139 * relay_create_buf - allocate and initialize a channel buffer
140 * @chan: the relay channel
141 * @cpu: cpu the buffer belongs to
142 *
143 * Returns channel buffer if successful, %NULL otherwise.
144 */
145static struct rchan_buf *relay_create_buf(struct rchan *chan)
146{
147 int ret;
148 struct rchan_buf *buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
149 if (!buf)
150 return NULL;
151
152// buf->cpu = cpu;
153 ret = relay_alloc_buf(buf, &chan->alloc_size);
154 if (ret)
155 goto free_buf;
156
157 buf->chan = chan;
158 kref_get(&buf->chan->kref);
159 return buf;
160
161free_buf:
162 kfree(buf);
163 return NULL;
164}
165
166/**
167 * relay_destroy_channel - free the channel struct
168 * @kref: target kernel reference that contains the relay channel
169 *
170 * Should only be called from kref_put().
171 */
172static void relay_destroy_channel(struct kref *kref)
173{
174 struct rchan *chan = container_of(kref, struct rchan, kref);
175 kfree(chan);
176}
177
178/**
179 * relay_destroy_buf - destroy an rchan_buf struct and associated buffer
180 * @buf: the buffer struct
181 */
182static void relay_destroy_buf(struct rchan_buf *buf)
183{
184 struct rchan *chan = buf->chan;
185 struct buf_page *buf_page, *n;
186 int result;
187
188 result = munmap(buf->buf_data, buf->buf_size);
189 if(result == -1) {
190 PERROR("munmap");
191 }
192
193//ust// chan->buf[buf->cpu] = NULL;
194 kfree(buf);
195 kref_put(&chan->kref, relay_destroy_channel);
196}
197
198/**
199 * relay_remove_buf - remove a channel buffer
200 * @kref: target kernel reference that contains the relay buffer
201 *
202 * Removes the file from the fileystem, which also frees the
203 * rchan_buf_struct and the channel buffer. Should only be called from
204 * kref_put().
205 */
206static void relay_remove_buf(struct kref *kref)
207{
208 struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref);
98963de4 209//ust// buf->chan->cb->remove_buf_file(buf);
bb07823d
PMF
210 relay_destroy_buf(buf);
211}
212
213/*
214 * High-level relay kernel API and associated functions.
215 */
216
217/*
218 * rchan_callback implementations defining default channel behavior. Used
219 * in place of corresponding NULL values in client callback struct.
220 */
221
222/*
223 * create_buf_file_create() default callback. Does nothing.
224 */
225static struct dentry *create_buf_file_default_callback(const char *filename,
226 struct dentry *parent,
227 int mode,
228 struct rchan_buf *buf)
229{
230 return NULL;
231}
232
233/*
234 * remove_buf_file() default callback. Does nothing.
235 */
236static int remove_buf_file_default_callback(struct dentry *dentry)
237{
238 return -EINVAL;
239}
240
241/**
242 * wakeup_readers - wake up readers waiting on a channel
243 * @data: contains the channel buffer
244 *
245 * This is the timer function used to defer reader waking.
246 */
247//ust// static void wakeup_readers(unsigned long data)
248//ust// {
249//ust// struct rchan_buf *buf = (struct rchan_buf *)data;
250//ust// wake_up_interruptible(&buf->read_wait);
251//ust// }
252
253/**
254 * __relay_reset - reset a channel buffer
255 * @buf: the channel buffer
256 * @init: 1 if this is a first-time initialization
257 *
258 * See relay_reset() for description of effect.
259 */
260static void __relay_reset(struct rchan_buf *buf, unsigned int init)
261{
262 if (init) {
263//ust// init_waitqueue_head(&buf->read_wait);
264 kref_init(&buf->kref);
265//ust// setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
266 } else
267//ust// del_timer_sync(&buf->timer);
268
269 buf->finalized = 0;
270}
271
272/*
273 * relay_open_buf - create a new relay channel buffer
274 *
275 * used by relay_open() and CPU hotplug.
276 */
277static struct rchan_buf *relay_open_buf(struct rchan *chan)
278{
279 struct rchan_buf *buf = NULL;
280 struct dentry *dentry;
281//ust// char *tmpname;
282
283//ust// tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL);
284//ust// if (!tmpname)
285//ust// goto end;
286//ust// snprintf(tmpname, NAME_MAX, "%s%d", chan->base_filename, cpu);
287
288 buf = relay_create_buf(chan);
289 if (!buf)
290 goto free_name;
291
292 __relay_reset(buf, 1);
293
294 /* Create file in fs */
295//ust// dentry = chan->cb->create_buf_file(tmpname, chan->parent, S_IRUSR,
296//ust// buf);
c1dea0b3
PMF
297
298 ltt_create_buf_file_callback(buf); // ust //
299
bb07823d
PMF
300//ust// if (!dentry)
301//ust// goto free_buf;
302//ust//
303//ust// buf->dentry = dentry;
304
305 goto free_name;
306
307free_buf:
308 relay_destroy_buf(buf);
309 buf = NULL;
310free_name:
311//ust// kfree(tmpname);
312end:
313 return buf;
314}
315
316/**
317 * relay_close_buf - close a channel buffer
318 * @buf: channel buffer
319 *
320 * Marks the buffer finalized and restores the default callbacks.
321 * The channel buffer and channel buffer data structure are then freed
322 * automatically when the last reference is given up.
323 */
324static void relay_close_buf(struct rchan_buf *buf)
325{
326//ust// del_timer_sync(&buf->timer);
327 kref_put(&buf->kref, relay_remove_buf);
328}
329
330//ust// static void setup_callbacks(struct rchan *chan,
331//ust// struct rchan_callbacks *cb)
332//ust// {
333//ust// if (!cb) {
334//ust// chan->cb = &default_channel_callbacks;
335//ust// return;
336//ust// }
337//ust//
338//ust// if (!cb->create_buf_file)
339//ust// cb->create_buf_file = create_buf_file_default_callback;
340//ust// if (!cb->remove_buf_file)
341//ust// cb->remove_buf_file = remove_buf_file_default_callback;
342//ust// chan->cb = cb;
343//ust// }
344
345/**
346 * relay_hotcpu_callback - CPU hotplug callback
347 * @nb: notifier block
348 * @action: hotplug action to take
349 * @hcpu: CPU number
350 *
351 * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
352 */
353//ust// static int __cpuinit relay_hotcpu_callback(struct notifier_block *nb,
354//ust// unsigned long action,
355//ust// void *hcpu)
356//ust// {
357//ust// unsigned int hotcpu = (unsigned long)hcpu;
358//ust// struct rchan *chan;
359//ust//
360//ust// switch (action) {
361//ust// case CPU_UP_PREPARE:
362//ust// case CPU_UP_PREPARE_FROZEN:
363//ust// mutex_lock(&relay_channels_mutex);
364//ust// list_for_each_entry(chan, &relay_channels, list) {
365//ust// if (chan->buf[hotcpu])
366//ust// continue;
367//ust// chan->buf[hotcpu] = relay_open_buf(chan, hotcpu);
368//ust// if (!chan->buf[hotcpu]) {
369//ust// printk(KERN_ERR
370//ust// "relay_hotcpu_callback: cpu %d buffer "
371//ust// "creation failed\n", hotcpu);
372//ust// mutex_unlock(&relay_channels_mutex);
373//ust// return NOTIFY_BAD;
374//ust// }
375//ust// }
376//ust// mutex_unlock(&relay_channels_mutex);
377//ust// break;
378//ust// case CPU_DEAD:
379//ust// case CPU_DEAD_FROZEN:
380//ust// /* No need to flush the cpu : will be flushed upon
381//ust// * final relay_flush() call. */
382//ust// break;
383//ust// }
384//ust// return NOTIFY_OK;
385//ust// }
386
387/**
388 * ltt_relay_open - create a new relay channel
389 * @base_filename: base name of files to create
390 * @parent: dentry of parent directory, %NULL for root directory
391 * @subbuf_size: size of sub-buffers
392 * @n_subbufs: number of sub-buffers
393 * @cb: client callback functions
394 * @private_data: user-defined data
395 *
396 * Returns channel pointer if successful, %NULL otherwise.
397 *
398 * Creates a channel buffer for each cpu using the sizes and
399 * attributes specified. The created channel buffer files
400 * will be named base_filename0...base_filenameN-1. File
401 * permissions will be %S_IRUSR.
402 */
403struct rchan *ltt_relay_open(const char *base_filename,
404 struct dentry *parent,
405 size_t subbuf_size,
406 size_t n_subbufs,
407 void *private_data)
408{
409 unsigned int i;
410 struct rchan *chan;
411//ust// if (!base_filename)
412//ust// return NULL;
413
414 if (!(subbuf_size && n_subbufs))
415 return NULL;
416
417 chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
418 if (!chan)
419 return NULL;
420
421 chan->version = LTT_RELAY_CHANNEL_VERSION;
422 chan->n_subbufs = n_subbufs;
423 chan->subbuf_size = subbuf_size;
424 chan->subbuf_size_order = get_count_order(subbuf_size);
425 chan->alloc_size = FIX_SIZE(subbuf_size * n_subbufs);
426 chan->parent = parent;
427 chan->private_data = private_data;
428//ust// strlcpy(chan->base_filename, base_filename, NAME_MAX);
429//ust// setup_callbacks(chan, cb);
430 kref_init(&chan->kref);
431
432 mutex_lock(&relay_channels_mutex);
433//ust// for_each_online_cpu(i) {
434 chan->buf = relay_open_buf(chan);
435 if (!chan->buf)
436 goto error;
437//ust// }
438 list_add(&chan->list, &relay_channels);
439 mutex_unlock(&relay_channels_mutex);
440
441 return chan;
442
443//ust//free_bufs:
444//ust// for_each_possible_cpu(i) {
445//ust// if (!chan->buf[i])
446//ust// break;
447//ust// relay_close_buf(chan->buf[i]);
448//ust// }
449
450 error:
451 kref_put(&chan->kref, relay_destroy_channel);
452 mutex_unlock(&relay_channels_mutex);
453 return NULL;
454}
455//ust// EXPORT_SYMBOL_GPL(ltt_relay_open);
456
457/**
458 * ltt_relay_close - close the channel
459 * @chan: the channel
460 *
461 * Closes all channel buffers and frees the channel.
462 */
463void ltt_relay_close(struct rchan *chan)
464{
465 unsigned int i;
466
467 if (!chan)
468 return;
469
470 mutex_lock(&relay_channels_mutex);
471//ust// for_each_possible_cpu(i)
472 if (chan->buf)
473 relay_close_buf(chan->buf);
474
475 list_del(&chan->list);
476 kref_put(&chan->kref, relay_destroy_channel);
477 mutex_unlock(&relay_channels_mutex);
478}
479//ust// EXPORT_SYMBOL_GPL(ltt_relay_close);
480
481/*
482 * Start iteration at the previous element. Skip the real list head.
483 */
484//ust// struct buf_page *ltt_relay_find_prev_page(struct rchan_buf *buf,
485//ust// struct buf_page *page, size_t offset, ssize_t diff_offset)
486//ust// {
487//ust// struct buf_page *iter;
488//ust// size_t orig_iter_off;
489//ust// unsigned int i = 0;
490//ust//
491//ust// orig_iter_off = page->offset;
492//ust// list_for_each_entry_reverse(iter, &page->list, list) {
493//ust// /*
494//ust// * Skip the real list head.
495//ust// */
496//ust// if (&iter->list == &buf->pages)
497//ust// continue;
498//ust// i++;
499//ust// if (offset >= iter->offset
500//ust// && offset < iter->offset + PAGE_SIZE) {
501//ust// #ifdef CONFIG_LTT_RELAY_CHECK_RANDOM_ACCESS
502//ust// if (i > 1) {
503//ust// printk(KERN_WARNING
504//ust// "Backward random access detected in "
505//ust// "ltt_relay. Iterations %u, "
506//ust// "offset %zu, orig iter->off %zu, "
507//ust// "iter->off %zu diff_offset %zd.\n", i,
508//ust// offset, orig_iter_off, iter->offset,
509//ust// diff_offset);
510//ust// WARN_ON(1);
511//ust// }
512//ust// #endif
513//ust// return iter;
514//ust// }
515//ust// }
516//ust// WARN_ON(1);
517//ust// return NULL;
518//ust// }
519//ust// EXPORT_SYMBOL_GPL(ltt_relay_find_prev_page);
520
521/*
522 * Start iteration at the next element. Skip the real list head.
523 */
524//ust// struct buf_page *ltt_relay_find_next_page(struct rchan_buf *buf,
525//ust// struct buf_page *page, size_t offset, ssize_t diff_offset)
526//ust// {
527//ust// struct buf_page *iter;
528//ust// unsigned int i = 0;
529//ust// size_t orig_iter_off;
530//ust//
531//ust// orig_iter_off = page->offset;
532//ust// list_for_each_entry(iter, &page->list, list) {
533//ust// /*
534//ust// * Skip the real list head.
535//ust// */
536//ust// if (&iter->list == &buf->pages)
537//ust// continue;
538//ust// i++;
539//ust// if (offset >= iter->offset
540//ust// && offset < iter->offset + PAGE_SIZE) {
541//ust// #ifdef CONFIG_LTT_RELAY_CHECK_RANDOM_ACCESS
542//ust// if (i > 1) {
543//ust// printk(KERN_WARNING
544//ust// "Forward random access detected in "
545//ust// "ltt_relay. Iterations %u, "
546//ust// "offset %zu, orig iter->off %zu, "
547//ust// "iter->off %zu diff_offset %zd.\n", i,
548//ust// offset, orig_iter_off, iter->offset,
549//ust// diff_offset);
550//ust// WARN_ON(1);
551//ust// }
552//ust// #endif
553//ust// return iter;
554//ust// }
555//ust// }
556//ust// WARN_ON(1);
557//ust// return NULL;
558//ust// }
559//ust// EXPORT_SYMBOL_GPL(ltt_relay_find_next_page);
560
561/**
562 * ltt_relay_write - write data to a ltt_relay buffer.
563 * @buf : buffer
564 * @offset : offset within the buffer
565 * @src : source address
566 * @len : length to write
567 * @page : cached buffer page
568 * @pagecpy : page size copied so far
569 */
570void _ltt_relay_write(struct rchan_buf *buf, size_t offset,
571 const void *src, size_t len, ssize_t cpy)
572{
573 do {
574 len -= cpy;
575 src += cpy;
576 offset += cpy;
577 /*
578 * Underlying layer should never ask for writes across
579 * subbuffers.
580 */
581 WARN_ON(offset >= buf->buf_size);
582
583 cpy = min_t(size_t, len, buf->buf_size - offset);
584 ltt_relay_do_copy(buf->buf_data + offset, src, cpy);
585 } while (unlikely(len != cpy));
586}
587//ust// EXPORT_SYMBOL_GPL(_ltt_relay_write);
588
589/**
590 * ltt_relay_read - read data from ltt_relay_buffer.
591 * @buf : buffer
592 * @offset : offset within the buffer
593 * @dest : destination address
594 * @len : length to write
595 */
596//ust// int ltt_relay_read(struct rchan_buf *buf, size_t offset,
597//ust// void *dest, size_t len)
598//ust// {
599//ust// struct buf_page *page;
600//ust// ssize_t pagecpy, orig_len;
601//ust//
602//ust// orig_len = len;
603//ust// offset &= buf->chan->alloc_size - 1;
604//ust// page = buf->rpage;
605//ust// if (unlikely(!len))
606//ust// return 0;
607//ust// for (;;) {
608//ust// page = ltt_relay_cache_page(buf, &buf->rpage, page, offset);
609//ust// pagecpy = min_t(size_t, len, PAGE_SIZE - (offset & ~PAGE_MASK));
610//ust// memcpy(dest, page_address(page->page) + (offset & ~PAGE_MASK),
611//ust// pagecpy);
612//ust// len -= pagecpy;
613//ust// if (likely(!len))
614//ust// break;
615//ust// dest += pagecpy;
616//ust// offset += pagecpy;
617//ust// /*
618//ust// * Underlying layer should never ask for reads across
619//ust// * subbuffers.
620//ust// */
621//ust// WARN_ON(offset >= buf->chan->alloc_size);
622//ust// }
623//ust// return orig_len;
624//ust// }
625//ust// EXPORT_SYMBOL_GPL(ltt_relay_read);
626
627/**
628 * ltt_relay_read_get_page - Get a whole page to read from
629 * @buf : buffer
630 * @offset : offset within the buffer
631 */
632//ust// struct buf_page *ltt_relay_read_get_page(struct rchan_buf *buf, size_t offset)
633//ust// {
634//ust// struct buf_page *page;
635
636//ust// offset &= buf->chan->alloc_size - 1;
637//ust// page = buf->rpage;
638//ust// page = ltt_relay_cache_page(buf, &buf->rpage, page, offset);
639//ust// return page;
640//ust// }
641//ust// EXPORT_SYMBOL_GPL(ltt_relay_read_get_page);
642
643/**
644 * ltt_relay_offset_address - get address of a location within the buffer
645 * @buf : buffer
646 * @offset : offset within the buffer.
647 *
648 * Return the address where a given offset is located.
649 * Should be used to get the current subbuffer header pointer. Given we know
650 * it's never on a page boundary, it's safe to write directly to this address,
651 * as long as the write is never bigger than a page size.
652 */
653void *ltt_relay_offset_address(struct rchan_buf *buf, size_t offset)
654{
655//ust// struct buf_page *page;
656//ust// unsigned int odd;
657//ust//
658//ust// offset &= buf->chan->alloc_size - 1;
659//ust// odd = !!(offset & buf->chan->subbuf_size);
660//ust// page = buf->hpage[odd];
661//ust// if (offset < page->offset || offset >= page->offset + PAGE_SIZE)
662//ust// buf->hpage[odd] = page = buf->wpage;
663//ust// page = ltt_relay_cache_page(buf, &buf->hpage[odd], page, offset);
664//ust// return page_address(page->page) + (offset & ~PAGE_MASK);
c1dea0b3 665 return ((char *)buf->buf_data)+offset;
bb07823d
PMF
666 return NULL;
667}
668//ust// EXPORT_SYMBOL_GPL(ltt_relay_offset_address);
669
670/**
671 * relay_file_open - open file op for relay files
672 * @inode: the inode
673 * @filp: the file
674 *
675 * Increments the channel buffer refcount.
676 */
677//ust// static int relay_file_open(struct inode *inode, struct file *filp)
678//ust// {
679//ust// struct rchan_buf *buf = inode->i_private;
680//ust// kref_get(&buf->kref);
681//ust// filp->private_data = buf;
682//ust//
683//ust// return nonseekable_open(inode, filp);
684//ust// }
685
686/**
687 * relay_file_release - release file op for relay files
688 * @inode: the inode
689 * @filp: the file
690 *
691 * Decrements the channel refcount, as the filesystem is
692 * no longer using it.
693 */
694//ust// static int relay_file_release(struct inode *inode, struct file *filp)
695//ust// {
696//ust// struct rchan_buf *buf = filp->private_data;
697//ust// kref_put(&buf->kref, relay_remove_buf);
698//ust//
699//ust// return 0;
700//ust// }
701
702//ust// const struct file_operations ltt_relay_file_operations = {
703//ust// .open = relay_file_open,
704//ust// .release = relay_file_release,
705//ust// };
706//ust// EXPORT_SYMBOL_GPL(ltt_relay_file_operations);
707
708//ust// static __init int relay_init(void)
709//ust// {
710//ust// hotcpu_notifier(relay_hotcpu_callback, 5);
711//ust// return 0;
712//ust// }
713
714//ust// module_init(relay_init);
e1152c37
PMF
715/*
716 * ltt/ltt-relay.c
717 *
718 * (C) Copyright 2005-2008 - Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
719 *
720 * LTTng lockless buffer space management (reader/writer).
721 *
722 * Author:
723 * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
724 *
725 * Inspired from LTT :
726 * Karim Yaghmour (karim@opersys.com)
727 * Tom Zanussi (zanussi@us.ibm.com)
728 * Bob Wisniewski (bob@watson.ibm.com)
729 * And from K42 :
730 * Bob Wisniewski (bob@watson.ibm.com)
731 *
732 * Changelog:
733 * 08/10/08, Cleanup.
734 * 19/10/05, Complete lockless mechanism.
735 * 27/05/05, Modular redesign and rewrite.
736 *
737 * Userspace reader semantic :
738 * while (poll fd != POLLHUP) {
739 * - ioctl RELAY_GET_SUBBUF_SIZE
740 * while (1) {
741 * - ioctl GET_SUBBUF
742 * - splice 1 subbuffer worth of data to a pipe
743 * - splice the data from pipe to disk/network
744 * - ioctl PUT_SUBBUF, check error value
745 * if err val < 0, previous subbuffer was corrupted.
746 * }
747 * }
748 */
749
bb07823d
PMF
750//ust// #include <linux/time.h>
751//ust// #include <linux/ltt-tracer.h>
752//ust// #include <linux/ltt-relay.h>
753//ust// #include <linux/module.h>
754//ust// #include <linux/string.h>
755//ust// #include <linux/slab.h>
756//ust// #include <linux/init.h>
757//ust// #include <linux/rcupdate.h>
758//ust// #include <linux/sched.h>
759//ust// #include <linux/bitops.h>
760//ust// #include <linux/fs.h>
761//ust// #include <linux/smp_lock.h>
762//ust// #include <linux/debugfs.h>
763//ust// #include <linux/stat.h>
764//ust// #include <linux/cpu.h>
765//ust// #include <linux/pipe_fs_i.h>
766//ust// #include <linux/splice.h>
767//ust// #include <asm/atomic.h>
768//ust// #include <asm/local.h>
e1152c37
PMF
769
770#if 0
771#define printk_dbg(fmt, args...) printk(fmt, args)
772#else
773#define printk_dbg(fmt, args...)
774#endif
775
e1152c37
PMF
776/*
777 * Last TSC comparison functions. Check if the current TSC overflows
778 * LTT_TSC_BITS bits from the last TSC read. Reads and writes last_tsc
779 * atomically.
780 */
781
782#if (BITS_PER_LONG == 32)
783static inline void save_last_tsc(struct ltt_channel_buf_struct *ltt_buf,
784 u64 tsc)
785{
786 ltt_buf->last_tsc = (unsigned long)(tsc >> LTT_TSC_BITS);
787}
788
789static inline int last_tsc_overflow(struct ltt_channel_buf_struct *ltt_buf,
790 u64 tsc)
791{
792 unsigned long tsc_shifted = (unsigned long)(tsc >> LTT_TSC_BITS);
793
794 if (unlikely((tsc_shifted - ltt_buf->last_tsc)))
795 return 1;
796 else
797 return 0;
798}
799#else
800static inline void save_last_tsc(struct ltt_channel_buf_struct *ltt_buf,
801 u64 tsc)
802{
803 ltt_buf->last_tsc = (unsigned long)tsc;
804}
805
806static inline int last_tsc_overflow(struct ltt_channel_buf_struct *ltt_buf,
807 u64 tsc)
808{
809 if (unlikely((tsc - ltt_buf->last_tsc) >> LTT_TSC_BITS))
810 return 1;
811 else
812 return 0;
813}
814#endif
815
5f54827b 816//ust// static struct file_operations ltt_file_operations;
e1152c37
PMF
817
818/*
819 * A switch is done during tracing or as a final flush after tracing (so it
820 * won't write in the new sub-buffer).
821 */
822enum force_switch_mode { FORCE_ACTIVE, FORCE_FLUSH };
823
824static int ltt_relay_create_buffer(struct ltt_trace_struct *trace,
825 struct ltt_channel_struct *ltt_chan,
826 struct rchan_buf *buf,
e1152c37
PMF
827 unsigned int n_subbufs);
828
bb07823d 829static void ltt_relay_destroy_buffer(struct ltt_channel_struct *ltt_chan);
e1152c37
PMF
830
831static void ltt_force_switch(struct rchan_buf *buf,
832 enum force_switch_mode mode);
833
834/*
835 * Trace callbacks
836 */
837static void ltt_buffer_begin_callback(struct rchan_buf *buf,
838 u64 tsc, unsigned int subbuf_idx)
839{
840 struct ltt_channel_struct *channel =
841 (struct ltt_channel_struct *)buf->chan->private_data;
842 struct ltt_subbuffer_header *header =
843 (struct ltt_subbuffer_header *)
844 ltt_relay_offset_address(buf,
845 subbuf_idx * buf->chan->subbuf_size);
846
847 header->cycle_count_begin = tsc;
848 header->lost_size = 0xFFFFFFFF; /* for debugging */
849 header->buf_size = buf->chan->subbuf_size;
850 ltt_write_trace_header(channel->trace, header);
851}
852
853/*
854 * offset is assumed to never be 0 here : never deliver a completely empty
855 * subbuffer. The lost size is between 0 and subbuf_size-1.
856 */
857static notrace void ltt_buffer_end_callback(struct rchan_buf *buf,
858 u64 tsc, unsigned int offset, unsigned int subbuf_idx)
859{
860 struct ltt_channel_struct *channel =
861 (struct ltt_channel_struct *)buf->chan->private_data;
bb07823d 862 struct ltt_channel_buf_struct *ltt_buf = channel->buf;
e1152c37
PMF
863 struct ltt_subbuffer_header *header =
864 (struct ltt_subbuffer_header *)
865 ltt_relay_offset_address(buf,
866 subbuf_idx * buf->chan->subbuf_size);
867
868 header->lost_size = SUBBUF_OFFSET((buf->chan->subbuf_size - offset),
869 buf->chan);
870 header->cycle_count_end = tsc;
c1dea0b3
PMF
871 header->events_lost = local_read(&ltt_buf->events_lost);
872 header->subbuf_corrupt = local_read(&ltt_buf->corrupted_subbuffers);
873
e1152c37
PMF
874}
875
46ef48cd
PMF
876void (*wake_consumer)(void *, int) = NULL;
877
878void relay_set_wake_consumer(void (*wake)(void *, int))
879{
880 wake_consumer = wake;
881}
882
883void relay_wake_consumer(void *arg, int finished)
884{
885 if(wake_consumer)
886 wake_consumer(arg, finished);
887}
888
e1152c37
PMF
889static notrace void ltt_deliver(struct rchan_buf *buf, unsigned int subbuf_idx,
890 void *subbuf)
891{
892 struct ltt_channel_struct *channel =
893 (struct ltt_channel_struct *)buf->chan->private_data;
bb07823d 894 struct ltt_channel_buf_struct *ltt_buf = channel->buf;
e1152c37 895
46ef48cd
PMF
896 if(ltt_buf->call_wake_consumer)
897 relay_wake_consumer(ACCESS_ONCE(ltt_buf->wake_consumer_arg), 0);
898//ust// atomic_set(&ltt_buf->wakeup_readers, 1);
e1152c37
PMF
899}
900
c1dea0b3 901static struct dentry *ltt_create_buf_file_callback(struct rchan_buf *buf)
e1152c37
PMF
902{
903 struct ltt_channel_struct *ltt_chan;
904 int err;
5f54827b 905//ust// struct dentry *dentry;
e1152c37
PMF
906
907 ltt_chan = buf->chan->private_data;
bb07823d 908 err = ltt_relay_create_buffer(ltt_chan->trace, ltt_chan, buf, buf->chan->n_subbufs);
e1152c37
PMF
909 if (err)
910 return ERR_PTR(err);
911
5f54827b
PMF
912//ust// dentry = debugfs_create_file(filename, mode, parent, buf,
913//ust// &ltt_file_operations);
914//ust// if (!dentry)
915//ust// goto error;
916//ust// return dentry;
c1dea0b3 917 return NULL; //ust//
5f54827b 918//ust//error:
bb07823d 919 ltt_relay_destroy_buffer(ltt_chan);
e1152c37
PMF
920 return NULL;
921}
922
bb07823d 923static int ltt_remove_buf_file_callback(struct rchan_buf *buf)
e1152c37 924{
bb07823d 925//ust// struct rchan_buf *buf = dentry->d_inode->i_private;
e1152c37
PMF
926 struct ltt_channel_struct *ltt_chan = buf->chan->private_data;
927
5f54827b 928//ust// debugfs_remove(dentry);
bb07823d 929 ltt_relay_destroy_buffer(ltt_chan);
e1152c37
PMF
930
931 return 0;
932}
933
934/*
935 * Wake writers :
936 *
937 * This must be done after the trace is removed from the RCU list so that there
938 * are no stalled writers.
939 */
bb07823d
PMF
940//ust// static void ltt_relay_wake_writers(struct ltt_channel_buf_struct *ltt_buf)
941//ust// {
942//ust//
943//ust// if (waitqueue_active(&ltt_buf->write_wait))
944//ust// wake_up_interruptible(&ltt_buf->write_wait);
945//ust// }
e1152c37
PMF
946
947/*
948 * This function should not be called from NMI interrupt context
949 */
950static notrace void ltt_buf_unfull(struct rchan_buf *buf,
951 unsigned int subbuf_idx,
952 long offset)
953{
bb07823d
PMF
954//ust// struct ltt_channel_struct *ltt_channel =
955//ust// (struct ltt_channel_struct *)buf->chan->private_data;
956//ust// struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
957//ust//
958//ust// ltt_relay_wake_writers(ltt_buf);
e1152c37
PMF
959}
960
961/**
962 * ltt_open - open file op for ltt files
963 * @inode: opened inode
964 * @file: opened file
965 *
966 * Open implementation. Makes sure only one open instance of a buffer is
967 * done at a given moment.
968 */
bb07823d
PMF
969//ust// static int ltt_open(struct inode *inode, struct file *file)
970//ust// {
971//ust// struct rchan_buf *buf = inode->i_private;
972//ust// struct ltt_channel_struct *ltt_channel =
973//ust// (struct ltt_channel_struct *)buf->chan->private_data;
974//ust// struct ltt_channel_buf_struct *ltt_buf =
975//ust// percpu_ptr(ltt_channel->buf, buf->cpu);
976//ust//
977//ust// if (!atomic_long_add_unless(&ltt_buf->active_readers, 1, 1))
978//ust// return -EBUSY;
979//ust// return ltt_relay_file_operations.open(inode, file);
980//ust// }
e1152c37
PMF
981
982/**
983 * ltt_release - release file op for ltt files
984 * @inode: opened inode
985 * @file: opened file
986 *
987 * Release implementation.
988 */
bb07823d
PMF
989//ust// static int ltt_release(struct inode *inode, struct file *file)
990//ust// {
991//ust// struct rchan_buf *buf = inode->i_private;
992//ust// struct ltt_channel_struct *ltt_channel =
993//ust// (struct ltt_channel_struct *)buf->chan->private_data;
994//ust// struct ltt_channel_buf_struct *ltt_buf =
995//ust// percpu_ptr(ltt_channel->buf, buf->cpu);
996//ust// int ret;
997//ust//
998//ust// WARN_ON(atomic_long_read(&ltt_buf->active_readers) != 1);
999//ust// atomic_long_dec(&ltt_buf->active_readers);
1000//ust// ret = ltt_relay_file_operations.release(inode, file);
1001//ust// WARN_ON(ret);
1002//ust// return ret;
1003//ust// }
e1152c37
PMF
1004
1005/**
1006 * ltt_poll - file op for ltt files
1007 * @filp: the file
1008 * @wait: poll table
1009 *
1010 * Poll implementation.
1011 */
bb07823d
PMF
1012//ust// static unsigned int ltt_poll(struct file *filp, poll_table *wait)
1013//ust// {
1014//ust// unsigned int mask = 0;
1015//ust// struct inode *inode = filp->f_dentry->d_inode;
1016//ust// struct rchan_buf *buf = inode->i_private;
1017//ust// struct ltt_channel_struct *ltt_channel =
1018//ust// (struct ltt_channel_struct *)buf->chan->private_data;
1019//ust// struct ltt_channel_buf_struct *ltt_buf =
1020//ust// percpu_ptr(ltt_channel->buf, buf->cpu);
1021//ust//
1022//ust// if (filp->f_mode & FMODE_READ) {
1023//ust// poll_wait_set_exclusive(wait);
1024//ust// poll_wait(filp, &buf->read_wait, wait);
1025//ust//
1026//ust// WARN_ON(atomic_long_read(&ltt_buf->active_readers) != 1);
1027//ust// if (SUBBUF_TRUNC(local_read(&ltt_buf->offset),
1028//ust// buf->chan)
1029//ust// - SUBBUF_TRUNC(atomic_long_read(&ltt_buf->consumed),
1030//ust// buf->chan)
1031//ust// == 0) {
1032//ust// if (buf->finalized)
1033//ust// return POLLHUP;
1034//ust// else
1035//ust// return 0;
1036//ust// } else {
1037//ust// struct rchan *rchan =
1038//ust// ltt_channel->trans_channel_data;
1039//ust// if (SUBBUF_TRUNC(local_read(&ltt_buf->offset),
1040//ust// buf->chan)
1041//ust// - SUBBUF_TRUNC(atomic_long_read(
1042//ust// &ltt_buf->consumed),
1043//ust// buf->chan)
1044//ust// >= rchan->alloc_size)
1045//ust// return POLLPRI | POLLRDBAND;
1046//ust// else
1047//ust// return POLLIN | POLLRDNORM;
1048//ust// }
1049//ust// }
1050//ust// return mask;
1051//ust// }
e1152c37 1052
9c67dc50 1053int ltt_do_get_subbuf(struct rchan_buf *buf, struct ltt_channel_buf_struct *ltt_buf, long *pconsumed_old)
e1152c37 1054{
bb07823d 1055 struct ltt_channel_struct *ltt_channel = (struct ltt_channel_struct *)buf->chan->private_data;
e1152c37
PMF
1056 long consumed_old, consumed_idx, commit_count, write_offset;
1057 consumed_old = atomic_long_read(&ltt_buf->consumed);
1058 consumed_idx = SUBBUF_INDEX(consumed_old, buf->chan);
1059 commit_count = local_read(&ltt_buf->commit_count[consumed_idx]);
1060 /*
1061 * Make sure we read the commit count before reading the buffer
1062 * data and the write offset. Correct consumed offset ordering
1063 * wrt commit count is insured by the use of cmpxchg to update
1064 * the consumed offset.
1065 */
1066 smp_rmb();
1067 write_offset = local_read(&ltt_buf->offset);
1068 /*
1069 * Check that the subbuffer we are trying to consume has been
1070 * already fully committed.
1071 */
1072 if (((commit_count - buf->chan->subbuf_size)
1073 & ltt_channel->commit_count_mask)
1074 - (BUFFER_TRUNC(consumed_old, buf->chan)
1075 >> ltt_channel->n_subbufs_order)
1076 != 0) {
1077 return -EAGAIN;
1078 }
1079 /*
1080 * Check that we are not about to read the same subbuffer in
1081 * which the writer head is.
1082 */
1083 if ((SUBBUF_TRUNC(write_offset, buf->chan)
1084 - SUBBUF_TRUNC(consumed_old, buf->chan))
1085 == 0) {
1086 return -EAGAIN;
1087 }
1088
1089 *pconsumed_old = consumed_old;
1090 return 0;
1091}
1092
9c67dc50 1093int ltt_do_put_subbuf(struct rchan_buf *buf, struct ltt_channel_buf_struct *ltt_buf, u32 uconsumed_old)
e1152c37
PMF
1094{
1095 long consumed_new, consumed_old;
1096
1097 consumed_old = atomic_long_read(&ltt_buf->consumed);
1098 consumed_old = consumed_old & (~0xFFFFFFFFL);
1099 consumed_old = consumed_old | uconsumed_old;
1100 consumed_new = SUBBUF_ALIGN(consumed_old, buf->chan);
1101
46ef48cd 1102//ust// spin_lock(&ltt_buf->full_lock);
e1152c37
PMF
1103 if (atomic_long_cmpxchg(&ltt_buf->consumed, consumed_old,
1104 consumed_new)
1105 != consumed_old) {
1106 /* We have been pushed by the writer : the last
1107 * buffer read _is_ corrupted! It can also
1108 * happen if this is a buffer we never got. */
46ef48cd 1109//ust// spin_unlock(&ltt_buf->full_lock);
e1152c37
PMF
1110 return -EIO;
1111 } else {
1112 /* tell the client that buffer is now unfull */
1113 int index;
1114 long data;
1115 index = SUBBUF_INDEX(consumed_old, buf->chan);
1116 data = BUFFER_OFFSET(consumed_old, buf->chan);
1117 ltt_buf_unfull(buf, index, data);
46ef48cd 1118//ust// spin_unlock(&ltt_buf->full_lock);
e1152c37
PMF
1119 }
1120 return 0;
1121}
1122
1123/**
1124 * ltt_ioctl - control on the debugfs file
1125 *
1126 * @inode: the inode
1127 * @filp: the file
1128 * @cmd: the command
1129 * @arg: command arg
1130 *
1131 * This ioctl implements three commands necessary for a minimal
1132 * producer/consumer implementation :
1133 * RELAY_GET_SUBBUF
1134 * Get the next sub buffer that can be read. It never blocks.
1135 * RELAY_PUT_SUBBUF
1136 * Release the currently read sub-buffer. Parameter is the last
1137 * put subbuffer (returned by GET_SUBBUF).
1138 * RELAY_GET_N_BUBBUFS
1139 * returns the number of sub buffers in the per cpu channel.
1140 * RELAY_GET_SUBBUF_SIZE
1141 * returns the size of the sub buffers.
1142 */
5f54827b
PMF
1143//ust// static int ltt_ioctl(struct inode *inode, struct file *filp,
1144//ust// unsigned int cmd, unsigned long arg)
1145//ust// {
1146//ust// struct rchan_buf *buf = inode->i_private;
1147//ust// struct ltt_channel_struct *ltt_channel =
1148//ust// (struct ltt_channel_struct *)buf->chan->private_data;
1149//ust// struct ltt_channel_buf_struct *ltt_buf =
1150//ust// percpu_ptr(ltt_channel->buf, buf->cpu);
1151//ust// u32 __user *argp = (u32 __user *)arg;
1152//ust//
1153//ust// WARN_ON(atomic_long_read(&ltt_buf->active_readers) != 1);
1154//ust// switch (cmd) {
1155//ust// case RELAY_GET_SUBBUF:
1156//ust// {
1157//ust// int ret;
1158//ust// ret = ltt_do_get_subbuf(buf, ltt_buf, &consumed_old);
1159//ust// if(ret < 0)
1160//ust// return ret;
1161//ust// return put_user((u32)consumed_old, argp);
1162//ust// }
1163//ust// case RELAY_PUT_SUBBUF:
1164//ust// {
1165//ust// int ret;
1166//ust// u32 uconsumed_old;
1167//ust// ret = get_user(uconsumed_old, argp);
1168//ust// if (ret)
1169//ust// return ret; /* will return -EFAULT */
1170//ust// return ltt_do_put_subbuf(buf, ltt_buf, uconsumed_old);
1171//ust// }
1172//ust// case RELAY_GET_N_SUBBUFS:
1173//ust// return put_user((u32)buf->chan->n_subbufs, argp);
1174//ust// break;
1175//ust// case RELAY_GET_SUBBUF_SIZE:
1176//ust// return put_user((u32)buf->chan->subbuf_size, argp);
1177//ust// break;
1178//ust// default:
1179//ust// return -ENOIOCTLCMD;
1180//ust// }
1181//ust// return 0;
1182//ust// }
1183
1184//ust// #ifdef CONFIG_COMPAT
1185//ust// static long ltt_compat_ioctl(struct file *file, unsigned int cmd,
1186//ust// unsigned long arg)
1187//ust// {
1188//ust// long ret = -ENOIOCTLCMD;
1189//ust//
1190//ust// lock_kernel();
1191//ust// ret = ltt_ioctl(file->f_dentry->d_inode, file, cmd, arg);
1192//ust// unlock_kernel();
1193//ust//
1194//ust// return ret;
1195//ust// }
1196//ust// #endif
1197
1198//ust// static void ltt_relay_pipe_buf_release(struct pipe_inode_info *pipe,
1199//ust// struct pipe_buffer *pbuf)
1200//ust// {
1201//ust// }
1202//ust//
1203//ust// static struct pipe_buf_operations ltt_relay_pipe_buf_ops = {
1204//ust// .can_merge = 0,
1205//ust// .map = generic_pipe_buf_map,
1206//ust// .unmap = generic_pipe_buf_unmap,
1207//ust// .confirm = generic_pipe_buf_confirm,
1208//ust// .release = ltt_relay_pipe_buf_release,
1209//ust// .steal = generic_pipe_buf_steal,
1210//ust// .get = generic_pipe_buf_get,
1211//ust// };
1212
1213//ust// static void ltt_relay_page_release(struct splice_pipe_desc *spd, unsigned int i)
1214//ust// {
1215//ust// }
e1152c37
PMF
1216
1217/*
1218 * subbuf_splice_actor - splice up to one subbuf's worth of data
1219 */
bb07823d
PMF
1220//ust// static int subbuf_splice_actor(struct file *in,
1221//ust// loff_t *ppos,
1222//ust// struct pipe_inode_info *pipe,
1223//ust// size_t len,
1224//ust// unsigned int flags)
1225//ust// {
1226//ust// struct rchan_buf *buf = in->private_data;
1227//ust// struct ltt_channel_struct *ltt_channel =
1228//ust// (struct ltt_channel_struct *)buf->chan->private_data;
1229//ust// struct ltt_channel_buf_struct *ltt_buf =
1230//ust// percpu_ptr(ltt_channel->buf, buf->cpu);
1231//ust// unsigned int poff, subbuf_pages, nr_pages;
1232//ust// struct page *pages[PIPE_BUFFERS];
1233//ust// struct partial_page partial[PIPE_BUFFERS];
1234//ust// struct splice_pipe_desc spd = {
1235//ust// .pages = pages,
1236//ust// .nr_pages = 0,
1237//ust// .partial = partial,
1238//ust// .flags = flags,
1239//ust// .ops = &ltt_relay_pipe_buf_ops,
1240//ust// .spd_release = ltt_relay_page_release,
1241//ust// };
1242//ust// long consumed_old, consumed_idx, roffset;
1243//ust// unsigned long bytes_avail;
1244//ust//
1245//ust// /*
1246//ust// * Check that a GET_SUBBUF ioctl has been done before.
1247//ust// */
1248//ust// WARN_ON(atomic_long_read(&ltt_buf->active_readers) != 1);
1249//ust// consumed_old = atomic_long_read(&ltt_buf->consumed);
1250//ust// consumed_old += *ppos;
1251//ust// consumed_idx = SUBBUF_INDEX(consumed_old, buf->chan);
1252//ust//
1253//ust// /*
1254//ust// * Adjust read len, if longer than what is available
1255//ust// */
1256//ust// bytes_avail = SUBBUF_TRUNC(local_read(&ltt_buf->offset), buf->chan)
1257//ust// - consumed_old;
1258//ust// WARN_ON(bytes_avail > buf->chan->alloc_size);
1259//ust// len = min_t(size_t, len, bytes_avail);
1260//ust// subbuf_pages = bytes_avail >> PAGE_SHIFT;
1261//ust// nr_pages = min_t(unsigned int, subbuf_pages, PIPE_BUFFERS);
1262//ust// roffset = consumed_old & PAGE_MASK;
1263//ust// poff = consumed_old & ~PAGE_MASK;
1264//ust// printk_dbg(KERN_DEBUG "SPLICE actor len %zu pos %zd write_pos %ld\n",
1265//ust// len, (ssize_t)*ppos, local_read(&ltt_buf->offset));
1266//ust//
1267//ust// for (; spd.nr_pages < nr_pages; spd.nr_pages++) {
1268//ust// unsigned int this_len;
1269//ust// struct buf_page *page;
1270//ust//
1271//ust// if (!len)
1272//ust// break;
1273//ust// printk_dbg(KERN_DEBUG "SPLICE actor loop len %zu roffset %ld\n",
1274//ust// len, roffset);
1275//ust//
1276//ust// this_len = PAGE_SIZE - poff;
1277//ust// page = ltt_relay_read_get_page(buf, roffset);
1278//ust// spd.pages[spd.nr_pages] = page->page;
1279//ust// spd.partial[spd.nr_pages].offset = poff;
1280//ust// spd.partial[spd.nr_pages].len = this_len;
1281//ust//
1282//ust// poff = 0;
1283//ust// roffset += PAGE_SIZE;
1284//ust// len -= this_len;
1285//ust// }
1286//ust//
1287//ust// if (!spd.nr_pages)
1288//ust// return 0;
1289//ust//
1290//ust// return splice_to_pipe(pipe, &spd);
1291//ust// }
e1152c37 1292
bb07823d
PMF
1293//ust// static ssize_t ltt_relay_file_splice_read(struct file *in,
1294//ust// loff_t *ppos,
1295//ust// struct pipe_inode_info *pipe,
1296//ust// size_t len,
1297//ust// unsigned int flags)
1298//ust// {
1299//ust// ssize_t spliced;
1300//ust// int ret;
1301//ust//
1302//ust// ret = 0;
1303//ust// spliced = 0;
1304//ust//
1305//ust// printk_dbg(KERN_DEBUG "SPLICE read len %zu pos %zd\n",
1306//ust// len, (ssize_t)*ppos);
1307//ust// while (len && !spliced) {
1308//ust// ret = subbuf_splice_actor(in, ppos, pipe, len, flags);
1309//ust// printk_dbg(KERN_DEBUG "SPLICE read loop ret %d\n", ret);
1310//ust// if (ret < 0)
1311//ust// break;
1312//ust// else if (!ret) {
1313//ust// if (flags & SPLICE_F_NONBLOCK)
1314//ust// ret = -EAGAIN;
1315//ust// break;
1316//ust// }
1317//ust//
1318//ust// *ppos += ret;
1319//ust// if (ret > len)
1320//ust// len = 0;
1321//ust// else
1322//ust// len -= ret;
1323//ust// spliced += ret;
1324//ust// }
1325//ust//
1326//ust// if (spliced)
1327//ust// return spliced;
1328//ust//
1329//ust// return ret;
1330//ust// }
e1152c37
PMF
1331
1332static void ltt_relay_print_subbuffer_errors(
1333 struct ltt_channel_struct *ltt_chan,
bb07823d 1334 long cons_off)
e1152c37
PMF
1335{
1336 struct rchan *rchan = ltt_chan->trans_channel_data;
bb07823d 1337 struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf;
e1152c37
PMF
1338 long cons_idx, commit_count, write_offset;
1339
1340 cons_idx = SUBBUF_INDEX(cons_off, rchan);
1341 commit_count = local_read(&ltt_buf->commit_count[cons_idx]);
1342 /*
1343 * No need to order commit_count and write_offset reads because we
1344 * execute after trace is stopped when there are no readers left.
1345 */
1346 write_offset = local_read(&ltt_buf->offset);
1347 printk(KERN_WARNING
1348 "LTT : unread channel %s offset is %ld "
bb07823d
PMF
1349 "and cons_off : %ld\n",
1350 ltt_chan->channel_name, write_offset, cons_off);
e1152c37
PMF
1351 /* Check each sub-buffer for non filled commit count */
1352 if (((commit_count - rchan->subbuf_size) & ltt_chan->commit_count_mask)
1353 - (BUFFER_TRUNC(cons_off, rchan) >> ltt_chan->n_subbufs_order)
1354 != 0)
1355 printk(KERN_ALERT
1356 "LTT : %s : subbuffer %lu has non filled "
1357 "commit count %lu.\n",
1358 ltt_chan->channel_name, cons_idx, commit_count);
1359 printk(KERN_ALERT "LTT : %s : commit count : %lu, subbuf size %zd\n",
1360 ltt_chan->channel_name, commit_count,
1361 rchan->subbuf_size);
1362}
1363
1364static void ltt_relay_print_errors(struct ltt_trace_struct *trace,
bb07823d 1365 struct ltt_channel_struct *ltt_chan)
e1152c37
PMF
1366{
1367 struct rchan *rchan = ltt_chan->trans_channel_data;
bb07823d 1368 struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf;
e1152c37
PMF
1369 long cons_off;
1370
1371 for (cons_off = atomic_long_read(&ltt_buf->consumed);
1372 (SUBBUF_TRUNC(local_read(&ltt_buf->offset),
1373 rchan)
1374 - cons_off) > 0;
1375 cons_off = SUBBUF_ALIGN(cons_off, rchan))
bb07823d 1376 ltt_relay_print_subbuffer_errors(ltt_chan, cons_off);
e1152c37
PMF
1377}
1378
bb07823d 1379static void ltt_relay_print_buffer_errors(struct ltt_channel_struct *ltt_chan)
e1152c37
PMF
1380{
1381 struct ltt_trace_struct *trace = ltt_chan->trace;
bb07823d 1382 struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf;
e1152c37
PMF
1383
1384 if (local_read(&ltt_buf->events_lost))
1385 printk(KERN_ALERT
1386 "LTT : %s : %ld events lost "
bb07823d 1387 "in %s channel.\n",
e1152c37
PMF
1388 ltt_chan->channel_name,
1389 local_read(&ltt_buf->events_lost),
bb07823d 1390 ltt_chan->channel_name);
e1152c37
PMF
1391 if (local_read(&ltt_buf->corrupted_subbuffers))
1392 printk(KERN_ALERT
1393 "LTT : %s : %ld corrupted subbuffers "
bb07823d 1394 "in %s channel.\n",
e1152c37
PMF
1395 ltt_chan->channel_name,
1396 local_read(&ltt_buf->corrupted_subbuffers),
bb07823d 1397 ltt_chan->channel_name);
e1152c37 1398
bb07823d 1399 ltt_relay_print_errors(trace, ltt_chan);
e1152c37
PMF
1400}
1401
bb07823d
PMF
1402static void ltt_relay_remove_dirs(struct ltt_trace_struct *trace)
1403{
5f54827b 1404//ust// debugfs_remove(trace->dentry.trace_root);
bb07823d 1405}
e1152c37
PMF
1406
1407static void ltt_relay_release_channel(struct kref *kref)
1408{
1409 struct ltt_channel_struct *ltt_chan = container_of(kref,
1410 struct ltt_channel_struct, kref);
bb07823d 1411 free(ltt_chan->buf);
e1152c37
PMF
1412}
1413
1414/*
1415 * Create ltt buffer.
1416 */
5f54827b
PMF
1417//ust// static int ltt_relay_create_buffer(struct ltt_trace_struct *trace,
1418//ust// struct ltt_channel_struct *ltt_chan, struct rchan_buf *buf,
1419//ust// unsigned int cpu, unsigned int n_subbufs)
1420//ust// {
1421//ust// struct ltt_channel_buf_struct *ltt_buf =
1422//ust// percpu_ptr(ltt_chan->buf, cpu);
1423//ust// unsigned int j;
1424//ust//
1425//ust// ltt_buf->commit_count =
1426//ust// kzalloc_node(sizeof(ltt_buf->commit_count) * n_subbufs,
1427//ust// GFP_KERNEL, cpu_to_node(cpu));
1428//ust// if (!ltt_buf->commit_count)
1429//ust// return -ENOMEM;
1430//ust// kref_get(&trace->kref);
1431//ust// kref_get(&trace->ltt_transport_kref);
1432//ust// kref_get(&ltt_chan->kref);
1433//ust// local_set(&ltt_buf->offset, ltt_subbuffer_header_size());
1434//ust// atomic_long_set(&ltt_buf->consumed, 0);
1435//ust// atomic_long_set(&ltt_buf->active_readers, 0);
1436//ust// for (j = 0; j < n_subbufs; j++)
1437//ust// local_set(&ltt_buf->commit_count[j], 0);
1438//ust// init_waitqueue_head(&ltt_buf->write_wait);
1439//ust// atomic_set(&ltt_buf->wakeup_readers, 0);
1440//ust// spin_lock_init(&ltt_buf->full_lock);
1441//ust//
1442//ust// ltt_buffer_begin_callback(buf, trace->start_tsc, 0);
1443//ust// /* atomic_add made on local variable on data that belongs to
1444//ust// * various CPUs : ok because tracing not started (for this cpu). */
1445//ust// local_add(ltt_subbuffer_header_size(), &ltt_buf->commit_count[0]);
1446//ust//
1447//ust// local_set(&ltt_buf->events_lost, 0);
1448//ust// local_set(&ltt_buf->corrupted_subbuffers, 0);
1449//ust//
1450//ust// return 0;
1451//ust// }
1452
e1152c37
PMF
1453static int ltt_relay_create_buffer(struct ltt_trace_struct *trace,
1454 struct ltt_channel_struct *ltt_chan, struct rchan_buf *buf,
bb07823d 1455 unsigned int n_subbufs)
e1152c37 1456{
5f54827b 1457 struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf;
e1152c37
PMF
1458 unsigned int j;
1459
1460 ltt_buf->commit_count =
c1dea0b3 1461 zmalloc(sizeof(ltt_buf->commit_count) * n_subbufs);
e1152c37
PMF
1462 if (!ltt_buf->commit_count)
1463 return -ENOMEM;
1464 kref_get(&trace->kref);
1465 kref_get(&trace->ltt_transport_kref);
1466 kref_get(&ltt_chan->kref);
c1dea0b3 1467 local_set(&ltt_buf->offset, ltt_subbuffer_header_size());
e1152c37
PMF
1468 atomic_long_set(&ltt_buf->consumed, 0);
1469 atomic_long_set(&ltt_buf->active_readers, 0);
1470 for (j = 0; j < n_subbufs; j++)
1471 local_set(&ltt_buf->commit_count[j], 0);
5f54827b 1472//ust// init_waitqueue_head(&ltt_buf->write_wait);
46ef48cd
PMF
1473//ust// atomic_set(&ltt_buf->wakeup_readers, 0);
1474//ust// spin_lock_init(&ltt_buf->full_lock);
e1152c37
PMF
1475
1476 ltt_buffer_begin_callback(buf, trace->start_tsc, 0);
e1152c37 1477
c1dea0b3 1478 local_add(ltt_subbuffer_header_size(), &ltt_buf->commit_count[0]);
5f54827b 1479
c1dea0b3
PMF
1480 local_set(&ltt_buf->events_lost, 0);
1481 local_set(&ltt_buf->corrupted_subbuffers, 0);
e1152c37 1482
46ef48cd
PMF
1483 ltt_buf->call_wake_consumer = 0;
1484 ltt_buf->wake_consumer_arg = NULL;
1485
e1152c37
PMF
1486 return 0;
1487}
1488
bb07823d 1489static void ltt_relay_destroy_buffer(struct ltt_channel_struct *ltt_chan)
e1152c37
PMF
1490{
1491 struct ltt_trace_struct *trace = ltt_chan->trace;
bb07823d 1492 struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf;
e1152c37
PMF
1493
1494 kref_put(&ltt_chan->trace->ltt_transport_kref,
1495 ltt_release_transport);
bb07823d 1496 ltt_relay_print_buffer_errors(ltt_chan);
e1152c37
PMF
1497 kfree(ltt_buf->commit_count);
1498 ltt_buf->commit_count = NULL;
1499 kref_put(&ltt_chan->kref, ltt_relay_release_channel);
1500 kref_put(&trace->kref, ltt_release_trace);
bb07823d 1501//ust// wake_up_interruptible(&trace->kref_wq);
e1152c37
PMF
1502}
1503
1504/*
1505 * Create channel.
1506 */
1507static int ltt_relay_create_channel(const char *trace_name,
1508 struct ltt_trace_struct *trace, struct dentry *dir,
1509 const char *channel_name, struct ltt_channel_struct *ltt_chan,
1510 unsigned int subbuf_size, unsigned int n_subbufs,
1511 int overwrite)
1512{
1513 char *tmpname;
1514 unsigned int tmpname_len;
1515 int err = 0;
1516
1517 tmpname = kmalloc(PATH_MAX, GFP_KERNEL);
1518 if (!tmpname)
1519 return EPERM;
1520 if (overwrite) {
1521 strncpy(tmpname, LTT_FLIGHT_PREFIX, PATH_MAX-1);
1522 strncat(tmpname, channel_name,
1523 PATH_MAX-1-sizeof(LTT_FLIGHT_PREFIX));
1524 } else {
1525 strncpy(tmpname, channel_name, PATH_MAX-1);
1526 }
1527 strncat(tmpname, "_", PATH_MAX-1-strlen(tmpname));
1528
1529 kref_init(&ltt_chan->kref);
1530
1531 ltt_chan->trace = trace;
1532 ltt_chan->buffer_begin = ltt_buffer_begin_callback;
1533 ltt_chan->buffer_end = ltt_buffer_end_callback;
1534 ltt_chan->overwrite = overwrite;
1535 ltt_chan->n_subbufs_order = get_count_order(n_subbufs);
1536 ltt_chan->commit_count_mask = (~0UL >> ltt_chan->n_subbufs_order);
bb07823d
PMF
1537//ust// ltt_chan->buf = percpu_alloc_mask(sizeof(struct ltt_channel_buf_struct), GFP_KERNEL, cpu_possible_map);
1538 ltt_chan->buf = malloc(sizeof(struct ltt_channel_buf_struct));
e1152c37 1539 if (!ltt_chan->buf)
bb07823d 1540 goto alloc_error;
e1152c37
PMF
1541 ltt_chan->trans_channel_data = ltt_relay_open(tmpname,
1542 dir,
1543 subbuf_size,
1544 n_subbufs,
e1152c37
PMF
1545 ltt_chan);
1546 tmpname_len = strlen(tmpname);
1547 if (tmpname_len > 0) {
1548 /* Remove final _ for pretty printing */
1549 tmpname[tmpname_len-1] = '\0';
1550 }
1551 if (ltt_chan->trans_channel_data == NULL) {
1552 printk(KERN_ERR "LTT : Can't open %s channel for trace %s\n",
1553 tmpname, trace_name);
1554 goto relay_open_error;
1555 }
1556
1557 err = 0;
1558 goto end;
1559
1560relay_open_error:
bb07823d
PMF
1561//ust// percpu_free(ltt_chan->buf);
1562alloc_error:
e1152c37
PMF
1563 err = EPERM;
1564end:
1565 kfree(tmpname);
1566 return err;
1567}
1568
bb07823d
PMF
1569static int ltt_relay_create_dirs(struct ltt_trace_struct *new_trace)
1570{
1571//ust// new_trace->dentry.trace_root = debugfs_create_dir(new_trace->trace_name,
1572//ust// get_ltt_root());
1573//ust// if (new_trace->dentry.trace_root == NULL) {
1574//ust// printk(KERN_ERR "LTT : Trace directory name %s already taken\n",
1575//ust// new_trace->trace_name);
1576//ust// return EEXIST;
1577//ust// }
1578
1579//ust// new_trace->callbacks.create_buf_file = ltt_create_buf_file_callback;
1580//ust// new_trace->callbacks.remove_buf_file = ltt_remove_buf_file_callback;
1581
1582 return 0;
1583}
e1152c37
PMF
1584
1585/*
1586 * LTTng channel flush function.
1587 *
1588 * Must be called when no tracing is active in the channel, because of
1589 * accesses across CPUs.
1590 */
1591static notrace void ltt_relay_buffer_flush(struct rchan_buf *buf)
1592{
46ef48cd
PMF
1593 struct ltt_channel_struct *channel =
1594 (struct ltt_channel_struct *)buf->chan->private_data;
1595 struct ltt_channel_buf_struct *ltt_buf = channel->buf;
1596
e1152c37
PMF
1597 buf->finalized = 1;
1598 ltt_force_switch(buf, FORCE_FLUSH);
46ef48cd
PMF
1599
1600 relay_wake_consumer(ltt_buf, 1);
e1152c37
PMF
1601}
1602
1603static void ltt_relay_async_wakeup_chan(struct ltt_channel_struct *ltt_channel)
1604{
bb07823d
PMF
1605//ust// unsigned int i;
1606//ust// struct rchan *rchan = ltt_channel->trans_channel_data;
1607//ust//
1608//ust// for_each_possible_cpu(i) {
1609//ust// struct ltt_channel_buf_struct *ltt_buf =
1610//ust// percpu_ptr(ltt_channel->buf, i);
1611//ust//
1612//ust// if (atomic_read(&ltt_buf->wakeup_readers) == 1) {
1613//ust// atomic_set(&ltt_buf->wakeup_readers, 0);
1614//ust// wake_up_interruptible(&rchan->buf[i]->read_wait);
1615//ust// }
1616//ust// }
e1152c37
PMF
1617}
1618
bb07823d 1619static void ltt_relay_finish_buffer(struct ltt_channel_struct *ltt_channel)
e1152c37
PMF
1620{
1621 struct rchan *rchan = ltt_channel->trans_channel_data;
1622
bb07823d
PMF
1623 if (rchan->buf) {
1624 struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
1625 ltt_relay_buffer_flush(rchan->buf);
1626//ust// ltt_relay_wake_writers(ltt_buf);
e1152c37
PMF
1627 }
1628}
1629
1630
1631static void ltt_relay_finish_channel(struct ltt_channel_struct *ltt_channel)
1632{
1633 unsigned int i;
1634
bb07823d
PMF
1635//ust// for_each_possible_cpu(i)
1636 ltt_relay_finish_buffer(ltt_channel);
e1152c37
PMF
1637}
1638
1639static void ltt_relay_remove_channel(struct ltt_channel_struct *channel)
1640{
1641 struct rchan *rchan = channel->trans_channel_data;
1642
1643 ltt_relay_close(rchan);
1644 kref_put(&channel->kref, ltt_relay_release_channel);
1645}
1646
1647struct ltt_reserve_switch_offsets {
1648 long begin, end, old;
1649 long begin_switch, end_switch_current, end_switch_old;
1650 long commit_count, reserve_commit_diff;
1651 size_t before_hdr_pad, size;
1652};
1653
1654/*
1655 * Returns :
1656 * 0 if ok
1657 * !0 if execution must be aborted.
1658 */
1659static inline int ltt_relay_try_reserve(
1660 struct ltt_channel_struct *ltt_channel,
1661 struct ltt_channel_buf_struct *ltt_buf, struct rchan *rchan,
1662 struct rchan_buf *buf,
1663 struct ltt_reserve_switch_offsets *offsets, size_t data_size,
1664 u64 *tsc, unsigned int *rflags, int largest_align)
1665{
1666 offsets->begin = local_read(&ltt_buf->offset);
1667 offsets->old = offsets->begin;
1668 offsets->begin_switch = 0;
1669 offsets->end_switch_current = 0;
1670 offsets->end_switch_old = 0;
1671
1672 *tsc = trace_clock_read64();
1673 if (last_tsc_overflow(ltt_buf, *tsc))
1674 *rflags = LTT_RFLAG_ID_SIZE_TSC;
1675
1676 if (SUBBUF_OFFSET(offsets->begin, buf->chan) == 0) {
1677 offsets->begin_switch = 1; /* For offsets->begin */
1678 } else {
1679 offsets->size = ltt_get_header_size(ltt_channel,
1680 offsets->begin, data_size,
1681 &offsets->before_hdr_pad, *rflags);
1682 offsets->size += ltt_align(offsets->begin + offsets->size,
1683 largest_align)
1684 + data_size;
1685 if ((SUBBUF_OFFSET(offsets->begin, buf->chan) + offsets->size)
1686 > buf->chan->subbuf_size) {
1687 offsets->end_switch_old = 1; /* For offsets->old */
1688 offsets->begin_switch = 1; /* For offsets->begin */
1689 }
1690 }
1691 if (offsets->begin_switch) {
1692 long subbuf_index;
1693
1694 if (offsets->end_switch_old)
1695 offsets->begin = SUBBUF_ALIGN(offsets->begin,
1696 buf->chan);
1697 offsets->begin = offsets->begin + ltt_subbuffer_header_size();
1698 /* Test new buffer integrity */
1699 subbuf_index = SUBBUF_INDEX(offsets->begin, buf->chan);
1700 offsets->reserve_commit_diff =
1701 (BUFFER_TRUNC(offsets->begin, buf->chan)
1702 >> ltt_channel->n_subbufs_order)
1703 - (local_read(&ltt_buf->commit_count[subbuf_index])
1704 & ltt_channel->commit_count_mask);
1705 if (offsets->reserve_commit_diff == 0) {
1706 /* Next buffer not corrupted. */
1707 if (!ltt_channel->overwrite &&
1708 (SUBBUF_TRUNC(offsets->begin, buf->chan)
1709 - SUBBUF_TRUNC(atomic_long_read(
1710 &ltt_buf->consumed),
1711 buf->chan))
1712 >= rchan->alloc_size) {
1713 /*
1714 * We do not overwrite non consumed buffers
1715 * and we are full : event is lost.
1716 */
1717 local_inc(&ltt_buf->events_lost);
1718 return -1;
1719 } else {
1720 /*
1721 * next buffer not corrupted, we are either in
1722 * overwrite mode or the buffer is not full.
1723 * It's safe to write in this new subbuffer.
1724 */
1725 }
1726 } else {
1727 /*
1728 * Next subbuffer corrupted. Force pushing reader even
1729 * in normal mode. It's safe to write in this new
1730 * subbuffer.
1731 */
1732 }
1733 offsets->size = ltt_get_header_size(ltt_channel,
1734 offsets->begin, data_size,
1735 &offsets->before_hdr_pad, *rflags);
1736 offsets->size += ltt_align(offsets->begin + offsets->size,
1737 largest_align)
1738 + data_size;
1739 if ((SUBBUF_OFFSET(offsets->begin, buf->chan) + offsets->size)
1740 > buf->chan->subbuf_size) {
1741 /*
1742 * Event too big for subbuffers, report error, don't
1743 * complete the sub-buffer switch.
1744 */
1745 local_inc(&ltt_buf->events_lost);
1746 return -1;
1747 } else {
1748 /*
1749 * We just made a successful buffer switch and the event
1750 * fits in the new subbuffer. Let's write.
1751 */
1752 }
1753 } else {
1754 /*
1755 * Event fits in the current buffer and we are not on a switch
1756 * boundary. It's safe to write.
1757 */
1758 }
1759 offsets->end = offsets->begin + offsets->size;
1760
1761 if ((SUBBUF_OFFSET(offsets->end, buf->chan)) == 0) {
1762 /*
1763 * The offset_end will fall at the very beginning of the next
1764 * subbuffer.
1765 */
1766 offsets->end_switch_current = 1; /* For offsets->begin */
1767 }
1768 return 0;
1769}
1770
1771/*
1772 * Returns :
1773 * 0 if ok
1774 * !0 if execution must be aborted.
1775 */
1776static inline int ltt_relay_try_switch(
1777 enum force_switch_mode mode,
1778 struct ltt_channel_struct *ltt_channel,
1779 struct ltt_channel_buf_struct *ltt_buf, struct rchan *rchan,
1780 struct rchan_buf *buf,
1781 struct ltt_reserve_switch_offsets *offsets,
1782 u64 *tsc)
1783{
1784 long subbuf_index;
1785
1786 offsets->begin = local_read(&ltt_buf->offset);
1787 offsets->old = offsets->begin;
1788 offsets->begin_switch = 0;
1789 offsets->end_switch_old = 0;
1790
1791 *tsc = trace_clock_read64();
1792
1793 if (SUBBUF_OFFSET(offsets->begin, buf->chan) != 0) {
1794 offsets->begin = SUBBUF_ALIGN(offsets->begin, buf->chan);
1795 offsets->end_switch_old = 1;
1796 } else {
1797 /* we do not have to switch : buffer is empty */
1798 return -1;
1799 }
1800 if (mode == FORCE_ACTIVE)
1801 offsets->begin += ltt_subbuffer_header_size();
1802 /*
1803 * Always begin_switch in FORCE_ACTIVE mode.
1804 * Test new buffer integrity
1805 */
1806 subbuf_index = SUBBUF_INDEX(offsets->begin, buf->chan);
1807 offsets->reserve_commit_diff =
1808 (BUFFER_TRUNC(offsets->begin, buf->chan)
1809 >> ltt_channel->n_subbufs_order)
1810 - (local_read(&ltt_buf->commit_count[subbuf_index])
1811 & ltt_channel->commit_count_mask);
1812 if (offsets->reserve_commit_diff == 0) {
1813 /* Next buffer not corrupted. */
1814 if (mode == FORCE_ACTIVE
1815 && !ltt_channel->overwrite
1816 && offsets->begin - atomic_long_read(&ltt_buf->consumed)
1817 >= rchan->alloc_size) {
1818 /*
1819 * We do not overwrite non consumed buffers and we are
1820 * full : ignore switch while tracing is active.
1821 */
1822 return -1;
1823 }
1824 } else {
1825 /*
1826 * Next subbuffer corrupted. Force pushing reader even in normal
1827 * mode
1828 */
1829 }
1830 offsets->end = offsets->begin;
1831 return 0;
1832}
1833
1834static inline void ltt_reserve_push_reader(
1835 struct ltt_channel_struct *ltt_channel,
1836 struct ltt_channel_buf_struct *ltt_buf,
1837 struct rchan *rchan,
1838 struct rchan_buf *buf,
1839 struct ltt_reserve_switch_offsets *offsets)
1840{
1841 long consumed_old, consumed_new;
1842
1843 do {
1844 consumed_old = atomic_long_read(&ltt_buf->consumed);
1845 /*
1846 * If buffer is in overwrite mode, push the reader consumed
1847 * count if the write position has reached it and we are not
1848 * at the first iteration (don't push the reader farther than
1849 * the writer). This operation can be done concurrently by many
1850 * writers in the same buffer, the writer being at the farthest
1851 * write position sub-buffer index in the buffer being the one
1852 * which will win this loop.
1853 * If the buffer is not in overwrite mode, pushing the reader
1854 * only happens if a sub-buffer is corrupted.
1855 */
1856 if ((SUBBUF_TRUNC(offsets->end-1, buf->chan)
1857 - SUBBUF_TRUNC(consumed_old, buf->chan))
1858 >= rchan->alloc_size)
1859 consumed_new = SUBBUF_ALIGN(consumed_old, buf->chan);
1860 else {
1861 consumed_new = consumed_old;
1862 break;
1863 }
1864 } while (atomic_long_cmpxchg(&ltt_buf->consumed, consumed_old,
1865 consumed_new) != consumed_old);
1866
1867 if (consumed_old != consumed_new) {
1868 /*
1869 * Reader pushed : we are the winner of the push, we can
1870 * therefore reequilibrate reserve and commit. Atomic increment
1871 * of the commit count permits other writers to play around
1872 * with this variable before us. We keep track of
1873 * corrupted_subbuffers even in overwrite mode :
1874 * we never want to write over a non completely committed
1875 * sub-buffer : possible causes : the buffer size is too low
1876 * compared to the unordered data input, or there is a writer
1877 * that died between the reserve and the commit.
1878 */
1879 if (offsets->reserve_commit_diff) {
1880 /*
1881 * We have to alter the sub-buffer commit count.
1882 * We do not deliver the previous subbuffer, given it
1883 * was either corrupted or not consumed (overwrite
1884 * mode).
1885 */
1886 local_add(offsets->reserve_commit_diff,
1887 &ltt_buf->commit_count[
1888 SUBBUF_INDEX(offsets->begin,
1889 buf->chan)]);
1890 if (!ltt_channel->overwrite
1891 || offsets->reserve_commit_diff
1892 != rchan->subbuf_size) {
1893 /*
1894 * The reserve commit diff was not subbuf_size :
1895 * it means the subbuffer was partly written to
1896 * and is therefore corrupted. If it is multiple
1897 * of subbuffer size and we are in flight
1898 * recorder mode, we are skipping over a whole
1899 * subbuffer.
1900 */
1901 local_inc(&ltt_buf->corrupted_subbuffers);
1902 }
1903 }
1904 }
1905}
1906
1907
1908/*
1909 * ltt_reserve_switch_old_subbuf: switch old subbuffer
1910 *
1911 * Concurrency safe because we are the last and only thread to alter this
1912 * sub-buffer. As long as it is not delivered and read, no other thread can
1913 * alter the offset, alter the reserve_count or call the
1914 * client_buffer_end_callback on this sub-buffer.
1915 *
1916 * The only remaining threads could be the ones with pending commits. They will
1917 * have to do the deliver themselves. Not concurrency safe in overwrite mode.
1918 * We detect corrupted subbuffers with commit and reserve counts. We keep a
1919 * corrupted sub-buffers count and push the readers across these sub-buffers.
1920 *
1921 * Not concurrency safe if a writer is stalled in a subbuffer and another writer
1922 * switches in, finding out it's corrupted. The result will be than the old
1923 * (uncommited) subbuffer will be declared corrupted, and that the new subbuffer
1924 * will be declared corrupted too because of the commit count adjustment.
1925 *
1926 * Note : offset_old should never be 0 here.
1927 */
1928static inline void ltt_reserve_switch_old_subbuf(
1929 struct ltt_channel_struct *ltt_channel,
1930 struct ltt_channel_buf_struct *ltt_buf, struct rchan *rchan,
1931 struct rchan_buf *buf,
1932 struct ltt_reserve_switch_offsets *offsets, u64 *tsc)
1933{
1934 long oldidx = SUBBUF_INDEX(offsets->old - 1, rchan);
1935
1936 ltt_channel->buffer_end(buf, *tsc, offsets->old, oldidx);
1937 /* Must write buffer end before incrementing commit count */
1938 smp_wmb();
1939 offsets->commit_count =
1940 local_add_return(rchan->subbuf_size
1941 - (SUBBUF_OFFSET(offsets->old - 1, rchan)
1942 + 1),
1943 &ltt_buf->commit_count[oldidx]);
1944 if ((BUFFER_TRUNC(offsets->old - 1, rchan)
1945 >> ltt_channel->n_subbufs_order)
1946 - ((offsets->commit_count - rchan->subbuf_size)
1947 & ltt_channel->commit_count_mask) == 0)
1948 ltt_deliver(buf, oldidx, NULL);
1949}
1950
1951/*
1952 * ltt_reserve_switch_new_subbuf: Populate new subbuffer.
1953 *
1954 * This code can be executed unordered : writers may already have written to the
1955 * sub-buffer before this code gets executed, caution. The commit makes sure
1956 * that this code is executed before the deliver of this sub-buffer.
1957 */
1958static inline void ltt_reserve_switch_new_subbuf(
1959 struct ltt_channel_struct *ltt_channel,
1960 struct ltt_channel_buf_struct *ltt_buf, struct rchan *rchan,
1961 struct rchan_buf *buf,
1962 struct ltt_reserve_switch_offsets *offsets, u64 *tsc)
1963{
1964 long beginidx = SUBBUF_INDEX(offsets->begin, rchan);
1965
1966 ltt_channel->buffer_begin(buf, *tsc, beginidx);
1967 /* Must write buffer end before incrementing commit count */
1968 smp_wmb();
1969 offsets->commit_count = local_add_return(ltt_subbuffer_header_size(),
1970 &ltt_buf->commit_count[beginidx]);
1971 /* Check if the written buffer has to be delivered */
1972 if ((BUFFER_TRUNC(offsets->begin, rchan)
1973 >> ltt_channel->n_subbufs_order)
1974 - ((offsets->commit_count - rchan->subbuf_size)
1975 & ltt_channel->commit_count_mask) == 0)
1976 ltt_deliver(buf, beginidx, NULL);
1977}
1978
1979
1980/*
1981 * ltt_reserve_end_switch_current: finish switching current subbuffer
1982 *
1983 * Concurrency safe because we are the last and only thread to alter this
1984 * sub-buffer. As long as it is not delivered and read, no other thread can
1985 * alter the offset, alter the reserve_count or call the
1986 * client_buffer_end_callback on this sub-buffer.
1987 *
1988 * The only remaining threads could be the ones with pending commits. They will
1989 * have to do the deliver themselves. Not concurrency safe in overwrite mode.
1990 * We detect corrupted subbuffers with commit and reserve counts. We keep a
1991 * corrupted sub-buffers count and push the readers across these sub-buffers.
1992 *
1993 * Not concurrency safe if a writer is stalled in a subbuffer and another writer
1994 * switches in, finding out it's corrupted. The result will be than the old
1995 * (uncommited) subbuffer will be declared corrupted, and that the new subbuffer
1996 * will be declared corrupted too because of the commit count adjustment.
1997 */
1998static inline void ltt_reserve_end_switch_current(
1999 struct ltt_channel_struct *ltt_channel,
2000 struct ltt_channel_buf_struct *ltt_buf, struct rchan *rchan,
2001 struct rchan_buf *buf,
2002 struct ltt_reserve_switch_offsets *offsets, u64 *tsc)
2003{
2004 long endidx = SUBBUF_INDEX(offsets->end - 1, rchan);
2005
2006 ltt_channel->buffer_end(buf, *tsc, offsets->end, endidx);
2007 /* Must write buffer begin before incrementing commit count */
2008 smp_wmb();
2009 offsets->commit_count =
2010 local_add_return(rchan->subbuf_size
2011 - (SUBBUF_OFFSET(offsets->end - 1, rchan)
2012 + 1),
2013 &ltt_buf->commit_count[endidx]);
2014 if ((BUFFER_TRUNC(offsets->end - 1, rchan)
2015 >> ltt_channel->n_subbufs_order)
2016 - ((offsets->commit_count - rchan->subbuf_size)
2017 & ltt_channel->commit_count_mask) == 0)
2018 ltt_deliver(buf, endidx, NULL);
2019}
2020
2021/**
2022 * ltt_relay_reserve_slot - Atomic slot reservation in a LTTng buffer.
2023 * @trace: the trace structure to log to.
2024 * @ltt_channel: channel structure
2025 * @transport_data: data structure specific to ltt relay
2026 * @data_size: size of the variable length data to log.
2027 * @slot_size: pointer to total size of the slot (out)
2028 * @buf_offset : pointer to reserved buffer offset (out)
2029 * @tsc: pointer to the tsc at the slot reservation (out)
2030 * @cpu: cpuid
2031 *
2032 * Return : -ENOSPC if not enough space, else returns 0.
2033 * It will take care of sub-buffer switching.
2034 */
2035static notrace int ltt_relay_reserve_slot(struct ltt_trace_struct *trace,
2036 struct ltt_channel_struct *ltt_channel, void **transport_data,
2037 size_t data_size, size_t *slot_size, long *buf_offset, u64 *tsc,
c1dea0b3 2038 unsigned int *rflags, int largest_align)
e1152c37
PMF
2039{
2040 struct rchan *rchan = ltt_channel->trans_channel_data;
bb07823d
PMF
2041 struct rchan_buf *buf = *transport_data = rchan->buf;
2042 struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
e1152c37
PMF
2043 struct ltt_reserve_switch_offsets offsets;
2044
2045 offsets.reserve_commit_diff = 0;
2046 offsets.size = 0;
2047
2048 /*
2049 * Perform retryable operations.
2050 */
bb07823d 2051 if (ltt_nesting > 4) {
e1152c37
PMF
2052 local_inc(&ltt_buf->events_lost);
2053 return -EPERM;
2054 }
2055 do {
2056 if (ltt_relay_try_reserve(ltt_channel, ltt_buf,
2057 rchan, buf, &offsets, data_size, tsc, rflags,
2058 largest_align))
2059 return -ENOSPC;
2060 } while (local_cmpxchg(&ltt_buf->offset, offsets.old,
2061 offsets.end) != offsets.old);
2062
2063 /*
2064 * Atomically update last_tsc. This update races against concurrent
2065 * atomic updates, but the race will always cause supplementary full TSC
2066 * events, never the opposite (missing a full TSC event when it would be
2067 * needed).
2068 */
2069 save_last_tsc(ltt_buf, *tsc);
2070
2071 /*
2072 * Push the reader if necessary
2073 */
2074 ltt_reserve_push_reader(ltt_channel, ltt_buf, rchan, buf, &offsets);
2075
2076 /*
2077 * Switch old subbuffer if needed.
2078 */
2079 if (offsets.end_switch_old)
2080 ltt_reserve_switch_old_subbuf(ltt_channel, ltt_buf, rchan, buf,
2081 &offsets, tsc);
2082
2083 /*
2084 * Populate new subbuffer.
2085 */
2086 if (offsets.begin_switch)
2087 ltt_reserve_switch_new_subbuf(ltt_channel, ltt_buf, rchan,
2088 buf, &offsets, tsc);
2089
2090 if (offsets.end_switch_current)
2091 ltt_reserve_end_switch_current(ltt_channel, ltt_buf, rchan,
2092 buf, &offsets, tsc);
2093
2094 *slot_size = offsets.size;
2095 *buf_offset = offsets.begin + offsets.before_hdr_pad;
2096 return 0;
2097}
2098
2099/*
2100 * Force a sub-buffer switch for a per-cpu buffer. This operation is
2101 * completely reentrant : can be called while tracing is active with
2102 * absolutely no lock held.
2103 *
2104 * Note, however, that as a local_cmpxchg is used for some atomic
2105 * operations, this function must be called from the CPU which owns the buffer
2106 * for a ACTIVE flush.
2107 */
2108static notrace void ltt_force_switch(struct rchan_buf *buf,
2109 enum force_switch_mode mode)
2110{
2111 struct ltt_channel_struct *ltt_channel =
2112 (struct ltt_channel_struct *)buf->chan->private_data;
bb07823d 2113 struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
e1152c37
PMF
2114 struct rchan *rchan = ltt_channel->trans_channel_data;
2115 struct ltt_reserve_switch_offsets offsets;
2116 u64 tsc;
2117
2118 offsets.reserve_commit_diff = 0;
2119 offsets.size = 0;
2120
2121 /*
2122 * Perform retryable operations.
2123 */
2124 do {
2125 if (ltt_relay_try_switch(mode, ltt_channel, ltt_buf,
2126 rchan, buf, &offsets, &tsc))
2127 return;
2128 } while (local_cmpxchg(&ltt_buf->offset, offsets.old,
2129 offsets.end) != offsets.old);
2130
2131 /*
2132 * Atomically update last_tsc. This update races against concurrent
2133 * atomic updates, but the race will always cause supplementary full TSC
2134 * events, never the opposite (missing a full TSC event when it would be
2135 * needed).
2136 */
2137 save_last_tsc(ltt_buf, tsc);
2138
2139 /*
2140 * Push the reader if necessary
2141 */
2142 if (mode == FORCE_ACTIVE)
2143 ltt_reserve_push_reader(ltt_channel, ltt_buf, rchan,
2144 buf, &offsets);
2145
2146 /*
2147 * Switch old subbuffer if needed.
2148 */
2149 if (offsets.end_switch_old)
2150 ltt_reserve_switch_old_subbuf(ltt_channel, ltt_buf, rchan, buf,
2151 &offsets, &tsc);
2152
2153 /*
2154 * Populate new subbuffer.
2155 */
2156 if (mode == FORCE_ACTIVE)
2157 ltt_reserve_switch_new_subbuf(ltt_channel,
2158 ltt_buf, rchan, buf, &offsets, &tsc);
2159}
2160
2161/*
2162 * for flight recording. must be called after relay_commit.
2163 * This function decrements de subbuffer's lost_size each time the commit count
2164 * reaches back the reserve offset (module subbuffer size). It is useful for
2165 * crash dump.
2166 * We use slot_size - 1 to make sure we deal correctly with the case where we
2167 * fill the subbuffer completely (so the subbuf index stays in the previous
2168 * subbuffer).
2169 */
2170#ifdef CONFIG_LTT_VMCORE
2171static inline void ltt_write_commit_counter(struct rchan_buf *buf,
2172 long buf_offset, size_t slot_size)
2173{
2174 struct ltt_channel_struct *ltt_channel =
2175 (struct ltt_channel_struct *)buf->chan->private_data;
2176 struct ltt_channel_buf_struct *ltt_buf =
2177 percpu_ptr(ltt_channel->buf, buf->cpu);
2178 struct ltt_subbuffer_header *header;
2179 long offset, subbuf_idx, commit_count;
2180 uint32_t lost_old, lost_new;
2181
2182 subbuf_idx = SUBBUF_INDEX(buf_offset - 1, buf->chan);
2183 offset = buf_offset + slot_size;
2184 header = (struct ltt_subbuffer_header *)
2185 ltt_relay_offset_address(buf,
2186 subbuf_idx * buf->chan->subbuf_size);
2187 for (;;) {
2188 lost_old = header->lost_size;
2189 commit_count =
2190 local_read(&ltt_buf->commit_count[subbuf_idx]);
2191 /* SUBBUF_OFFSET includes commit_count_mask */
2192 if (!SUBBUF_OFFSET(offset - commit_count, buf->chan)) {
2193 lost_new = (uint32_t)buf->chan->subbuf_size
2194 - SUBBUF_OFFSET(commit_count, buf->chan);
2195 lost_old = cmpxchg_local(&header->lost_size, lost_old,
2196 lost_new);
2197 if (lost_old <= lost_new)
2198 break;
2199 } else {
2200 break;
2201 }
2202 }
2203}
2204#else
2205static inline void ltt_write_commit_counter(struct rchan_buf *buf,
2206 long buf_offset, size_t slot_size)
2207{
2208}
2209#endif
2210
2211/*
2212 * Atomic unordered slot commit. Increments the commit count in the
2213 * specified sub-buffer, and delivers it if necessary.
2214 *
2215 * Parameters:
2216 *
2217 * @ltt_channel : channel structure
2218 * @transport_data: transport-specific data
2219 * @buf_offset : offset following the event header.
2220 * @slot_size : size of the reserved slot.
2221 */
2222static notrace void ltt_relay_commit_slot(
2223 struct ltt_channel_struct *ltt_channel,
2224 void **transport_data, long buf_offset, size_t slot_size)
2225{
2226 struct rchan_buf *buf = *transport_data;
bb07823d 2227 struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
e1152c37
PMF
2228 struct rchan *rchan = buf->chan;
2229 long offset_end = buf_offset;
2230 long endidx = SUBBUF_INDEX(offset_end - 1, rchan);
2231 long commit_count;
2232
2233 /* Must write slot data before incrementing commit count */
2234 smp_wmb();
2235 commit_count = local_add_return(slot_size,
2236 &ltt_buf->commit_count[endidx]);
2237 /* Check if all commits have been done */
2238 if ((BUFFER_TRUNC(offset_end - 1, rchan)
2239 >> ltt_channel->n_subbufs_order)
2240 - ((commit_count - rchan->subbuf_size)
2241 & ltt_channel->commit_count_mask) == 0)
2242 ltt_deliver(buf, endidx, NULL);
2243 /*
2244 * Update lost_size for each commit. It's needed only for extracting
2245 * ltt buffers from vmcore, after crash.
2246 */
2247 ltt_write_commit_counter(buf, buf_offset, slot_size);
2248}
2249
2250/*
2251 * This is called with preemption disabled when user space has requested
2252 * blocking mode. If one of the active traces has free space below a
2253 * specific threshold value, we reenable preemption and block.
2254 */
2255static int ltt_relay_user_blocking(struct ltt_trace_struct *trace,
2256 unsigned int chan_index, size_t data_size,
2257 struct user_dbg_data *dbg)
2258{
bb07823d
PMF
2259//ust// struct rchan *rchan;
2260//ust// struct ltt_channel_buf_struct *ltt_buf;
2261//ust// struct ltt_channel_struct *channel;
2262//ust// struct rchan_buf *relay_buf;
2263//ust// int cpu;
2264//ust// DECLARE_WAITQUEUE(wait, current);
2265//ust//
2266//ust// channel = &trace->channels[chan_index];
2267//ust// rchan = channel->trans_channel_data;
2268//ust// cpu = smp_processor_id();
2269//ust// relay_buf = rchan->buf[cpu];
2270//ust// ltt_buf = percpu_ptr(channel->buf, cpu);
2271//ust//
2272//ust// /*
2273//ust// * Check if data is too big for the channel : do not
2274//ust// * block for it.
2275//ust// */
2276//ust// if (LTT_RESERVE_CRITICAL + data_size > relay_buf->chan->subbuf_size)
2277//ust// return 0;
2278//ust//
2279//ust// /*
2280//ust// * If free space too low, we block. We restart from the
2281//ust// * beginning after we resume (cpu id may have changed
2282//ust// * while preemption is active).
2283//ust// */
2284//ust// spin_lock(&ltt_buf->full_lock);
2285//ust// if (!channel->overwrite) {
2286//ust// dbg->write = local_read(&ltt_buf->offset);
2287//ust// dbg->read = atomic_long_read(&ltt_buf->consumed);
2288//ust// dbg->avail_size = dbg->write + LTT_RESERVE_CRITICAL + data_size
2289//ust// - SUBBUF_TRUNC(dbg->read,
2290//ust// relay_buf->chan);
2291//ust// if (dbg->avail_size > rchan->alloc_size) {
2292//ust// __set_current_state(TASK_INTERRUPTIBLE);
2293//ust// add_wait_queue(&ltt_buf->write_wait, &wait);
2294//ust// spin_unlock(&ltt_buf->full_lock);
2295//ust// preempt_enable();
2296//ust// schedule();
2297//ust// __set_current_state(TASK_RUNNING);
2298//ust// remove_wait_queue(&ltt_buf->write_wait, &wait);
2299//ust// if (signal_pending(current))
2300//ust// return -ERESTARTSYS;
2301//ust// preempt_disable();
2302//ust// return 1;
2303//ust// }
2304//ust// }
2305//ust// spin_unlock(&ltt_buf->full_lock);
e1152c37
PMF
2306 return 0;
2307}
2308
2309static void ltt_relay_print_user_errors(struct ltt_trace_struct *trace,
2310 unsigned int chan_index, size_t data_size,
c1dea0b3 2311 struct user_dbg_data *dbg)
e1152c37
PMF
2312{
2313 struct rchan *rchan;
2314 struct ltt_channel_buf_struct *ltt_buf;
2315 struct ltt_channel_struct *channel;
2316 struct rchan_buf *relay_buf;
2317
2318 channel = &trace->channels[chan_index];
2319 rchan = channel->trans_channel_data;
bb07823d
PMF
2320 relay_buf = rchan->buf;
2321 ltt_buf = channel->buf;
e1152c37
PMF
2322
2323 printk(KERN_ERR "Error in LTT usertrace : "
2324 "buffer full : event lost in blocking "
2325 "mode. Increase LTT_RESERVE_CRITICAL.\n");
bb07823d 2326 printk(KERN_ERR "LTT nesting level is %u.\n", ltt_nesting);
e1152c37
PMF
2327 printk(KERN_ERR "LTT avail size %lu.\n",
2328 dbg->avail_size);
2329 printk(KERN_ERR "avai write : %lu, read : %lu\n",
2330 dbg->write, dbg->read);
2331
2332 dbg->write = local_read(&ltt_buf->offset);
2333 dbg->read = atomic_long_read(&ltt_buf->consumed);
2334
2335 printk(KERN_ERR "LTT cur size %lu.\n",
2336 dbg->write + LTT_RESERVE_CRITICAL + data_size
2337 - SUBBUF_TRUNC(dbg->read, relay_buf->chan));
2338 printk(KERN_ERR "cur write : %lu, read : %lu\n",
2339 dbg->write, dbg->read);
2340}
2341
5f54827b
PMF
2342//ust// static struct ltt_transport ltt_relay_transport = {
2343//ust// .name = "relay",
2344//ust// .owner = THIS_MODULE,
2345//ust// .ops = {
2346//ust// .create_dirs = ltt_relay_create_dirs,
2347//ust// .remove_dirs = ltt_relay_remove_dirs,
2348//ust// .create_channel = ltt_relay_create_channel,
2349//ust// .finish_channel = ltt_relay_finish_channel,
2350//ust// .remove_channel = ltt_relay_remove_channel,
2351//ust// .wakeup_channel = ltt_relay_async_wakeup_chan,
2352//ust// .commit_slot = ltt_relay_commit_slot,
2353//ust// .reserve_slot = ltt_relay_reserve_slot,
2354//ust// .user_blocking = ltt_relay_user_blocking,
2355//ust// .user_errors = ltt_relay_print_user_errors,
2356//ust// },
2357//ust// };
2358
2359static struct ltt_transport ust_relay_transport = {
2360 .name = "ustrelay",
bb07823d 2361//ust// .owner = THIS_MODULE,
e1152c37
PMF
2362 .ops = {
2363 .create_dirs = ltt_relay_create_dirs,
2364 .remove_dirs = ltt_relay_remove_dirs,
2365 .create_channel = ltt_relay_create_channel,
2366 .finish_channel = ltt_relay_finish_channel,
2367 .remove_channel = ltt_relay_remove_channel,
2368 .wakeup_channel = ltt_relay_async_wakeup_chan,
2369 .commit_slot = ltt_relay_commit_slot,
2370 .reserve_slot = ltt_relay_reserve_slot,
2371 .user_blocking = ltt_relay_user_blocking,
2372 .user_errors = ltt_relay_print_user_errors,
2373 },
2374};
2375
5f54827b
PMF
2376//ust// static int __init ltt_relay_init(void)
2377//ust// {
2378//ust// printk(KERN_INFO "LTT : ltt-relay init\n");
2379//ust//
2380//ust// ltt_file_operations = ltt_relay_file_operations;
2381//ust// ltt_file_operations.owner = THIS_MODULE;
2382//ust// ltt_file_operations.open = ltt_open;
2383//ust// ltt_file_operations.release = ltt_release;
2384//ust// ltt_file_operations.poll = ltt_poll;
2385//ust// ltt_file_operations.splice_read = ltt_relay_file_splice_read,
2386//ust// ltt_file_operations.ioctl = ltt_ioctl;
2387//ust//#ifdef CONFIG_COMPAT
2388//ust// ltt_file_operations.compat_ioctl = ltt_compat_ioctl;
2389//ust//#endif
2390//ust//
2391//ust// ltt_transport_register(&ltt_relay_transport);
2392//ust//
2393//ust// return 0;
2394//ust// }
2395
4db647c5
PMF
2396static char initialized = 0;
2397
54d6c4f2 2398void __attribute__((constructor)) init_ustrelay_transport(void)
e1152c37 2399{
4db647c5
PMF
2400 if(!initialized) {
2401 ltt_transport_register(&ust_relay_transport);
2402 initialized = 1;
2403 }
e1152c37
PMF
2404}
2405
2406static void __exit ltt_relay_exit(void)
2407{
5f54827b 2408//ust// printk(KERN_INFO "LTT : ltt-relay exit\n");
e1152c37 2409
bb07823d 2410 ltt_transport_unregister(&ust_relay_transport);
e1152c37
PMF
2411}
2412
5f54827b
PMF
2413//ust// module_init(ltt_relay_init);
2414//ust// module_exit(ltt_relay_exit);
2415//ust//
2416//ust// MODULE_LICENSE("GPL");
2417//ust// MODULE_AUTHOR("Mathieu Desnoyers");
2418//ust// MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Lockless Relay");
This page took 0.124708 seconds and 4 git commands to generate.