6 * Event logging infrastructure
8 * (c) 2012-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
9 * economic rights: Technische Universität Dresden (Germany)
10 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
19 #include <l4/util/atomic.h>
20 #include <l4/util/rdtsc.h>
21 #include <l4/sys/kdebug.h>
24 * Namespace containing classes regarding measurements and
27 * XXX: C compatibility! Don't use C++ features except inside __cplusplus parts -> I want to
28 * use this header file from C files, too
31 namespace Measurements
46 struct __attribute__((packed))
48 l4_uint64_t tsc; // TSC: stop
49 l4_uint32_t vcpu; // vcpu ptr
50 unsigned char type; // event type
54 struct __attribute__((packed))
63 struct __attribute__((packed))
72 struct __attribute__((packed))
80 struct __attribute__((packed))
87 struct __attribute__((packed))
90 struct SensorHead header;
92 struct PagefaultEvent pf;
93 struct SyscallEvent sys;
95 struct TrapEvent trap;
104 * An event buffer holds events of the GenericEvent type. The class does not
105 * allocate memory. Instead the underlying buffer needs to be specified using
106 * the set_buffer() function.
108 * Once the buffer is valid, users obtain an element using the next() method
109 * and fill it appropriately.
111 * The buffer is managed as a ring buffer and may overflow, in which case the
112 * oldest elements get overwritten. The index variable is increased monotonically,
113 * so users may determine whether the buffer has already overflown by checking
114 * if index > size. If so, (index mod size) points to the oldest element.
116 * The whole buffer can be dumped using the dump() method. This will produce a UU-encoded
117 * version of the zipped buffer content.
119 struct __attribute__((packed))
122 struct GenericEvent* buffer;
126 l4_uint64_t *timestamp;
132 * Create event buffer
134 * sharableTSC -> allow the TSC value to be located in a way that we can share
135 * this value among different address spaces (e.g., have replicas
136 * log events themselves using this TSC). This requires the timestamp
137 * value to be placed on a dedicated page.
139 EventBuf(bool sharableTSC = false)
140 : buffer(0), index(0), size(0), sharedTSC(sharableTSC ? 1 : 0)
142 static_assert(sizeof(SensorHead) == 13, "Sensor head not 13 bytes large!");
143 static_assert(sizeof(GenericEvent) == 32, "GenericEvent larger than 24 bytes!");
144 //static_assert((l4_umword_t)((EventBuf const *)0)->_end < sizeof(GenericEvent), "head too large?");
147 timestamp = new l4_uint64_t();
150 static unsigned char dummyBuffer[32];
151 set_buffer(dummyBuffer, 32);
157 enter_kdebug("~EventBuf");
164 void set_buffer(unsigned char *buf, unsigned size_in_bytes)
166 buffer = reinterpret_cast<GenericEvent*>(buf);
167 size = size_in_bytes / sizeof(GenericEvent);
171 void set_tsc_buffer(l4_uint64_t *buf)
177 static void launchTimerThread(l4_addr_t timerAddress, unsigned CPU);
179 l4_uint64_t getTime(bool local=false)
189 * Get the next buffer entry.
191 * Safe against concurrent calls by using atomic increment on the
192 * counter. Concurrent accesses may lead to events not being properly
197 unsigned val = l4util_inc32_res(&index) - 1;
203 unsigned oldest() const
221 l4_uint64_t evbuf_get_time(void *eb, unsigned local);
222 struct GenericEvent* evbuf_next(void *eb);