os/kernelhwsrv/kerneltest/e32test/smpsoak/d_smpsoak.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2002-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
// e32test\smpsoak\d_smpsoak.cpp
sl@0
    14
//
sl@0
    15
sl@0
    16
// LDD for smpsoak - setting Thread CPU Affinity
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "d_smpsoak.h"
sl@0
    20
#include <platform.h>
sl@0
    21
#include <kernel/kern_priv.h>
sl@0
    22
sl@0
    23
const TInt KMajorVersionNumber=0;
sl@0
    24
const TInt KMinorVersionNumber=1;
sl@0
    25
const TInt KBuildVersionNumber=1;
sl@0
    26
sl@0
    27
class DSmpSoakFactory : public DLogicalDevice
sl@0
    28
//
sl@0
    29
// IPC copy LDD factory
sl@0
    30
//
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	DSmpSoakFactory();
sl@0
    34
	virtual TInt Install();						//overriding pure virtual
sl@0
    35
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
sl@0
    36
	virtual TInt Create(DLogicalChannelBase*& aChannel);	//overriding pure virtual
sl@0
    37
	};
sl@0
    38
sl@0
    39
class DSmpSoak : public DLogicalChannelBase
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
	DSmpSoak();
sl@0
    43
	virtual ~DSmpSoak();
sl@0
    44
protected:
sl@0
    45
	virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
sl@0
    46
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    47
public:
sl@0
    48
	static void IDfcFn(TAny* aPtr);
sl@0
    49
public:
sl@0
    50
	void OccupyCpus();
sl@0
    51
	};
sl@0
    52
sl@0
    53
DECLARE_STANDARD_LDD()
sl@0
    54
	{
sl@0
    55
	Kern::Printf("DSmpSoak called");
sl@0
    56
    return new DSmpSoakFactory;
sl@0
    57
    }
sl@0
    58
sl@0
    59
DSmpSoakFactory::DSmpSoakFactory()
sl@0
    60
//
sl@0
    61
// Constructor
sl@0
    62
//
sl@0
    63
    {
sl@0
    64
	Kern::Printf("DSmpSoakFactory::DSmpSoakFactory called");
sl@0
    65
    iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
    66
    }
sl@0
    67
sl@0
    68
TInt DSmpSoakFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
    69
//
sl@0
    70
// Create a new DSmpSoak on this logical device
sl@0
    71
//
sl@0
    72
    {
sl@0
    73
	Kern::Printf("DSmpSoakFactory::Create called");
sl@0
    74
	aChannel=new DSmpSoak;
sl@0
    75
    return aChannel?KErrNone:KErrNoMemory;
sl@0
    76
    }
sl@0
    77
sl@0
    78
TInt DSmpSoakFactory::Install()
sl@0
    79
//
sl@0
    80
// Install the LDD - overriding pure virtual
sl@0
    81
//
sl@0
    82
    {
sl@0
    83
	Kern::Printf("DSmpSoakFactory::Install called");
sl@0
    84
    return SetName(&KSmpSoakLddName);
sl@0
    85
    }
sl@0
    86
sl@0
    87
void DSmpSoakFactory::GetCaps(TDes8& aDes) const
sl@0
    88
//
sl@0
    89
// Get capabilities - overriding pure virtual
sl@0
    90
//
sl@0
    91
    {
sl@0
    92
    Kern::Printf("DSmpSoakFactory::GetCaps called");
sl@0
    93
    }
sl@0
    94
sl@0
    95
DSmpSoak::DSmpSoak()
sl@0
    96
//
sl@0
    97
// Constructor
sl@0
    98
//
sl@0
    99
	{
sl@0
   100
	Kern::Printf("DSmpSoak::DSmpSoak called");
sl@0
   101
	}
sl@0
   102
sl@0
   103
DSmpSoak::~DSmpSoak()
sl@0
   104
	{
sl@0
   105
	Kern::Printf("DSmpSoak::~DSmpSoak called");
sl@0
   106
	}
sl@0
   107
sl@0
   108
TInt DSmpSoak::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
sl@0
   109
//
sl@0
   110
// Create channel
sl@0
   111
//
sl@0
   112
    {
sl@0
   113
	Kern::Printf("DSmpSoak::DoCreate called");
sl@0
   114
sl@0
   115
    if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   116
    	return KErrNotSupported;
sl@0
   117
	
sl@0
   118
	return KErrNone;
sl@0
   119
	}
sl@0
   120
sl@0
   121
sl@0
   122
TInt DSmpSoak::Request(TInt aFunction, TAny* a1, TAny* a2)
sl@0
   123
	{
sl@0
   124
	DThread *pT = NULL;
sl@0
   125
	NThread *pMyNThread = NULL;
sl@0
   126
	TInt handle = (TInt)a1;
sl@0
   127
	TInt priority = (TInt)a2;
sl@0
   128
sl@0
   129
	TInt r = KErrNotSupported;
sl@0
   130
	Kern::Printf("DSmpSoak::Request called aFunction = %d, a1 = %d, a2 = %d", aFunction, a1, a2);
sl@0
   131
sl@0
   132
	switch (aFunction)
sl@0
   133
		{
sl@0
   134
		case RSMPSoak::KGETPROCESSORCOUNT:
sl@0
   135
			r = NKern::NumberOfCpus();
sl@0
   136
			Kern::Printf("DSmpSoak::Request Processor count = %d", r);
sl@0
   137
			break;
sl@0
   138
		case RSMPSoak::KGETCURRENTCPU:
sl@0
   139
			r = NKern::CurrentCpu();
sl@0
   140
			Kern::Printf("DSmpSoak::Request Current CPU = %d", r);
sl@0
   141
			break;
sl@0
   142
		case RSMPSoak::KGETCURRENTTHREAD:
sl@0
   143
			r = (TInt)NKern::CurrentThread();
sl@0
   144
			Kern::Printf("DSmpSoak::Request Current Thread %02x", r);
sl@0
   145
			break;
sl@0
   146
		case RSMPSoak::KTHREADSETCPUAFFINITY:
sl@0
   147
			r = NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), (TInt)a1);
sl@0
   148
			r = (TInt)NKern::CurrentCpu();
sl@0
   149
			Kern::Printf("DSmpSoak::Request Current Cpu = %d", r);
sl@0
   150
			break;
sl@0
   151
		case RSMPSoak::KOCCUPYCPUS:
sl@0
   152
			Kern::Printf("DSmpSoak::Request OCCUPYCPUS: called");
sl@0
   153
			OccupyCpus();
sl@0
   154
			break;
sl@0
   155
		case RSMPSoak::KCHANGEAFFINITY:
sl@0
   156
			Kern::Printf("DSmpSoak::Request CHANGEAFFINITY");
sl@0
   157
			NKern::LockSystem();
sl@0
   158
			pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle);
sl@0
   159
			pMyNThread=(NThread*)&pT->iNThread;
sl@0
   160
			NKern::ThreadSetCpuAffinity((NThread*)pMyNThread, (TInt)a2);
sl@0
   161
			NKern::UnlockSystem();
sl@0
   162
			break;
sl@0
   163
		case RSMPSoak::KCHANGETHREADPRIORITY:
sl@0
   164
			Kern::Printf("DSmpSoak::Request CHANGETHREADPRIORITY");
sl@0
   165
			NKern::LockSystem();
sl@0
   166
			pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle);
sl@0
   167
			Kern::Printf("DSmpSoak::Request Current Thread %d", pT);
sl@0
   168
			pT->SetThreadPriority(priority);
sl@0
   169
			Kern::Printf("DSmpSoak::CHANGETHREADPRIORITY now  %d", pT->iThreadPriority);
sl@0
   170
			NKern::UnlockSystem();
sl@0
   171
			break;
sl@0
   172
		default:
sl@0
   173
			Kern::Printf("DSmpSoak::Request default: called");
sl@0
   174
			break;
sl@0
   175
		}
sl@0
   176
	return r;
sl@0
   177
	}
sl@0
   178
sl@0
   179
void DSmpSoak::OccupyCpus()
sl@0
   180
	{
sl@0
   181
	Kern::Printf(">>>DSmpSoak::OccupyCpus()");
sl@0
   182
	}
sl@0
   183
sl@0
   184
sl@0
   185