ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÄÚºËÖеÄjiffies

·¢²¼Ê±¼ä:2007-03-30 00:54:44À´Ô´:ºìÁª×÷Õß:DearMichael
¡¡¡¡Ó²¼þ¸øÄÚºËÌṩһ¸öϵͳ¶¨Ê±Æ÷ÓÃÒÔ¼ÆËãºÍ¹ÜÀíʱ¼ä£¬ÄÚºËͨ¹ý±à³ÌÔ¤Éèϵͳ¶¨Ê±Æ÷µÄƵÂÊ£¬¼´½ÚÅÄÂÊ£¨tick rate),ÿһ¸öÖÜÆÚ³Æ×÷Ò»¸ötick(½ÚÅÄ£©¡£LinuxÄں˴Ó2.5°æÄں˿ªÊ¼°ÑƵÂÊ´Ó100µ÷¸ßµ½1000£¨µ±È»´øÀ´Á˺ܶàÓŵ㣬ҲÓÐһЩȱµã£©.

¡¡¡¡jiffiesÊÇÄÚºËÖеÄÒ»¸öÈ«¾Ö±äÁ¿£¬ÓÃÀ´¼Ç¼×ÔϵͳÆô¶¯Ò»À´²úÉúµÄ½ÚÅÄÊý¡£Æ©È磬Èç¹û¼ÆËãϵͳÔËÐÐÁ˶೤ʱ¼ä£¬¿ÉÒÔÓà jiffies/tick rate À´¼ÆËã¡£jiffies¶¨ÒåÔÚÎļþÖУº

¡¡¡¡extern unsigned long volatile jiffies;

¿ÉÒÔÀûÓÃjiffiesÉèÖó¬Ê±µÈ£¬Æ©È磺
unsigned long timeout = jiffies + tick_rate * 2; // 2ÃëÖÓºó³¬Ê±


if(time_before(jiffies, timeout){
// »¹Ã»Óг¬Ê±

}
else{
// ÒѾ­³¬Ê±

}

¡¡¡¡ÄÚºËÌṩÁËËĸöºêÀ´±È½Ï½ÚÅļÆÊý£¬ÕâЩºê¶¨ÒåÔÚÎļþÖУº

time_before(unknown, known)
time_after(unknown, known)
time_before_eq(unknown, known)
time_after_eq(unknown, known)

¡¡¡¡±È½ÏµÄʱºòÓÃÕâЩºê¿ÉÒÔ±ÜÃâjiffiesÓÉÓÚ¹ý´óÔì³ÉµÄ»ØÈÆÎÊÌâ¡£

¡¡¡¡³ýÁËϵͳ¶¨Ê±Æ÷Í⣬»¹ÓÐÒ»¸öÓëʱ¼äÓйصÄʱÖÓ£ºÊµÊ±Ê±ÖÓ£¨RTC£©£¬ÕâÊÇÒ»¸öÓ²¼þʱÖÓ£¬ÓÃÀ´³Ö¾Ã´æ·Åϵͳʱ¼ä£¬ÏµÍ³¹Ø±Õºó¿¿Ö÷°åÉϵÄ΢Ð͵ç³Ø±£³Ö¼Æʱ¡£ÏµÍ³Æô¶¯Ê±£¬ÄÚºËͨ¹ý¶ÁÈ¡RTCÀ´³õʼ»¯Wall Time,²¢´æ·ÅÔÚxtime±äÁ¿ÖУ¬ÕâÊÇRTC×îÖ÷ÒªµÄ×÷Óá£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ