src/libruntime/rmem/cache.c
/**
 * @todo TODO: provide a detailed description for this function.
 */
@todo TODO: provide a detailed description for this function.
@todo TODO : provide a detailed description for this function .
int nanvix_rcache_flush(rpage_t pgnum)
{
	int err;
	int idx;
	int pgnum_block;
	int pgnum_abs;
	int idx_abs;
	cache_time++;
	if ((pgnum == RMEM_NULL) || (RMEM_BLOCK_NUM(pgnum) >= RMEM_NUM_BLOCKS))
		return (-EFAULT);
	if ((idx = nanvix_rcache_page_search(pgnum)) < 0)
		return (-EFAULT);
	pgnum_block = idx%RMEM_CACHE_BLOCK_SIZE;
	pgnum_abs = (int)(pgnum - pgnum_block);
	idx_abs = idx - pgnum_block;
	for (int i = 0; i < RMEM_CACHE_BLOCK_SIZE; i++)
	{
		if ((err = nanvix_rmem_write((rpage_t)(pgnum_abs+i), cache_lines[idx_abs+i].pages)) < 0)
			return (err);
	}
#ifdef CACHE_DEBUG
	uprintf("[benchmark] %d misses, %d hits", stats.nmisses, stats.nhits);
#endif
	return (0);
}
int nanvix_rcache_flush ( rpage_t pgnum ) { int err ; int idx ; int pgnum_block ; int pgnum_abs ; int idx_abs ; cache_time ++ ; if ( ( pgnum == RMEM_NULL ) || ( RMEM_BLOCK_NUM ( pgnum ) >= RMEM_NUM_BLOCKS ) ) return ( - EFAULT ) ; if ( ( idx = nanvix_rcache_page_search ( pgnum ) ) < 0 ) return ( - EFAULT ) ; pgnum_block = idx % RMEM_CACHE_BLOCK_SIZE ; pgnum_abs = ( int ) ( pgnum - pgnum_block ) ; idx_abs = idx - pgnum_block ; for ( int i = 0 ; i < RMEM_CACHE_BLOCK_SIZE ; i ++ ) { if ( ( err = nanvix_rmem_write ( ( rpage_t ) ( pgnum_abs + i ) , cache_lines [ idx_abs + i ] . pages ) ) < 0 ) return ( err ) ; } #ifdef CACHE_DEBUG uprintf ( " " , stats . nmisses , stats . nhits ) ; #endif return ( 0 ) ; }
@todo TODO: provide a detailed description for this function.
@todo TODO : provide a detailed description for this function .
/* Invalid page number. */ /* Search for page in the cache. */ /* Write page back to remote memory. */