Forum > GPU crunching

Sleeping for less than 1ms in Windows - is it possible and how?

<< < (3/5) > >>

Raistmer:

--- Quote from: Urs Echternacht on 30 Oct 2013, 08:11:39 pm ---http://www.tutorials.de/c-c/229782-c-sleep-kleiner-als-ms-2.html#post1197886

--- End quote ---
Oh, I'm not too strong in Deutch now (unfortunately), but code sample looks familiar - similar code was in first references review. Again. Yes, it will wait fraction of ms, but with 100% or so CPU load cause constantly querying performance counter.

Raistmer:

--- Quote from: arkayn on 30 Oct 2013, 08:17:38 pm ---
--- Quote from: Urs Echternacht on 30 Oct 2013, 08:11:39 pm ---http://www.tutorials.de/c-c/229782-c-sleep-kleiner-als-ms-2.html#post1197886

--- End quote ---

And a translated page for Raistmer
http://translate.google.com/translate?sl=auto&tl=ru&js=n&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.tutorials.de%2Fc-c%2F229782-c-sleep-kleiner-als-ms-2.html%23post1197886&act=url

and Joe
http://translate.google.com/translate?hl=en&sl=de&tl=en&u=http%3A%2F%2Fwww.tutorials.de%2Fc-c%2F229782-c-sleep-kleiner-als-ms-2.html%23post1197886

--- End quote ---

thanks, but conclusion is no good:
"
Forget it under Windows
You can only access to the timer, the OS makes available the you. On Windows, the minimum 1ms
"

EDIT: LoL, they recall QNX... yeah, nice OS, but we need same on Windows....

Raistmer:

--- Quote from: Urs Echternacht on 30 Oct 2013, 08:34:03 pm ---Thanks Arkayn. (german does not translate very good into english when done by a machine! In this case "security" should read "computer"!  ;) )

Here is some POSIX source : nanosleep.c

Here is same for apple : nanosleep.c

Additionally there is a function "clock_nanosleep()" which allows to choose between different clocks on Linux. (real time, monotonic, other)

--- End quote ---

And again, saw same code in first searching trial (my comments in color):


--- Quote ---  want = u64 = request->tv_sec * POW10_3 + request->tv_nsec / POW10_6;
    while (u64 > 0 && rc == 0) {
        if (u64 >= MAX_SLEEP_IN_MS) ms = MAX_SLEEP_IN_MS;
        else ms = (unsigned long) u64;

        u64 -= ms;
        rc = SleepEx(ms, TRUE); //R: Sleep, but in ms scale
    }

    if (rc != 0) { /* WAIT_IO_COMPLETION (192) */
        if (remain != NULL) {
            GetSystemTimeAsFileTime(&_end.ft);
            real = (_end.ns100 - _start.ns100) / POW10_4;

            if (real >= want) u64 = 0;
            else u64 = want - real;

            remain->tv_sec = u64 / POW10_3;
            remain->tv_nsec = (long) (u64 % POW10_3) * POW10_6; //R: just report how many ns to sleep w/o real way to do such sleep
        }

--- End quote ---

Raistmer:
And initial suggestion that started this search:


--- Quote ---1) export LD_PRELOAD=libsleep.so

You would not have to reserve any physical or logigal cores for AP.
-- The 100% usage is only for yield() - an idle loop inside NVIDIA openCl driver. Libsleep.so replaces yield() with nanosleep. This gives lower proirity tasks (CPU tasks) an opportunity to run.
--- End quote ---

Obviously, we can't directly do the same cause can't use nanosleep Windows port to sleep lass than 1ms. Sleep(0) will do same as yield(). But attempting to do "nanosleep(0.1ms)" instead will lead to even more CPU-demanding loop cause prev nanosleep on Windows code will just return immediately with remaining sleep fraction of 0.1ms and loop will reiterate giving no context switch opportunity at all.

Urs Echternacht:
Read your own reference from first post a little bit more detailed. That person solved the problem of 100% CPU activity by combining QueryPerformanceCounters() with Sleep(0) and some other little tricks.

And, by the way, if it is possible to reduce the "active" wait time to some fraction of a millisecond, wouldn't that reduce the totals CPU and elapsed time, too ?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version