Skip to content

Commit

Permalink
adjust parameters for prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Dec 23, 2020
1 parent 7e85107 commit 4d1b958
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libslim/source/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ BOOL cache_load_sector(CACHE *cache, BYTE drv, LBA_t sector, BYTE *dst)
}
else
{
memcpy(dst, &cache[i].data, FF_MAX_SS);
mem_cpy(dst, &cache[i].data, FF_MAX_SS);
}
leaveCriticalSection(oldIME);
return true;
Expand Down
21 changes: 15 additions & 6 deletions libslim/source/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef __SLIM_CACHE_H__
#define __SLIM_CACHE_H__
#include "ff.h"
#include <assert.h>
#include <limits.h>

/**
* This option defines how the cache will be implemented
Expand All @@ -42,14 +44,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* This option defines the default cache size in number of sectors
*/
#define SLIM_CACHE_SIZE 64
#define SLIM_CACHE_SIZE 256

/**
* This option defines whether or not to use DMA to store sectors to the cache
*
* 0 - Uses a CPU memcpy to store sectors
* 1 - Uses DMA to store sectors
* 2 - Uses NDMA to store sectors, on DSi, using CPU memcpy otherwise.
*
* Do not use options 1 or 2. They are experimental and may cause SD card corruption.
*/
#define SLIM_CACHE_STORE_CPY 0

Expand All @@ -70,15 +74,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* 0 - Single sector reads read exactly one sector on a single sector read
* > 1 - Single sector reads trigger a prefetch of SLIM_PREFETCH_AMOUNT extra sectors into the cache
*/
#define SLIM_PREFETCH_AMOUNT 0
#define SLIM_PREFETCH_AMOUNT 7

/**
* This configures the max number of sectors fetched from the SD card per chunk.
* If this is 0, then defaults to (sizeof(BITMAP_PRIMITIVE)
*
* Must be 1 < SLIM_SECTORS_PER_CHUNK <= (sizeof(BITMAP_PRIMITIVE) * CHAR_BIT)
*/
#define SLIM_SECTORS_PER_CHUNK 0
#define SLIM_SECTORS_PER_CHUNK 8

/**
* **YOU SHOULD NOT NEED TO CHANGE THIS OPTION**
Expand All @@ -87,21 +91,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Changes the size of the chunk used.
*/
#define BITMAP_PRIMITIVE BYTE
#define BITMAP_PRIMITIVE_SIZE 1

static_assert(BITMAP_PRIMITIVE_SIZE == sizeof(BITMAP_PRIMITIVE), "Invalid Primitive Size");

#define MAX_SECTORS_PER_CHUNK (BITMAP_PRIMITIVE_SIZE * CHAR_BIT)

#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))


#if !SLIM_SECTORS_PER_CHUNK
#define SECTORS_PER_CHUNK MAX_SECTORS_PER_CHUNK
#else
#define SECTORS_PER_CHUNK MAX(1, MIN(SLIM_SECTORS_PER_CHUNK, MAX_SECTORS_PER_CHUNK))
#endif

#if SLIM_CHUNKED_READS && (SECTORS_PER_CHUNK < SLIM_PREFETCH_AMOUNT)
#error "Not enough scratch space will be allocated to support the specified prefetch amount."
#if SLIM_CHUNKED_READS
static_assert(SECTORS_PER_CHUNK > SLIM_PREFETCH_AMOUNT, "Not enough scratch space will be allocated to support the specified prefetch amount.");
#endif

#define MAX_SECTORS_PER_CHUNK (sizeof(BITMAP_PRIMITIVE) * CHAR_BIT)

#if SLIM_USE_CACHE && FF_MAX_SS != FF_MIN_SS
#error "Cache can only be used for fixed sector size."
Expand Down
4 changes: 4 additions & 0 deletions libslim/source/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <stdlib.h>

#include <nds/bios.h>
#include <nds/disc_io.h>
#include <nds/arm9/cache.h>
#include <nds/interrupts.h>
Expand Down Expand Up @@ -170,6 +171,7 @@ static inline DRESULT disk_read_internal(
if ((disc_io = get_disc_io(drv)) != NULL)
{
DRESULT res = disc_io->readSectors(sector, count, buff) ? RES_OK : RES_ERROR;
swiDelay(256);
return res;
}
return RES_PARERR;
Expand Down Expand Up @@ -373,6 +375,8 @@ DRESULT disk_write(
if ((disc_io = get_disc_io(drv)) != NULL)
{
DRESULT res = disc_io->writeSectors(sector, count, buff) ? RES_OK : RES_ERROR;
swiDelay(256);

#if SLIM_USE_CACHE
for (BYTE i = 0; i < count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion libslim/source/memcopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string.h>
#include <tonccpy.h>

#define MEMCOPY(dst, src, sz) memcpy(dst, src, sz)
#define MEMCOPY(dst, src, sz) tonccpy(dst, src, sz)
#define MEMSET(dst, val, sz) memset(dst, val, sz)
#define MEMCLR(dst, sz) MEMSET(dst, 0, sz)

Expand Down

0 comments on commit 4d1b958

Please sign in to comment.