We really need a pshared semaphore, but those aren't always available.
Just implement a cruddy local semaphore type, fio only really needs
to signal start/stop conditions.
http://linux01.gwdg.de/~pbleser/rpm-navigation.php?cat=System/fio
+Building
+--------
+
+Just type 'make' and 'make install'. If on FreeBSD, for now you have to
+specify the FreeBSD Makefile with -f, eg:
+
+$ make -f Makefile.Freebsd && make -f Makefile.FreeBSD install
+
+This might change in the future if I opt for an autoconf type setup.
+
+
Options
-------
#define should_fsync(td) ((td_write(td) || td_rw(td)) && (!(td)->odirect || (td)->override_sync))
-static sem_t startup_sem;
+static volatile int startup_sem;
#define TERMINATE_ALL (-1)
#define JOB_START_TIMEOUT (5 * 1000)
goto err;
td_set_runstate(td, TD_INITIALIZED);
- sem_post(&startup_sem);
- sem_wait(&td->mutex);
+ fio_sem_up(&startup_sem);
+ fio_sem_down(&td->mutex);
if (!td->create_serialize && setup_file(td))
goto err;
*/
td_set_runstate(td, TD_CREATED);
map[this_jobs++] = td;
- sem_init(&startup_sem, 0, 1);
+ fio_sem_init(&startup_sem, 1);
nr_started++;
if (td->use_thread) {
}
} else {
if (fork())
- sem_wait(&startup_sem);
+ fio_sem_down(&startup_sem);
else {
fork_main(shm_id, i);
exit(0);
m_rate += td->ratemin;
t_rate += td->rate;
todo--;
- sem_post(&td->mutex);
+ fio_sem_up(&td->mutex);
}
reap_threads(&nr_running, &t_rate, &m_rate);
#include <pthread.h>
#include <sys/time.h>
#include <sys/resource.h>
-#include <semaphore.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
unsigned long long zone_bytes;
unsigned long long this_io_bytes[2];
unsigned long long last_pos;
- sem_t mutex;
+ volatile int mutex;
os_random_state_t random_state;
unsigned long *file_map;
extern int parse_options(int, char **);
extern int init_random_state(struct thread_data *);
+/*
+ * This is a pretty crappy semaphore implementation, but with the use that fio
+ * has (just signalling start/go conditions), it doesn't have to be better.
+ * Naturally this would not work for any type of contended semaphore or
+ * for real locking.
+ */
+static inline void fio_sem_init(volatile int volatile *sem, int val)
+{
+ *sem = val;
+}
+
+static inline void fio_sem_down(volatile int volatile *sem)
+{
+ while (*sem == 0)
+ usleep(10000);
+
+ (*sem)--;
+}
+
+static inline void fio_sem_up(volatile int volatile *sem)
+{
+ (*sem)++;
+}
+
#endif
} else
strncpy(td->file_name, jobname, sizeof(td->file_name) - 1);
- sem_init(&td->mutex, 0, 0);
+ fio_sem_init(&td->mutex, 0);
td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;