问题
I am working on a testing tool for nvme-cli(written in c and can run on linux).
I am interested in repeating a nvme command 'r' number of times with 't' number of threads.
The below code does the repeat of a command along with threading, but the issue here is the parallel execution time is very much high compared to serial execution.
As per my observation the reason is the invocation of ioctl()
system call from
err = nvme_identify(fd, 0, 1, data);
i.e nvme_identify()
inturn calls ioctl()
.
So can I know if ioctl()
is blocking for nvme ?
Also can I have any way (solution) to reduce the execution time by threading?
int repeat_cmd(int fd, void *data, int nsid,int cmd, int rc, int flags,
struct repeatfields *rf, int threadcount)
{
pthread_t tid[threadcount];
int err, i=0,j=0;
struct my_struct1 my_struct[threadcount];
switch(cmd){
case 1 :
for (j=0; j <threadcount; j++)
{
my_struct[j].fd = fd;
my_struct[j].data = data;
my_struct[j].flags = flags;
my_struct[j].rf = *rf;
my_struct[j].rcount = rc/threadcount;
pthread_create(&tid[j], NULL, ThreadFun_id_ctrl, (void*)&my_struct[i]);
}
for (j=0; j <threadcount; j++)
pthread_join(tid[j], NULL);
break;
}
The thread function is as follows :
void *ThreadFun_id_ctrl(void *val)
{
int err,j;
struct my_struct1 *my_struct = (struct my_struct1 *)val;
int fd = my_struct->fd;
void *data = my_struct->data;
struct repeatfields rf = my_struct->rf;
int flags = my_struct->flags;
int rcount = my_struct->rcount;
printf("Printing count = %d\n",rcount);
for (j=0; j <rcount; j++)
{
err = nvme_identify(fd, 0, 1, data);
if (!err) {
if (rf.fmt == BINARY)
d_raw((unsigned char *)&rf.ctrl, sizeof(rf.ctrl));
else if (rf.fmt == JSON)
json_nvme_id_ctrl(data, flags, 0);
else {
printf("NVME Identify Controller:\n");
__show_nvme_id_ctrl(data, flags, 0);
}
}
else if (err > 0){
fprintf(stderr, "NVMe Status:%s(%x)\n",
nvme_status_to_string(err), err);
}
else
perror("identify controller");
printf("Printing from Thread id = %d\n",syscall(SYS_gettid));
}
return NULL;
来源:https://stackoverflow.com/questions/47646051/can-i-invoke-ioctl-system-call-for-nvme-with-different-threads-using-pthread