1 / 48
文档名称:

map源码分析.doc

格式:doc   大小:140KB   页数:48页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

map源码分析.doc

上传人:liangwei2005 2019/10/20 文件大小:140 KB

下载得到文件列表

map源码分析.doc

相关文档

文档介绍

文档介绍:高性能网络I/map源码分析(1)作者:@博客:-:/glinuxerQQ技术群:map,看了它的介绍和设计,确实是个好东西。其设计思想与业界不谋而合——因为为了提高性能,几个性能瓶颈放在那里,解决方法自然也是类似的。由于保密性,我是不可能拿公司的设计来和大家讨论和分享的。而netmap的出现,提供了这么一个好机会。它既实现了一个高性能的网络I/O框架,代码量又不算大,map的作者,map的文档写得很不错,map可以达到高性能。,将网卡驱动的ring内存空间映射到用户空间。这样用户态可以直接访问到原始的数据包,避免了内核和用户态的两次拷贝;——前两天我还想写这么一个东西呢。。这样减少了内核原有的动态分配;——对于网络设备来说,固定大小的内存池比buddy要有效的多。之前我跟Bean_lee也提过此事呵。。这样就减少了系统调用;更具体的内容,map的官方网站上看吧,写得很详细。虽然英文,大家还是耐着性子好好看看,map不可避免的要修改网卡驱动。不过这个修改量很小。。map最早是在FreeBSD上实现的,为了在linux达到最小的修改,使用了大量的宏,这给代码的阅读带来了一些困难。e1000_probe的修改俺不是写驱动的。。。e1000_probe里面很多代码看不明白,map的分析。map的patch,知道是在e1000完成一系列硬件初始化以后,并注册成功,map_attach@@-1175,6+1183,10@***@staticint__devinite1000_probe(structif(err)gotoerr_register;+#MAP+map_attach(adapter);+#endif/*MAP*/+/*printbustype/speed/widthinfo*/e_info(probe,"(PCI%s:%dMHz:%d-bit)%pM\n",((hw->bus_type==e1000_bus_type_pcix)?"-X":""),map_attach(structSOFTC_T*adapter){map_adapterna;bzero(&na,sizeof(na));=adapter->netdev;=0;=adapter->tx_ring[0].count;=adapter->rx_ring[0].count;=map_reg;=map_txsync;=map_attach(&na,1);}SOFTC_T是一个宏定义,对于e1000,实际上是e1000_adapter,即e1000网卡驱动对应的privatedata。map_adapter的定义/**Thisstructextendsthe'structadapter'(or*equivalent)*mapoperation.*/map_adapter{/**Onlinuxwedonothaveagoodwaytotellifaninterface*map-:*NA(ifp)pointshere,andthefirstentry(whichhopefully*alwaysexistsandisatleast32bits)containsamagic*valuewhichwecanusetodetectthattheinterfaceisgood.*/uint32_tmagic;uint32_tna_flags;/*MAP*/intrefcount;/*numberofuser-spacedescriptorsusingthisinterface,map_ifobjsinthemappedregion.*//**Theselwakeupintheinterruptthreadcanuseper-ring**ofeachtypewehavesowecanoptimizethedrivers,*andespeciallyavoidhugecontentiononthelocks.*/intna_single;/*threadsattachedtoasinglehwqueue