//------------------------------------------------ // Discover device storage capacity, etc. // static bool discover_device(device* dev) { int fd = fd_get(dev); if (fd == -1) { return false; } uint64_t device_bytes; if (g_scfg.file_size == 0) { ioctl(fd, BLKGETSIZE64, &device_bytes); } else { // undocumented file mode device_bytes = g_scfg.file_size; if (ftruncate(fd, (off_t)device_bytes) != 0) { fprintf(stdout, "ERROR: ftruncate file %s errno %d '%s'\n", dev->name, errno, act_strerror(errno)); fd_put(dev, fd); return false; } } dev->n_large_blocks = device_bytes / g_scfg.large_block_ops_bytes; dev->min_op_bytes = discover_min_op_bytes(fd, dev->name); fd_put(dev, fd); if (dev->n_large_blocks == 0) { fprintf(stdout, "ERROR: %s ioctl to discover size\n", dev->name); return false; } if (dev->min_op_bytes == 0) { return false; } fprintf(stdout, "%s size = %" PRIu64 " bytes, %" PRIu64 " large blocks, " "minimum IO size = %" PRIu32 " bytes\n", dev->name, device_bytes, dev->n_large_blocks, dev->min_op_bytes); discover_read_pattern(dev); if (g_scfg.commit_to_device) { discover_write_pattern(dev); } // else - write load is all accounted for with large-block writes. return true; }
//------------------------------------------------ // Discover device storage capacity. // static bool discover_num_blocks(device* p_device) { int fd = fd_get(p_device); if (fd == -1) { return false; } g_fd_device = fd; uint64_t device_bytes = 0; ioctl(fd, BLKGETSIZE64, &device_bytes); p_device->num_large_blocks = device_bytes / g_large_block_ops_bytes; p_device->min_op_bytes = discover_min_op_bytes(fd, p_device->name); if (! (p_device->num_large_blocks && p_device->min_op_bytes)) { return false; } uint64_t num_min_op_blocks = (p_device->num_large_blocks * g_large_block_ops_bytes) / p_device->min_op_bytes; uint64_t read_req_min_op_blocks = (g_record_bytes + p_device->min_op_bytes - 1) / p_device->min_op_bytes; p_device->num_read_offsets = num_min_op_blocks - read_req_min_op_blocks + 1; p_device->read_bytes = read_req_min_op_blocks * p_device->min_op_bytes; if (g_output_file){ fprintf(g_output_file, "-> Blocks Infomation:\n - %s size = %" PRIu64 " bytes\n - %" PRIu64 " large blocks\n - " "%" PRIu64 " %" PRIu32 "-byte blocks\n - buffers are %" PRIu32 " bytes\n", p_device->name, device_bytes, p_device->num_large_blocks, num_min_op_blocks, p_device->min_op_bytes, p_device->read_bytes); fprintf(g_output_file, "__________________________________________\n"); } if (g_ref_tab_columns) { if (!g_device->ref_tab) { g_device->ref_tab = malloc((g_device->num_read_offsets * g_ref_tab_columns) / 8); memset(g_device->ref_tab, 0, sizeof(g_device->ref_tab)); printf("Table of Reference created(%"PRIu64")!\n", (g_device->num_read_offsets * g_ref_tab_columns) / 64); } }else{ return false; } return true; }