0

This code is part of nvme-cli(its built on linux api)

I am trying to build an option to repeat a nvme-command say n times with p number of threads.

For example, if I say repeat 50-times with 5-threads, then each of the 5 threads should repeat 10-times individually.

So for that, I need to run the below for loop with multiple threads. Since I am new to multi-threading I thought of using P-threads. Can I know the syntax for doing so?

int* identify(int fd, int name_space, void *ctrl, int cns, int rc)
{
    int *err,count=0;
    struct nvme_admin_cmd cmd;
    static const char *perrstr;
    memset(&cmd, 0, sizeof(cmd));
    cmd.opcode = nvme_admin_identify;
    cmd.nsid = name_space;
    cmd.addr = (__u64)(uintptr_t)ctrl;
    cmd.data_len = 4096;
    cmd.cdw10 = cns;
    for(count=0; count<rc; count++){
        *(err+count) = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
    }
    return err;
}
Arjun G S
  • 23
  • 13
  • 1
    You will need to specify which threading library you want to use and which platform it is to run on — nvme-cli may be self-explanatory to those in the know, but not necessarily to everyone (and specifically not to me). The general concept will be that you create 5 threads, and tell each thread to execute 10 times. You'll need to make sure that the function called is properly thread-safe. It isn't clear whether the function you plan to call is `ioctl()` or something else. – Jonathan Leffler Nov 09 '17 at 04:19
  • For sure i need to call `ioclt()` function. – Arjun G S Nov 09 '17 at 04:25
  • The code is to be executed in linux environment with versions greater than 3.3 to support nvme. – Arjun G S Nov 09 '17 at 04:27
  • Playing devil's advocate, why do you need to call the `ioctl()` so often, What is the benefit of calling from multiple threads? Oh, and it would be good to edit the question to add the background info I requested, rather than leave it in comments. Links to good resources on NVME would not go amiss. – Jonathan Leffler Nov 09 '17 at 04:29
  • My code is part of a testing tool. Its done to test the consistency. I hope i am not wrong – Arjun G S Nov 09 '17 at 04:38

0 Answers0