From 26e6281bb7df5c817a2250b58169bae47195329c Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Tue, 22 May 2012 14:47:47 +0100 Subject: [PATCH] fix PgEnt_strs_in_use counter --- C/threads.c | 2 +- OPTYap/opt.init.c | 4 ++++ OPTYap/opt.macros.h | 15 ++++++++++++--- OPTYap/opt.structs.h | 4 ++++ OPTYap/tab.tries.c | 4 ++-- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/C/threads.c b/C/threads.c index 9b7b6757d..d676f3624 100644 --- a/C/threads.c +++ b/C/threads.c @@ -190,6 +190,7 @@ thread_die(int wid, int always_die) LOCAL_top_dep_fr = NULL; #ifdef USE_PAGES_MALLOC DETACH_PAGES(_pages_void); +#endif /* USE_PAGES_MALLOC */ DETACH_PAGES(_pages_tab_ent); #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) DETACH_PAGES(_pages_sg_ent); @@ -205,7 +206,6 @@ thread_die(int wid, int always_die) #endif /* THREADS_FULL_SHARING */ DETACH_PAGES(_pages_gt_node); DETACH_PAGES(_pages_gt_hash); -#endif /* USE_PAGES_MALLOC */ #ifdef OUTPUT_THREADS_TABLING fclose(LOCAL_thread_output); #endif /* OUTPUT_THREADS_TABLING */ diff --git a/OPTYap/opt.init.c b/OPTYap/opt.init.c index 61a0f84ee..d7407158d 100644 --- a/OPTYap/opt.init.c +++ b/OPTYap/opt.init.c @@ -71,8 +71,10 @@ void Yap_init_global_optyap_data(int max_table_size, int n_workers, int sch_loop int i; /* global data related to memory management */ +#ifdef USE_PAGES_MALLOC INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_alloc, void *); INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_void, void *); +#endif /* USE_PAGES_MALLOC */ #ifdef TABLING INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tab_ent, struct table_entry); #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) @@ -180,7 +182,9 @@ void Yap_init_local_optyap_data(int wid) { #ifdef YAPOR REMOTE_next_free_ans_node(wid) = NULL; #elif THREADS +#ifdef USE_PAGES_MALLOC INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_void(wid), void *); +#endif INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_tab_ent(wid), struct table_entry); #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_sg_ent(wid), struct subgoal_entry); diff --git a/OPTYap/opt.macros.h b/OPTYap/opt.macros.h index 2883eda99..cc2ef7099 100644 --- a/OPTYap/opt.macros.h +++ b/OPTYap/opt.macros.h @@ -101,6 +101,15 @@ extern int Yap_page_size; /******************************************************************************************* ** ! USE_PAGES_MALLOC ** *******************************************************************************************/ +#define MOVE_PAGES(FROM_PG_ENT, TO_PG_ENT) \ + UPDATE_STATS(PgEnt_strs_in_use(TO_PG_ENT), PgEnt_strs_in_use(FROM_PG_ENT)); \ + PgEnt_strs_in_use(FROM_PG_ENT) = 0 +#define DETACH_PAGES(_PG_ENT) \ + LOCK(PgEnt_lock(GLOBAL##_PG_ENT)); \ + MOVE_PAGES(LOCAL##_PG_ENT, GLOBAL##_PG_ENT); \ + UNLOCK(PgEnt_lock(GLOBAL##_PG_ENT)) +#define ATTACH_PAGES(_PG_ENT) \ + MOVE_PAGES(GLOBAL##_PG_ENT, LOCAL##_PG_ENT) #define GET_FREE_STRUCT(STR, STR_TYPE, PG_ENT, EXTRA_PG_ENT) \ LOCK_PAGE_ENTRY(PG_ENT); \ UPDATE_STATS(PgEnt_strs_in_use(PG_ENT), 1); \ @@ -141,14 +150,14 @@ extern int Yap_page_size; MOVE_PAGES(GLOBAL##_PG_ENT, LOCAL##_PG_ENT); \ } -#define GET_PAGE_FIRST_LEVEL(PG_HD) GET_ALLOC_PAGE(PG_HD) -#define GET_ALLOC_PAGE_NEXT_LEVEL(PG_HD) GET_VOID_PAGE(PG_HD) -#define GET_VOID_PAGE_NEXT_LEVEL(PG_HD) /******************************************************************************************* #define GET_PAGE_FIRST_LEVEL(PG_HD) GET_VOID_PAGE(PG_HD) #define GET_VOID_PAGE_NEXT_LEVEL(PG_HD) GET_ALLOC_PAGE(PG_HD) #define GET_ALLOC_PAGE_NEXT_LEVEL(PG_HD) *******************************************************************************************/ +#define GET_PAGE_FIRST_LEVEL(PG_HD) GET_ALLOC_PAGE(PG_HD) +#define GET_ALLOC_PAGE_NEXT_LEVEL(PG_HD) GET_VOID_PAGE(PG_HD) +#define GET_VOID_PAGE_NEXT_LEVEL(PG_HD) #define GET_ALLOC_PAGE(PG_HD) \ LOCK(PgEnt_lock(GLOBAL_pages_alloc)); \ diff --git a/OPTYap/opt.structs.h b/OPTYap/opt.structs.h index 679fc8e72..92d310c1a 100644 --- a/OPTYap/opt.structs.h +++ b/OPTYap/opt.structs.h @@ -153,8 +153,10 @@ struct local_page_entry { ***************************/ struct global_pages { +#ifdef USE_PAGES_MALLOC struct global_page_entry alloc_pages; struct global_page_entry void_pages; +#endif /* USE_PAGES_MALLOC */ #ifdef TABLING struct global_page_entry table_entry_pages; @@ -199,7 +201,9 @@ struct local_pages { #ifdef YAPOR struct answer_trie_node *next_free_answer_trie_node; #elif THREADS +#ifdef USE_PAGES_MALLOC struct local_page_entry void_pages; +#endif struct local_page_entry table_entry_pages; #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) struct local_page_entry subgoal_entry_pages; diff --git a/OPTYap/tab.tries.c b/OPTYap/tab.tries.c index e86d52f2d..7d922213a 100644 --- a/OPTYap/tab.tries.c +++ b/OPTYap/tab.tries.c @@ -1524,7 +1524,7 @@ void abolish_table(tab_ent_ptr tab_ent) { CACHE_REGS sg_node_ptr sg_node; -#if defined(THREADS) && defined(USE_PAGES_MALLOC) +#ifdef THREADS if (GLOBAL_NOfThreads == 1) { ATTACH_PAGES(_pages_tab_ent); #if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING) @@ -1542,7 +1542,7 @@ void abolish_table(tab_ent_ptr tab_ent) { ATTACH_PAGES(_pages_gt_node); ATTACH_PAGES(_pages_gt_hash); } -#endif /* THREADS && USE_PAGES_MALLOC */ +#endif /* THREADS */ sg_node = get_subgoal_trie_for_abolish(tab_ent PASS_REGS); if (sg_node) { if (TrNode_child(sg_node)) {