none
How does the GetProcessTimes() API works...? RRS feed

  • Question

  • No matter what value I specify for s_cpu_budget(1, 5, 10 , 12, 15), the loop breaks up only after 15.625 msec.

    The next number for s_cpu_budget is 30 where I can see the change, In between 15 to 30 there is no impact. 

    Does it work at the multiples of 15..? What change I have to make for this logic to break at 10msec...?

       

    int s_cpu_budget = 15;
    FILETIME ft1, ft2, ft3, current_time, start_time;
    ULARGE_INTEGER current_time_int, start_time_int;
    const unsigned int FT_TO_MS = 10000;

    GetProcessTimes(GetCurrentProcess(), &ft1, &ft2, &ft3, &start_time);
    start_time_int.HighPart = start_time.dwHighDateTime;
    start_time_int.LowPart = start_time.dwLowDateTime;
    Sleep(s_cpu_budget);

    while (true)
    {
    GetProcessTimes(GetCurrentProcess(), &ft1, &ft2, &ft3, &current_time);
    current_time_int.HighPart = current_time.dwHighDateTime;
    current_time_int.LowPart = current_time.dwLowDateTime;
    if (((current_time_int.QuadPart - start_time_int.QuadPart) / FT_TO_MS) >= s_cpu_budget)
    break; // Breaks only after 15.625 msec

    Sleep(1);
    }

    Tuesday, October 15, 2019 9:30 AM

All replies

  • >Does it work at the multiples of 15..? What change I have to make for this logic to break at 10msec...?

    Yes, 15ms is the default - see here https://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/

    Dave

    Tuesday, October 15, 2019 10:13 AM
  • Yes.  The system scheduler runs at a fixed interval.  That interval varies depending on the Windows version (meaning past versions using a different number, and servers use a different number from the workstations), but 15.625ms is the most common value.  When you do "Sleep(1)", that only means that your process becomes ELIGIBLE to run after 1 ms.  The scheduler won't go back to re-evaluate the priorities until its next interval.  Windows is not a real-time operating system.

    What are you really trying to do here?  What is your overall goal?  There are ways to get more accurate timestamps, but they are expensive, and they still won't help with the situation you have above.  It is possible to change the scheduler interval using beginTimePeriod and endTimePeriod, but that changes the interval system-wide, which increases the system overhead considerably.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, October 15, 2019 5:20 PM
  • It's a multi threaded process and this thread is the controller for other threads.
    It starts all other threads, then waits for "SOMETIME" to give time for other threads to execute and then suspend all threads.
    Increments a frame number needed for synchronization and again starts all the thread and this loop goes on.

    That "SOMETIME" which I need is 10msec, but it actually waits for 15.625msec.
    I use GetProcessTimes() because I also have to debug other threads using breakpoints. 
    Other API's are not giving me this flexibility but they are precise.
    Tuesday, October 15, 2019 6:33 PM