免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 33153 | 回复: 116
打印 上一主题 下一主题

[FreeBSD] 精通polling参数调优的进来帮帮忙吧 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-23 18:30 |只看该作者 |倒序浏览
我测试FreeBSD无丢包网络转发性能。
我现在测试用的硬件配置:
CPU:奔四2.8G
内存:1G DDR333双通道
网卡:双Intel千兆网卡用来做网桥,还有一个百兆的用来访问
还有千兆网线和smartbit千兆口


我开了polling以后,无论怎么设置,转发性能都上不去,64字节下双向到达18万pps以后,就开始丢包,但CPU占用率一直不到1%


我尝试过设置内核配置文件的值HZ=1000改为2000也不行,我还设置过如下参数,都没有能很好的提升性能:
kern.polling.user_frac
kern.polling.each_burst
kern.polling.burst_max


[ 本帖最后由 xfsoul 于 2006-5-23 18:32 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-05-23 18:45 |只看该作者
而且我在网上看到很多人碰到和我一样的问题:
在FreeBSD6系列中开了polling性能会很差:
http://www.monkey.org/freebsd/ar ... 00501/msg00060.html
http://www.freebsdchina.org/foru ... 70d4b88fede6fedee03

我这里开了polling性能比linux差很多。

[ 本帖最后由 xfsoul 于 2006-5-23 18:51 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2006-05-23 18:55 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2006-05-23 19:05 |只看该作者
没有看到。
现在怎么办呢。
在第一个硬件平台上测试。FreeBSD网络转发性能貌似不如linux

论坛徽章:
0
5 [报告]
发表于 2006-05-23 19:08 |只看该作者
我重新编译内核,彻底去掉polling看看,性能能否比得上linux。

论坛徽章:
0
6 [报告]
发表于 2006-05-23 23:24 |只看该作者
1.2.1  全局变量
从第106行开始,都是POLLING相关的全局变量.首先是建立一SYSCTL树的节点.下图中的SYSCTL_NODE宏代表在父节点_kern下建立一个_kern_polling节点.
SYSCTL_NODE(_kern, OID_AUTO, polling, CTLFLAG_RW, 0,        "Device polling parameters");
                  下图中的变量全部可用sysctl来查看,大部分都可以调整设置.这些全局变量都是使用宏SYSCTL_UINT把他们加入到_kern_polling节点下,成为该节点的叶子.之所以这样,是因为可以通过用户区来调整这些参数.

-----------------------------------------------------------------------------------------------------
static u_int32_t poll_burst = 5;                                                                 ------ kern_poll.cstatic u_int32_t poll_each_burst = 5;
static u_int32_t poll_burst_max = 150;
static u_int32_t poll_in_idle_loop=0;
u_int32_t poll_in_trap;
static u_int32_t user_frac = 50;
static u_int32_t reg_frac = 20 ;static u_int32_t short_ticks;
static u_int32_t lost_polls;
static u_int32_t pending_polls;
static int residual_burst = 0;
static u_int32_t poll_handlers;
static int polling = 0;
static u_int32_t phase;

static u_int32_t suspect;
static u_int32_t stalled;
static u_int32_t idlepoll_sleeping;                                                          ------ kern_poll.c
----------------------------图1-2-2 ----------------------------
在图1-2-2中.这些变量按功能分可分为  3  大类.
A.        开关型:
polling: 初始为0,即默认为不打开轮询功能.要打开轮询功能,必须用:
#sysctl kern.polling=1
poll_in_idle_loop:该参数用于poll_idle函数,用来确定是否进入一低优先权的循环轮询中.即CPU空闲时是否来执行轮询.

poll_in_trap:此参数不但是在陷入时是否执行轮询的开关,而且其值也是在陷入(trap)时执行多少次轮询
B.        算法参数
poll_each_burst:一个基本的轮询次数,很多其他变量都来和他进行比较(主要是空闲时执行轮询或陷入时执行轮询).该值系统默认是5,

poll_burst:一个动态的轮询次数,主要用于根据核心(轮询)占用的时间片调整轮询次数,在核心(轮询)时间片小于预定的时间片时,该值加1,当核心(轮询)时间片过长,导致丢失一个或更多的时钟嘀嗒时,该值将减去该值的8分之1.这种算法是FreeBSD中轮询技术的主要算法.当然有一定的局限性.当网络分组快速增加时,此算法只是加1来增加次数再来调用软件中断,从而形成软中断暴增的做法并不好.而且在占用时间片过长时的减8分之1的做法也缺少理论依据.

poll_burst_max:轮训的最大值,该值是用来限制poll_burst在累加过程中的最大量.当然该值可以调整.他的调整范围在后面讲的两个宏之内.

user_frac:用户区占用的CPU时间片的百分比.该值用来确定核心(轮询)所占时间片是否有剩余,如果有的话就调整动态值poll_burst,使其加1.

residual_burst:在正常的轮询次数中,都是以poll_each_burst为标准的,而当动态的poll_burst>poll_each_burst时候,就会产生剩余没轮询的次数,该次数就是residual_burst,当然其结果就是继续轮询完residual_burst.

idlepoll_sleeping:该值的使用前提是poll_in_idle_loop变量开关已经打开,即在CPU空闲时支持轮询.系统置该值为0,可以直接进入到CPU空闲时的轮询代码中;如果poll_in_idle_loop变量开关还没开放,系统会给该值置1,也就是说.该值其实是一个CPU空闲时是否进入轮询代码的状态,

reg_frac:在整个循环代码执行了该值的次数之后,就进行检查网卡的状态寄存器.看看网卡是否有什么问题.

pending_polls:在进入轮询前(我们有个时钟嘀嗒钩子函数),此参数加1,再轮询后会对其减1,再次进入时钟嘀嗒后半部分会判断是否平衡,如果由于轮询时间过长,此次嘀嗒便会错过.
C.        调试与参考
short_ticks:每次时钟嘀嗒钩子函数所花的时间如果小于5毫秒.那这种间隔时间太短了.这是以HZ=100来计算的.源代码作者认为.在100M卡时,HZ数调整到1000比较合适,那么我们的时钟嘀嗒钩子函数所花时间在小于0.5毫秒是合适的.
lost_polls: 由于pending_polls的不平衡.记录一次嘀嗒时间错过,该值会不停的累加,给系统管理员提示可以调整poll_burst_max值小一些.或根据情况把user_frac(用户占用CPU时间片的百分比)的值调的更小些.
poll_handlers:有多少个网络设备支持并注册了轮询.
phase:指示轮询进行到了哪个阶段.轮询代码共分为6个阶段.
                0阶段代表是初始阶段或上次轮询的结束.
                1阶段时钟嘀嗒钩子函数在设置网络软中断(轮询中断)前
                2阶段时钟嘀嗒钩子函数在设置网络软中断(轮询中断)后.
                3阶段是进入软中断netisr_poll前.
                4阶段是从软中断netisr_poll中出来.
                5阶段是进入软中断netisr_pollmore前
                6阶段是从软中断netisr_pollmore中出来.
suspect:由于最后的软中断netisr_pollmore在处理时会再完成时把阶段标志phase置为0(即一次POLLING的完成,),或出现其他未完成情况时进入阶段5和6.那么就是说.我们的时钟嘀嗒钩子在最初时小于2阶段的话,一定是在0阶段.如果出现1或2阶段的话就意味着时钟硬件中断发生了嵌套.此值在出现这种问题时进行记录.

stalled:由于pending_polls太大(大于100),也就是说由于每次轮询时间过长,以至于轮询丢失了太多嘀嗒,当到达100次时,该值加1.(源代码的作者认为不会发生此类事情,除了在网卡激活时)

以上是一些参数说明,你可以参照下.(不过是基于5.3的)
另外,请开空闲HOOK.

论坛徽章:
0
7 [报告]
发表于 2006-05-23 23:51 |只看该作者
我想知道调度器的情况.以下是对/sys/kern/kern_poll.c中在第106行左右的
SYSCTL_NODE(_kern, OID_AUTO, polling, CTLFLAG_RW, 0,
        "Device polling parameters");
的后面加入以下:(拷贝粘帖就可以了)
SYSCTL_NODE(_kern_polling, OID_AUTO, dbg, CTLFLAG_RW, 0,
        "Device polling node kernel debug");

static uint32_t poll_coun;
SYSCTL_UINT(_kern_polling_dbg, OID_AUTO, poll_coun, CTLFLAG_RD,                &poll_coun,0,"netisr_poll and netisr_pollmore count");

static uint32_t pollmore_coun;
SYSCTL_UINT(_kern_polling_dbg, OID_AUTO, pollmore_coun, CTLFLAG_RD,                &pollmore_coun,0,"netisr_pollmore count");
static struct timeval pollstart_t;
static uint32_t poll_start;
static uint32_t poll_suspect;
SYSCTL_UINT(_kern_polling_dbg, OID_AUTO, poll_suspect, CTLFLAG_RD,                &poll_suspect,0,"poll_suspect count");
static uint32_t poll_invoke;
SYSCTL_UINT(_kern_polling_dbg, OID_AUTO, poll_invoke, CTLFLAG_RD,                &poll_invoke,0,"poll_invoke");
static int32_t net_load;
SYSCTL_INT(_kern_polling_dbg, OID_AUTO, net_load, CTLFLAG_RD,                &net_load,0,"net_load");
static int32_t on_cpu1;
SYSCTL_INT(_kern_polling_dbg, OID_AUTO, on_cpu1, CTLFLAG_RD,&on_cpu1,0,"run on cpu1");
static int32_t on_cpu2;
SYSCTL_INT(_kern_polling_dbg, OID_AUTO, on_cpu2, CTLFLAG_RD,&on_cpu2,0,"run on cpu2");
/*end*/
然后到netisr_pollmore()函数中的第6,7行左右if (residual_burst > 0) {语句后
加入:
pollmore_coun++;
                if (pollmore_coun>0xfffffffe)
                        pollmore_coun=0;
到netisr_poll()函数中第一行的大括号后面加上:
        struct timeval netisr_t;
到6,7行phase = 3;这句后面加入:
        poll_coun++;
        if (poll_coun>0xfffffffe)
                poll_coun=0;
        if (poll_start==0)
                poll_suspect++;
        microuptime(&netisr_t);
        poll_invoke=(poll_invoke+((netisr_t.tv_usec - pollstart_t.tv_usec)+(netisr_t.tv_sec - pollstart_t.tv_sec)*1000000))/2;
其他的你还暂时用不上.
重新编译核心.
重启动开POLLING后.执行:
sysctl kern.polling.
大概每秒执行下看看,把数据发上来.

[ 本帖最后由 xie_minix 于 2006-5-23 23:58 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2006-05-24 00:08 |只看该作者
目前本人正在做POLLING的NetBSD移植.
对于POLLING的效率问题听过很多网友
反映,我没有条件测试,移植的目的主要
是想解决SMP上效率问题,还有参数的动态
调整,希望大家能帮忙一起解决.NetBSD的
POLLING原代码我争取在这几天发到这.关于
POLLING的原代码详解也将快发到CNFUG的
期刊上(整整写了一年了,效率和没调优的
POLLING一样).到时希望大家指正.

[ 本帖最后由 xie_minix 于 2006-5-24 00:10 编辑 ]

论坛徽章:
0
9 [报告]
发表于 2006-05-24 06:31 |只看该作者
在FBSD下打开Polling的效果并不明显
尤其是桥+polling

论坛徽章:
0
10 [报告]
发表于 2006-05-24 08:37 |只看该作者
多谢xfsoul的测试和xie_minix的分析!我找到了一篇含有polling性能测试的文章,并把FreeBSD的net、performance和hackers邮件列表上从2003年到现在的关于polling的讨论话题整理了一下,希望大家能够一起把这个问题弄明白。^_^

Improving Passive Packet Capture: Beyond Device Polling
    http://luca.ntop.org/Ring.pdf

FreeBSD-net

if_bridge + polling get lower througphts
    http://unix.derkeiler.com/Mailin ... 06-03/msg00142.html

Polling for ath driver
    http://unix.derkeiler.com/Mailin ... 06-02/msg00054.html

dummynet, em driver, device polling issues :-((
    http://unix.derkeiler.com/Mailin ... t/2005-10/0019.html

[REVIEW/TEST] polling(4) changes
    http://unix.derkeiler.com/Mailin ... t/2005-09/0259.html

About guideline of parameters tuning while in polling mode.
    http://unix.derkeiler.com/Mailin ... t/2005-09/0147.html

polling in 4.11 vs 5.4
    http://unix.derkeiler.com/Mailin ... t/2005-08/0183.html

polling and twa coexistence problems under 5.4-PRE
    http://unix.derkeiler.com/Mailin ... t/2005-03/0217.html

Re: Giant-free polling [PATCH]
    http://unix.derkeiler.com/Mailin ... t/2005-03/0011.html

xl(4) & polling
    http://unix.derkeiler.com/Mailin ... t/2005-02/0090.html

freebsd router project. Problems with polling?
    http://unix.derkeiler.com/Mailin ... t/2005-01/0259.html

polling(4) rocks!
    http://unix.derkeiler.com/Mailin ... t/2004-11/0144.html

sf(4) device polling
    http://unix.derkeiler.com/Mailin ... t/2004-11/0067.html

device polling takes more CPU hits??
    http://unix.derkeiler.com/Mailin ... t/2004-07/0158.html

[PATCH] vr(4) locking (and DEVICE_POLLING)
    http://unix.derkeiler.com/Mailin ... t/2004-07/0049.html

[PATCH] rl(4) locking and DEVICE_POLLING
    http://unix.derkeiler.com/Mailin ... t/2004-07/0048.html

Per-interface polling(4) status
    http://unix.derkeiler.com/Mailin ... t/2004-04/0104.html

polling(4) and rl(4)
    http://unix.derkeiler.com/Mailin ... t/2004-04/0095.html

Re: Testers wanted: polling(4) support for vr(4)
    http://unix.derkeiler.com/Mailin ... t/2004-04/0094.html

Device polling, kern.polling.burst_max and gig-e
    http://unix.derkeiler.com/Mailin ... t/2004-01/0380.html

DEVICE_POLLING with SMP
    http://unix.derkeiler.com/Mailin ... t/2004-01/0349.html

Paper on device polling and packet capture performance
    http://unix.derkeiler.com/Mailin ... t/2004-01/0070.html

Re: Polling CPU usage
    http://unix.derkeiler.com/Mailin ... t/2004-01/0027.html

Polling CPU usage
    http://unix.derkeiler.com/Mailin ... t/2003-12/0139.html

DEVICE_POLLING together with link0 interrupt offloading?
    http://unix.derkeiler.com/Mailin ... t/2003-09/0156.html

Device polling support for em and bge
    http://unix.derkeiler.com/Mailin ... t/2003-08/0238.html




FreeBSD-performance

Re: [fbsd] Re: Device polling heavy traffic
    http://unix.derkeiler.com/Mailin ... 06-01/msg00006.html

Device polling heavy traffic
    http://unix.derkeiler.com/Mailin ... 05-12/msg00069.html

polling in 4.11 vs 5.4
    http://unix.derkeiler.com/Mailin ... e/2005-08/0047.html

freebsd router project. Problems with polling?
    http://unix.derkeiler.com/Mailin ... e/2005-01/0061.html



FreeBSD-hackers

em0, polling performance, P4 2.8ghz FSB 800mhz
    http://unix.derkeiler.com/Mailin ... s/2004-02/0389.html

Device polling, with SMP?
    http://unix.derkeiler.com/Mailin ... s/2003-11/0259.html

[ 本帖最后由 雨丝风片 于 2006-5-24 09:24 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP