34
53
size_t total_size = 0;
35
54
size_t last_write = 0;
39
60
size_t max_size = (size_t)-1;
40
61
char *buffer;//[BUFSIZE];
41
62
long double mcoef = 1000000. / (1024 * 1024);
42
63
int flags = O_RDONLY|O_NOATIME|O_LARGEFILE;
67
size_t curio, schedio;
68
int done[AIO_MODE + EXTRA_BUFFERS];
71
struct iocb io[AIO_MODE], *ioptr[AIO_MODE];
74
struct io_event ev[AIO_MODE];
81
printf("Used buffer: %i MB, Block: %i KB\n", BUFSIZE / 1024 / 1024, BLOCK_SIZE/1024);
48
83
posix_memalign((void**)&buffer, FASTWRITER_SYNCIO_ALIGN, BUFSIZE);
63
98
printf("Unable to open device %s\n", argv[1]);
67
102
size_t size = BLOCK_SIZE;
105
memset(done, 0, sizeof(done));
106
memset(&aio, 0, sizeof(aio));
107
io_queue_init(AIO_MODE, &aio);
108
for (i = 0; i < AIO_MODE; i++) {
110
memset(ioptr[i], 0, sizeof(struct iocb));
111
io_prep_pread(ioptr[i], fd, buffer + i * BLOCK_SIZE, BLOCK_SIZE, i * BLOCK_SIZE);
112
io_set_callback(ioptr[i], (void*)(uintptr_t)i);
118
#endif /* AIO_MODE */
69
120
gettimeofday(&start, NULL);
123
err = io_submit(aio, AIO_MODE, ioptr);
124
if (err != AIO_MODE) {
125
printf("io_submit returned %i\n", err);
126
perror("Failed to submit initial AIO jobs");
128
#endif /* AIO_MODE */
133
if (!done[curio%(AIO_MODE + EXTRA_BUFFERS)]) {
134
err = io_getevents(aio, 1, AIO_MODE - events, &ev[events], NULL);
135
if (err < 0) perror("Error waiting for AIO\n");
137
if ((!ready)&&(err > 1)) {
138
printf("*** Multiple read requests (%i of %i) are finished simultaneously. It is either:\n", err, AIO_MODE);
139
printf(" Small buffer size (%i KB)\n", BLOCK_SIZE/1024);
140
printf(" More parallel AIOs (%i) than supported by kernel, try %i\n", AIO_MODE, AIO_MODE - err);
143
for (i = 0; i < err; i++) {
144
struct io_event *ep = &ev[events + i];
145
int doneio = (uintptr_t)ep->data;
146
if (ep->res2 || (ep->res != BLOCK_SIZE)) perror("Error in async IO");
147
done[doneio%(AIO_MODE + EXTRA_BUFFERS)] = 1;
148
// printf("done (%i): %i\n", i, doneio);
153
for (i = events - 1; (i >= 0)&&((schedio - curio) < (AIO_MODE + EXTRA_BUFFERS)); i--) {
154
struct iocb *newio = (struct iocb *)ev[i].obj;
155
memset(newio, 0, sizeof(struct iocb));
156
io_prep_pread(newio, fd, buffer + (schedio % (AIO_MODE + EXTRA_BUFFERS)) * BLOCK_SIZE, BLOCK_SIZE, schedio * BLOCK_SIZE);
157
io_set_callback(newio, (void*)(uintptr_t)schedio);
158
err = io_submit(aio, 1, &newio);
159
if (err != 1) perror("Failed to submit AIO jobs");
165
printf("*** Unprocessed events (%i), probably not enough buffer space...\n", events);
166
// printf(" curio (%zu), schedio (%zu)\n", curio, schedio);
173
done[curio%(AIO_MODE + EXTRA_BUFFERS)] = 0;
71
178
res = read(fd, buffer, size);
180
#endif /* AIO_MODE */
73
182
if (res != size) {
74
183
printf("Incomplete read: %zu bytes read instead of %zu\n", res, size);
79
188
gettimeofday(&tv, NULL);
80
189
us = (tv.tv_sec - start.tv_sec) * 1000000 + (tv.tv_usec - start.tv_usec);
81
190
if ((us - last_write) > WRITE_INTERVAL * 1000000) {
191
printf("Reading: %s (%lu GB), Measured speed: %zu MB/s, Current speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us), (size_t)(mcoef * (total_size - last_size) / (us - last_write)));
83
printf("Reading: %s (%lu GB), Measured speed: %zu MB/s\n", argv[0], total_size / 1024 / 1024 / 1024, (size_t)(mcoef * total_size / us));
193
last_size = total_size;
86
196
if (total_size > max_size) {