diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2009-02-12 00:03:37 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-02-16 01:43:34 -0500 |
commit | ac45f602ee3d1b6f326f68bc0c2591ceebf05ba4 (patch) | |
tree | c92c86bd0d89b844a3794c0e441aa2fccb36725f /include | |
parent | cb9eff097831007afb30d64373f29d99825d0068 (diff) |
net: infrastructure for hardware time stamping
The additional per-packet information (16 bytes for time stamps, 1
byte for flags) is stored for all packets in the skb_shared_info
struct. This implementation detail is hidden from users of that
information via skb_* accessor functions. A separate struct resp.
union is used for the additional information so that it can be
stored/copied easily outside of skb_shared_info.
Compared to previous implementations (reusing the tstamp field
depending on the context, optional additional structures) this
is the simplest solution. It does not extend sk_buff itself.
TX time stamping is implemented in software if the device driver
doesn't support hardware time stamping.
The new semantic for hardware/software time stamping around
ndo_start_xmit() is based on two assumptions about existing
network device drivers which don't support hardware time
stamping and know nothing about it:
- they leave the new skb_shared_tx unmodified
- the keep the connection to the originating socket in skb->sk
alive, i.e., don't call skb_orphan()
Given that skb_shared_tx is new, the first assumption is safe.
The second is only true for some drivers. As a result, software
TX time stamping currently works with the bnx2 driver, but not
with the unmodified igb driver (the two drivers this patch series
was tested with).
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/skbuff.h | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 924700844580..f96bc91bf0a3 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -132,6 +132,57 @@ struct skb_frag_struct { | |||
132 | __u32 size; | 132 | __u32 size; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | #define HAVE_HW_TIME_STAMP | ||
136 | |||
137 | /** | ||
138 | * skb_shared_hwtstamps - hardware time stamps | ||
139 | * | ||
140 | * @hwtstamp: hardware time stamp transformed into duration | ||
141 | * since arbitrary point in time | ||
142 | * @syststamp: hwtstamp transformed to system time base | ||
143 | * | ||
144 | * Software time stamps generated by ktime_get_real() are stored in | ||
145 | * skb->tstamp. The relation between the different kinds of time | ||
146 | * stamps is as follows: | ||
147 | * | ||
148 | * syststamp and tstamp can be compared against each other in | ||
149 | * arbitrary combinations. The accuracy of a | ||
150 | * syststamp/tstamp/"syststamp from other device" comparison is | ||
151 | * limited by the accuracy of the transformation into system time | ||
152 | * base. This depends on the device driver and its underlying | ||
153 | * hardware. | ||
154 | * | ||
155 | * hwtstamps can only be compared against other hwtstamps from | ||
156 | * the same device. | ||
157 | * | ||
158 | * This structure is attached to packets as part of the | ||
159 | * &skb_shared_info. Use skb_hwtstamps() to get a pointer. | ||
160 | */ | ||
161 | struct skb_shared_hwtstamps { | ||
162 | ktime_t hwtstamp; | ||
163 | ktime_t syststamp; | ||
164 | }; | ||
165 | |||
166 | /** | ||
167 | * skb_shared_tx - instructions for time stamping of outgoing packets | ||
168 | * | ||
169 | * @hardware: generate hardware time stamp | ||
170 | * @software: generate software time stamp | ||
171 | * @in_progress: device driver is going to provide | ||
172 | * hardware time stamp | ||
173 | * | ||
174 | * These flags are attached to packets as part of the | ||
175 | * &skb_shared_info. Use skb_tx() to get a pointer. | ||
176 | */ | ||
177 | union skb_shared_tx { | ||
178 | struct { | ||
179 | __u8 hardware:1, | ||
180 | software:1, | ||
181 | in_progress:1; | ||
182 | }; | ||
183 | __u8 flags; | ||
184 | }; | ||
185 | |||
135 | /* This data is invariant across clones and lives at | 186 | /* This data is invariant across clones and lives at |
136 | * the end of the header data, ie. at skb->end. | 187 | * the end of the header data, ie. at skb->end. |
137 | */ | 188 | */ |
@@ -143,10 +194,12 @@ struct skb_shared_info { | |||
143 | unsigned short gso_segs; | 194 | unsigned short gso_segs; |
144 | unsigned short gso_type; | 195 | unsigned short gso_type; |
145 | __be32 ip6_frag_id; | 196 | __be32 ip6_frag_id; |
197 | union skb_shared_tx tx_flags; | ||
146 | #ifdef CONFIG_HAS_DMA | 198 | #ifdef CONFIG_HAS_DMA |
147 | unsigned int num_dma_maps; | 199 | unsigned int num_dma_maps; |
148 | #endif | 200 | #endif |
149 | struct sk_buff *frag_list; | 201 | struct sk_buff *frag_list; |
202 | struct skb_shared_hwtstamps hwtstamps; | ||
150 | skb_frag_t frags[MAX_SKB_FRAGS]; | 203 | skb_frag_t frags[MAX_SKB_FRAGS]; |
151 | #ifdef CONFIG_HAS_DMA | 204 | #ifdef CONFIG_HAS_DMA |
152 | dma_addr_t dma_maps[MAX_SKB_FRAGS + 1]; | 205 | dma_addr_t dma_maps[MAX_SKB_FRAGS + 1]; |
@@ -465,6 +518,16 @@ static inline unsigned char *skb_end_pointer(const struct sk_buff *skb) | |||
465 | /* Internal */ | 518 | /* Internal */ |
466 | #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB))) | 519 | #define skb_shinfo(SKB) ((struct skb_shared_info *)(skb_end_pointer(SKB))) |
467 | 520 | ||
521 | static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb) | ||
522 | { | ||
523 | return &skb_shinfo(skb)->hwtstamps; | ||
524 | } | ||
525 | |||
526 | static inline union skb_shared_tx *skb_tx(struct sk_buff *skb) | ||
527 | { | ||
528 | return &skb_shinfo(skb)->tx_flags; | ||
529 | } | ||
530 | |||
468 | /** | 531 | /** |
469 | * skb_queue_empty - check if a queue is empty | 532 | * skb_queue_empty - check if a queue is empty |
470 | * @list: queue head | 533 | * @list: queue head |
@@ -1730,6 +1793,11 @@ static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb, | |||
1730 | 1793 | ||
1731 | extern void skb_init(void); | 1794 | extern void skb_init(void); |
1732 | 1795 | ||
1796 | static inline ktime_t skb_get_ktime(const struct sk_buff *skb) | ||
1797 | { | ||
1798 | return skb->tstamp; | ||
1799 | } | ||
1800 | |||
1733 | /** | 1801 | /** |
1734 | * skb_get_timestamp - get timestamp from a skb | 1802 | * skb_get_timestamp - get timestamp from a skb |
1735 | * @skb: skb to get stamp from | 1803 | * @skb: skb to get stamp from |
@@ -1739,11 +1807,18 @@ extern void skb_init(void); | |||
1739 | * This function converts the offset back to a struct timeval and stores | 1807 | * This function converts the offset back to a struct timeval and stores |
1740 | * it in stamp. | 1808 | * it in stamp. |
1741 | */ | 1809 | */ |
1742 | static inline void skb_get_timestamp(const struct sk_buff *skb, struct timeval *stamp) | 1810 | static inline void skb_get_timestamp(const struct sk_buff *skb, |
1811 | struct timeval *stamp) | ||
1743 | { | 1812 | { |
1744 | *stamp = ktime_to_timeval(skb->tstamp); | 1813 | *stamp = ktime_to_timeval(skb->tstamp); |
1745 | } | 1814 | } |
1746 | 1815 | ||
1816 | static inline void skb_get_timestampns(const struct sk_buff *skb, | ||
1817 | struct timespec *stamp) | ||
1818 | { | ||
1819 | *stamp = ktime_to_timespec(skb->tstamp); | ||
1820 | } | ||
1821 | |||
1747 | static inline void __net_timestamp(struct sk_buff *skb) | 1822 | static inline void __net_timestamp(struct sk_buff *skb) |
1748 | { | 1823 | { |
1749 | skb->tstamp = ktime_get_real(); | 1824 | skb->tstamp = ktime_get_real(); |
@@ -1759,6 +1834,20 @@ static inline ktime_t net_invalid_timestamp(void) | |||
1759 | return ktime_set(0, 0); | 1834 | return ktime_set(0, 0); |
1760 | } | 1835 | } |
1761 | 1836 | ||
1837 | /** | ||
1838 | * skb_tstamp_tx - queue clone of skb with send time stamps | ||
1839 | * @orig_skb: the original outgoing packet | ||
1840 | * @hwtstamps: hardware time stamps, may be NULL if not available | ||
1841 | * | ||
1842 | * If the skb has a socket associated, then this function clones the | ||
1843 | * skb (thus sharing the actual data and optional structures), stores | ||
1844 | * the optional hardware time stamping information (if non NULL) or | ||
1845 | * generates a software time stamp (otherwise), then queues the clone | ||
1846 | * to the error queue of the socket. Errors are silently ignored. | ||
1847 | */ | ||
1848 | extern void skb_tstamp_tx(struct sk_buff *orig_skb, | ||
1849 | struct skb_shared_hwtstamps *hwtstamps); | ||
1850 | |||
1762 | extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len); | 1851 | extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len); |
1763 | extern __sum16 __skb_checksum_complete(struct sk_buff *skb); | 1852 | extern __sum16 __skb_checksum_complete(struct sk_buff *skb); |
1764 | 1853 | ||