系統(tǒng)之家 - 系統(tǒng)光盤(pán)下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux變量jiffies用法

Linux全局變量jiffies的用法

時(shí)間:2015-01-14 17:23:30 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪(fǎng)問(wèn): https://m.xitongzhijia.net/xtjc/20150114/34867.html 手機(jī)查看 評(píng)論

  jiffies是Linux系統(tǒng)中的全局變量,與時(shí)間有關(guān),那么jiffies變量具體有哪些作用呢?下面小編就給大家介紹下Linux全局變量jiffies的用法,感興趣的朋友不妨來(lái)了解下吧。

 Linux全局變量jiffies的用法

  系統(tǒng)運(yùn)行時(shí)間以秒為單位,等于jiffies/Hz。

  注意,jiffies類(lèi)型為無(wú)符號(hào)長(zhǎng)整型(unsigned long),其他任何類(lèi)型存放它都不正確。

  將以秒為單位的時(shí)間轉(zhuǎn)化為jiffies:

  seconds * Hz

  將jiffies轉(zhuǎn)化為以秒為單位的時(shí)間:

  jiffies / Hz

  相比之下,內(nèi)核中將秒轉(zhuǎn)換為jiffies用的多些。

  jiffies的內(nèi)部表示

  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)腳本用于連接主內(nèi)核映像(在x86上位于arch/i386/kernel/vmlinux.lds.S中),然后用jiffies_64變量的初值覆蓋jiffies變量。因此jiffies取整個(gè)jiffies_64變量的低32位。

  訪(fǎng)問(wèn)jiffies的代碼只會(huì)讀取jiffies_64的低32位,通過(guò)get_jiffies_64()函數(shù)就可以讀取整個(gè)64位的值。在64位體系結(jié)構(gòu)上,jiffies_64和jiffies指的是同一個(gè)變量。

  #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

  當(dāng)jiffies的值超過(guò)它的最大存放范圍后就會(huì)發(fā)生溢出。對(duì)于32位無(wú)符號(hào)長(zhǎng)整型,最大取值為(2^32)-1,即429496795。如果節(jié)拍計(jì)數(shù)達(dá)到了最大值后還要繼續(xù)增加,它的值就會(huì)回繞到0。

  內(nèi)核提供了四個(gè)宏來(lái)幫助比較節(jié)拍計(jì)數(shù),它們能正確的處理節(jié)拍計(jì)數(shù)回繞的問(wèn)題:

  /*

  * 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) /

 。╰ypecheck(unsigned long, a) && /

  typecheck(unsigned long, b) && /

 。ǎ╨ong)(b) - (long)(a) 《 0))

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

  #define time_after_eq(a,b) /

 。╰ypecheck(unsigned long, a) && /

  typecheck(unsigned long, b) && /

 。ǎ╨ong)(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) /

 。╰ypecheck(__u64, a) && /

  typecheck(__u64, b) && /

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

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

  用戶(hù)空間和HZ

標(biāo)簽 變量

發(fā)表評(píng)論

0

沒(méi)有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解

立即評(píng)論

以上留言?xún)H代表用戶(hù)個(gè)人觀(guān)點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

熱門(mén)教程

人氣教程排行

Linux系統(tǒng)推薦

掃碼關(guān)注
掃碼關(guān)注

掃碼關(guān)注 官方交流群 軟件收錄