summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-07-29 15:41:23 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:13 +0900
commit88ef4131a0df0735ebef19306285b4bea608cbab (patch)
treed59961ffc1c7a6253c3e5ac2a2be300d18c94b25 /src/bin
parent47be3a2b819ed6319a65018195b31b622b547aab (diff)
evas/cserve2: Share paths of index tables with clients
- Send paths to all connected clients - Send paths upon connection from a new client - Client side: - Fast find opened images - Fast find loaded images - Optimize load by skipping socket wait Also, remap indexes when needed (file size changed) When index file grows, the clients are not notified, so they must constantly check that their mapping matches the current array size.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/evas/evas_cserve2.h4
-rw-r--r--src/bin/evas/evas_cserve2_cache.c74
-rw-r--r--src/bin/evas/evas_cserve2_index.c35
-rw-r--r--src/bin/evas/evas_cserve2_main.c31
4 files changed, 111 insertions, 33 deletions
diff --git a/src/bin/evas/evas_cserve2.h b/src/bin/evas/evas_cserve2.h
index c91e822b6b..f4a1d8da32 100644
--- a/src/bin/evas/evas_cserve2.h
+++ b/src/bin/evas/evas_cserve2.h
@@ -233,7 +233,7 @@ void cserve2_client_del(Client *client);
233void cserve2_client_deliver(Client *client); 233void cserve2_client_deliver(Client *client);
234void cserve2_client_error_send(Client *client, unsigned int rid, int error_code); 234void cserve2_client_error_send(Client *client, unsigned int rid, int error_code);
235ssize_t cserve2_client_send(Client *client, const void *data, size_t size); 235ssize_t cserve2_client_send(Client *client, const void *data, size_t size);
236void cserve2_index_list_send(const char *files_index_path, const char *images_index_path, const char *fonts_index_path); 236void cserve2_index_list_send(const char *strings_index_path, const char *strings_entries_path, const char *files_index_path, const char *images_index_path, const char *fonts_index_path, Client *client);
237 237
238Eina_Bool cserve2_fd_watch_add(int fd, Fd_Flags flags, Fd_Watch_Cb cb, const void *data); 238Eina_Bool cserve2_fd_watch_add(int fd, Fd_Flags flags, Fd_Watch_Cb cb, const void *data);
239Eina_Bool cserve2_fd_watch_del(int fd); 239Eina_Bool cserve2_fd_watch_del(int fd);
@@ -357,6 +357,8 @@ void *cserve2_shared_mempool_buffer_get(Shared_Mempool *sm, int bufferid);
357 357
358 358
359// Shared strings 359// Shared strings
360const char *cserve2_shared_strings_table_name_get();
361const char *cserve2_shared_strings_index_name_get();
360int cserve2_shared_string_add(const char *str); 362int cserve2_shared_string_add(const char *str);
361int cserve2_shared_string_ref(int id); 363int cserve2_shared_string_ref(int id);
362void cserve2_shared_string_del(int id); 364void cserve2_shared_string_del(int id);
diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c
index 777d35c337..5bbe014fae 100644
--- a/src/bin/evas/evas_cserve2_cache.c
+++ b/src/bin/evas/evas_cserve2_cache.c
@@ -148,7 +148,8 @@ struct _File_Watch {
148}; 148};
149 149
150static unsigned int _entry_id = 0; 150static unsigned int _entry_id = 0;
151static unsigned int _freed_entry_count = 0; 151static unsigned int _freed_file_entry_count = 0;
152static unsigned int _freed_image_entry_count = 0;
152 153
153static Shared_Array *_file_data_array = NULL; 154static Shared_Array *_file_data_array = NULL;
154static Shared_Array *_image_data_array = NULL; 155static Shared_Array *_image_data_array = NULL;
@@ -315,12 +316,13 @@ _repack()
315{ 316{
316 Shared_Array *sa; 317 Shared_Array *sa;
317 int count; 318 int count;
319 Eina_Bool updated = EINA_FALSE;
318 320
319 // Repack when we have 10% fragmentation over the whole shm buffer 321 // Repack when we have 10% fragmentation over the whole shm buffer
320 322
321 count = cserve2_shared_array_size_get(_file_data_array); 323 count = cserve2_shared_array_size_get(_file_data_array);
322 if ((count > 0) && (_freed_entry_count > 100 || 324 if ((count > 0) && (_freed_file_entry_count > 100 ||
323 ((_freed_entry_count * 100) / count >= 10))) 325 ((_freed_file_entry_count * 100) / count >= 10)))
324 { 326 {
325 DBG("Repacking file data array: %s", 327 DBG("Repacking file data array: %s",
326 cserve2_shared_array_name_get(_file_data_array)); 328 cserve2_shared_array_name_get(_file_data_array));
@@ -331,19 +333,46 @@ _repack()
331 if (!sa) 333 if (!sa)
332 { 334 {
333 ERR("Failed to repack array. Keeping previous references!"); 335 ERR("Failed to repack array. Keeping previous references!");
334 return; 336 goto skip_files;
335 } 337 }
336 338
337 cserve2_shared_array_del(_file_data_array); 339 cserve2_shared_array_del(_file_data_array);
338 _freed_entry_count = 0; 340 _freed_file_entry_count = 0;
339 _file_data_array = sa; 341 _file_data_array = sa;
342 updated = EINA_TRUE;
340 } 343 }
344skip_files:
341 345
342 // FIXME TODO: Repack image data array as well 346 count = cserve2_shared_array_size_get(_image_data_array);
347 if ((count > 0) && (_freed_image_entry_count > 100 ||
348 ((_freed_image_entry_count * 100) / count >= 10)))
349 {
350 DBG("Repacking image data array: %s",
351 cserve2_shared_array_name_get(_image_data_array));
343 352
344 cserve2_index_list_send(cserve2_shared_array_name_get(_file_data_array), 353 sa = cserve2_shared_array_repack(_image_data_array,
345 cserve2_shared_array_name_get(_image_data_array), 354 _repack_skip_cb,
346 NULL); 355 _shm_object_id_cmp_cb, NULL);
356 if (!sa)
357 {
358 ERR("Failed to repack array. Keeping previous references!");
359 goto skip_images;
360 }
361
362 cserve2_shared_array_del(_image_data_array);
363 _freed_image_entry_count = 0;
364 _image_data_array = sa;
365 updated = EINA_TRUE;
366 }
367skip_images:
368
369 if (updated)
370 cserve2_index_list_send(cserve2_shared_strings_index_name_get(),
371 cserve2_shared_strings_table_name_get(),
372 cserve2_shared_array_name_get(_file_data_array),
373 cserve2_shared_array_name_get(_image_data_array),
374 NULL,
375 NULL);
347} 376}
348 377
349 378
@@ -404,6 +433,18 @@ _image_loaded_msg_create(Image_Entry *ientry, Image_Data *idata, int *size)
404 msg->shm.image_size = cserve2_shm_size_get(ientry->shm); 433 msg->shm.image_size = cserve2_shm_size_get(ientry->shm);
405 msg->alpha_sparse = idata->alpha_sparse; 434 msg->alpha_sparse = idata->alpha_sparse;
406 435
436 if (idata->shm_id)
437 {
438 const char *old = cserve2_shared_string_get(idata->shm_id);
439 if (strcmp(old, shmpath))
440 {
441 cserve2_shared_string_del(idata->shm_id);
442 idata->shm_id = cserve2_shared_string_add(shmpath);
443 }
444 }
445 else
446 idata->shm_id = cserve2_shared_string_add(shmpath);
447
407 buf = (char *)msg + sizeof(*msg); 448 buf = (char *)msg + sizeof(*msg);
408 memcpy(buf, shmpath, path_len); 449 memcpy(buf, shmpath, path_len);
409 450
@@ -723,7 +764,7 @@ _scaling_prepare_and_do(Image_Entry *ientry, Image_Data *idata)
723 cserve2_shm_unref(ientry->shm); 764 cserve2_shm_unref(ientry->shm);
724 cserve2_shared_string_del(idata->shm_id); 765 cserve2_shared_string_del(idata->shm_id);
725 ientry->shm = scale_shm; 766 ientry->shm = scale_shm;
726 idata->shm_id = cserve2_shared_string_add(cserve2_shm_name_get(ientry->shm)); 767 idata->shm_id = 0;
727 768
728 return 0; 769 return 0;
729} 770}
@@ -891,6 +932,8 @@ _hash_image_entry_free(void *data)
891 { 932 {
892 _image_id_free(idata); 933 _image_id_free(idata);
893 _image_entry_free(ientry); 934 _image_entry_free(ientry);
935 _freed_image_entry_count++;
936 _repack();
894 } 937 }
895 else ERR("Could not find image entry %u", ENTRYID(ientry)); 938 else ERR("Could not find image entry %u", ENTRYID(ientry));
896} 939}
@@ -951,7 +994,7 @@ _hash_file_entry_free(void *data)
951 _file_data_free(fd); 994 _file_data_free(fd);
952 _file_entry_free(fentry); 995 _file_entry_free(fentry);
953 996
954 _freed_entry_count++; 997 _freed_file_entry_count++;
955 _repack(); 998 _repack();
956} 999}
957 1000
@@ -1165,6 +1208,7 @@ _entry_unused_push(Image_Entry *ientry)
1165 1208
1166 idata = _image_data_find(ENTRYID(ientry)); 1209 idata = _image_data_find(ENTRYID(ientry));
1167 if (!idata) return; 1210 if (!idata) return;
1211 idata->unused = EINA_TRUE;
1168 1212
1169 size = _image_entry_size_get(ientry); 1213 size = _image_entry_size_get(ientry);
1170 if ((size > max_unused_mem_usage) || !(idata->doload)) 1214 if ((size > max_unused_mem_usage) || !(idata->doload))
@@ -1191,7 +1235,6 @@ _entry_unused_push(Image_Entry *ientry)
1191 unused_mem_usage = 0; 1235 unused_mem_usage = 0;
1192 } 1236 }
1193 image_entries_lru = eina_list_append(image_entries_lru, ientry); 1237 image_entries_lru = eina_list_append(image_entries_lru, ientry);
1194 idata->unused = EINA_TRUE;
1195 unused_mem_usage += size; 1238 unused_mem_usage += size;
1196} 1239}
1197 1240
@@ -1303,6 +1346,13 @@ cserve2_cache_client_new(Client *client)
1303 client->files.referencing = eina_hash_int32_new(_entry_free_cb); 1346 client->files.referencing = eina_hash_int32_new(_entry_free_cb);
1304 client->images.referencing = eina_hash_int32_new(_entry_free_cb); 1347 client->images.referencing = eina_hash_int32_new(_entry_free_cb);
1305 client->fonts.referencing = NULL; 1348 client->fonts.referencing = NULL;
1349
1350 cserve2_index_list_send(cserve2_shared_strings_index_name_get(),
1351 cserve2_shared_strings_table_name_get(),
1352 cserve2_shared_array_name_get(_file_data_array),
1353 cserve2_shared_array_name_get(_image_data_array),
1354 NULL,
1355 client);
1306} 1356}
1307 1357
1308void 1358void
diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c
index 329ceeb4e2..6563872f5b 100644
--- a/src/bin/evas/evas_cserve2_index.c
+++ b/src/bin/evas/evas_cserve2_index.c
@@ -12,7 +12,6 @@
12#include <stdint.h> 12#include <stdint.h>
13 13
14typedef struct _Data_Shm Data_Shm; 14typedef struct _Data_Shm Data_Shm;
15typedef struct _Index_Entry Index_Entry;
16typedef struct _Block Block; 15typedef struct _Block Block;
17typedef struct _Shared_Index Shared_Index; 16typedef struct _Shared_Index Shared_Index;
18 17
@@ -60,16 +59,6 @@ struct _Block
60 int32_t shmid; 59 int32_t shmid;
61}; 60};
62 61
63struct _Index_Entry
64{
65 int32_t id; // Write last, can't be 0
66 int32_t refcount;
67 // Block entry
68 int32_t length;
69 int32_t offset;
70 int32_t shmid;
71};
72
73 62
74// Data blocks will be aligned to blocks of DATA_BLOCKSIZE bytes to reduce 63// Data blocks will be aligned to blocks of DATA_BLOCKSIZE bytes to reduce
75// fragmentation (after del). 16 is convenient for debugging with hd :) 64// fragmentation (after del). 16 is convenient for debugging with hd :)
@@ -159,7 +148,7 @@ _block_rbtree_block_find(const Block *node, const void *key,
159 148
160// Data shm 149// Data shm
161 150
162Data_Shm * 151static Data_Shm *
163_shared_data_shm_new(int size) 152_shared_data_shm_new(int size)
164{ 153{
165 Data_Shm *ds; 154 Data_Shm *ds;
@@ -194,7 +183,7 @@ _shared_data_shm_new(int size)
194 return ds; 183 return ds;
195} 184}
196 185
197void 186static void
198_shared_data_shm_del(Data_Shm *ds) 187_shared_data_shm_del(Data_Shm *ds)
199{ 188{
200 if (!ds) return; 189 if (!ds) return;
@@ -202,7 +191,7 @@ _shared_data_shm_del(Data_Shm *ds)
202 free(ds); 191 free(ds);
203} 192}
204 193
205int 194static int
206_shared_data_shm_resize(Data_Shm *ds, size_t newsize) 195_shared_data_shm_resize(Data_Shm *ds, size_t newsize)
207{ 196{
208 Shm_Handle *shm; 197 Shm_Handle *shm;
@@ -803,6 +792,24 @@ cserve2_shared_mempool_buffer_get(Shared_Mempool *sm, int bufferid)
803 792
804// Shared strings 793// Shared strings
805 794
795const char *
796cserve2_shared_strings_table_name_get()
797{
798 if (!_string_mempool)
799 return NULL;
800
801 return cserve2_shm_name_get(_string_mempool->ds->shm);
802}
803
804const char *
805cserve2_shared_strings_index_name_get()
806{
807 if (!_string_mempool)
808 return NULL;
809
810 return cserve2_shared_array_name_get(_string_mempool->index->sa);
811}
812
806int 813int
807cserve2_shared_string_add(const char *str) 814cserve2_shared_string_add(const char *str)
808{ 815{
diff --git a/src/bin/evas/evas_cserve2_main.c b/src/bin/evas/evas_cserve2_main.c
index 5982c0d297..ae4a80e854 100644
--- a/src/bin/evas/evas_cserve2_main.c
+++ b/src/bin/evas/evas_cserve2_main.c
@@ -36,17 +36,27 @@ cserve2_client_error_send(Client *client, unsigned int rid, int error_code)
36} 36}
37 37
38void 38void
39cserve2_index_list_send(const char *files_index_path, 39cserve2_index_list_send(const char *strings_index_path,
40 const char *strings_entries_path,
41 const char *files_index_path,
40 const char *images_index_path, 42 const char *images_index_path,
41 const char *fonts_index_path) 43 const char *fonts_index_path,
44 Client *client)
42{ 45{
43 Eina_Iterator *iter; 46 Eina_Iterator *iter;
44 Client *client;
45 Msg_Index_List msg; 47 Msg_Index_List msg;
46 const int size = sizeof(msg); 48 const int size = sizeof(msg);
47 49
50 INF("New shared index: strings: '%s':'%s' files: '%s' images: '%s', fonts: '%s'",
51 strings_index_path, strings_entries_path,
52 files_index_path, images_index_path, fonts_index_path);
53
48 memset(&msg, 0, size); 54 memset(&msg, 0, size);
49 msg.base.type = CSERVE2_INDEX_LIST; 55 msg.base.type = CSERVE2_INDEX_LIST;
56 if (strings_index_path)
57 eina_strlcpy(msg.strings_index_path, strings_index_path, 64);
58 if (strings_entries_path)
59 eina_strlcpy(msg.strings_entries_path, strings_entries_path, 64);
50 if (files_index_path) 60 if (files_index_path)
51 eina_strlcpy(msg.files_index_path, files_index_path, 64); 61 eina_strlcpy(msg.files_index_path, files_index_path, 64);
52 if (images_index_path) 62 if (images_index_path)
@@ -54,14 +64,23 @@ cserve2_index_list_send(const char *files_index_path,
54 if (fonts_index_path) 64 if (fonts_index_path)
55 eina_strlcpy(msg.fonts_index_path, fonts_index_path, 64); 65 eina_strlcpy(msg.fonts_index_path, fonts_index_path, 64);
56 66
57 iter = eina_hash_iterator_data_new(client_list); 67 if (!client)
58 EINA_ITERATOR_FOREACH(iter, client) 68 {
69 iter = eina_hash_iterator_data_new(client_list);
70 EINA_ITERATOR_FOREACH(iter, client)
71 {
72 DBG("Sending updated list of indexes to client %d", client->id);
73 cserve2_client_send(client, &size, sizeof(size));
74 cserve2_client_send(client, &msg, sizeof(msg));
75 }
76 eina_iterator_free(iter);
77 }
78 else
59 { 79 {
60 DBG("Sending updated list of indexes to client %d", client->id); 80 DBG("Sending updated list of indexes to client %d", client->id);
61 cserve2_client_send(client, &size, sizeof(size)); 81 cserve2_client_send(client, &size, sizeof(size));
62 cserve2_client_send(client, &msg, sizeof(msg)); 82 cserve2_client_send(client, &msg, sizeof(msg));
63 } 83 }
64 eina_iterator_free(iter);
65} 84}
66 85
67static void 86static void