When splitting a memory read into numerous reads (in the ReadTargetMemory Insight worker task), use the page size if it's available and not less than 256 bytes.

This commit is contained in:
Nav
2022-12-17 14:45:54 +00:00
parent a1defa02c0
commit 9097e37375
2 changed files with 19 additions and 3 deletions

View File

@@ -1,21 +1,37 @@
#include "ReadTargetMemory.hpp" #include "ReadTargetMemory.hpp"
#include <cmath> #include <cmath>
#include <algorithm>
#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetMemory.hpp"
#include "src/Exceptions/Exception.hpp"
namespace Bloom namespace Bloom
{ {
using TargetController::TargetControllerConsole; using TargetController::TargetControllerConsole;
void ReadTargetMemory::run(TargetControllerConsole& targetControllerConsole) { void ReadTargetMemory::run(TargetControllerConsole& targetControllerConsole) {
using Targets::TargetMemorySize;
const auto& targetDescriptor = targetControllerConsole.getTargetDescriptor();
const auto memoryDescriptorIt = targetDescriptor.memoryDescriptorsByType.find(this->memoryType);
if (memoryDescriptorIt == targetDescriptor.memoryDescriptorsByType.end()) {
throw Exceptions::Exception("Invalid memory type");
}
const auto& memoryDescriptor = memoryDescriptorIt->second;
/* /*
* To prevent locking up the TargetController for too long, we split the read into numerous reads. * To prevent locking up the TargetController for too long, we split the read into numerous reads.
* *
* This allows the TargetController to service other commands in-between reads, reducing the likelihood of * This allows the TargetController to service other commands in-between reads, reducing the likelihood of
* command timeouts when we're reading lots of data. * command timeouts when we're reading lots of data.
*/ */
constexpr auto readSize = 256; const auto readSize = std::max(
TargetMemorySize(256),
memoryDescriptor.pageSize.value_or(TargetMemorySize(0))
);
const auto readsRequired = static_cast<std::uint32_t>( const auto readsRequired = static_cast<std::uint32_t>(
std::ceil(static_cast<float>(this->size) / static_cast<float>(readSize)) std::ceil(static_cast<float>(this->size) / static_cast<float>(readSize))
); );

View File

@@ -65,12 +65,12 @@ namespace Bloom::Targets
{ {
TargetMemoryType type; TargetMemoryType type;
TargetMemoryAddressRange addressRange; TargetMemoryAddressRange addressRange;
std::optional<std::uint32_t> pageSize; std::optional<TargetMemorySize> pageSize;
TargetMemoryDescriptor( TargetMemoryDescriptor(
TargetMemoryType type, TargetMemoryType type,
TargetMemoryAddressRange addressRange, TargetMemoryAddressRange addressRange,
std::optional<std::uint32_t> pageSize = std::nullopt std::optional<TargetMemorySize> pageSize = std::nullopt
) )
: type(type) : type(type)
, addressRange(addressRange) , addressRange(addressRange)