读取链式计数器

Reading a chained counter

As the multiple 16b registers cannot be read atomically, a wrap from one value to the next can occur at any time, leading to an inconsistent readout of the current value. The usual procedure to overcome it is the following:

1. Read all 16b values of the chained CNT registers in the first set of variables, excluding the least significant CNT register
2. Read all 16b values again in the same order into a second set of variables, excluding the least significant CNT register
3. Compare the first set with the second set. If they differ, start again from the top.
4. Use the first set of variables as the consistent chained counter value.

This sequence exploits the fact that reads are much faster than the least significant counter can ever overflow. The likelihood of encountering an overflow during the read sequence is therefore low. If an overflow occurs it will be detected and the next attempt would then succeed to read all values without any overflows in the chain. Unconditionallu retrying on any difference is a necessity though as, for example, interrupts could affect the timing and add unexpected delays.

由于多个 16b 寄存器无法自动读取,因此随时可能发生从一个值到下一个值的回绕,从而导致当前值的读出不一致。克服它的通常过程如下:

1. 读取第一组变量中链接的 CNT 寄存器的所有 16b 值,不包括最低有效的 CNT 寄存器
2. 以相同的顺序再次将所有 16b 值读取到第二组变量中,不包括最低有效的 CNT 寄存器
3. 比较第一组和第二组。如果不同,则从顶部重新开始。
4. 使用第一组变量作为一致的链式计数器值。

该序列利用了这样一个事实:读取速度比最低有效计数器溢出的速度要快得多。因此,在读取序列期间遇到溢出的可能性很低。如果发生溢出,它将被检测到,并且下一次尝试将成功读取所有值,而链中不会发生任何溢出。无条件地重试任何差异是必要的,例如,中断可能会影响计时并增加意外的延迟。

你可能感兴趣的:(history)