diff --git a/arch/Kconfig b/arch/Kconfig index 7910fc012f5..39954d60964 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -742,7 +742,7 @@ config DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS Defines the number of bins (buckets) in the histogram used for gathering execution timing information for demand paging. - This requires z_eviction_histogram_bounds[] and + This requires k_mem_paging_eviction_histogram_bounds[] and z_backing_store_histogram_bounds[] to define the upper bounds for each bin. See kernel/statistics.c for information. diff --git a/include/sys/mem_manage.h b/include/sys/mem_manage.h index eee95340ca3..1bcf319efb8 100644 --- a/include/sys/mem_manage.h +++ b/include/sys/mem_manage.h @@ -503,6 +503,40 @@ __syscall void k_mem_paging_histogram_backing_store_page_out_get( /** @} */ +/** + * Eviction algorithm APIs + * + * @defgroup mem-demand-paging-eviction Eviction Algorithm APIs + * @{ + */ + +/** + * Select a page frame for eviction + * + * The kernel will invoke this to choose a page frame to evict if there + * are no free page frames. + * + * This function will never be called before the initial + * k_mem_paging_eviction_init(). + * + * This function is invoked with interrupts locked. + * + * @param [out] Whether the page to evict is dirty + * @return The page frame to evict + */ +struct z_page_frame *k_mem_paging_eviction_select(bool *dirty); + +/** + * Initialization function + * + * Called at POST_KERNEL to perform any necessary initialization tasks for the + * eviction algorithm. k_mem_paging_eviction_select() is guaranteed to never be + * called until this has returned, and this will only be called once. + */ +void k_mem_paging_eviction_init(void); + +/** @} */ + #ifdef __cplusplus } #endif diff --git a/kernel/include/mmu.h b/kernel/include/mmu.h index 50e28394b06..a505d0ee094 100644 --- a/kernel/include/mmu.h +++ b/kernel/include/mmu.h @@ -230,34 +230,6 @@ extern size_t z_free_page_count; #endif #ifdef CONFIG_DEMAND_PAGING -/* - * Eviction algorihm APIs - */ - -/** - * Select a page frame for eviction - * - * The kernel will invoke this to choose a page frame to evict if there - * are no free page frames. - * - * This function will never be called before the initial z_eviction_init(). - * - * This function is invoked with interrupts locked. - * - * @param [out] Whether the page to evict is dirty - * @return The page frame to evict - */ -struct z_page_frame *z_eviction_select(bool *dirty); - -/** - * Initialization function - * - * Called at POST_KERNEL to perform any necessary initialization tasks for the - * eviction algorithm. z_eviction_select() is guaranteed to never be called - * until this has returned, and this will only be called once. - */ -void z_eviction_init(void); - /* * Backing store APIs */ diff --git a/kernel/mmu.c b/kernel/mmu.c index b4f5fe276da..fafb0ddc9e0 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -430,7 +430,7 @@ static int map_anon_page(void *addr, uint32_t flags) bool dirty; int ret; - pf = z_eviction_select(&dirty); + pf = k_mem_paging_eviction_select(&dirty); __ASSERT(pf != NULL, "failed to get a page frame"); LOG_DBG("evicting %p at 0x%lx", pf->addr, z_page_frame_to_phys(pf)); @@ -791,7 +791,7 @@ void z_mem_manage_init(void) z_paging_histogram_init(); #endif z_backing_store_init(); - z_eviction_init(); + k_mem_paging_eviction_init(); #endif #if __ASSERT_ON page_frames_initialized = true; @@ -1162,7 +1162,7 @@ static inline struct z_page_frame *do_eviction_select(bool *dirty) #endif /* CONFIG_DEMAND_PAGING_STATS_USING_TIMING_FUNCTIONS */ #endif /* CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM */ - pf = z_eviction_select(dirty); + pf = k_mem_paging_eviction_select(dirty); #ifdef CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM #ifdef CONFIG_DEMAND_PAGING_STATS_USING_TIMING_FUNCTIONS @@ -1195,7 +1195,7 @@ static bool do_page_fault(void *addr, bool pin) /* * TODO: Add performance accounting: - * - z_eviction_select() metrics + * - k_mem_paging_eviction_select() metrics * * periodic timer execution time histogram (if implemented) */ diff --git a/kernel/paging/statistics.c b/kernel/paging/statistics.c index 907c0f8245c..6322d8964fc 100644 --- a/kernel/paging/statistics.c +++ b/kernel/paging/statistics.c @@ -28,7 +28,8 @@ struct k_mem_paging_histogram_t z_paging_histogram_backing_store_page_out; */ extern unsigned long -z_eviction_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS]; +k_mem_paging_eviction_histogram_bounds[ + CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS]; extern unsigned long z_backing_store_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS]; @@ -40,7 +41,7 @@ z_backing_store_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS] * This provides the upper bounds of the bins in eviction timing histogram. */ __weak unsigned long -z_eviction_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS] = { +k_mem_paging_eviction_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS] = { NS_TO_CYC(1), NS_TO_CYC(5), NS_TO_CYC(10), @@ -142,7 +143,8 @@ void z_paging_histogram_init(void) */ memset(&z_paging_histogram_eviction, 0, sizeof(z_paging_histogram_eviction)); - memcpy(z_paging_histogram_eviction.bounds, z_eviction_histogram_bounds, + memcpy(z_paging_histogram_eviction.bounds, + k_mem_paging_eviction_histogram_bounds, sizeof(z_paging_histogram_eviction.bounds)); memset(&z_paging_histogram_backing_store_page_in, 0, diff --git a/subsys/demand_paging/eviction/nru.c b/subsys/demand_paging/eviction/nru.c index bfdb9ea2bf9..650f54feb2b 100644 --- a/subsys/demand_paging/eviction/nru.c +++ b/subsys/demand_paging/eviction/nru.c @@ -40,7 +40,7 @@ static void nru_periodic_update(struct k_timer *timer) irq_unlock(key); } -struct z_page_frame *z_eviction_select(bool *dirty_ptr) +struct z_page_frame *k_mem_paging_eviction_select(bool *dirty_ptr) { unsigned int last_prec = 4U; struct z_page_frame *last_pf = NULL, *pf; @@ -89,7 +89,7 @@ struct z_page_frame *z_eviction_select(bool *dirty_ptr) static K_TIMER_DEFINE(nru_timer, nru_periodic_update, NULL); -void z_eviction_init(void) +void k_mem_paging_eviction_init(void) { k_timer_start(&nru_timer, K_NO_WAIT, K_MSEC(CONFIG_EVICTION_NRU_PERIOD)); diff --git a/tests/kernel/mem_protect/demand_paging/src/main.c b/tests/kernel/mem_protect/demand_paging/src/main.c index e26938f9d2e..d285ba0479e 100644 --- a/tests/kernel/mem_protect/demand_paging/src/main.c +++ b/tests/kernel/mem_protect/demand_paging/src/main.c @@ -20,7 +20,8 @@ #ifdef CONFIG_BOARD_QEMU_X86 unsigned long -z_eviction_histogram_bounds[CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS] = { +k_mem_paging_eviction_histogram_bounds[ + CONFIG_DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS] = { 10000, 20000, 30000,