Unified · Split
| @@ -9,6 +9,7 @@ · 8 unmodified lines | |||
| 9 | #include <thread.h> | 9 | #include <thread.h> |
| 10 | #include <plumb.h> | 10 | #include <plumb.h> |
| 11 | #include <cursor.h> | 11 | #include <cursor.h> |
| 12 | #include <tos.h> | ||
| 12 | 13 | ||
| 13 | #define MIN(x,y) ((x)<=(y)?(x):(y)) | 14 | #define MIN(x,y) ((x)<=(y)?(x):(y)) |
| 14 | #define MAX(x,y) ((x)>=(y)?(x):(y)) | 15 | #define MAX(x,y) ((x)>=(y)?(x):(y)) |
| @@ -517,41 +518,21 @@ selext(int xdt, int ydt) · 502 unmodified lines | |||
| 517 | * nsec() is wallclock and can be adjusted by timesync | 518 | * nsec() is wallclock and can be adjusted by timesync |
| 518 | * so need to use cycles() instead, but fall back to | 519 | * so need to use cycles() instead, but fall back to |
| 519 | * nsec() in case we can't | 520 | * nsec() in case we can't |
| 520 | * | ||
| 521 | * "fasthz" is how many ticks there are in a second | ||
| 522 | * can be read from /dev/time | ||
| 523 | * | ||
| 524 | * perhaps using RDTSCP is even better | ||
| 525 | */ | 521 | */ |
| 526 | static uvlong | 522 | uvlong |
| 527 | nanosec(void) | 523 | nanosec(void) |
| 528 | { | 524 | { |
| 529 | static uvlong fasthz, xstart; | 525 | static uvlong fasthz, xstart; |
| 530 | uvlong x, div; | 526 | uvlong x, div; |
| 531 | int f, n, i; | ||
| 532 | char tmp[128], *e; | ||
| 533 | 527 | ||
| 534 | if (fasthz == ~0ULL) | 528 | if(fasthz == ~0ULL) |
| 535 | return nsec() - xstart; | 529 | return nsec() - xstart; |
| 536 | 530 | ||
| 537 | if (fasthz == 0) { | 531 | if(fasthz == 0){ |
| 538 | fasthz = ~0ULL; | ||
| 539 | xstart = nsec(); | 532 | xstart = nsec(); |
| 540 | if (usensec) | 533 | if((fasthz = _tos->cyclefreq) == 0){ |
| 541 | return 0; | 534 | fasthz = ~0ULL; |
| 542 | if ((f = open("/dev/time", OREAD)) >= 0 && (n = read(f, tmp, sizeof(tmp)-1)) > 2) { | 535 | fprint(2, "cyclefreq not available, falling back to nsec()\n"); |
| 543 | tmp[n] = 0; | ||
| 544 | e = tmp; | ||
| 545 | for (i = 0; i < 3; i++) | ||
| 546 | strtoll(e, &e, 10); | ||
| 547 | if ((fasthz = strtoll(e, nil, 10)) < 1) | ||
| 548 | fasthz = ~0ULL; | ||
| 549 | else | ||
| 550 | cycles(&xstart); | ||
| 551 | } | ||
| 552 | close(f); | ||
| 553 | if (fasthz == ~0ULL) { | ||
| 554 | fprint(2, "couldn't get fasthz, falling back to nsec()\n"); | ||
| 555 | fprint(2, "you might want to disable aux/timesync\n"); | 536 | fprint(2, "you might want to disable aux/timesync\n"); |
| 556 | return 0; | 537 | return 0; |
| 557 | } | 538 | } |
| @@ -559,7 +540,8 @@ nanosec(void) · 1 unmodified line | |||
| 559 | cycles(&x); | 540 | cycles(&x); |
| 560 | x -= xstart; | 541 | x -= xstart; |
| 561 | 542 | ||
| 562 | for (div = 1000000000ULL; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL); | 543 | /* this is ugly */ |
| 544 | for(div = 1000000000ULL; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL); | ||
| 563 | 545 | ||
| 564 | return x / (fasthz / div); | 546 | return x / (fasthz / div); |
| 565 | } | 547 | } |