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
48 struct __attribute__((packed))
50 l4_uint64_t tsc; // TSC: stop
51 l4_uint32_t vcpu; // vcpu ptr
52 unsigned char type; // event type
56 struct __attribute__((packed))
65 struct __attribute__((packed))
74 struct __attribute__((packed))
82 struct __attribute__((packed))
89 struct __attribute__((packed))
102 struct __attribute__((packed))
107 unsigned owner; // current owner
108 unsigned type; // 1 -> init
116 struct __attribute__((packed))
124 struct __attribute__((packed))
127 struct SensorHead header;
129 struct PagefaultEvent pf;
130 struct SyscallEvent sys;
132 struct TrapEvent trap;
133 struct LockEvent lock;
134 struct SHMLockEvent shml;
135 struct BarnesEvent barnes;
144 * An event buffer holds events of the GenericEvent type. The class does not
145 * allocate memory. Instead the underlying buffer needs to be specified using
146 * the set_buffer() function.
148 * Once the buffer is valid, users obtain an element using the next() method
149 * and fill it appropriately.
151 * The buffer is managed as a ring buffer and may overflow, in which case the
152 * oldest elements get overwritten. The index variable is increased monotonically,
153 * so users may determine whether the buffer has already overflown by checking
154 * if index > size. If so, (index mod size) points to the oldest element.
156 * The whole buffer can be dumped using the dump() method. This will produce a UU-encoded
157 * version of the zipped buffer content.
159 struct __attribute__((packed))
162 struct GenericEvent* buffer;
166 l4_uint64_t *timestamp;
172 * Create event buffer
174 * sharableTSC -> allow the TSC value to be located in a way that we can share
175 * this value among different address spaces (e.g., have replicas
176 * log events themselves using this TSC). This requires the timestamp
177 * value to be placed on a dedicated page.
179 EventBuf(bool sharableTSC = false)
180 : buffer(0), index(0), size(0), sharedTSC(sharableTSC ? 1 : 0)
182 static_assert(sizeof(SensorHead) == 13, "Sensor head not 13 bytes large!");
183 static_assert(sizeof(GenericEvent) == 32, "GenericEvent larger than 24 bytes!");
184 //static_assert((l4_umword_t)((EventBuf const *)0)->_end < sizeof(GenericEvent), "head too large?");
187 timestamp = new l4_uint64_t();
190 static unsigned char dummyBuffer[32];
191 set_buffer(dummyBuffer, 32);
197 enter_kdebug("~EventBuf");
204 void set_buffer(unsigned char *buf, unsigned size_in_bytes)
206 buffer = reinterpret_cast<GenericEvent*>(buf);
207 size = size_in_bytes / sizeof(GenericEvent);
211 void set_tsc_buffer(l4_uint64_t *buf)
217 static void launchTimerThread(l4_addr_t timerAddress, unsigned CPU);
219 l4_uint64_t getTime(bool local=false)
229 * Get the next buffer entry.
231 * Safe against concurrent calls by using atomic increment on the
232 * counter. Concurrent accesses may lead to events not being properly
237 unsigned val = l4util_inc32_res(&index) - 1;
243 unsigned oldest() const
261 void *evbuf_get_address(void);
262 l4_uint64_t evbuf_get_time(void *eb, unsigned is_local);
263 struct GenericEvent* evbuf_next(void *eb);