Linux直接访问块设备扇区

作者

QQ群:852283276
微信:arm80x86
微信公众号:青儿创客基地
B站:主页 https://space.bilibili.com/208826118

方法

获取块设备大小

ret = ioctl(fd[i], BLKGETSIZE64, &size);
   if (ret < 0) {
       printf("ioctl BLKGETSIZE64 error, errno=%d\n", errno);
       return -1;
   }

读写,

lseek(fd[i], diskStart, SEEK_SET);
ret = write(fd[i], (void *)(unsigned long)sysStart, rwLength);
   if (ret < 0) {
       printf("write error, errno=%d\n", errno);
       return -1;
   }
ret = read(fd[i], (void *)(unsigned long)sysStart, rwLength);
if (ret < 0) {
	printf("readerror, errno=%d\n", errno);
	return -1;
}

测试

在xilinx zynqmp平台上,读写PS端内存,zynqmp用一个PCIe2.0x8接到PLX8724上,

root@zynqmp:~# blk_benchmark -r /dev/nvme1n1 -s 0 -l 0x400000 -c 16
speed: 412.90MB/s, cost times: 155ms
root@zynqmp:~# blk_benchmark -r /dev/nvme0n1 -s 0 -l 0x400000 -c 32
speed: 526.75MB/s, cost times: 243ms
root@zynqmp:~# blk_benchmark -r /dev/nvme0n1 -s 0 -l 0x400000 -c 128
speed: 1034.34MB/s, cost times: 495ms
root@zynqmp:~# blk_benchmark -w /dev/nvme1n1 -s 0 -l 0x400000 -c 16
speed: 1032.26MB/s, cost times: 62ms
root@zynqmp:~# blk_benchmark -w /dev/nvme1n1 -s 0 -l 0x400000 -c 32
speed: 1066.67MB/s, cost times: 120ms
root@zynqmp:~# blk_benchmark -w /dev/nvme1n1 -s 0 -l 0x400000 -c 128
speed: 1075.63MB/s, cost times: 476ms

在T2080平台上测试,T2080用一个PCIe2.0x4接到PLX的Switch上,

root@t2080rdb:~# blk_benchmark -r /dev/nvme0n1 -s 0 -l 0x400000 -c 32 
speed: 414.24MB/s, cost times: 309ms
root@t2080rdb:~# blk_benchmark -r /dev/nvme0n1 -s 0 -l 0x400000 -c 128
speed: 420.36MB/s, cost times: 1218ms
root@t2080rdb:~# blk_benchmark -w /dev/nvme0n1 -s 0 -l 0x400000 -c 128 
speed: 387.59MB/s, cost times: 1321ms
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值