#include #include #include #include #include #include #include #include #include #include #include #include #include #define __NR_spe_run 278 #define __NR_spe_create 279 #define LS_SIZE 0x40000 #define SPENODE "/spu/stoplooptest" #define MFTB(RA) __asm__ volatile("mftb %0":"=r"(RA)) long long do_test(void) { int spefd = -1, lsfd = -1; int npc, status; long long ret = -1; char buf[LS_SIZE]; int n; uint32_t t1, t2; /* create context */ spefd = syscall(__NR_spe_create, SPENODE, 0, S_IRUSR | S_IWUSR | S_IXUSR); if (spefd < 0) goto out; /* run once to assign physical spe */ npc = 0; syscall(__NR_spe_run, spefd, &npc, &status); /* get /mem file descriptor */ lsfd = open(SPENODE "/mem", O_RDWR, S_IRUSR | S_IWUSR); if (lsfd < 0) goto out; /* make sure main memory is allocated and writable for 'buf' */ memset(buf, 0, sizeof buf); /* write mem */ MFTB(t1); if (write(lsfd, buf, LS_SIZE) != LS_SIZE) { goto out; } MFTB(t2); ret = t2 - t1; out: if ( lsfd >= 0 ) close(lsfd); if ( spefd >= 0 ) close(spefd); return ret; } int main(int argc, char *argv[]) { long long r; r = do_test(); printf("%lld\n", r); return 0; }