From e0a62ecabb494e0842e50814cc8441d786f27b40 Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Wed, 18 Mar 2015 13:30:34 +0000 Subject: [PATCH] fixed watch allocate to use small, fixed-size pool for first few allocations --- watchsyscall/wa_callbacks.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/watchsyscall/wa_callbacks.c b/watchsyscall/wa_callbacks.c index 4675302..63d3435 100644 --- a/watchsyscall/wa_callbacks.c +++ b/watchsyscall/wa_callbacks.c @@ -74,20 +74,29 @@ typedef struct } reg_values_t; #define PAGESIZE 4096 -#define MAXADDRSPERPAGE ((PAGESIZE/(2*sizeof(int)))-(8*sizeof(int))) +#define MAXADDRSPERPAGE ((PAGESIZE/(2*sizeof(int)))-(16*sizeof(int))) +#define INITIAL_SET_SIZE 5 typedef struct addr_list addr_list_t; struct addr_list { - int pairs; + short pairs; + short max; addr_list_t *next; struct { int start; int end; - } addrs[MAXADDRSPERPAGE]; + } addrs[INITIAL_SET_SIZE]; // may over allocate }; +addr_list_t OK_first = +{ + 0, INITIAL_SET_SIZE, NULL, {{0,0},{0,0},{0,0},{0,0},{0,0}} +}; + + + addr_list_t *OK_list=NULL; @@ -113,7 +122,7 @@ void add_to_list(int start, int end) { page_no++; //print_str_debug("checking for space.\n"); - if(al->pairs<MAXADDRSPERPAGE) + if(al->pairs<al->max) { #ifdef DEBUG_ADD print_str_debug("Found space in this list_entry. page="); @@ -138,10 +147,10 @@ void add_to_list(int start, int end) print_str_debug("\n"); #endif // no space in any list item. - assert(sizeof(addr_list_t)); - cgc_allocate(sizeof(addr_list_t), 0==0, &al); + cgc_allocate( sizeof(addr_list_t)+(8*(MAXADDRSPERPAGE-INITIAL_SET_SIZE)) , 0==0, &al); al->next=OK_list; al->pairs=1; + al->max=MAXADDRSPERPAGE; al->addrs[0].start=start; al->addrs[0].end=end; OK_list=al; @@ -153,13 +162,15 @@ void add_to_list(int start, int end) void zipr_init_addrs( int ret, int start, int end) { #ifdef DEBUG -// char *str=" in init: start="; -// print_str("in init: start="); -// print_int(start); -// print_str(" end="); -// print_int(end); -// print_str("\n"); + char *str=" in init: start="; + print_str("in init: start="); + print_int(start); + print_str(" end="); + print_int(end); + print_str("\n"); #endif + if(OK_list==NULL) + OK_list=&OK_first; add_to_list(start,end); } -- GitLab