曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 5997|回复: 0
打印 上一主题 下一主题

得到 jiffies_64 值 | get_jiffies_64()

[复制链接]

4917

主题

5879

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34382
跳转到指定楼层
楼主
发表于 2011-4-20 20:26:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
内核:2.6.38.2
在 64 位的计算机架构上,jiffies 和 jiffies_64 是同一个变量。但在 32 位的处理器上,对 64 位的值的访问不是原子的,也就是说,在读取 64 位值的高 32 位和低 32 位这段时间间隔里,可能会再次发生更新,从而获得错误的值。因此,对 64 为计数器的直接读取是靠不住的。但如果必须读取 64 位计数器,那么就应该使用 get_jiffies_64() 这个特殊的辅助函数,它声明在 linux/jiffies.h 中:
[C++] 纯文本查看 复制代码
/* some arch's have a small-data section that can be accessed register-relative
 * but that can only take up to, say, 4-byte variables. jiffies being part of
 * an 8-byte variable may not be correctly accessed unless we force the issue
 */
#define __jiffy_data  __attribute__((section(".data")))


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


#if (BITS_PER_LONG < 64)
u64 get_jiffies_64(void);
#else
static inline u64 get_jiffies_64(void)
{
    return (u64)jiffies;
}



上面 BITS_PER_LONG 小于 64 即表示是 32 位的平台。如果在 64 位平台上,就直接返回 jiffies,可见该变量和 jiffies_64 是同一个,此时 get_jiffies_64() 是个内联函数.
如果是在 32 位平台,则执行下面的函数体:

[C++] 纯文本查看 复制代码
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;
}


上面,read_seqbegin() 和 read_seqretry() 是顺序锁的通常使用方法,它们用来在 32 位平台上读取 64 位数据的原子性。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-16 20:28 , Processed in 0.094567 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表