printk_ratelimit

在Linux内核代码里当需要限制printk打印频率时会用到__ratelimitprintk_ratelimit(封装了__ratelimit)

printk_ratelimit默认允许在5s内最多打印10条消息出来

1
2
3
4
$cat /proc/sys/kernel/printk_ratelimit
5
$cat /proc/sys/kernel/printk_ratelimit_burst
10
1
2
3
4
5
6
7
8
9
if (printk_ratelimit()) {
dev_err(adev->dev, "GPU fault detected: %d 0x%08x\n",
entry->src_id, entry->src_data[0]);
dev_err(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
addr);
dev_err(adev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
status);
gmc_v8_0_vm_decode_fault(adev, status, addr, mc_client);
}

参考

  • 限制printk打印频率函数printk_ratelimit