summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-04-22 20:22:35 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-04-22 20:24:27 +0900
commit1ed6e2cf9cbd87948232f7554d91f31711083761 (patch)
treeaff5154780940d89112b535809efcd29316863d0
parentc0aa0b3410d40b1006ae75216afed060e6a5bed0 (diff)
improve eo call stack
it now does up to 8192 entries and madvise unused upper pages when dropping. also delay dropping to avoi too many syscalls
-rw-r--r--src/lib/eo/eo.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 6ad7fc5..382d2c2 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -256,7 +256,7 @@ EAPI Eo_Hook_Call eo_hook_call_post = NULL;
256#define EO_INVALID_DATA (void *) -1 256#define EO_INVALID_DATA (void *) -1
257// 1024 entries == 8k or 16k (32 or 64bit) for eo call stack. that's 1024 257// 1024 entries == 8k or 16k (32 or 64bit) for eo call stack. that's 1024
258// recursion entires it can handle before barfing. i'd say that's ok 258// recursion entires it can handle before barfing. i'd say that's ok
259#define EO_CALL_STACK_DEPTH 1024 259#define EO_CALL_STACK_DEPTH 16
260 260
261typedef struct _Eo_Stack_Frame 261typedef struct _Eo_Stack_Frame
262{ 262{
@@ -272,10 +272,12 @@ typedef struct _Eo_Stack_Frame
272static Eina_TLS _eo_call_stack_key = 0; 272static Eina_TLS _eo_call_stack_key = 0;
273 273
274typedef struct _Eo_Call_Stack { 274typedef struct _Eo_Call_Stack {
275 Eo_Stack_Frame *frames; 275 Eo_Stack_Frame *frames;
276 Eo_Stack_Frame *frame_ptr; 276 Eo_Stack_Frame *frame_ptr;
277 Eo_Stack_Frame *last_frame; 277 Eo_Stack_Frame *last_frame;
278 Eo_Stack_Frame *shrink_frame; 278 Eo_Stack_Frame *shrink_frame;
279 size_t max_size;
280 int dropcount;
279} Eo_Call_Stack; 281} Eo_Call_Stack;
280 282
281#define MEM_PAGE_SIZE 4096 283#define MEM_PAGE_SIZE 4096
@@ -345,8 +347,8 @@ _eo_call_stack_create()
345 347
346// XXX: leave in for noew in case this breaks, but remove later when ok 348// XXX: leave in for noew in case this breaks, but remove later when ok
347// stack->frames = calloc(EO_CALL_STACK_DEPTH, sizeof(Eo_Stack_Frame)); 349// stack->frames = calloc(EO_CALL_STACK_DEPTH, sizeof(Eo_Stack_Frame));
348 stack->frames = _eo_call_stack_mem_alloc(EO_CALL_STACK_DEPTH * 350 stack->max_size = 8192 * sizeof(Eo_Stack_Frame);
349 sizeof(Eo_Stack_Frame)); 351 stack->frames = _eo_call_stack_mem_alloc(stack->max_size);
350 if (!stack->frames) 352 if (!stack->frames)
351 { 353 {
352 free(stack); 354 free(stack);
@@ -372,9 +374,7 @@ _eo_call_stack_free(void *ptr)
372 { 374 {
373// XXX: leave in for noew in case this breaks, but remove later when ok 375// XXX: leave in for noew in case this breaks, but remove later when ok
374// free(stack->frames); 376// free(stack->frames);
375 _eo_call_stack_mem_free(stack->frames, 377 _eo_call_stack_mem_free(stack->frames, stack->max_size);
376 (stack->last_frame - stack->frames + 1) *
377 sizeof(Eo_Stack_Frame));
378 } 378 }
379 free(stack); 379 free(stack);
380} 380}
@@ -409,19 +409,34 @@ _eo_call_stack_resize(Eo_Call_Stack *stack, Eina_Bool grow)
409 size_t sz, next_sz; 409 size_t sz, next_sz;
410 int frame_offset; 410 int frame_offset;
411 411
412 frame_offset = stack->frame_ptr - stack->frames;
413 sz = stack->last_frame - stack->frames + 1; 412 sz = stack->last_frame - stack->frames + 1;
414 if (grow) 413 if (grow)
415 next_sz = sz << 1; 414 {
415 next_sz = sz * 2;
416 // reset drop counter to avoid dropping stack for up to 2 ^ 18
417 // requests/tries
418 stack->dropcount = 1 << 18;
419 }
416 else 420 else
417 next_sz = sz >> 1; 421 {
422 // if we want to drop - delay if dropcounter still > 0 and drop it
423 if (stack->dropcount > 0)
424 {
425 stack->dropcount--;
426 return;
427 }
428 // actually drop
429 next_sz = sz / 2;
430 }
431 frame_offset = stack->frame_ptr - stack->frames;
418 432
419 DBG("resize from %lu to %lu", (long unsigned int)sz, (long unsigned int)next_sz); 433 DBG("resize from %lu to %lu", (long unsigned int)sz, (long unsigned int)next_sz);
420// XXX: leave in for noew in case this breaks, but remove later when ok 434// XXX: leave in for noew in case this breaks, but remove later when ok
421// stack->frames = realloc(stack->frames, next_sz * sizeof(Eo_Stack_Frame)); 435// stack->frames = realloc(stack->frames, next_sz * sizeof(Eo_Stack_Frame));
422 _eo_call_stack_mem_resize((void **)&(stack->frames), 436 if (!grow)
423 next_sz * sizeof(Eo_Stack_Frame), 437 _eo_call_stack_mem_resize((void **)&(stack->frames),
424 sz * sizeof(Eo_Stack_Frame)); 438 next_sz * sizeof(Eo_Stack_Frame),
439 stack->max_size);
425 if (!stack->frames) 440 if (!stack->frames)
426 { 441 {
427 CRI("unable to resize call stack, abort."); 442 CRI("unable to resize call stack, abort.");
@@ -534,7 +549,7 @@ _eo_do_end(const Eo **eo_id EINA_UNUSED)
534 549
535 stack->frame_ptr--; 550 stack->frame_ptr--;
536 551
537 if (fptr == stack->shrink_frame) 552 if (fptr <= stack->shrink_frame)
538 _eo_call_stack_resize(stack, EINA_FALSE); 553 _eo_call_stack_resize(stack, EINA_FALSE);
539} 554}
540 555