kerneltest/e32test/mmu/paging_info.cpp
changeset 0 a41df078684a
child 26 c734af59ce98
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\mmu\paging_info.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32debug.h>
       
    19 #include <e32svr.h>
       
    20 #include <u32hal.h>
       
    21 #include <hal.h>
       
    22 #include "paging_info.h"
       
    23 
       
    24 
       
    25 const TUint8* BenchmarkNames[] =
       
    26 	{
       
    27 	(const TUint8*)"Read rom page",
       
    28 	(const TUint8*)"Read code page",
       
    29 	(const TUint8*)"Decompress",
       
    30 	(const TUint8*)"Set code page free",
       
    31 	(const TUint8*)"Set code page old",
       
    32 	(const TUint8*)"Read media",
       
    33 	(const TUint8*)"Fixup code page",
       
    34 	(const TUint8*)"Read data page",
       
    35 	(const TUint8*)"Write data page",
       
    36 	(const TUint8*)"Del notify data page",
       
    37 	(const TUint8*)"Read media data page",
       
    38 	(const TUint8*)"Write media data page",
       
    39 	};
       
    40 
       
    41 __ASSERT_COMPILE(sizeof(BenchmarkNames)/sizeof(TUint8*) == EMaxPagingBm);
       
    42 
       
    43 
       
    44 TInt PagingInfo::ResetConcurrency(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
    45 	{
       
    46 	TInt r = UserSvr::HalFunction(EHalGroupVM, EVMHalResetConcurrencyInfo, NULL, NULL);
       
    47 	if (r!=KErrNotSupported && r!=KErrNone)
       
    48 		return r;
       
    49 	if(aLocDrvNo>=0)
       
    50 		r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalResetConcurrencyInfo,(TAny*)aLocDrvNo,(TAny*)aMediaStats);
       
    51 	if(r==KErrNotSupported)
       
    52 		r = KErrNone;
       
    53 	return r;
       
    54 	}
       
    55 
       
    56 
       
    57 TInt PagingInfo::PrintConcurrency(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
    58 	{
       
    59 	SPagingConcurrencyInfo info;
       
    60 	TInt r = UserSvr::HalFunction(EHalGroupVM, EVMHalGetConcurrencyInfo, &info, NULL);
       
    61 	if (r!=KErrNotSupported && r!=KErrNone)
       
    62 		return r;
       
    63 	if (r == KErrNone)
       
    64 		{
       
    65 		RDebug::Printf("Concurrency info:");
       
    66 		RDebug::Printf("  Max waiting threads == %d", info.iMaxWaitingCount);
       
    67 		RDebug::Printf("  Max paging threads == %d", info.iMaxPagingCount);
       
    68 		}
       
    69 	if(aLocDrvNo>=0)
       
    70 		{
       
    71 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsRom)
       
    72 			{
       
    73 			SMediaROMPagingConcurrencyInfo info;		
       
    74 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetROMConcurrencyInfo,(TAny*)aLocDrvNo,&info);
       
    75 			if (r!=KErrNotSupported && r!=KErrNone)
       
    76 				return r;
       
    77 			if(r==KErrNone)
       
    78 				{
       
    79 				RDebug::Printf("ROM paging media concurrency stats on drive %d:",aLocDrvNo);
       
    80 				RDebug::Printf("  Total page-in issued whilst processing other page-ins              : %d",info.iTotalConcurrentReqs);
       
    81 				RDebug::Printf("  Total page-in issued with at least one queue not empty             : %d",info.iTotalReqIssuedNonEmptyQ);
       
    82 				RDebug::Printf("  Max pending page-in in the main queue                              : %d",info.iMaxReqsInPending);
       
    83 				RDebug::Printf("  Max pending page-in in the deferred queue                          : %d",info.iMaxReqsInDeferred);
       
    84 				RDebug::Printf("  Total page-in first-time deferred during this session              : %d",info.iTotalFirstTimeDeferrals);
       
    85 				RDebug::Printf("  Total page-in re-deferred during this session                      : %d",info.iTotalReDeferrals);
       
    86 				RDebug::Printf("  Maximum deferrals of any single page-in                            : %d",info.iMaxDeferrals);
       
    87 				RDebug::Printf("  Total times the main queue was emptied during asynchronous request : %d",info.iTotalSynchEmptiedMainQ);
       
    88 				RDebug::Printf("  Total page-in serviced from main queue during asynchronous request : %d",info.iTotalSynchServicedFromMainQ);
       
    89 				RDebug::Printf("  Total page-in deferred from main queue during asynchronous request : %d",info.iTotalSynchDeferredFromMainQ);
       
    90 				RDebug::Printf("  Total page-in DFC run with an empty main queue                     : %d",info.iTotalRunDry);
       
    91 				RDebug::Printf("  Total dry runs of paging DFC avoided                               : %d",info.iTotalDryRunsAvoided);
       
    92 				}
       
    93 			}
       
    94 
       
    95 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsCode)
       
    96 			{
       
    97 			SMediaCodePagingConcurrencyInfo infoCode;
       
    98 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetCodeConcurrencyInfo,(TAny*)aLocDrvNo,&infoCode);
       
    99 			if(r==KErrNone)
       
   100 				{
       
   101 				RDebug::Printf("Media Code Paging concurrency stats on drive %d", aLocDrvNo);
       
   102 				RDebug::Printf("  Total page-in issued whilst processing other page in requests      : %d", infoCode.iTotalConcurrentReqs);
       
   103 				RDebug::Printf("  Total page-in issued with at least one queue not empty             : %d", infoCode.iTotalReqIssuedNonEmptyQ);
       
   104 				RDebug::Printf("  Max pending page-in in the main queue                              : %d", infoCode.iMaxReqsInPending);
       
   105 				RDebug::Printf("  Max pending page-in requests in the deferred queue                 : %d", infoCode.iMaxReqsInDeferred);
       
   106 				RDebug::Printf("  Total page-in first-time deferred                                  : %d", infoCode.iTotalFirstTimeDeferrals);
       
   107 				RDebug::Printf("  Total page-in re-deferred during this session (from deferred queue): %d", infoCode.iTotalReDeferrals);
       
   108 				RDebug::Printf("  Max number of deferrals of any single page in                      : %d", infoCode.iMaxDeferrals);
       
   109 				RDebug::Printf("  Total pagein serviced from main queue during asynchronous request  : %d", infoCode.iTotalSynchServicedFromMainQ);
       
   110 				RDebug::Printf("  Total pagein deferred from main queue during asynchronous request  : %d", infoCode.iTotalSynchDeferredFromMainQ);
       
   111 				}
       
   112 			}
       
   113 		}
       
   114 	if (r == KErrNotSupported)
       
   115 		r = KErrNone;
       
   116 	return r;
       
   117 	}
       
   118 
       
   119 
       
   120 TInt PagingInfo::ResetEvents()
       
   121 	{
       
   122 	return UserSvr::HalFunction(EHalGroupVM,EVMHalResetEventInfo,0,0);
       
   123 	}
       
   124 
       
   125 
       
   126 TInt PagingInfo::PrintEvents()
       
   127 	{
       
   128 	SVMEventInfo info;
       
   129 	TPckg<SVMEventInfo> infoBuf(info);
       
   130 	TInt r = UserSvr::HalFunction(EHalGroupVM,EVMHalGetEventInfo,&infoBuf,0);
       
   131 	if(r!=KErrNone)
       
   132 		return r;
       
   133 	RDebug::Printf("Event info:");
       
   134 	RDebug::Printf("  Page fault events: %Ld", info.iPageFaultCount);
       
   135 	RDebug::Printf("  Page in events: %Ld", info.iPageInReadCount);
       
   136 	return KErrNone;
       
   137 	}
       
   138 
       
   139 
       
   140 TInt PagingInfo::ResetBenchmarks(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
   141 	{
       
   142 	TInt r = KErrNone;
       
   143 	for (TInt i = 0 ; r == KErrNone && i < EMaxPagingBm ; ++i)
       
   144 		{
       
   145 		r = UserSvr::HalFunction(EHalGroupVM, EVMHalResetPagingBenchmark, (TAny*)i, NULL);
       
   146 		if (r!=KErrNotSupported && r!=KErrNone)
       
   147 			return r;
       
   148 		}
       
   149 	if(aLocDrvNo>=0)
       
   150 		r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalResetPagingBenchmark,(TAny*)aLocDrvNo,(TAny*)aMediaStats);
       
   151 	if(r==KErrNotSupported)
       
   152 		r = KErrNone;
       
   153 	return r;
       
   154 	}
       
   155 
       
   156 
       
   157 TInt PagingInfo::PrintBenchmarks(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
   158 	{
       
   159 	RDebug::Printf("Paging benchmarks:");
       
   160 	RDebug::Printf("  Name:                         Count:  Min (us):  Max(us):  Avg(us):");
       
   161 	
       
   162 	TInt freq = 0;
       
   163 	TReal min;
       
   164 	TReal max;
       
   165 	TReal avg;
       
   166 	TInt r = HAL::Get(HAL::EFastCounterFrequency, freq);
       
   167 	if (r != KErrNone)
       
   168 		return r;
       
   169 
       
   170 	TReal mult = 1000000.0 / freq;
       
   171 	
       
   172 	for (TInt i = 0 ; i < EMaxPagingBm ; ++i)
       
   173 		{
       
   174 		SPagingBenchmarkInfo info;
       
   175 		r = UserSvr::HalFunction(EHalGroupVM, EVMHalGetPagingBenchmark, (TAny*)i, &info);
       
   176 		if (r!=KErrNotSupported && r!=KErrNone)
       
   177 			return r;
       
   178 		if (r == KErrNone)
       
   179 			{
       
   180 			min = 0.0;
       
   181 			max = 0.0;
       
   182 			avg = 0.0;
       
   183 			if (info.iCount != 0)
       
   184 				{
       
   185 				min = info.iMinTime * mult;
       
   186 				max = info.iMaxTime * mult;
       
   187 				avg = (info.iTotalTime * mult) / info.iCount;
       
   188 				}
       
   189 			const TUint8* name = BenchmarkNames[i];
       
   190 			RDebug::Printf("  %-30s %6d %9.1f %9.1f %9.1f", name, info.iCount, min, max, avg);
       
   191 			}
       
   192 		}
       
   193 
       
   194 	if(aLocDrvNo>=0)
       
   195 		{
       
   196 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsRom)
       
   197 			{
       
   198 			SPagingBenchmarkInfo info;
       
   199 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetROMPagingBenchmark,(TAny*)aLocDrvNo,&info);
       
   200 			if (r!=KErrNotSupported && r!=KErrNone)
       
   201 				return r;
       
   202 			if(r==KErrNone)
       
   203 				{
       
   204 				if (info.iCount != 0)
       
   205 					{
       
   206 					min = info.iMinTime * mult;
       
   207 					max = info.iMaxTime * mult;
       
   208 					avg = (info.iTotalTime * mult) / info.iCount;
       
   209 					RDebug::Printf("ROM paging media benchmarks on drive %d:",aLocDrvNo);
       
   210 					RDebug::Printf("  %-30s %6d %9.1f %9.1f %9.1f", "Page-in latency", info.iCount, min, max, avg);
       
   211 					}
       
   212 				}
       
   213 			}
       
   214 
       
   215 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsCode)
       
   216 			{
       
   217 			SPagingBenchmarkInfo info;
       
   218 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetCodePagingBenchmark,(TAny*)aLocDrvNo,&info);
       
   219 			if (r!=KErrNotSupported && r!=KErrNone)
       
   220 				return r;
       
   221 			if(r==KErrNone)
       
   222 				{
       
   223 				if (info.iCount != 0)
       
   224 					{
       
   225 					min = info.iMinTime * mult;
       
   226 					max = info.iMaxTime * mult;
       
   227 					avg = (info.iTotalTime * mult) / info.iCount;
       
   228 					RDebug::Printf("Code paging media benchmarks on drive %d:",aLocDrvNo);
       
   229 					RDebug::Printf("  %-30s %6d %9.1f %9.1f %9.1f", "Page-in latency", info.iCount, min, max, avg);
       
   230 					}
       
   231 				}
       
   232 			}
       
   233 
       
   234 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsDataIn)
       
   235 			{
       
   236 			SPagingBenchmarkInfo info;
       
   237 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetDataInPagingBenchmark,(TAny*)aLocDrvNo,&info);
       
   238 			if (r!=KErrNotSupported && r!=KErrNone)
       
   239 				return r;
       
   240 			if(r==KErrNone)
       
   241 				{
       
   242 				if (info.iCount != 0)
       
   243 					{
       
   244 					min = info.iMinTime * mult;
       
   245 					max = info.iMaxTime * mult;
       
   246 					avg = (info.iTotalTime * mult) / info.iCount;
       
   247 					RDebug::Printf("Data page-in media benchmarks on drive %d:",aLocDrvNo);
       
   248 					RDebug::Printf("  %-30s %6d %9.1f %9.1f %9.1f", "Page-in latency", info.iCount, min, max, avg);
       
   249 					}
       
   250 				}
       
   251 			}
       
   252 
       
   253 		if(aMediaStats==EMediaPagingStatsAll || aMediaStats==EMediaPagingStatsDataOut)
       
   254 			{
       
   255 			SPagingBenchmarkInfo info;
       
   256 			r=UserSvr::HalFunction(EHalGroupMedia,EMediaHalGetDataOutPagingBenchmark,(TAny*)aLocDrvNo,&info);
       
   257 			if (r!=KErrNotSupported && r!=KErrNone)
       
   258 				return r;
       
   259 			if(r==KErrNone)
       
   260 				{
       
   261 				if (info.iCount != 0)
       
   262 					{
       
   263 					min = info.iMinTime * mult;
       
   264 					max = info.iMaxTime * mult;
       
   265 					avg = (info.iTotalTime * mult) / info.iCount;
       
   266 					RDebug::Printf("Data page-out media benchmarks on drive %d:",aLocDrvNo);
       
   267 					RDebug::Printf("  %-30s %6d %9.1f %9.1f %9.1f", "Page-in latency", info.iCount, min, max, avg);
       
   268 					}
       
   269 				}
       
   270 			}
       
   271 
       
   272 		}
       
   273 
       
   274 	return KErrNone;
       
   275 	}
       
   276 
       
   277 
       
   278 TInt PagingInfo::ResetAll(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
   279 	{
       
   280 	TInt r = ResetEvents();
       
   281 	if (r == KErrNone || r == KErrNotSupported)
       
   282 		r = ResetConcurrency(aLocDrvNo,aMediaStats);
       
   283 	if (r == KErrNone || r == KErrNotSupported)
       
   284 		r = ResetBenchmarks(aLocDrvNo,aMediaStats);
       
   285 	if (r == KErrNotSupported)
       
   286 		r = KErrNone;
       
   287 	return r;
       
   288 	}
       
   289 
       
   290 
       
   291 TInt PagingInfo::PrintAll(TInt aLocDrvNo, TMediaPagingStats aMediaStats)
       
   292 	{
       
   293 	TInt r = PrintEvents();
       
   294 	if (r == KErrNone || r == KErrNotSupported)
       
   295 		r = PrintConcurrency(aLocDrvNo,aMediaStats);
       
   296 	if (r == KErrNone || r == KErrNotSupported)
       
   297 		r = PrintBenchmarks(aLocDrvNo,aMediaStats);
       
   298 	if (r == KErrNotSupported)
       
   299 		r = KErrNone;
       
   300 	return r;
       
   301 	}
       
   302 
       
   303