mirror of https://github.com/google/gemma.cpp.git
Fix preadv error: only enable if we have a handle
PiperOrigin-RevId: 795455020
This commit is contained in:
parent
78573b6718
commit
41a86d41a9
30
io/io.cc
30
io/io.cc
|
|
@ -226,21 +226,26 @@ void InternalInit() {
|
|||
}
|
||||
|
||||
uint64_t IOBatch::Read(const File& file) const {
|
||||
#if GEMMA_IO_PREADV
|
||||
HWY_ASSERT(!spans_.empty());
|
||||
|
||||
ssize_t bytes_read;
|
||||
for (;;) {
|
||||
bytes_read =
|
||||
preadv(file.Handle(), reinterpret_cast<const iovec*>(spans_.data()),
|
||||
static_cast<int>(spans_.size()), offset_);
|
||||
if (bytes_read >= 0) break;
|
||||
if (errno == EINTR) continue; // signal: retry
|
||||
HWY_WARN("preadv failed, errno %d.", errno);
|
||||
return 0;
|
||||
#if GEMMA_IO_PREADV
|
||||
if (file.Handle() != -1) {
|
||||
ssize_t bytes_read;
|
||||
for (;;) {
|
||||
bytes_read =
|
||||
preadv(file.Handle(), reinterpret_cast<const iovec*>(spans_.data()),
|
||||
static_cast<int>(spans_.size()), offset_);
|
||||
if (bytes_read >= 0) break;
|
||||
if (errno == EINTR) continue; // signal: retry
|
||||
HWY_WARN("preadv(%d) for %4zu spans from offset %12zu failed, errno %d.",
|
||||
file.Handle(), spans_.size(), offset_, errno);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<uint64_t>(bytes_read);
|
||||
}
|
||||
return static_cast<uint64_t>(bytes_read);
|
||||
#else
|
||||
#endif // GEMMA_IO_PREADV
|
||||
|
||||
// preadv disabled or no handle: use normal reads (higher kernel overhead).
|
||||
uint64_t total = 0;
|
||||
uint64_t offset = offset_;
|
||||
for (const IOSpan& span : spans_) {
|
||||
|
|
@ -249,7 +254,6 @@ uint64_t IOBatch::Read(const File& file) const {
|
|||
offset += span.bytes;
|
||||
}
|
||||
return total;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace gcpp
|
||||
|
|
|
|||
Loading…
Reference in New Issue