当我在 linux 用户空间和内核空间运行一些简单的 while 循环代码并测量经过的时间时,我可以得到差异。
测试代码是访问 Arm Cortex SoC 芯片中的一些硬件寄存器。
for(k = 0; k < 100000; k++)
{ //I tested this code in user space and kernel space with IOCTL.
for(i = 0; i < 1000; i++)
{
tv2 = *(volatile UInt32 *)(0xfe110080);
*(volatile UInt32 *)(0xfe628024) = i + tv2 ;
}
}
结果是
用户层:52002.16 ms
内核层:32650.53 ms
内核层比用户层快 1.6 倍。