免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 瀚海书香

软中断在多核cpu上的负载均衡 [复制链接]

论坛徽章:
0
发表于 2010-07-21 09:59 |显示全部楼层
不是呀,我说的是google那个补丁,它在队列层放下截获数据包,根据skb的hash值,将skb较均匀地重新调度 ...
独孤九贱 发表于 2010-07-21 09:32


它是否可以保证相同的 connection 分配在相同的 CPU 上?如果不能保证,那么是否可能会产生乱序现象?

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
发表于 2010-07-21 10:10 |显示全部楼层
它是否可以保证相同的 connection 分配在相同的 CPU 上?如果不能保证,那么是否可能会产生乱序现象?
platinum 发表于 2010-07-21 09:59


对,还是需要看一下补丁是否解决TCP保序的问题

论坛徽章:
0
发表于 2010-07-21 10:13 |显示全部楼层
我在Atom的机器应用了这个补丁,并进行测试。性能没有patch得到的效果那样,没有什么改变。
我是Atom 330的CPU,内核是2.6.32,网卡是82574L,驱动是e1000.sf.net上下载的1.2.8,没有使用NAPI。

论坛徽章:
0
发表于 2010-07-21 10:14 |显示全部楼层
对,还是需要看一下补丁是否解决TCP保序的问题
Godbach 发表于 2010-07-21 10:10


我觉得不仅是 TCP,其实 UDP 也是一样的,只不过处理端在客户系统上,如果乱许,根据 application 的处理,一样会重传的

论坛徽章:
0
发表于 2010-07-21 10:17 |显示全部楼层
我观察了一下hi集中到了一个CPU上,然后si在第2个CPU上。第一个CPU上基本上没有si。
我改天找一个4核的CPU在我G41的主板上测试一下。看看效果。
谢谢!

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
发表于 2010-07-21 10:17 |显示全部楼层
也就是如果网卡只是简单的根据一些算法将中断均衡到多核CPU上,但是不考虑connection的话,效果也不好说

论坛徽章:
1
天蝎座
日期:2013-10-23 21:11:03
发表于 2010-07-21 10:34 |显示全部楼层

论坛徽章:
0
发表于 2010-07-21 15:45 |显示全部楼层
回复 47# openspace


    人家讨论的是软中断的均衡{:3_180:}

论坛徽章:
0
发表于 2010-07-21 17:17 |显示全部楼层
它是否可以保证相同的 connection 分配在相同的 CPU 上?如果不能保证,那么是否可能会产生乱序现象?
platinum 发表于 2010-07-21 09:59



不会乱序,使用对skb进行hash的方法,保证了不会乱序,不过,作者说样会导致CPU 缓存不命中,带来一定的性能形销,解决方法是,同时支持硬件hash,以达到加速的目的。(我现在还没有搞懂,网卡如何利用之)。
以下代码是计算hash并找到与之对应的CPU:
  1. +static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb)
  2. +{
  3. +        struct ipv6hdr *ip6;
  4. +        struct iphdr *ip;
  5. +        struct netdev_rx_queue *rxqueue;
  6. +        struct rps_map *map;
  7. +        int cpu = -1;
  8. +        u8 ip_proto;
  9. +        u32 addr1, addr2, ports, ihl;
  10. +
  11. +        rcu_read_lock();
  12. +
  13. +        if (skb_rx_queue_recorded(skb)) {
  14. +                u16 index = skb_get_rx_queue(skb);
  15. +                if (unlikely(index >= dev->num_rx_queues)) {
  16. +                        if (net_ratelimit()) {
  17. +                                WARN(1, "Received packet on %s for queue %u, "
  18. +                                    "but number of RX queues is %u\n",
  19. +                                     dev->name, index, dev->num_rx_queues);
  20. +                        }
  21. +                        goto done;
  22. +                }
  23. +                rxqueue = dev->_rx + index;
  24. +        } else
  25. +                rxqueue = dev->_rx;
  26. +
  27. +        if (!rxqueue->rps_map)
  28. +                goto done;
  29. +
  30. +        if (skb->rxhash)
  31. +                goto got_hash; /* Skip hash computation on packet header */
  32. +
  33. +        switch (skb->protocol) {
  34. +        case __constant_htons(ETH_P_IP):
  35. +                if (!pskb_may_pull(skb, sizeof(*ip)))
  36. +                        goto done;
  37. +
  38. +                ip = (struct iphdr *) skb->data;
  39. +                ip_proto = ip->protocol;
  40. +                addr1 = ip->saddr;
  41. +                addr2 = ip->daddr;
  42. +                ihl = ip->ihl;
  43. +                break;
  44. +        case __constant_htons(ETH_P_IPV6):
  45. +                if (!pskb_may_pull(skb, sizeof(*ip6)))
  46. +                        goto done;
  47. +
  48. +                ip6 = (struct ipv6hdr *) skb->data;
  49. +                ip_proto = ip6->nexthdr;
  50. +                addr1 = ip6->saddr.s6_addr32[3];
  51. +                addr2 = ip6->daddr.s6_addr32[3];
  52. +                ihl = (40 >> 2);
  53. +                break;
  54. +        default:
  55. +                goto done;
  56. +        }
  57. +        ports = 0;
  58. +        switch (ip_proto) {
  59. +        case IPPROTO_TCP:
  60. +        case IPPROTO_UDP:
  61. +        case IPPROTO_DCCP:
  62. +        case IPPROTO_ESP:
  63. +        case IPPROTO_AH:
  64. +        case IPPROTO_SCTP:
  65. +        case IPPROTO_UDPLITE:
  66. +                if (pskb_may_pull(skb, (ihl * 4) + 4))
  67. +                        ports = *((u32 *) (skb->data + (ihl * 4)));
  68. +                break;
  69. +
  70. +        default:
  71. +                break;
  72. +        }
  73. +
  74. +        skb->rxhash = jhash_3words(addr1, addr2, ports, hashrnd);
  75. +        if (!skb->rxhash)
  76. +                skb->rxhash = 1;
  77. +
  78. +got_hash:
  79. +        map = rcu_dereference(rxqueue->rps_map);
  80. +        if (map) {
  81. +                u16 tcpu = map->cpus[((u64) skb->rxhash * map->len) >> 32];
  82. +
  83. +                if (cpu_online(tcpu)) {
  84. +                        cpu = tcpu;
  85. +                        goto done;
  86. +                }
  87. +        }
  88. +
  89. +done:
  90. +        rcu_read_unlock();
  91. +        return cpu;
  92. +}
复制代码

论坛徽章:
0
发表于 2010-07-21 17:23 |显示全部楼层
不会乱序,使用对skb进行hash的方法,保证了不会乱序,不过,作者说样会导致CPU 缓存不命中,带来一定 ...
独孤九贱 发表于 2010-07-21 17:17


这个 hashkey 取的真妙!既保证了同一个连接可以得出一个 key 值,又利用了不同传输层 port 部分结构相同的特点提高了工作效率
赞一个!

至于九贱兄说的硬件实现的问题继续关注
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP