void main (int argc, char **argv) { pid_t pid; uint pte; #define SIZE (1024*1024) char buf[SIZE]; pid = fork(); //==================== SERVER ====================// if (pid == 0) { ipc_register(IPC_USER, dispatch); envid = sys_geteid(); sleep(5); return; } //==================== CLIENT ====================// envid = pid2envid(pid); yield(envid); // The "shared" memory used to communicate with the server shared_state = (arg_t *) malloc (sizeof(arg_t)); if (shared_state == NULL) { printf ("[CLIENT] Couldn't allocate shared_state memory\n"); exit(-1); } shared_state->nbytes = 12345; // touch the memory // Figure out the pte corresponding to the "shared" memory pte = sys_read_pte ((uint) shared_state, 0, sys_geteid()); if (pte == 0) { printf ("[CLIENT] Found null pte\n"); exit (-1); } // Now start the operations S_INIT(pte); { int i, t=0, rounds=atoi(argv[1]); for (i=0 ; i < rounds ; i++) { pctrval t0 = rdtsc(); S_EMPTY(0); t += (rdtsc() - t0); bzero ((void *)buf, SIZE); } printf ("%d\t%d\n", rounds, (unsigned int) t/200); } }
int ae_eth_sendv(struct ae_recv *outgoing, int netcardno) { int ret = 0; int sz, i; char filler[ETHER_MIN_LEN]; volatile uint pending = 1; assert (netcardno < XOKNET_MAXNETS); /* make sure size is >= ETHER_MIN_LEN */ for (sz = 0, i = 0; i < outgoing->n; i++) { sz += outgoing->r[i].sz; } if (sz < ETHER_MIN_LEN) { outgoing->r[outgoing->n].sz = ETHER_MIN_LEN - sz; outgoing->r[outgoing->n].data = &filler[0]; outgoing->n++; } ret = sys_net_xmit (netcardno, outgoing, (uint *) &pending, 1); assert ((ret == 0) || (ret == -1)); while ((ret == 0) && pending > 0) { sys_geteid(); asm volatile ("" : : : "memory"); } return (ret); }
int ae_eth_send(void *d, int sz, int netcardno) { int ret = 0; volatile uint pending = 1; char filler[ETHER_MIN_LEN]; struct ae_recv recv; recv.r[0].data = d; recv.r[0].sz = sz; recv.n = 1; assert (netcardno < XOKNET_MAXNETS); if (sz < ETHER_MIN_LEN) { recv.r[1].data = filler; recv.r[1].sz = ETHER_MIN_LEN - sz; recv.n = 2; } ret = sys_net_xmit (netcardno, &recv, (uint *) &pending, 1); assert ((ret == 0) || (ret == -1)); while ((ret == 0) && (pending > 0)) { sys_geteid(); asm volatile ("" : : : "memory"); } return (ret); }
void __start () { char xstack[2048]; /* No reason for this to be in a function, except that gcc seems to * require it. */ DEF_SYM (UAREA, UADDR); DEF_SYM (__u_xesp, &UAREA.u_xsp); DEF_SYM (__u_ppc, &UAREA.u_ppc); DEF_SYM (__u_donate, &UAREA.u_donate); DEF_SYM (__u_in_critical, &UAREA.u_in_critical); DEF_SYM (__u_interrupted, &UAREA.u_interrupted); DEF_SYM (__envs, UENVS); DEF_SYM (__ppages, UPPAGES); DEF_SYM (__sysinfo, SYSINFO); DEF_SYM (__si_system_ticks, &__sysinfo.si_system_ticks); DEF_SYM (__bc, UBC); DEF_SYM (__xr, UXN); DEF_SYM (__xn_free_map, UXNMAP); DEF_SYM (vpt, UVPT); #define SRL(val, shamt) (((val) >> (shamt)) & ~(-1 << (32 - (shamt)))) DEF_SYM (vpd, UVPT + SRL(UVPT, 10)); UAREA.u_xsp = (u_int) xstack + sizeof (xstack); UAREA.u_entipc1 = UAREA.u_entipc2 = 0; UAREA.u_entfault = (u_int) xue_fault; UAREA.u_entprologue = (u_int) xue_prologue; UAREA.u_entepilogue = (u_int) xue_epilogue; UAREA.u_fpu = 0; UAREA.pid = sys_geteid(); __brkpt = ((u_int) &end + PGMASK) & ~PGMASK; /* UAREA.u_ppc is inited to 0 in parent so if it is none zero it means that the quantum expired since the beginning of the program and we need to yield before our slice gets yanked */ if (UAREA.u_ppc) yield(-1); pw_init (); /* and off we go */ main (); __exit(); start_text_addr = __start; }