/* * blk_init_worker -- initialize worker */ static int blk_init_worker(struct benchmark *bench, struct benchmark_args *args, struct worker_info *worker) { struct blk_worker *bworker = (struct blk_worker *)malloc(sizeof(*bworker)); if (!bworker) { perror("malloc"); return -1; } struct blk_bench *bb = (struct blk_bench *)pmembench_get_priv(bench); struct blk_args *bargs = (struct blk_args *)args->opts; bworker->seed = os_rand_r(&bargs->seed); bworker->buff = (unsigned char *)malloc(args->dsize); if (!bworker->buff) { perror("malloc"); goto err_buff; } /* fill buffer with some random data */ memset(bworker->buff, bworker->seed, args->dsize); assert(args->n_ops_per_thread != 0); bworker->blocks = (off_t *)malloc(sizeof(*bworker->blocks) * args->n_ops_per_thread); if (!bworker->blocks) { perror("malloc"); goto err_blocks; } if (bargs->rand) { for (size_t i = 0; i < args->n_ops_per_thread; i++) { bworker->blocks[i] = worker->index * bb->blocks_per_thread + os_rand_r(&bworker->seed) % bb->blocks_per_thread; } } else { for (size_t i = 0; i < args->n_ops_per_thread; i++) bworker->blocks[i] = i % bb->blocks_per_thread; } worker->priv = bworker; return 0; err_blocks: free(bworker->buff); err_buff: free(bworker); return -1; }
/* * init_offsets -- initialize offsets[] array depending on the selected mode */ static int init_offsets(struct benchmark_args *args, struct memset_bench *mb, enum operation_mode op_mode) { unsigned n_threads = args->n_threads; size_t n_ops = args->n_ops_per_thread; mb->n_offsets = n_ops * n_threads; assert(mb->n_offsets != 0); mb->offsets = (uint64_t *)malloc(mb->n_offsets * sizeof(*mb->offsets)); if (!mb->offsets) { perror("malloc"); return -1; } unsigned seed = mb->pargs->seed; for (unsigned i = 0; i < n_threads; i++) { for (size_t j = 0; j < n_ops; j++) { size_t o; switch (op_mode) { case OP_MODE_STAT: o = i; break; case OP_MODE_SEQ: o = i * n_ops + j; break; case OP_MODE_RAND: o = i * n_ops + os_rand_r(&seed) % n_ops; break; default: assert(0); return -1; } mb->offsets[i * n_ops + j] = o * mb->pargs->chunk_size; } } return 0; }