#define DEF_VERIFY (0)
#define DEF_STONEWALL (0)
#define DEF_NUMJOBS (1)
+#define DEF_USE_THREAD (0)
static int repeatable = DEF_RAND_REPEAT;
static char *ini_file;
td->verify = parent->verify;
td->stonewall = parent->stonewall;
td->numjobs = parent->numjobs;
+ td->use_thread = parent->use_thread;
memcpy(&td->cpumask, &parent->cpumask, sizeof(td->cpumask));
return td;
fgetpos(f, &off);
continue;
}
+ if (!strncmp(p, "thread", 6)) {
+ td->use_thread = 1;
+ fgetpos(f, &off);
+ continue;
+ }
+
printf("Client%d: bad option %s\n",td->thread_number,p);
}
fsetpos(f, &off);
def_thread.verify = DEF_VERIFY;
def_thread.stonewall = DEF_STONEWALL;
def_thread.numjobs = DEF_NUMJOBS;
+ def_thread.use_thread = DEF_USE_THREAD;
return 0;
}
#include <time.h>
#include <math.h>
#include <assert.h>
+#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
}
-static void *thread_main(int shm_id, int offset, char *argv[])
+static void *thread_main(void *data)
{
- struct thread_data *td;
+ struct thread_data *td = data;
int ret = 1;
- void *data;
setsid();
-
- data = shmat(shm_id, NULL, 0);
- if (data == (void *) -1) {
- perror("shmat");
- return NULL;
- }
-
- td = data + offset * sizeof(struct thread_data);
td->pid = getpid();
if (init_io_u(td))
goto err;
}
- sprintf(argv[0], "fio%d", offset);
-
if (td->use_aio && init_aio(td))
goto err;
sem_wait(&td->mutex);
}
td_set_runstate(td, TD_EXITED);
+ return NULL;
+
+}
+
+static void *fork_main(int shm_id, int offset)
+{
+ struct thread_data *td;
+ void *data;
+
+ data = shmat(shm_id, NULL, 0);
+ if (data == (void *) -1) {
+ perror("shmat");
+ return NULL;
+ }
+
+ td = data + offset * sizeof(struct thread_data);
+ thread_main(td);
shmdt(data);
return NULL;
}
continue;
td_set_runstate(td, TD_REAPED);
- waitpid(td->pid, NULL, 0);
+
+ if (td->use_thread) {
+ long ret;
+
+ if (pthread_join(td->thread, (void *) &ret))
+ perror("thread_join");
+ } else
+ waitpid(td->pid, NULL, 0);
+
(*nr_running)--;
(*m_rate) -= td->ratemin;
(*t_rate) -= td->rate;
check_str_update(td, *nr_running, *t_rate, *m_rate);
-
- if (td->terminate)
- continue;
}
}
todo--;
nr_started++;
- if (fork())
- sem_wait(&startup_sem);
- else {
- thread_main(shm_id, i, argv);
- exit(0);
+ if (td->use_thread) {
+ if (pthread_create(&td->thread, NULL, thread_main, td)) {
+ perror("thread_create");
+ nr_started--;
+ }
+ } else {
+ if (fork())
+ sem_wait(&startup_sem);
+ else {
+ fork_main(shm_id, i);
+ exit(0);
+ }
}
}