如何从内核模块使用XPS(传输数据包控制)

问题描述 投票:0回答:1

我的方案需要:

  1. 一个自定义可加载内核模块,用于组合数据包(skbuff)并尝试同步发送它们
  2. Intel I40e驱动程序(从内核源代码树内核版本4.15.12中提取)

自定义可加载内核模块

我的数据包不是一个复杂的数据包。我可以在模块的初始阶段初始化数据包,并反复使用相同的数据包。这就是我目前所做的,因为通信抖动比数据包本身的内容重要。

...
// I was doing
// txq = skb_get_tx_queue(skb->dev, skb);
// but it seemed that I will not be allowed to choose my desired queue in this case.

// thus, I tried to hardcode it for the time being.
txq =  &dev->_tx[7]; 
local_bh_disable();

HARD_TX_LOCK(skb->dev, txq, 7);

if (unlikely(netif_xmit_frozen_or_drv_stopped(txq))) {
    ret = NETDEV_TX_BUSY;
    goto unlock;
}
// prior to this approach, I was using ndo_start_xmit directly as
// skb->dev->netdev_ops->ndo_start_xmit(skb, skb->dev);
// but, with this I was not able to use XPS, thus I was trying [netdev_start_xmit()][1] [which ultimately invokes ndo_start_xmit]

ret = netdev_start_xmit(skb, skb->dev, txq, 0);

unlock:
HARD_TX_UNLOCK(skb->dev, txq);

local_bh_enable();

...

我从https://elixir.bootlin.com/linux/v4.15.12/source/net/core/pktgen.c#L3487获取了数据包传输代码参考

我不确定我做得对。结果并没有这么说。我期待我的数据包流经Tx队列7,但它们仍然流经默认的TX-Queue 0。

linux networking linux-kernel linux-device-driver kernel-module
1个回答
0
投票

为了以防万一,如果有人正在寻找一个快速的脏修复,以下两行的修改对我有用。

txq =  &dev->_tx[7]; 
local_bh_disable();

变成

skb_set_queue_mapping(skb, 7);
txq = skb_get_tx_queue(dev, skb);

有了这个,我能够通过Tx队列7引导我的数据包,但我仍然遇到抖动,这可能源于其他一些来源。

https://elixir.bootlin.com/linux/v4.19-rc3/ident/netdev_pick_tx

https://elixir.bootlin.com/linux/v4.19-rc3/ident/skb_set_queue_mapping

https://elixir.bootlin.com/linux/v4.15.12/source/net/core/pktgen.c#L3487

问候,

Cooshal。

© www.soinside.com 2019 - 2024. All rights reserved.