* [PATCH net-next v2 0/2] Combine standard and phy timestamping logic
@ 2014-09-03 23:38 Alexander Duyck
2014-09-03 23:39 ` [PATCH net-next v2 1/2] net-timestamp: Merge shared code between phy and regular timestamping Alexander Duyck
2014-09-03 23:42 ` [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping Alexander Duyck
0 siblings, 2 replies; 4+ messages in thread
From: Alexander Duyck @ 2014-09-03 23:38 UTC (permalink / raw)
To: netdev; +Cc: richardcochran, davem, willemb
This change makes it so that the core path for the phy timestamping logic
is shared between skb_tx_tstamp and skb_complete_tx_timestamp. In addition
it provides a means of using the same skb clone type path in non phy
timestamping drivers.
The main motivation for this is to enable non-phy drivers to be able to
manipulate tx timestamp skbs for such things as putting them in lists or
setting aside buffer in the context block.
---
v2: Incorporated suggested changes from Willem de Bruijn and Eric Dumazet
dropped uneeded comment
restored order of hwtstamp vs swtstamp
added destructor for skb
Dropped usage of skb_complete_tx_timestamp as a kfree_skb w/ destructor
Alexander Duyck (2):
net-timestamp: Merge shared code between phy and regular timestamping
net-timestamp: Make the clone operation stand-alone from phy timestamping
drivers/net/phy/dp83640.c | 6 ++--
include/linux/skbuff.h | 2 +
net/core/skbuff.c | 77 +++++++++++++++++++++++++++++++++------------
net/core/timestamping.c | 43 ++-----------------------
4 files changed, 64 insertions(+), 64 deletions(-)
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v2 1/2] net-timestamp: Merge shared code between phy and regular timestamping
2014-09-03 23:38 [PATCH net-next v2 0/2] Combine standard and phy timestamping logic Alexander Duyck
@ 2014-09-03 23:39 ` Alexander Duyck
2014-09-03 23:42 ` [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping Alexander Duyck
1 sibling, 0 replies; 4+ messages in thread
From: Alexander Duyck @ 2014-09-03 23:39 UTC (permalink / raw)
To: netdev; +Cc: richardcochran, davem, willemb
This change merges the shared bits that exist between skb_tx_tstamp and
skb_complete_tx_timestamp. By doing this we can avoid the two diverging as
there were already changes pushed into skb_tx_tstamp that hadn't made it
into the other function.
In addition this resolves issues with the fact that
skb_complete_tx_timestamp was included in linux/skbuff.h even though it was
only compiled in if phy timestamping was enabled.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
v2: Dropped comment and restored original order based on comments
from Willem de Bruijn.
net/core/skbuff.c | 65 ++++++++++++++++++++++++++++++-----------------
net/core/timestamping.c | 29 ---------------------
2 files changed, 42 insertions(+), 52 deletions(-)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 53ce536..697e696 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3511,33 +3511,13 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk)
}
EXPORT_SYMBOL(sock_dequeue_err_skb);
-void __skb_tstamp_tx(struct sk_buff *orig_skb,
- struct skb_shared_hwtstamps *hwtstamps,
- struct sock *sk, int tstype)
+static void __skb_complete_tx_timestamp(struct sk_buff *skb,
+ struct sock *sk,
+ int tstype)
{
struct sock_exterr_skb *serr;
- struct sk_buff *skb;
int err;
- if (!sk)
- return;
-
- if (hwtstamps) {
- *skb_hwtstamps(orig_skb) =
- *hwtstamps;
- } else {
- /*
- * no hardware time stamps available,
- * so keep the shared tx_flags and only
- * store software time stamp
- */
- orig_skb->tstamp = ktime_get_real();
- }
-
- skb = skb_clone(orig_skb, GFP_ATOMIC);
- if (!skb)
- return;
-
serr = SKB_EXT_ERR(skb);
memset(serr, 0, sizeof(*serr));
serr->ee.ee_errno = ENOMSG;
@@ -3554,6 +3534,45 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
if (err)
kfree_skb(skb);
}
+
+void skb_complete_tx_timestamp(struct sk_buff *skb,
+ struct skb_shared_hwtstamps *hwtstamps)
+{
+ struct sock *sk = skb->sk;
+
+ skb->sk = NULL;
+
+ if (hwtstamps) {
+ *skb_hwtstamps(skb) = *hwtstamps;
+ __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
+ } else {
+ kfree_skb(skb);
+ }
+
+ sock_put(sk);
+}
+EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);
+
+void __skb_tstamp_tx(struct sk_buff *orig_skb,
+ struct skb_shared_hwtstamps *hwtstamps,
+ struct sock *sk, int tstype)
+{
+ struct sk_buff *skb;
+
+ if (!sk)
+ return;
+
+ if (hwtstamps)
+ *skb_hwtstamps(orig_skb) = *hwtstamps;
+ else
+ orig_skb->tstamp = ktime_get_real();
+
+ skb = skb_clone(orig_skb, GFP_ATOMIC);
+ if (!skb)
+ return;
+
+ __skb_complete_tx_timestamp(skb, sk, tstype);
+}
EXPORT_SYMBOL_GPL(__skb_tstamp_tx);
void skb_tstamp_tx(struct sk_buff *orig_skb,
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index a877039..f48a59f 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -63,35 +63,6 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
}
EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp);
-void skb_complete_tx_timestamp(struct sk_buff *skb,
- struct skb_shared_hwtstamps *hwtstamps)
-{
- struct sock *sk = skb->sk;
- struct sock_exterr_skb *serr;
- int err;
-
- if (!hwtstamps) {
- sock_put(sk);
- kfree_skb(skb);
- return;
- }
-
- *skb_hwtstamps(skb) = *hwtstamps;
-
- serr = SKB_EXT_ERR(skb);
- memset(serr, 0, sizeof(*serr));
- serr->ee.ee_errno = ENOMSG;
- serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
- skb->sk = NULL;
-
- err = sock_queue_err_skb(sk, skb);
-
- sock_put(sk);
- if (err)
- kfree_skb(skb);
-}
-EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);
-
bool skb_defer_rx_timestamp(struct sk_buff *skb)
{
struct phy_device *phydev;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping
2014-09-03 23:38 [PATCH net-next v2 0/2] Combine standard and phy timestamping logic Alexander Duyck
2014-09-03 23:39 ` [PATCH net-next v2 1/2] net-timestamp: Merge shared code between phy and regular timestamping Alexander Duyck
@ 2014-09-03 23:42 ` Alexander Duyck
2014-09-04 2:22 ` Alexander Duyck
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Duyck @ 2014-09-03 23:42 UTC (permalink / raw)
To: netdev; +Cc: richardcochran, davem, willemb
The phy timestamping takes a different path than the regular timestamping
does in that it will create a clone first so that the packets needing to be
timestamped can be placed in a queue, or the context block could be used.
In order to support these use cases I am pulling the core of the code out
so it can be used in other drivers beyond just phy devices.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
v2: Renamed function to skb_clone_sk.
Added destructor to call sock_put instead of doing it ourselves.
Dropped freeing functionality from skb_complete_tx_timestamp.
Added additional documentation to the code.
drivers/net/phy/dp83640.c | 6 +++---
include/linux/skbuff.h | 2 ++
net/core/skbuff.c | 40 ++++++++++++++++++++++++++++------------
net/core/timestamping.c | 14 +++-----------
4 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index d5991ac..87648b3 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1148,7 +1148,7 @@ static void dp83640_remove(struct phy_device *phydev)
kfree_skb(skb);
while ((skb = skb_dequeue(&dp83640->tx_queue)) != NULL)
- skb_complete_tx_timestamp(skb, NULL);
+ kfree_skb(skb);
clock = dp83640_clock_get(dp83640->clock);
@@ -1405,7 +1405,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,
case HWTSTAMP_TX_ONESTEP_SYNC:
if (is_sync(skb, type)) {
- skb_complete_tx_timestamp(skb, NULL);
+ kfree_skb(skb);
return;
}
/* fall through */
@@ -1416,7 +1416,7 @@ static void dp83640_txtstamp(struct phy_device *phydev,
case HWTSTAMP_TX_OFF:
default:
- skb_complete_tx_timestamp(skb, NULL);
+ kfree_skb(skb);
break;
}
}
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 02529fc..1cf0cfa 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2690,6 +2690,8 @@ static inline ktime_t net_invalid_timestamp(void)
return ktime_set(0, 0);
}
+struct sk_buff *skb_clone_sk(struct sk_buff *skb);
+
#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
void skb_clone_tx_timestamp(struct sk_buff *skb);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 697e696..92c7288 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3511,6 +3511,32 @@ struct sk_buff *sock_dequeue_err_skb(struct sock *sk)
}
EXPORT_SYMBOL(sock_dequeue_err_skb);
+static void skb_clone_sk_destructor(struct sk_buff *skb)
+{
+ sock_put(skb->sk);
+}
+
+struct sk_buff *skb_clone_sk(struct sk_buff *skb)
+{
+ struct sock *sk = skb->sk;
+ struct sk_buff *clone;
+
+ if (!sk || !atomic_inc_not_zero(&sk->sk_refcnt))
+ return NULL;
+
+ clone = skb_clone(skb, GFP_ATOMIC);
+ if (!clone) {
+ sock_put(sk);
+ return NULL;
+ }
+
+ clone->sk = sk;
+ clone->destructor = skb_clone_sk_destructor;
+
+ return clone;
+}
+EXPORT_SYMBOL(skb_clone_sk);
+
static void __skb_complete_tx_timestamp(struct sk_buff *skb,
struct sock *sk,
int tstype)
@@ -3538,18 +3564,8 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb,
void skb_complete_tx_timestamp(struct sk_buff *skb,
struct skb_shared_hwtstamps *hwtstamps)
{
- struct sock *sk = skb->sk;
-
- skb->sk = NULL;
-
- if (hwtstamps) {
- *skb_hwtstamps(skb) = *hwtstamps;
- __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
- } else {
- kfree_skb(skb);
- }
-
- sock_put(sk);
+ *skb_hwtstamps(skb) = *hwtstamps;
+ __skb_complete_tx_timestamp(skb, skb->sk, SCM_TSTAMP_SND);
}
EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index f48a59f..43d3dd6 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -36,10 +36,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
{
struct phy_device *phydev;
struct sk_buff *clone;
- struct sock *sk = skb->sk;
unsigned int type;
- if (!sk)
+ if (!skb->sk)
return;
type = classify(skb);
@@ -48,16 +47,9 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
phydev = skb->dev->phydev;
if (likely(phydev->drv->txtstamp)) {
- if (!atomic_inc_not_zero(&sk->sk_refcnt))
+ clone = skb_clone_sk(skb);
+ if (!clone)
return;
-
- clone = skb_clone(skb, GFP_ATOMIC);
- if (!clone) {
- sock_put(sk);
- return;
- }
-
- clone->sk = sk;
phydev->drv->txtstamp(phydev, clone, type);
}
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping
2014-09-03 23:42 ` [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping Alexander Duyck
@ 2014-09-04 2:22 ` Alexander Duyck
0 siblings, 0 replies; 4+ messages in thread
From: Alexander Duyck @ 2014-09-04 2:22 UTC (permalink / raw)
To: Alexander Duyck, netdev; +Cc: richardcochran, davem, willemb
On 09/03/2014 04:42 PM, Alexander Duyck wrote:
> The phy timestamping takes a different path than the regular timestamping
> does in that it will create a clone first so that the packets needing to be
> timestamped can be placed in a queue, or the context block could be used.
>
> In order to support these use cases I am pulling the core of the code out
> so it can be used in other drivers beyond just phy devices.
>
> Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
This patch can be ignored. I need to submit a v3 with some fixes for
socket accounting.
Thanks,
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-04 2:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-03 23:38 [PATCH net-next v2 0/2] Combine standard and phy timestamping logic Alexander Duyck
2014-09-03 23:39 ` [PATCH net-next v2 1/2] net-timestamp: Merge shared code between phy and regular timestamping Alexander Duyck
2014-09-03 23:42 ` [PATCH net-next v2 2/2] net-timestamp: Make the clone operation stand-alone from phy timestamping Alexander Duyck
2014-09-04 2:22 ` Alexander Duyck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).