public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr@ncbi.nlm.nih.gov>
To: David Allsopp <David.Allsopp@cl.cam.ac.uk>,
	"cygwin-patches@cygwin.com" <cygwin-patches@cygwin.com>
Subject: RE: Fix nanosleep returning negative rem
Date: Wed, 21 Jul 2021 17:57:30 +0000	[thread overview]
Message-ID: <DM8PR09MB709596AB900FED8AE7BB23A7A5E39@DM8PR09MB7095.namprd09.prod.outlook.com> (raw)
In-Reply-To: <2271051beb734ce984ed71eab4180746@metastack.com>

> I can get it easily get this on my desktop (AMD Ryzen Threadripper 3990X) but not at all on my laptop (Intel Core i7-8650U)

Not sure if that's really related but:

Have you checked what is your default Windows timer resolution?  Some applications change it from the default
100HZ to 1000HZ (by e.g. using timeBeginPeriod(1) -- MS Edge does this, and Chrome, I think, but not Firefox -- yet
the change is actually _global_ as documented).

The following code shows the timer resolution:

#include <windows.h>
#include <timeapi.h>
#include <stdio.h>
#include <synchapi.h>

int main()
{
    unsigned int prev = timeGetTime(), next;
    Sleep(1);
    next = timeGetTime();
    printf("Sleep(1) = %u\n", next - prev);
    return 0;
}

Output:

Sleep(1) = 10
means the default 100HZ

Sleep(1) = 1
means the increased resolution of 1ms

Anton Lavrentiev
Contractor NIH/NLM/NCBI

P.S. timeBeginPeriod():

This function affects a global Windows setting. Windows uses the lowest value (that is, highest
resolution) requested by any process. Setting a higher resolution can improve the accuracy of
time-out intervals in wait functions. However, it can also reduce overall system performance,
because the thread scheduler switches tasks more often. High resolutions can also prevent the
CPU power management system from entering power-saving modes.

  reply	other threads:[~2021-07-21 17:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-20 15:16 David Allsopp
2021-07-21  8:39 ` Corinna Vinschen
2021-07-21  9:07   ` David Allsopp
2021-07-21  9:30     ` Corinna Vinschen
2021-07-21  9:33       ` Corinna Vinschen
2021-07-21 16:02         ` David Allsopp
2021-07-21 17:57           ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] [this message]
2021-07-22  8:01           ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM8PR09MB709596AB900FED8AE7BB23A7A5E39@DM8PR09MB7095.namprd09.prod.outlook.com \
    --to=lavr@ncbi.nlm.nih.gov \
    --cc=David.Allsopp@cl.cam.ac.uk \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).