00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "ki.h"
00025
#include <ia64.h>
00026
#include <ntia64.h>
00027
#include <ntexapi.h>
00028
00029
VOID
00030
KiProcessProfileList (
00031 IN PKTRAP_FRAME TrFrame,
00032 IN KPROFILE_SOURCE Source,
00033 IN PLIST_ENTRY ListHead
00034 );
00035
00036
00037 BOOLEAN
00038 KiChkTimerExpireSysDpc (
00039 IN ULONGLONG TickCount
00040 )
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 {
00063 BOOLEAN ret =
FALSE;
00064
00065 PLIST_ENTRY ListHead = &
KiTimerTableListHead[(ULONG)
TickCount%
TIMER_TABLE_SIZE];
00066 PLIST_ENTRY NextEntry = ListHead->Flink;
00067
00068
00069
00070
00071
if (NextEntry != ListHead) {
00072
PKTIMER Timer = CONTAINING_RECORD(NextEntry,
KTIMER, TimerListEntry);
00073 ULONGLONG TimeValue = Timer->
DueTime.QuadPart;
00074
00075
00076
00077
00078
00079
if (TimeValue <= SharedUserData->InterruptTime) {
00080
00081 PKPRCB Prcb =
KeGetCurrentPrcb();
00082
PKDPC Dpc = &
KiTimerExpireDpc;
00083
00084 _disable();
00085
#if !defined(NT_UP)
00086
KiAcquireSpinLock(&Prcb->DpcLock);
00087
#endif
00088
00089
00090
00091
if (Dpc->
Lock ==
NULL) {
00092
00093
00094
00095
00096
00097
00098 Prcb->DpcCount += 1;
00099 Prcb->DpcQueueDepth += 1;
00100 Dpc->
Lock = &Prcb->DpcLock;
00101 Dpc->
SystemArgument1 = (PVOID)
TickCount;
00102 Dpc->
SystemArgument2 = 0;
00103 InsertTailList(&Prcb->DpcListHead, &Dpc->
DpcListEntry);
00104
KiRequestSoftwareInterrupt(
DISPATCH_LEVEL);
00105 }
00106
00107 ret =
TRUE;
00108
00109
#if !defined(NT_UP)
00110
KiReleaseSpinLock(&Prcb->DpcLock);
00111
#endif
00112
00113 _enable();
00114 }
00115 }
00116
00117
return(ret);
00118 }
00119
00120
00121
VOID
00122 KeUpdateSystemTime (
00123 IN PKTRAP_FRAME TrFrame,
00124 IN ULONG Increment
00125 )
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 {
00153
long SaveTickOffset;
00154 LARGE_INTEGER SystemTime;
00155
00156 SharedUserData->InterruptTime +=
Increment;
00157 SharedUserData->InterruptHigh2Time = (LONG)(SharedUserData->InterruptTime >> 32);
00158
KiTickOffset -=
Increment;
00159
00160 SaveTickOffset =
KiTickOffset;
00161
00162
if ((LONG)
KiTickOffset > 0)
00163 {
00164
00165
00166
00167
00168
00169
00170
KiChkTimerExpireSysDpc(
KeTickCount);
00171
00172 }
else {
00173
00174
00175
00176
00177
00178
00179
00180
00181
KiTickOffset +=
KeMaximumIncrement;
00182 SystemTime.HighPart = SharedUserData->SystemHigh1Time;
00183 SystemTime.LowPart = SharedUserData->SystemLowTime;
00184 SystemTime.QuadPart +=
KeTimeAdjustment;
00185 SharedUserData->SystemHigh1Time = SystemTime.HighPart;
00186 SharedUserData->SystemLowTime = SystemTime.LowPart;
00187 SharedUserData->SystemHigh2Time = SystemTime.HighPart;
00188 ++
KeTickCount;
00189 SharedUserData->TickCountLow = (ULONG)
KeTickCount;
00190
00191
00192
00193
00194
00195
00196
if (!
KiChkTimerExpireSysDpc(
KeTickCount - 1))
00197
KiChkTimerExpireSysDpc(
KeTickCount);
00198
00199 }
00200
00201
if (SaveTickOffset <= 0) {
00202
KeUpdateRunTime(TrFrame);
00203 }
00204 }
00205
00206
00207
VOID
00208 KeUpdateRunTime (
00209 IN PKTRAP_FRAME TrFrame
00210 )
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 {
00231 KSPIN_LOCK
Lock;
00232 PKPRCB Prcb =
KeGetCurrentPrcb();
00233
PKTHREAD Thread =
KeGetCurrentThread();
00234
PKPROCESS Process = Thread->
ApcState.
Process;
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
if (TrFrame->PreviousMode !=
KernelMode) {
00250 ++Thread->
UserTime;
00251
00252
00253
ExInterlockedIncrementLong(&Process->
UserTime, &
Lock);
00254
00255
00256 ++Prcb->UserTime;
00257 }
else {
00258
00259
if (TrFrame->OldIrql >
DISPATCH_LEVEL) {
00260 ++Prcb->InterruptTime;
00261 }
else if ((TrFrame->OldIrql <
DISPATCH_LEVEL) ||
00262 (Prcb->DpcRoutineActive == 0)) {
00263 ++Thread->
KernelTime;
00264
ExInterlockedIncrementLong(&Process->
KernelTime, &
Lock);
00265 }
else {
00266 ++Prcb->DpcTime;
00267 }
00268
00269
00270
00271
00272
00273 ++Prcb->KernelTime;
00274 }
00275
00276
00277
00278
00279
00280
00281 Prcb->DpcRequestRate = ((Prcb->DpcCount - Prcb->DpcLastCount) + Prcb->DpcRequestRate) >> 1;
00282 Prcb->DpcLastCount = Prcb->DpcCount;
00283
00284
00285
00286
00287
00288
00289
00290
if (Prcb->DpcQueueDepth != 0 && Prcb->DpcRoutineActive == 0) {
00291
00292 Prcb->AdjustDpcThreshold =
KiAdjustDpcThreshold;
00293
00294
00295
KiRequestSoftwareInterrupt(
DISPATCH_LEVEL);
00296
00297
if (Prcb->DpcRequestRate <
KiIdealDpcRate && Prcb->MaximumDpcQueueDepth > 1)
00298 --Prcb->MaximumDpcQueueDepth;
00299 }
else {
00300
00301
00302
00303
00304
00305
00306 --Prcb->AdjustDpcThreshold;
00307
if (Prcb->AdjustDpcThreshold == 0) {
00308 Prcb->AdjustDpcThreshold =
KiAdjustDpcThreshold;
00309
if (
KiMaximumDpcQueueDepth != Prcb->MaximumDpcQueueDepth)
00310 ++Prcb->MaximumDpcQueueDepth;
00311 }
00312 }
00313
00314
00315
00316
00317 Thread->
Quantum -=
CLOCK_QUANTUM_DECREMENT;
00318
00319
00320
if (Thread->
Quantum == 0 && Thread != Prcb->IdleThread) {
00321
00322 Prcb->QuantumEnd = 1;
00323
00324
00325
KiRequestSoftwareInterrupt(
DISPATCH_LEVEL);
00326 }
00327
00328 }
00329
00330
00331
VOID
00332 KiDecrementQuantum (
00333 )
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 {
00354
PKTHREAD Thread =
KeGetCurrentThread();
00355 PKPRCB Prcb =
KeGetCurrentPrcb();
00356
00357 Thread->
Quantum -=
CLOCK_QUANTUM_DECREMENT;
00358
00359
00360
if (Thread->
Quantum == 0 && Thread != Prcb->IdleThread)
00361 Prcb->QuantumEnd = 1;
00362 }
00363
00364
00365
VOID
00366 KeProfileInterrupt (
00367 IN PKTRAP_FRAME TrFrame
00368 )
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 {
00392 KPROFILE_SOURCE Source = 0;
00393
00394
KeProfileInterruptWithSource(TrFrame, Source);
00395
00396
return;
00397 }
00398
00399
00400
VOID
00401 KeProfileInterruptWithSource (
00402 IN PKTRAP_FRAME TrFrame,
00403 IN KPROFILE_SOURCE Source
00404 )
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 {
00430
PKTHREAD Thread =
KeGetCurrentThread();
00431
PKPROCESS Process = Thread->
ApcState.
Process;
00432
00433
#if !defined(NT_UP)
00434
KiAcquireSpinLock(&
KiProfileLock);
00435
#endif
00436
00437
KiProcessProfileList(TrFrame, Source, &Process->
ProfileListHead);
00438
00439
KiProcessProfileList(TrFrame, Source, &
KiProfileListHead);
00440
00441
#if !defined(NT_UP)
00442
KiAcquireSpinLock(&
KiProfileLock);
00443
#endif
00444
return;
00445 }
00446
00447
00448
VOID
00449 KiProcessProfileList (
00450 IN PKTRAP_FRAME TrFrame,
00451 IN KPROFILE_SOURCE Source,
00452 IN PLIST_ENTRY ListHead
00453 )
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 {
00481 PLIST_ENTRY NextEntry = ListHead->Flink;
00482 PKPRCB Prcb =
KeGetCurrentPrcb();
00483
00484
00485
00486
00487
for (; NextEntry != ListHead; NextEntry = NextEntry->Flink) {
00488
00489 PCHAR BucketPter;
00490 PULONG BucketValue;
00491
00492
PKPROFILE Profile = CONTAINING_RECORD(NextEntry,
KPROFILE, ProfileListEntry);
00493
00494
if (Profile->
Source != Source || ((Profile->
Affinity & Prcb->SetMember) == 0))
00495
continue;
00496
00497
if ((PVOID)TrFrame->StIIP < Profile->
RangeBase || (PVOID)TrFrame->StIIP > Profile->
RangeLimit)
00498
continue;
00499
00500 BucketPter = (PCHAR)Profile->
Buffer +
00501 ((((PCHAR)TrFrame->StIIP - (PCHAR)Profile->
RangeBase)
00502 >> Profile->
BucketShift) & 0xFFFFFFFC);
00503
00504 BucketValue = (PULONG) BucketPter;
00505 ++BucketValue;
00506 }
00507
00508
return;
00509 }