Sumon
Sumon

Reputation: 11

My driver is `igc` for the ethernet interface. How to get timestamp in ebpf-XDP program?

The fact is i am a beginner in such programming. How can I get timestamp in the xdp program. A detail step by step instruction would be helpful for me. Right now, even I linked the the header library in the makefile with -l flag but it is not working. Echoing the path

Receive nic rx timestamp for every rx packet.

Upvotes: 1

Views: 200

Answers (1)

Dylan Reimerink
Dylan Reimerink

Reputation: 7968

In kernel v6.3 the bpf_xdp_metadata_rx_timestamp kfunc was added which adds exactly this functionality.

In kernek v6.5 support for the igc driver was added.

According to example code found in the kernel selftests this should work (disclaimer: have not personally tested this):

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
                     __u64 *timestamp) __ksym;

SEC("xdp")
int rx(struct xdp_md *ctx)
{
    __u64 rx_timestamp;
    int err;

    err = bpf_xdp_metadata_rx_timestamp(ctx, &rx_timestamp);
    if (err)
        return XDP_ABORTED;
    
    return XDP_PASS;
}

char _license[] SEC("license") = "GPL";

Note that before the addition of this kfunc this info is also available, but only in program that use __sk_buff contexts, so not XDP.

Upvotes: 0

Related Questions