[PCIe] linux 下测试ASPM
1. kernel config & driver
.config - Linux/arm64 5.4.31 Kernel Configuration
> Device Drivers > PCI support
打开 PCI Express ASPM control和Debug PCI Express ASPM (会在sys_fs中添加aspm的控制node,方便手动修改进行测试)
电源策略选择Power Supersave
电源策略也可以通过读写sysfs节点进行动态修改
cat /sys/module/pcie_aspm/parameters/policy
default performance powersave [powersupersave]
echo powersave > /sys/module/pcie_aspm/parameters/policy
在dts中修改bootargs,增加pcie_aspm=force
启动kernel后会看到aspm force的打印
[ 0.000000] PCIe ASPM is forcibly enabled
2. 通过sys_fs接口进行测试
加载aspm driver后默认device的aspm cap还是关闭的,需要手动打开,然后查看ltssm状态机,观察link状态是否会自动切换到L0s或L1。
2.1 首先通过lspci -vv查看当前LnkCtl的值
这里可以看到这个device是支持L0s和L1的ASPM,不过当前状态是关闭的。
2.2 通过sys_fs打开ASPM
打开CONFIG_PCIEASPM_DEBUG后,在/sys/bus/pci/devices/0000\:00\:00.0/power/下会多出一个link_state节点(/0000\:00\:00.0/这个是domain/bus/device/function 需自行修改操作的设备值)。
cat一下看看初始值,为0。
这个link_state的定义在kernel\drivers\pci\pcie\aspm.c中,0是关闭ASPM,非0值的含义如下:
/* Note: those are not register definitions */
#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
#define ASPM_STATE_L1 (4) /* L1 state */
#define ASPM_STATE_L1_1 (8) /* ASPM L1.1 state */
#define ASPM_STATE_L1_2 (0x10) /* ASPM L1.2 state */
#define ASPM_STATE_L1_1_PCIPM (0x20) /* PCI PM L1.1 state */
#define ASPM_STATE_L1_2_PCIPM (0x40) /* PCI PM L1.2 state */
#define ASPM_STATE_L1_SS_PCIPM (ASPM_STATE_L1_1_PCIPM | ASPM_STATE_L1_2_PCIPM)
#define ASPM_STATE_L1_2_MASK (ASPM_STATE_L1_2 | ASPM_STATE_L1_2_PCIPM)
#define ASPM_STATE_L1SS (ASPM_STATE_L1_1 | ASPM_STATE_L1_1_PCIPM |\
ASPM_STATE_L1_2_MASK)
#define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
#define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1 | \
ASPM_STATE_L1SS)
具体配置把需要打开的ASPM能力对应的值或在一起就可以了,例如需要打开L0s.tx 和L0s.rx :
# echo 3 > /sys/bus/pci/devices/0000\:00\:00.0/power/link_state
# cat /sys/bus/pci/devices/0000\:00\:00.0/power/link_state
3
再lspci -vv查看,ASPM L0s已经打开
查看LTSSM寄存器值(这个是特定芯片的地址,仅供示例)
可以看到打开ASPM L0s之后LTSSM在L0s的各个状态之间跳转
L1的测试类似,link_state写入7,打开ASPM L1 enable
# echo 7 > /sys/bus/pci/devices/0000\:00\:00.0/power/link_state
# cat /sys/bus/pci/devices/0000\:00\:00.0/power/link_state
7
lspci -vv 确认已经打开L1
稍等一会查看LTSSM寄存器,已经进入到L1.Idle
更多推荐
所有评论(0)