linux 内核rps,Linux kernel之网络rps

Linux kernel之网络rps

rps即receive package scaling, 是内核软件层实现的一个性能扩展机制,根据网络包数据计算hash值,然后挂载到对应cpu的backlog队列中,代码如下:

static int netif_rx_internal(struct sk_buff *skb)

{

int ret;

net_timestamp_check(netdev_tstamp_prequeue, skb);

trace_netif_rx(skb);

#ifdef CONFIG_RPS

if (static_key_false(&rps_needed)) {

struct rps_dev_flow voidflow, *rflow = &voidflow;

int cpu;

preempt_disable();

rcu_read_lock();

cpu = get_rps_cpu(skb->dev, skb, &rflow); //获取cpu号

if (cpu < 0)

cpu = smp_processor_id();

ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);//入队到cpu的backlog队列

rcu_read_unlock();

preempt_enable();

} else

#endif

{

unsigned int qtail;

ret = enqueue_to_backlog(skb, get_cpu(), &qtail);

put_cpu();

}

return ret;

}

其关键点在于get_rps_cpu(),其函数实现如下:

根据skb入队记录获取skb的rxqueue

获取rxqueue->rps_map,若不存在映射表返回-1,这种情况下由上述netif_rx_internal()函数分析可知直接挂在到处理cpu的backlog队列中,若该rxqueue的map到唯一cpu,直接返回相应cpu

进入核心流程skb_get_hash(),即计算skb hash值

/*

* get_rps_cpu is called from netif_receive_skb and returns the target

* CPU from the RPS map of the receiving queue for a given skb.

* rcu_read_lock must be held on entry.

*/

static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,

struct rps_dev_flow **rflowp)

{

struct netdev_rx_queue *rxqueue;

struct rps_map *map;

struct rps_dev_flow_table *flow_table;

struct rps_sock_flow_table *sock_flow_table;

int cpu = -1;

u16 tcpu;

u32 hash;

if (skb_rx_queue_recorded(skb)) {

u16 index = skb_get_rx_queue(skb);

if (unlikely(index >= dev->real_num_rx_queues)) {

WARN_ONCE(dev->real_num_rx_queues > 1,

"%s received packet on queue %u, but number "

"of RX queues is %u\n",

dev->name, index, dev->real_num_rx_queues);

goto done;

}

rxqueue = dev->_rx + index;

} else

rxqueue = dev->_rx;

map = rcu_dereference(rxqueue->rps_map);

if (map) {

i

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值