sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // e32test\smpsoak\d_smpsoak.cpp sl@0: // sl@0: sl@0: // LDD for smpsoak - setting Thread CPU Affinity sl@0: // sl@0: sl@0: #include "d_smpsoak.h" sl@0: #include sl@0: #include sl@0: sl@0: const TInt KMajorVersionNumber=0; sl@0: const TInt KMinorVersionNumber=1; sl@0: const TInt KBuildVersionNumber=1; sl@0: sl@0: class DSmpSoakFactory : public DLogicalDevice sl@0: // sl@0: // IPC copy LDD factory sl@0: // sl@0: { sl@0: public: sl@0: DSmpSoakFactory(); sl@0: virtual TInt Install(); //overriding pure virtual sl@0: virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual sl@0: }; sl@0: sl@0: class DSmpSoak : public DLogicalChannelBase sl@0: { sl@0: public: sl@0: DSmpSoak(); sl@0: virtual ~DSmpSoak(); sl@0: protected: sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); sl@0: public: sl@0: static void IDfcFn(TAny* aPtr); sl@0: public: sl@0: void OccupyCpus(); sl@0: }; sl@0: sl@0: DECLARE_STANDARD_LDD() sl@0: { sl@0: Kern::Printf("DSmpSoak called"); sl@0: return new DSmpSoakFactory; sl@0: } sl@0: sl@0: DSmpSoakFactory::DSmpSoakFactory() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoakFactory::DSmpSoakFactory called"); sl@0: iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); sl@0: } sl@0: sl@0: TInt DSmpSoakFactory::Create(DLogicalChannelBase*& aChannel) sl@0: // sl@0: // Create a new DSmpSoak on this logical device sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoakFactory::Create called"); sl@0: aChannel=new DSmpSoak; sl@0: return aChannel?KErrNone:KErrNoMemory; sl@0: } sl@0: sl@0: TInt DSmpSoakFactory::Install() sl@0: // sl@0: // Install the LDD - overriding pure virtual sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoakFactory::Install called"); sl@0: return SetName(&KSmpSoakLddName); sl@0: } sl@0: sl@0: void DSmpSoakFactory::GetCaps(TDes8& aDes) const sl@0: // sl@0: // Get capabilities - overriding pure virtual sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoakFactory::GetCaps called"); sl@0: } sl@0: sl@0: DSmpSoak::DSmpSoak() sl@0: // sl@0: // Constructor sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoak::DSmpSoak called"); sl@0: } sl@0: sl@0: DSmpSoak::~DSmpSoak() sl@0: { sl@0: Kern::Printf("DSmpSoak::~DSmpSoak called"); sl@0: } sl@0: sl@0: TInt DSmpSoak::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) sl@0: // sl@0: // Create channel sl@0: // sl@0: { sl@0: Kern::Printf("DSmpSoak::DoCreate called"); sl@0: sl@0: if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer)) sl@0: return KErrNotSupported; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt DSmpSoak::Request(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: DThread *pT = NULL; sl@0: NThread *pMyNThread = NULL; sl@0: TInt handle = (TInt)a1; sl@0: TInt priority = (TInt)a2; sl@0: sl@0: TInt r = KErrNotSupported; sl@0: Kern::Printf("DSmpSoak::Request called aFunction = %d, a1 = %d, a2 = %d", aFunction, a1, a2); sl@0: sl@0: switch (aFunction) sl@0: { sl@0: case RSMPSoak::KGETPROCESSORCOUNT: sl@0: r = NKern::NumberOfCpus(); sl@0: Kern::Printf("DSmpSoak::Request Processor count = %d", r); sl@0: break; sl@0: case RSMPSoak::KGETCURRENTCPU: sl@0: r = NKern::CurrentCpu(); sl@0: Kern::Printf("DSmpSoak::Request Current CPU = %d", r); sl@0: break; sl@0: case RSMPSoak::KGETCURRENTTHREAD: sl@0: r = (TInt)NKern::CurrentThread(); sl@0: Kern::Printf("DSmpSoak::Request Current Thread %02x", r); sl@0: break; sl@0: case RSMPSoak::KTHREADSETCPUAFFINITY: sl@0: r = NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), (TInt)a1); sl@0: r = (TInt)NKern::CurrentCpu(); sl@0: Kern::Printf("DSmpSoak::Request Current Cpu = %d", r); sl@0: break; sl@0: case RSMPSoak::KOCCUPYCPUS: sl@0: Kern::Printf("DSmpSoak::Request OCCUPYCPUS: called"); sl@0: OccupyCpus(); sl@0: break; sl@0: case RSMPSoak::KCHANGEAFFINITY: sl@0: Kern::Printf("DSmpSoak::Request CHANGEAFFINITY"); sl@0: NKern::LockSystem(); sl@0: pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle); sl@0: pMyNThread=(NThread*)&pT->iNThread; sl@0: NKern::ThreadSetCpuAffinity((NThread*)pMyNThread, (TInt)a2); sl@0: NKern::UnlockSystem(); sl@0: break; sl@0: case RSMPSoak::KCHANGETHREADPRIORITY: sl@0: Kern::Printf("DSmpSoak::Request CHANGETHREADPRIORITY"); sl@0: NKern::LockSystem(); sl@0: pT=(DThread*)Kern::CurrentThread().ObjectFromHandle(handle); sl@0: Kern::Printf("DSmpSoak::Request Current Thread %d", pT); sl@0: pT->SetThreadPriority(priority); sl@0: Kern::Printf("DSmpSoak::CHANGETHREADPRIORITY now %d", pT->iThreadPriority); sl@0: NKern::UnlockSystem(); sl@0: break; sl@0: default: sl@0: Kern::Printf("DSmpSoak::Request default: called"); sl@0: break; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: void DSmpSoak::OccupyCpus() sl@0: { sl@0: Kern::Printf(">>>DSmpSoak::OccupyCpus()"); sl@0: } sl@0: sl@0: sl@0: