IOzone使用简介(Linux)
- 格式:doc
- 大小:740.00 KB
- 文档页数:8
如何在Linux 下撰写程序来使用I/O 端口1. 介绍本文的内容说明了 Intel x86 架构下如何在使用者模式 (user-mode) 中撰写程序来使用硬件 I/O 端口以及等待一小段的时间周期. 内容源自於一篇非常短的文章 IO-Port mini-HOWTO 其作者与本文同.本文 1995-1997 的版权属於 Riku Saikkonen 所有. 版权声明详见网页Linux HOWTO copyright.如果您对本文有任何指教不论是错误修正或是内容补述, 都欢迎寄信给我(Riku.Saikkonen@hut.fi)...本文对前一次发行的版本 (Mar 30 1997) 作了如下的修正:∙对于 inb_p/outb_p 和端口地址 0x80 之间的关系做出了澄清.∙删除了关于 udelay() 函数的数据, 因为 nanosleep() 函数提供了比较明确的使用方法.∙将内容转换成 Linuxdoc-SGML 格式, 并且重新作了些许的编排.2. 如何在 C 语言下使用 I/O 端口2.1 正规的方法用来存取 I/O 端口的常式 (Routine) 都放在文件 /usr/include/asm/io.h 里(或放在核心源代码程序集的 linux/include/asm-i386/io.h 文件里). 这些常式是以单行宏 (inline macros) 的方式写成的, 所以使用时只要以 #include<asm/io.h> 的方式引用就够了; 不需要附加任何函数馆 (libraries).译注: 常式(Routine) 通常是指系统调用(System Call)与函数(Function)的总称.因为 gcc (至少出现在 2.7.2.3 和以前的版本) 以及 egcs (所有的版本) 的限制, 你在编译任何使用到这些常式的源代码时必须打开最佳化选项 (gcc -O1 或较高层次的), 或者是在做 #include <asm/io.h> 这个动作前使用 #define extern 将 extern 定义成空白.为了调试的目的, 你编译时可以使用 gcc -g -O (至少现在的 gcc 版本是这样), 但是最佳化之后有时可能会让调试器 (debugger) 的行为变的有点奇怪. 如果这个状况对你而言是个困扰, 你可以将所有使用到 I/O 端口的常式集中放在一个文件里并只在编译该文件时□打开最佳化选项.在你存取任何 I/O 端口之前, 你必须让你的程序有如此做的权限. 要达成这个目的你可以在你的程序一开始的地方 (但是要在任何 I/O 端口存取动作之前) 调用 ioperm() 这个函数 (该函数被宣言於文件 unistd.h , 并且被定义在核心中). 使用语法是 ioperm(from, num, turn_on), 其中 from 是第一个允许存取的 I/O 端口地址, num 是接著连续存取 I/O 端口地址的数目. 例如, ioperm(0x300, 5, 1) 的意思就是说允许存取端口 0x300 到 0x304 (一共五个端口地址). 而最后一个参数是一个布林代数值用来指定是否给予程序存取 I/O 端口的权限 (true (1)) 或是除去存取的权限 (false (0)). 你可以多次调用函数 ioperm() 以便使用多个不连续的端口地址. 至於语法的细节请参考ioperm(2) 的使用说明文件.你的程序必须拥有 root 的权限□能调用函数 ioperm() ; 所以你如果不是以root 的身份执行该程序, 就是得将该程序 setuid 成 root. 当你调用过函数ioperm() 打开 I/O 端口的存取权限後你便可以拿掉 root 的权限. 在你的程序结束之后并不特别要求你以 ioperm(..., 0) 这个方式拿掉 I/O 端口的存取权限; 因为当你的程序执行完毕之后这个动作会自动完成.调用函数 setuid() 将目前执行程序的有效使用者识别码 (ID) 设定成非 root 的使用者并不影响其先前以 ioperm() 的方式所取得的 I/O 端口存取权限, 但是调用函数 fork() 的方式却会有所影响 (虽然父行程 (parent process) 保有存取权限, 但是子行程 (child process) 却无法取得存取权限).函数 ioperm() 只能让你取得端口地址 0x000 到 0x3ff 的存取权限; 至於较高地址的端口, 你得使用函数 iopl() (该函数让你一次可以存取所有的端口地址). 将权限等级参数值设为 3 (例如, iopl(3)) 以便你的程序能够存取所有的 I/O 端口 (因此要小心 --- 如果存取到错误的端口地址将对你的计算机造成各种不可预期的损害. 同样地, 调用函数 iopl() 你得拥有 root 的权限.至於语法的细节请参考 iopl(2) 的使用说明文件.接著, 我们来实际地存取 I/O 端口... 要从某个端口地址输入一个 byte (8 个 bits) 的数据, 你得调用函数 inb(port) , 该函数会传回所取得的一个byte 的数据. 要输出一个 byte 的数据, 你得调用函数 outb(value, port) (请记住参数的次序). 要从某二个端口地址 x 和 x+1 (二个 byte 组成一个word, 故使用组合语言指令 inw) 输入一个 word (16 个 bits) 的数据, 你得调用函数 inw(x) ; 要输出一个 word 的数据到二个端口地址, 你得调用函数outw(value, x) . 如果你不确定使用那个端口指令 (byte 或 word), 你大概须要 inb() 与 outb() 这二个端口指令 --- 因为大多数的装置都是采用 byte 大小的端口存取方式来设计的. 注意所有的端口存取指令都至少需要大约一微秒的时间来执行.如果你使用的是 inb_p(), outb_p(), inw_p(), 以及 outw_p() 等宏指令, 在你对端口位作址存取动作之后只需很短的(大约一微秒)延迟时间就可以完成;你也可以让延迟时间变成大约四微秒方法是在使用 #include <asm/io.h> 之前使用 #define REALLY_SLOW_IO. 这些宏指令通常 (除非你使用的是 #define SLOW_IO_BY_JUMPING, 这个方法可能较不准确) 会利用输出数据到端口地址0x80 以便达到延迟时间的目的, 所以你得先以函数 ioperm() 取得端口地址0x80 的使用权限 (输出数据到端口地址 0x80 不应该会对系统的其它其它部分造成影响). 至於其它通用的延迟时间的方法, 请继续读下去.ioperm(2), iopl(2) 等函数, 和上面所述及的宏指令的使用说明会收录在最近出版的 Linux 使用说明文件包中.2.2 另一个替代的方法: /dev/port另一个存取 I/O 端口的方法是以函数 open() 开启文件 /dev/port (一个字符装置,主要装置编号为 1, 次要装置编号为 4) 以便执行读且/或写的动作 (注意标准输出入 (stdio) 函数 f*() 有内部的缓冲 (buffering), 所以要避免使用). 接著使用 lseek() 函数以便在该字符装置文件中找到某个 byte 数据的正确位置 (文件位置 0 = 端口地址 0x00, 文件位置 1 = 端口地址 0x01, 以此类推), 然后你可以使用 read() 或 write() 函数对某个端口地址做读或写一个 byte 或 word 数据的动作.这个替代的方法就是在你的程序里使用 read/write 函数来存取 /dev/port 字符装置文件. 这个方法的执行速度或许比前面所讲的一般方法还慢, 但是不需要编译器的最佳化功能也不需要使用函数 ioperm() . 如果你允许非 root 使用者或群组存取 /dev/port 字符设装置案, 操作时就不需拥有 root 权限 --但是对于系统安全而言是个非常糟糕的事情, 因为他可能伤害到你的系统, 或许会有人因而取的 root 的权限, 利用 /dev/port 字符装置文件直接存取硬盘, 网卡, 等设备.3. 硬件中断 (IRQs) 与 DMA 存取你的程序如果在使用者模式 (user-mode) 下执行不可以直接使用硬件中断(IRQs) 或 DMA. 你必需撰写一个核心驱动程序; 相关的细节请参考网页The Linux Kernel Hacker's Guide以及拿核心程序源代码来当范例.也就是说, 你在使用者模式 (user-mode) 中所写的程序无法抑制硬件中断的产生.4. 高精确的时序4.1 延迟时间首先, 我会说不保证你在使用者模式 (user-mode) 中执行的行程 (process)能够精确地控制时序因为 Linux 是个多工的操作环境. 你在执行中的行程(process) 随时会因为各种原因被暂停大约 10 毫秒到数秒 (在系统负荷非常高的时候). 然而, 对于大多数使用 I/O 端口的应用而言, 这个延迟时间实际上算不了什么. 要缩短延迟时间, 你得使用函数 nice 将你在执行中的行程(process ) 设定成高优先权(请参考 nice(2) 使用说明文件) 或使用实时排程法 (real-time scheduling) (请看下面).如果你想获得比在一般使用者模式 (user-mode) 中执行的行程 (process) 还要精确的时序, 有一些方法可以让你在使用者模式 (user-mode) 中做到 `实时' 排程的支持. Linux 2.x 版本的核心中有软件方式的实时排程支持; 详细的说明请参考 sched_setscheduler(2) 使用说明文件. 有一个特殊的核心支持植件的实时排程; 详细的信息请参考网页/~rtlinux/休息中(Sleeping) : sleep()与usleep()现在, 让我们开始较简单的时序函数调用. 想要延迟数秒的时间, 最佳的方法大概是使用函数 sleep() . 想要延迟至少数十毫秒的时间 (10 ms 似乎已是最短的延迟时间了), 函数 usleep() 应该可以使用. 这些函数是让出 CPU 的使用权给其它想要执行的行程 (processes) (``自己休息去了''), 所以没有浪费掉 CPU 的时间. 细节请参考 sleep(3) 与 usleep(3) 的说明文件.如果让出 CPU 的使用权因而使得时间延迟了大约 50 毫秒 (这取决於处理器与机器的速度, 以及系统的负荷), 就浪费掉 CPU 太多的时间, 因为 Linux 的排程器 (scheduler) (单就 x86 架构而言) 在将控制权发还给你的行程(process) 之前通常至少要花费 10-30 毫秒的时间. 因此, 短时间的延迟, 使用函数 usleep(3) 所得到的延迟结果通常会大於你在参数所指定的值, 大约至少有 10 ms.nanosleep()在 Linux 2.0.x 一系列的核心发行版本中, 有一个新的系统调用 (system call), nanosleep() (请参考 nanosleep(2) 的说明文件), 他让你能够休息或延迟一个短的时间 (数微秒或更多).如果延迟的时间 <= 2 ms, 若(且唯若)你执行中的行程 (process) 设定了软件的实时排程 (就是使用函数 tt/sched_setscheduler()/), 调用函数nanosleep() 时不是使用一个忙碌循环来延迟时间; 就是会像函数 usleep()一样让出 CPU 的使用权休息去了.这个忙碌循环使用函数 udelay() (一个驱动程序常会用到的核心内部的函数)来达成, 并且使用 BogoMips 值 (BogoMips 可以准确量测这类忙碌循环的速度)来计算循环延迟的时间长度. 其如何动作的细节请参考/usr/include/asm/delay.h).使用I/O 端口来延迟时间另一个延迟数微秒的方法是使用 I/O 端口. 就是从端口地址 0x80 输入或输出任何 byte 的数据 (请参考前面) 等待的时间应该几乎只要 1 微秒这要看你的处理器的型别与速度. 如果要延迟数微秒的时间你可以将这个动作多做几次.在任何标准的机器上输出数据到该端口地址应该不会有不良的後果□对 (而且有些核心的设备驱动程序也在使用他). {in|out}[bw]_p() 等函数就是使用这个方法来产生时间延迟的 (请参考文件 asm/io.h).实际上, 一个使用到端口地址范围为 0-0x3ff 的 I/O 端口指令几乎只要 1 微秒的时间, 所以如果你要如此做, 例如, 直接使用并口, 只要加上几个 inb() 函数从该端口地址范围读入 byte 的数据即可.使用组合语言来延迟时间如果你知道执行程序所在机器的处理器型别与时种速度, 你可以执行某些组合语言指令以便获得较短的延迟时间 (但是记住, 你在执行中的行程 (process) 随时会被暂停, 所以有时延迟的时间会比实际长). 如下面的表格所示, 内部处理器的速度决定了所要使用的时种周期数; 如, 一个 50 MHz 的处理器(486DX-50 或 486DX2-50), 一个时种周期要花费 1/50000000 秒 (=200 奈秒).指令 i386 时种周期数 i486 时种周期数nop 3 1xchg %ax,%ax 3 3or %ax,%ax 2 1mov %ax,%ax 2 1add %ax,0 2 1(对不起, 我不知道 Pentiums 的数据, 或许与 i486 接近吧. 我无法在 i386 的数据上找到只花费一个时种周期的指令. 如果能够就请使用花费一个时种周期的指令, 要不然就使用管线技术的新式处理器也是可以缩短时间的.)上面的表格中指令 nop 与 xchg 应该不会有不良的後果. 指令最后可能会改变旗号暂存器的内容, 但是这没关系因为 gcc 会处理. 指令 nop 是个好的选择.想要在你的程序中使用到这些指令, 你得使用 asm("instruction"). 指令的语法就如同上面表格的用法; 如果你想要在单一的 asm() 叙述中使用多个指令, 可以使用分号将他们隔开. 例如, asm("nop ; nop ; nop ; nop") 会执行四个nop 指令, 在 i486 或 Pentium 处理器中会延迟四个时种周期 (或是 i386 会延迟 12 个时种周期).gcc 会将 asm() 翻译成单行组合语言程序代码, 所以不会有调用函数的负荷.在 Intel x86 架构中不可能有比一个时种周期还短的时间延迟.在Pentiums 处理器上使用函数rdtsc对于 Pentiums 处理器而言, 你可以使用下面的 C 语言程序代码来取得自从上次重新开机到现在经过了多少个时种周期:extern __inline__ unsigned long long int rdtsc(){unsigned long long int x;__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));return x;}你可以询问参考此值以便延迟你想要的时种周期数.4.2 时间的量测想要时间精确到一秒种, 使用函数 time() 或许是最简单的方法. 想要时间更精确, 函数 gettimeofday() 大约可以精确到微秒 (但是如前所述会受到 CPU 排程的影响). 至於 Pentiums 处理器, 使用上面的程序代码片断就可以精确到一个时种周期.如果你要你执行中的行程 (process) 在一段时间到了之后能够被通知 (get a signal), 你得使用函数 setitimer() 或 alarm() . 细节请参考函数的使用说明文件.5使用其它程序语言上面的说明集中在 C 程序语言. 他应该可以直接应用在 C++ 及 Objective C 之上. 至於组合语言部分, 虽然你必须先在 C 语言中调用函数 ioperm() 或iopl() , 但是之后你就可以直接使用 I/O 端口读写指令.至於其它程序语言, 除非你可以在该程序语言中插入单行组合语言或 C 语言之程序代码或者使用上面所说的系统调用, 否则倒不如撰写一个内含有存取 I/O端口或延迟时间所必需函数之简单的 C 原始程序代码或许还比较容易, 编译之后再与你的程序链结. 要不然就是使用前面所说的 /dev/port 字符装置文件.6. 一些有用的 I/O 端口本节提供一些常用 I/O 端口的程序撰写信息这些都是可以直接拿来用的一般目的 TTL (或 CMOS) 逻辑位准的 I/O 端口.如果你要按照其原始的设计目的来使用这些或其它常用的I/O 端口 (例如, 控制一般的打印机或调制解调器), 你应该会使用现成的装置驱动程序 (他通常被含在核心中) 而不会如本文所说地去撰写 I/O 端口程序. 本节主要是提供给那些想要将 LCD 显示器, 步进马达, 或是其它商业电子产品连接到 PC 标准 I/O 端口的人.如果你想要控制大众市场所贩卖的装置像是扫描器 (已经在市场贩卖了一段期间), 去找看看是否有现成的 Linux 装置驱动程序. 网页Hardware-HOWTO是个好的参考起点.至於想要知道更多有关如何连接电子装置到计算机(以及一般的电子学原理)的相关信息则网页http://www.hut.fi/Misc/Electronics/是个好的数据来源.6.1 并口 (parallel port)并口的基本端口地址 (以下称之为 ``BASE'') 之於 /dev/lp0 是 0x3bc , 之於 /dev/lp1 是 0x378 , 之於 /dev/lp2 是 0x278 . 如果你只是想要控制一些像是一般打印机的动作, 可以参考网页Printing-HOWTO.除了下面即将描述的标准仅输出 (output-only) 模式, 大多数的并口都有 `扩充的' 双向 (bidirectional) 模式. 至於较新的 ECP/EPP 模式 (以及一般的IEEE 1284 标准) 端口口的相关数据, 可以参考网页/以及.au/~cpeacock/parallel.htm. 因为在使用者模式(user-mode) 中的程序无法使用 IRQs 或 DMA, 想要使用 ECP/EPP 模式你或许得撰写一个核心的装置驱动程序; 我想应该有人写了这类的装置驱动程序, 但是详情我并不知道.端口地址 BASE+0 (数据端口) 用来控制数据端口的信号位准 (D0 到 D7 分别代表著 bits 0 到 7, 位准状态: 0 = 低位准 (0 V), 1 = 高位准 (5 V)). 一个写入数据到该端口的动作会将数据信号位准拴住 (latches) 在端口的脚位(pins) 上. 一个将该端口的数据读出的动作会将上一次以标准仅输出(output-only) 模式或扩充的写入模式所拴住的数据信号位准读回, 或是以扩充读出模式从另外一个装置将脚位上的数据信号位准读回.端口地址 BASE+1 (状态端口) 是个仅读 (read-only) 的端口, 会将下面的输入信号位准读回:∙Bits 0 和 1 保留不用.∙Bit 2 IRQ 的状态 (不是个脚位 (pin) , 我不知道他的工作原理) ∙Bit 3 ERROR (1=高位准)∙Bit 4 SLCT (1=高位准)∙Bit 5 PE (1=高位准)∙Bit 6 ACK (1=高位准)∙Bit 7 -BUSY (0=高位准)(我不确定高低位准的电压状态.)端口地址 BASE+2 (控制端口) 是个仅写 (write-only) 的端口 (一个将该端口的数据读出的动作仅会将上一次写入的数据信号位准读回), 用来控制下面的状态信号:∙Bit 0 -STROBE (0=高位准)∙Bit 1 AUTO_FD_XT (1=高位准)∙Bit 2 -INIT (0=高位准)∙Bit 3 SLCT_IN (1=高位准)∙Bit 4 当被设定为 1 时允许并口产生 IRQ 信号 (发生在 ACK 脚位的位准由低变高的瞬间)∙Bit 5 用来控制扩充模式时端口的输出入方向 (0 = 写, 1 = 读), 这是个仅写 (write-only) 的端口 (一个将该端口的数据读出的动作对此bit 一点用处也没有).∙Bits 6 and 7 保留不用.(同样地, 我不确定高低位准的电压状态.)端口的脚位排列 (Pinout) 方式 (该端口是一个 25 只脚 D 字形外壳(D-shell) 的母头连接器) (i=输入, o=输出):1io -STROBE, 2io D0, 3io D1, 4io D2, 5io D3, 6io D4, 7io D5, 8io D6, 9io D7, 10i ACK, 11i -BUSY, 12i PE, 13i SLCT, 14o AUTO_FD_XT,15i ERROR, 16o -INIT, 17o SLCT_IN, 18-25 GroundIBM 的规格文件上说脚位 1, 14, 16, 和 17 (控制信号的输出) 采用电晶体的开集极 (open collector) 驱动方式必需使用 4.7 仟欧姆 (kiloohm) 的提升电阻接至 5 V 的电压 (可流入电流 20 mA, 流出电流 0.55 mA, 高位准的输出电压就是 5.0 V 减去提升电阻的电压). 剩下来的脚位可流入电流 24 mA, 流出电流 15 mA, 高位准的输出电压最小 2.4 V. 低位准的输出电压二者都是最大0.5 V. 那些非 IBM 规格的并口或许会偏离这个标准. 更多的相关数据请参考网页http://www.hut.fi/Misc/Electronics/circuits/lptpower.html.最后, 给你一个警告: 留心接地的问题. 我曾经在计算机还是开机的状况就去连接他因而弄坏好几个并口. 发生了这种事情你可能会觉得还是不要将并口整合到主机板里面比较好. (你通常可以拿一片便宜的标准 `multi-I/O' 卡安装第二个并口; 只要将其它不需要的端口停用, 然后将卡片上并口的端口地址设定在空著的地址即可. 你不需在意并口的 IRQ 设定, 因为通常不会被用到.) 6.2 游戏 (操纵□) 端口 (game port)游戏端口的端口地址范围为 0x200-0x207. 想要控制一般的操纵□, 有一个核心层次的操纵□驱动程序, 可参考网址ftp:///pub/Linux/kernel/patches/, 文件名 joystick-*.端口的脚位排列 (Pinout) 方式 (该端口是一个 15 只脚 D 字形外壳(D-shell) 的母头连接器):∙1,8,9,15: +5 V (电源)∙4,5,12: 接地∙2,7,10,14: 分别是 BA1, BA2, BB1, 和 BB2 等数字输入∙3,6,11,13: 分别是 AX, AY, BX, 和 BY 等``模拟''输入+5 V 的脚位似乎通常会被直接连接到主机板的电源在线, 所以他应该能够提供相当的电力, 这还要看所使用主机板, 电源供给器, 以及游戏端口的类型.数字输入用于操纵□的按钮可以让你连接二个操纵□的四个按钮 (操纵□ A 和操纵□ B, 各有二个按钮) 到游戏端口也就是数字输入的四个脚位. 他们应该是一般 TTL 电压位准的输入, 你可以直接从状态端口 (参考下面说明) 读出他们的位准状态. 一个实际的操纵□在按钮被压下时会传回低位准 (0 V) 状态否则就是高位准 (5V 经由 1 Kohm 的电阻连接到电源脚位) 状态.所谓的模拟输入实际是量测到的阻抗值. 游戏端口有四个单击多谐振□器(one-shot multivibrator) (一个 558 芯片) 连接到四个模拟输入脚位. 每个模拟输入脚位与多谐振□器的输出之间连接著一个 2.2 Kohm 的电阻, 而且多谐振□器的输出与地之间连接著一个 0.01 uF 的时序电容 (timing capacitor). 一个实际的操纵□其每个座标 (X 和 Y) 上会有一个可变电阻, 连接在 +5 V与每个相对的模拟输入脚位之间 (脚位 AX 或 AY 是给操纵□ A 用的, 而脚位BX 或 BY 是给操纵□ B用的).操作的时候, 多谐振□器将其输出设定为高位准 (5 V) 并且等到时序电容上的电压达到 3.3 V 之后将相对的输出设定为低位准. 因此操纵□中多谐振□器输出的高位准时间周期与可变电阻的电阻值成正比 (也就是, 操纵□在相对座标的位置), 如下所示:R = (t - 24.2) / 0.011,其中 R 是可变电阻的阻抗值 (ohms) 而 t 是高位准时间周期的长度 (秒).因此要读出模拟输入脚位的数值, 首先你得启动多谐振□器 (以端口写入的方式; 请看下面), 然后查询四个座标的信号状态(以持续的端口读出方式)一直到信号状态由高位准变成低位准, 计算其高位准时间周期的长度. 这个持续查询的动作花费相当多的 CPU 时间, 而且在一个非实时的多工环境像是 (一般的使用者模式 (user-mode) ) Linux, 所得的结果不是非常准确因为你无法以固定的时间来查询信号的状态 (除非你使用核心层次的驱动程序而且你得在你查询的时候抑制掉中断的产生, 但是这样做会浪费更多的 CPU 时间). 如果你知道信号的状态将会花费一段不短的时间 (数十毫秒) □会成为低位准, 你可以在查询之前调用函数 usleep() 将 CPU 的时间让给其它想要执行的行程(processes).游戏端口中唯一需要你来存取的端口地址是 0x201 (其它的端口地址不是动作一样就是没用). 任何对这个端口地址所做的写入动作 (不论你写入什么) 都会启动多谐振□器. 对这个端口地址做读出动作会取回输入信号的状态:∙Bit 0: AX ( (1=高位准) 多谐振□器的输出状态)∙Bit 1: AY ( (1=高位准) 多谐振□器的输出状态)∙Bit 2: BX ( (1=高位准) 多谐振□器的输出状态)∙Bit 3: BY ( (1=高位准) 多谐振□器的输出状态)∙Bit 4: BA1 (数字输入, 1=高位准)∙Bit 5: BA2 (数字输入, 1=高位准)∙Bit 6: BB1 (数字输入, 1=高位准)∙Bit 7: BB2 (数字输入, 1=高位准)6.3 串口 (serial port)如果你所说的装置是支持一些像是 RS-232 那类的东西, 你应该可以如你所愿地使用串口. Linux 所提供的串口驱动程序应该能够应用在任何地方 (你应该不需要直接撰写串口程序, 或是核心的驱动程序); 他相当具有通用性, 所以像是使用非标准的 bps 速率以及其它等等应该不是问题. 请参考 termios(3) 说明文件, 串口驱动程序原始程序代码 (linux/drivers/char/serial.c), 以及网页/~mike/serial/index.html上有更多在 Unix 操作系统撰写串口程序的相关数据.7. 提示如果你想要有好的 I/O 品值, 你可以在并口上自行组装 ADC 且/或 DAC 芯片(提示: 电源部分, 可使用游戏端口上的或将未用到的磁盘电源连接头接至机壳之外, 如果你的装置功率消耗低则可以拿并口来充当电源, 不然就是使用外部的电源供给), 或是买 AD/DA 卡片 (大部分较旧型/较低速的产品可由 I/O 端口控制). 或者是 Linux 音效卡驱动程序所支持的便宜音效卡 (速度还相当的快) 上 1 或 2 个不精确, (可能会) 无法归零的信号信道对你而言就够了.使用精确的模拟装置, 不当的接地可能造成模拟输出入信号的误差. 如果你有界面的经验, 你可能会尝试以光耦合器来隔绝 (计算机与你的装置之间所有的信号) 电子乾扰. 试著从计算机上取得光耦合器的电源 (在端口上未用到的信号脚位可以提供足够的电源) 以求达到最佳的隔绝效果.如果你现在正在寻找能在 Linux 上使用的印刷电路板设计软件, 有一个称为Pcb 没镅的 X11 应用程序应该能够胜任, 只要你不要做一些太复杂的事. 许多的 Linux 发行版本 (distributions) 都内含这个程序, 同时他也被放在网址ftp:///pub/Linux/apps/circuits/上(文件名为 pcb-*).8. 问题排除Q1.当我存取 I/O 端口时结果碰到 segmentation faults 这个问题A1.不是你的程序没有 root 权限, 就是因为某些理由导致函数 ioperm()调用失败. 检查函数 ioperm() 的传回值. 同时, 检查你所存取的端口也就是你以函数 ioperm() 所启用的端口地址 (参考 Q3). 如果你使用的是延迟时间的宏指令 (inb_p(), outb_p(), 等等), 记得也要调用函数 ioperm() 以便存取端口地址 0x80.Q2.我无法找到 in*(), out*() 等函数被定义在何处, 同时 gcc 也抱怨参考到未定义的符号 (undefined references).A2.你在编译程序时没有打开最佳化选项 (-O), 因此 gcc 不能解析asm/io.h 中的宏指令. 或是你根本就没有使用 #include <asm/io.h>. Q3.out*() 没有动作, 或是动作怪怪的.A3.检查参数所放置的次序; 他应该是这样 outb(value, port) , 而不是MS-DOS 上常用的那样 outportb(port, value)Q4.。
Iozone Filesystem BenchmarkIOzone is a filesystem benchmark tool. The benchmark generates and measures a variety of file operations. Iozone has been ported to many machines and runs under many operating systems. This document will cover the many different types of operations that are tested as well as coverage of all of the command line options.Iozone is useful for determining a broad filesystem analysis of a vendor’s computer platform. The benchmark tests file I/O performance for the following operations.Read, write, re-read, re-write, read backwards, read strided, fread, fwrite, random read/write,pread/pwrite variants, aio_read, aio_write, mmap,While computers are typically purchased with an application in mind it is also likely that over time the application mix will change. Many vendors have enhanced their operating systems to perform well for some frequently used applications. Although this accelerates the I/O for those few applications it is also likely that the system may not perform well for other applications that were not targeted by the operating system. An example of this type of enhancement is: Database. Many operating systems have tested and tuned the filesystem so it works well with databases. While the database users are happy, the other users may not be so happy as the entire system may be giving all of the system resources to the database users at the expense of all other users. As time rolls on the system administrator may decide that a few more office automation tasks could be shifted to this machine. The load may now shift from a random reader application (database) to a sequential reader. The users may discover that the machine is very slow when running this new application and become dissatisfied with the decision to purchase this platform. By using Iozone to get a broad filesystem performance coverage the buyer is much more likely to see any hot or cold spots and pick a platform and operating system that is more well balanced.Features:∙ANSII ‘C’ source.∙POSIX async I/O.∙Mmap() file I/O.∙Normal file I/O.∙Single stream measurement.∙Multiple stream measurement.∙POSIX pthreads.∙Multi-process measurement.∙Excel importable output for graph generation.∙I/O Latency data for plots.∙64-bit compatible source.∙Large file compatible.∙Stonewalling in throughput tests to eliminate straggler effects.∙Processor cache size configurable.∙Selectable measurements with fsync, O_SYNC.∙Options targeted for testing over NFS.Building IOzoneOnce you have obtained the source for IOzone you should have 12 files.∙iozone.c (source code)∙libasync.c (source code)∙makefile (makefile)∙libbif.c (source code)∙Iozone_msword_98.doc (documentation in Word format)∙iozone.1 (documentation in nroff format)∙gnuplot.dem (sample gnuplot file )∙gnuplotps.dem (sample gnuplot file that generates postscript output)∙read_telemetry (sample file for read telemetry file)∙write_telemetry (sample file for write telemetry file)∙Run_rules.doc (run rules to get reasonable results)∙Changes.txt (log of changes to Iozone since its beginning)Type: makeThe makefile will display a list of supported platforms. Pick the one that matches yourconfiguration and then type: make targetThat’s it. You’re done. There is no need to have any install procedures as IOzone creates all o f its files in the current working directory. Just copy Iozone to wherever you wish to test the filesystem performance and then run it. Or you can use the –f command line option to specify a target path, for example, a path/filename in a new filesystem.Before you run Iozone please read the run rules at the bottom of this document. Examples of running Iozone:The simplest way to get started is to try the automatic mode.Iozone –aIf you wish to generate graphs then you may wish to turn on Excel mode.Iozone –Ra ( Output can be imported using space and tab delimited)OrIozone –Rab output.wks ( Output file “output.wks” is a binary format spreadsheet) If you have more than 512 Mbytes of memory then you need to increase the maximum file size to a larger value. For example if your system has 1 Gbyte of memory then you would want to try something like:Iozone –Ra –g 2GIf you only care about read/write and do not wish to spend the time to perform all of the tests, then you may wish to limit the testing like:Iozone –Ra –g 2G –i 0 –i 1If you are running Iozone over NFS on an NFS client then you may wish to use:Iozone –RacThis tells Iozone to include the close() in the measurement. This may be needed if the client is running NFS version 3. Including the close() helps to reduce the client side cache effects of NFS version 3. If you use a file size that is larger than the amount of memory in the client then the ‘c’ flag is not needed. Definitions of the testsWrite: This test measures the performance of writing a new file. When a new file is written not only does the data need to be stored but also the overhead information for keeping track of where the data is located on the storage media. This overhead is called the “metadata” It consists of the directory information, the space allocation and any other data associated with a file that is not part of the data contained in the file. It is normal for the initial write performance to be lower than the performance of re-writing a file due to this overhead information.Re-write: This test measures the performance of writing a file that already exists. When a file is written that already exists the work required is less as the metadata already exists. It is normal for the rewrite performance to be higher than the performance of writing a new file.Read: This test measures the performance of reading an existing file.Re-Read: This test measures the performance of reading a file that was recently read. It is normal for the performance to be higher as the operating system generally maintains a cache of the data for files that were recently read. This cache can be used to satisfy reads and improves the performance.Random Read: This test measures the performance of reading a file with accesses being made to random locations within the file. The performance of a system under this type of activity can be impacted by several factors such as: Size of operating system’s cache, number of disks, seek latencies, and others.Random Write: This test measures the performance of writing a file with accesses being made to random locations within the file. Again the performance of a system under this type of activity can be impacted by several factors such as: Size of operating system’s cache, number of disks, seek latencies, and others.Random Mix: This test measures the performance of reading and writing a file with accesses being made to random locations within the file. Again the performance of a system under this type of activity can be impacted by several factors such as: Size of operating system’s cache, number of disks, seek latencies, and others. This test is only available in throughput mode. Each thread/process runs either the read or the write test. The distribution of read/write is done on a round robin basis. More than onethread/process is required for proper operation.Backwards Read: This test measures the performance of reading a file backwards. This may seem like a strange way to read a file but in fact there are applications that do this. MSC Nastran is anexample of an application that reads its files backwards. With MSC Nastran, these files are very large (Gbytes to Tbytes in size). Although many operating systems have special features that enable them to read a file forward more rapidly, there are very few operating systems that detect and enhance the performance of reading a file backwards.Record Rewrite: This test measures the performance of writing and re-writing a particular spot within a file. This hot spot can have very interesting behaviors. If the size of the spot is small enough to fit in the CPU data cache then the performance is very high. If the size of the spot is bigger than the CPU data cache but still fits in the TLB then one gets a different level of performance. If the size of the spot is larger than the CPU data cache and larger than the TLB but still fits in the operating system cache then one gets another level of performance, and if the size of the spot is bigger than the operating system cache then one gets yet another level of performance.Strided Read: This test measures the performance of reading a file with a strided access behavior. An example would be: Read at offset zero for a length of 4 Kbytes, then seek 200 Kbytes, and then read for a length of 4 Kbytes, then seek 200 Kbytes and so on. Here the pattern is to read 4 Kbytes and then Seek 200 Kbytes and repeat the pattern. This again is a typical application behavior for applications that have data structures contained within a file and is accessing a particular region of the data structure.Most operating systems do not detect this behavior or implement any techniques to enhance the performance under this type of access behavior.This access behavior can also sometimes produce interesting performance anomalies. An example would be if the application’s stride causes a particular disk, in a striped file system, to become the bottleneck.Fwrite: This test measures the performance of writing a file using the library function fwrite(). This is a library routine that performs buffered write operations. The buffer is within the user’s address space. If an application were to write in very small size transfers then the buffered & blocked I/O functionality of fwrite() can enhance the performance of the application by reducing the number of actual operating system calls and increasing the size of the transfers when operating system calls are made.This test is writing a new file so again the overhead of the metadata is included in the measurement.Frewrite: This test measures the performance of writing a file using the library function fwrite(). This is a library routine that performs buffered & blocked write operations. The buffer is within the user’s address space. If an application were to write in very small size transfers then the buffered & blocked I/O functionality of fwrite() can enhance the performance of the application by reducing the number of actual operating system calls and increasing the size of the transfers when operating system calls are made.This test is writing to an existing file so the performance should be higher as there are no metadata operations required.Fread: This test measures the performance of reading a file using the library function fread(). This is a lib rary routine that performs buffered & blocked read operations. The buffer is within the user’s address space. If an application were to read in very small size transfers then the buffered & blocked I/O functionality of fread() can enhance the performance of the application by reducing the number of actual operating system calls and increasing the size of the transfers when operating system calls are made.Freread: This test is the same as fread above except that in this test the file that is being read was read in the recent past. This should result in higher performance as the operating system is likely to have the file data in cache.Specialized tests:Mmap: Many operating systems support the use of mmap() to map a file into a user’s address space. Once this mapping is in place then stores to this location in memory will result in the data being stored going to a file. This is handy if an application wishes to treat files as chunks of memory. An example would be to have an array in memory that is also being maintained as a file in the files system.The semantics of mmap files is somewhat different than normal files. If a store to the memory location is done then no actual file I/O may occur immediately. The use of the msyc() with the flags MS_SYNC, and MS_ASYNC control the coherency of the memory and the file. A call to msync() with MS_SYNC will force the contents of memory to the file and wait for it to be on storage before returning to the application.A call to msync() with the flag MS_ASYNC tells the operating system to flush the memory out to storage using an asynchronous mechanism so that the application may return into execution without waiting for the data to be written to storage.This test measures the performance of using the mmap() mechanism for performing I/O.Async I/O: Another mechanism that is supported by many operating systems for performing I/O is POSIX async I/O. The application uses the POSIX standard async I/O interfaces to accomplish this.Example: aio_write(), aio_read(), aio_error(). This test measures the performance of the POSIX async I/O mechanism.Command Line options:The following is the output from the built in help. Each option’s purpose is explained in this section of the manual.Usage: iozone [-s filesize_Kb] [-r record_size_Kb ] [-f [path]filename][-i test] [-E] [-p] [-a] [-A] [-z] [-Z] [-m] [-M] [-t children] [-h] [-o][-l min_number_procs] [-u max_number_procs] [-v] [-R] [-x][-d microseconds] [-F path1 path2...] [-V pattern] [-j stride][-T] [-C] [-B] [-D] [-G] [-I] [-H depth] [-k depth] [-U mount_point][-S cache_size] [-O] [-K] [-L line_size] [-g max_filesize_Kb][-n min_filesize_Kb] [-N] [-Q] [-P start_cpu] [-c] [-e] [-b filename][-J milliseconds] [-X filename] [-Y filename] [-w] [-W][-y min_recordsize_Kb] [-q max_recordsize_Kb] [-+m filename][-+u ] [ -+d ] [-+p percent_read] [-+r] [-+t ] [-+A #]What do they all mean ?-aUsed to select full automatic mode. Produces output that covers all tested file operationsfor record sizes of 4k to 16M for file sizes of 64k to 512M.-AThis version of automatic mode provides more coverage but consumes a bunch of time.The –a option will automatically stop using transfer sizes less than 64k once the filesize is 32 MB or larger. This saves time. The –A option tells Iozone that you are willing towait and want dense coverage for small transfers even when the file size is very large.NOTE: This option is deprecated in Iozone version 3.61. Use –az –i 0 –i 1 instead.-b filenameIozone will create a binary file format file in Excel compatible output of results.-BUse mmap() files. This causes all of the temporary files being measured to be createdand accessed with the mmap() interface. Some applications prefer to treat files as arraysof memory. These applications mmap() the file and then just access the array with loadsand stores to perform file I/O.-cInclude close() in the timing calculations. This is useful only if you suspect that close() isbroken in the operating system currently under test. It can be useful for NFS Version 3testing as well to help identify if the nfs3_commit is working well.-CShow bytes transferred by each child in throughput testing. Useful if your operatingsystem has any starvation problems in file I/O or in process management.-d #Microsecond delay out of barrier. During the throughput tests all threads or processes areforced to a barrier before beginning the test. Normally, all of the threads or processes arereleased at the same moment. This option allows one to delay a specified time inmicroseconds between releasing each of the processes or threads.-DUse msync(MS_ASYNC) on mmap files. This tells the operating system that all the data inthe mmap space needs to be written to disk asynchronously.-eInclude flush (fsync,fflush) in the timing calculations-EUsed to select the extension tests. Only available on some platforms. Uses pread interfaces.-f filenameUsed to specify the filename for the temporary file under test. This is useful whenthe unmount option is used. When testing with unmount between tests it is necessary forthe temporary file under test to be in a directory that can be unmounted. It is not possibleto unmount the current working directory as the process Iozone is running in this directory.-F filena me filename filename …Specify each of the temporary file names to be used in the throughput testing. The number of names should be equal to the number of processes or threads that are specified.-g #Set maximum file size (in Kbytes) for auto mode.-GUse msync(MS_SYNC) on mmap files. This tells the operating system that all the data in the mmap space needs to be written to disk synchronously.-hDisplays help screen.-H#Use POSIX async I/O with # async operations. Iozone will use POSIX async I/O with abcopy from the async buffers back into the applications buffer. Some versions of MSCNASTRAN perform I/O this way. This technique is used by applications so that the async I/O may be performed in a library and requires no changes to the applications internal model.-i #Used to specify which tests to run. (0=write/rewrite, 1=read/re-read, 2=random-read/write 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite, 7=fread/Re-fread, 8=random mix, 9=pwrite/Re-pwrite, 10=pread/Re-pread, 11=pwritev/Re-pwritev, 12=preadv/Re-preadv).One will always need to specify 0 so that any of the following tests will have a file to measure.-i # -i # -i # is also supported so that one may select more than one test.-IUse VxFS VX_DIRECT for all file operations. Tells the VXFS filesystem that all operations to the file are to bypass the buffer cache and go directly to disk.-j #Set stride of file accesses to (# * record size). The stride read test will read records at this stride. -J # (in milliseconds)Perform a compute delay of this many milliseconds before each I/O operation. See also-X and -Y for other options to control compute delay.-k#Use POSIX async I/O (no bcopy) with # async operations. Iozone will use POSIX asyncI/O and will not perform any extra bcopys. The buffers used by Iozone will be handed tothe async I/O system call directly.-KGenerate some random accesses during the normal testing.-l#Set the lower limit on number of processes to run. When running throughput tests thisoption allows the user to specify the least number of processes or threads to start. Thisoption should be used in conjunction with the -u option.-L #Set processor cache line size to value (in bytes). Tells Iozone the processor cache line size.This is used internally to help speed up the test.-mTells Iozone to use multiple buffers internally. Some applications read into a singlebuffer over and over. Others have an array of buffers. This option allows both types of applications to be simulated. Iozone’s default behavior is to re-use internal buffers.This option allows one to override the default and to use multiple internal buffers.-MIozone will call uname() and will put the string in the output file.-n #Set minimum file size (in Kbytes) for auto mode.-NReport results in microseconds per operation.-oWrites are synchronously written to disk. (O_SYNC). Iozone will open the files with theO_SYNC flag. This forces all writes to the file to go completely to disk before returning to the benchmark.-OGive results in operations per second.-pThis purges the processor cache before each file operation. Iozone will allocate anotherinternal buffer that is aligned to the same processor cache boundary and is of a size thatmatches the processor cache. It will zero fill this alternate buffer before beginning each test.This will purge the processor cache and allow one to see the memory subsystem without the acceleration due to the processor cache.-P#Bind processes/threads to processors, starting with this cpu #. Only available on someplatforms. The first sub process or thread will begin on the specified processor. Future processes or threads will be placed on the next processor. Once the total number of cpus is exceeded then future processes or threads will be placed in a round robin fashion.-q #Set maximum record size (in Kbytes) for auto mode. One may also specify-q #k (size in Kbytes) or -q #m (size in Mbytes) or -q #g (size in Gbytes).See –y for setting minimum record size.-QCreate offset/latency files. Iozone will create latency versus offset data files that can beimported with a graphics package and plotted. This is useful for finding if certain offsets have very high latencies. Such as the point where UFS will allocate its first indirect block.One can see from the data the impacts of the extent allocations for extent based filesystems with this option.-r#Used to specify the record size, in Kbytes, to test. One may also specify-r #k (size in Kbytes) or -r #m (size in Mbytes) or -r #g (size in Gbytes).-RGenerate Excel report. Iozone will generate an Excel compatible report to standard out. This file may be imported with Microsoft Excel (space delimited) and used to create a graph of the filesystem performance. Note: The 3D graphs are column oriented. You will need toselect this when graphing as the default in Excel is row oriented data.-s#Used to specify the size, in Kbytes, of the file to test. One may also specify-s #k (size in Kbytes) or -s #m (size in Mbytes) or -s #g (size in Gbytes).-S#Set processor cache size to value (in Kbytes). This tells Iozone the size of the processor cache.It is used internally for buffer alignment and for the purge functionality.-t #Run Iozone in a throughput mode. This option allows the user to specify howmany threads or processes to have active during the measurement.-TUse POSIX pthreads for throughput tests. Available on platforms that have POSIX threads.-u#Set the upper limit on number of processes to run. When running throughput tests thisoption allows the user to specify the greatest number of processes or threads to start.This option should be used in conjunction with the -l option.-U mountpointMount point to unmount and remount between tests. Iozone will unmount and remountthis mount point before beginning each test. This guarantees that the buffer cache does not contain any of the file under test.-vDisplay the version of Iozone.-V#Specify a pattern that is to be written to the temporary file and validated for accuracy ineach of the read tests.-wDo not unlink temporary files when finished using them. Leave them present in the filesystem. -WLock files when reading or writing.-xTurn off stone-walling. Stonewalling is a technique used internally to Iozone. It is used during the throughput tests. The code starts all threads or processes and then stops them on a barrier.Once they are all ready to start then they are all released at the same time. The moment that any of the threads or processes finish their work then the entire test is terminated andthroughput is calculated on the total I/O that was completed up to this point. This ensuresthat the entire measurement was taken while all of the processes or threads were runningin parallel. This flag allows one to turn off the stonewalling and see what happens.-X filenameUse this file for write telemetry information. The file contains triplets of information:Byte offset, size of transfer, compute delay in milliseconds. This option is useful if one has taken a system call trace of the application that is of interest. This allows Iozone to replicate the I/O operations that this specific application generates and provide benchmark results for this file behavior. (if column 1 contains # then the line is a comment)-y #Set minimum record size (in Kbytes) for auto mode. One may also specify-y #k (size in Kbytes) or -y #m (size in Mbytes) or -y #g (size in Gbytes).See –q for setting maximum record size.-Y filenameUse this file for read telemetry information. The file contains triplets of information:Byte offset, size of transfer, compute delay in milliseconds. This option is useful if one has taken a system call trace of the application that is of interest. This allows Iozone to replicate the I/O operations that this specific application generates and provide benchmark results for this file behavior. (if column 1 contains # then the line is a comment)-zUsed in conjunction with -a to test all possible record sizes. Normally Iozone omits testing of small record sizes for very large files when used in full automatic mode. This option forces Iozone to include the small record sizes in the automatic tests also.-ZEnable mixing mmap I/O and file I/O.-+m filenameUse this file to obtain the configuration information of the clients for cluster testing. The file contains one line for each client. Each line has three fields. The fields are space delimited. A # sign in column zero is a comment line. The first field is the name of the client. The second field is the path, on the client, for the working directory where Iozone will execute. The third field is the path, on the client, for the executable Iozone.To use this option one must be able to execute commands on the clients without being challenged for a password. Iozone will start remote execution by using “rsh”.-+uEnable CPU utilization mode.-+dEnable diagnostic mode. In this mode every byte is validated. This is handy if one suspects a broken I/O subsystem.-+p percent_readSet the percentage of the thread/processes that will perform random read testing. Only valid in throughput mode and with more than 1 process/thread.-+rEnable O_RSYNC and O_SYNC for all I/O testing.-+tEnable network performance test. Requires -+m-+AEnable madvise. 0 = normal, 1=random, 2=sequential, 3=dontneed, 4=willneed.For use with options that activate mmap() file I/O. See: -BWhat can I see: The following are some graphs that were generated from the Iozone output files.From the graph above one can clearly see the buffer cache helping out for file sizes that are less than 256MB but after that the actual disk I/O speed can be seen. Also note that the processor cache effects can be seen for file sizes of 16 Kbytes to 1Mbyte. CPU cache effectBuffer cache effectCPU cache effectBuffer cache effectNot measuredI/O performance aftercaches are exceededThe graph above is displaying the impact of re-reading a file. Notice that the processor cache is now very important and causes the sharp peak. The next plateau to the right is buffer cache and finally above 256MB the file no longer fits in the buffer cache and real spindle speeds can be seen.The graph above was created by running Iozone multiple times and then graphing the combination of the results. Here the graph is showing the throughput performance as a function of processes and number of disks participating in a filesystem. (disk striping) The good news is that on this system as one adds disks the throughput increases. Not all platforms scale so well.CPU cache effectBuffer cache effectNot measuredThe graph above shows single stream performance where file size and request size are changed. The place on the lower right that touches the floor of the graph is not actual data. Excel graphs empty cells as containing a zero. This run was taken with the –a option. If one used the –A option then the area that was not tested would have been tested and had real values. Normally this is not a desirable area to test because it is very time consuming to write a 512MB file in 4k transfer sizes. The –a option in Iozone tells Iozone to discontinue use of transfer sizes less than 64k once the file size is 32MB or bigger. This saves quite a bit of time. Notice the ridge that runs from the top left to the lower right down the center of the graph. This is where the request size fits in the processor cache. For file sizes less than the size of the processor cache you can see the rise in performance as well. When both the file size and the transfer size is less than the processor cache it rises even higher. Although interesting to see, it is unlikely that you will be able to get applications to never write files that are bigger than the processor cache However it might be possible to get applications to try to re-use buffers and keep the buffer size smaller than the processor cache size.。
iozone常用测试方法【原创实用版3篇】目录(篇1)1.iozone 简介2.iozone 的常用测试方法3.测试方法的优缺点4.结论正文(篇1)1.iozone 简介iozone 是一个用于测试文件系统性能的工具,它可以测试文件系统的吞吐量和性能。
iozone 可以在本地文件系统、网络文件系统(NFS)以及分布式文件系统(如 HDFS)上运行。
它提供了一系列测试脚本,这些脚本可以测试不同类型的文件操作,如创建、删除、读取和写入文件等。
2.iozone 的常用测试方法iozone 提供了多种测试方法,以下是其中几种常用的测试方法:- 测试文件创建和删除:该测试方法用于测试文件系统的创建和删除文件性能。
- 测试文件读取:该测试方法用于测试文件系统的读取文件性能。
- 测试文件写入:该测试方法用于测试文件系统的写入文件性能。
- 测试目录操作:该测试方法用于测试文件系统的目录操作性能,如创建、删除和读取目录等。
3.测试方法的优缺点iozone 的测试方法具有以下优点:- 可以测试不同类型的文件操作,如创建、删除、读取和写入文件等。
- 可以在多种文件系统上运行,包括本地文件系统、网络文件系统(NFS)以及分布式文件系统(如 HDFS)。
然而,iozone 的测试方法也存在一些缺点:- 测试结果可能受到系统硬件和软件配置的影响,因此可能不具有通用性。
- 测试过程可能需要较长时间,尤其是在测试大型文件系统时。
4.结论iozone 是一个功能强大的文件系统性能测试工具,它可以测试文件系统的吞吐量和性能。
通过使用 iozone 的测试方法,用户可以评估文件系统的性能,并找出可能存在的性能瓶颈。
目录(篇2)1.iozone 简介2.iozone 的常用测试方法3.iozone 测试方法的优势和局限性正文(篇2)1.iozone 简介iozone 是一个用于测试文件系统性能的工具,它可以测试文件系统的读写速度、吞吐量和稳定性。
[转载]IOZONE和FIO的安装测试说明原⽂地址:IOZONE和FIO的安装测试说明作者:____MoIOZONE说明iozone是⼀个⽂件系统的benchmark⼯具,可以测试不同的操作系统中⽂件系统的读写性能。
可以测试 Read, write, re-read,re-write, read backwards, read strided, fread, fwrite, random read, pread, mmap, aio_read, aio_write 等等不同的模式下的硬盘的性能。
测试的时候请注意,设置的测试⽂件的⼤⼩⼀定要⼤过你的内存(最佳为内存的两倍⼤⼩),不然linux会给你的读写的内容进⾏缓存。
会使数值⾮常不真实。
IOZONE安装包iozone3_430.tarIOZONE安装步骤[root@linux156 bin]# tar -xvf iozone3_430.tar[root@linux156 bin]# cd /usr/linkapp/bin/iozone3_430/src/current/[root@linux156 current]# make linux查找:[root@linux156 iozone3_430]# find /-name iozoneIOZONE测试命令[root@linux156 current]# ./iozone -zx -b iozone-test.xls -g 8g -y 64k -i 0 -i 1说明:-az——执⾏不同粒度(record size)和测试⽂(file size)的⾃动化测试,默认情况下record size从4K—16M,filesize从64K—512M。
-b——指定测试后⽣成的excel⽂件。
-g——指定最⼤的file size⼤⼩。
(⼀般为内存的两倍)-y——指定最⼩的record size数值。
-i——指定测试的种类。
I/O 端口和I/O 内存每种外设都是通过读写寄存器来进行控制。
在硬件层,内存区和I/O 区域没有概念上的区别: 它们都是通过向在地址总线和控制总线发出电平信号来进行访问,再通过数据总线读写数据。
因为外设要与I\O总线匹配,而大部分流行的I/O 总线是基于个人计算机模型(主要是x86 家族:它为读和写I/O 端口提供了独立的线路和特殊的CPU 指令),所以即便那些没有单独I/O 端口地址空间的处理器,在访问外设时也要模拟成读写I\O端口。
这一功能通常由外围芯片组(PC 中的南北桥)或CPU 中的附加电路实现(嵌入式中的方法)。
Linux 在所有的计算机平台上实现了I/O 端口。
但不是所有的设备都将寄存器映射到I/O 端口。
虽然ISA设备普遍使用I/O 端口,但大部分PCI 设备则把寄存器映射到某个内存地址区,这种I/O内存方法通常是首选的。
因为它无需使用特殊的处理器指令,CPU核访问内存更有效率,且编译器在访问内存时在寄存器分配和寻址模式的选择上有更多自由。
I/O 寄存器和常规内存在进入这部分学习的时候,首先要理解一个概念:sideeffect,书中译为边际效应,第二版译为副作用。
我觉得不管它是怎么被翻译的,都不可能精准表达原作者的意思,所以我个人认为记住sideeffect就好。
下面来讲讲side effect的含义。
我先贴出两个网上已有的两种说法(在这里谢谢两位高人的分享):第一种说法:3. side effect(译为边际效应或副作用):是指读取某个地址时可能导致该地址内容发生变化,比如,有些设备的中断状态寄存器只要一读取,便自动清零。
I/O寄存器的操作具有side effect,因此,不能对其操作不能使用cpu缓存。
原文网址:/62733495.html第二种说法:说一下我的理解:I/O端口与实际外部设备相关联,通过访问I/O端口控制外部设备,“边际效应”是指控制设备(读取或写入)生效,访问I/O口的主要目的就是边际效应,不像访问普通的内存,只是在一个位置存储或读取一个数值,没有别的含义了。
Linux IO系统简介和调度器的工作流程详细概述Linux I/O 系统简介Linux I/O调度器(Linux I/O Scheduler)是LinuxI/O体系的一个组件,它介于通用块层和块设备驱动程序之间。
如图1 所示。
图1 Linux I/O调度器介于通用块层和块设备驱动程序之间当Linux内核组件要读写一些数据时,并不是请求一发出,内核便立即执行该请求,而是将其推迟执行。
当传输一个新数据块时,内核需要检查它能否通过。
Linux IO调度程序是介于通用块层和块设备驱动程序之间,所以它接收来自通用块层的请求,试图合并请求,并找到最合适的请求下发到块设备驱动程序中。
之后块设备驱动程序会调用一个函数来响应这个请求。
Linux整体I/O体系可以分为七层,它们分别是:1. VFS虚拟文件系统:内核要跟多种文件系统打交道,内核抽象了这VFS,专门用来适配各种文件系统,并对外提供统一操作接口。
2. 磁盘缓存:磁盘缓存是一种将磁盘上的一些数据保留着RAM中的软件机制,这使得对这部分数据的访问可以得到更快的响应。
磁盘缓存在Linux中有三种类型:Dentry cache ,Page cache ,Buffer cache。
3. 映射层:内核从块设备上读取数据,这样内核就必须确定数据在物理设备上的位置,这由映射层(Mapping Layer)来完成。
4. 通用块层:由于绝大多数情况的I/O操作是跟块设备打交道,所以Linux在此提供了一个类似vfs层的块设备操作抽象层。
下层对接各种不同属性的块设备,对上提供统一的Block IO请求标准。
5. I/O调度层:大多数的块设备都是磁盘设备,所以有必要根据这类设备的特点以及应用特点来设置一些不同的调度器。
iozone的使用与介绍iozone介绍:iozone()是一个文件系统的benchmark工具,可以测试不同的操作系统中文件系统的读写性能。
可以测试Read, write, re-read,re-write, read backwards, read strided, fread, fwrite, random read, pread,mmap, aio_read, aio_write 等等不同的模式下的硬盘的性能。
测试的时候请注意,设置的测试文件的大小一定要大过你的内存(最佳为内存的两倍大小),不然linux会给你的读写的内容进行缓存。
会使数值非常不真实.iozone常用的几个参数.-a 全面测试,比如块大小它会自动加-i N 用来选择测试项, 比如Read/Write/Random 比较常用的是0 1 2,可以指定成-i 0 -i 1 -i2.这些别的详细内容请查man0=write/rewrite1=read/re-read2=random-read/write3=Read-backwards4=Re-write-record5=stride-read6=fwrite/re-fwrite7=fread/Re-fread8=random mix9=pwrite/Re-pwrite10=pread/Re-pread11=pwritev/Re-pwritev12=preadv/Re-preadv-r block size 指定一次写入/读出的块大小-s file size 指定测试文件的大小-f filename 指定测试文件的名字,完成后会自动删除(这个文件必须指定你要测试的那个硬盘中)-F file1 file2... 指定多线程下测试的文件名批量测试项:-g -n 指定测试文件大小范围,最大测试文件为4G,可以这样写-g 4G-y -q 指定测试块的大小范围输出:下面是几个日志记录的参数.好象要输出成图象进行分析,需要指定-a的测试才能输出-R 产生Excel到标准输出-b 指定输出到指定文件上. 比如-Rb ttt.xls我的测试实例:#./iozone -a -n 512m -g 4g -i 0 -i 1 -i 5 -f /mnt/iozone -Rb ./iozone.xls注:进行全面测试.最小测试文件为512M直到测试到4G.测试read,write,和Strided Read.测试的地方在mnt下。
编译IOzone源码#makeMakefile里有IOzone所支持的操作系统平台清单。
选择其中符合你的配置的那个并#make target这就完成了。
无须任何安装过程因为IOzone将自动在它的工作目录中产生所有文件。
你只要将IOzone拷贝到你想测试文件系统性能的任何一个文件夹并运行它。
或者你可以使用-f命令行参数来指定一个目标路径,例如,一个新文件系统中的路径/文件名。
一、参数:Usage: iozone [-s filesize_Kb] [-r record_size_Kb ] [-f [path]filename][-i test] [-E] [-p] [-a] [-A] [-z] [-Z] [-m] [-M] [-t children] [-h] [-o][-l min_number_procs] [-u max_number_procs] [-v] [-R] [-x][-d microseconds] [-F path1 path2...] [-V pattern] [-j stride][-T] [-C] [-B] [-D] [-G] [-I] [-H depth] [-k depth] [-U mount_point][-S cache_size] [-O] [-K] [-L line_size] [-g max_filesize_Kb][-n min_filesize_Kb] [-N] [-Q] [-P start_cpu] [-c] [-e] [-b filename][-J milliseconds] [-X filename] [-Y filename] [-w] [-W][-y min_recordsize_Kb] [-q max_recordsize_Kb] [-+m filename][-+u ] [ -+d ] [-+p percent_read] [-+r] [-+t ] [-+A #]二、常用参数含义-a——执行自动化测试;-z——与-a配合使用,进行更加完善的自动化测试;-b——指定测试后生成的excel;-i——指定测试种类;-q——指定最大的record size;-y——指定最小的record size;-r——指定单一的record size;-g——指定最大的file size;-n——指定最小的file size;-s——指定单一的file size;-+m filename——获得客户端的配置信息;-t——集群测试,指定客户端的数量。
Iozone使用简介(Linux)
修改记录
目录
实战简介(单节点) (3)
一、Iozone的安装: (3)
二、执行测试: (3)
二、测试结果收集与整理: (4)
实战简介(集群测试) (5)
一、Iozone的安装: (5)
二、rsh配置: (5)
二、Iozone集群测试: (6)
三、测试结果收集与整理: (6)
知识串烧 (8)
一、经常用到的参数: (8)
二、Iozone包含的测试种类: (8)
三、资料路径: (8)
实战简介(单节点)
一、Iozone的安装:
1、安装rpm -ivh iozone-3.226-1.0.rh8.dag.i386.rpm;
2、查找生成的Iozone可执行文件find / -name iozone;
3、将找到的文件拷贝至测试目录cp /usr/bin/iozone /mnt/(/mnt为蓝鲸的挂在目录)
详细过程见下图:
二、执行测试:
执行命令:./iozone -az -b **** -g 4g -y 32k -i 0 -i 1
说明:-az——执行不同粒度(record size)和测试文(file size)的自动化测试,默认情况下record size从4K—16M,file size从64K—512M。
-b——指定测试后生成的excel文件。
-g——指定最大的file size大小。
(一般为内存的两倍)
-y——指定最小的record size数值。
-i——指定测试的种类。
(0代表write/rewrite,1代表read/re-read)下图为测试过程中屏幕显示部分信息:
第一列为测试的file size;第二列为测试的record size;后四列分别对应不同测试方法的测试结果(单位为Kb/s)。
二、测试结果收集与整理:
在生成的excel中可以看到如下图的数据:左边一列为file size的不同数值;横行显示的为不同的record size。
下图中,测试的种类为写测试,测试出了不同组合下的写的速度。
还可以将上述结果用excel整理成曲面图的形式,如下图所示:
(上述测试环境为:Dell 2950服务器+豪威盘阵单路径+BWFS5.3.2RC2+CentOS5.2客户端)
实战简介(集群测试)
一、Iozone的安装:
1、解包:tar xvf iozone3_218.tar
2、进入指定目录进行编译:cd src/current/ && make linux
3、将生成的iozone拷贝至待测试目录中
4、以上操作需要在每个被测试的客户端上进行。
安装Iozone,既可以直接用rpm包安装,也可以用tar包进行编译。
二、rsh配置:
由于Iozone在进行集群测试的过程中会使用rsh登录到各个测试节点上执行测试指令,所以需要在各个节点上配置rsh,使各个节点之间能够相互通过rsh无密码登录。
1、确认rsh与rsh server已经安装:rpm -qa |grep rsh。
如果没有安装,可到对应的系统iso 中提取并安装。
2、按照下图执行以下步骤:
3、在被登录的节点上创建/root/.rhosts文件,并在其中添加登录节点的信息,如想从10.10.170.139用rsh登录到10.10.170.138上,需在138上创建/root/.rhost,并添加如下内容。
配置完成后,此时可以从139用rsh无需密码登录到138上。
4、配置通过主机名无密码登录:
还是从139登录到138上,则需要在139节点上对/etc/hosts文件进行编辑,添加如下内容:其中“10.10.170.138 as138”为新添加内容。
5、在每个测试节点上,完成以上配置,达到任意两个节点之间能够通过rsh+hostname进行无密码登录。
二、Iozone集群测试:
测试时,可以在任意一个待测试客户端上执行Iozone测试指令。
1、创建-+m filename所需的filename文件,并进行编辑。
文件名任意,编辑内容如下图:
文档中每行代表一个客户端的信息,每行包含三部分,每部分用空格隔开:第一部分为客户端的主机名;第二部分为客户端待测试的目录;第三部分为客户端待测试目录下将要执行的Iozone可执行文件。
2、在创建了filename文件的节点上执行集群化Iozone测试,参考指令如下:
./iozone -b ../bbb -s 1g -r 32k -i 0 -i 1 -+m ../client -t 2
上述指令,通过client文件在两个节点进行了策略为file size=1g,record size=32k的读/重复读、写/重复写的测试。
其中,-+m——指定了客户端配置信息的文件
-t——指定了客户端的数量(这个数量不能小于或大于client文件中配置的客户端数量)
(注意:在进行集群测试时,不能通过-az参数进行自动化测试,只能指定粒度进行多次测试,可以通过脚本来实现。
)
三、测试结果收集与整理:
下图为测试过程中屏幕上的部分显示信息:
下图为测试后生成的excel中的结果:
知识串烧
一、经常用到的参数:
-a——执行自动化测试;
-z——与-a配合使用,进行更加完善的自动化测试;
-b——指定测试后生成的excel;
-i——指定测试种类;
-q——指定最大的record size;
-y——指定最小的record size;
-r——指定单一的record size;
-g——指定最大的file size;
-n——指定最小的file size;
-s——指定单一的file size;
-+m filename——获得客户端的配置信息;
-t——集群测试,指定客户端的数量。
二、Iozone包含的测试种类:
指定方法为-i 0 –i 1 ……
0=write/rewrite, 1=read/re-read, 2=random-read/write, 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite, 7=fread/Re-fread, 8=random mix, 9=pwrite/Re-pwrite,
10=pread/Re-pread, 11=pwritev/Re-pwritev, 12=preadv/Repreadv
三、资料路径:
文档:
iozone_msword_98.pdf——\public\groups\test\各种工具\测试工具\iozone(天津蓝鲸)
软件包:
iozone-3.226-1.0.rh8.dag.i386.rpm——cvs:common/testtools/Iozone/
——\public\groups\test\各种工具\测试工具\iozone(天津蓝鲸)iozone3_218.tar——\public\groups\test\各种工具\测试工具\iozone(天津蓝鲸)
——cvs:common/testtools/Iozone/
网址:
/
注意:关于详细的说明请大家参看iozone_msword_98.pdf文档。