WheeelTimer定时器

WhellTimer定时器
enum
{
WHEEL_BUCKETS = 4,
TVN_BITS = 6,                   // time vector level shift bits
TVR_BITS = 8,                   // timer vector shift bits
TVN_SIZE = (1 << TVN_BITS),     // wheel slots of level vector
TVR_SIZE = (1 << TVR_BITS),     // wheel slots of vector
TVN_MASK = (TVN_SIZE - 1),      //
TVR_MASK = (TVR_SIZE - 1),      //

MAX_TVAL = ((uint64_t)((1ULL << (TVR_BITS + 4 * TVN_BITS)) - 1)),
};

(实际上就是jiffies_的值,jiffies_在每个tick都会自增一次)

[0,256)   [0,TVR_SIZE)
[256,16384)  [TVR_SIZE, TVR_BITS + TVN_BITS)
[16384,1048576) [ TVR_BITS + TVN_BIT, TVR_BITS + 2*TVN_BITS)
[1048576,67108864)
[67108864,4294967296)

256 = 1 << 8
16384 = 1 << (8+6)
1048576 = 1 << (8+2*6)

39000在[16384,1048576)范围内,

(39000 >> (8+6)) & 63 = 2 等价于 39000 / 16384 % 64

(39000 >> 8) & 63 = 24 等价于 39000 / 256 % 64

39000 & 255 = 88 等价于 39000 % 256

7507 % 60 = 7
7507 / 60 % 60 = 5 (/ 60是为了求出有多少分钟,

7507 / 3600 = 2

256相当于秒针到分针的进率60,
64相当于分针到时针的进率60

39000 = 16384*2 + 256 * 24 + 88

39000转二进制                    1001100001011000
16384*2(即1 << (8+6))*2)转二进制 1000000000000000
(1 << 8) * 24  转二进制           0001100000000000
88  转二进制                     0000000001011000

32768在[16384,1048576)范围内,

(32768 >> (8+6)) & 63 = 2

(32768 >> 8) & 63 = 0

32768 & 255 = 0

32768 = 16384*2 + 256 * 0 + 0

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客