akaros/kern/src/trace.c
<<
>>
Prefs
   1/* Copyright (c) 2013 The Regents of the University of California
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   5 * Simple ring-buffer tracing for in-kernel events. */
   6
   7#include <trace.h>
   8#include <smp.h>
   9#include <string.h>
  10
  11void trace_ring_init(struct trace_ring *tr, void *buf, size_t buf_size,
  12                     size_t event_size)
  13{
  14        tr->tr_buf = buf;
  15        tr->tr_buf_sz = buf_size;
  16        tr->tr_event_sz_shift = LOG2_UP(event_size);
  17        tr->tr_max = (1 << LOG2_DOWN(buf_size / (1 << tr->tr_event_sz_shift)));
  18        printd("Initializing TR with %d elements of shift %d (%d)\n",
  19               tr->tr_max, tr->tr_event_sz_shift, (1 << tr->tr_event_sz_shift));
  20        trace_ring_reset_and_clear(tr);
  21}
  22
  23void trace_ring_reset(struct trace_ring *tr)
  24{
  25        tr->tr_next = 0;
  26}
  27
  28void trace_ring_reset_and_clear(struct trace_ring *tr)
  29{
  30        memset(tr->tr_buf, 0, tr->tr_buf_sz);
  31        tr->tr_next = 0;
  32}
  33
  34void trace_ring_foreach(struct trace_ring *tr, trace_handler_t tr_func,
  35                        void *data)
  36{
  37        for (int i = 0; i < tr->tr_max; i++)
  38                tr_func(__get_tr_slot(tr, i), data);
  39}
  40