Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HW/SW TX timestamp feature #37

Merged
merged 4 commits into from
May 26, 2023
Merged

Implement HW/SW TX timestamp feature #37

merged 4 commits into from
May 26, 2023

Conversation

tribela
Copy link
Contributor

@tribela tribela commented May 25, 2023

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

This PR produces these functions:

  • TsnSocket.enable_tx_timestamp()
    Enables TX timestamp feature
    Even if failed to set HW TX timestamp, SW(kernel) TX timestamp is still can be used on get_tx_timestamp() which is better than application level SW timestamp

  • TsnSocket.get_tx_timestamp()
    Use this function right after TsnSock.send() on TX timestamp enabled socket. It returns tsn::time::Timespec

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

Even if failed to set HW TX timestamp, SW TX timestamp is still can be
used.
@tribela tribela requested review from junppyo and SikYoon7 May 25, 2023 06:34
@SikYoon7
Copy link

SikYoon7 commented May 25, 2023

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
Copy link
Contributor Author

tribela commented May 25, 2023

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

src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@tribela tribela merged commit 65a26fe into main May 26, 2023
9 checks passed
@tribela tribela deleted the tx-timestamp branch May 26, 2023 01:29
junppyo pushed a commit that referenced this pull request May 30, 2023
* Implement HW TX timestamp

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

* Cargo fmt, Clippy

* Remove perror

* Remove print, fix typo
tribela added a commit that referenced this pull request Aug 30, 2023
* get rx, tx timestamp

* no more call SystemTime::now() on oneway mode

* fix cargo fmt

* Fix sock_open to return created vlan name instead of interface name (#32)

* Get rx timestamp from HW on latency app (#33)

* get rx, tx timestamp

* no more call SystemTime::now() on oneway mode

* fix cargo fmt

* print only rx timestamp

* fix fmt

* Revert "Fix sock_open to return created vlan name instead of interface name (#32)" (#35)

This reverts commit 2cec046.

* Implement HW/SW TX timestamp feature (#37)

* Implement HW TX timestamp

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

* Cargo fmt, Clippy

* Remove perror

* Remove print, fix typo

* change latency protocol (#36)

* change protocol

* fix fmt, clippy

* change server get rx by packet, clean code

* server identifies act as opcode

* store ts only last one and server don't get oneway parameter

* get SW timestamp immediately after receive the message

* clean code

* change opcode match in server

* error handling about negative elapsed time

* fix fmt, clippy

* server prints negative elapsed time

* simplify get tx_timestamp at packet

* fix fmt

* get HW tx_timestamp that apply to latency

* get rx, tx timestamp

* no more call SystemTime::now() on oneway mode

* merge hw_tx_timestamp

* Consume tx timestamp after sending SYNC packet

* Warn if SW TX timestamp is used

---------

Co-authored-by: Jeong Arm <kjwonmail@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants