| 1 | #include <inttypes.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <time.h>
|
|---|
| 5 |
|
|---|
| 6 | uint64_t nano_count()
|
|---|
| 7 | {
|
|---|
| 8 | struct timespec t;
|
|---|
| 9 | int ret;
|
|---|
| 10 | ret = clock_gettime(CLOCK_MONOTONIC,&t);
|
|---|
| 11 | if(ret != 0) {
|
|---|
| 12 | fprintf(stderr, "clock_gettime failed\n");
|
|---|
| 13 | exit(2);
|
|---|
| 14 | }
|
|---|
| 15 | return (uint64_t) t.tv_sec * 1000000000 + t.tv_nsec;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | int
|
|---|
| 19 | main()
|
|---|
| 20 | {
|
|---|
| 21 | uint64_t old_nanos = 0;
|
|---|
| 22 | for (;;) {
|
|---|
| 23 | uint64_t nanos = nano_count();
|
|---|
| 24 | if (nanos <= old_nanos) {
|
|---|
| 25 | fprintf(stderr, "!!! Clock is not monotonic: %lu >= %lu\n", old_nanos,
|
|---|
| 26 | nanos);
|
|---|
| 27 | exit(1);
|
|---|
| 28 | }
|
|---|
| 29 | old_nanos = nanos;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|