GMAC
介绍GMAC的功能和使用方法。
模块介绍
GMAC(Gigabit Media Access Controller)模块是一种用于支持千兆以太网通信的控制器,负责数据帧的发送、接收和网络流量管理。
功能介绍
应用层:面向用户提供应用服务。
协议栈层:实现网络协议,为应用层提供系统调用接口。
网络设备抽象层:屏蔽驱动实现细节,为协议栈提供统一接口。
网络设备驱动层:实现数据传输和设备管理。
物理层:网络硬件设备。
源码结构介绍
gmac驱动代码在drivers\net\ethernet\spacemit目录下:
drivers\net\ethernet\spacemit
|-- emac-ptp.c #提供PTP协议支持
|-- k1x-emac.c #k1 gmac驱动代码
|-- k1x-emac.h #k1 gmac驱动头文件
关键特性
特性
特性 | 特性说明 |
---|---|
支持10/100/1000M以太网 | 兼容多速率以太网连接 |
支持DMA | 高效数据传输降低CPU负载 |
支持NAPI | 提升中断处理效率减少CPU开销 |
中断合并机 制 | 合并中断提升高负载性能 |
支持RGMII/RMII | 适应多应用场景 |
支持PTP | 实现设备间亚微秒级时间同步 |
支持电源管理 | 支持挂起恢复适应低功耗需求 |
性能参数
单网卡单工 | 单网卡双工 | 双网卡单工 | 双网卡双工 | |
---|---|---|---|---|
TX速率 (MB/s) | 942 | 930 | 942 | 797 |
RX速率 (MB/s) | 941 | 940 | 941 | 881 |
注:双工情形下测试带宽具有一定波动 |
性能测试
测试环境
测试 物料:一块k1-deb1板;一台PC,型号:HP ProBook 450 15.6 inch G10 Notebook PC、系统:Ubuntu 22.04.4 LTS
网络拓扑:k1-deb1 eth0口与PC以太网口直连;k1-deb1 eth1口经2.5G usb转以太网连接器与PC直连
IP设置:直连网口IP设置在同一个网段,PC端开启两个iperf服务端
# Set IP for the PC
ifconfig <ethernet-interface> 192.168.1.100 netmask 255.255.255.0
ifconfig <usb-ethernet-interface> 192.168.2.100 netmask 255.255.255.0
# Set IP for the k1-deb1 net device
ifconfig eth0 192.168.1.200 netmask 255.255.255.0
ifconfig eth1 192.168.2.200 netmask 255.255.255.0
# Start iperf3 server on the PC
iperf3 -s -B 192.168.1.100 -A 10 -D
iperf3 -s -B 192.168.2.100 -A 11 -D
性能优化
为最大化网络吞吐量,在测试前先对k1-deb1板网口中断进行合理的CPU绑定和分配,以充分利用多核资源
第一步:通过以下命令查看当前中断分配情况,确认两个网卡对应的中断号:
cat /proc/interrupts | grep eth*
85: 11041 2332003 0 0 0 0 0 0 SiFive PLIC 131 Edge eth0
86: 234 0 409744 0 0 0 0 0 SiFive PLIC 133 Edge eth1
第二步:将网口硬件中断绑定到不同CPU核,例如eth0绑定至CPU1、eth1绑定至CPU2
echo 02 > /proc/irq/85/smp_affinity
echo 04 > /proc/irq/86/smp_affinity
第三步:启用 RPS(Receive Packet Steering)进行接收端的软中断负载均衡。例如下面命令允许CPU4处理eth0上接收数据包、CPU5处理eth1接收数据包,充分利用多核 优势。
echo 10 > /sys/devices/platform/soc/cac80000.ethernet/net/eth0/queues/rx-0/rps_cpus
echo 4096 > /sys/devices/platform/soc/cac80000.ethernet/net/eth0/queues/rx-0/rps_flow_cnt
echo 20 > /sys/devices/platform/soc/cac81000.ethernet/net/eth1/queues/rx-0/rps_cpus
echo 4096 > /sys/devices/platform/soc/cac81000.ethernet/net/eth1/queues/rx-0/rps_flow_cnt
单网卡测试
使用eth0口进行单网卡测试,并将 当前iperf3进程绑定到CPU6
单工/TX
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 6
单工/RX
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 6 -R
双工
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 6 --bidir
双网卡测试
双网卡测试中将两个iperf3进程分别绑定到CPU6、CPU7
单工/TX
# Bind CPU6 for the first test, bind CPU7 for the second test
iperf3 -c 192.168.2.100 -B 192.168.2.200 -t 100 -A 6 > 1.txt &
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 7 > 2.txt &
# View the test results
cat 1.txt
cat 2.txt
单工/RX
iperf3 -c 192.168.2.100 -B 192.168.2.200 -t 100 -A 6 -R > 1.txt &
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 7 -R > 2.txt &
cat 1.txt
cat 2.txt
双工
iperf3 -c 192.168.2.100 -B 192.168.2.200 -t 100 -A 6 --bidir > 1.txt &
iperf3 -c 192.168.1.100 -B 192.168.1.200 -t 100 -A 7 --bidir > 2.txt &
cat 1.txt
cat 2.txt
配置介绍
主要包括驱动使能配置和dts配置
CONFIG配置
NET_VENDOR_SPACEMIT:如果使用的是 Spacemit 类型的以太网芯片,请将此选项设置 Y
config NET_VENDOR_SPACEMIT
bool "Spacemit devices"
default y
depends on SOC_SPACEMIT
help
If you have a network (Ethernet) chipset belonging to this class,
say Y.
Note that the answer to this question does not directly affect
the kernel: saying N will just cause the configurator to skip all
the questions regarding Spacemit chipsets. If you say Y, you will
be asked for your specific chipset/driver in the following questions.
K1X_EMAC:启用 Spacemit的GMAC驱动
config K1X_EMAC
bool "k1-x Emac Driver"
depends on SOC_SPACEMIT_K1X
select PHYLIB
help
This Driver support Spacemit k1-x Ethernet MAC
Say Y to enable support for the Spacemit Ethernet.