void file_fill_buffer(char *buf, unsigned int len, size_t offset) { unsigned int i; for (i = 0; i < len - (FILE_CHECKSUM_LENGTH + FILE_OFFSET_LENGTH); i++) buf[i] = sb_rnd() & 0xFF; /* Store the checksum */ *(int *)(buf + i) = (int)crc32(0, buf, len - (FILE_CHECKSUM_LENGTH + FILE_OFFSET_LENGTH)); /* Store the offset */ *(long *)(buf + i + FILE_CHECKSUM_LENGTH) = offset; }
int memory_execute_request(sb_request_t *sb_req, int thread_id) { sb_mem_request_t *mem_req = &sb_req->u.mem_request; int tmp = 0; int idx; int *buf, *end; log_msg_t msg; log_msg_oper_t op_msg; long i; unsigned int rand; /* Prepare log message */ msg.type = LOG_MSG_TYPE_OPER; msg.data = &op_msg; if (mem_req->scope == SB_MEM_SCOPE_GLOBAL) buf = buffer; else buf = buffers[thread_id]; end = (int *)((char *)buf + memory_block_size); LOG_EVENT_START(msg, thread_id); if (memory_access_rnd) { rand = sb_rnd(); switch (mem_req->type) { case SB_MEM_OP_WRITE: for (i = 0; i < memory_block_size; i++) { idx = (int)((double)rand / (double)SB_MAX_RND * (double)(memory_block_size / sizeof(int))); buf[idx] = tmp; } break; case SB_MEM_OP_READ: for (i = 0; i < memory_block_size; i++) { idx = (int)((double)rand / (double)SB_MAX_RND * (double)(memory_block_size / sizeof(int))); tmp = buf[idx]; } break; default: log_text(LOG_FATAL, "Unknown memory request type:%d. Aborting...\n", mem_req->type); return 1; } } else { switch (mem_req->type) { case SB_MEM_OP_NONE: for (; buf < end; buf++) tmp = end - buf; break; case SB_MEM_OP_WRITE: for (; buf < end; buf++) *buf = tmp; break; case SB_MEM_OP_READ: for (; buf < end; buf++) tmp = *buf; break; default: log_text(LOG_FATAL, "Unknown memory request type:%d. Aborting...\n", mem_req->type); return 1; } } LOG_EVENT_STOP(msg, thread_id); return 0; }
sb_request_t file_get_rnd_request(void) { sb_request_t sb_req; sb_file_request_t *file_req = &sb_req.u.file_request; unsigned int randnum; unsigned long long tmppos; int real_mode = test_mode; int mode = test_mode; static unsigned long long ag_pos = 0; static int ag_group = 0; sb_req.type = SB_REQ_TYPE_FILE; /* Convert mode for combined tests. Locking to get consistent values We have to use "real" values for mixed test */ if (test_mode==MODE_RND_RW) { SB_THREAD_MUTEX_LOCK(); if ((double)(real_read_ops + 1) / (real_write_ops + 1) < file_rw_ratio) mode=MODE_RND_READ; else mode=MODE_RND_WRITE; SB_THREAD_MUTEX_UNLOCK(); } /* fsync all files (if requested by user) as soon as we are done */ if (req_performed == sb_globals.max_requests && sb_globals.max_requests > 0) { if (file_fsync_end != 0 && (real_mode == MODE_RND_WRITE || real_mode == MODE_RND_RW || real_mode == MODE_AG4_WRITE || real_mode == MODE_MIXED)) { pthread_mutex_lock(&fsync_mutex); if(fsynced_file2 < num_files) { file_req->file_id = fsynced_file2; file_req->operation = FILE_OP_TYPE_FSYNC; file_req->pos = 0; file_req->size = 0; fsynced_file2++; pthread_mutex_unlock(&fsync_mutex); return sb_req; } pthread_mutex_unlock(&fsync_mutex); } sb_req.type = SB_REQ_TYPE_NULL; return sb_req; } /* is_dirty is only set if writes are done and cleared after all files are synced */ if(file_fsync_freq != 0 && is_dirty) { if (req_performed % file_fsync_freq == 0) { file_req->operation = FILE_OP_TYPE_FSYNC; file_req->file_id = fsynced_file; file_req->pos = 0; file_req->size = 0; fsynced_file++; if (fsynced_file == num_files) { fsynced_file = 0; is_dirty = 0; } return sb_req; } } randnum=sb_rnd(); if (mode==MODE_RND_WRITE) /* mode shall be WRITE or RND_WRITE only */ file_req->operation = FILE_OP_TYPE_WRITE; else file_req->operation = FILE_OP_TYPE_READ; if (mode==MODE_AG4_WRITE) { if (++ag_group == 4) { ag_pos += file_block_size*2; ag_pos %= total_size / 4; ag_group = 0; } tmppos = ag_pos + total_size / 4 * ag_group; file_req->operation = FILE_OP_TYPE_WRITE; } else { tmppos = (long long)((double)randnum / (double)SB_MAX_RND * (double)(total_size)); } tmppos = tmppos - (tmppos % (long long)file_block_size); file_req->file_id = (int)(tmppos / (long long)file_size); file_req->pos = (long long)(tmppos % (long long)file_size); file_req->size = file_block_size; req_performed++; if (file_req->operation == FILE_OP_TYPE_WRITE) is_dirty = 1; return sb_req; }
int sb_lua_rnd(lua_State *L) { lua_pushnumber(L, sb_rnd()); return 1; }