| plan 9 kernel history: overview | file list | diff list |
1999/0421/port/tod.c (diff list | history)
| 1999/0227/sys/src/9/port/tod.c:31,41 – 1999/0421/sys/src/9/port/tod.c:31,41 (short | long | prev | next) | ||
| 1999/0225 | // constraints: // // 1) log2(1000000000<<s1) <= 63 | |
| 1999/0421 | // or s1 <= 32 // 2) accomodate 1 minute of ticks without overflow // or log2(((1000000000<<s1)/f)*((60*f)>>s2)) <= 63 // or log2(mult) + 6 + log2(f) - s2 <= 63 // or log2(mult) + log2(f) - 57 <= s2 | |
| 1999/0225 | // // by definition // | |
| 1999/0227/sys/src/9/port/tod.c:50,58 – 1999/0421/sys/src/9/port/tod.c:50,58 | ||
| 1999/0225 | // // Combining 2) and 4) we get // | |
| 1999/0421 | // 5) log2(f) - s2 + log2(f) - 57 <= s2 // or 2*log2(f) - 57 <= 2*s2 // or log2(f) - 28 <= s2 | |
| 1999/0225 | // // Combining 3) and 4) // | |
| 1999/0227/sys/src/9/port/tod.c:74,91 – 1999/0421/sys/src/9/port/tod.c:74,91 | ||
| 1999/0225 | // // for f = 267000000, log2(f) = 28 // | |
| 1999/0421 | // s2 = 0 // s1 = 26 | |
| 1999/0225 | // // for f = 2000000000, log2(f) = 31 // | |
| 1999/0421 | // s2 = 3 // s1 = 29 | |
| 1999/0225 | // // for f = 8000000000, log2(f) = 33 // | |
| 1999/0421 | // s2 = 5 // s1 = 31 | |
| 1999/0219 | // frequency of the tod clock #define TODFREQ 1000000000LL | |
| 1999/0227/sys/src/9/port/tod.c:97,103 – 1999/0421/sys/src/9/port/tod.c:97,102 | ||
| 1999/0225 | int s1; // time = ((ticks>>s2)*multiplier)>>(s1-s2) | |
| 1999/0219 | vlong multiplier; // ... | |
| 1999/0225 | int s2; // ... | |
| 1999/0219 | vlong hz; // frequency of fast clock vlong last; // last reading of fast clock vlong off; // offset from epoch to last | |
| 1999/0227/sys/src/9/port/tod.c:148,163 – 1999/0421/sys/src/9/port/tod.c:147,161 | ||
| 1999/0219 | ilock(&tod); tod.hz = f; | |
| 1999/0225 | lf = log2(f); | |
| 1999/0421 | tod.s2 = lf - 28; | |
| 1999/0225 | if(tod.s2 < 0) tod.s2 = 0; tod.s1 = 2*lf - tod.s2 - 30; if(tod.s1 < 0) tod.s1 = 0; | |
| 1999/0421 | if(tod.s1 > 32) tod.s1 = 32; | |
| 1999/0225 | tod.multiplier = (TODFREQ<<tod.s1)/f; | |
| 1999/0219 | iunlock(&tod); } | |
| 1999/0227/sys/src/9/port/tod.c:219,229 – 1999/0421/sys/src/9/port/tod.c:217,225 | ||
| 1999/0225 | x = ((diff>>tod.s2)*tod.multiplier)>>(tod.s1-tod.s2); | |
| 1999/0219 | x += tod.off; | |
| 1999/0225 |
| |
| 1999/0219 |
| |
| 1999/0421 | // protect against overflows (gettod is called at least once a second) tod.last = ticks; tod.off = x; | |
| 1999/0219 | /* time can't go backwards */ if(x < tod.lasttime) | |