I saw that the memory stick access is pretty unefficient when using fread(3).
From what I can see this is because BUFSIZ is set to 1024 in the psptoolchain, and it could be improved to up to 8x.
How about using a BUFSIZ value like 65k to (dramatically) improve Memory Stick perfs?
I did the following tests with read(2):
Code: Select all
test_bufsiz= 512 - read(2): 31493ms (22048501B, 700.11B/s)
test_bufsiz= 1024 - read(2): 16443ms (22048501B, 1340.91B/s)
test_bufsiz= 2048 - read(2): 8964ms (22048501B, 2459.67B/s)
test_bufsiz= 4096 - read(2): 5457ms (22048501B, 4040.41B/s)
test_bufsiz= 8192 - read(2): 3703ms (22048501B, 5954.23B/s)
test_bufsiz= 16384 - read(2): 2842ms (22048501B, 7758.09B/s)
test_bufsiz= 32768 - read(2): 2391ms (22048501B, 9221.46B/s)
test_bufsiz= 65536 - read(2): 2162ms (22048501B, 10198.20B/s)
test_bufsiz= 131072 - read(2): 2126ms (22048501B, 10370.88B/s)
test_bufsiz= 262144 - read(2): 2113ms (22048501B, 10434.69B/s)
test_bufsiz= 524288 - read(2): 2104ms (22048501B, 10479.33B/s)
test_bufsiz= 1048576 - read(2): 2099ms (22048501B, 10504.29B/s)
test_bufsiz= 2097152 - read(2): 2097ms (22048501B, 10514.31B/s)
test_bufsiz= 4194304 - read(2): 2096ms (22048501B, 10519.32B/s)
test_bufsiz= 8388608 - read(2): 2094ms (22048501B, 10529.37B/s)
test_bufsiz=16777216 - read(2): 2095ms (22048501B, 10524.34B/s)
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <SDL/SDL.h>
#include <pspmoduleinfo.h>
PSP_HEAP_SIZE_MAX();
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
Uint32 start;
printf("I/O perf test\n");
int i;
for (i = 9; i <= 24; i++)
{
int test_bufsiz = 1<<i;
char* buf = malloc(test_bufsiz);
if (buf == NULL) printf("out of memory\n"), exit(0);
printf("test_bufsiz=%8d -", test_bufsiz);
start = SDL_GetTicks();
int nb_read = 0;
int total = 0;
int din = open("ms0:/340.PBP", 0);
while ((nb_read = read(din, buf, test_bufsiz)) > 0) total += nb_read;
int t = SDL_GetTicks() - start;
printf(" read(2): %5dms (%8dB, %.2fB/s)", t, total, 1.0*total/t);
close(din);
printf("\n");
free(buf);
}
SDL_Quit();
return 0;
}
Code: Select all
test_bufsiz= 512 - fread(3): 28748ms (22048256B, 766.95B/s)
test_bufsiz= 1024 - fread(3): 28704ms (22047744B, 768.11B/s)
test_bufsiz= 2048 - fread(3): 28348ms (22046720B, 777.72B/s)
test_bufsiz= 4096 - fread(3): 28681ms (22044672B, 768.62B/s)
test_bufsiz= 8192 - fread(3): 28712ms (22044672B, 767.79B/s)
test_bufsiz= 16384 - fread(3): 28376ms (22036480B, 776.59B/s)
test_bufsiz= 32768 - fread(3): 28742ms (22020096B, 766.13B/s)
test_bufsiz= 65536 - fread(3): 28725ms (22020096B, 766.58B/s)
test_bufsiz= 131072 - fread(3): 28379ms (22020096B, 775.93B/s)
test_bufsiz= 262144 - fread(3): 28741ms (22020096B, 766.16B/s)
test_bufsiz= 524288 - fread(3): 28722ms (22020096B, 766.66B/s)
test_bufsiz= 1048576 - fread(3): 28372ms (22020096B, 776.12B/s)
test_bufsiz= 2097152 - fread(3): 28735ms (20971520B, 729.82B/s)
test_bufsiz= 4194304 - fread(3): 28726ms (20971520B, 730.05B/s)
test_bufsiz= 8388608 - fread(3): 28367ms (16777216B, 591.43B/s)
test_bufsiz=16777216 - fread(3): 28725ms (16777216B, 584.06B/s)
Source code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <SDL/SDL.h>
#include <pspmoduleinfo.h>
PSP_HEAP_SIZE_MAX();
int main()
{
SDL_Init(SDL_INIT_EVERYTHING);
Uint32 start;
printf("I/O perf test\n");
int i;
for (i = 9; i <= 24; i++)
{
int test_bufsiz = 1<<i;
char* buf = malloc(test_bufsiz);
if (buf == NULL) printf("out of memory\n"), exit(0);
printf("test_bufsiz=%8d -", test_bufsiz);
start = SDL_GetTicks();
int total2 = 0;
FILE* fin = fopen("ms0:/340.PBP", "rb");
while (fread(buf, test_bufsiz, 1, fin)) total2 += test_bufsiz;
int t = SDL_GetTicks() - start;
printf(" fread(3): %5dms (%8dB, %.2fB/s)", t, total2, 1.0*total2/t);
fclose(fin);
printf("\n");
free(buf);
}
SDL_Quit();
return 0;
}