当前位置: 首页 > ds >正文

linux 常用工具的静态编译之一

   

目录

I2C-utils

正确编译修改

部分静态编译问题

can-utils

iozone

编译

使用

初次测试速率

增加I参数,使能direct测试

EMMC的设计速率

修改块大小及测试文件大小

 dd命令速率对比


在嵌入式开发中,有时一些常用的工具在系统中并没有,这时或者通过buildroot等在制作文件系统时生成,或者静态交叉编译使用。

  静态交叉编译出的文件虽然大,但通用性好。本文介绍几个常用工具的交叉编译,在x86机器编译aarch64。

I2C-utils

正确编译修改

i2c-tools-4.4.tar.xz  下载此软件包

修改makefile,左侧为修改后的,右侧为原始的。

1)CC CFLAGS LDFLAGS等是常规操作,也就是配置采用的交叉编译工具链、静态编译、静态连接。

  • ?=:条件赋值(Conditional Assignment),意思是:

    • 如果 CC 未定义,则将其赋值为 aarch64-linux-gnu-gcc

    • 如果 CC 已定义(比如通过命令行或环境变量传入),则保持原值不变。

系统中默认会有CC等的定义,所以这里修改makefile的时候要改成明确赋值的形式,不能用原先的条件赋值。

2) BUILD_DYNAMIC_LIB ?= 1
BUILD_STATIC_LIB ?= 1
USE_STATIC_LIB ?= 0

这三个宏在make 命令时指也可以,含义分别是编译出动态库、静态库、以及是否使用静态库链接。默认会将动态库和静态库都编译出来,这点I2C utils做的比较好,将依赖的库也放到包里,一起编译,不用单独去下载lib库进行编译。

i2c/i2c-tools-4.4/lib$ ls
libi2c.3  libi2c.a  libi2c.map  libi2c.so  libi2c.so.0  libi2c.so.0.1.1  Module.mk  smbus.ao  smbus.c  smbus.o

关键的USE_STATIC_LIB配置,配置了此选项,加上CFLAGS LDFLAGS,就达到静态编译的效果。

最终文件确认: 

i2c/i2c-tools-4.4/tools$ file i2cdetect
i2cdetect: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=7bd3c3fd4c15c1fe8674111b4e02e223a947935e, not stripped

部分静态编译问题

  由于配置不完全,遇到过部分静态编译的情况,即:

   

  1. ldd tools/i2cdetect 提示"不是动态可执行文件"

  2. file tools/i2cdetect 却显示"dynamically linked"

 通过如下两个命令可以看到还需要动态库。

aarch64-linux-gnu-readelf -d tools/i2cdetectDynamic section at offset 0x3c08 contains 29 entries:标记        类型                         名称/值0x0000000000000001 (NEEDED)             共享库:[libi2c.so.0]0x0000000000000001 (NEEDED)             共享库:[libc.so.6]0x0000000000000001 (NEEDED)             共享库:[ld-linux-aarch64.so.1]0x000000000000000c (INIT)               0x12f0

 

aarch64-linux-gnu-objdump -x tools/i2cdetect | grep NEEDEDNEEDED               libi2c.so.0NEEDED               libc.so.6NEEDED               ld-linux-aarch64.so.1

can-utils

git clone https://github.com/linux-can/can-utils.git
cd can-utils

make CC=aarch64-linux-gnu-gcc CFLAGS="-Wall -O2 -static" LDFLAGS="-static" -j$(nproc)

file candump
candump: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=8f368bccb53ba7db96dca03b447b2ff004b3200b, not stripped

can的交叉编译是最简单的一个了 

iozone

编译

ozone/iozone3_492/src/current$ make -f makefile linux CC=aarch64-linux-gnu-gcc CFLAGS="-O3 -static -pthread" LDFLAGS="-static -pthread"

虽然有如下告警,但不影响使用

iozone_linux.o:在函数‘time_so_far.part.24’中:
iozone.c:(.text+0x96c): 警告: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
iozone_linux.o:在函数‘child_send’中:
iozone.c:(.text+0x6760): 警告: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
aarch64-linux-gnu-gcc  -O3 -O3 -static -pthread -Dlinux fileop_linux.o -o fileop
aarch64-linux-gnu-gcc  -O3 -O3 -static -pthread -Dlinux pit_server.o -o pit_server
pit_server.o:在函数‘openSckt.constprop.0’中:
pit_server.c:(.text+0x8e4): 警告: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

使用

初次测试速率

../iozone -s 200M -i 0 -i 1 -i 2 -f ./testfileIozone: Performance Test of File I/OVersion $Revision: 3.492 $Compiled for 64 bit mode.Build: linuxContributors:William Norcott, Don Capps, Isom Crawford, Kirby CollinsAl Slater, Scott Rhine, Mike Wisner, Ken GossSteve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer,Vangel Bojaxhi, Ben England, Vikentsi Lapa,Alexey Skidanov, Sudhir Kumar.Run began: Fri Mar  9 12:37:09 2018File size set to 204800 kBCommand line used: ../iozone -s 200M -i 0 -i 1 -i 2 -f ./testfileOutput is in kBytes/secTime Resolution = 0.000001 seconds.Processor cache size set to 1024 kBytes.Processor cache line size set to 32 bytes.File stride size set to 17 * record size.random    random     bkwd    record    stride                                   kB  reclen    write  rewrite    read    reread    read     write     read   rewrite      read   fwrite frewrite    fread  freread204800       4   586795  1463232  2878627  2226543  1346881  1022359iozone test complete.

 

  • write:顺序写入速度(KB/s)。

  • rewrite:随机写入速度(KB/s)。

  • read:顺序读取速度(KB/s)。

  • reread:随机读取速度(KB/s)

测试模式速率 (KB/s)换算为 MB/s (÷1024)
顺序写 (write)586795 KB/s573.0 MB/s
随机写 (rewrite)1463232 KB/s1428.9 MB/s
顺序读 (read)2878627 KB/s2811.2 MB/s
随机读 (reread)2226543 KB/s2174.4 MB/s

iozone 默认可能使用系统缓存(尤其是 read 测试),导致速度虚高

 

增加I参数,使能direct测试

../iozone -I -s 200M -i 0 -i 1 -i 2 -f ./testfile

O_DIRECT feature enabled

../iozone -I -s 200M -i 0 -i 1 -i 2 -f ./testfileIozone: Performance Test of File I/OVersion $Revision: 3.492 $Compiled for 64 bit mode.Build: linuxContributors:William Norcott, Don Capps, Isom Crawford, Kirby CollinsAl Slater, Scott Rhine, Mike Wisner, Ken GossSteve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer,Vangel Bojaxhi, Ben England, Vikentsi Lapa,Alexey Skidanov, Sudhir Kumar.Run began: Fri Mar  9 12:44:58 2018O_DIRECT feature enabledFile size set to 204800 kBCommand line used: ../iozone -I -s 200M -i 0 -i 1 -i 2 -f ./testfileOutput is in kBytes/secTime Resolution = 0.000001 seconds.Processor cache size set to 1024 kBytes.Processor cache line size set to 32 bytes.File stride size set to 17 * record size.random    random     bkwd    record    stride                                   kB  reclen    write  rewrite    read    reread    read     write     read   rewrite      read   fwrite frewrite    fread  freread204800       4    32024    35229    20319    20327    19883    22648
  • 写入速度
    • 顺序写:31.27 MB/s
    • 随机写:34.40 MB/s(比顺序写稍快,可能是缓存优化)
  • 读取速度
    • 顺序读:19.84 MB/s
    • 随机读:19.85 MB/s(几乎相同,说明随机访问影响不大)

EMMC的设计速率

根据下面信息 理论到400MB/s,而实际几十M,相差太大

cat /sys/kernel/debug/mmc0/ios
clock:          200000000 Hz
actual clock:   200000000 Hz
vdd:            18 (3.0 ~ 3.1 V)
bus mode:       2 (push-pull)
chip select:    0 (don't care)
power mode:     2 (on)
bus width:      3 (8 bits)
timing spec:    10 (mmc HS400 enhanced strobe)
signal voltage: 1 (1.80 V)
driver type:    0 (driver type B)

修改块大小及测试文件大小

../iozone -I -s 1G -i 0 -i 1 -r 1M -f  /root/emmctest/testfileiozoneO_DIRECT feature enabledFile size set to 1048576 kBRecord Size 1024 kBOutput is in kBytes/secTime Resolution = 0.000001 seconds.Processor cache size set to 1024 kBytes.Processor cache line size set to 32 bytes.File stride size set to 17 * record size.random    random     bkwd    record    stride                                   kB  reclen    write  rewrite    read    reread    read     write     read   rewrite      read   fwrite frewrite    fread  freread1048576    1024   205861   199180   261145   261067
  • 关键读写速率 (KB/s):

    • 顺序写 (write)205861 KB/s ≈ 201 MB/s

    • 随机写 (rewrite)199180 KB/s ≈ 194.5 MB/s

    • 顺序读 (read)261145 KB/s ≈ 255 MB/s

    • 随机读 (reread)261067 KB/s ≈ 255 MB/s

 dd命令速率对比

 sync; dd if=/dev/zero of=/root/emmctest/testfile bs=1M count=200 oflag=direct conv=fdatasync
200+0 records in
200+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 1.11376 s, 188 MB/secho 3 > /proc/sys/vm/drop_caches
dd if=/root/emmctest/testfile of=/dev/null bs=1M count=200 iflag=direct
200+0 records in
200+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 0.876424 s, 239 MB/s

  • eMMC 芯片性能

    • 高端 eMMC 5.1 芯片在 HS400ES 下可达 300~350 MB/s(顺序读写)。

    • 低端芯片可能仅达 200~250 MB/s

   为了测试硬件的性能,我们需要选取有效参数。

http://www.xdnf.cn/news/14431.html

相关文章:

  • Python打卡训练营-Day31-文件的规范拆分和写法
  • Vue2 与 Vue3 中环境变量配置的差异详解。
  • 电力系统时间同步检测技术
  • (下)通用智能体与机器人Transformer:Gato和RT-1技术解析及与LLM Transformer的异同
  • 【Golang面试题】什么是 sync.Once
  • 安全生产台账系统
  • 【无标题】二维势能塌陷的拓扑色动力学:数学物理框架与引力本质探索
  • 华为OD机试_2025 B卷_数组排列求和(Python,100分)(附详细解题思路)
  • vim编辑常用命令
  • JAVA理论第十七章-RocketMQKafaka
  • 【Linux教程】Linux 生存指南:掌握常用命令,避开致命误操作
  • 基于可靠消息确保分布式事务的最终一致性:以电商系统中订单服务的新建订单为例
  • C# 使用 TreeView 实践 WinRiver II 的测量管理功能
  • 篇章六 论坛系统——业务开发——实现业务功能
  • Java 与 MySQL 性能优化:Linux服务器上MySQL性能指标解读与监控方法
  • 修改Typora快捷键
  • 新的激活函数B-SiLU和NeLU:ReLU函数的复兴
  • 6.14项目一话术
  • 四六级英语作文模版
  • LeetCode 第72题:编辑距离(巧妙的动态规划方法)
  • 同旺科技 USB TO SPI / I2C适配器(专业版)--EEPROM读写——C
  • uni-app项目实战笔记14--给全屏页面添加遮罩层
  • 深度学习中的激活函数:PyTorch中的ReLU及其应用
  • 人工智能学习14-Numpy-数组广播机制
  • AtCoder AT_abc410_e [ABC410E] Battles in a Row 题解
  • 如何识别并管理多项目环境下的潜在风险
  • 【Git】使用 SSH 协议 解决 Git 推送失败问题
  • 思科资料-思科交换机的常见配置(详细总结)
  • SCADA|KingSCADA对比显示任意几条实时曲线的方法
  • [特殊字符] Next.js Turbo 模式不支持 @svgr/webpack 的原因与解决方案