summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/halalpha/eisaprof.c
blob: 71350f4f6e9c9d4431f6e25e8921bf69e398a8db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/*++

Copyright (c) 1992, 1993  Digital Equipment Corporation

Module Name:

    eisaprof.c

Abstract:

    This module handles the Profile Counter and all Profile counter functions 
    for the standard EISA interval timer.

Author:

    Jeff McLeman (mcleman) 05-June-1992

Environment:

    Kernel mode

Revision History:


    Rod Gamache	[DEC]	9-Mar-1993
			Fix profile clock.


--*/

#include "halp.h"
#include "eisa.h"
#include "halprof.h"

//
// Define global data.
//

//
// Values used for Profile Clock
//

//	Convert the interval to rollover count for 8254 timer. Since
//	the 8254 counts down a 16 bit value at the clock rate of 1.193 MHZ,
//	the computation is:
//
//	RolloverCount = (Interval * 0.0000001) * (1193 * 1000000)
//		      = Interval * .1193
//		      = Interval * 1193 / 10000

#define PROFILE_INTERVAL 1193
#define PROFILE_INTERVALS_PER_100NS 10000/1193
#define MIN_PROFILE_TICKS 4
#define MAX_PROFILE_TICKS 0x10000		// 16 bit counter (zero is max)

//
// Since the profile timer interrupts at a frequency of 1.193 MHZ, we
// have .1193 intervals each 100ns. So we need a more reasonable value.
// If we compute the timer based on 1600ns intervals, we get 16 * .1193 or
// about 1.9 ticks per 16 intervals.
//
// We round this to 2 ticks per 1600ns intervals.
//

#define PROFILE_TIMER_1600NS_TICKS 2

//
// Default Profile Interval to be about 1ms.
//

ULONG HalpProfileInterval = PROFILE_TIMER_1600NS_TICKS * PROFILE_INTERVALS_PER_100NS * 10000 / 16; // ~1ms

//
// Default Number of Profile Clock Ticks per sample
//

ULONG HalpNumberOfTicks = 1;

//
// Define the profile interrupt object.
//

PKINTERRUPT HalpProfileInterruptObject;

//
// Declare profile interrupt handler.
//

BOOLEAN
HalpProfileInterrupt(
    PKSERVICE_ROUTINE InterruptRoutine,
    PVOID ServiceContext,
    PKTRAP_FRAME TrapFrame
    );

//
// Function prototypes.
//

BOOLEAN
HalQueryProfileInterval(
    IN KPROFILE_SOURCE Source
    );

NTSTATUS
HalSetProfileSourceInterval(
    IN KPROFILE_SOURCE ProfileSource,
    IN OUT ULONG *Interval
    );

//
// Function definitions.
//


NTSTATUS
HalpProfileSourceInformation (
    OUT PVOID   Buffer,
    IN  ULONG   BufferLength,
    OUT PULONG  ReturnedLength
    )
/*++

Routine Description:

    Returns the HAL_PROFILE_SOURCE_INFORMATION for this processor.

Arguments:

    Buffer - output buffer
    BufferLength - length of buffer on input
    ReturnedLength - The length of data returned

Return Value:

    STATUS_SUCCESS
    STATUS_BUFFER_TOO_SMALL - The ReturnedLength contains the buffersize
        currently needed.

--*/
{
   PHAL_PROFILE_SOURCE_INFORMATION SourceInfo;
   NTSTATUS Status;


   if (BufferLength != sizeof(HAL_PROFILE_SOURCE_INFORMATION)) {
       Status = STATUS_INFO_LENGTH_MISMATCH;
       return Status;
   }

   SourceInfo = (PHAL_PROFILE_SOURCE_INFORMATION)Buffer;
   SourceInfo->Supported = HalQueryProfileInterval(SourceInfo->Source);

   if (SourceInfo->Supported) {
       SourceInfo->Interval = HalpProfileInterval * HalpNumberOfTicks;
   }

   Status = STATUS_SUCCESS;
   return Status;
}


NTSTATUS
HalpProfileSourceInterval (
    OUT PVOID   Buffer,
    IN  ULONG   BufferLength
    )
/*++

Routine Description:

    Returns the HAL_PROFILE_SOURCE_INTERVAL for this processor.

Arguments:

    Buffer - output buffer
    BufferLength - length of buffer on input

Return Value:

    STATUS_SUCCESS
    STATUS_BUFFER_TOO_SMALL - The ReturnedLength contains the buffersize
        currently needed.

--*/
{
   PHAL_PROFILE_SOURCE_INTERVAL Interval;
   NTSTATUS Status;


   if (BufferLength != sizeof(HAL_PROFILE_SOURCE_INTERVAL)) {
       Status = STATUS_INFO_LENGTH_MISMATCH;
       return Status;
   }

   Interval = (PHAL_PROFILE_SOURCE_INTERVAL)Buffer;
   Status = HalSetProfileSourceInterval(Interval->Source,
                                        &Interval->Interval);
   return Status;
}


VOID
HalpInitializeProfiler(
    VOID
    )
/*++

Routine Description:

    Initialize the profiler by setting initial values and connecting
    the profile interrupt.

Arguments:

    InterfaceType - Supplies the interface type of the bus on which the
                    profiler will be connected.

    BusNumber - Supplies the number of the bus on which the profiler will
                be connected.

    BusInterruptLevel - Supplies the bus interrupt level to connect the
                profile interrupt.

Return Value:

    None.

--*/
{
    KAFFINITY Affinity;
    KIRQL Irql;
    ULONG Vector;

    //
    // Get the interrupt vector and synchronization Irql.
    //

    Vector = HalGetInterruptVector( Eisa,
                                    0,
                                    0,
                                    0,
                                    &Irql,
                                    &Affinity );

    IoConnectInterrupt( &HalpProfileInterruptObject,
                        (PKSERVICE_ROUTINE)HalpProfileInterrupt,
                        NULL,
                        NULL,
                        Vector,
                        Irql,
                        Irql,
                        Latched,
                        FALSE,
                        Affinity,
                        FALSE );

    return;
}


BOOLEAN
HalpProfileInterrupt(
    PKSERVICE_ROUTINE InterruptRoutine,
    PVOID ServiceContext,
    PKTRAP_FRAME TrapFrame
    )
/*++

Routine Description:

    This routine is entered as a result of an interrupt generated by
    the profile timer. Its function is to acknowlege the interrupt and
    transfer control to the standard system routine to update the
    system profile time.

Arguments:

    InterruptRoutine - not used.

    ServiceContext - not used.

    TrapFrame - Supplies a pointer to the trap frame for the profile interrupt.

Returned Value:

    None

--*/
{

    //
    // See if profiling is active
    //

    if ( HAL_PCR->ProfileCount ) {

        //
        // Check to see if the interval has expired
        // If it has then call the kernel routine for profile
        // and reset the count, else return.


        if ( !(--HAL_PCR->ProfileCount) ) {

            KeProfileInterrupt( TrapFrame );
            HAL_PCR->ProfileCount = HalpNumberOfTicks;

        }
    }

    return TRUE;

}


BOOLEAN
HalQueryProfileInterval(
    IN KPROFILE_SOURCE ProfileSource
    )

/*++

Routine Description:

    Given a profile source, returns whether or not that source is
    supported.

Arguments:

    Source - Supplies the profile source

Return Value:

    TRUE - Profile source is supported

    FALSE - Profile source is not supported

--*/

{
  if (ProfileSource == ProfileTime)
    return(TRUE);
  else
    return(FALSE);
}


NTSTATUS
HalSetProfileSourceInterval(
    IN KPROFILE_SOURCE ProfileSource,
    IN OUT ULONG *Interval
    )

/*++

Routine Description:

    Sets the profile interval for a specified profile source

Arguments:

    ProfileSource - Supplies the profile source

    Interval - Supplies the specified profile interval
               Returns the actual profile interval

Return Value:

    NTSTATUS

--*/

{
  if (ProfileSource != ProfileTime)
    return(STATUS_NOT_IMPLEMENTED);

  //
  // Set the interval.
  //

  *Interval = HalSetProfileInterval(*Interval);

  //
  // We're done.
  //

  return(STATUS_SUCCESS);
}


ULONG
HalSetProfileInterval (
    IN ULONG Interval
    )

/*++

Routine Description:

    This routine sets the profile interrupt interval.

Arguments:

    Interval - Supplies the desired profile interval in 100ns units.

Return Value:

    The actual profile interval.

--*/

{

    HalpProfileInterval = (Interval/16) * PROFILE_TIMER_1600NS_TICKS;

    HalpProfileInterval = ( HalpProfileInterval < MIN_PROFILE_TICKS ) ?
				MIN_PROFILE_TICKS : HalpProfileInterval;

    return HalpProfileInterval * PROFILE_INTERVALS_PER_100NS;
}


VOID
HalStartProfileInterrupt (
    KPROFILE_SOURCE ProfileSource
    )

/*++

Routine Description:

    This routine turns on the profile interrupt.

    N.B. This routine must be called at PROCLK_LEVEL while holding the
        profile lock.

Arguments:

    None.

Return Value:

    None.

--*/

{

    if (ProfileSource != ProfileTime)
      return;

    //
    // Assume that we only need 1 clock tick before we collect data
    //

    HalpNumberOfTicks = 1;

    if ( HalpProfileInterval > MAX_PROFILE_TICKS ) {

	HalpNumberOfTicks = HalpProfileInterval / (MAX_PROFILE_TICKS / 4);
	HalpNumberOfTicks = 4 * HalpNumberOfTicks;
	HalpProfileInterval = MAX_PROFILE_TICKS / 4;

    }

    //
    // Set current profile count and interval.
    //

    HAL_PCR->ProfileCount = HalpNumberOfTicks;

    PIC_PROFILER_ON(HalpProfileInterval);

    return;
}


VOID
HalStopProfileInterrupt (
    KPROFILE_SOURCE ProfileSource
    )

/*++

Routine Description:

    This routine turns off the profile interrupt.

    N.B. This routine must be called at PROCLK_LEVEL while holding the
        profile lock.

Arguments:

    None.

Return Value:

    None.

--*/

{

    if (ProfileSource != ProfileTime)
      return;
  
    //
    // Clear the current profile count and turn off the profiler timer.
    //

    HAL_PCR->ProfileCount = 0;

    PIC_PROFILER_OFF();

    return;
}