CAN Bus hardware timestamps don't come from the hardware
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- c
- Domain
- embedded-iot, operating-systems
Research direction
Start with drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c and mcp251xfd.h, reading the timestamp initialization and skb timestamp helper. Trace how the mcp2518fd hardware timestamp reaches the socket buffer and compare the clock bases used there. Done means the hardware timestamp is preserved, the time base is monotonic, and the previous receive-time replacement is removed.
Written by the indexing model from the issue text.
Description
The mcp251xfd driver has been patched to have the "hardware" timestamps be based on the monotonic clock, except it wipes away the hardware timestamp completely and replaces it with the current monotonic time at the time the packet is received by the driver:
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
index dcbbd2b2fae8273844bd1843209ecd5a2ed3a43c..5ee4672e48136f7de6bf06be0a14fe5d6468a1d3 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
@@ -825,7 +825,7 @@ static inline void mcp251xfd_skb_set_timestamp(struct sk_buff *skb, u64 ns)
{
struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb);
- hwtstamps->hwtstamp = ns_to_ktime(ns);
+ hwtstamps->hwtstamp = ktime_get_raw();
}
static inline
This means that there is nondeterministic latency between the actual reception time and the reported timestamp. Instead, the driver should be patched to keep the timestamp from the mcp2518fd hardware but switch the time base to the monotonic clock (and the previous patch should be reverted):
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
index 202ca0d24d03b9f5bebba23a9f8d0e6f6422c728..3b6b47cb09a4e09f1b25a8a339d7a837a527806a 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-timestamp.c
@@ -53,7 +53,7 @@ void mcp251xfd_timestamp_init(struct mcp251xfd_priv *priv)
void mcp251xfd_timestamp_start(struct mcp251xfd_priv *priv)
{
- timecounter_init(&priv->tc, &priv->cc, ktime_get_real_ns());
+ timecounter_init(&priv->tc, &priv->cc, ktime_get_ns());
schedule_delayed_work(&priv->timestamp,
MCP251XFD_TIMESTAMP_WORK_DELAY_SEC * HZ);
}
This patch also uses CLOCK_MONOTONIC, not CLOCK_MONOTONIC_RAW as the current patch does, since we're using CLOCK_MONOTONIC everywhere else.
- Dominant language
- Java
- Stars
- 190
- Forks
- 25
- Avg merge
- 6h 7m
- Merged PRs (30d)
- 13
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wpilibsuite/SystemcoreTesting
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
wpilibsuite/SystemcoreTesting#380 ·
Maintainers usually reply within 1 day
-
Limelight Pending
Difficulty 1/5 Under an hour Newbie friendliness 78/100
wpilibsuite/SystemcoreTesting#315 ·
Maintainers usually reply within 1 day
-
CAN FD not workingOpen
Difficulty 4/5 3-5 days Newbie friendliness 35/100
wpilibsuite/SystemcoreTesting#412 · 18 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
wpilibsuite/SystemcoreTesting#411 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
wpilibsuite/SystemcoreTesting#406 · 4 comments ·
Maintainers usually reply within 1 day
All issues in wpilibsuite/SystemcoreTesting
Similar issues
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opfab/operatorfabric-core#10653 ·
Maintainers usually reply within 1 day
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersPossibly taken @innoprej claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
salesforce/multicloudj#667 ·
Maintainers usually reply within 1 day
-
bug documentation
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MetricsHub/winrm-java#202 ·
Maintainers usually reply within 1 day
-
ASCN/cBioPortal Pipelines/cBioPortal
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mskcc/smile-server#1990 ·