src/sys/mm/rmem/main.c
/**
 * @brief Handles remote memory requests.
 *
 * @returns Upon successful completion zero is returned. Upon failure,
 * a negative error code is returned instead.
 */
@brief Handles remote memory requests.
@returns Upon successful completion zero is returned. Upon failure,
a negative error code is returned instead.
@brief Handles remote memory requests . @returns Upon successful completion zero is returned . Upon failure a negative error code is returned instead .
static int do_rmem_loop(void)
{
	int shutdown = 0;
	uint64_t t0, t1;
	kclock(&stats.tstart);
	while(!shutdown)
	{
		int source;
		struct rmem_message msg;
		uassert(
			kmailbox_read(
				inbox,
				&msg,
				sizeof(struct rmem_message)
			) == sizeof(struct rmem_message)
		);
		rmem_debug("rmem request source=%d opcode=%d",
			msg.header.source,
			msg.header.opcode
		);
		switch (msg.header.opcode)
		{
			case RMEM_WRITE:
				stats.nwrites++;
				kclock(&t0);
					msg.errcode = do_rmem_write(msg.header.source, msg.blknum);
					uassert((source = kmailbox_open(msg.header.source)) >= 0);
					uassert(kmailbox_write(source, &msg, sizeof(struct rmem_message)) == sizeof(struct rmem_message));
					uassert(kmailbox_close(source) == 0);
				kclock(&t1);
				stats.twrite += (t1 - t0);
				break;
			case RMEM_READ:
				stats.nreads++;
				kclock(&t0);
					uassert((source = kmailbox_open(msg.header.source)) >= 0);
					msg.errcode = do_rmem_read(msg.header.source, msg.blknum, source, msg.header.port);
					uassert(kmailbox_write(source, &msg, sizeof(struct rmem_message)) == sizeof(struct rmem_message));
					uassert(kmailbox_close(source) == 0);
				kclock(&t1);
				stats.tread += (t1 - t0);
				break;
			case RMEM_ALLOC:
				stats.nallocs++;
				kclock(&t0);
					msg.blknum = do_rmem_alloc();
					msg.errcode = (msg.blknum == RMEM_NULL) ? -ENOMEM : 0;
					uassert((source = kmailbox_open(msg.header.source)) >= 0);
					uassert(kmailbox_write(source, &msg, sizeof(struct rmem_message)) == sizeof(struct rmem_message));
					uassert(kmailbox_close(source) == 0);
				kclock(&t1);
				stats.talloc += (t1 - t0);
			    break;
			case RMEM_MEMFREE:
				stats.nfrees++;
				kclock(&t0);
					msg.errcode = do_rmem_free(msg.blknum);
					uassert((source = kmailbox_open(msg.header.source)) >= 0);
					uassert(kmailbox_write(source, &msg, sizeof(struct rmem_message)) == sizeof(struct rmem_message));
					uassert(kmailbox_close(source) == 0);
				kclock(&t1);
				stats.tfree += (t1 - t0);
			    break;
			case RMEM_EXIT:
				kclock(&stats.tshutdown);
				shutdown = 1;
				break;
			default:
				break;
		}
	}
	uprintf("[nanvix][rmem] talloc=%d nallocs=%d tfree=%d nfrees=%d tread=%d nreads=%d twrite=%d nwrites=%d",
			stats.talloc, stats.nallocs,
			stats.tfree, stats.nfrees,
			stats.tread, stats.nreads,
			stats.twrite, stats.nwrites
	);
	return (0);
}
static int do_rmem_loop ( void ) { int shutdown = 0 ; uint64_t t0 , t1 ; kclock ( & stats . tstart ) ; while ( ! shutdown ) { int source ; struct rmem_message msg ; uassert ( kmailbox_read ( inbox , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; rmem_debug ( " " , msg . header . source , msg . header . opcode ) ; switch ( msg . header . opcode ) { case RMEM_WRITE : stats . nwrites ++ ; kclock ( & t0 ) ; msg . errcode = do_rmem_write ( msg . header . source , msg . blknum ) ; uassert ( ( source = kmailbox_open ( msg . header . source ) ) >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; kclock ( & t1 ) ; stats . twrite += ( t1 - t0 ) ; break ; case RMEM_READ : stats . nreads ++ ; kclock ( & t0 ) ; uassert ( ( source = kmailbox_open ( msg . header . source ) ) >= 0 ) ; msg . errcode = do_rmem_read ( msg . header . source , msg . blknum , source , msg . header . port ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; kclock ( & t1 ) ; stats . tread += ( t1 - t0 ) ; break ; case RMEM_ALLOC : stats . nallocs ++ ; kclock ( & t0 ) ; msg . blknum = do_rmem_alloc ( ) ; msg . errcode = ( msg . blknum == RMEM_NULL ) ? - ENOMEM : 0 ; uassert ( ( source = kmailbox_open ( msg . header . source ) ) >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; kclock ( & t1 ) ; stats . talloc += ( t1 - t0 ) ; break ; case RMEM_MEMFREE : stats . nfrees ++ ; kclock ( & t0 ) ; msg . errcode = do_rmem_free ( msg . blknum ) ; uassert ( ( source = kmailbox_open ( msg . header . source ) ) >= 0 ) ; uassert ( kmailbox_write ( source , & msg , sizeof ( struct rmem_message ) ) == sizeof ( struct rmem_message ) ) ; uassert ( kmailbox_close ( source ) == 0 ) ; kclock ( & t1 ) ; stats . tfree += ( t1 - t0 ) ; break ; case RMEM_EXIT : kclock ( & stats . tshutdown ) ; shutdown = 1 ; break ; default : break ; } } uprintf ( " " , stats . talloc , stats . nallocs , stats . tfree , stats . nfrees , stats . tread , stats . nreads , stats . twrite , stats . nwrites ) ; return ( 0 ) ; }
@brief Handles remote memory requests.
@brief Handles remote memory requests .
/* handle write operation. */ /* Write to RMEM. */ /* Read a page. */ /* Allocates a page. */ /* Free frees a page. */ /* Should not happen. */ /* Dump statistics. */