Unified · Split
| @@ -9,6 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <thread.h> |
| 10 | 10 | #include <plumb.h> |
| 11 | 11 | #include <cursor.h> |
| 12 | +#include <tos.h> | |
| 12 | 13 | |
| 13 | 14 | #define MIN(x,y) ((x)<=(y)?(x):(y)) |
| 14 | 15 | #define MAX(x,y) ((x)>=(y)?(x):(y)) |
| @@ -517,41 +518,21 @@ selext(int xdt, int ydt) · 502 unmodified lines | ||
| 517 | 518 | * nsec() is wallclock and can be adjusted by timesync |
| 518 | 519 | * so need to use cycles() instead, but fall back to |
| 519 | 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 | 523 | nanosec(void) |
| 528 | 524 | { |
| 529 | 525 | static uvlong fasthz, xstart; |
| 530 | 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 | 529 | return nsec() - xstart; |
| 536 | 530 | |
| 537 | − if (fasthz == 0) { | |
| 538 | − fasthz = ~0ULL; | |
| 531 | + if(fasthz == 0){ | |
| 539 | 532 | xstart = nsec(); |
| 540 | − if (usensec) | |
| 541 | − return 0; | |
| 542 | − if ((f = open("/dev/time", OREAD)) >= 0 && (n = read(f, tmp, sizeof(tmp)-1)) > 2) { | |
| 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"); | |
| 533 | + if((fasthz = _tos->cyclefreq) == 0){ | |
| 534 | + fasthz = ~0ULL; | |
| 535 | + fprint(2, "cyclefreq not available, falling back to nsec()\n"); | |
| 555 | 536 | fprint(2, "you might want to disable aux/timesync\n"); |
| 556 | 537 | return 0; |
| 557 | 538 | } |
| @@ -559,7 +540,8 @@ nanosec(void) · 1 unmodified line | ||
| 559 | 540 | cycles(&x); |
| 560 | 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 | 546 | return x / (fasthz / div); |
| 565 | 547 | } |