20
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <piprofiler/ProfilerVersion.h>
|
|
20 |
#include <piprofiler/ProfilerTraces.h>
|
|
21 |
#include <kern_priv.h>
|
|
22 |
#include <arm.h>
|
|
23 |
|
|
24 |
#include "GppSamplerImpl.h"
|
|
25 |
|
|
26 |
extern TUint* IntStackPtr();
|
|
27 |
#define TAG(obj) (*(TUint32*)&(obj.iAsyncDeleteNext))
|
|
28 |
|
62
|
29 |
#ifndef __SMP__
|
|
30 |
extern TUint IDFCRunning();
|
|
31 |
#endif
|
|
32 |
|
|
33 |
#ifdef __SMP__
|
|
34 |
static TSpinLock CpuSpinLock = TSpinLock(TSpinLock::EOrderGenericIrqLow3);
|
|
35 |
#endif
|
|
36 |
|
20
|
37 |
// properties for ISA task parsing
|
|
38 |
const TUid KIsaPropertyCat={0x2001E5AD};
|
|
39 |
enum TIsaPropertyKeys
|
|
40 |
{
|
|
41 |
EIsaPropertyIsaTaskParserStatus = 1,
|
|
42 |
EIsaPropertyIsaTaskAddressStart,
|
|
43 |
EIsaPropertyIsaTaskAddressEnd,
|
|
44 |
EIsaPropertyIsaTaskAddress,
|
|
45 |
EIsaPropertyIsaOsTaskRunningAddress,
|
|
46 |
EIsaPropertyIsaTaskParsedName
|
|
47 |
};
|
|
48 |
|
|
49 |
|
|
50 |
DGppSamplerImpl::DGppSamplerImpl()
|
|
51 |
{
|
|
52 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl");
|
62
|
53 |
#ifndef __SMP__
|
20
|
54 |
iInterruptStack = (TUint*)IntStackPtr();
|
62
|
55 |
#endif
|
|
56 |
|
20
|
57 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl - attaching to properties");
|
|
58 |
|
62
|
59 |
TInt err(iIsaStartAddr.Attach(KIsaPropertyCat, EIsaPropertyIsaTaskAddressStart));
|
20
|
60 |
if(err != KErrNone)
|
|
61 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl() - Property EIsaPropertyIsaTaskAddressStart not available");
|
|
62 |
err = iIsaEndAddr.Attach(KIsaPropertyCat, EIsaPropertyIsaTaskAddressEnd);
|
|
63 |
if(err != KErrNone)
|
|
64 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl() - Property EIsaPropertyIsaTaskAddressEnd not available");
|
|
65 |
err = iIsaPluginStatus.Attach(KIsaPropertyCat, EIsaPropertyIsaTaskParserStatus);
|
|
66 |
if(err != KErrNone)
|
|
67 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl() - Property EIsaPropertyIsaTaskParserStatus not available");
|
|
68 |
err = iIsaOsTaskRunning.Attach(KIsaPropertyCat, EIsaPropertyIsaOsTaskRunningAddress);
|
|
69 |
if(err != KErrNone)
|
|
70 |
LOGTEXT("GppSamplerImpl::GppSamplerImpl() - Property EIsaPropertyIsaOsTaskRunningAddress not available");
|
|
71 |
|
|
72 |
PROFILER_ISA_TASK_NAMES
|
|
73 |
|
62
|
74 |
NKern::LockSystem();
|
|
75 |
// get status of ISA plug-in
|
|
76 |
TPropertyStatus status;
|
|
77 |
if(iIsaPluginStatus.GetStatus(status))
|
|
78 |
{
|
|
79 |
iIsaPluginStatus.Get(iIsaStatus);
|
|
80 |
LOGSTRING2("GppSamplerImpl::Reset - ISA plug-in status %d", iIsaStatus);
|
|
81 |
}
|
|
82 |
NKern::UnlockSystem();
|
20
|
83 |
Reset();
|
|
84 |
}
|
|
85 |
|
|
86 |
DGppSamplerImpl::~DGppSamplerImpl()
|
|
87 |
{
|
|
88 |
iIsaStartAddr.Close();
|
|
89 |
iIsaEndAddr.Close();
|
|
90 |
iIsaPluginStatus.Close();
|
|
91 |
iIsaOsTaskRunning.Close();
|
|
92 |
}
|
|
93 |
|
|
94 |
void DGppSamplerImpl::Reset()
|
|
95 |
{
|
62
|
96 |
LOGSTRING("GppSamplerImpl::Reset() - entry");
|
20
|
97 |
iLastPc = 0;
|
42
|
98 |
iLastThread = 0xfffffffe;
|
20
|
99 |
iRepeat = 0;
|
|
100 |
iIsaStatus = 0;
|
|
101 |
iIsaStart = 0;
|
|
102 |
iIsaEnd = 0;
|
|
103 |
// isaOsTaskRunningAddr = 0;
|
62
|
104 |
iPrevTS = NKern::TickCount(); // get the system tick value for sync purposes
|
20
|
105 |
|
|
106 |
// in SMP start time common with all CPUs, provided by DGeneralsDriver class
|
|
107 |
#ifndef __SMP__
|
62
|
108 |
iStartTime = ( iPrevTS & 0xfffffffc );
|
|
109 |
#else
|
|
110 |
iStartTime = ( iPrevTS & 0xfffffff0 );
|
20
|
111 |
#endif
|
|
112 |
|
62
|
113 |
TInt osAddr(0);
|
20
|
114 |
|
62
|
115 |
LOGSTRING("GppSamplerImpl::Reset - getting status");
|
20
|
116 |
|
|
117 |
if(iIsaStatus > 0)
|
|
118 |
{
|
62
|
119 |
LOGSTRING("GppSamplerImpl::Reset - get isa start address");
|
20
|
120 |
iIsaStartAddr.Get(iIsaStart);
|
62
|
121 |
LOGSTRING("GppSamplerImpl::Reset - get isa end address");
|
20
|
122 |
iIsaEndAddr.Get(iIsaEnd);
|
62
|
123 |
LOGSTRING("GppSamplerImpl::Reset - get isa os_task_running address");
|
20
|
124 |
iIsaOsTaskRunning.Get(osAddr);
|
|
125 |
isaOsTaskRunningAddr = reinterpret_cast<TInt*>(osAddr);
|
|
126 |
LOGSTRING2("GppSamplerImpl::Reset - got isa os_task_running address 0x%X", osAddr);
|
|
127 |
}
|
|
128 |
|
62
|
129 |
LOGSTRING("GppSamplerImpl::Reset - initializing isa task list");
|
20
|
130 |
|
|
131 |
iIsaSample = false;
|
|
132 |
|
62
|
133 |
for(TInt i(0);i<256;i++)
|
20
|
134 |
knownIsaTasks[i] = -1;
|
|
135 |
|
|
136 |
knownIsaTaskCount = 0;
|
|
137 |
|
|
138 |
iCpuSelector = 0x3;
|
|
139 |
#ifndef __SMP__
|
|
140 |
iMask = 0xfffffffc;
|
|
141 |
#else
|
|
142 |
iMask = 0xfffffff0;
|
|
143 |
switch(iCpuNumber)
|
|
144 |
{
|
|
145 |
case 0:
|
|
146 |
iCpuSelector = 0x1;
|
|
147 |
break;
|
|
148 |
case 1:
|
|
149 |
iCpuSelector = 0x2;
|
|
150 |
break;
|
|
151 |
case 2:
|
|
152 |
iCpuSelector = 0x4;
|
|
153 |
break;
|
|
154 |
case 3:
|
|
155 |
iCpuSelector = 0x8;
|
|
156 |
break;
|
|
157 |
}
|
|
158 |
#endif
|
62
|
159 |
LOGSTRING("GppSamplerImpl::Reset() - exit");
|
20
|
160 |
}
|
|
161 |
|
|
162 |
TUint8* DGppSamplerImpl::EncodeTag(TUint8* aPtr)
|
|
163 |
//
|
|
164 |
// Encode a tag and version to the trace data. This allows the offline analyser to
|
|
165 |
// identify the sample data.
|
|
166 |
//
|
|
167 |
{
|
|
168 |
_LIT(KGppSamplerVersion,"Bappea_GPP_V");
|
|
169 |
_LIT(KProfilerVersion,"#Prof#");
|
|
170 |
_LIT(KSamplerVersion,"#Samp#");
|
|
171 |
#ifdef __SMP__
|
|
172 |
_LIT(KCPUNumberText,"#CPU#");
|
|
173 |
#endif
|
|
174 |
|
|
175 |
TBuf<64> buf;
|
|
176 |
buf.Zero();
|
|
177 |
buf.Append(KGppSamplerVersion);
|
|
178 |
buf.Append(PROFILER_GPP_SAMPLER_VERSION);
|
|
179 |
buf.Append(KProfilerVersion);
|
|
180 |
buf.Append(PROFILER_VERSION_SHORT);
|
|
181 |
buf.Append(KSamplerVersion);
|
|
182 |
buf.Append(PROFILER_SAMPLER_VERSION);
|
|
183 |
#ifdef __SMP__
|
|
184 |
buf.Append(KCPUNumberText);
|
|
185 |
buf.AppendNum(iCpuNumber);
|
|
186 |
#endif
|
|
187 |
aPtr = EncodeText(aPtr, buf);
|
|
188 |
return aPtr;
|
|
189 |
}
|
|
190 |
|
|
191 |
TUint8* DGppSamplerImpl::EncodeInt(TUint8* aPtr,TInt aValue)
|
|
192 |
{
|
|
193 |
LOGSTRING2("Encoding int 0x%x",aPtr);
|
|
194 |
|
|
195 |
LOGSTRING2("TIint = 0x%x",aValue);
|
62
|
196 |
#ifdef __SMP__
|
|
197 |
TInt intState(0);
|
|
198 |
intState = __SPIN_LOCK_IRQSAVE(CpuSpinLock);
|
|
199 |
#endif
|
20
|
200 |
TUint byte;
|
|
201 |
for (;;)
|
|
202 |
{
|
|
203 |
byte = aValue & 0x7f;
|
|
204 |
if ((aValue >> 6) == (aValue >> 7))
|
|
205 |
break;
|
|
206 |
aValue >>= 7;
|
|
207 |
*aPtr++ = byte;
|
|
208 |
}
|
|
209 |
*aPtr++ = byte | 0x80;
|
62
|
210 |
#ifdef __SMP__
|
|
211 |
__SPIN_UNLOCK_IRQRESTORE(CpuSpinLock, intState);
|
|
212 |
#endif
|
20
|
213 |
LOGSTRING2("Encoded int 0x%x",aPtr);
|
|
214 |
|
|
215 |
return aPtr;
|
|
216 |
}
|
|
217 |
|
|
218 |
TUint8* DGppSamplerImpl::EncodeUint(TUint8* aPtr,TUint aValue)
|
|
219 |
{
|
|
220 |
LOGSTRING2("Encoding Uint 0x%x",aPtr);
|
|
221 |
|
|
222 |
LOGSTRING2("TUint = 0x%x",aValue);
|
|
223 |
|
62
|
224 |
#ifdef __SMP__
|
|
225 |
TInt intState(0);
|
|
226 |
intState = __SPIN_LOCK_IRQSAVE(CpuSpinLock);
|
|
227 |
#endif
|
20
|
228 |
TUint byte;
|
|
229 |
for (;;)
|
|
230 |
{
|
|
231 |
byte = aValue & 0x7f;
|
|
232 |
aValue >>= 7;
|
|
233 |
if (aValue == 0)
|
|
234 |
break;
|
|
235 |
*aPtr++ = byte;
|
|
236 |
}
|
|
237 |
*aPtr++ = byte | 0x80;
|
62
|
238 |
#ifdef __SMP__
|
|
239 |
__SPIN_UNLOCK_IRQRESTORE(CpuSpinLock, intState);
|
|
240 |
#endif
|
20
|
241 |
LOGSTRING2("Encoded Uint 0x%x",aPtr);
|
|
242 |
|
|
243 |
return aPtr;
|
|
244 |
}
|
|
245 |
|
|
246 |
TUint8* DGppSamplerImpl::EncodeText(TUint8* aPtr, const TDesC& aDes)
|
|
247 |
//
|
|
248 |
// Encode a descriptor into the data stream
|
|
249 |
// This is currently limited to a descriptor that is up to 255 characters in length,
|
|
250 |
// and Unicode characters are truncated to 8 bits
|
|
251 |
//
|
|
252 |
{
|
|
253 |
LOGSTRING2("Encoding text 0x%x",aPtr);
|
62
|
254 |
TInt len(aDes.Length());
|
|
255 |
#ifdef __SMP__
|
|
256 |
TInt intState(0);
|
|
257 |
intState = __SPIN_LOCK_IRQSAVE(CpuSpinLock);
|
|
258 |
#endif
|
20
|
259 |
*aPtr++ = TUint8(len);
|
|
260 |
const TText* p = aDes.Ptr();
|
|
261 |
while (--len >= 0)
|
|
262 |
{
|
|
263 |
*aPtr++ = TUint8(*p++);
|
|
264 |
}
|
62
|
265 |
#ifdef __SMP__
|
|
266 |
__SPIN_UNLOCK_IRQRESTORE(CpuSpinLock, intState);
|
|
267 |
#endif
|
20
|
268 |
LOGSTRING2("Encoded text 0x%x",aPtr);
|
|
269 |
return aPtr;
|
|
270 |
}
|
|
271 |
|
|
272 |
|
|
273 |
TUint8* DGppSamplerImpl::EncodeName(TUint8* aPtr, DObject& aObject,TUint32 id)
|
|
274 |
//
|
|
275 |
// Encode the name of a kernel object
|
|
276 |
//
|
|
277 |
{
|
|
278 |
LOGSTRING2("Encoding name 0x%x",aPtr);
|
|
279 |
TBuf8<0x5f> name;
|
|
280 |
aObject.TraceAppendName(name,false);
|
62
|
281 |
LOGSTRING2("DGppSamplerImpl::EncodeName() - new process/thread found: %S", &name);
|
|
282 |
|
20
|
283 |
if(id != 0xffffffff)
|
|
284 |
{
|
|
285 |
name.Append('[');
|
|
286 |
name.AppendNum(id,EHex);
|
|
287 |
name.Append(']');
|
|
288 |
}
|
|
289 |
else
|
|
290 |
{
|
|
291 |
name.Append('[');
|
|
292 |
name.AppendNum((TUint32)((void*)&(((DThread*)&aObject)->iNThread)),EHex);
|
|
293 |
name.Append(']');
|
|
294 |
}
|
|
295 |
|
|
296 |
aPtr = EncodeText(aPtr,name);
|
|
297 |
LOGSTRING2("Encoded name 0x%x",aPtr);
|
|
298 |
return aPtr;
|
|
299 |
}
|
|
300 |
|
|
301 |
TUint8* DGppSamplerImpl::EncodeThread(TUint8* aPtr, DThread& aThread)
|
|
302 |
//
|
|
303 |
// Encode a thread name in the data stream.
|
|
304 |
// The thread is identified by its name, and the identity of its owning process.
|
|
305 |
// If the process has not been identified in the data stream already, it's name is
|
|
306 |
// also encoded.
|
|
307 |
//
|
|
308 |
{
|
|
309 |
LOGSTRING2("Encoding thread 0x%x",aPtr);
|
|
310 |
|
62
|
311 |
DProcess& p(*aThread.iOwningProcess);
|
20
|
312 |
|
|
313 |
aPtr = EncodeUint(aPtr, p.iId);
|
|
314 |
|
|
315 |
#ifdef __SMP__
|
|
316 |
// check if first time founding
|
|
317 |
if ((TAG(p) & iMask) != iStartTime)
|
|
318 |
{
|
|
319 |
// mark tagged for this CPU
|
|
320 |
TAG(p) = (iStartTime | iCpuSelector);
|
|
321 |
|
|
322 |
// The thread is 'unknown' to this sample, so encode the thread name
|
|
323 |
aPtr = EncodeName(aPtr, p, p.iId);
|
|
324 |
}
|
|
325 |
// check if thread appeared already on this CPU
|
|
326 |
else if((TAG(p) & iCpuSelector) != iCpuSelector)
|
|
327 |
{
|
|
328 |
TAG(p) = (TAG(p) | iCpuSelector);
|
|
329 |
// The thread is 'unknown' to this sample, so encode the thread name
|
|
330 |
aPtr = EncodeName(aPtr, p, p.iId);
|
|
331 |
}
|
62
|
332 |
else
|
|
333 |
{
|
|
334 |
|
|
335 |
}
|
20
|
336 |
#else
|
|
337 |
if (TAG(p) != iStartTime)
|
|
338 |
{
|
|
339 |
TAG(p) = iStartTime;
|
|
340 |
// Provide the name matching this process ID
|
|
341 |
aPtr = EncodeName(aPtr, p, p.iId);
|
|
342 |
}
|
|
343 |
#endif
|
|
344 |
aPtr = EncodeName(aPtr, aThread,0xffffffff);
|
|
345 |
|
|
346 |
LOGSTRING2("Encoded thread 0x%x",aPtr);
|
|
347 |
|
|
348 |
return aPtr;
|
|
349 |
}
|
|
350 |
|
|
351 |
TUint8* DGppSamplerImpl::EncodeRepeat(TUint8* aPtr)
|
|
352 |
//
|
|
353 |
// Encode a repeated sequence of samples
|
|
354 |
//
|
|
355 |
{
|
|
356 |
LOGSTRING2("Encoding repeat, 0x%x",iRepeat);
|
|
357 |
|
|
358 |
aPtr = EncodeInt(aPtr, 0);
|
|
359 |
aPtr = EncodeUint(aPtr, iRepeat);
|
|
360 |
iRepeat = 0;
|
|
361 |
|
|
362 |
LOGSTRING2("Encoded repeat, 0x%x",iRepeat);
|
|
363 |
|
|
364 |
return aPtr;
|
|
365 |
}
|
|
366 |
|
|
367 |
TInt DGppSamplerImpl::CreateFirstSample()
|
|
368 |
{
|
|
369 |
LOGTEXT("GppSamplerImpl::CreateFirstSample");
|
|
370 |
Reset();
|
|
371 |
|
62
|
372 |
TUint8* w(this->tempBuf);
|
20
|
373 |
w = EncodeTag(w);
|
|
374 |
|
62
|
375 |
TInt length(w-tempBuf);
|
20
|
376 |
|
|
377 |
LOGSTRING2("TAG encoded, length %d",length);
|
|
378 |
return length;
|
|
379 |
}
|
|
380 |
|
|
381 |
TBool DGppSamplerImpl::IsaTaskKnown(TUint8 task)
|
|
382 |
{
|
62
|
383 |
for(TInt i(0);i<256;i++)
|
20
|
384 |
{
|
|
385 |
if(knownIsaTasks[i] == -1)
|
|
386 |
{
|
|
387 |
knownIsaTasks[i] = task;
|
|
388 |
knownIsaTaskCount++;
|
|
389 |
return false;
|
|
390 |
}
|
|
391 |
else if(knownIsaTasks[i] == task)
|
|
392 |
{
|
|
393 |
return true;
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
return false;
|
|
398 |
}
|
|
399 |
|
|
400 |
TUint8* DGppSamplerImpl::EncodeIsaTask(TUint8* aPtr, TUint task)
|
|
401 |
|
|
402 |
{
|
|
403 |
LOGSTRING2("Encoding ISA task 0x%x",aPtr);
|
|
404 |
|
|
405 |
aPtr = EncodeUint(aPtr,task);
|
|
406 |
// use the task name as the process name
|
|
407 |
aPtr = EncodeIsaName(aPtr,task,true);
|
|
408 |
// then encode the task name
|
|
409 |
aPtr = EncodeIsaName(aPtr,task,false);
|
|
410 |
|
|
411 |
LOGSTRING2("Encoded ISA task 0x%x",aPtr);
|
|
412 |
|
|
413 |
return aPtr;
|
|
414 |
}
|
|
415 |
|
|
416 |
TUint8* DGppSamplerImpl::EncodeIsaName(TUint8* aPtr, TUint task,TBool process)
|
|
417 |
//
|
|
418 |
// Encode a descriptor into the data stream
|
|
419 |
// This is currently limited to a descriptor that is up to 255 characters in length,
|
|
420 |
// and Unicode characters are truncated to 8 bits
|
|
421 |
//
|
|
422 |
{
|
|
423 |
TBuf8<256> aDes;
|
|
424 |
|
|
425 |
if(iIsaStatus > 0)
|
|
426 |
{
|
|
427 |
// resolve the isa task name from the task name array
|
|
428 |
if((task-100000) < PROFILER_ISA_OS_TASK_AMOUNT && process == false)
|
|
429 |
{
|
|
430 |
aDes.Append(isaTaskNames[(task-100000)]);
|
|
431 |
}
|
|
432 |
else
|
|
433 |
{
|
|
434 |
aDes.Append(_L8("NativeOS_Task"));
|
|
435 |
}
|
|
436 |
}
|
|
437 |
else
|
|
438 |
{
|
|
439 |
aDes.Append(_L8("NativeOS_Task"));
|
|
440 |
}
|
|
441 |
|
|
442 |
aDes.Append('[');
|
|
443 |
aDes.AppendNum((task-100000),EHex);
|
|
444 |
aDes.Append(']');
|
|
445 |
|
|
446 |
LOGSTRING2("Encoding ISA name 0x%x",aPtr);
|
62
|
447 |
TInt len(aDes.Length());
|
20
|
448 |
*aPtr++ = TUint8(len);
|
62
|
449 |
const TText* p(aDes.Ptr());
|
20
|
450 |
while (--len >= 0)
|
|
451 |
{
|
|
452 |
*aPtr++ = TUint8(*p++);
|
|
453 |
}
|
|
454 |
|
|
455 |
LOGSTRING2("Encoded ISA name 0x%x",aPtr);
|
|
456 |
return aPtr;
|
|
457 |
}
|
|
458 |
|
|
459 |
|
|
460 |
TInt DGppSamplerImpl::SampleImpl()
|
|
461 |
//
|
|
462 |
// ISR for the profile timer
|
|
463 |
// This extracts the thread and PC that was current when the interrupt went off and
|
|
464 |
// encodes it into the sample data buffer. If enough data has been generated, the
|
|
465 |
// DFC is triggered to complete a read request
|
|
466 |
//
|
|
467 |
{
|
62
|
468 |
NThread* pN(NKern::CurrentThread());
|
|
469 |
TUint8* w(this->tempBuf);
|
|
470 |
//TInt currCpu(NKern::CurrentCpu());
|
|
471 |
TInt mySampleStartTime(NKern::TickCount()); // get the system tick value for sync purposes, in ms
|
|
472 |
// TInt tickdiff(mySampleStartTime-iPrevTS);
|
|
473 |
|
|
474 |
if (Kern::NThreadToDThread(pN)==NULL)
|
|
475 |
{
|
|
476 |
LOGSTRING("Kern::NThreadToDThread is null");
|
|
477 |
}
|
20
|
478 |
|
62
|
479 |
else
|
|
480 |
{
|
|
481 |
// check timestamp & compare to previous
|
|
482 |
// if out of sync, encode unknown::unknown thread
|
20
|
483 |
|
62
|
484 |
/*
|
|
485 |
// In SMP environment there have been missing ticks. These prints are for helping debug this issue
|
|
486 |
// but solution might not work.
|
|
487 |
if(tickdiff > 1)
|
|
488 |
{
|
|
489 |
Kern::Printf(("DGppSamplerImpl::SampleImpl() - Current time tick %d"), mySampleStartTime);
|
|
490 |
Kern::Printf(("DGppSamplerImpl::SampleImpl() - Previous time tick %d"), iPrevTS);
|
|
491 |
// Kern::Printf(("DGppSamplerImpl::SampleImpl() - Tick period %d"),NKern::TickPeriod());
|
|
492 |
Kern::Printf(("DGppSamplerImpl::SampleImpl() - Tick difference %d"),tickdiff);
|
|
493 |
Kern::Printf(("DGppSamplerImpl::SampleImpl() - Current cpu %d"),NKern::CurrentCpu());
|
|
494 |
}
|
|
495 |
// else
|
|
496 |
// {
|
|
497 |
// Kern::Printf(("DGppSamplerImpl::SampleImpl() - Tick differance <= 1: %d"),tickdiff);
|
|
498 |
// }
|
|
499 |
*/
|
20
|
500 |
|
62
|
501 |
TLinAddr pC;
|
|
502 |
|
|
503 |
#ifdef __SMP__
|
|
504 |
pC = Arm::IrqReturnAddress();
|
|
505 |
#else
|
|
506 |
// get program counter of irq mode
|
|
507 |
pC = iInterruptStack[-1]; // ignore the low bit being set for THUMB mode - we use for something else
|
|
508 |
#endif
|
|
509 |
//Kern::Printf(("pc value 0x%x sp 0x%x"),pc,iInterruptStack);
|
|
510 |
pC &= ~1;
|
|
511 |
TInt diff(pC - iLastPc);
|
|
512 |
iLastPc = pC;
|
|
513 |
|
|
514 |
if(iIsaStatus > 0)
|
|
515 |
{
|
|
516 |
if((TUint32)pC > (TUint32)iIsaStart && (TUint32)pC < (TUint32)iIsaEnd)
|
|
517 |
{
|
|
518 |
iIsaSample = true;
|
|
519 |
}
|
|
520 |
else
|
|
521 |
{
|
|
522 |
iIsaSample = false;
|
|
523 |
}
|
|
524 |
}
|
|
525 |
|
|
526 |
// if((TUint32)pC < 0x80000000 || (TUint32)pC > 0x8FFFFFFF)
|
|
527 |
// {
|
|
528 |
// //Kern::Printf("DGppSamplerImpl::SampleImpl() - wrong PC value, 0x%x", (TUint32)pC);
|
|
529 |
// iIsaSample = true;
|
|
530 |
// }
|
|
531 |
|
|
532 |
// request for current thread from kernel
|
|
533 |
DThread& t(((DThread&)*Kern::NThreadToDThread(pN)));
|
|
534 |
|
|
535 |
TUint tid;
|
|
536 |
TUint8 isaTask(0);
|
|
537 |
if(iIsaSample)
|
|
538 |
{
|
|
539 |
//Kern::Printf(("Reading ISA task number from 0x%x"),isaOsTaskRunningAddr);
|
|
540 |
// if we don't get reasonable ISA address to read, skip ISA task handling
|
|
541 |
if(isaOsTaskRunningAddr == 0)
|
|
542 |
{
|
|
543 |
tid = 100000; // to tell the difference from SOS threads
|
|
544 |
iIsaSample = false;
|
|
545 |
}
|
|
546 |
else // normal ISA task parsing process
|
|
547 |
{
|
|
548 |
isaTask = *isaOsTaskRunningAddr;
|
|
549 |
LOGSTRING2("ISA task = %d",isaTask);
|
|
550 |
tid = isaTask;
|
|
551 |
// this will make sure we don't mix ISA tasks and normal tasks
|
|
552 |
tid += 100000;
|
|
553 |
}
|
|
554 |
}
|
|
555 |
else
|
|
556 |
{
|
|
557 |
tid = t.iId;
|
|
558 |
}
|
|
559 |
|
|
560 |
if (tid != iLastThread)
|
|
561 |
{
|
|
562 |
diff |= 1; // Change of thread is marked in the low bit of the PC difference
|
|
563 |
}
|
|
564 |
TUint rp(iRepeat);
|
|
565 |
if (diff == 0)
|
|
566 |
{
|
|
567 |
iRepeat = rp + 1; // Identical sample, bump up the repeat count
|
|
568 |
}
|
|
569 |
else
|
|
570 |
{
|
|
571 |
if (rp)
|
|
572 |
{
|
|
573 |
w = EncodeRepeat(w); // Encode the repeat data
|
|
574 |
}
|
|
575 |
w = EncodeInt(w, diff); // Encode the PC difference
|
|
576 |
//if (diff & 0x1 == 1)
|
|
577 |
if (diff & 1)
|
|
578 |
{
|
|
579 |
// LOGSTRING3("Encode pc diff curr cpu %d diff %d", currCpu, diff);
|
|
580 |
if(iIsaSample) // Encode the new thread ID
|
|
581 |
{
|
|
582 |
iLastThread = tid;
|
|
583 |
// LOGSTRING2("Encode thread id UINT curr cpu %d", currCpu);
|
|
584 |
w = EncodeUint(w,tid);
|
|
585 |
if(!this->IsaTaskKnown(isaTask))
|
|
586 |
{
|
|
587 |
//Kern::Printf("Encode isa task");
|
|
588 |
w = EncodeIsaTask(w,iLastThread);
|
|
589 |
}
|
|
590 |
//LOGSTRING2("Sample total length: %d",w-tempBuf);
|
|
591 |
TInt length = w-tempBuf;
|
|
592 |
return length; // encoded isa task, return here
|
|
593 |
}
|
|
594 |
iLastThread = tid;
|
|
595 |
// LOGSTRING2("Encode lastthread id UinT curr cpu %d", currCpu);
|
|
596 |
w = EncodeUint(w, tid);
|
|
597 |
|
|
598 |
#ifdef __SMP__
|
|
599 |
// iStartTime format: 0xXXXXXXX0, the last byte set to zero
|
|
600 |
// iMask = 0xfffffff0(0b111....1110000), last bits reserved for the CPUs bit0=CPU0 etc.
|
|
601 |
// iCpuSelector = 0x1(0b0001), 0x2(0b0010), 0x4(0b0100) or 0x8(0b1000), to use against the mask
|
|
602 |
//#define TAG(obj) (*(TUint32*)&(obj.iAsyncDeleteNext))
|
|
603 |
// check first time founding
|
|
604 |
LOGSTRING4("TAG(t) 0x%x, iMask 0x%x, AND 0x%x ",TAG(t),iMask, (TAG(t)& iMask));
|
|
605 |
if ((TAG(t) & iMask) != iStartTime)
|
|
606 |
{
|
|
607 |
// mark tagged for this CPU
|
|
608 |
TAG(t) = (iStartTime | iCpuSelector);
|
|
609 |
|
|
610 |
// The thread is 'unknown' to this sample, so encode the thread name
|
|
611 |
// LOGSTRING2("Encode SMP thread start time curr cpu %d", currCpu);
|
|
612 |
w = EncodeThread(w, t);
|
|
613 |
}
|
|
614 |
// check if thread appeared on this CPU
|
|
615 |
else if((TAG(t) & iCpuSelector) != iCpuSelector)
|
|
616 |
{
|
|
617 |
TAG(t) = (TAG(t) | iCpuSelector);
|
|
618 |
// The thread is 'unknown' to this sample, so encode the thread name
|
|
619 |
// LOGSTRING2("Encode SMP thread cpu selector curr cpu %d", currCpu);
|
|
620 |
w = EncodeThread(w, t);
|
|
621 |
}
|
|
622 |
#else
|
|
623 |
// check if tag has not been set, neither original nor
|
|
624 |
if ((TAG(t) & 0xfffffffc) != iStartTime)
|
|
625 |
{
|
|
626 |
TAG(t) = ((TAG(t) & 0x3) | iStartTime);
|
|
627 |
// The thread is 'unknown' to this sample, so encode the thread name
|
|
628 |
w = EncodeThread(w, t);
|
|
629 |
}
|
|
630 |
|
|
631 |
#endif
|
|
632 |
}
|
|
633 |
}
|
|
634 |
}
|
20
|
635 |
|
62
|
636 |
TInt length(w-tempBuf);
|
|
637 |
LOGSTRING2("Sample total length: %d",length);
|
|
638 |
iPrevTS = mySampleStartTime; // get the system tick value for sync purposes
|
|
639 |
return length;
|
|
640 |
}
|
20
|
641 |
|