Skip to content

Commit 5dbe70c

Browse files
committed
hipFile: Mirror kernel's MAX_RW_COUNT computation
Since PAGE_SIZE is not the same on all plaforms, mirror the kernel's computation of MAX_RW_COUNT so that hipFile doesn't use an incorrect value.
1 parent 1e95a6c commit 5dbe70c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/amd_detail/backend.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@
1212
#include "sys.h"
1313

1414
#include <cstddef>
15+
#include <climits>
1516
#include <memory>
1617
#include <sys/types.h>
1718
#include <unistd.h>
1819

1920
namespace hipFile {
2021

22+
static const size_t PAGE_SIZE{[] {
23+
long v = sysconf(_SC_PAGE_SIZE);
24+
if (v == -1) {
25+
throw std::runtime_error("sysconf(_SC_PAGE_SIZE) failed");
26+
}
27+
return static_cast<size_t>(v);
28+
}()};
29+
30+
static const size_t PAGE_MASK{~(PAGE_SIZE - 1)};
31+
2132
// The maximum number of bytes that can be transferred in a single read() or
2233
// write() system call. Mirrors kernel's MAX_RW_COUNT
23-
static const size_t MAX_RW_COUNT = 0x7ffff000;
34+
static const size_t MAX_RW_COUNT = (INT_MAX & PAGE_MASK);
2435

2536
struct Backend {
2637
virtual ~Backend() = default;

0 commit comments

Comments
 (0)