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 /net/core | |
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 'net/core')
-rw-r--r-- | net/core/dev.c | 32 | ||||
-rw-r--r-- | net/core/skbuff.c | 41 |
2 files changed, 71 insertions, 2 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index 1e27a67df242..d20c28e839d3 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -1672,10 +1672,21 @@ static int dev_gso_segment(struct sk_buff *skb) | |||
1672 | return 0; | 1672 | return 0; |
1673 | } | 1673 | } |
1674 | 1674 | ||
1675 | static void tstamp_tx(struct sk_buff *skb) | ||
1676 | { | ||
1677 | union skb_shared_tx *shtx = | ||
1678 | skb_tx(skb); | ||
1679 | if (unlikely(shtx->software && | ||
1680 | !shtx->in_progress)) { | ||
1681 | skb_tstamp_tx(skb, NULL); | ||
1682 | } | ||
1683 | } | ||
1684 | |||
1675 | int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, | 1685 | int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, |
1676 | struct netdev_queue *txq) | 1686 | struct netdev_queue *txq) |
1677 | { | 1687 | { |
1678 | const struct net_device_ops *ops = dev->netdev_ops; | 1688 | const struct net_device_ops *ops = dev->netdev_ops; |
1689 | int rc; | ||
1679 | 1690 | ||
1680 | prefetch(&dev->netdev_ops->ndo_start_xmit); | 1691 | prefetch(&dev->netdev_ops->ndo_start_xmit); |
1681 | if (likely(!skb->next)) { | 1692 | if (likely(!skb->next)) { |
@@ -1689,13 +1700,29 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, | |||
1689 | goto gso; | 1700 | goto gso; |
1690 | } | 1701 | } |
1691 | 1702 | ||
1692 | return ops->ndo_start_xmit(skb, dev); | 1703 | rc = ops->ndo_start_xmit(skb, dev); |
1704 | /* | ||
1705 | * TODO: if skb_orphan() was called by | ||
1706 | * dev->hard_start_xmit() (for example, the unmodified | ||
1707 | * igb driver does that; bnx2 doesn't), then | ||
1708 | * skb_tx_software_timestamp() will be unable to send | ||
1709 | * back the time stamp. | ||
1710 | * | ||
1711 | * How can this be prevented? Always create another | ||
1712 | * reference to the socket before calling | ||
1713 | * dev->hard_start_xmit()? Prevent that skb_orphan() | ||
1714 | * does anything in dev->hard_start_xmit() by clearing | ||
1715 | * the skb destructor before the call and restoring it | ||
1716 | * afterwards, then doing the skb_orphan() ourselves? | ||
1717 | */ | ||
1718 | if (likely(!rc)) | ||
1719 | tstamp_tx(skb); | ||
1720 | return rc; | ||
1693 | } | 1721 | } |
1694 | 1722 | ||
1695 | gso: | 1723 | gso: |
1696 | do { | 1724 | do { |
1697 | struct sk_buff *nskb = skb->next; | 1725 | struct sk_buff *nskb = skb->next; |
1698 | int rc; | ||
1699 | 1726 | ||
1700 | skb->next = nskb->next; | 1727 | skb->next = nskb->next; |
1701 | nskb->next = NULL; | 1728 | nskb->next = NULL; |
@@ -1705,6 +1732,7 @@ gso: | |||
1705 | skb->next = nskb; | 1732 | skb->next = nskb; |
1706 | return rc; | 1733 | return rc; |
1707 | } | 1734 | } |
1735 | tstamp_tx(skb); | ||
1708 | if (unlikely(netif_tx_queue_stopped(txq) && skb->next)) | 1736 | if (unlikely(netif_tx_queue_stopped(txq) && skb->next)) |
1709 | return NETDEV_TX_BUSY; | 1737 | return NETDEV_TX_BUSY; |
1710 | } while (skb->next); | 1738 | } while (skb->next); |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index ab7d2e9f02fa..e5a8351ff12d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -55,6 +55,7 @@ | |||
55 | #include <linux/rtnetlink.h> | 55 | #include <linux/rtnetlink.h> |
56 | #include <linux/init.h> | 56 | #include <linux/init.h> |
57 | #include <linux/scatterlist.h> | 57 | #include <linux/scatterlist.h> |
58 | #include <linux/errqueue.h> | ||
58 | 59 | ||
59 | #include <net/protocol.h> | 60 | #include <net/protocol.h> |
60 | #include <net/dst.h> | 61 | #include <net/dst.h> |
@@ -215,7 +216,9 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, | |||
215 | shinfo->gso_segs = 0; | 216 | shinfo->gso_segs = 0; |
216 | shinfo->gso_type = 0; | 217 | shinfo->gso_type = 0; |
217 | shinfo->ip6_frag_id = 0; | 218 | shinfo->ip6_frag_id = 0; |
219 | shinfo->tx_flags.flags = 0; | ||
218 | shinfo->frag_list = NULL; | 220 | shinfo->frag_list = NULL; |
221 | memset(&shinfo->hwtstamps, 0, sizeof(shinfo->hwtstamps)); | ||
219 | 222 | ||
220 | if (fclone) { | 223 | if (fclone) { |
221 | struct sk_buff *child = skb + 1; | 224 | struct sk_buff *child = skb + 1; |
@@ -2945,6 +2948,44 @@ int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer) | |||
2945 | } | 2948 | } |
2946 | EXPORT_SYMBOL_GPL(skb_cow_data); | 2949 | EXPORT_SYMBOL_GPL(skb_cow_data); |
2947 | 2950 | ||
2951 | void skb_tstamp_tx(struct sk_buff *orig_skb, | ||
2952 | struct skb_shared_hwtstamps *hwtstamps) | ||
2953 | { | ||
2954 | struct sock *sk = orig_skb->sk; | ||
2955 | struct sock_exterr_skb *serr; | ||
2956 | struct sk_buff *skb; | ||
2957 | int err; | ||
2958 | |||
2959 | if (!sk) | ||
2960 | return; | ||
2961 | |||
2962 | skb = skb_clone(orig_skb, GFP_ATOMIC); | ||
2963 | if (!skb) | ||
2964 | return; | ||
2965 | |||
2966 | if (hwtstamps) { | ||
2967 | *skb_hwtstamps(skb) = | ||
2968 | *hwtstamps; | ||
2969 | } else { | ||
2970 | /* | ||
2971 | * no hardware time stamps available, | ||
2972 | * so keep the skb_shared_tx and only | ||
2973 | * store software time stamp | ||
2974 | */ | ||
2975 | skb->tstamp = ktime_get_real(); | ||
2976 | } | ||
2977 | |||
2978 | serr = SKB_EXT_ERR(skb); | ||
2979 | memset(serr, 0, sizeof(*serr)); | ||
2980 | serr->ee.ee_errno = ENOMSG; | ||
2981 | serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; | ||
2982 | err = sock_queue_err_skb(sk, skb); | ||
2983 | if (err) | ||
2984 | kfree_skb(skb); | ||
2985 | } | ||
2986 | EXPORT_SYMBOL_GPL(skb_tstamp_tx); | ||
2987 | |||
2988 | |||
2948 | /** | 2989 | /** |
2949 | * skb_partial_csum_set - set up and verify partial csum values for packet | 2990 | * skb_partial_csum_set - set up and verify partial csum values for packet |
2950 | * @skb: the skb to set | 2991 | * @skb: the skb to set |