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 |
//
|
|
20 |
// LDD for thread time profiling
|
|
21 |
//
|
|
22 |
|
|
23 |
#include <kern_priv.h>
|
|
24 |
#include <platform.h>
|
|
25 |
#include <arm.h>
|
62
|
26 |
#include <kernel/kpower.h>
|
20
|
27 |
|
|
28 |
#ifdef __SMP__
|
|
29 |
#include <assp/naviengine/naviengine.h>
|
|
30 |
#include <nkernsmp/arm/arm_gic.h>
|
|
31 |
#include <nkernsmp/arm/arm_tmr.h>
|
|
32 |
#endif
|
|
33 |
|
|
34 |
#include "GeneralsDriver.h"
|
|
35 |
#include <piprofiler/PluginDriver.h>
|
|
36 |
#include <piprofiler/PluginSampler.h>
|
|
37 |
#include <piprofiler/ProfilerTraces.h>
|
|
38 |
|
|
39 |
#include "GppSamplerImpl.h"
|
|
40 |
#include "GfcSamplerImpl.h"
|
|
41 |
#include "IttSamplerImpl.h"
|
|
42 |
#include "MemSamplerImpl.h"
|
|
43 |
#include "PriSamplerImpl.h"
|
|
44 |
|
|
45 |
|
|
46 |
#ifndef __SMP__
|
|
47 |
extern TUint* IntStackPtr();
|
|
48 |
extern void UsrModLr(TUint32*);
|
|
49 |
#endif
|
|
50 |
// for security check
|
|
51 |
#define KProfilerExeSecurUid 0x2001E5AD
|
|
52 |
static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
|
|
53 |
static _LIT_SECURITY_POLICY_FAIL( KDenyAllPolicy );
|
|
54 |
|
|
55 |
// CONSTANTS
|
|
56 |
//_LIT(DProfilerThread,"DProfilerThread");
|
62
|
57 |
const TInt KDSamplerThreadPriority = 27;
|
20
|
58 |
|
|
59 |
const TInt KGeneralsDriverThreadPriority = 24;
|
|
60 |
_LIT(KGeneralsDriverThread, "PIGeneralsDriver");
|
|
61 |
|
|
62 |
// global Dfc Que
|
62
|
63 |
TDynamicDfcQue* gDfcQ;
|
20
|
64 |
|
62
|
65 |
#ifdef __SMP__
|
|
66 |
static TSpinLock PiSpinLock = TSpinLock(TSpinLock::EOrderGenericIrqLow2);
|
|
67 |
#endif
|
20
|
68 |
|
|
69 |
/*
|
|
70 |
*
|
|
71 |
*
|
62
|
72 |
* Class DGeneralsProfilerFactory definition
|
20
|
73 |
*
|
|
74 |
*
|
|
75 |
*/
|
|
76 |
|
|
77 |
class DGeneralsProfilerFactory : public DLogicalDevice
|
|
78 |
{
|
|
79 |
public:
|
|
80 |
DGeneralsProfilerFactory();
|
|
81 |
~DGeneralsProfilerFactory();
|
|
82 |
|
|
83 |
public:
|
|
84 |
virtual TInt Install();
|
|
85 |
virtual void GetCaps(TDes8& aDes) const;
|
|
86 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
|
87 |
};
|
|
88 |
|
|
89 |
/*
|
|
90 |
*
|
|
91 |
*
|
62
|
92 |
* Class DGeneralsDriver definition
|
20
|
93 |
*
|
|
94 |
*
|
|
95 |
*/
|
|
96 |
class DPluginDriver;
|
62
|
97 |
class DSamplerPowerHandler;
|
20
|
98 |
|
|
99 |
class DGeneralsDriver : public DPluginDriver
|
|
100 |
{
|
|
101 |
|
|
102 |
public:
|
|
103 |
DGeneralsDriver();
|
|
104 |
~DGeneralsDriver();
|
62
|
105 |
TInt StartSampling(TInt aRate, TInt aInterruptNumber);
|
|
106 |
TInt StopSampling();
|
20
|
107 |
private:
|
62
|
108 |
TInt isExecuted;
|
|
109 |
TInt NewStart(TInt aRate);
|
|
110 |
void IncrementSampleNeededState(TInt aId);
|
|
111 |
void DecrementSampleNeededState();
|
20
|
112 |
static void NewDoProfilerProfile(TAny*);
|
|
113 |
static void NewDoDfc(TAny*);
|
|
114 |
|
|
115 |
// called by each core
|
62
|
116 |
static void Sample(TAny* aPtr);
|
20
|
117 |
|
|
118 |
TInt GetSampleTime(TUint32* time);
|
|
119 |
//TInt Test(TUint32 testCase);
|
|
120 |
|
|
121 |
|
|
122 |
void InitialiseSamplerList();
|
|
123 |
|
|
124 |
DProfilerSamplerBase* GetSamplerForId(TInt samplerId);
|
|
125 |
TInt GetSamplerVersion(TDes* aDes);
|
|
126 |
|
|
127 |
#ifdef __SMP__
|
|
128 |
void UnbindInterrupts();
|
|
129 |
#endif
|
|
130 |
TInt ProcessStreamReadRequest(TBapBuf* aBuf,TRequestStatus* aStatus);
|
|
131 |
|
|
132 |
TInt MarkTraceActive(TInt samplerIdToActivate);
|
|
133 |
TInt MarkTraceInactive(TInt samplerIdToDisable);
|
|
134 |
TInt OutputSettingsForTrace(TInt samplerId,TInt settings);
|
|
135 |
TInt AdditionalTraceSettings(TInt samplerId,TInt settings);
|
|
136 |
TInt AdditionalTraceSettings2(TInt samplerId,TInt settings);
|
|
137 |
TInt SetSamplingPeriod(TInt /*samplerId*/,TInt settings);
|
|
138 |
private:
|
|
139 |
// create the driver in EKA-2 version
|
|
140 |
TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
141 |
|
|
142 |
// receive commands and control in EKA-2 version
|
|
143 |
void HandleMsg(TMessageBase* aMsg);
|
|
144 |
private:
|
|
145 |
// timer mechanism in EKA-2 version
|
|
146 |
NTimer iTimer;
|
|
147 |
TDfc iNewDfc;
|
|
148 |
TInt iCount;
|
|
149 |
TInt iLastPcVal;
|
|
150 |
TInt iPeriod;
|
|
151 |
|
|
152 |
// sync sample number property for synchronizing other samplers
|
|
153 |
RPropertyRef iSampleStartTimeProp;
|
|
154 |
TInt iSampleStartTime;
|
|
155 |
|
|
156 |
DProfilerGppSampler<10000> gppSampler;
|
|
157 |
#ifdef __SMP__
|
|
158 |
DProfilerGppSampler<10000> gppSampler2;
|
|
159 |
DProfilerGppSampler<10000> gppSampler3;
|
|
160 |
DProfilerGppSampler<10000> gppSampler4;
|
|
161 |
#endif
|
|
162 |
DProfilerGfcSampler<10000> gfcSampler;
|
|
163 |
DProfilerIttSampler<10000> ittSampler;
|
62
|
164 |
DProfilerMemSampler<10000> memSampler;
|
20
|
165 |
DProfilerPriSampler<10000> priSampler;
|
|
166 |
#ifdef __SMP__
|
|
167 |
// DProfilerPriSampler<10000> priSampler2;
|
|
168 |
// DProfilerPriSampler<10000> priSampler3;
|
|
169 |
// DProfilerPriSampler<10000> priSampler4;
|
|
170 |
#endif
|
|
171 |
|
|
172 |
#ifndef __SMP__
|
|
173 |
static const TInt KSamplerAmount = 5;
|
|
174 |
#else
|
|
175 |
static const TInt KSamplerAmount = 8;
|
|
176 |
#endif
|
|
177 |
DProfilerSamplerBase* iSamplers[KSamplerAmount];
|
62
|
178 |
TUint iInterruptCounter[KMaxCpus];
|
20
|
179 |
TInt iMaxCpus;
|
|
180 |
TUint32 iStartTime;
|
62
|
181 |
TInt8 postSampleNeeded;
|
|
182 |
DSamplerPowerHandler* iPowerHandler;
|
|
183 |
|
|
184 |
/* using the HAL machine UID we determine the platform Bridge/Naviengine */
|
|
185 |
enum TPlatform
|
|
186 |
{
|
|
187 |
/* Bridge Platform STE500*/
|
|
188 |
EBridge,
|
|
189 |
/* Naviengine Platform NE1_TB */
|
|
190 |
ENaviengine,
|
|
191 |
/* Not recognised platform */
|
|
192 |
ENotRecognised,
|
|
193 |
/* Spare */
|
|
194 |
ESpare
|
|
195 |
};
|
|
196 |
TPlatform iPlatform;
|
|
197 |
|
|
198 |
public:
|
|
199 |
TUint8 iStarted;
|
|
200 |
TUint8 iOff;
|
|
201 |
TInt iRate;
|
|
202 |
TInt iIntNo; // Interrupt Number
|
20
|
203 |
};
|
62
|
204 |
/*
|
|
205 |
* PowerHandler
|
|
206 |
*/
|
|
207 |
class DSamplerPowerHandler : public DPowerHandler
|
|
208 |
{
|
|
209 |
public: // from DPowerHandler
|
|
210 |
void PowerUp();
|
|
211 |
void PowerDown(TPowerState);
|
|
212 |
public:
|
|
213 |
DSamplerPowerHandler(DGeneralsDriver* aChannel);
|
|
214 |
public:
|
|
215 |
DGeneralsDriver* iChannel;
|
|
216 |
};
|
|
217 |
|
20
|
218 |
|
|
219 |
/*
|
|
220 |
*
|
|
221 |
*
|
|
222 |
* Class DGeneralsProfilerFactory implementation
|
|
223 |
*
|
|
224 |
*
|
|
225 |
*/
|
|
226 |
|
|
227 |
DECLARE_STANDARD_LDD()
|
|
228 |
{
|
|
229 |
return new DGeneralsProfilerFactory();
|
|
230 |
}
|
|
231 |
|
|
232 |
TInt DGeneralsProfilerFactory::Create(DLogicalChannelBase*& aChannel)
|
|
233 |
{
|
|
234 |
aChannel = new DGeneralsDriver;
|
|
235 |
return aChannel?KErrNone:KErrNoMemory;
|
|
236 |
}
|
|
237 |
|
|
238 |
|
|
239 |
DGeneralsProfilerFactory::DGeneralsProfilerFactory()
|
|
240 |
{
|
|
241 |
// major, minor, and build version number
|
|
242 |
iVersion=TVersion(1,0,1);
|
|
243 |
}
|
|
244 |
|
|
245 |
DGeneralsProfilerFactory::~DGeneralsProfilerFactory()
|
|
246 |
{
|
62
|
247 |
if (gDfcQ)
|
|
248 |
{
|
|
249 |
gDfcQ->Destroy();
|
|
250 |
}
|
20
|
251 |
}
|
|
252 |
|
|
253 |
TInt DGeneralsProfilerFactory::Install()
|
|
254 |
{
|
62
|
255 |
// Allocate a kernel thread to run the DFC
|
|
256 |
TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDSamplerThreadPriority, KGeneralsDriverThread);
|
|
257 |
if (r != KErrNone)
|
|
258 |
{
|
|
259 |
return r;
|
|
260 |
}
|
|
261 |
|
20
|
262 |
return(SetName(&KPluginSamplerName));
|
|
263 |
}
|
|
264 |
|
|
265 |
void DGeneralsProfilerFactory::GetCaps(TDes8& aDes) const
|
|
266 |
{
|
|
267 |
TCapsSamplerV01 b;
|
|
268 |
|
|
269 |
b.iVersion=TVersion(1,0,1);
|
|
270 |
|
|
271 |
aDes.FillZ(aDes.MaxLength());
|
|
272 |
aDes.Copy((TUint8*)&b,Min(aDes.MaxLength(),sizeof(b)));
|
|
273 |
}
|
|
274 |
|
|
275 |
/*
|
|
276 |
*
|
|
277 |
*
|
|
278 |
* Class DGeneralsDriver implementation
|
|
279 |
*
|
|
280 |
*
|
|
281 |
*/
|
|
282 |
|
|
283 |
DGeneralsDriver::DGeneralsDriver() :
|
|
284 |
iTimer(NewDoProfilerProfile,this),
|
|
285 |
iNewDfc(NewDoDfc,this,NULL,7),
|
|
286 |
#ifdef __SMP__
|
|
287 |
gppSampler(0),
|
|
288 |
gppSampler2(1),
|
|
289 |
gppSampler3(2),
|
|
290 |
gppSampler4(3),
|
|
291 |
#endif
|
|
292 |
gfcSampler(gppSampler.GetExportData()),
|
|
293 |
ittSampler(gppSampler.GetExportData()),
|
|
294 |
memSampler(gppSampler.GetExportData(), PROFILER_MEM_SAMPLER_ID),
|
|
295 |
priSampler(gppSampler.GetExportData(), PROFILER_PRI_SAMPLER_ID)
|
|
296 |
#ifdef __SMP__
|
|
297 |
// ,priSampler2(gppSampler.GetExportData(), PROFILER_PRI_SAMPLER_ID),
|
|
298 |
// priSampler3(gppSampler.GetExportData(), PROFILER_PRI_SAMPLER_ID),
|
|
299 |
// priSampler4(gppSampler.GetExportData(), PROFILER_PRI_SAMPLER_ID)
|
|
300 |
#endif
|
|
301 |
{
|
|
302 |
LOGSTRING("DGeneralsDriver::DGeneralsDriver()");
|
|
303 |
|
|
304 |
iState = EStopped;
|
|
305 |
iEndRequestStatus = 0;
|
|
306 |
doingDfc = 0;
|
|
307 |
sampleRunning = 0;
|
|
308 |
iSyncOffset = 0;
|
|
309 |
iStartTime = 0;
|
62
|
310 |
postSampleNeeded = 0;
|
20
|
311 |
InitialiseSamplerList();
|
|
312 |
}
|
|
313 |
|
|
314 |
/*
|
|
315 |
*
|
|
316 |
* This method has to be changed for each new sampler
|
|
317 |
*
|
|
318 |
*/
|
|
319 |
void DGeneralsDriver::InitialiseSamplerList()
|
|
320 |
{
|
|
321 |
// initialize all samplers to zero
|
|
322 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
323 |
{
|
|
324 |
iSamplers[i] = 0;
|
|
325 |
}
|
|
326 |
|
|
327 |
TInt i(0);
|
|
328 |
iSamplers[i] = &gppSampler;i++;
|
|
329 |
#ifdef __SMP__
|
|
330 |
iSamplers[i] = &gppSampler2;i++;
|
|
331 |
iSamplers[i] = &gppSampler3;i++;
|
|
332 |
iSamplers[i] = &gppSampler4;i++;
|
|
333 |
#endif
|
|
334 |
iSamplers[i] = &gfcSampler;i++;
|
|
335 |
iSamplers[i] = &ittSampler;i++;
|
|
336 |
iSamplers[i] = &memSampler;i++;
|
|
337 |
iSamplers[i] = &priSampler;i++;
|
|
338 |
|
|
339 |
#ifdef __SMP__
|
|
340 |
// get the number of cpus
|
|
341 |
iMaxCpus = NKern::NumberOfCpus();
|
62
|
342 |
for(TInt nCpu(0); nCpu < iMaxCpus; nCpu++)
|
|
343 |
{
|
|
344 |
iInterruptCounter[nCpu] = 0;
|
|
345 |
}
|
|
346 |
|
20
|
347 |
#else
|
|
348 |
iMaxCpus = 0;
|
|
349 |
#endif
|
|
350 |
|
|
351 |
// initialize synchronizing property
|
|
352 |
LOGSTRING("DGeneralsDriver::InitialiseSamplerList() - initializing property");
|
|
353 |
TInt r(iSampleStartTimeProp.Attach(KGppPropertyCat, EGppPropertySyncSampleNumber));
|
|
354 |
if (r!=KErrNone)
|
|
355 |
{
|
62
|
356 |
Kern::Printf("DGeneralsDriver::InitialiseSamplerList() - error in attaching counter property, error %d", r);
|
20
|
357 |
}
|
|
358 |
LOGSTRING("DGeneralsDriver::InitialiseSamplerList() - defining properties");
|
|
359 |
r = iSampleStartTimeProp.Define(RProperty::EInt, KAllowAllPolicy, KDenyAllPolicy, 0, NULL);
|
|
360 |
if (r!=KErrNone)
|
|
361 |
{
|
62
|
362 |
Kern::Printf("DGeneralsDriver::InitialiseSamplerList() - error in defining counter property, error %d", r);
|
|
363 |
}
|
20
|
364 |
}
|
|
365 |
|
|
366 |
|
|
367 |
DProfilerSamplerBase* DGeneralsDriver::GetSamplerForId(TInt samplerIdToGet)
|
|
368 |
{
|
|
369 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
370 |
{
|
|
371 |
if(iSamplers[i]->iSamplerId == samplerIdToGet)
|
|
372 |
{
|
|
373 |
return iSamplers[i];
|
|
374 |
}
|
|
375 |
}
|
|
376 |
return (DProfilerSamplerBase*)0;
|
|
377 |
}
|
|
378 |
|
|
379 |
TInt DGeneralsDriver::DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer)
|
|
380 |
{
|
|
381 |
TUint8 err(KErrNone);
|
62
|
382 |
LOGSTRING("DGeneralsDriver::DoCreate()");
|
20
|
383 |
if (!Kern::QueryVersionSupported(TVersion(1,0,1),aVer))
|
|
384 |
return KErrNotSupported;
|
|
385 |
|
|
386 |
// just for testing
|
|
387 |
#ifndef __SMP__
|
|
388 |
LOGTEXT("Initializing the stack pointer");
|
|
389 |
stackTop=(TUint32*)IntStackPtr();
|
|
390 |
LOGSTRING2("Got stack pointer 0x%x",(TUint32)stackTop);
|
|
391 |
#endif
|
|
392 |
|
|
393 |
iClient = &Kern::CurrentThread();
|
|
394 |
err = iClient->Open();
|
|
395 |
|
|
396 |
DProcess* clientProcess(iClient->iOwningProcess);
|
|
397 |
if (clientProcess)
|
|
398 |
{
|
|
399 |
//Require Power Management and All Files to use this driver
|
|
400 |
// Not ideal, but better than nothing
|
|
401 |
if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by GeneralsDriver.ldd")))
|
62
|
402 |
{
|
|
403 |
Kern::Printf("DGeneralsDriver::CurrentThreadHasCapability - denied");
|
20
|
404 |
return KErrPermissionDenied;
|
62
|
405 |
}
|
20
|
406 |
if(!Kern::CurrentThreadHasCapability(ECapabilityAllFiles,__PLATSEC_DIAGNOSTIC_STRING("Checked by GeneralsDriver.ldd")))
|
62
|
407 |
{
|
|
408 |
Kern::Printf("DGeneralsDriver::CurrentThreadHasCapability - denied");
|
|
409 |
return KErrPermissionDenied;
|
|
410 |
}
|
20
|
411 |
|
|
412 |
SSecurityInfo secureInfo = clientProcess->iS;
|
|
413 |
if (secureInfo.iSecureId != KProfilerExeSecurUid)
|
|
414 |
{
|
62
|
415 |
Kern::Printf("DGeneralsDriver::security - denied");
|
20
|
416 |
return KErrPermissionDenied;
|
|
417 |
}
|
|
418 |
}
|
|
419 |
|
|
420 |
// initiate sample stream ready for collecting the trace data
|
|
421 |
iSampleStream.InsertCurrentClient(iClient);
|
|
422 |
|
|
423 |
iTimer.Cancel();
|
|
424 |
iNewDfc.Cancel();
|
|
425 |
|
62
|
426 |
Kern::SetThreadPriority(KGeneralsDriverThreadPriority);
|
20
|
427 |
|
62
|
428 |
SetDfcQ(gDfcQ);
|
|
429 |
iNewDfc.SetDfcQ(iDfcQ);
|
|
430 |
iMsgQ.Receive();
|
|
431 |
|
|
432 |
// create the power handler
|
|
433 |
iPowerHandler = new DSamplerPowerHandler(this);
|
|
434 |
if (!iPowerHandler)
|
20
|
435 |
{
|
62
|
436 |
Kern::Printf("DGeneralsDriver::DoCreate() : new DSamplerPowerHandler(this) failed");
|
|
437 |
return KErrNoMemory;
|
20
|
438 |
}
|
62
|
439 |
iPowerHandler->Add();
|
20
|
440 |
return err;
|
|
441 |
}
|
|
442 |
|
|
443 |
DGeneralsDriver::~DGeneralsDriver()
|
|
444 |
{
|
|
445 |
if (iState!=EStopped)
|
|
446 |
iTimer.Cancel();
|
|
447 |
iNewDfc.Cancel();
|
|
448 |
|
|
449 |
iSampleStartTimeProp.Close();
|
|
450 |
Kern::SafeClose((DObject*&)iClient,NULL);
|
|
451 |
}
|
|
452 |
|
|
453 |
|
|
454 |
TInt DGeneralsDriver::GetSampleTime(TUint32* time)
|
|
455 |
{
|
|
456 |
LOGSTRING("DGeneralsDriver::GetSampleTime - entry");
|
|
457 |
|
|
458 |
Kern::ThreadRawWrite( iClient,(TAny*)time,
|
|
459 |
(TAny*)&gppSampler.GetExportData()->sampleNumber,
|
|
460 |
4, iClient);
|
|
461 |
|
|
462 |
LOGSTRING("DGeneralsDriver::GetSampleTime - exit");
|
|
463 |
|
|
464 |
return KErrNone;
|
|
465 |
}
|
|
466 |
|
|
467 |
|
|
468 |
TInt DGeneralsDriver::GetSamplerVersion(TDes* aDes)
|
|
469 |
{
|
|
470 |
LOGSTRING2("DGeneralsDriver::GetSamplerVersion - 0x%x",aDes);
|
|
471 |
|
|
472 |
TBuf8<16> aBuf;
|
|
473 |
aBuf.Append(PROFILER_SAMPLER_VERSION);
|
|
474 |
Kern::ThreadDesWrite(iClient,aDes,aBuf,0,KChunkShiftBy0,iClient);
|
|
475 |
LOGSTRING("DGeneralsDriver::GetSamplerVersion - written client descriptor");
|
|
476 |
return KErrNone;
|
|
477 |
}
|
|
478 |
|
|
479 |
TInt DGeneralsDriver::NewStart(TInt aDelay)
|
|
480 |
{
|
|
481 |
LOGSTRING("DGeneralsDriver::NewStart");
|
|
482 |
iEndRequestStatus = 0;
|
|
483 |
|
|
484 |
aDelay = Min(KMaxDelay, Max(KMinDelay, aDelay));
|
|
485 |
|
|
486 |
// always use this rate
|
|
487 |
iPeriod = aDelay;
|
|
488 |
|
|
489 |
#ifdef __SMP__
|
|
490 |
/*
|
62
|
491 |
* Bind and enable the sampling interrupts
|
20
|
492 |
*/
|
|
493 |
TInt err(0);
|
62
|
494 |
TUint32 flags(NKern::EIrqBind_Count);
|
|
495 |
TInt noofCpu(NKern::NumberOfCpus());
|
20
|
496 |
|
62
|
497 |
//Binding to the interrupt(s)
|
|
498 |
for( TInt nCpu(0); nCpu < noofCpu; nCpu++ )
|
|
499 |
{
|
|
500 |
LOGSTRING3(" > Interrupt::InterruptBind %d + %d - 32", iIntNo, nCpu );
|
|
501 |
err = NKern::InterruptBind( (iIntNo + nCpu - 32) , DGeneralsDriver::Sample, this, flags, 0);
|
|
502 |
if(err < 0)
|
|
503 |
{
|
|
504 |
Kern::Printf(" InterruptBind %d + %d - 32 Error = 0x%x", iIntNo, nCpu, err );
|
|
505 |
return err;
|
|
506 |
}
|
|
507 |
}
|
|
508 |
|
|
509 |
//Enabling Interrupt(s)
|
|
510 |
for( TInt nCpu(0); nCpu < noofCpu; nCpu++ )
|
|
511 |
{
|
|
512 |
LOGSTRING3(" > NKern::InterruptEnable %d + %d - 32", iIntNo, nCpu );
|
|
513 |
err = NKern::InterruptEnable(iIntNo + nCpu - 32);
|
|
514 |
if(err < 0)
|
|
515 |
{
|
|
516 |
Kern::Printf(" InterruptEnable %d + %d - 32 ret = 0x%x", iIntNo, nCpu, err );
|
|
517 |
return err;
|
|
518 |
}
|
|
519 |
|
|
520 |
/* For Bridge we enable one single interrupt for CPU 1 */
|
|
521 |
if(iPlatform == EBridge)
|
|
522 |
break;
|
|
523 |
}
|
20
|
524 |
|
|
525 |
#endif
|
|
526 |
|
|
527 |
iTimer.OneShot(aDelay);
|
|
528 |
|
|
529 |
iState = ERunning;
|
|
530 |
|
|
531 |
return KErrNone;
|
|
532 |
}
|
|
533 |
|
62
|
534 |
void DGeneralsDriver::IncrementSampleNeededState(TInt aId)
|
|
535 |
{
|
|
536 |
LOGSTRING2("DGeneralsDriver::IncrementSampleNeededState() - incrementing sample needed state, caller id: %d", (aId+1));
|
|
537 |
#ifdef __SMP__
|
|
538 |
TInt intState(0);
|
|
539 |
intState = __SPIN_LOCK_IRQSAVE(PiSpinLock);
|
|
540 |
#endif
|
|
541 |
postSampleNeeded++;
|
|
542 |
#ifdef __SMP__
|
|
543 |
__SPIN_UNLOCK_IRQRESTORE(PiSpinLock, intState);
|
|
544 |
#endif
|
|
545 |
}
|
|
546 |
|
|
547 |
void DGeneralsDriver::DecrementSampleNeededState()
|
|
548 |
{
|
|
549 |
LOGSTRING("DGeneralsDriver::DecrementSampleNeededState() - decrementing sample needed state");
|
|
550 |
#ifdef __SMP__
|
|
551 |
TInt intState(0);
|
|
552 |
intState = __SPIN_LOCK_IRQSAVE(PiSpinLock);
|
|
553 |
#endif
|
|
554 |
postSampleNeeded--;
|
|
555 |
#ifdef __SMP__
|
|
556 |
__SPIN_UNLOCK_IRQRESTORE(PiSpinLock, intState);
|
|
557 |
#endif
|
|
558 |
}
|
|
559 |
|
|
560 |
|
20
|
561 |
/*
|
|
562 |
* This function is run in each interrupt
|
|
563 |
*/
|
|
564 |
// EKA-2 implementation of the sampler method
|
|
565 |
|
|
566 |
void DGeneralsDriver::NewDoProfilerProfile(TAny* aPtr)
|
|
567 |
{
|
|
568 |
LOGSTRING("DGeneralsDriver::NewDoProfilerProfile - entry");
|
62
|
569 |
DGeneralsDriver& d=*(DGeneralsDriver*)aPtr;
|
20
|
570 |
#ifdef __SMP__
|
|
571 |
TInt currCpu(NKern::CurrentCpu());
|
|
572 |
#endif
|
62
|
573 |
|
|
574 |
if(!d.iOff)
|
|
575 |
{
|
|
576 |
if (d.iState == ERunning && d.sampleRunning == 0)
|
|
577 |
{
|
|
578 |
// start timer again
|
|
579 |
d.iTimer.Again(d.iPeriod);
|
|
580 |
d.sampleRunning++;
|
|
581 |
|
|
582 |
#ifdef __SMP__
|
|
583 |
// print out the sample tick
|
|
584 |
if(d.gppSampler.GetExportData()->sampleNumber% 1000 == 0)
|
|
585 |
{
|
|
586 |
Kern::Printf(("PIPROF SAMPLE TICK, #%d"), d.gppSampler.GetExportData()->sampleNumber);
|
|
587 |
}
|
|
588 |
|
|
589 |
// call the actual CPU sampling function for CPU 0 (in NaviEngine), later may be on any of the CPUs
|
|
590 |
Sample(aPtr);
|
|
591 |
|
|
592 |
/*
|
|
593 |
This is the master sampler from the watchdog timer, so
|
|
594 |
send interrupts to the other CPU(s)
|
|
595 |
*/
|
|
596 |
TScheduler *theSched = TScheduler::Ptr();
|
|
597 |
// GicDistributor* gicDist = (GicDistributor* )theSched->i_GicDistAddr;
|
|
598 |
GicDistributor* gicDist = (GicDistributor* )(theSched->iSX.iGicDistAddr);
|
|
599 |
|
|
600 |
// post-sampling for NTimer interrupted CPU
|
|
601 |
//d.postSampleNeeded += d.iSamplers[currCpu]->PostSampleNeeded();
|
|
602 |
|
|
603 |
if (d.iPlatform == EBridge)
|
|
604 |
{
|
|
605 |
/* The Interrupt ID is hardcoded for Bridge to be 108/117, using SPI on ARM GIC
|
|
606 |
* Programming the GIC Distributor Set-Pending Register to raise an interrupt
|
|
607 |
* Programming the GIC Distributor Target Register to set an interrupt in CPU 1
|
|
608 |
*/
|
|
609 |
|
|
610 |
/* Interrupt Processor Targets Registers (ICDIPTRn)
|
|
611 |
* target register ICDIPTR number, M, is given by M = N DIV 4
|
|
612 |
* so M is 27 for N = 108/117
|
|
613 |
* NTimer interrupt is always defaulted to CPU 0 so we have to interrupt CPU 1
|
|
614 |
* setting 0bxxxxxx1x CPU interface 1
|
|
615 |
*/
|
|
616 |
// gicDist->iTarget[27] |= 0x00000002;
|
|
617 |
// gicDist->iTarget[27] &= 0xFE;
|
|
618 |
gicDist->iTarget[29] |= 0x00000200;
|
|
619 |
gicDist->iTarget[29] &= 0xFFFFFEFF;
|
20
|
620 |
|
62
|
621 |
/* Interrupt Set-Pending Registers (ICDISPRn)
|
|
622 |
* the corresponding ICDISPR number, M, is given by M = N DIV 32
|
|
623 |
* M = 3 for N being 108/117
|
|
624 |
* the bit number of the required Set-pending bit in this register is N MOD 32
|
|
625 |
* which in this case is 12
|
|
626 |
*/
|
|
627 |
// gicDist->iPendingSet[3] = 1<<((12)); // N = 108
|
|
628 |
gicDist->iPendingSet[3] = 1<<((21)); // N = 117
|
|
629 |
|
|
630 |
arm_dsb();
|
|
631 |
|
|
632 |
}
|
|
633 |
else if (d.iPlatform == ENaviengine) //naviengine platform
|
|
634 |
{
|
|
635 |
for( TInt nCpu(0); nCpu < NKern::NumberOfCpus(); nCpu++ )
|
|
636 |
{
|
|
637 |
if( nCpu != currCpu )
|
|
638 |
{
|
|
639 |
//Kern::Printf(("DProfile::TimerSampleIsr() > iSoftIrq: to cpu%d, 0x%08X"), nCpu, ( 0x10000 << nCpu ) | (d.iIntNo + nCpu));
|
|
640 |
gicDist->iSoftIrq = ( 0x10000 << nCpu ) | (d.iIntNo + nCpu);
|
|
641 |
}
|
|
642 |
// post-sampling for CPUs with specifically generated interrupts
|
|
643 |
//d.postSampleNeeded += d.iSamplers[nCpu]->PostSampleNeeded();
|
|
644 |
}
|
|
645 |
arm_dsb();
|
|
646 |
|
|
647 |
}
|
|
648 |
else
|
|
649 |
{
|
|
650 |
Kern::Printf("DGeneralsDriver::NewDoProfilerProfile - SMP Platform not recognised " );
|
|
651 |
}
|
|
652 |
|
|
653 |
#endif
|
|
654 |
// then sample the rest of non-cpu samplers
|
|
655 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
656 |
{
|
|
657 |
if(d.iSamplers[i]->iEnabled)
|
|
658 |
{
|
|
659 |
d.iSamplers[i]->Sample(aPtr);
|
|
660 |
if(d.iSamplers[i]->PostSampleNeeded())
|
|
661 |
{
|
|
662 |
d.IncrementSampleNeededState(i);
|
|
663 |
}
|
|
664 |
}
|
|
665 |
}
|
|
666 |
|
|
667 |
// // check if post sampling is needed for samplers
|
|
668 |
// for(TInt i(0);i<KSamplerAmount;i++)
|
|
669 |
// {
|
|
670 |
// if(d.iSamplers[i]->iEnabled)
|
|
671 |
// {
|
|
672 |
// if(d.iSamplers[i]->PostSampleNeeded())
|
|
673 |
// {
|
|
674 |
// d.IncrementSampleNeededState(i);
|
|
675 |
// }
|
|
676 |
// }
|
|
677 |
// }
|
|
678 |
|
|
679 |
if(d.postSampleNeeded > 0 && d.doingDfc == 0)
|
|
680 |
//if(d.postSampleNeeded > 0)
|
|
681 |
{
|
|
682 |
LOGSTRING2("DGeneralsDriver::NewDoProfilerProfile - postSampleNeeded count %d ", d.postSampleNeeded );
|
|
683 |
d.doingDfc++;
|
|
684 |
d.iNewDfc.Add();
|
20
|
685 |
|
62
|
686 |
d.sampleRunning--;
|
20
|
687 |
|
62
|
688 |
return;
|
|
689 |
}
|
|
690 |
d.sampleRunning--;
|
|
691 |
} // if (d.iState == ERunning && d.sampleRunning == 0)
|
|
692 |
else if (d.iState == EStopping && d.sampleRunning == 0)
|
20
|
693 |
{
|
62
|
694 |
// add a dfc for this final time
|
|
695 |
d.iNewDfc.Add();
|
|
696 |
LOGSTRING("DGeneralsDriver::NewDoProfilerProfile - sampling added to dfc queue");
|
20
|
697 |
}
|
62
|
698 |
else
|
20
|
699 |
{
|
62
|
700 |
// the previous sample has not finished,
|
|
701 |
Kern::Printf("DGeneralsDriver::NewDoProfilerProfile - Profiler Sampler Error - interrupted before finished sampling!!");
|
20
|
702 |
}
|
62
|
703 |
LOGSTRING("DGeneralsDriver::NewDoProfilerProfile - exit");
|
|
704 |
} // iOff
|
|
705 |
else
|
|
706 |
{
|
|
707 |
Kern::Printf("DGeneralsDriver::iOff");
|
20
|
708 |
}
|
62
|
709 |
}
|
20
|
710 |
|
|
711 |
|
|
712 |
void DGeneralsDriver::Sample(TAny* aPtr)
|
|
713 |
{
|
|
714 |
LOGSTRING("DGeneralsDriver::Sample - entry");
|
|
715 |
|
|
716 |
#ifdef __SMP__
|
|
717 |
DGeneralsDriver& d=*(DGeneralsDriver*)aPtr;
|
|
718 |
|
62
|
719 |
TInt currCpu(NKern::CurrentCpu());
|
|
720 |
++d.iInterruptCounter[currCpu];
|
20
|
721 |
|
62
|
722 |
d.iSamplers[currCpu]->Sample(aPtr);
|
20
|
723 |
#endif
|
|
724 |
LOGSTRING("DGeneralsDriver::Sample - exit");
|
|
725 |
}
|
62
|
726 |
|
20
|
727 |
/*
|
|
728 |
* This function is run when any of the samplers
|
|
729 |
* requires post sampling
|
|
730 |
*/
|
|
731 |
void DGeneralsDriver::NewDoDfc(TAny* pointer)
|
|
732 |
{
|
|
733 |
DGeneralsDriver& d(*((DGeneralsDriver*)pointer));
|
|
734 |
|
|
735 |
if(d.iState == ERunning)
|
|
736 |
{
|
|
737 |
// for all enabled samplers, perform
|
|
738 |
// post sample if needed
|
|
739 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
740 |
{
|
|
741 |
if(d.iSamplers[i]->iEnabled)
|
|
742 |
{
|
|
743 |
if(d.iSamplers[i]->PostSampleNeeded())
|
|
744 |
{
|
62
|
745 |
LOGSTRING3("DGeneralsDriver::NewDoDfc iSamplers[%d] PostSampleNeeded count %d", i, d.postSampleNeeded);
|
|
746 |
d.iSamplers[i]->PostSample();
|
|
747 |
d.DecrementSampleNeededState();
|
|
748 |
LOGSTRING3("DGeneralsDriver::NewDoDfc iSamplers[%d] PostSampleNeeded count %d", i, d.postSampleNeeded);
|
20
|
749 |
}
|
|
750 |
}
|
|
751 |
}
|
|
752 |
d.doingDfc--;
|
|
753 |
}
|
|
754 |
|
|
755 |
else if(d.iState == EStopping)
|
|
756 |
{
|
62
|
757 |
LOGSTRING("DGeneralsDriver::NewDoDfc state Stopping()");
|
20
|
758 |
// for all enabled samplers,
|
|
759 |
// perform end sampling
|
|
760 |
TBool releaseBuffer(false);
|
|
761 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
762 |
{
|
|
763 |
if(d.iSamplers[i]->iEnabled)
|
|
764 |
{
|
62
|
765 |
LOGSTRING("DGeneralsDriver::NewDoDfc() - ending");
|
|
766 |
if(d.iSamplers[i]->PostSampleNeeded())
|
|
767 |
{
|
|
768 |
LOGSTRING2("DGeneralsDriver::NewDoDfc iSamplers[%d] PostSampleNeeded still", i);
|
|
769 |
d.iSamplers[i]->PostSample();
|
|
770 |
}
|
20
|
771 |
// perform end sampling for all samplers
|
|
772 |
// stream mode samplers may be pending, if they
|
|
773 |
// are still waiting for another client buffer
|
|
774 |
if(d.iSamplers[i]->EndSampling() == KErrNotReady)
|
|
775 |
{
|
62
|
776 |
LOGSTRING("DGeneralsDriver::NewDoDfc() - stream data pending");
|
20
|
777 |
releaseBuffer = true;
|
|
778 |
}
|
|
779 |
else
|
|
780 |
{
|
62
|
781 |
LOGSTRING("DGeneralsDriver::NewDoDfc() - no data pending");
|
20
|
782 |
releaseBuffer = true;
|
|
783 |
}
|
|
784 |
}
|
|
785 |
}
|
|
786 |
|
|
787 |
// At the end, once all the samplers are gone through, the buffer should be released
|
|
788 |
if (true == releaseBuffer)
|
|
789 |
{
|
62
|
790 |
LOGSTRING("DGeneralsDriver::NewDoDfc() - release the buffer");
|
20
|
791 |
d.iSampleStream.ReleaseIfPending();
|
|
792 |
}
|
|
793 |
|
|
794 |
d.iState = EStopped;
|
|
795 |
if(d.iEndRequestStatus != 0 && d.iClient != 0)
|
|
796 |
{
|
|
797 |
// sampling has ended
|
|
798 |
Kern::RequestComplete(d.iClient,d.iEndRequestStatus,KErrNone);
|
62
|
799 |
LOGSTRING("DGeneralsDriver::NewDoDfc() - request complete, stopped");
|
20
|
800 |
}
|
|
801 |
}
|
|
802 |
}
|
|
803 |
|
|
804 |
|
|
805 |
/*
|
|
806 |
* All controls are handled here
|
|
807 |
*/
|
|
808 |
|
|
809 |
void DGeneralsDriver::HandleMsg(TMessageBase* aMsg)
|
|
810 |
{
|
|
811 |
TInt r(KErrNone);
|
|
812 |
TThreadMessage& m(*(TThreadMessage*)aMsg);
|
|
813 |
|
|
814 |
LOGSTRING5("DGeneralsDriver::HandleMsg 0x%x 0x%x 0x%x 0x%x",m.Int0(),m.Int1(),m.Int2(),m.Int3());
|
|
815 |
|
|
816 |
if(m.iValue == (TInt)ECloseMsg)
|
|
817 |
{
|
|
818 |
LOGSTRING("DGeneralsDriver::HandleMsg - received close message");
|
|
819 |
iTimer.Cancel();
|
|
820 |
iNewDfc.Cancel();
|
|
821 |
|
|
822 |
m.Complete(KErrNone,EFalse);
|
|
823 |
iMsgQ.CompleteAll(KErrServerTerminated);
|
|
824 |
LOGSTRING("DGeneralsDriver::HandleMsg - cleaned up the driver!");
|
|
825 |
return;
|
|
826 |
}
|
|
827 |
|
|
828 |
if (m.Client()!=iClient)
|
|
829 |
{
|
|
830 |
LOGSTRING("DGeneralsDriver::HandleMsg - ERROR, wrong client");
|
|
831 |
m.PanicClient(_L("GENERALSSAMPLER"),EAccessDenied);
|
|
832 |
return;
|
|
833 |
}
|
|
834 |
|
|
835 |
TInt id(m.iValue);
|
|
836 |
switch(id)
|
|
837 |
{
|
|
838 |
//Controls are handled here
|
|
839 |
case RPluginSampler::EMarkTraceActive:
|
|
840 |
LOGSTRING("DGeneralsDriver::HandleMsg - EMarkTraceActive");
|
|
841 |
r = MarkTraceActive((TInt)m.Int0());
|
|
842 |
break;
|
|
843 |
|
|
844 |
case RPluginSampler::EOutputSettingsForTrace:
|
|
845 |
LOGSTRING("DGeneralsDriver::HandleMsg - EOutputSettingsForTrace");
|
|
846 |
r = OutputSettingsForTrace((TInt)m.Int0(),(TInt)m.Int1());
|
|
847 |
break;
|
|
848 |
|
|
849 |
case RPluginSampler::EAdditionalTraceSettings:
|
|
850 |
LOGSTRING("DGeneralsDriver::HandleMsg - EAdditionalTraceSettings");
|
|
851 |
r = AdditionalTraceSettings((TInt)m.Int0(),(TInt)m.Int1());
|
|
852 |
break;
|
|
853 |
|
|
854 |
case RPluginSampler::EAdditionalTraceSettings2:
|
|
855 |
LOGSTRING("DGeneralsDriver::HandleMsg - EAdditionalTraceSettings2");
|
|
856 |
r = AdditionalTraceSettings2((TInt)m.Int0(),(TInt)m.Int1());
|
|
857 |
break;
|
|
858 |
|
|
859 |
case RPluginSampler::ESetSamplingPeriod:
|
|
860 |
LOGSTRING2("DGeneralsDriver::HandleMsg - ESetSamplingPeriod %d", (TInt)m.Int1());
|
|
861 |
r = SetSamplingPeriod((TInt)m.Int0(),(TInt)m.Int1());
|
|
862 |
break;
|
|
863 |
|
|
864 |
case RPluginSampler::EMarkTraceInactive:
|
|
865 |
LOGSTRING("DGeneralsDriver::HandleMsg - EMarkTraceInactive");
|
|
866 |
r = MarkTraceInactive((TInt)m.Int0());
|
|
867 |
break;
|
|
868 |
|
|
869 |
case RPluginSampler::ESample:
|
|
870 |
LOGSTRING("DGeneralsDriver::HandleMsg - ESample");
|
|
871 |
//r = Sample(); // hack. Original implementation of sample just returned 0
|
|
872 |
r = 0;
|
|
873 |
break;
|
|
874 |
|
|
875 |
case RPluginSampler::EStartSampling:
|
62
|
876 |
LOGSTRING("DGeneralsDriver::HandleMsg - EStartSampling");
|
|
877 |
iStarted = (TUint8)ETrue;
|
|
878 |
r=StartSampling(m.Int0(),m.Int1());
|
|
879 |
//r = StartSampling();
|
20
|
880 |
break;
|
|
881 |
|
|
882 |
case RPluginSampler::EGetSampleTime:
|
|
883 |
LOGSTRING("DGeneralsDriver::HandleMsg - EGetSampleTime");
|
|
884 |
r = GetSampleTime(reinterpret_cast<TUint32*>(m.Ptr0()));
|
|
885 |
break;
|
|
886 |
|
|
887 |
case RPluginSampler::EGetSamplerVersion:
|
|
888 |
LOGSTRING("DGeneralsDriver::HandleMsg - EGetSamplerVersion");
|
|
889 |
r = GetSamplerVersion(reinterpret_cast<TDes*>(m.Ptr0()));
|
|
890 |
break;
|
|
891 |
|
|
892 |
case RPluginSampler::ECancelStreamRead:
|
|
893 |
LOGSTRING("DGeneralsDriver::HandleMsg - ECancelStreamRead");
|
|
894 |
iStreamReadCancelStatus = reinterpret_cast<TRequestStatus*>(m.Ptr0());
|
|
895 |
r = ProcessStreamReadCancel();
|
|
896 |
break;
|
|
897 |
|
|
898 |
|
|
899 |
// Requests are handled here
|
|
900 |
|
|
901 |
case ~RPluginSampler::EStopAndWaitForEnd:
|
62
|
902 |
LOGSTRING("DGeneralsDriver::HandleMsg - EStopAndWaitForEnd");
|
20
|
903 |
iEndRequestStatus = reinterpret_cast<TRequestStatus*>(m.Ptr0());
|
|
904 |
r = StopSampling();
|
|
905 |
#ifdef __SMP__
|
|
906 |
UnbindInterrupts();
|
|
907 |
#endif
|
|
908 |
break;
|
|
909 |
|
|
910 |
case ~RPluginSampler::ERequestFillThisStreamBuffer:
|
|
911 |
LOGSTRING("DGeneralsDriver::HandleMsg - ERequestFillThisStreamBuffer");
|
|
912 |
r = ProcessStreamReadRequest( reinterpret_cast<TBapBuf*>(m.Ptr1()),
|
|
913 |
reinterpret_cast<TRequestStatus*>(m.Ptr0()));
|
|
914 |
break;
|
|
915 |
|
|
916 |
default:
|
62
|
917 |
Kern::Printf("DGeneralsDriver::HandleMsg - ERROR, unknown command %d",id);
|
20
|
918 |
r = KErrNotSupported;
|
|
919 |
break;
|
|
920 |
}
|
|
921 |
|
|
922 |
LOGSTRING("DGeneralsDriver::HandleMsg - Completed");
|
|
923 |
m.Complete(r,ETrue);
|
|
924 |
}
|
|
925 |
|
|
926 |
#ifdef __SMP__
|
|
927 |
inline void DGeneralsDriver::UnbindInterrupts()
|
|
928 |
{
|
|
929 |
TInt err(0);
|
62
|
930 |
/*
|
|
931 |
* Disable and unbind the sampling interrupts associated with each core.
|
|
932 |
*/
|
|
933 |
TInt noofCpu(NKern::NumberOfCpus());
|
|
934 |
//Disabling Interrupt(s)
|
|
935 |
for( TInt nCpu(0); nCpu < noofCpu; nCpu++ )
|
|
936 |
{
|
|
937 |
err = NKern::InterruptDisable(iIntNo + nCpu - 32);
|
|
938 |
if(err < 0)
|
|
939 |
{
|
|
940 |
Kern::Printf(" Interrupt Disable iIntNo + %d - 32 ret = %d", nCpu, err );
|
|
941 |
}
|
|
942 |
}
|
|
943 |
|
|
944 |
//UnBinding to the interrupt(s)
|
|
945 |
for( TInt nCpu(0); nCpu < noofCpu; nCpu++ )
|
|
946 |
{
|
|
947 |
LOGSTRING3(" > Interrupt::InterruptUnBind + %d -32 =%d", nCpu, iIntNo + nCpu -32 );
|
|
948 |
err = NKern::InterruptUnbind( (iIntNo + nCpu - 32) );
|
|
949 |
if(err < 0)
|
|
950 |
{
|
|
951 |
Kern::Printf(" InterruptUnBind iIntNo + %d - 32 Error = %d", nCpu, err );
|
|
952 |
}
|
|
953 |
}
|
20
|
954 |
}
|
|
955 |
#endif
|
|
956 |
|
|
957 |
inline TInt DGeneralsDriver::ProcessStreamReadRequest(TBapBuf* aBuf,TRequestStatus* aStatus)
|
|
958 |
{
|
|
959 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest - entry");
|
|
960 |
|
|
961 |
// a new sample buffer has been received from the client
|
|
962 |
iSampleStream.AddSampleBuffer(aBuf,aStatus);
|
|
963 |
|
|
964 |
// check if we are waiting for the last data to be written to the client
|
|
965 |
if(iState == EStopped)
|
|
966 |
{
|
|
967 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest state = EStopped");
|
|
968 |
|
|
969 |
// sampling has stopped and stream read cancel is pending
|
|
970 |
// try to perform the end sampling procedure again
|
|
971 |
TBool releaseBuffer(false);
|
|
972 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
973 |
{
|
|
974 |
// only for all enabled samplers that have stream output mode
|
|
975 |
if(iSamplers[i]->iEnabled /*&& samplers[i]->outputMode == 2*/)
|
|
976 |
{
|
|
977 |
//TInt pending = 0;
|
|
978 |
// stream mode samplers may be pending, if they
|
|
979 |
// are still waiting for another client buffer,
|
|
980 |
// in that case, the request should be completed already
|
|
981 |
if(iSamplers[i]->EndSampling() == KErrNotReady)
|
|
982 |
{
|
62
|
983 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest - still data pending");
|
|
984 |
releaseBuffer = false;
|
20
|
985 |
}
|
|
986 |
else
|
|
987 |
{
|
62
|
988 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest - no data pending");
|
20
|
989 |
releaseBuffer = true;
|
|
990 |
}
|
|
991 |
}
|
|
992 |
}
|
|
993 |
// At the end, once all the samplers are gone through, the buffer should be released
|
|
994 |
if (true == releaseBuffer)
|
|
995 |
{
|
62
|
996 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest - all data copied, release the buffer");
|
20
|
997 |
iSampleStream.ReleaseIfPending();
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
LOGSTRING("DGeneralsDriver::ProcessStreamReadRequest - exit");
|
|
1001 |
|
|
1002 |
return KErrNone;
|
|
1003 |
}
|
|
1004 |
|
|
1005 |
|
|
1006 |
/*
|
|
1007 |
* Mark traces active or inactive, this can be done
|
|
1008 |
* only if sampling is not running
|
|
1009 |
*/
|
|
1010 |
|
|
1011 |
inline TInt DGeneralsDriver::MarkTraceActive(TInt samplerIdToActivate)
|
|
1012 |
{
|
|
1013 |
LOGSTRING2("DGeneralsDriver::MarkTraceActive %d",samplerIdToActivate);
|
|
1014 |
|
|
1015 |
TInt cpus(0);
|
|
1016 |
#ifdef __SMP__
|
|
1017 |
cpus = NKern::NumberOfCpus();
|
|
1018 |
if( samplerIdToActivate == PROFILER_GPP_SAMPLER_ID )
|
|
1019 |
{
|
|
1020 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
62
|
1021 |
{
|
|
1022 |
LOGSTRING2("DGeneralsDriver::MarkTraceActive - activating CPU %d",cpu);
|
|
1023 |
iSamplers[cpu]->SetEnabledFlag(true);
|
|
1024 |
}
|
20
|
1025 |
return KErrNone;
|
|
1026 |
}
|
|
1027 |
#endif
|
|
1028 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1029 |
{
|
|
1030 |
if(iSamplers[i]->iSamplerId == samplerIdToActivate)
|
|
1031 |
{
|
|
1032 |
iSamplers[i]->SetEnabledFlag(true);
|
|
1033 |
return KErrNone;
|
|
1034 |
}
|
|
1035 |
}
|
|
1036 |
|
62
|
1037 |
Kern::Printf("DGeneralsDriver::MarkTraceActive - %d not supported",samplerIdToActivate);
|
20
|
1038 |
return KErrNotSupported;
|
|
1039 |
}
|
|
1040 |
|
|
1041 |
inline TInt DGeneralsDriver::MarkTraceInactive(TInt samplerIdToDisable)
|
|
1042 |
{
|
|
1043 |
LOGSTRING2("DGeneralsDriver::MarkTraceInactive %d",samplerIdToDisable);
|
|
1044 |
|
|
1045 |
TInt cpus(0);
|
|
1046 |
#ifdef __SMP__
|
|
1047 |
cpus = NKern::NumberOfCpus();
|
|
1048 |
if( samplerIdToDisable == PROFILER_GPP_SAMPLER_ID )
|
|
1049 |
{
|
|
1050 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
|
1051 |
{
|
|
1052 |
iSamplers[cpu]->SetEnabledFlag(false);
|
|
1053 |
}
|
|
1054 |
return KErrNone;
|
|
1055 |
}
|
|
1056 |
#endif
|
|
1057 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1058 |
{
|
|
1059 |
if(iSamplers[i]->iSamplerId == samplerIdToDisable)
|
|
1060 |
{
|
|
1061 |
iSamplers[i]->SetEnabledFlag(false);
|
|
1062 |
return KErrNone;
|
|
1063 |
}
|
|
1064 |
}
|
|
1065 |
|
62
|
1066 |
Kern::Printf("DGeneralsDriver::MarkTraceInactive - %d not supported",samplerIdToDisable);
|
20
|
1067 |
return KErrNotSupported;
|
|
1068 |
}
|
|
1069 |
|
|
1070 |
/*
|
|
1071 |
* Set output settings for a trace
|
|
1072 |
*/
|
|
1073 |
|
|
1074 |
inline TInt DGeneralsDriver::OutputSettingsForTrace(TInt samplerId,TInt settings)
|
|
1075 |
{
|
|
1076 |
LOGSTRING3("DGeneralsDriver::OutputSettingsForTrace id:%d set:%d",samplerId,settings);
|
|
1077 |
|
|
1078 |
TInt cpus(0);
|
|
1079 |
#ifdef __SMP__
|
|
1080 |
cpus = NKern::NumberOfCpus();
|
|
1081 |
if( samplerId == PROFILER_GPP_SAMPLER_ID )
|
|
1082 |
{
|
|
1083 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
|
1084 |
{
|
|
1085 |
iSamplers[cpu]->SetOutputCombination(settings);
|
|
1086 |
}
|
|
1087 |
return KErrNone;
|
|
1088 |
}
|
|
1089 |
#endif
|
|
1090 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1091 |
{
|
|
1092 |
if(iSamplers[i]->iSamplerId == samplerId)
|
|
1093 |
{
|
|
1094 |
iSamplers[i]->SetOutputCombination(settings);
|
|
1095 |
return KErrNone;
|
|
1096 |
}
|
|
1097 |
}
|
|
1098 |
|
|
1099 |
return KErrNotSupported;
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
/*
|
|
1103 |
* Set additional settings for a trace
|
|
1104 |
*/
|
|
1105 |
|
|
1106 |
inline TInt DGeneralsDriver::AdditionalTraceSettings(TInt samplerId,TInt settings)
|
|
1107 |
{
|
|
1108 |
LOGSTRING3("DGeneralsDriver::SetAdditionalTraceSettings id:%d set:%d",samplerId,settings);
|
|
1109 |
|
|
1110 |
TInt cpus(0);
|
|
1111 |
#ifdef __SMP__
|
|
1112 |
cpus = NKern::NumberOfCpus();
|
|
1113 |
if( samplerId == PROFILER_GPP_SAMPLER_ID )
|
|
1114 |
{
|
|
1115 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
|
1116 |
{
|
|
1117 |
iSamplers[cpu]->SetAdditionalSettings(settings);
|
|
1118 |
}
|
|
1119 |
return KErrNone;
|
|
1120 |
}
|
|
1121 |
#endif
|
|
1122 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1123 |
{
|
|
1124 |
if(iSamplers[i]->iSamplerId == samplerId)
|
|
1125 |
{
|
|
1126 |
iSamplers[i]->SetAdditionalSettings(settings);
|
|
1127 |
return KErrNone;
|
|
1128 |
}
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
return KErrNotSupported;
|
|
1132 |
}
|
|
1133 |
|
|
1134 |
inline TInt DGeneralsDriver::AdditionalTraceSettings2(TInt samplerId,TInt settings)
|
|
1135 |
{
|
|
1136 |
LOGSTRING3("DGeneralsDriver::SetAdditionalTraceSettings id:%d set:%d",samplerId,settings);
|
|
1137 |
|
|
1138 |
TInt cpus(0);
|
|
1139 |
#ifdef __SMP__
|
|
1140 |
cpus = NKern::NumberOfCpus();
|
|
1141 |
if( samplerId == PROFILER_GPP_SAMPLER_ID )
|
|
1142 |
{
|
|
1143 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
|
1144 |
{
|
|
1145 |
iSamplers[cpu]->SetAdditionalSettings2(settings);
|
|
1146 |
}
|
|
1147 |
return KErrNone;
|
|
1148 |
}
|
|
1149 |
#endif
|
|
1150 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1151 |
{
|
|
1152 |
if(iSamplers[i]->iSamplerId == samplerId)
|
|
1153 |
{
|
|
1154 |
iSamplers[i]->SetAdditionalSettings2(settings);
|
|
1155 |
return KErrNone;
|
|
1156 |
}
|
|
1157 |
}
|
|
1158 |
|
|
1159 |
return KErrNotSupported;
|
|
1160 |
}
|
|
1161 |
|
|
1162 |
inline TInt DGeneralsDriver::SetSamplingPeriod(TInt samplerId,TInt settings)
|
|
1163 |
{
|
|
1164 |
LOGSTRING2("DGeneralsDriver::SetSamplingPeriod - set:%d",settings);
|
|
1165 |
|
|
1166 |
TInt cpus(0);
|
|
1167 |
#ifdef __SMP__
|
|
1168 |
cpus = NKern::NumberOfCpus();
|
|
1169 |
if( samplerId == PROFILER_GPP_SAMPLER_ID )
|
|
1170 |
{
|
|
1171 |
for(TInt cpu(0);cpu<cpus;cpu++)
|
|
1172 |
{
|
|
1173 |
iSamplers[cpu]->SetSamplingPeriod(settings);
|
|
1174 |
}
|
|
1175 |
return KErrNone;
|
|
1176 |
}
|
|
1177 |
#endif
|
|
1178 |
for(TInt i(cpus);i<KSamplerAmount;i++)
|
|
1179 |
{
|
|
1180 |
if(iSamplers[i]->iSamplerId == samplerId)
|
|
1181 |
{
|
|
1182 |
iSamplers[i]->SetSamplingPeriod(settings);
|
|
1183 |
return KErrNone;
|
|
1184 |
}
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
return KErrNotSupported;
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
/*
|
|
1191 |
* Mark traces active or inactive, this can be done
|
|
1192 |
* only if sampling is not running
|
|
1193 |
*/
|
|
1194 |
|
62
|
1195 |
TInt DGeneralsDriver::StartSampling(TInt aRate, TInt aInterruptNumber)
|
20
|
1196 |
{
|
|
1197 |
LOGSTRING("DGeneralsDriver::StartSampling");
|
|
1198 |
|
|
1199 |
if(iState == EStopped)
|
|
1200 |
{
|
|
1201 |
// reset iSampleStartTimeProp property value
|
|
1202 |
iSampleStartTime = NKern::TickCount(); // get the system tick value for sync purposes
|
|
1203 |
#ifdef __SMP__
|
62
|
1204 |
TInt err;
|
20
|
1205 |
iStartTime = (iSampleStartTime & 0xfffffff0);
|
|
1206 |
#endif
|
|
1207 |
TInt r(iSampleStartTimeProp.Set(iSampleStartTime));
|
|
1208 |
|
|
1209 |
Kern::Printf(("PIPROF SAMPLE TICK, #0")); // for remote profiling with Profiler Activator
|
|
1210 |
|
|
1211 |
// reset all enabled samplers
|
|
1212 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
1213 |
{
|
|
1214 |
if(iSamplers[i]->iEnabled)
|
|
1215 |
{
|
|
1216 |
// reset with stream option
|
|
1217 |
#ifndef __SMP__
|
62
|
1218 |
LOGSTRING2(("DGeneralsDriver::StartSampling - stream reset for generals driver, sync offset %d"), 0);
|
20
|
1219 |
iSamplers[i]->Reset(&iSampleStream, 0);
|
|
1220 |
#else
|
62
|
1221 |
LOGSTRING2(("DGeneralsDriver::StartSampling - stream reset for generals driver, start time %d"), iStartTime);
|
20
|
1222 |
iSamplers[i]->Reset(&iSampleStream, iStartTime);
|
|
1223 |
#endif
|
|
1224 |
}
|
|
1225 |
}
|
62
|
1226 |
#ifdef __SMP__
|
|
1227 |
iRate = aRate;
|
|
1228 |
iIntNo = aInterruptNumber;
|
|
1229 |
// use HAL to understand the underlying hardware
|
|
1230 |
// not so elegant but used for two SMP pltaforms Bridge and Naviengine
|
|
1231 |
TVariantInfoV01 info;
|
|
1232 |
TPckg<TVariantInfoV01> infoPckg(info);
|
|
1233 |
err = Kern::HalFunction(EHalGroupVariant, EVariantHalVariantInfo, (TAny*)&infoPckg, NULL);
|
|
1234 |
|
|
1235 |
if(err != KErrNone)
|
|
1236 |
{
|
|
1237 |
Kern::Printf("Error in reading HAL Entry EVariantHalVariantInfo %r ", err);
|
|
1238 |
}
|
|
1239 |
if (info.iMachineUniqueId.iData[0] == KBridgeMachineUID)
|
|
1240 |
{
|
|
1241 |
iPlatform = EBridge;
|
|
1242 |
LOGSTRING("DGeneralsDriver::StartSampling() - Bridge HW");
|
|
1243 |
}
|
|
1244 |
else if (info.iMachineUniqueId.iData[0] == KNaviengineMachineUID)
|
|
1245 |
{
|
|
1246 |
iPlatform = ENaviengine;
|
|
1247 |
LOGSTRING("DGeneralsDriver::StartSampling() - NaviEngine HW");
|
|
1248 |
}
|
|
1249 |
else
|
|
1250 |
{
|
|
1251 |
Kern::Printf("DGeneralsDriver::StartSampling() - Unknown HW, 0x%x", info.iMachineUniqueId.iData[0]);
|
|
1252 |
}
|
|
1253 |
|
|
1254 |
//users are restricted to use the default Interrupt Number for Bridge
|
|
1255 |
if ((iPlatform == EBridge) && (aInterruptNumber != KValueZero) && (aInterruptNumber != KBridgeProfilerInterruptId) )
|
|
1256 |
{
|
|
1257 |
Kern::Printf("Invalid Interrupt Number for Bridge used %d interrupt...Please use %d Interrupt Number", iIntNo, KBridgeProfilerInterruptId);
|
|
1258 |
return KErrNotSupported;
|
|
1259 |
}
|
|
1260 |
if (aInterruptNumber == KValueZero)
|
|
1261 |
iIntNo = KDefaultInterruptNumber;
|
|
1262 |
|
|
1263 |
if (iPlatform == EBridge)
|
|
1264 |
/* By default for Bridge we are using KBridgeProfilerInterruptId */
|
|
1265 |
iIntNo = KBridgeProfilerInterruptId;
|
|
1266 |
#endif
|
20
|
1267 |
NewStart(gppSampler.GetPeriod());
|
|
1268 |
return KErrNone;
|
|
1269 |
}
|
|
1270 |
else
|
|
1271 |
{
|
|
1272 |
return KErrGeneral;
|
|
1273 |
}
|
|
1274 |
}
|
|
1275 |
|
|
1276 |
/*
|
|
1277 |
* Mark traces active or inactive, this can be done
|
|
1278 |
* only if sampling is not running
|
|
1279 |
*/
|
|
1280 |
|
|
1281 |
TInt DGeneralsDriver::StopSampling()
|
|
1282 |
{
|
62
|
1283 |
LOGSTRING2("DGeneralsDriver::StopSampling - iState %", iState);
|
|
1284 |
TInt noofCpu(NKern::NumberOfCpus());
|
20
|
1285 |
|
|
1286 |
if(iState == ERunning)
|
|
1287 |
{
|
|
1288 |
this->iState = EStopping;
|
|
1289 |
// reset all enabled samplers
|
|
1290 |
for(TInt i(0);i<KSamplerAmount;i++)
|
|
1291 |
{
|
62
|
1292 |
// do the reset only for memory and itt samplers
|
|
1293 |
if(iSamplers[i]->iEnabled &&
|
|
1294 |
(iSamplers[i]->iSamplerId == PROFILER_ITT_SAMPLER_ID ||
|
|
1295 |
iSamplers[i]->iSamplerId == PROFILER_MEM_SAMPLER_ID ))
|
20
|
1296 |
{
|
|
1297 |
// reset with stream option
|
62
|
1298 |
LOGSTRING(("DGeneralsDriver::StopSampling - stream reset for samplers"));
|
|
1299 |
iSamplers[i]->Reset(&iSampleStream, KStateSamplingEnding);
|
20
|
1300 |
}
|
|
1301 |
}
|
62
|
1302 |
LOGSTRING2("\nDGeneralsDriver::StopSampling - Number of times the Timer counter expired on CPU 0 = %d ", iInterruptCounter[0]);
|
|
1303 |
|
|
1304 |
for(TInt nCpu(1); nCpu < noofCpu; nCpu++)
|
|
1305 |
{
|
|
1306 |
Kern::Printf( "\n Number of times we interrupted CPU[%d] = %d and Number of Missed CPU interrupts = %d", nCpu, iInterruptCounter[nCpu],(iInterruptCounter[0] - iInterruptCounter[nCpu]));
|
|
1307 |
Kern::Printf( "\n Number of times CPU sampler[0] accessed: %d", gppSampler.GetExportData()->sampleNumber);
|
|
1308 |
#ifdef __SMP__
|
|
1309 |
Kern::Printf( "\n Number of times CPU sampler[1] accessed: %d", gppSampler2.GetExportData()->sampleNumber);
|
|
1310 |
#endif
|
|
1311 |
}
|
20
|
1312 |
|
|
1313 |
return KErrNone;
|
|
1314 |
}
|
|
1315 |
else
|
|
1316 |
{
|
|
1317 |
return KErrGeneral;
|
|
1318 |
}
|
|
1319 |
}
|
|
1320 |
|
62
|
1321 |
DSamplerPowerHandler::DSamplerPowerHandler(DGeneralsDriver* aChannel)
|
|
1322 |
: DPowerHandler(KPluginSamplerName),
|
|
1323 |
iChannel(aChannel)
|
|
1324 |
{
|
|
1325 |
LOGSTRING("DSamplerPowerHandler::DSamplerPowerHandler\n");
|
|
1326 |
}
|
|
1327 |
|
|
1328 |
void DSamplerPowerHandler::PowerUp()
|
|
1329 |
{
|
|
1330 |
LOGSTRING("DSamplerPowerHandler::PowerUp()1\n");
|
|
1331 |
iChannel->iOff = (TUint8)EFalse;
|
|
1332 |
if (iChannel->iStarted)
|
|
1333 |
{
|
|
1334 |
LOGSTRING("DSamplerPowerHandler::PowerUp()2\n");
|
|
1335 |
iChannel->StartSampling(iChannel->iRate, iChannel->iIntNo);
|
|
1336 |
}
|
|
1337 |
PowerUpDone();
|
|
1338 |
}
|
|
1339 |
|
|
1340 |
void DSamplerPowerHandler::PowerDown(TPowerState)
|
|
1341 |
{
|
|
1342 |
LOGSTRING("DSamplerPowerHandler::PowerDown()\n");
|
|
1343 |
iChannel->iOff = (TUint8)ETrue;
|
|
1344 |
//iChannel->iState = EStopped;
|
|
1345 |
iChannel->StopSampling();
|
|
1346 |
PowerDownDone();
|
|
1347 |
}
|
20
|
1348 |
|