timestamp error in linux kernel?

佐手、 提交于 2019-12-13 01:24:46

问题


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. 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 Could someone please help me : how to get the timestamp for linux kernel.

Later I changed my code to :

 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 : https://github.com/embest-tech/platform_prebuilt/blob/master/ndk/android-ndk-r7/platforms/android-4/arch-x86/usr/include/linux/skbuff.h

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

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


回答1:


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);
    }
}

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

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

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();
}



回答2:


You can do it this way

your_function(struct sk_buff *skb)
{
    struct timeval tv;

    do_gettimeofday(&tv);
    skb->tstamp = timeval_to_ktime(tv);
}

Have a look at this code mwifiex_hard_start_xmit function

On a side-note in most of the cases , you do not need to provide your own implementation of netif_rx



来源:https://stackoverflow.com/questions/23003449/timestamp-error-in-linux-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!