When I break the code into two threads it runs much slower.
Please let me know if there is any specific tuning I should look into.
Do I need -DREENTRANT?
I am using the default pspsdk Makefile template.
There is no need for mutual exclusion in this code.
since the main thread only reads the data
and the loader thread only writes the data.
they are protected by the poor mans semaphore.
(an atomic pointer assignment)
Is there a better way to force the thread to relese the CPU then sceKernelDelayThread(100000);
I think I use the VFPU in the main thread which takes advantage of
pspgl, but the loader thread only performs IO
the following code is tested and runs correctly on the PSP.
Please point me in the right direction.
Code: Select all
int ChartsInit()
{
fprintf(stderr, "sizeof Tile: %d\n", sizeof(Tile));
#ifdef __psp__
//#define SINGLETHREAD
#ifndef SINGLETHREAD
int thid = 0;
thid = sceKernelCreateThread("tile_load", ChartLoaderThread,
0x18, 0xFA0, 0, 0);
if (thid >= 0)
sceKernelStartThread(thid, 0, 0);
#endif
#else
pthread_t thrd;
pthread_create(&thrd, NULL, ChartLoaderThread, NULL);
#endif
return(1);
}
I have what I think is a relatively low priority.
Code: Select all
void *ChartLoaderThread(void *dummy)
{
Tile *t;
int i;
unsigned char *tmpBits;
#ifndef SINGLETHREAD
while (1)
{
printf("+");
#ifdef __psp__
sceKernelDelayThread(100000);
#else
usleep(100000);
#endif
if (p.vfrSectionals == 0)
continue;
#endif
// load
for (i=0; i<numTiles; i++)
{
int c;
t = &tiles[i];k
// this function opens a file from the flash drive and reads the
// pre-compiled texture
if (t->visible) && (t->bits == NULL))
LoadBits(t);
}
#ifndef SINGLETHREAD
}
#endif
}
running the thread causes the main thread to slow to a crawl
If I run single threaded and call this function in the main() it
executes correctly just a little too slow for my needs.
the dynamic memory is very regimented and controlled.
no memory leak on other platforms.
I was hoping to perform the file management in the background.
I figured file IO would release the CPU and switch to the main thread when waiting for the flash to respond.
I was expecting a significant increase in performance even with a single CPU
this same code runs well on my ipod and did yield the expected performance gain.
Each tile is about 769 Kbytes
Currently I am limiting it to one tile at a time for debugging purposes.
here is the file IO function
Code: Select all
{
FILE *fptr;
int ret;
unsigned char *tmpBits;
/* open cache file */
printf("load bits for %s\n", t->filename);
fptr = fopen(t->filename, "r");
if (fptr == NULL)
{
printf("could not open %s\n", t->filename);
//unlink(t->filename);
return;
}
printf("opened file\n");
/* skip the tile structure - fix me with long word apadded fields */
//fseek(fptr, sizeof(Tile), SEEK_SET);
fseek(fptr, 296, SEEK_SET);
printf("skipped header\n");
/* allocate memory for pixmap */
tmpBits = malloc(3*C_TILE_X*C_TILE_Y);
if (tmpBits == NULL)
{
fprintf(stderr, "could not allocate pixmap for cached tile\n");
fclose(fptr);
return;
}
printf("allocated pixmap for cached tile\n");
/* read the pixmap */
ret = fread(tmpBits, 1, 3*C_TILE_X*C_TILE_Y, fptr);
if (ret != 3*C_TILE_X*C_TILE_Y)
{
fprintf(stderr, "could not read cache tile\n");
fclose(fptr);
unlink(t->filename);
free(tmpBits);
t->bits = NULL;
return;
}
printf("read pixmap for cached tile\n");
t->bits = tmpBits;
fclose(fptr);
}