os/kernelhwsrv/kerneltest/e32test/realtime/t_latncy.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\realtime\t_latncy.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32svr.h>
sl@0
    20
sl@0
    21
LOCAL_D RTest test(_L("Latency"));
sl@0
    22
LOCAL_D CConsoleBase* console=NULL;
sl@0
    23
sl@0
    24
struct SLatencyValues
sl@0
    25
	{
sl@0
    26
	TUint iAddress;
sl@0
    27
	TUint iLatencies;
sl@0
    28
	TUint iThreadIds;
sl@0
    29
	TUint iSwi;
sl@0
    30
	};
sl@0
    31
sl@0
    32
struct SMaxLatencyValues
sl@0
    33
	{
sl@0
    34
	TInt iMaxIntLatency;
sl@0
    35
	TUint iMaxIntLatencyRetAddr;
sl@0
    36
	TInt iMaxThreadLatency;
sl@0
    37
	TUint iMaxThreadLatencyRetAddr;
sl@0
    38
	};
sl@0
    39
sl@0
    40
extern void GetLatencyValues(TInt, TInt&, SLatencyValues*);
sl@0
    41
sl@0
    42
inline TInt* NullTIntPtr()	// to allow generation of a NULL reference without the compiler complaining
sl@0
    43
	{ return 0; }
sl@0
    44
sl@0
    45
void GetMaxLatencyValues(SMaxLatencyValues& a)
sl@0
    46
	{
sl@0
    47
	GetLatencyValues(2,*NullTIntPtr(),(SLatencyValues*)&a);
sl@0
    48
	}
sl@0
    49
sl@0
    50
LOCAL_C void DumpValues(TInt aCount, SLatencyValues* aValues)
sl@0
    51
	{
sl@0
    52
	TInt i;
sl@0
    53
	for (i=0; i<aCount; i++)
sl@0
    54
		{
sl@0
    55
		SLatencyValues v=aValues[i];
sl@0
    56
		TInt addr=v.iAddress;
sl@0
    57
		TInt iticks=v.iLatencies>>16;
sl@0
    58
		TInt tticks=v.iLatencies & 0xffff;
sl@0
    59
		TInt ius=(iticks*125+124)>>6;
sl@0
    60
		TInt tus=(tticks*125+124)>>6;
sl@0
    61
//		TInt oldtid=v.iThreadIds & 0xffff;
sl@0
    62
//		TInt newtid=v.iThreadIds >> 16;
sl@0
    63
		TInt swi=v.iSwi;
sl@0
    64
		RDebug::Print(_L("%08x %4d %4d %08x %08x"),addr,ius,tus,v.iThreadIds,swi);
sl@0
    65
		}
sl@0
    66
	}
sl@0
    67
sl@0
    68
LOCAL_C void DisplayMaxLatencyValues()
sl@0
    69
	{
sl@0
    70
	SMaxLatencyValues v;
sl@0
    71
	GetMaxLatencyValues(v);
sl@0
    72
	TInt ius=(v.iMaxIntLatency*125+124)>>6;
sl@0
    73
	TInt tus=(v.iMaxThreadLatency*125+124)>>6;
sl@0
    74
	console->Printf(_L("Interrupt: %4dus return address %08x\n"),ius,v.iMaxIntLatencyRetAddr);
sl@0
    75
	console->Printf(_L("Thread:    %4dus return address %08x\n"),tus,v.iMaxThreadLatencyRetAddr);
sl@0
    76
	}
sl@0
    77
sl@0
    78
GLDEF_C TInt E32Main()
sl@0
    79
	{
sl@0
    80
	TInt c;
sl@0
    81
	SLatencyValues* pV=new SLatencyValues[28672];
sl@0
    82
sl@0
    83
	test.Title();
sl@0
    84
	console=test.Console();
sl@0
    85
	if (!pV)
sl@0
    86
		User::Panic(_L("OOM"),0);
sl@0
    87
sl@0
    88
	TBool exit=EFalse;
sl@0
    89
	while(!exit)
sl@0
    90
		{
sl@0
    91
		TKeyCode k=test.Getch();
sl@0
    92
		switch(k)
sl@0
    93
			{
sl@0
    94
			case '0':
sl@0
    95
				console->Printf(_L("Getting Latency Values\n"));
sl@0
    96
				GetLatencyValues(0,c,pV);
sl@0
    97
				DumpValues(c,pV);
sl@0
    98
				break;
sl@0
    99
			case '1':
sl@0
   100
				console->Printf(_L("Clearing Latency Values\n"));
sl@0
   101
				GetLatencyValues(1,c,pV);
sl@0
   102
				break;
sl@0
   103
			case '2':
sl@0
   104
				DisplayMaxLatencyValues();
sl@0
   105
				break;
sl@0
   106
			case 'x':
sl@0
   107
			case 'X':
sl@0
   108
				exit=ETrue;
sl@0
   109
				break;
sl@0
   110
			default:
sl@0
   111
				break;
sl@0
   112
			}
sl@0
   113
		}
sl@0
   114
sl@0
   115
	test.End();
sl@0
   116
	return 0;
sl@0
   117
	}
sl@0
   118