static int thread_number;
static char *ini_file;
+static int max_jobs = MAX_JOBS;
+
static int shm_id;
enum {
if (global)
return &def_thread;
- if (thread_number >= MAX_JOBS)
+ if (thread_number >= max_jobs)
return NULL;
td = &threads[thread_number++];
}
}
-int main(int argc, char *argv[])
+int setup_thread_area(void)
{
- static unsigned long max_run[2], min_run[2], total_blocks[2];
- static unsigned long max_bw[2], min_bw[2], maxl[2], minl[2];
- static unsigned long read_mb, write_mb, read_agg, write_agg;
- int i;
+ /*
+ * 1024 is too much on some machines, scale max_jobs if
+ * we get a failure that looks like too large a shm segment
+ */
+ do {
+ int s = max_jobs * sizeof(struct thread_data);
- shm_id = shmget(0, MAX_JOBS * sizeof(struct thread_data), IPC_CREAT | 0600);
- if (shm_id == -1) {
- perror("shmget");
+ shm_id = shmget(0, s, IPC_CREAT | 0600);
+ if (shm_id != -1)
+ break;
+ if (errno != EINVAL) {
+ perror("shmget");
+ break;
+ }
+
+ max_jobs >>= 1;
+ } while (1);
+
+ if (shm_id == -1)
return 1;
- }
threads = shmat(shm_id, NULL, 0);
- if (threads == (void *) -1 ) {
+ if (threads == (void *) -1) {
perror("shmat");
return 1;
}
atexit(free_shm);
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ static unsigned long max_run[2], min_run[2], total_blocks[2];
+ static unsigned long max_bw[2], min_bw[2], maxl[2], minl[2];
+ static unsigned long read_mb, write_mb, read_agg, write_agg;
+ int i;
+
+ if (setup_thread_area())
+ return 1;
if (sched_getaffinity(getpid(), sizeof(cpu_set_t), &def_thread.cpumask) == -1) {
perror("sched_getaffinity");