History

plan9: use _tos->cyclefreq instead of reading /dev/time

Sigrid Haflínudóttir committed 6 years ago

Commit b70bc701 parent febae881 file · +9 −27Browse files

Unified · Split

plan9.c+9−27
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <thread.h>
1010 #include <plumb.h>
1111 #include <cursor.h>
12+#include <tos.h>
1213
1314 #define MIN(x,y) ((x)<=(y)?(x):(y))
1415 #define MAX(x,y) ((x)>=(y)?(x):(y))
@@ -517,41 +518,21 @@ selext(int xdt, int ydt) · 502 unmodified lines
517518 * nsec() is wallclock and can be adjusted by timesync
518519 * so need to use cycles() instead, but fall back to
519520 * 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
525521 */
526−static uvlong
522+uvlong
527523 nanosec(void)
528524 {
529525 static uvlong fasthz, xstart;
530526 uvlong x, div;
531− int f, n, i;
532− char tmp[128], *e;
533527
534− if (fasthz == ~0ULL)
528+ if(fasthz == ~0ULL)
535529 return nsec() - xstart;
536530
537− if (fasthz == 0) {
538− fasthz = ~0ULL;
531+ if(fasthz == 0){
539532 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");
555536 fprint(2, "you might want to disable aux/timesync\n");
556537 return 0;
557538 }
@@ -559,7 +540,8 @@ nanosec(void) · 1 unmodified line
559540 cycles(&x);
560541 x -= xstart;
561542
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);
563545
564546 return x / (fasthz / div);
565547 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t