Created
November 24, 2012 07:15
-
-
Save unknownbrackets/4138761 to your computer and use it in GitHub Desktop.
PSP scheduling/priority tests
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
#include <common.h> | |
#include <pspsdk.h> | |
#include <pspkernel.h> | |
#include <pspdisplay.h> | |
#include <pspthreadman.h> | |
#include <psploadexec.h> | |
SceUID threads[4]; | |
volatile int thread_time[4]; | |
int thread_num[4]; | |
int spinThread(SceSize args, void *argp) { | |
int n = *(int*) argp; | |
while (1) { | |
thread_time[n]++; | |
sceKernelDelayThread(1); | |
} | |
return 0; | |
} | |
int rotateThread(SceSize args, void *argp) { | |
int n = *(int*) argp; | |
while (1) { | |
thread_time[n]++; | |
sceKernelRotateThreadReadyQueue(0x77); | |
} | |
return 0; | |
} | |
int initSpentTest(const char *name, void *func, int pri[4]) { | |
int n; | |
char buf[96]; | |
for (n = 0; n < 4; n++) { | |
thread_num[n] = n; | |
thread_time[n] = 0; | |
sprintf(buf, "threadFunc%d", n); | |
threads[n] = sceKernelCreateThread(buf, func, pri[n], 0x1000, 0, NULL); | |
if (threads[n] > 0) | |
sceKernelStartThread(threads[n], sizeof(n), &n); | |
else | |
{ | |
printf("%s fail: %08x (#%d)\n", name, threads[n], n); | |
return 0; | |
} | |
} | |
return 1; | |
} | |
void reportSpentTest(const char *name) { | |
printf("%s spent: ", name); | |
int n; | |
for (n = 0; n < 4; n++) { | |
sceKernelTerminateThread(threads[n]); | |
sceKernelDeleteThread(threads[n]); | |
printf("%d:%d ", n, thread_time[n]); | |
} | |
printf("\n"); | |
} | |
void testTimeSpent(const char *name, void *func, int p1, int p2, int p3, int p4) { | |
int pri[4]; | |
pri[0] = p1; | |
pri[1] = p2; | |
pri[2] = p3; | |
pri[3] = p4; | |
if (!initSpentTest(name, func, pri)) | |
return; | |
sceKernelDelayThread(250000); | |
reportSpentTest(name); | |
} | |
void testMutate(const char *name, void *func, int p1, int p2, int p3, int p4, int inc) { | |
int pri[4]; | |
pri[0] = p1; | |
pri[1] = p2; | |
pri[2] = p3; | |
pri[3] = p4; | |
if (!initSpentTest(name, func, pri)) | |
return; | |
int times = 250000 / 250; | |
int n; | |
while (--times > 0) { | |
pri[0] += inc; | |
if (pri[0] > 0x77) | |
pri[0] = 0x77; | |
else if (pri[0] < 0x08) | |
pri[0] = 0x08; | |
for (n = 0; n < 250; ++n) { | |
sceKernelChangeThreadPriority(threads[0], pri[0]); | |
sceKernelRotateThreadReadyQueue(0x77); | |
} | |
} | |
reportSpentTest(name); | |
} | |
void testRotate(const char *name, void *func, int p1, int p2, int p3, int p4, int rotp) { | |
int pri[4]; | |
pri[0] = p1; | |
pri[1] = p2; | |
pri[2] = p3; | |
pri[3] = p4; | |
if (!initSpentTest(name, func, pri)) | |
return; | |
int times = 250000; | |
while (--times > 0) { | |
sceKernelRotateThreadReadyQueue(rotp); | |
} | |
reportSpentTest(name); | |
} | |
void testSimpleScheduling(void *spinThread) { | |
testTimeSpent("Same priority", spinThread, 0x12, 0x12, 0x12, 0x12); | |
testTimeSpent("One high", spinThread, 0x13, 0x12, 0x12, 0x12); | |
testTimeSpent("One higher", spinThread, 0x77, 0x12, 0x12, 0x12); | |
testTimeSpent("One ultra high", spinThread, 0x78, 0x12, 0x12, 0x12); | |
testTimeSpent("All higher", spinThread, 0x77, 0x77, 0x77, 0x77); | |
testTimeSpent("One low", spinThread, 0x11, 0x12, 0x12, 0x12); | |
testTimeSpent("One lower", spinThread, 0x08, 0x12, 0x12, 0x12); | |
testTimeSpent("One ultra low", spinThread, 0x01, 0x12, 0x12, 0x12); | |
testTimeSpent("All lower", spinThread, 0x08, 0x08, 0x08, 0x08); | |
testTimeSpent("Sequential", spinThread, 0x15, 0x14, 0x13, 0x12); | |
testTimeSpent("Very sequential", spinThread, 0x50, 0x40, 0x30, 0x20); | |
testTimeSpent("Reverse sequential", spinThread, 0x12, 0x13, 0x14, 0x15); | |
testTimeSpent("Reverse very sequential", spinThread, 0x20, 0x30, 0x40, 0x50); | |
} | |
void testMutateScheduling(void *spinThread) { | |
testMutate("Same priority", spinThread, 0x12, 0x12, 0x12, 0x12, 0); | |
testMutate("One high", spinThread, 0x13, 0x12, 0x12, 0x12, 0); | |
testMutate("One higher", spinThread, 0x77, 0x12, 0x12, 0x12, 0); | |
testMutate("Incrementing same", spinThread, 0x12, 0x12, 0x12, 0x12, 1); | |
testMutate("Incrementing higher", spinThread, 0x20, 0x12, 0x12, 0x12, 1); | |
testMutate("Decrementing higher", spinThread, 0x20, 0x12, 0x12, 0x12, -1); | |
} | |
void testRotateScheduling(void *spinThread) { | |
testRotate("Same priority", spinThread, 0x12, 0x12, 0x12, 0x12, 0x12); | |
testRotate("One high rotate same", spinThread, 0x13, 0x12, 0x12, 0x12, 0x12); | |
testRotate("One high rotate high", spinThread, 0x13, 0x12, 0x12, 0x12, 0x13); | |
testRotate("One higher rotate same", spinThread, 0x77, 0x12, 0x12, 0x12, 0x12); | |
testRotate("One higher rotate high", spinThread, 0x77, 0x12, 0x12, 0x12, 0x15); | |
testRotate("One higher rotate higher", spinThread, 0x72, 0x12, 0x12, 0x12, 0x72); | |
testRotate("Same rotate higher", spinThread, 0x12, 0x12, 0x12, 0x12, 0x20); | |
testRotate("Higher rotate higher", spinThread, 0x20, 0x12, 0x12, 0x12, 0x20); | |
testRotate("Lower rotate lower", spinThread, 0x08, 0x12, 0x12, 0x12, 0x08); | |
testRotate("One higher rotate 0", spinThread, 0x77, 0x12, 0x12, 0x12, 0); | |
testRotate("One higher rotate -1", spinThread, 0x77, 0x12, 0x12, 0x12, -1); | |
testRotate("Rotate low", spinThread, 0x77, 0x77, 0x12, 0x12, 0x12); | |
testRotate("Rotate high", spinThread, 0x77, 0x77, 0x12, 0x12, 0x77); | |
} | |
int main(int argc, char **argv) { | |
testSimpleScheduling(spinThread); | |
testMutateScheduling(spinThread); | |
testRotateScheduling(spinThread); | |
// Doesn't work. | |
//testSimpleScheduling(rotateThread); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment