/* Time to wait for workers to get preempted (seconds) */ #define PREEMPT_TIME 20 /* *FactorbywhichtomultiplynumberofonlineCPUsfortotalnumberof *workerthreads
*/ #define THREAD_FACTOR 8
externlong preempt_vsx(vector int *varray, int *threads_starting, int *running);
long vsx_memcmp(vector int *a) {
vector int zero = {0, 0, 0, 0}; int i;
FAIL_IF(a != varray);
for(i = 0; i < 12; i++) { if (memcmp(&a[i + 12], &zero, sizeof(vector int)) == 0) {
fprintf(stderr, "Detected zero from the VSX reg %d\n", i + 12); return2;
}
}
if (memcmp(a, &a[12], 12 * sizeof(vector int))) { long *p = (long *)a;
fprintf(stderr, "VSX mismatch\n"); for (i = 0; i < 24; i=i+2)
fprintf(stderr, "%d: 0x%08lx%08lx | 0x%08lx%08lx\n",
i/2 + i%2 + 20, p[i], p[i + 1], p[i + 24], p[i + 25]); return1;
} return0;
}
void *preempt_vsx_c(void *p)
{ int i, j; long rc;
srand(pthread_self()); for (i = 0; i < 12; i++) for (j = 0; j < 4; j++) {
varray[i][j] = rand(); /* Don't want zero because it hides kernel problems */ if (varray[i][j] == 0)
j--;
}
rc = preempt_vsx(varray, &threads_starting, &running); if (rc == 2)
fprintf(stderr, "Caught zeros in VSX compares\n"); return (void *)rc;
}
int test_preempt_vsx(void)
{ int i, rc, threads;
pthread_t *tids;
running = true;
threads_starting = threads; for (i = 0; i < threads; i++) {
rc = pthread_create(&tids[i], NULL, preempt_vsx_c, NULL);
FAIL_IF(rc);
}
setbuf(stdout, NULL); /* Not really nessesary but nice to wait for every thread to start */
printf("\tWaiting for %d workers to start...", threads_starting); while(threads_starting) asmvolatile("": : :"memory");
printf("done\n");
printf("\tWaiting for %d seconds to let some workers get preempted...", PREEMPT_TIME);
sleep(PREEMPT_TIME);
printf("done\n");
printf("\tStopping workers..."); /* *Workingarecheckingthisvalueeveryloop.Inpreempt_vsx'cmpwir5,0;bne2b'. *r5willhaveloadedthevalueofrunning.
*/
running = 0; for (i = 0; i < threads; i++) { void *rc_p;
pthread_join(tids[i], &rc_p);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.