summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-02-28 18:47:50 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-02-28 20:03:05 +0000
commit559bbd8ce3511ef2cd6cf78b4526feee362d8628 (patch)
treec5a9f29fafd19635baf5a59c0f3ece6d23264ad4
parent84a34d2ef62832a8cddff9911821aeca71150721 (diff)
freeq - up numbers for fq blocks and other limits to defer big batches
this should improve some perf by upping the max a free queu can baloon up to 256k items and 32m of data (whichever is hit first).
-rw-r--r--src/lib/ecore/ecore_main.c22
-rw-r--r--src/lib/eina/eina_freeq.c221
2 files changed, 233 insertions, 10 deletions
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index 7e84d9d231..fc35331f3f 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -316,6 +316,16 @@ _gfd_events_from_fdh(Ecore_Fd_Handler *fdh)
316} 316}
317#endif 317#endif
318 318
319
320static void
321_ecore_main_pre_idle_exit(void)
322{
323 // even if we never go idle, keep up flushing some of our freeq away
324 // on every idle exit which may happen if we even never called idlers
325 // for now an idea but dont enforce
326// eina_freeq_reduce(eina_freeq_main_get(), 128);
327}
328
319#ifdef HAVE_LIBUV 329#ifdef HAVE_LIBUV
320static void 330static void
321_ecore_main_uv_poll_cb(uv_poll_t *handle, int status, int events) 331_ecore_main_uv_poll_cb(uv_poll_t *handle, int status, int events)
@@ -332,6 +342,7 @@ _ecore_main_uv_poll_cb(uv_poll_t *handle, int status, int events)
332 DBG("not IDLE anymore"); 342 DBG("not IDLE anymore");
333 _ecore_main_uv_idling = EINA_FALSE; 343 _ecore_main_uv_idling = EINA_FALSE;
334 eina_file_statgen_next(); 344 eina_file_statgen_next();
345 _ecore_main_pre_idle_exit();
335 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 346 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
336 _ecore_animator_run_reset(); 347 _ecore_animator_run_reset();
337 } 348 }
@@ -532,11 +543,7 @@ _ecore_main_idler_all_call(Eo *loop, Efl_Loop_Data *pd)
532{ 543{
533 if (pd->idlers) 544 if (pd->idlers)
534 efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE, NULL); 545 efl_event_callback_call(loop, EFL_LOOP_EVENT_IDLE, NULL);
535 // just spin in an idler until the free queue is empty freeing 84 items 546 eina_freeq_reduce(eina_freeq_main_get(), 256);
536 // from the free queue each time.for now this seems like an ok balance
537 // between going in and out of a reduce func with mutexes around it
538 // vs blocking mainloop for too long. this number is up for discussion
539 eina_freeq_reduce(eina_freeq_main_get(), 84);
540} 547}
541 548
542#ifdef HAVE_SYS_EPOLL_H 549#ifdef HAVE_SYS_EPOLL_H
@@ -797,6 +804,7 @@ _ecore_main_gsource_dispatch(GSource *source EINA_UNUSED,
797 { 804 {
798 _ecore_animator_run_reset(); 805 _ecore_animator_run_reset();
799 eina_file_statgen_next(); 806 eina_file_statgen_next();
807 _ecore_main_pre_idle_exit();
800 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 808 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
801 ecore_idling = 0; 809 ecore_idling = 0;
802 } 810 }
@@ -812,6 +820,7 @@ _ecore_main_gsource_dispatch(GSource *source EINA_UNUSED,
812 { 820 {
813 _ecore_animator_run_reset(); 821 _ecore_animator_run_reset();
814 eina_file_statgen_next(); 822 eina_file_statgen_next();
823 _ecore_main_pre_idle_exit();
815 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 824 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
816 ecore_idling = 0; 825 ecore_idling = 0;
817 } 826 }
@@ -872,6 +881,7 @@ _ecore_main_loop_timer_run(uv_timer_t *timer EINA_UNUSED)
872 { 881 {
873 _ecore_main_uv_idling = EINA_FALSE; 882 _ecore_main_uv_idling = EINA_FALSE;
874 eina_file_statgen_next(); 883 eina_file_statgen_next();
884 _ecore_main_pre_idle_exit();
875 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 885 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
876 _ecore_animator_run_reset(); 886 _ecore_animator_run_reset();
877 } 887 }
@@ -2250,6 +2260,7 @@ _ecore_main_loop_uv_prepare(uv_prepare_t *handle EINA_UNUSED)
2250 if (_ecore_main_uv_idling) 2260 if (_ecore_main_uv_idling)
2251 { 2261 {
2252 eina_file_statgen_next(); 2262 eina_file_statgen_next();
2263 _ecore_main_pre_idle_exit();
2253 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 2264 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
2254 _ecore_animator_run_reset(); 2265 _ecore_animator_run_reset();
2255 _ecore_main_uv_idling = EINA_FALSE; 2266 _ecore_main_uv_idling = EINA_FALSE;
@@ -2481,6 +2492,7 @@ process_all: //-*********************************************************
2481 { 2492 {
2482 _ecore_animator_run_reset(); // XXX: 2493 _ecore_animator_run_reset(); // XXX:
2483 eina_file_statgen_next(); 2494 eina_file_statgen_next();
2495 _ecore_main_pre_idle_exit();
2484 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL); 2496 efl_event_callback_call(obj, EFL_LOOP_EVENT_IDLE_EXIT, NULL);
2485 } 2497 }
2486 // call the fd handler per fd that became alive... 2498 // call the fd handler per fd that became alive...
diff --git a/src/lib/eina/eina_freeq.c b/src/lib/eina/eina_freeq.c
index 5abb7b8f45..0cc7cd5fad 100644
--- a/src/lib/eina/eina_freeq.c
+++ b/src/lib/eina/eina_freeq.c
@@ -17,9 +17,23 @@
17// ========================================================================= // 17// ========================================================================= //
18 18
19#define ITEM_FILLPAT_MAX 0 19#define ITEM_FILLPAT_MAX 0
20#define ITEM_TOTAL_MAX ( 16 * 1024) 20#define ITEM_TOTAL_MAX ( 256 * 1024)
21#define ITEM_MEM_MAX (1024 * 1024) 21#define ITEM_MEM_MAX ( 32 * 1024 * 1024)
22#define ITEM_BLOCK_COUNT 42 22#if __WORDSIZE == 32
23// 4kb blocks
24//# define ITEM_BLOCK_COUNT 340
25// 64k blocks
26# define ITEM_BLOCK_COUNT 5459
27// 256k blocks
28//# define ITEM_BLOCK_COUNT 21844
29#else // __WORDSIZE == 64
30// 4kb blocks
31//# define ITEM_BLOCK_COUNT 170
32// 64k blocks
33# define ITEM_BLOCK_COUNT 2730
34// 256k blocks
35//# define ITEM_BLOCK_COUNT 10922
36#endif
23 37
24// ========================================================================= // 38// ========================================================================= //
25 39
@@ -28,6 +42,186 @@ typedef struct _Eina_FreeQ_Block Eina_FreeQ_Block;
28 42
29// ========================================================================= // 43// ========================================================================= //
30 44
45// these items are highly compressable. here is a dump of F: ptr freefunc size
46// ...
47// F: 0xaaab0454dd00 0xffff8b83b628 0x10
48// F: 0xaaab0454bd00 0xffff8b83b648 0x20
49// F: 0xaaab0454dd10 0xffff8b83b628 0x10
50// F: 0xaaab0454bd20 0xffff8b83b648 0x20
51// F: 0xaaab0454dd20 0xffff8b83b628 0x10
52// F: 0xaaab0454bd40 0xffff8b83b648 0x20
53// F: 0xaaab0454dd30 0xffff8b83b628 0x10
54// F: 0xaaab0454bd60 0xffff8b83b648 0x20
55// F: 0xaaab0454bda0 0xffff8b83b648 0x20
56// F: 0xaaab0454bdc0 0xffff8b83b648 0x20
57// ...
58// F: 0xaaab049176d0 0xffff8b83b648 0x20
59// F: 0xaaab04917750 0xffff8b83b648 0x20
60// F: 0xaaab04917770 0xffff8b83b648 0x20
61// F: 0xaaab04917330 0xffff8b83b648 0x20
62// F: 0xaaab0481b3c0 0xffff8b83b628 0x10
63// F: 0xaaab049177f0 0xffff8b83b648 0x20
64// F: 0xaaab049259a0 0xffff8af1c638 0x38
65// F: 0xaaab049172d0 0xffff8b83b648 0x20
66// F: 0xaaab049172f0 0xffff8b83b648 0x20
67// F: 0xaaab04925c00 0xffff8af1c638 0x38
68// F: 0xaaab04925c40 0xffff8af1c638 0x38
69// F: 0xaaab0481b3b0 0xffff8b83b628 0x10
70// F: 0xaaab04917310 0xffff8b83b648 0x20
71// F: 0xaaab04925bc0 0xffff8af1c638 0x38
72// F: 0xaaab0491d240 0xffff8af1c638 0x40
73// F: 0xaaab0492b3a0 0xffff8af1c638 0x38
74// F: 0xaaab049225c0 0xffff8af1c638 (nil)
75// F: 0xaaab04917730 0xffff8b83b648 0x20
76// F: 0xaaab04917790 0xffff8b83b648 0x20
77// F: 0xaaab049177b0 0xffff8b83b648 0x20
78// F: 0xaaab0492b710 0xffff8af1c638 0x38
79// F: 0xaaab0492b750 0xffff8af1c638 0x38
80// F: 0xaaab0481b420 0xffff8b83b628 0x10
81// F: 0xaaab049177d0 0xffff8b83b648 0x20
82// F: 0xaaab0492b2d0 0xffff8af1c638 0x38
83// F: 0xaaab0481b410 0xffff8b83b628 0x10
84// F: 0xaaab04917710 0xffff8b83b648 0x20
85// F: 0xaaab0492b280 0xffff8af1c638 0x40
86// F: 0xaaab0481b430 0xffff8b83b628 0x10
87// F: 0xaaab04917810 0xffff8b83b648 0x20
88// F: 0xaaab0492b6d0 0xffff8af1c638 0x38
89// F: 0xaaab0491ca80 0xffff8af1c638 (nil)
90// F: 0xaaab0492b350 0xffff8af1c638 0x40
91// F: 0xaaab0490fef0 0xffff8af1c638 0x38
92// F: 0xaaab0481b320 0xffff8b83b628 0x10
93// F: 0xaaab04916ff0 0xffff8b83b648 0x20
94// F: 0xaaab0481b330 0xffff8b83b628 0x10
95// F: 0xaaab04917030 0xffff8b83b648 0x20
96// F: 0xaaab04920560 0xffff8af1c638 0x38
97// F: 0xaaab0481b350 0xffff8b83b628 0x10
98// F: 0xaaab049170f0 0xffff8b83b648 0x20
99// F: 0xaaab04917050 0xffff8b83b648 0x20
100// F: 0xaaab04920510 0xffff8af1c638 0x40
101// F: 0xaaab04920850 0xffff8af1c638 0x38
102// F: 0xaaab04917070 0xffff8b83b648 0x20
103// F: 0xaaab04920800 0xffff8af1c638 0x40
104// F: 0xaaab04920c30 0xffff8af1c638 0x38
105// F: 0xaaab04917090 0xffff8b83b648 0x20
106// F: 0xaaab04920be0 0xffff8af1c638 0x40
107// F: 0xaaab04920e60 0xffff8af1c638 0x38
108// F: 0xaaab04920e10 0xffff8af1c638 0x40
109// F: 0xaaab049212b0 0xffff8af1c638 0x38
110// F: 0xaaab0481b340 0xffff8b83b628 0x10
111// F: 0xaaab049170d0 0xffff8b83b648 0x20
112// F: 0xaaab04921260 0xffff8af1c638 0x40
113// F: 0xaaab0481b1f0 0xffff8b83b628 0x10
114// F: 0xaaab04875d50 0xffff8b83b648 0x20
115// F: 0xaaab0490fea0 0xffff8af1c638 0x40
116// F: 0xaaab049102e0 0xffff8af1c638 0x38
117// F: 0xaaab04917010 0xffff8b83b648 0x20
118// F: 0xaaab0490b4f0 0xffff8af1c638 (nil)
119// F: 0xaaab04910290 0xffff8af1c638 0x40
120// F: 0xaaab0481b460 0xffff8b83b628 0x10
121// F: 0xaaab049178b0 0xffff8b83b648 0x20
122// F: 0xaaab0481b450 0xffff8b83b628 0x10
123// F: 0xaaab04917870 0xffff8b83b648 0x20
124// F: 0xaaab0481b490 0xffff8b83b628 0x10
125// F: 0xaaab049e56f0 0xffff8b83b648 0x20
126// F: 0xaaab0481b4a0 0xffff8b83b628 0x10
127// F: 0xaaab049e5710 0xffff8b83b648 0x20
128// F: 0xaaab0481b4b0 0xffff8b83b628 0x10
129// F: 0xaaab049e5730 0xffff8b83b648 0x20
130// F: 0xaaab0481b4c0 0xffff8b83b628 0x10
131// F: 0xaaab049e5750 0xffff8b83b648 0x20
132// F: 0xaaab0481b4f0 0xffff8b83b628 0x10
133// F: 0xaaab049e57d0 0xffff8b83b648 0x20
134// F: 0xaaab049e5990 0xffff8b83b648 0x20
135// F: 0xaaab049e5770 0xffff8b83b648 0x20
136// F: 0xaaab0481b4d0 0xffff8b83b628 0x10
137// F: 0xaaab049e5790 0xffff8b83b648 0x20
138// F: 0xaaab049e5a50 0xffff8b83b648 0x20
139// F: 0xaaab049e57b0 0xffff8b83b648 0x20
140// ...
141// F: 0xaaab04d9f330 0xffff8b83b648 0x20
142// F: 0xaaab04b18920 0xffff8b83b628 0x10
143// F: 0xaaab04d9f350 0xffff8b83b648 0x20
144// F: 0xaaab04d4d000 0xffff8b83b648 0x20
145// F: 0xaaab04d9f370 0xffff8b83b648 0x20
146// F: 0xaaab04d9f390 0xffff8b83b648 0x20
147// F: 0xaaab04d9f3b0 0xffff8b83b648 0x20
148// F: 0xaaab04b18930 0xffff8b83b628 0x10
149// F: 0xaaab04d9f3d0 0xffff8b83b648 0x20
150// F: 0xaaab04d9f3f0 0xffff8b83b648 0x20
151// F: 0xaaab04d9f410 0xffff8b83b648 0x20
152// F: 0xaaab04d9f430 0xffff8b83b648 0x20
153// F: 0xaaab04b18940 0xffff8b83b628 0x10
154// F: 0xaaab04d9f450 0xffff8b83b648 0x20
155// F: 0xaaab04d4d020 0xffff8b83b648 0x20
156// F: 0xaaab04d9f470 0xffff8b83b648 0x20
157// F: 0xaaab04d9f490 0xffff8b83b648 0x20
158// F: 0xaaab04d9f4b0 0xffff8b83b648 0x20
159// F: 0xaaab04b18950 0xffff8b83b628 0x10
160// F: 0xaaab04d9f4d0 0xffff8b83b648 0x20
161// F: 0xaaab04d9f4f0 0xffff8b83b648 0x20
162// F: 0xaaab04d9f510 0xffff8b83b648 0x20
163// F: 0xaaab04d9f530 0xffff8b83b648 0x20
164// F: 0xaaab04b18960 0xffff8b83b628 0x10
165// F: 0xaaab04d9f550 0xffff8b83b648 0x20
166// F: 0xaaab04640ce0 0xffff8b83b628 0x10
167// F: 0xaaab04d9ee10 0xffff8b83b648 0x20
168// F: 0xaaab04577e50 0xffff8af1c638 (nil)
169// F: 0xaaab04571570 0xffff8af1c638 (nil)
170// F: 0xaaab04577ee0 0xffff8af1c638 0x40
171// F: 0xaaab0457af50 0xffff8af1c638 (nil)
172// F: 0xaaab04571590 0xffff8af1c638 (nil)
173// F: 0xaaab0457afe0 0xffff8af1c638 0x40
174// F: 0xaaab0457e0c0 0xffff8af1c638 (nil)
175// F: 0xaaab0457b360 0xffff8af1c638 (nil)
176// F: 0xaaab0457e150 0xffff8af1c638 0x40
177// F: 0xaaab04581860 0xffff8af1c638 (nil)
178// F: 0xaaab04581330 0xffff8af1c638 (nil)
179// F: 0xaaab045818f0 0xffff8af1c638 0x40
180// F: 0xaaab0490ed00 0xffff8af1c638 0xc0
181// F: 0xaaab0490f090 0xffff8af1c638 0xc0
182// F: 0xaaab04922760 0xffff8af1c638 0xc0
183// F: 0xaaab04922880 0xffff8af1c638 0xc0
184// F: 0xaaab04922a20 0xffff8af1c638 0xc0
185// F: 0xaaab0491cb80 0xffff8af1c638 0xc0
186// F: 0xaaab0492b8e0 0xffff8af1c638 0xc0
187// F: 0xaaab0492c4b0 0xffff8af1c638 0xc0
188// F: 0xaaab0492c5c0 0xffff8af1c638 0xc0
189// F: 0xaaab0492c750 0xffff8af1c638 0xc0
190// F: 0xaaab04926230 0xffff8af1c638 0xc0
191// F: 0xaaab04920d00 0xffff8af1c638 0xc0
192// F: 0xaaab04920aa0 0xffff8af1c638 0xc0
193// F: 0xaaab04a05280 0xffff8af1c638 0xc0
194// F: 0xaaab04a053d0 0xffff8af1c638 0xc0
195// F: 0xaaab04a05520 0xffff8af1c638 0xc0
196// F: 0xaaab049f3860 0xffff8af1c638 0xc0
197// F: 0xaaab049f3a30 0xffff8af1c638 0xc0
198// F: 0xaaab04a06e60 0xffff8af1c638 0xc0
199// F: 0xaaab04a25490 0xffff8af1c638 0xc0
200// F: 0xaaab04a55170 0xffff8af1c638 0xc0
201// F: 0xaaab04a55ca0 0xffff8af1c638 0xc0
202// ...
203// so in future maybe create delta compression. keep a "start value" in the
204// Eina_FreeQ_Block block for each to begin from (and update these as we
205// march blcok->start forward (or at least update them when we finish a run
206// of processing items at the end of the processing.
207//
208// we can store things as DELTAS from the preview value. ptr, func, size all
209// are ptr sized values so we can compress them with deltas and thus encode
210// them in variable runs of bytes depending on the size of the delta. e.g.
211// use LEB128 maybe or PrefixVariant.
212//
213// after some playng leb128 seems to be the best from simplicity (so fast
214// encode which matters and decode needs to be good too) and size. i saw
215// a reduction to 24% of the original data size this way based on the sample
216// data i collected like above. is it worth the extra cycles? don't know.
217//
218// when looking at the deltas i noticed that func and sie delats are very
219// often 0 for long runs. this means we can probably use RLE effectively
220// if we split this into 3 streams wahc delta compressed then RLE compressed
221// per stream. walking is more complex and filling the block means taking
222// a guess at pre-allocating offsets per stream so it may not fill the blocks
223// as affectively then. again - is it worth it? need to measure if RLE helps
224// a lot or not in keeping size down in addition to delta + leb128.
31struct _Eina_FreeQ_Item 225struct _Eina_FreeQ_Item
32{ 226{
33 void *ptr; 227 void *ptr;
@@ -67,6 +261,20 @@ static unsigned char _eina_freeq_fillpat_freed_val = 0x77;
67static int _eina_freeq_total_max = ITEM_TOTAL_MAX; 261static int _eina_freeq_total_max = ITEM_TOTAL_MAX;
68static size_t _eina_freeq_mem_max = ITEM_MEM_MAX; 262static size_t _eina_freeq_mem_max = ITEM_MEM_MAX;
69 263
264// debgging/tuning info to enable in future when gathering stats
265#if 0
266static int _max_seen = 0;
267# define FQMAX(fq) \
268 if (fq == _eina_freeq_main) { \
269 if (fq->count > _max_seen) { \
270 _max_seen = fq->count; \
271 printf("FQ max: %i\n", _max_seen); \
272 } \
273 }
274#else
275# define FQMAX(fq)
276#endif
277
70// ========================================================================= // 278// ========================================================================= //
71 279
72#define LOCK_FQ(fq); do { \ 280#define LOCK_FQ(fq); do { \
@@ -108,9 +316,9 @@ err:
108static void 316static void
109_eina_freeq_free_do(void *ptr, 317_eina_freeq_free_do(void *ptr,
110 void (*free_func) (void *ptr), 318 void (*free_func) (void *ptr),
111 size_t size EINA_UNUSED) 319 size_t size)
112{ 320{
113 if ((size < _eina_freeq_fillpat_max) && (size > 0)) 321 if (EINA_LIKELY((size > 0) && (size < _eina_freeq_fillpat_max)))
114 { 322 {
115 _eina_freeq_fill_check(ptr, free_func, size); 323 _eina_freeq_fill_check(ptr, free_func, size);
116 _eina_freeq_freed_fill_do(ptr, size); 324 _eina_freeq_freed_fill_do(ptr, size);
@@ -157,6 +365,7 @@ _eina_freeq_flush_nolock(Eina_FreeQ *fq)
157{ 365{
158 if (fq->postponed) return; 366 if (fq->postponed) return;
159 367
368 FQMAX(fq);
160 while ((fq->count > fq->count_max) || (fq->mem_total > fq->mem_max)) 369 while ((fq->count > fq->count_max) || (fq->mem_total > fq->mem_max))
161 _eina_freeq_process(fq); 370 _eina_freeq_process(fq);
162} 371}
@@ -323,6 +532,7 @@ eina_freeq_clear(Eina_FreeQ *fq)
323{ 532{
324 if (!fq) return; 533 if (!fq) return;
325 LOCK_FQ(fq); 534 LOCK_FQ(fq);
535 FQMAX(fq);
326 while (fq->count > 0) _eina_freeq_process(fq); 536 while (fq->count > 0) _eina_freeq_process(fq);
327 UNLOCK_FQ(fq); 537 UNLOCK_FQ(fq);
328} 538}
@@ -332,6 +542,7 @@ eina_freeq_reduce(Eina_FreeQ *fq, int count)
332{ 542{
333 if (!fq) return; 543 if (!fq) return;
334 LOCK_FQ(fq); 544 LOCK_FQ(fq);
545 FQMAX(fq);
335 while ((fq->count > 0) && (count > 0)) 546 while ((fq->count > 0) && (count > 0))
336 { 547 {
337 _eina_freeq_process(fq); 548 _eina_freeq_process(fq);