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