Rev 369 | Rev 373 | 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> |
||
370 | giacomo | 64 | #include <kernel/kern.h> |
352 | giacomo | 65 | #include "FTrace.h" |
66 | |||
364 | giacomo | 67 | #define TRACER_NO_OUTPUT 0 |
68 | #define TRACER_UDP_OUTPUT 1 |
||
69 | |||
352 | giacomo | 70 | #define TRACER_LOGEVENT fast_logevent |
71 | |||
365 | giacomo | 72 | int tracer_initialize(int MemorySize); |
362 | giacomo | 73 | void tracer_enable(); |
74 | void tracer_disable(); |
||
75 | void tracer_print_statistics(); |
||
76 | |||
369 | giacomo | 77 | int tracer_send_logged_events(int NumberOfEvents); |
78 | void tracer_flush_sent_events(); |
||
79 | |||
365 | giacomo | 80 | //UDP |
81 | |||
370 | giacomo | 82 | int tracer_init_udp(int flag, char *local_ip, char *target_ip); |
83 | int tracer_create_udp_task(TASK_MODEL *m, int EventsForPeriod); |
||
365 | giacomo | 84 | |
352 | giacomo | 85 | #define TRACER_SERIALIZE |
86 | |||
87 | /* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size) |
||
88 | if (flag & 1) + 4(par1) |
||
89 | if (flag & 3) + 4(par2) |
||
90 | * Return 0 -> Success |
||
91 | * Return 1 -> Inactive |
||
92 | * Return 2 -> Error |
||
93 | */ |
||
94 | extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
95 | { |
||
96 | |||
97 | extern void *StartTracerBuffer; |
||
98 | extern void *EndTracerBuffer; |
||
362 | giacomo | 99 | extern void *LastBeforeEndTracerBuffer; |
352 | giacomo | 100 | extern void *CurrentTracerBuffer; |
362 | giacomo | 101 | extern void *FirstTracerBuffer; |
102 | |||
352 | giacomo | 103 | extern int TracerActive; |
104 | extern unsigned long long TracerEventsRecorded; |
||
368 | giacomo | 105 | extern unsigned int TracerEventsPresent; |
352 | giacomo | 106 | |
107 | SYS_FLAGS f; |
||
108 | |||
109 | DWORD tsc_low, tsc_high; |
||
110 | BYTE size = 10; |
||
111 | |||
112 | f = ll_fsave(); |
||
113 | |||
114 | if (!TracerActive) { |
||
115 | ll_frestore(f); |
||
116 | return 1; |
||
117 | } |
||
118 | |||
119 | #ifdef TRACER_SERIALIZE |
||
120 | __asm__("xorl %%eax,%%eax\n\t" |
||
121 | "cpuid\n\t" |
||
122 | "rdtsc\n\t" |
||
123 | :"=a" (tsc_low), "=d" (tsc_high) |
||
124 | : |
||
125 | :"ebx","ecx"); |
||
126 | #else |
||
127 | __asm__("rdtsc\n\t" |
||
128 | :"=a" (tsc_low), "=d" (tsc_high) |
||
129 | ::); |
||
130 | #endif |
||
131 | |||
132 | if (flag & 1) size += 4; |
||
133 | if (flag & 3) size += 4; |
||
134 | |||
362 | giacomo | 135 | // Adjust FirstTracerBuffer |
368 | giacomo | 136 | if (FirstTracerBuffer >= CurrentTracerBuffer && TracerEventsPresent != 0) { |
363 | giacomo | 137 | while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer && |
138 | FirstTracerBuffer != StartTracerBuffer) { |
||
362 | giacomo | 139 | FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9); |
363 | giacomo | 140 | if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer; |
362 | giacomo | 141 | } |
364 | giacomo | 142 | } else { |
368 | giacomo | 143 | TracerEventsPresent++; |
362 | giacomo | 144 | } |
145 | |||
146 | // Check if we overcome EndTracerBuffer |
||
352 | giacomo | 147 | if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) { |
148 | //Cyclical Buffer implementation |
||
362 | giacomo | 149 | LastBeforeEndTracerBuffer = CurrentTracerBuffer; |
352 | giacomo | 150 | CurrentTracerBuffer = StartTracerBuffer; |
362 | giacomo | 151 | //Set the First Event |
363 | giacomo | 152 | while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer) { |
153 | FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9); |
||
154 | if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer; |
||
155 | } |
||
352 | giacomo | 156 | } |
157 | |||
362 | giacomo | 158 | // Add the new event |
352 | giacomo | 159 | *(BYTE *)CurrentTracerBuffer = type; |
160 | CurrentTracerBuffer++; |
||
161 | *(DWORD *)(CurrentTracerBuffer) = tsc_high; |
||
162 | CurrentTracerBuffer+=4; |
||
163 | *(DWORD *)(CurrentTracerBuffer) = tsc_low; |
||
164 | CurrentTracerBuffer+=4; |
||
165 | *(BYTE *)(CurrentTracerBuffer) = size; |
||
166 | CurrentTracerBuffer++; |
||
167 | if (flag & 1) { |
||
168 | *(DWORD *)(CurrentTracerBuffer) = par1; |
||
169 | CurrentTracerBuffer+=4; |
||
170 | } |
||
171 | if (flag & 3) { |
||
172 | *(DWORD *)(CurrentTracerBuffer) = par2; |
||
173 | CurrentTracerBuffer+=4; |
||
174 | } |
||
175 | |||
176 | if (CurrentTracerBuffer > EndTracerBuffer) { |
||
177 | ll_frestore(f); |
||
178 | return 2; |
||
179 | } |
||
180 | |||
181 | TracerEventsRecorded++; |
||
182 | |||
183 | ll_frestore(f); |
||
184 | return 0; |
||
185 | |||
186 | } |
||
187 | |||
188 | #else |
||
189 | |||
190 | #define TRACER_LOGEVENT(a,b,c,d) |
||
191 | |||
192 | #endif |
||
193 | |||
194 | #endif |
||
195 | |||
196 | #endif |