int main(int argc, char** argv) { uint32_t vcoreid = vcore_id(); int retval = 0; mcs_barrier_init(&b, max_vcores()); /* begin: stuff userspace needs to do before switching to multi-mode */ vcore_lib_init(); #if 0 /* tell the kernel where and how we want to receive notifications */ struct notif_method *nm; for (int i = 0; i < MAX_NR_NOTIF; i++) { nm = &__procdata.notif_methods[i]; nm->flags |= NOTIF_WANTED | NOTIF_MSG | NOTIF_IPI; nm->vcoreid = i % 2; // vcore0 or 1, keepin' it fresh. } #endif /* Need to save this somewhere that you can find it again when restarting * core0 */ core0_tls = get_tls_desc(0); /* Need to save our floating point state somewhere (like in the * user_thread_tcb so it can be restarted too */ /* end: stuff userspace needs to do before switching to multi-mode */ /* get into multi mode */ retval = vcore_request(1); if (retval) printf("F****d!\n"); printf("Proc %d requesting another vcore\n", getpid()); begin = read_tsc(); retval = vcore_request(1); if (retval) printf("F****d!\n"); while (!core1_up) cpu_relax; end = read_tsc(); printf("Took %llu usec (%llu nsec) to receive 1 core (cold).\n", udiff(begin, end), ndiff(begin, end)); printf("[T]:002:%llu:%llu:1:C.\n", udiff(begin, end), ndiff(begin, end)); core1_up = FALSE; udelay(2000000); printf("Proc %d requesting the vcore again\n", getpid()); begin = read_tsc(); retval = vcore_request(1); if (retval) printf("F****d!\n"); while (!core1_up) cpu_relax(); end = read_tsc(); printf("Took %llu usec (%llu nsec) to receive 1 core (warm).\n", udiff(begin, end), ndiff(begin, end)); printf("[T]:002:%llu:%llu:1:W.\n", udiff(begin, end), ndiff(begin, end)); return 0; }
/* Test program for the audio device. mmap()s the stuff, sets up a notif * handler, and switches to multi_mode. * * Note: this has a lot of mhello-like MCP infrastructure. When Lithe is * working, you won't need any of this. Just the mmap stuff and the notif * handler. Stuff specific to the ethernet audio device is marked ETH_AUD. */ int main() { int retval; int in_fd, out_fd; /* ETHAUD mmap the input and output buffers */ in_fd = open("/dev/eth_audio_in", O_RDONLY); out_fd = open("/dev/eth_audio_out", O_RDWR); assert(in_fd != -1); assert(out_fd != -1); in_buf = mmap(0, PGSIZE, PROT_READ, 0, in_fd, 0); if (in_buf == MAP_FAILED) { int err = errno; perror("Can't mmap the input buf:"); } out_buf = mmap(0, PGSIZE, PROT_READ | PROT_WRITE, MAP_POPULATE, out_fd, 0); if (out_buf == MAP_FAILED) { int err = errno; perror("Can't mmap the output buf:"); } //strncpy(out_buf, "Nanwan loves you!\n", 19); /* begin: stuff userspace needs to do before switching to multi-mode */ vcore_lib_init(); /* ETHAUD Turn on Free apple pie (which is the network packet) */ enable_kevent(EV_FREE_APPLE_PIE, 0, EVENT_IPI); /* Need to save this somewhere that you can find it again when restarting * core0 */ core0_tls = get_tls_desc(0); /* Need to save our floating point state somewhere (like in the * user_thread_tcb so it can be restarted too */ /* end: stuff userspace needs to do before switching to multi-mode */ /* ETHAUD */ /* Switch into _M mode */ retval = vcore_request(1); /* Stay alive for a minute (will take interrupts) */ udelay(60000000); printf("Eth aud, finishing up!\n"); /* Need to do unmap it, due to some limitations in the kernel */ munmap(in_buf, PGSIZE); munmap(out_buf, PGSIZE); close(in_fd); close(out_fd); }
int main(int argc, char** argv) { uint32_t vcoreid; vcore_lib_init(); if ((vcoreid = vcore_id())) { printf("Should never see me! (from vcore %d)\n", vcoreid); } else { // core 0 printf("Hello from else vcore 0\n"); printf("Multi-Goodbye, world, from PID: %d!\n", getpid()); switch (test) { case TEST_MMAP: printf("Testing MMAP\n"); void *addr; addr = sys_mmap((void*)USTACKTOP - 20*PGSIZE, 8*PGSIZE, 3, MAP_FIXED | MAP_ANONYMOUS, -1, 0); printf("got addr = 0x%08x\n", addr); *(int*)addr = 0xdeadbeef; *(int*)(addr + 3*PGSIZE) = 0xcafebabe; // these should work printf("reading addr: 0x%08x\n", *(int*)addr); printf("reading addr+3pg: 0x%08x\n", *(int*)(addr + 3*PGSIZE)); // this should fault printf("Should page fault and die now.\n"); *(int*)(addr - 3*PGSIZE) = 0xdeadbeef; printf("Should not see me!!!!!!!!!!!!!!!!!!\n"); while(1); case TEST_ONE_CORE: vcore_request_more(1); printf("One core test's core0 is done\n"); printf("Check to see it's on a worker core.\n"); while(1); case TEST_ASK_FOR_TOO_MANY_CORES: vcore_request_more(12); printf("Asked for too many is done\n"); return 0; case TEST_INCREMENTAL_CHANGES: vcore_request_more(4); break; default: vcore_request_more(5); } printf("Should see me if you want to relocate core0's context " "when moving from RUNNING_S\n"); } // vcore0 only below here switch (test) { case TEST_YIELD_OUT_OF_ORDER: udelay(10000000); printf("Core 2 should have yielded, asking for another\n"); vcore_request_more(5); break; case TEST_YIELD_0_OUT_OF_ORDER: udelay(5000000); printf("Core %d yielding\n", vcoreid); sys_yield(0); printf("Core 0 came back where it left off in RUNNING_M!!!\n"); break; } global_tests(vcoreid); printf("Vcore %d Done!\n", vcoreid); while (1); return 0; }