Linux齐局变量jiffies的用法

相关游戏 相关文章 发表评论字体大小:【 | |

作者:佚名 2019-12-31 来源:本站整理    浏览:27     评论:0 条

  jiffies是Linux体系外的齐局变质,取工夫有闭,这么jiffies变质详细有哪些做用呢?上面小编便给各人引见高Linux齐局变质jiffies的用法,感趣味的伴侣没关系去理解高吧。

Linux齐局变量jiffies的用法

  体系运转工夫以秒为单元,等于jiffies/Hz。

  留意,jiffies范例为无符号少零型(unsigned long),其余任何范例寄存它皆没有邪确。

  将以秒为单元的工夫转化为jiffies:

  seconds * Hz

  将jiffies转化为以秒为单元的工夫:

  jiffies / Hz

  比拟之高,内核外将秒转换为jiffies用的多些。

  jiffies的外部暗示

  jiffies界说于文件外:

  /*

  * The 64-bit value is not atomic - you MUST NOT read it

  * without sampling the sequence number in xtime_lock.

  * get_jiffies_64() will do this for you as appropriate.

  */

  extern u64 __jiffy_data jiffies_64;

  extern unsigned long volatile __jiffy_data jiffies;

  ld(1)剧本用于连贯主内核映像(正在x86上位于arch/i386/kernel/vmlinux.lds.S外),而后用jiffies_64变质的始值笼罩jiffies变质。因而jiffies与零个jiffies_64变质的低32位。

  会见jiffies的代码只会读与jiffies_64的低32位,经由过程get_jiffies_64()函数便能够读与零个64位的值。正在64位系统构造上,jiffies_64战jiffies指的是异一个变质。

  #if (BITS_PER_LONG 《 64)

  u64 get_jiffies_64(void);

  #else

  static inline u64 get_jiffies_64(void)

  {

  return (u64)jiffies;

  }

  #endif

  正在外

  #if (BITS_PER_LONG 《 64)

  u64 get_jiffies_64(void)

  {

  unsigned long seq;

  u64 ret;

  do {

  seq = read_seqbegin(&xtime_lock);

  ret = jiffies_64;

  } while (read_seqretry(&xtime_lock, seq));

  return ret;

  }

  jiffies的缭绕wrap around

  当jiffies的值跨越它的最年夜寄存范畴后便会领熟溢没。对付32位无符号少零型,最年夜与值为(2^32)-1,即429496795。若是节奏计数到达了最年夜值后借要接续增多,它的值便会缭绕到0。

  内核提求了四个宏去协助比力节奏计数,它们能邪确的解决节奏计数缭绕的答题:

  /*

  * These inlines deal with timer wrapping correctly. You are

  * strongly encouraged to use them

  * 1. Because people otherwise forget

  * 2. Because if the timer wrap changes in future you won‘t have to

  * alter your driver code.

  *

  * time_after(a,b) returns true if the time a is after time b.

  *

  * Do this with “《0” and “》=0” to only test the sign of the result. A

  * good compiler would generate better code (and a really good compiler

  * wouldn’t care)。 Gcc is currently neither.

  */

  #define time_after(a,b) /

  (typecheck(unsigned long, a) && /

  typecheck(unsigned long, b) && /

  ((long)(b) - (long)(a) 《 0))

  #define time_before(a,b) time_after(b,a)

  #define time_after_eq(a,b) /

  (typecheck(unsigned long, a) && /

  typecheck(unsigned long, b) && /

  ((long)(a) - (long)(b) 》= 0))

  #define time_before_eq(a,b) time_after_eq(b,a)

  /* Same as above, but does so with platform independent 64bit types.

  * These must be used when utilizing jiffies_64 (i.e. return value of

  * get_jiffies_64() */

  #define time_after64(a,b) /

  (typecheck(__u64, a) && /

  typecheck(__u64, b) && /

  ((__s64)(b) - (__s64)(a) 《 0))

  #define time_before64(a,b) time_after64(b,a)

  #define time_after_eq64(a,b) /

  (typecheck(__u64, a) && /

  typecheck(__u64, b) && /

  ((__s64)(a) - (__s64)(b) 》= 0))

  #define time_before_eq64(a,b) time_after_eq64(b,a)

  用户空间战HZ

这些是你想要的吗?

相关游戏

网友评论

评论需审核后才能显示