我可以使用pthreads为不同的线程调用nvme的ioctl()(系统调用)

我正在为nvme-cli开发一个测试工具(用c编写,可以在linux上运行)。

我有兴趣用’t’个线程重复一个nvme命令’r’次。

下面的代码重复执行命令和线程,但问题是并行执行时间与串行执行相比非常高。

根据我的观察,原因是从err = nvme_identify(fd, 0, 1, data);调用ioctl()系统调用err = nvme_identify(fd, 0, 1, data);nvme_identify()调用ioctl()

所以我可以知道ioctl()是否阻止了nvme?

我也可以通过线程减少执行时间(解决方案)吗?

 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; } 

线程function如下:

 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  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;