内核统计信息的最大值-python

内核统计信息的最大值-python,python,c,linux,integer-overflow,iostat,Python,C,Linux,Integer Overflow,Iostat,问:内核统计计数器的最大值是多少?我如何在python代码中处理它 上下文:我根据内核统计信息计算一些统计信息(例如/proc/partitions——它将是定制的python iostat版本)。但是我有一个溢出值的问题-负值。原始iostat代码注释: * Counters overflows are possible, but don't need to be handled in * a special way: The difference is still properly calc

问:内核统计计数器的最大值是多少?我如何在python代码中处理它

上下文:我根据内核统计信息计算一些统计信息(例如/proc/partitions——它将是定制的python iostat版本)。但是我有一个溢出值的问题-负值。原始iostat代码注释:

* Counters overflows are possible, but don't need to be handled in
* a special way: The difference is still properly calculated if the
* result is of the same type as the two values.

我的语言是python,在我的例子中,我需要关心溢出问题。可能还取决于体系结构(32/64)。我尝试了2^64-1(64位系统),但没有成功。

以下函数适用于32位计数器:

def calc_32bit_diff(old, new):
  return (new - old + 0x100000000) % 0x100000000

print calc_32bit_diff(1, 42)
print calc_32bit_diff(2147483647, -2147483648)
print calc_32bit_diff(-2147483648, 2147483647)
这显然是行不通的,因为计数器在两次连续读取之间多次环绕(但由于信息已无法恢复地丢失,因此其他方法也无法工作)

编写此文件的64位版本留给读者作为练习。:)