os/kernelhwsrv/kerneltest/e32test/defrag/perf/t_perfdll.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/defrag/perf/t_perfdll.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,146 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test/defrag/perf/t_perfdll.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#define __E32TEST_EXTENSION__
    1.22 +#include <e32test.h>
    1.23 +#include <e32hal.h>
    1.24 +#include "..\d_pagemove.h"
    1.25 +#include "t_perf.h"
    1.26 +#include "t_testdll.h"
    1.27 +
    1.28 +_LIT(KDllbaseName, "t_defragperf");
    1.29 +
    1.30 +TPtrC TestPlExtNames = _L(".dll");
    1.31 +
    1.32 +const TInt KIterations = 50;
    1.33 +
    1.34 +#define MAXDLLS 1
    1.35 +
    1.36 +
    1.37 +#define MINDLL_PAGES (100 * E_SIZE)
    1.38 +
    1.39 +typedef TInt (*TCallFunction)(TUint32 funcIndex, TInt param1, TInt param2);
    1.40 +
    1.41 +TInt DllDefrag::LoadTheLib(TInt aIdx, RTest& test)
    1.42 +	{
    1.43 +
    1.44 +	TBuf<128>           nameBuffer;
    1.45 +	TUint32             FuncCount;
    1.46 +	TLibraryFunction    InitFunc;
    1.47 +	TLibraryFunction    FunctionCountFunc;
    1.48 +	TCallFunction       CallFunctionFunc;
    1.49 +	TLibraryFunction    SetCloseFunc;
    1.50 +	TLibraryFunction    Function0AddrFunc, FunctionNAddrFunc;
    1.51 +	TInt retVal;
    1.52 +
    1.53 +	if (iLib == NULL)
    1.54 +		return KErrNoMemory;
    1.55 +
    1.56 +
    1.57 +	nameBuffer.Format(_L("%S%d%S"), &KDllbaseName, aIdx, &TestPlExtNames);
    1.58 +
    1.59 +	/* Load the DLL */
    1.60 +	TEST_PRINTF(_L("Loading the DLL (%S) ...\n"), &nameBuffer);
    1.61 +
    1.62 +	retVal = iLib->Load(nameBuffer);
    1.63 +
    1.64 +	if (retVal != KErrNone)
    1.65 +		{
    1.66 +		test.Printf(_L("Load Failed %S (%d)\n"), &nameBuffer, aIdx);
    1.67 +		return KErrGeneral;
    1.68 +		}
    1.69 +
    1.70 +	TEST_PRINTF(_L("Loaded %S (%d)\n"), &nameBuffer, aIdx);
    1.71 +
    1.72 +	/* Test that the DLL is loaded correctly */
    1.73 +	InitFunc = iLib->Lookup(DEFRAGDLL_FUNC_Init);
    1.74 +	FunctionCountFunc = iLib->Lookup(DEFRAGDLL_FUNC_FunctionCount);
    1.75 +	CallFunctionFunc = (TCallFunction)iLib->Lookup(DEFRAGDLL_FUNC_CallFunction);
    1.76 +	SetCloseFunc = iLib->Lookup(DEFRAGDLL_FUNC_SetClose);
    1.77 +	Function0AddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_func0);
    1.78 +	FunctionNAddrFunc = iLib->Lookup(DEFRAGDLL_FUNC_funcN);
    1.79 +
    1.80 +	if (InitFunc == NULL ||
    1.81 +		FunctionCountFunc == NULL ||
    1.82 +		CallFunctionFunc == NULL ||
    1.83 +		SetCloseFunc == NULL)
    1.84 +		{
    1.85 +		return KErrGeneral;
    1.86 +		}
    1.87 +
    1.88 +	retVal = (InitFunc)();
    1.89 +	if (retVal != KErrNone)
    1.90 +		return KErrGeneral;
    1.91 +
    1.92 +	FuncCount = (FunctionCountFunc)();
    1.93 +	if (FuncCount == 0)
    1.94 +		return KErrGeneral;
    1.95 +
    1.96 +	iFunc0Addr = (TInt8 *)(Function0AddrFunc)();
    1.97 +	iFuncNAddr = (TInt8 *)(FunctionNAddrFunc)();
    1.98 +		
    1.99 +	TEST_PRINTF(_L("%S:Func0 = %x FuncN = %x\n"), &nameBuffer, iFunc0Addr, iFuncNAddr);
   1.100 +	
   1.101 +	if (iFunc0Addr == NULL || iFuncNAddr == NULL)
   1.102 +			return KErrGeneral;
   1.103 +
   1.104 +	if (iFunc0Addr > iFuncNAddr) 
   1.105 +		return KErrGeneral;
   1.106 +
   1.107 +	return KErrNone;
   1.108 +	}
   1.109 +
   1.110 +TInt DllDefrag::TestDLLPerformance(TInt aDummy, RPageMove& aPageMove, RTest& test)
   1.111 +{
   1.112 +	DefragLatency timer;
   1.113 +	TInt size = iFuncNAddr - iFunc0Addr;
   1.114 +	const TUint8 *end = (TUint8 *)iFunc0Addr + size; 
   1.115 +
   1.116 +	TInt pageSize;
   1.117 +	TInt r = UserHal::PageSizeInBytes(pageSize);
   1.118 +	test_KErrNone(r);
   1.119 +	TEST_PRINTF(_L("size %x"), size);
   1.120 +	TInt pagesToMove = _ALIGN_UP(size, pageSize) / pageSize;
   1.121 +	// Ensure there is at least one page to move
   1.122 +	test_Compare(size, >=, 1);
   1.123 +
   1.124 +	timer.CalibrateTimer(test);
   1.125 +
   1.126 +
   1.127 +	for (TInt j = 0; j < KIterations; j++)
   1.128 +		{
   1.129 +		TUint8* base = (TUint8 *)iFunc0Addr;
   1.130 +				
   1.131 +		timer.StartTimer();
   1.132 +		while (base < end) 
   1.133 +			{
   1.134 +			test_KErrNone(aPageMove.TryMovingUserPage(base));
   1.135 +			base += pageSize;
   1.136 +			}
   1.137 +		timer.StopTimer(test);
   1.138 +		}
   1.139 +	
   1.140 +	DTime_t average, max, min, delay;
   1.141 +	TEST_PRINTF(_L("Finished moving %d dll pages\n"), pagesToMove);
   1.142 +	average = timer.GetResult(max, min, delay);
   1.143 +	test.Printf(_L("Fast counter ticks to move %d dll pages: Av %d Min %d Max %d (Overhead %d)\n"), pagesToMove, average, min, max, delay);
   1.144 +	test.Printf(_L("Average of %d ticks to move one page\n\n"), average / pagesToMove);
   1.145 +
   1.146 +	return KErrNone;
   1.147 +	}
   1.148 +
   1.149 +