测试工具sgp_dd是sg3_utils包中的一个测试裸盘读写速度的工具,它利用多线程以将磁盘分区域并行读写的方式来测试
分析目的集中于信号处理方式、多线程以及SCSI命令简介
包含文件及宏定义
除了包含linux中的库文件之外,在sgp_dd.c中还包含了3个头文件,跟sg有关:
l sg_lib.h:SG通用库头文件;
l sg_cmds_basic.h:SG基本命令头文件;
l sg_io_linux: SG在linux平台上的io处理函数头文件;
一些关于默认块大小、默认每次传输块数、SCSI命令描述块大小(CDB:command descriptor block)、设备类型的宏定义:
#define FT_OTHER 1 /* filetype other than one of the following */ #define FT_SG 2 /* filetype is sg char device */ #define FT_RAW 4 /* filetype is raw char device */ #define FT_DEV_NULL 8 /* either "/dev/null" or "." as filename */ #define FT_ST 16 /* filetype is st char device (tape) */ #define FT_BLOCK 32 /* filetype is a block device */ #define FT_ERROR 64 /* couldn't "stat" file */ |
通过stat()函数获得设备文件名代表的文件属性信息st,可通过查看st. st_mode判断是字符设备还是块设备,st. st_rdev的主次设备号,判断具体是哪种设备。相关函数和宏有:S_ISCHR()、S_ISBLK()、major()和minor等。
几个结构体
结构体struct flags_t,各种标记组合的结构体
类型 |
域 |
描述 |
int |
append |
用于设置打开标记O_APPEND |
int |
coe |
continue on error, 0->exit (def), 1->zero + continue 出错时时根据这个值决定如何处理 |
int |
dio |
is direct IO, 1->attempt, 0->indirect IO (def),用于设置struct sg_io_hdr的flags |= SG_FLAG_DIRECT_IO |
int |
direct |
|
int |
dpo |
用于设置CDB |
int |
dsync |
用于设置open标记O_SYNC |
int |
excl |
用于设置open标记O_EXCL |
int |
fua |
force unit access: 0->don't(def), 1->OFILE, 2->IFILE, 3->OFILE+IFILE 用于设置CDB |
[root@oss5 ~]# sgp_dd --help | grep dpo
Usage: sgp_dd [bs=BS] [count=COUNT] [ibs=BS] [if=IFILE][iflag=FLAGS]
[obs=BS] [of=OFILE][oflag=FLAGS] [seek=SEEK] [skip=SKIP]
[--help] [--version]
[bpt=BPT] [cdbsz=6|10|12|16][coe=0|1] [deb=VERB] [dio=0|1]
[fua=0|1|2|3] [sync=0|1][thr=THR] [time=0|1] [verbose=VERB]
where:
bpt is blocks_per_transfer(default is 128)
bs must be device blocksize (default 512)
cdbsz size of SCSI READ orWRITE cdb (default is 10)
coe continue on error,0->exit (def), 1->zero + continue
count number of blocks tocopy (def: device size)
deb for debug, 0->none(def), > 0->varying degrees of debug
dio is direct IO,1->attempt, 0->indirect IO (def)
fua force unit access:0->don't(def), 1->OFILE, 2->IFILE,
3->OFILE+IFILE
if file or device to readfrom (def: stdin)
iflag comma separated listfrom: [coe,dio,direct,dpo,dsync,excl,
fua, null]
of file or device towrite to (def: stdout), OFILE of '.'
treated as /dev/null
oflag comma separated listfrom: [append,coe,dio,direct,dpo,dsync,
excl,fua,null]
sync 0->no sync(def), 1->SYNCHRONIZECACHE on OFILE after copy
thr is number of threads,must be > 0, default 4, max 16
time 0->no timing(def),1->time plus calculate throughput
verbose same as 'deb=VERB':increase verbosity
--help output this usagemessage then exit
--