Example #1
0
void *random_io_reader(void *p)
{
  thread_arg_t *arg = (thread_arg_t *) p;
  char *bp; 
  posix_memalign((void **)&bp, 512, access_size);

  int num_reqs_per_thread = num_requests / num_threads;
  double t1 = gettimeofday_sec();
  //for (int i = 0; i < num_reqs_per_thread; ++i) {
  while (true) {
    off_t block_number = random_range(0, ionum-1) + access_from_block;
    //std::cout << arg->id << ": " << block_number << std::endl;
    if (!_pread(arg->fd, bp, access_size, block_number * access_size)) {
      perror("pread");
    }
    pthread_mutex_lock(&mutex);
    ++counter;
    pthread_mutex_unlock(&mutex);
    if (counter >= num_requests) {
      return NULL;
    }
  }
  double t2 = gettimeofday_sec();
  iops[arg->id] = num_reqs_per_thread / (t2-t1);
  mbps[arg->id] = (double) num_reqs_per_thread * access_size / (t2-t1);
  //std::cout << arg->id << ": " << iops[arg->id] << std::endl;
  return NULL;
}
Example #2
0
/**
 * ntfs_pread - positioned read from disk
 * @dev:	device to read from
 * @pos:	position in device to read from
 * @count:	number of bytes to read
 * @b:		output data buffer
 *
 * This function will read @count bytes from device @dev at position @pos into
 * the data buffer @b.
 *
 * On success, return the number of successfully read bytes. If this number is
 * lower than @count this means that we have either reached end of file or
 * encountered an error during the read so that the read is partial. 0 means
 * end of file or nothing to read (@count is 0).
 *
 * On error and nothing has been read, return -1 with errno set appropriately
 * to the return code of either seek, read, or set to EINVAL in case of
 * invalid arguments.
 */
s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b)
{
	s64 br, total;
	struct ntfs_device_operations *dops;
	s64 (*_pread)(struct ntfs_device *, void *, s64, s64);

	ntfs_log_trace("Entering for pos 0x%llx, count 0x%llx.\n", pos, count);
	if (!b || count < 0 || pos < 0) {
		errno = EINVAL;
		return -1;
	}
	if (!count)
		return 0;
	dops = dev->d_ops;
	_pread = dops->pread;
	if (!_pread)
		_pread = fake_pread;
seek:
	/* Locate to position if pread is to be emulated by seek() + read(). */
	if (_pread == fake_pread &&
			dops->seek(dev, pos, SEEK_SET) == (off_t)-1) {
		ntfs_log_perror("ntfs_pread: device seek to 0x%llx returned "
				"error", pos);
		return -1;
	}
	/* Read the data. */
	for (total = 0; count; count -= br, total += br) {
		br = _pread(dev, (char*)b + total, count, pos + total);
		/* If everything ok, continue. */
		if (br > 0)
			continue;
		/* If EOF or error return number of bytes read. */
		if (!br || total)
			return total;
		/*
		 * If pread is not supported by the OS, fall back to emulating
		 * it by seek() + read() and set the device pread() pointer to
		 * NULL so we automatically use seek() + read() from now on.
		 */
		if (errno == ENOSYS && _pread != fake_pread) {
			_pread = fake_pread;
			dops->pread = NULL;
			goto seek;
		}
		/* Nothing read and error, return error status. */
		return br;
	}
	/* Finally, return the number of bytes read. */
	return total;
}
Example #3
0
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
	char *p = buf;
	ssize_t total = 0;

	while (count > 0) {
		ssize_t loaded = _pread(fd, p, count, offset);
		if (unlikely(loaded < 0))
			return -1;
		if (unlikely(loaded == 0))
			return total;
		count -= loaded;
		p += loaded;
		total += loaded;
		offset += loaded;
	}

	return total;
}
Example #4
0
ssize_t pread(int fd, void *buf, size_t count, off_t offset)
{
    //printf("INTERCEPTED pread\n");
    
        
    clock_t start = clock();
    
    ssize_t ret = _pread(fd,buf,count,offset);

    clock_t end = clock();

    double called_time = (double)(start-program_start)/(double)(CLOCKS_PER_SEC);

    double exec_time = (double)(end-start)/(double)(CLOCKS_PER_SEC);

    fprintf(logFile,"%lf %lf pread %d %p %zu %ld = %zu\n",called_time,exec_time,fd,buf,count,offset,ret);

    return ret;

 
}