You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a discussion issue meant to center around ways to make the current BlockDevice HAL in machine better.
Today
// BlockDevice is the raw device that is meant to store flash data.typeBlockDeviceinterface {
// ReadAt reads the given number of bytes from the block device.
io.ReaderAt// WriteAt writes the given number of bytes to the block device.
io.WriterAt// Size returns the number of bytes in this block device.Size() int64// WriteBlockSize returns the block size in which data can be written to// memory. It can be used by a client to optimize writes, non-aligned writes// should always work correctly.WriteBlockSize() int64// EraseBlockSize returns the smallest erasable area on this particular chip// in bytes. This is used for the block size in EraseBlocks.// It must be a power of two, and may be as small as 1. A typical size is 4096.EraseBlockSize() int64// EraseBlocks erases the given number of blocks. An implementation may// transparently coalesce ranges of blocks into larger bundles if the chip// supports this. The start and len parameters are in block numbers, use// EraseBlockSize to map addresses to blocks.EraseBlocks(start, lenint64) error
}
Issues
ReaderAt/WriteAt methods is not the correct HAL, as is indicated by sister methods which operate on a block indexing scheme.
This means that all BlockDevice implementations must reimplement block to address indexing conversion and checks leading to lots of duplicated code between reimplementations
No access to actual block reading HAL for when block read/write is what the user wants
Obfuscates the cost of a read operation for users who actually are unaware what a block device actually is
Same goes for Size, a more correct approach would be NumBlocks/BlockCount instead.
Block sizes can be represented as int type since they must fit into main memory or else the API is completely unusable since a single block read results in OOM
Proposal
The actual meat of the proposal is replacing with the following abstraction. dst and data buffers should be a multiple of the block size for efficient use of the block device. WE can have a BlockDeviceOperator type that wraps a BlockDevice that implements reading less than multiple of a block which I believe would be a good design practice- it simplifies all BlockDevice implementations and puts all that complexity in one single place making maintenance much easier on developers.
typeBlockReaderinterface {
ReadBlocks(dst []byte, startBlockint64) (int, error)
}
typeBlockWriterinterface {
WriteBlocks(data []byte, startBlockint64) (int, error)
}
// BlockDevice is the basic interface that must be implemented for a device to function properly.typeBlockDeviceinterface {
BlockReaderBlockWriterEraseBlocks(startBlock, numBlocksint64) errorBlockSize() intEraseBlockSize() intBlockCount() int64
}
Sub Proposals
These are just observations on things that could be better
Move BlockDevice into an internal package, exported one should live in tinygo drivers repo
The text was updated successfully, but these errors were encountered:
Do you have examples of flash block devices that do not allow reads and writes to individual bytes?
Also, I don't think mapping these sizes is very complicated. Do you have code samples that show it leads to complicated code?
This is a discussion issue meant to center around ways to make the current
BlockDevice
HAL in machine better.Issues
Size
, a more correct approach would beNumBlocks
/BlockCount
instead.int
type since they must fit into main memory or else the API is completely unusable since a single block read results in OOMProposal
The actual meat of the proposal is replacing with the following abstraction. dst and data buffers should be a multiple of the block size for efficient use of the block device. WE can have a BlockDeviceOperator type that wraps a BlockDevice that implements reading less than multiple of a block which I believe would be a good design practice- it simplifies all BlockDevice implementations and puts all that complexity in one single place making maintenance much easier on developers.
Sub Proposals
These are just observations on things that could be better
The text was updated successfully, but these errors were encountered: