Esempio n. 1
0
int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
{
	int orig_timeout = timeout;
	struct timespec start;
	int ret;

	clock_gettime_mono(&start);

	while (true) {
		struct timespec now;
		int64_t elapsed;

		ret = poll(fds, num_fds, timeout);
		if (ret != -1) {
			break;
		}
		if (errno != EINTR) {
			break;
		}
		clock_gettime_mono(&now);
		elapsed = nsec_time_diff(&now, &start);
		timeout = (orig_timeout - elapsed) / 1000000;
	};
	return ret;
}
Esempio n. 2
0
static void asys_fsync_do(void *private_data)
{
	struct asys_job *job = (struct asys_job *)private_data;
	struct asys_fsync_args *args = &job->args.fsync_args;

	clock_gettime_mono(&job->start_time);
	job->ret = fsync(args->fildes);
	clock_gettime_mono(&job->end_time);

	if (job->ret == -1) {
		job->err = errno;
	}
}
Esempio n. 3
0
static void asys_pread_do(void *private_data)
{
	struct asys_job *job = (struct asys_job *)private_data;
	struct asys_pread_args *args = &job->args.pread_args;

	clock_gettime_mono(&job->start_time);
	job->ret = pread(args->fildes, args->buf, args->nbyte, args->offset);
	clock_gettime_mono(&job->end_time);

	if (job->ret == -1) {
		job->err = errno;
	}
}
Esempio n. 4
0
static void stopwatch_stop(struct stopwatch *watch,
        long long bytes_read)
{
    double elapsed, rate;

    if (clock_gettime_mono(&watch->stop)) {
        int err = errno;
        fprintf(stderr, "clock_gettime(CLOCK_MONOTONIC) failed with "
            "error %d (%s)\n", err, strerror(err));
        goto done;
    }
    elapsed = timespec_to_double(&watch->stop) -
        timespec_to_double(&watch->start);
    rate = (bytes_read / elapsed) / (1024 * 1024 * 1024);
    printf("stopwatch: took %.5g seconds to read %lld bytes, "
        "for %.5g GB/s\n", elapsed, bytes_read, rate);
    printf("stopwatch:  %.5g seconds\n", elapsed);
done:
    free(watch);
}
Esempio n. 5
0
static struct stopwatch *stopwatch_create(void)
{
    struct stopwatch *watch;

    watch = calloc(1, sizeof(struct stopwatch));
    if (!watch) {
        fprintf(stderr, "failed to allocate memory for stopwatch\n");
        goto error;
    }
    if (clock_gettime_mono(&watch->start)) {
        int err = errno;
        fprintf(stderr, "clock_gettime(CLOCK_MONOTONIC) failed with "
            "error %d (%s)\n", err, strerror(err));
        goto error;
    }
    return watch;

error:
    free(watch);
    return NULL;
}