Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Very short interval (like 10 microseconds) timer?

Michael_RolleMichael_Rolle Member - All Emails Posts: 135

I can hear some of you saying "Why would you want to do that? Windows is not a real-time operating system.'
However, since I want to access some on-board registers frequently, I can't use a TIMER because it can't fire more often than every 0.5 msec. It requires a kernel driver to get at the registers.
I don't intend my driver for public distribution, just as a performance measuring tool to run on my own computer.
The onboard hardware can generate an interrupt whenever there's something for the driver to know about. But I'm not sure I can safely hook an ISR to this interrupt. Hence the alternative of polling the hardware. Ideally I want to poll it at a 10 microsecond interval.
Some possibilities:
1. Use a high priority thread in my application that just checks the precise system time and every 10 usec it will send a control IRP to the driver. This is certainly doable on my 4-core computer.
2. Use the APIC timer on the CPU whose registers I want to get to, and hook an interrupt vector to the timer. This has the same problem as I would have hooking to the interrupt generated by the measurement hardware itself.
3. Take advantage of the HPET which (I think) is implemented on my AMD Ryzen 3. I tried bcdedit setting useplatformclock = yes, with the hope that ExQueryTimerResolution would give me a shorter interval, but it still showed min = 5000 (0.5 ms), and ExSetTimerResolution allowed me to set it to 4988. So apparently either HPET isn't on my system or Windows doesn't take advantage of it. Anyone have any tips about exploiting the HPET? Any documentation from AMD on how to access the HPET from a driver?
4. Is there some other way of using the kernel API to achieve the result?
5. Is there a driver somewhere that my driver could use to do this? Perhaps one that uses the APIC timer?

I'm hoping I don't have to put up with a 50 times slower sampling rate (as using KeSetTimer would provide), or wrestling with the interrupt vector issue.

BTW, I've posted other discussions here about connecting to the right interrupt vector.

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,428
    via Email
    Have you looked at KeStallExecutionProcessor?

    Bent from my phone
    ________________________________
    From: Michael_Rolle
    Sent: Monday, February 25, 2019 6:21:50 PM
    To: Doron Holan
    Subject: [NTDEV] Very short interval (like 10 microseconds) timer?

    OSR https://nam06.safelinks.protection.outlook.com/?url=https://community.osr.com/&data=02|01|[email protected]|d7ac847b54ae44f1c14608d69b912ac0|72f988bf86f141af91ab2d7cd011db47|1|1|636867445125196058&sdata=rW00hVrnv2kL2vW/jMgy8Ug9PvIijjjBcAy4u+sl2/c=&reserved=0
    Michael_Rolle started a new discussion: Very short interval (like 10 microseconds) timer?

    I can hear some of you saying "Why would you want to do that? Windows is not a real-time operating system.'

    However, since I want to access some on-board registers frequently, I can't use a TIMER because it can't fire more often than every 0.5 msec. It requires a kernel driver to get at the registers.

    I don't intend my driver for public distribution, just as a performance measuring tool to run on my own computer.

    The onboard hardware can generate an interrupt whenever there's something for the driver to know about. But I'm not sure I can safely hook an ISR to this interrupt. Hence the alternative of polling the hardware. Ideally I want to poll it at a 10 microsecond interval.

    Some possibilities:

    1. Use a high priority thread in my application that just checks the precise system time and every 10 usec it will send a control IRP to the driver. This is certainly doable on my 4-core computer.

    2. Use the APIC timer on the CPU whose registers I want to get to, and hook an interrupt vector to the timer. This has the same problem as I would have hooking to the interrupt generated by the measurement hardware itself.

    3. Take advantage of the HPET which (I think) is implemented on my AMD Ryzen 3. I tried bcdedit setting useplatformclock = yes, with the hope that ExQueryTimerResolution would give me a shorter interval, but it still showed min = 5000 (0.5 ms), and ExSetTimerResolution allowed me to set it to 4988. So apparently either HPET isn't on my system or Windows doesn't take advantage of it. Anyone have any tips about exploiting the HPET? Any documentation from AMD on how to access the HPET from a driver?

    4. Is there some other way of using the kernel API to achieve the result?

    5. Is there a driver somewhere that my driver could use to do this? Perhaps one that uses the APIC timer?

    I'm hoping I don't have to put up with a 50 times slower sampling rate (as using KeSetTimer would provide), or wrestling with the interrupt vector issue.

    BTW, I've posted other discussions here about connecting to the right interrupt vector.
    d
  • Michael_RolleMichael_Rolle Member - All Emails Posts: 135

    @Doron_Holan said:
    Have you looked at KeStallExecutionProcessor?

    I have now. I don't like it because it pretty much hogs a processor. I would be waiting my 10 usec repeatedly. I might as well (and it would be better to) do this in user-mode code.
    Your suggestion would have been OK if the driver only had to do it once in a while.
    Thanks.

  • Michael_RolleMichael_Rolle Member - All Emails Posts: 135

    My Ryzen does indeed have an HPET device in the device tree under ACPI\Microsoft ACPI-Compliant System. It has a 400h-sized memory range and two IRQs. There are no driver files. Whether there is any HAL or other system code that I could call is a mystery to me. Any ideas, anyone?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 25 Feb 2019 OSR Seminar Space
Developing Minifilters 8 April 2019 OSR Seminar Space