[Bug 262273] Subsuquent Calls to clock_gettime(CLOCK_THREAD_CPUTIME_ID,... ) return time in the past

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 01 Mar 2022 13:59:11 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262273

            Bug ID: 262273
           Summary: Subsuquent Calls to
                    clock_gettime(CLOCK_THREAD_CPUTIME_ID,... ) return
                    time in the past
           Product: Base System
           Version: Unspecified
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: donaldsharp72@gmail.com

When I run:
```
#include <stdio.h>
#include <time.h>

void main(void)
{
        struct timespec before, after;

        while (1) {
                clock_gettime(CLOCK_THREAD_CPUTIME_ID, &before);
                clock_gettime(CLOCK_THREAD_CPUTIME_ID, &after);

                printf("before: %lu:%lu after %lu:%lu\n",
                        before.tv_sec, before.tv_nsec,
                        after.tv_sec, after.tv_nsec);

                if (after.tv_nsec < before.tv_nsec)
                        exit(-1);
        }
}
```

I get this output:

before: 0:18195000 after 0:18198000
before: 0:26005000 after 0:18258000

The after time is prior to the before time.

I am running on 12.1-Release in a vm on a ryzen 3900x.  I also asked a friend
to run it on bare metal and got the same issue:
before: 0:444288000 after 0:444288000
before: 0:446097000 after 0:444290000

They are running on FreeBSD 12.3-STABLE stable/12-n163-259bedb8f

It is my expectation that there should not be jumps backwards in time.  Is my
assumption incorrect?

-- 
You are receiving this mail because:
You are the assignee for the bug.