Skip to content

Commit 70713dd

Browse files
Qitao Xudavem330
authored andcommitted
net_sched: introduce tracepoint trace_qdisc_enqueue()
Tracepoint trace_qdisc_enqueue() is introduced to trace skb at the entrance of TC layer on TX side. This is similar to trace_qdisc_dequeue(): 1. For both we only trace successful cases. The failure cases can be traced via trace_kfree_skb(). 2. They are called at entrance or exit of TC layer, not for each ->enqueue() or ->dequeue(). This is intentional, because we want to make trace_qdisc_enqueue() symmetric to trace_qdisc_dequeue(), which is easier to use. The return value of qdisc_enqueue() is not interesting here, we have Qdisc's drop packets in ->dequeue(), it is impossible to trace them even if we have the return value, the only way to trace them is tracing kfree_skb(). We only add information we need to trace ring buffer. If any other information is needed, it is easy to extend it without breaking ABI, see commit 3dd344e ("net: tracepoint: exposing sk_family in all tcp:tracepoints"). Reviewed-by: Cong Wang <[email protected]> Signed-off-by: Qitao Xu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 851f36e commit 70713dd

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

include/trace/events/qdisc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ TRACE_EVENT(qdisc_dequeue,
4646
__entry->txq_state, __entry->packets, __entry->skbaddr )
4747
);
4848

49+
TRACE_EVENT(qdisc_enqueue,
50+
51+
TP_PROTO(struct Qdisc *qdisc, const struct netdev_queue *txq, struct sk_buff *skb),
52+
53+
TP_ARGS(qdisc, txq, skb),
54+
55+
TP_STRUCT__entry(
56+
__field(struct Qdisc *, qdisc)
57+
__field(void *, skbaddr)
58+
__field(int, ifindex)
59+
__field(u32, handle)
60+
__field(u32, parent)
61+
),
62+
63+
TP_fast_assign(
64+
__entry->qdisc = qdisc;
65+
__entry->skbaddr = skb;
66+
__entry->ifindex = txq->dev ? txq->dev->ifindex : 0;
67+
__entry->handle = qdisc->handle;
68+
__entry->parent = qdisc->parent;
69+
),
70+
71+
TP_printk("enqueue ifindex=%d qdisc handle=0x%X parent=0x%X skbaddr=%px",
72+
__entry->ifindex, __entry->handle, __entry->parent, __entry->skbaddr)
73+
);
74+
4975
TRACE_EVENT(qdisc_reset,
5076

5177
TP_PROTO(struct Qdisc *q),

net/core/dev.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
#include <trace/events/napi.h>
132132
#include <trace/events/net.h>
133133
#include <trace/events/skb.h>
134+
#include <trace/events/qdisc.h>
134135
#include <linux/inetdevice.h>
135136
#include <linux/cpu_rmap.h>
136137
#include <linux/static_key.h>
@@ -3844,6 +3845,18 @@ static void qdisc_pkt_len_init(struct sk_buff *skb)
38443845
}
38453846
}
38463847

3848+
static int dev_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *q,
3849+
struct sk_buff **to_free,
3850+
struct netdev_queue *txq)
3851+
{
3852+
int rc;
3853+
3854+
rc = q->enqueue(skb, q, to_free) & NET_XMIT_MASK;
3855+
if (rc == NET_XMIT_SUCCESS)
3856+
trace_qdisc_enqueue(q, txq, skb);
3857+
return rc;
3858+
}
3859+
38473860
static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38483861
struct net_device *dev,
38493862
struct netdev_queue *txq)
@@ -3862,8 +3875,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38623875
* of q->seqlock to protect from racing with requeuing.
38633876
*/
38643877
if (unlikely(!nolock_qdisc_is_empty(q))) {
3865-
rc = q->enqueue(skb, q, &to_free) &
3866-
NET_XMIT_MASK;
3878+
rc = dev_qdisc_enqueue(skb, q, &to_free, txq);
38673879
__qdisc_run(q);
38683880
qdisc_run_end(q);
38693881

@@ -3879,7 +3891,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38793891
return NET_XMIT_SUCCESS;
38803892
}
38813893

3882-
rc = q->enqueue(skb, q, &to_free) & NET_XMIT_MASK;
3894+
rc = dev_qdisc_enqueue(skb, q, &to_free, txq);
38833895
qdisc_run(q);
38843896

38853897
no_lock_out:
@@ -3923,7 +3935,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
39233935
qdisc_run_end(q);
39243936
rc = NET_XMIT_SUCCESS;
39253937
} else {
3926-
rc = q->enqueue(skb, q, &to_free) & NET_XMIT_MASK;
3938+
rc = dev_qdisc_enqueue(skb, q, &to_free, txq);
39273939
if (qdisc_run_begin(q)) {
39283940
if (unlikely(contended)) {
39293941
spin_unlock(&q->busylock);

0 commit comments

Comments
 (0)