-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows using the extra memory available on at32f435 which was not possible with ring_io. It also has two side-goals of reducing the diff and I/O behavior in image handlers compared to stable-v3 and reducing overall code size. While readahead was a core principal of ring_io, it is more of a bolt-on for file_cache; file_cache focuses more on batched reads and writes. File_cache tries to look more like the normal F_read, F_write, and volume_cache with the main difference being that operations cannot span sectors. file_cache_{read,write} could easily support multi-sector ops, but no callers need such a thing as multi-sector reads/writes were for batching. file_cache still supports the "write directly to the cache" behavior available in ring_io, but HFE and QD are the only images that make use of it. The other images use a write buffer to avoid the read-then-write that was required with ring_io. Those other images now do not do reading-during-writing when their sector sizes are 512 or larger, which matches stable-v3 behavior. Since file_cache doesn't require read-before-write, the readahead can be higher or lower priority than writes.
- Loading branch information
Showing
19 changed files
with
928 additions
and
1,006 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* file_cache.h | ||
* | ||
* Caching I/O for a single file. | ||
* | ||
* Written & released by Keir Fraser <keir.xen@gmail.com> and Eric Anderson | ||
* <ejona86@gmail.com> | ||
* | ||
* This is free and unencumbered software released into the public domain. | ||
* See the file COPYING for more details, or visit <http://unlicense.org>. | ||
*/ | ||
|
||
/* The cache is a write-back cache and uses an I/O scheduler to schedule reads | ||
* and writes, with preference given to reads. Cache tracking is per-sector of | ||
* 512 bytes. | ||
* | ||
* The cache tries to batch reads and writes into batches of maximum size | ||
* 'batch_secs'. The file is split into aligned groups of batch_secs, and | ||
* batching cannot cross the boundary of groups. A read batch starts from the | ||
* sector requested and ends at the first already-read sector or end of the | ||
* group. Writes are not delayed to form a batch, but batches form if there are | ||
* delays due to reads or slow writes. | ||
* | ||
* In addition to batch reads, readahead can be enabled via | ||
* file_cache_readahead(). Reads and writes within the provided region will | ||
* cause the scheduler to read additional sectors, wrapping around when getting | ||
* to the end of the region. | ||
*/ | ||
|
||
struct file_cache; | ||
|
||
struct file_cache *file_cache_init(FIL *fp, uint8_t batch_secs, | ||
void *start, void *end); | ||
/* Waits until written data is flushed and synced to storage. */ | ||
void file_cache_sync_wait(struct file_cache *fcache); | ||
/* Stops scheduling I/O and waits for outstanding I/O to complete. To ensure | ||
* data is not lost, use file_cache_sync_wait() first. */ | ||
void file_cache_shutdown(struct file_cache *fcache); | ||
/* Run the I/O scheduler without requesting new I/O. Necessary for periods | ||
* without I/O operations for writing and readahead. */ | ||
void file_cache_progress(struct file_cache *fcache); | ||
/* Limit I/O operation size potentially below that of batch_sec. 0 disables the | ||
* limit. */ | ||
void file_cache_io_limit(struct file_cache *fcache, uint8_t io_max); | ||
/* Enable readahead for I/O ops within the specified region. @prio bytes are | ||
* higher priority than writes. */ | ||
void file_cache_readahead( | ||
struct file_cache *fcache, FSIZE_t ofs, UINT btr, UINT prio); | ||
|
||
/* Read within a sector. Will block until data is read. */ | ||
void file_cache_read(struct file_cache *fcache, void *buf, FSIZE_t ofs, | ||
UINT btr); | ||
/* Read within a sector. If FALSE, try again later. */ | ||
bool_t file_cache_try_read(struct file_cache *fcache, void *buf, FSIZE_t ofs, | ||
UINT btr); | ||
/* Read 512 bytes at sector-aligned @ofs. Returns NULL if read is not yet | ||
* available. */ | ||
const void *file_cache_peek_read(struct file_cache *fcache, FSIZE_t ofs); | ||
|
||
/* Write within a sector. May block waiting on cache space, or if a partial | ||
* sector is being written and the sector data is not already cached. */ | ||
void file_cache_write(struct file_cache *fcache, const void *buf, | ||
FSIZE_t ofs, UINT btw); | ||
/* Write within a sector. If FALSE, try again later. */ | ||
bool_t file_cache_try_write(struct file_cache *fcache, const void *buf, | ||
FSIZE_t ofs, UINT btw); | ||
/* Read 512 bytes at sector-aligned @ofs . Returns NULL if | ||
* the write is not yet possible. If the return is non-NULL, data written to | ||
* the buffer is observed by the next write or file_cache_sync(). Reads are | ||
* not permitted until the written data is observed. */ | ||
void *file_cache_peek_write(struct file_cache *fcache, FSIZE_t ofs); | ||
|
||
/* Flush filesystem cached data for file. Does not wait for it to complete. */ | ||
void file_cache_sync(struct file_cache *fcache); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.