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