Rev 377 | Rev 497 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
352 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | #ifndef __TRACER_H__ |
||
19 | #define __TRACER_H__ |
||
20 | |||
21 | #ifdef __OLD_TRACER__ |
||
22 | |||
23 | #include <ll/sys/types.h> |
||
24 | #include "types.h" |
||
25 | #include "trace.h" |
||
355 | giacomo | 26 | #include "FTrace.h" |
352 | giacomo | 27 | |
28 | #define TRACER_LOGEVENT oldtrace |
||
29 | |||
30 | extern int (*trc_register_eventclass) |
||
31 | (int class,int num,int(*func)(trc_event_t *, int event, void *ptr)); |
||
32 | |||
33 | extern void (*trc_logevent)(int event, void *ptr); |
||
34 | |||
35 | extern int (*trc_resume)(void); |
||
36 | extern int (*trc_suspend)(void); |
||
37 | |||
38 | #define NOT_DEFINED 0xFF |
||
39 | |||
40 | extern __inline__ void oldtrace(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
41 | { |
||
42 | |||
43 | static int oldtype; |
||
44 | static int oldpar; |
||
45 | extern BYTE conv[256]; // Conversion table: ctable.c |
||
46 | BYTE ttype = 0; |
||
47 | |||
48 | ttype = type & 0x0F; |
||
49 | type = type >> 4; |
||
50 | type |= (ttype << 4); |
||
51 | |||
52 | oldtype = conv[type]; |
||
53 | |||
54 | if (oldtype != NOT_DEFINED) trc_logevent(oldtype,&oldpar); |
||
55 | |||
56 | } |
||
57 | |||
58 | |||
59 | #else |
||
60 | #ifdef __NEW_TRACER__ |
||
61 | |||
62 | #include <ll/sys/types.h> |
||
63 | #include <ll/i386/hw-instr.h> |
||
64 | #include "FTrace.h" |
||
65 | |||
364 | giacomo | 66 | #define TRACER_NO_OUTPUT 0 |
67 | #define TRACER_UDP_OUTPUT 1 |
||
68 | |||
352 | giacomo | 69 | #define TRACER_LOGEVENT fast_logevent |
70 | |||
365 | giacomo | 71 | int tracer_initialize(int MemorySize); |
362 | giacomo | 72 | void tracer_enable(); |
73 | void tracer_disable(); |
||
74 | void tracer_print_statistics(); |
||
75 | |||
369 | giacomo | 76 | int tracer_send_logged_events(int NumberOfEvents); |
77 | void tracer_flush_sent_events(); |
||
78 | |||
365 | giacomo | 79 | //UDP |
80 | |||
370 | giacomo | 81 | int tracer_init_udp(int flag, char *local_ip, char *target_ip); |
373 | giacomo | 82 | int tracer_create_udp_task(void *m, int EventsForPeriod); |
365 | giacomo | 83 | |
352 | giacomo | 84 | #define TRACER_SERIALIZE |
85 | |||
86 | /* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size) |
||
87 | if (flag & 1) + 4(par1) |
||
88 | if (flag & 3) + 4(par2) |
||
89 | * Return 0 -> Success |
||
90 | * Return 1 -> Inactive |
||
91 | * Return 2 -> Error |
||
92 | */ |
||
93 | extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
94 | { |
||
95 | |||
96 | extern void *StartTracerBuffer; |
||
97 | extern void *EndTracerBuffer; |
||
362 | giacomo | 98 | extern void *LastBeforeEndTracerBuffer; |
352 | giacomo | 99 | extern void *CurrentTracerBuffer; |
362 | giacomo | 100 | extern void *FirstTracerBuffer; |
101 | |||
352 | giacomo | 102 | extern int TracerActive; |
103 | extern unsigned long long TracerEventsRecorded; |
||
368 | giacomo | 104 | extern unsigned int TracerEventsPresent; |
352 | giacomo | 105 | |
106 | SYS_FLAGS f; |
||
107 | |||
108 | DWORD tsc_low, tsc_high; |
||
109 | BYTE size = 10; |
||
110 | |||
111 | f = ll_fsave(); |
||
112 | |||
113 | if (!TracerActive) { |
||
114 | ll_frestore(f); |
||
115 | return 1; |
||
116 | } |
||
117 | |||
118 | #ifdef TRACER_SERIALIZE |
||
119 | __asm__("xorl %%eax,%%eax\n\t" |
||
120 | "cpuid\n\t" |
||
121 | "rdtsc\n\t" |
||
122 | :"=a" (tsc_low), "=d" (tsc_high) |
||
123 | : |
||
124 | :"ebx","ecx"); |
||
125 | #else |
||
126 | __asm__("rdtsc\n\t" |
||
127 | :"=a" (tsc_low), "=d" (tsc_high) |
||
128 | ::); |
||
129 | #endif |
||
130 | |||
377 | giacomo | 131 | if (flag & 1) size += 4; |
132 | if (flag & 2) size += 4; |
||
352 | giacomo | 133 | |
362 | giacomo | 134 | // Adjust FirstTracerBuffer |
368 | giacomo | 135 | if (FirstTracerBuffer >= CurrentTracerBuffer && TracerEventsPresent != 0) { |
363 | giacomo | 136 | while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer && |
137 | FirstTracerBuffer != StartTracerBuffer) { |
||
362 | giacomo | 138 | FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9); |
363 | giacomo | 139 | if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer; |
362 | giacomo | 140 | } |
364 | giacomo | 141 | } else { |
368 | giacomo | 142 | TracerEventsPresent++; |
362 | giacomo | 143 | } |
144 | |||
145 | // Check if we overcome EndTracerBuffer |
||
352 | giacomo | 146 | if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) { |
147 | //Cyclical Buffer implementation |
||
362 | giacomo | 148 | LastBeforeEndTracerBuffer = CurrentTracerBuffer; |
352 | giacomo | 149 | CurrentTracerBuffer = StartTracerBuffer; |
362 | giacomo | 150 | //Set the First Event |
363 | giacomo | 151 | while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer) { |
152 | FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9); |
||
153 | if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer; |
||
154 | } |
||
352 | giacomo | 155 | } |
156 | |||
362 | giacomo | 157 | // Add the new event |
352 | giacomo | 158 | *(BYTE *)CurrentTracerBuffer = type; |
159 | CurrentTracerBuffer++; |
||
160 | *(DWORD *)(CurrentTracerBuffer) = tsc_high; |
||
161 | CurrentTracerBuffer+=4; |
||
162 | *(DWORD *)(CurrentTracerBuffer) = tsc_low; |
||
163 | CurrentTracerBuffer+=4; |
||
164 | *(BYTE *)(CurrentTracerBuffer) = size; |
||
165 | CurrentTracerBuffer++; |
||
377 | giacomo | 166 | if (flag & 1) { |
352 | giacomo | 167 | *(DWORD *)(CurrentTracerBuffer) = par1; |
168 | CurrentTracerBuffer+=4; |
||
169 | } |
||
377 | giacomo | 170 | if (flag & 2) { |
352 | giacomo | 171 | *(DWORD *)(CurrentTracerBuffer) = par2; |
172 | CurrentTracerBuffer+=4; |
||
173 | } |
||
174 | |||
175 | if (CurrentTracerBuffer > EndTracerBuffer) { |
||
176 | ll_frestore(f); |
||
177 | return 2; |
||
178 | } |
||
179 | |||
180 | TracerEventsRecorded++; |
||
181 | |||
182 | ll_frestore(f); |
||
183 | return 0; |
||
184 | |||
185 | } |
||
186 | |||
187 | #else |
||
188 | |||
399 | giacomo | 189 | #include "FTrace.h" |
190 | |||
352 | giacomo | 191 | #define TRACER_LOGEVENT(a,b,c,d) |
192 | |||
193 | #endif |
||
194 | |||
195 | #endif |
||
196 | |||
197 | #endif |