简体   繁体   English

如何获得Linux内核的时间戳?

[英]how to get the timetamp for the linux kernel?

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

the above api is the receiver side api, which receives the data from the sender. 上面的api是接收方api,它从发送方接收数据。 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 上面的API在2993行是内核源代码,位于/linux/net/core/dev.c。
but I am getting ERROR: as struct sk_buff has no member named stamp. 但是我得到了错误:因为sk_buff结构没有名为stamp的成员。

http://lxr.free-electrons.com/source/include/linux/skbuff.h Could someone please help me : how to get the timestamp for linux kernel. http://lxr.free-electrons.com/source/include/linux/skbuff.h有人可以帮助我:如何获取Linux内核的时间戳。

Later I changed my code to : 后来我将代码更改为:

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

now I am getting error as : ktime_t has no memeber named "tv_sec". 现在我收到错误消息:ktime_t没有名为“ tv_sec”的成员。 struct timeval but argument is of type unio ktime_t. struct timeval,但参数的类型为unio ktime_t。

sk_buff->tstamp is variable of ktime_t type. sk_buff->tstampktime_t类型的变量。 do_gettimeofday sets time to variable of struct timeval . do_gettimeofday将时间设置为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);
    }
}

尝试使用tstamp代替stamp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM