tsnlab / libtsn

TSN library for C
GNU General Public License v3.0
5 stars 3 forks source link

Implement HW/SW TX timestamp feature #37

Closed tribela closed 1 year ago

tribela commented 1 year ago

Even if failed to set HW TX timestamp, SW TX timestamp is still can be used.

This PR produces these functions:

example code:

use std::env;

fn main() {
    let args = env::args().collect::<Vec<String>>();
    if args.len() != 2 {
        println!("Usage: {} <iface>", args[0]);
        return;
    }
    let iface = &args[1];

    let mut sock = match tsn::sock_open(iface, 10, 3, 0x0003) {
        Ok(sock) => sock,
        Err(e) => {
            eprintln!("Error: {}", e);
            return;
        }
    };

    if sock.enable_tx_timestamp().is_err() {
        eprintln!("Error: failed to enable tx timestamp");
        return;
    }

    let buf = [0u8; 1024];

    sock.send(&buf);
    let ts = sock.get_tx_timestamp().unwrap();

    println!("tx timestamp: {:?}", ts);

    if let Err(err) = sock.close() {
        eprintln!("Error: {}", err);
    };
}
SikYoon7 commented 1 year ago

I wonder how much time difference will occur between HW and SW(Kernel) timestamp roughly? Could you give some description or example measurement with an available target board?

tribela commented 1 year ago

I wonder how much time difference will occur between HW and SW(Kernel) timestamp roughly? Could you give some description with an available target board?

I never seen that both HW and SW timestamping support in one NIC. AIK, SW(kernel) timestamp is when the kernel sends packet to NIC(HW), HW timestamp is when the NIC sends packet to outer port.

Kontron NIC and the NIC used on NXP switch(IDK what vendor used on this) has HW timestamping support without SW timestamping My Realtek NIC has SW timestaming support without HW timstamping