[Denali] Update the read many request to take a sector count as well.
This greatly reduces the size of the message (we had surpassed the 1 page - 4KiB message limit with the previous method).
This commit is contained in:
parent
9f0e87b51d
commit
41bf78cf98
|
@ -35,28 +35,30 @@ glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
ReadResponse& resp) {
|
ReadResponse& resp) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
||||||
|
|
||||||
uint64_t region_paddr;
|
if (req.lba().size() != req.sector_cnt().size()) {
|
||||||
OwnedMemoryRegion region = OwnedMemoryRegion::ContiguousPhysical(
|
return glcr::INVALID_ARGUMENT;
|
||||||
req.lba().size() * 512, ®ion_paddr);
|
}
|
||||||
|
|
||||||
auto& vec = req.lba();
|
uint64_t sector_cnt = 0;
|
||||||
uint64_t curr_run_start = 0;
|
for (uint64_t i = 0; i < req.sector_cnt().size(); i++) {
|
||||||
for (uint64_t i = 0; i < vec.size(); i++) {
|
sector_cnt += req.sector_cnt().at(i);
|
||||||
if (i + 1 < vec.size() && vec.at(i) + 1 == vec.at(i + 1)) {
|
}
|
||||||
continue;
|
uint64_t region_paddr;
|
||||||
}
|
OwnedMemoryRegion region =
|
||||||
uint64_t lba = vec.at(curr_run_start);
|
OwnedMemoryRegion::ContiguousPhysical(sector_cnt * 512, ®ion_paddr);
|
||||||
uint64_t size = (i - curr_run_start) + 1;
|
|
||||||
uint64_t paddr = region_paddr + curr_run_start * 512;
|
for (uint64_t i = 0; i < req.lba().size(); i++) {
|
||||||
DmaReadCommand command(lba, size, paddr);
|
uint64_t lba = req.lba().at(i);
|
||||||
|
uint64_t size = req.sector_cnt().at(i);
|
||||||
|
DmaReadCommand command(lba, size, region_paddr);
|
||||||
device->IssueCommand(&command);
|
device->IssueCommand(&command);
|
||||||
command.WaitComplete();
|
command.WaitComplete();
|
||||||
|
|
||||||
curr_run_start = i + 1;
|
region_paddr += size * 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.set_device_id(req.device_id());
|
resp.set_device_id(req.device_id());
|
||||||
resp.set_size(req.lba().size());
|
resp.set_size(sector_cnt);
|
||||||
resp.set_memory(region.DuplicateCap());
|
resp.set_memory(region.DuplicateCap());
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,10 @@ message ReadRequest {
|
||||||
|
|
||||||
message ReadManyRequest {
|
message ReadManyRequest {
|
||||||
u64 device_id;
|
u64 device_id;
|
||||||
|
// FIXME: Add repeated message fields.
|
||||||
|
// Must be the same length.
|
||||||
repeated u64 lba;
|
repeated u64 lba;
|
||||||
|
repeated u64 sector_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ReadResponse {
|
message ReadResponse {
|
||||||
|
|
|
@ -100,11 +100,21 @@ void ReadManyRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint
|
||||||
lba_.PushBack(bytes.At<uint64_t>(i));
|
lba_.PushBack(bytes.At<uint64_t>(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse sector_cnt.
|
||||||
|
auto sector_cnt_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 2));
|
||||||
|
|
||||||
|
sector_cnt_.Resize(sector_cnt_pointer.length / sizeof(uint64_t));
|
||||||
|
for (uint64_t i = offset + sector_cnt_pointer.offset;
|
||||||
|
i < offset + sector_cnt_pointer.offset + sector_cnt_pointer.length;
|
||||||
|
i += sizeof(uint64_t)) {
|
||||||
|
sector_cnt_.PushBack(bytes.At<uint64_t>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
uint32_t next_extension = header_size + 8 * 2;
|
uint32_t next_extension = header_size + 8 * 3;
|
||||||
const uint32_t core_size = next_extension;
|
const uint32_t core_size = next_extension;
|
||||||
// Write device_id.
|
// Write device_id.
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), device_id());
|
||||||
|
@ -121,6 +131,19 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
||||||
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
||||||
}
|
}
|
||||||
|
// Write sector_cnt.
|
||||||
|
ExtPointer sector_cnt_ptr{
|
||||||
|
.offset = next_extension,
|
||||||
|
.length = (uint32_t)(sector_cnt().size() * sizeof(uint64_t)),
|
||||||
|
};
|
||||||
|
|
||||||
|
next_extension += sector_cnt_ptr.length;
|
||||||
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 2), sector_cnt_ptr);
|
||||||
|
|
||||||
|
for (uint64_t i = 0; i < sector_cnt().size(); i++) {
|
||||||
|
uint32_t ext_offset = offset + sector_cnt_ptr.offset + (i * sizeof(uint64_t));
|
||||||
|
bytes.WriteAt<uint64_t>(ext_offset, sector_cnt().at(i));
|
||||||
|
}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
@ -129,7 +152,7 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
|
||||||
uint32_t next_extension = header_size + 8 * 2;
|
uint32_t next_extension = header_size + 8 * 3;
|
||||||
const uint32_t core_size = next_extension;
|
const uint32_t core_size = next_extension;
|
||||||
uint64_t next_cap = 0;
|
uint64_t next_cap = 0;
|
||||||
// Write device_id.
|
// Write device_id.
|
||||||
|
@ -147,6 +170,19 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
uint32_t ext_offset = offset + lba_ptr.offset + (i * sizeof(uint64_t));
|
||||||
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
bytes.WriteAt<uint64_t>(ext_offset, lba().at(i));
|
||||||
}
|
}
|
||||||
|
// Write sector_cnt.
|
||||||
|
ExtPointer sector_cnt_ptr{
|
||||||
|
.offset = next_extension,
|
||||||
|
.length = (uint32_t)(sector_cnt().size() * sizeof(uint64_t)),
|
||||||
|
};
|
||||||
|
|
||||||
|
next_extension += sector_cnt_ptr.length;
|
||||||
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 2), sector_cnt_ptr);
|
||||||
|
|
||||||
|
for (uint64_t i = 0; i < sector_cnt().size(); i++) {
|
||||||
|
uint32_t ext_offset = offset + sector_cnt_ptr.offset + (i * sizeof(uint64_t));
|
||||||
|
bytes.WriteAt<uint64_t>(ext_offset, sector_cnt().at(i));
|
||||||
|
}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
|
@ -47,10 +47,13 @@ class ReadManyRequest {
|
||||||
void set_device_id(const uint64_t& value) { device_id_ = value; }
|
void set_device_id(const uint64_t& value) { device_id_ = value; }
|
||||||
const glcr::Vector<uint64_t>& lba() const { return lba_; }
|
const glcr::Vector<uint64_t>& lba() const { return lba_; }
|
||||||
void add_lba(const uint64_t& value) { lba_.PushBack(value); }
|
void add_lba(const uint64_t& value) { lba_.PushBack(value); }
|
||||||
|
const glcr::Vector<uint64_t>& sector_cnt() const { return sector_cnt_; }
|
||||||
|
void add_sector_cnt(const uint64_t& value) { sector_cnt_.PushBack(value); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t device_id_;
|
uint64_t device_id_;
|
||||||
glcr::Vector<uint64_t> lba_;
|
glcr::Vector<uint64_t> lba_;
|
||||||
|
glcr::Vector<uint64_t> sector_cnt_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
|
|
|
@ -78,14 +78,19 @@ glcr::ErrorOr<OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
|
||||||
const glcr::Vector<uint64_t>& block_list) {
|
const glcr::Vector<uint64_t>& block_list) {
|
||||||
ReadManyRequest req;
|
ReadManyRequest req;
|
||||||
req.set_device_id(device_id_);
|
req.set_device_id(device_id_);
|
||||||
// FIXME: We should have better ergonomics for setting a repeated field in
|
|
||||||
// Yunq.
|
|
||||||
for (uint64_t i = 0; i < block_list.size(); i++) {
|
for (uint64_t i = 0; i < block_list.size(); i++) {
|
||||||
uint64_t sector = lba_offset_ + block_list.at(i) * SectorsPerBlock();
|
uint64_t curr_start = lba_offset_ + block_list.at(i) * SectorsPerBlock();
|
||||||
for (uint64_t j = 0; j < SectorsPerBlock(); j++) {
|
uint64_t curr_run_len = 1;
|
||||||
req.add_lba(sector + j);
|
while ((i + 1) < block_list.size() &&
|
||||||
|
block_list.at(i + 1) == block_list.at(i) + 1) {
|
||||||
|
i++;
|
||||||
|
curr_run_len++;
|
||||||
}
|
}
|
||||||
|
req.add_lba(curr_start);
|
||||||
|
req.add_sector_cnt(curr_run_len * SectorsPerBlock());
|
||||||
|
dbgln("Read {x}, {x}", curr_start, curr_run_len * SectorsPerBlock());
|
||||||
}
|
}
|
||||||
|
dbgln("Read many: {x}", req.lba().size());
|
||||||
ReadResponse resp;
|
ReadResponse resp;
|
||||||
RET_ERR(denali_.ReadMany(req, resp));
|
RET_ERR(denali_.ReadMany(req, resp));
|
||||||
return OwnedMemoryRegion::FromCapability(resp.memory());
|
return OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
|
|
Loading…
Reference in New Issue