net: introduce dev_consume_skb_any()
Some network drivers use dev_kfree_skb_any() and dev_kfree_skb_irq() helpers to free skbs, both for dropped packets and TX completed ones. We need to separate the two causes to get better diagnostics given by dropwatch or "perf record -e skb:kfree_skb" This patch provides two new helpers, dev_consume_skb_any() and dev_consume_skb_irq() to be used for consumed skbs. __dev_kfree_skb_irq() is slightly optimized to remove one atomic_dec_and_test() in fast path, and use this_cpu_{r|w} accessors. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
f96eb74c84
commit
e6247027e5
@@ -2368,17 +2368,52 @@ static inline int netif_copy_real_num_queues(struct net_device *to_dev,
|
||||
#define DEFAULT_MAX_NUM_RSS_QUEUES (8)
|
||||
int netif_get_num_default_rss_queues(void);
|
||||
|
||||
/* Use this variant when it is known for sure that it
|
||||
* is executing from hardware interrupt context or with hardware interrupts
|
||||
* disabled.
|
||||
*/
|
||||
void dev_kfree_skb_irq(struct sk_buff *skb);
|
||||
enum skb_free_reason {
|
||||
SKB_REASON_CONSUMED,
|
||||
SKB_REASON_DROPPED,
|
||||
};
|
||||
|
||||
/* Use this variant in places where it could be invoked
|
||||
* from either hardware interrupt or other context, with hardware interrupts
|
||||
* either disabled or enabled.
|
||||
void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
|
||||
void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
|
||||
|
||||
/*
|
||||
* It is not allowed to call kfree_skb() or consume_skb() from hardware
|
||||
* interrupt context or with hardware interrupts being disabled.
|
||||
* (in_irq() || irqs_disabled())
|
||||
*
|
||||
* We provide four helpers that can be used in following contexts :
|
||||
*
|
||||
* dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
|
||||
* replacing kfree_skb(skb)
|
||||
*
|
||||
* dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
|
||||
* Typically used in place of consume_skb(skb) in TX completion path
|
||||
*
|
||||
* dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
|
||||
* replacing kfree_skb(skb)
|
||||
*
|
||||
* dev_consume_skb_any(skb) when caller doesn't know its current irq context,
|
||||
* and consumed a packet. Used in place of consume_skb(skb)
|
||||
*/
|
||||
void dev_kfree_skb_any(struct sk_buff *skb);
|
||||
static inline void dev_kfree_skb_irq(struct sk_buff *skb)
|
||||
{
|
||||
__dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
|
||||
}
|
||||
|
||||
static inline void dev_consume_skb_irq(struct sk_buff *skb)
|
||||
{
|
||||
__dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
|
||||
}
|
||||
|
||||
static inline void dev_kfree_skb_any(struct sk_buff *skb)
|
||||
{
|
||||
__dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
|
||||
}
|
||||
|
||||
static inline void dev_consume_skb_any(struct sk_buff *skb)
|
||||
{
|
||||
__dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
|
||||
}
|
||||
|
||||
int netif_rx(struct sk_buff *skb);
|
||||
int netif_rx_ni(struct sk_buff *skb);
|
||||
|
Reference in New Issue
Block a user