Linux I/O Performance Tests using dd

本文提供关于在Linux环境下使用dd命令进行简单I/O性能测量的实用信息,包括参数选择、笔记本与服务器实例的性能测试以及参考文献。

Under Linux, the dd command can be used for simple I/O performance measurements. This article will provide valuable information about which parameters should be used.

Contents

 [hide

Basics

dd can be used for simplified copying of data at the low level.[1] In doing this, device files are often access directly. Since additional queries do not arrive while the device is being accessed, erroneous usage of dd can quickly lead to data loss. We absolutely recommend performing the steps described below on test systems. If dd is used incorrectly, data loss will be the result.

Measuring Write Performance

Modern operating systems do not normally write files immediately to RAID systems or hard disks. Temporary memory that is not currently in use will be used to cache writes and reads (regarding this, see also Operating System Caches).

So that I/O performance measurements will not be affected by these caches (temporary memory), the oflag parameter can be used. Thereby, the following two flags are interesting (for details, see dd --help and Dd using direct or synchronized I/O):

  • direct (use direct I/O for data)
  • dsync (use synchronized I/O for data)
  • sync (likewise, but also for metadata)

For measuring write performance, the data to be written should be read from /dev/zero[2] and ideally written it to an empty RAID array, hard disk or partition (such as using of=/dev/sda for the first hard disk or of=/dev/sda2 for the second partition on the first hard disk). If this is not possible, a normal file in the file system (such as using of=/root/testdatei1GB) can be written. The write performance achieved thereby will be a little slower (because metadata will also be written to the file system).

Important: When writing to a device (such as /dev/sda), the data stored there will be lost. For that reason, you should only use empty RAID arrays, hard disks or partitions.

Note:

  • When using if=/dev/zero and bs=1G, Linux will need 1GB of free space in RAM. If your test system does not have sufficient RAM available, use a smaller parameter for bs (such as 512MB).
  • In order to get results closer to real-life, we recommend performing the tests described several times (three to ten times, for example). By doing so, you can quickly detectoutliers. Such outliers can include cron jobs, interrupts or general conditions due to parallel processing, which can all briefly affect performance. An extreme example, which clarifies this issue, would be the parallel execution of updatedb by a cron job.

Laptop Example

In this example, the test data will be written to /dev/sda2. The test system (a Thinkpad T43 Type 2668-4GG) had 1.5 GByte of RAM and a Fujitsu MHT2060AH hard disk rotating at 5,400 rpm.

Laptop Throughput (Streaming I/O)

One gigabyte was written for the test, first with the cache activated (hdparm -W1 /dev/sda):

root@grml ~ # dd if=/dev/zero of=/dev/sda2 bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 32.474 s, 33.1 MB/s
root@grml ~ # 

Then, with the cache deactivated (hdparm -W0 /dev/sda):

root@grml ~ # dd if=/dev/zero of=/dev/sda2 bs=1G count=1 oflag=direct    
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 123.37 s, 8.7 MB/s
root@grml ~ # 
Laptop Latency

In this test, 512 bytes were written one thousand times, first with the cache activated (hdparm -W1 /dev/sda):

root@grml ~ # dd if=/dev/zero of=/dev/sda2 bs=512 count=1000 oflag=direct
1000+0 records in
1000+0 records out
512000 bytes (512 kB) copied, 0.36084 s, 1.4 MB/s
root@grml ~ #

Then, with the cache deactivated (hdparm -W0 /dev/sda): One thousand accesses required 11.18 seconds, meaning one access took 11.18 ms.

root@grml ~ # dd if=/dev/zero of=/dev/sda2 bs=512 count=1000 oflag=direct
1000+0 records in
1000+0 records out
512000 bytes (512 kB) copied, 11.1865 s, 45.8 kB/s
root@grml ~ # 

Server with RAID10 Example

In this example, the test data was written to an empty partition. The test system was an 2HE Intel Dual-CPU SC823 Server with six 147 GB SAS Fujitsu MBA3147RC (15,000 rpm) hard disks and an Adaptec 5805 RAID controller with the cache activated and a BBU.

Server Throughput (Streaming I/O)

One gigabyte was written for the test:

test-sles10sp2:~ # dd if=/dev/zero of=/dev/sda6 bs=1G count=1 oflag=dsync
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 5.11273 seconds, 210 MB/s
test-sles10sp2:~ 
Server Latency

In this test, 512 bytes were written one thousand times. Thereby, the 0.084 seconds that were measured for one thousand accesses corresponded to precisely 0.084 ms for each access. This value is so low because of the RAID controller’s cache:

test-sles10sp2:~ # dd if=/dev/zero of=/dev/sda6 bs=512 count=1000 oflag=dsync
1000+0 records in
1000+0 records out
512000 bytes (512 kB) copied, 0.083902 seconds, 6.1 MB/s
test-sles10sp2:~ #

References

  1.  Dd (Unix) (en.wikipedia.org)
  2.  /dev/zero (en.wikipedia.org)

Author: Werner Fischer


From
【电能质量扰动】基于ML和DWT的电能质量扰动分类方法研究(Matlab实现)内容概要:本文研究了一种基于机器学习(ML)和离散小波变换(DWT)的电能质量扰动分类方法,并提供了Matlab实现方案。首先利用DWT对电能质量信号进行多尺度分解,提取信号的时频域特征,有效捕捉电压暂降、暂升、中断、谐波、闪变等常见扰动的关键信息;随后结合机器学习分类器(如SVM、BP神经网络等)对提取的特征进行训练与分类,实现对不同类型扰动的自动识别与准确区分。该方法充分发挥DWT在信号去噪与特征提取方面的优势,结合ML强大的模式识别能力,提升了分类精度与鲁棒性,具有较强的实用价值。; 适合人群:电气工程、自动化、电力系统及其自动化等相关专业的研究生、科研人员及从事电能质量监测与分析的工程技术人员;具备一定的信号处理基础和Matlab编程能力者更佳。; 使用场景及目标:①应用于智能电网中的电能质量在线监测系统,实现扰动类型的自动识别;②作为高校或科研机构在信号处理、模式识别、电力系统分析等课程的教学案例或科研实验平台;③目标是提高电能质量扰动分类的准确性与效率,为后续的电能治理与设备保护提供决策依据。; 阅读建议:建议读者结合Matlab代码深入理解DWT的实现过程与特征提取步骤,重点关注小波基选择、分解层数设定及特征向量构造对分类性能的影响,并尝试对比不同机器学习模型的分类效果,以全面掌握该方法的核心技术要点。
<think>我们面对的是在编译RISC-V测试程序时出现的链接错误:`ldcannotfind-lgcc`。根据之前的分析和引用内容,我们可以从以下几个方面解决:###问题原因分析1.**工具链路径问题**:链接器无法找到`libgcc.a`库文件,可能因为工具链安装不完整或环境变量未正确设置。2.**specs文件缺失**:在裸机环境下编译需要指定特殊的specs文件(如`nosys.specs`)来替代标准库。3.**库搜索路径未包含**:编译时未通过`-L`选项指定`libgcc.a`所在的目录。###解决方案步骤####1.定位libgcc库文件首先确定工具链中`libgcc.a`的实际位置。假设你的RISC-V工具链安装在`/opt/riscv32i`(根据Makefile中的路径`/opt/riscv32i/bin/riscv32-unknown-elf-gcc`推断),执行以下命令搜索:```bashfind/opt/riscv32i-name"libgcc.a"```典型结果可能为:```/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/libgcc.a```####2.修改Makefile指定库路径在Makefile的链接步骤中,通过`-L`选项添加库路径。根据上述搜索结果,修改链接命令:```makefile#修改前$(CC)...-lgcc#修改后:添加-L路径$(CC)...-L/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/-lgcc```####3.添加裸机specs文件引用[2]提到裸机编译需使用`nosys.specs`或`nano.specs`。在链接标志中加入:```makefileLDFLAGS+=-specs=nosys.specs```完整链接步骤示例:```makefile/opt/riscv32i/bin/riscv32-unknown-elf-gcc\-Os-mabi=ilp32-march=rv32imc\-ffreestanding-nostdlib\-specs=nosys.specs\#添加此行-L/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/\#添加此行-Wl,--build-id=none,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug\...其他对象文件...\-lgcc```####4.验证工具链完整性若仍报错,检查工具链是否完整。重新安装RISC-V工具链:```bash#下载官方工具链(若未安装)gitclone--recursivehttps://github.com/riscv/riscv-gnu-toolchaincdriscv-gnu-toolchain./configure--prefix=/opt/riscv32i--with-arch=rv32imc--with-abi=ilp32make```###完整Makefile修正示例```makefile#修改前/opt/riscv32i/bin/riscv32-unknown-elf-gcc-Os...-ofirmware/firmware.elf...-lgcc#修改后/opt/riscv32i/bin/riscv32-unknown-elf-gcc\-Os-mabi=ilp32-march=rv32imc\-ffreestanding-nostdlib\-specs=nosys.specs\-L/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/\-Wl,...\...\-lgcc```###验证解决重新执行`maketest`,链接错误应消失。###相关问题1.RISC-V工具链中`libgcc.a`的作用是什么?2.如何在CMake项目中正确配置RISC-V交叉编译?3.`nosys.specs`与`nano.specs`有何区别?[^2]4.RISC-V链接脚本(`.lds`)如何编写以适应不同内存布局?[^1]:引用自RISC-V工具链使用指南[^2]:引用自GCC裸机编译规范文档</think>## RISC-V GCC编译时 "ld cannot find -lgcc" 解决方案 ### 问题根源分析 根据您的构建日志和引用内容[^1][^2],此错误通常由以下原因造成: 1. **工具链路径配置不完整**:`libgcc.a`库文件未在链接器搜索路径中 2. **specs文件缺失**:裸机环境需要特殊specs文件(如`nosys.specs`) 3. **ABI不匹配**:编译选项与库文件ABI不一致 4. **工具链安装问题**:GCC运行时库未正确安装 ### 逐步解决方案 #### 1. 验证libgcc库是否存在 ```bash # 在工具链目录查找libgcc.a find /opt/riscv32i -name "libgcc.a" # 典型路径示例 /opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/libgcc.a ``` #### 2. 修改Makefile添加库路径 在链接命令中显式添加库路径(根据上一步找到的实际路径): ```makefile # 修改前 $(CC) ... -lgcc # 修改后:添加-L路径参数 $(CC) ... -L/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/ -lgcc ``` #### 3. 添加裸机specs文件配置 引用[^2]中提到裸机环境需要特殊specs文件,在编译选项中添加: ```makefile # 在CFLAGS或LDFLAGS中添加 -specs=nosys.specs ``` #### 4. 完整Makefile修改示例 ```makefile # 修改后的链接命令 /opt/riscv32i/bin/riscv32-unknown-elf-gcc \ -Os -mabi=ilp32 -march=rv32imc \ -ffreestanding -nostdlib \ -specs=nosys.specs \ # 添加specs -L/opt/riscv32i/lib/gcc/riscv32-unknown-elf/8.2.0/ \ # 添加库路径 -Wl,--build-id=none,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \ ... # 其他对象文件 -lgcc ``` #### 5. 验证工具链安装 如果找不到libgcc.a,重新安装工具链: ```bash # 下载官方工具链 git clone --recursive https://github.com/riscv/riscv-gnu-toolchain # 配置并安装32位工具链 cd riscv-gnu-toolchain ./configure --prefix=/opt/riscv32i --with-arch=rv32imc --with-abi=ilp32 make ``` ### 根本原因解析 1. **libgcc作用**:提供底层运行时支持(除法和浮点操作等) 2. **specs文件作用**:定义裸机环境系统调用桩函数[^2] 3. **路径问题**:RISC-V工具链默认不包含标准库搜索路径 ### 相关问题 1. 如何为不同RISC-V扩展(如C扩展)定制工具链? 2. `nosys.specs`和`nano.specs`有何区别?[^2] 3. RISC-V链接器脚本(sections.lds)的关键配置项有哪些? 4. 如何验证RISC-V工具链安装完整性? [^1]: 引用自RISC-V工具链调试指南 [^2]: 引用自GCC裸机编译规范文档
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值