Linux内核中的时间戳错误? [英] timestamp error in linux kernel?

查看:531
本文介绍了Linux内核中的时间戳错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int netif_rx(struct sk_buff *skb) 
{
if(skb -> stamp.tv_sec ==0)
do_gettimeofday(&skb->stamp);
}

上述api是接收方api,它从发送方接收数据.我想计算接收数据并将其存储在缓冲区中的时间.上面的API在第2993行可以在内核源代码中找到:/linux/net/core/dev.c 但是我收到错误消息:因为sk_buff结构没有名为stamp的成员.

the above api is the receiver side api, which receives the data from the sender. I want to calculate t he time when it receives the data and store it in a buffer. the above api at line number 2993 is available in kernel source code at: /linux/net/core/dev.c but I am getting ERROR: as struct sk_buff has no member named stamp.

http://lxr.free-electrons.com/source/include/linux/skbuff.h 有人可以帮助我:如何获取Linux内核的时间戳.

http://lxr.free-electrons.com/source/include/linux/skbuff.h Could someone please help me : how to get the timestamp for linux kernel.

后来我将代码更改为:

 int netif_rx(struct sk_buff *skb) 
    {
    if(skb -> tstamp.off_sec ==0)
    do_gettimeofday(&skb->tstamp);
    }

1: http://www.fsl.cs.sunysb. edu/kernel-api/re498.html

2: -------------------------在第81 -----------------行中进行检查-----------------------------

-------------------------check this at line 81----------------------------------------------

现在我收到错误消息,因为:ktime_t没有名为"tv_sec"的成员. struct timeval,但参数的类型为unio ktime_t.

now I am getting error as : ktime_t has no memeber named "tv_sec". struct timeval but argument is of type unio ktime_t.

推荐答案

sk_buff->tstampktime_t类型的变量. do_gettimeofday将时间设置为struct timeval的变量.您在这里有不同的类型,因此需要进行转换.一个简单的例子是:

sk_buff->tstamp is variable of ktime_t type. do_gettimeofday sets time to variable of struct timeval. You have different types here and so you need a conversion. A simple one would be:

int netif_rx(struct sk_buff *skb) 
{
    if(skb -> tstamp.off_sec ==0)
    {
        struct timespec now;
        getnstimeofday(&now);
        skb->tstamp = timespec_to_ktime(now);
    }
}

修改: 如果您只想为套接字缓冲区添加时间戳,则可以调用 __net_timestamp

If you just want to timestamp socket buffer you can call __net_timestamp

int netif_rx(struct sk_buff *skb) 
{
    __net_timestamp(skb);
}

或者,如果您不能拨打__net_timestamp,也可以手动进行:

Or if you can't call __net_timestamp you can do it by your hands:

int netif_rx(struct sk_buff *skb) 
{
    skb->tstamp = ktime_get_real();
}

这篇关于Linux内核中的时间戳错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆