Commit Graph

35 Commits

Author SHA1 Message Date
Marcel Hollerbach 1b39c772ea eina: prefetch for _eo_obj_pointer_get
Reviewers: raster, stefan_schmidt

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D11603
2020-03-26 16:42:46 +00:00
Jean-Philippe Andre 5a98f78ce8 eo: Improve invalid EO ID error message
This focus on the domain and ID bits is very confusing. Let's
keep it at the end of the message, and also try to guess whether
the object may have been deleted or simply doesn't belong to the
current thread.
2017-06-22 13:19:23 +09:00
Carsten Haitzler 1d0b37a9e6 eo - eoid - finally rtemove option to not have eoid. it doesn't work
we use too many bits for metadata now so eoid is broken... remove it
as an option so people dont break out the foot guns
2017-05-17 15:04:01 +09:00
Jean-Philippe Andre 9a81165830 eo: Remove super bit from eo id
It is not required anymore as the super class and super bit can
be stored inside the object data. See the previous patches.
2017-04-19 11:41:15 +09:00
Jean-Philippe Andre 9dc0a15499 eo: Make _eo_obj_pointer_done an inline function
@optimization
2017-02-21 10:52:39 +09:00
Gustavo Sverzut Barbieri 227463bdde eo: allow valgrind-like tracking of object lifecycle.
Eo pointer indirection is super nice as it avoids you to access
invalid memory, but this extra checks inhibits valgrind's own tracking
of memory lifecycle, usually it would report when the object was
created and when the object is deleted, both as stack traces.

This commits introduces logging of object creation and destruction
under its own eina_log_domain and controlled by EO_LIFECYCLE_DEBUG and
EO_LIFECYCLE_NO_DEBUG envvars. These will only be available if
compiled with EO_DEBUG, thus shouldn't cause any performance hits on
production code.

Running a bogus app with invalid efl_class_name_get() and double
efl_del() will report as below:

```sh
$ export EO_LIFECYCLE_NO_DEBUG=Efl_Loop_Timer,Efl_Promise,Efl_Future
$ export EO_LIFECYCLE_DEBUG=1
$ export EINA_LOG_LEVELS=eo_lifecycle:4
$ /tmp/bogus_app
DBG:eo_lifecycle lib/eo/eo.c:2712 _eo_log_obj_init() will log all object allocation and free
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Future'
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Promise'
DBG:eo_lifecycle lib/eo/eo.c:2788 _eo_log_obj_init() will NOT log class 'Efl_Loop_Timer'
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35a1aa0 obj_id=0x4000000002cf38ef class=0x563fa35a1450 (Efl_Vpath_Core) [0.0004]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35af8d0 obj_id=0x4000000006cf38f0 class=0x563fa35aecf0 (Efl_Loop) [0.0005]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d61a0 obj_id=0x400000007ecf390e class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0054]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d6470 obj_id=0x4000000082cf390f class=0x563fa35d0d60 (Efl_Net_Dialer_Tcp) [0.0055]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d75b0 obj_id=0x4000000086cf3910 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0056]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35d8f70 obj_id=0x400000008acf3911 class=0x563fa35d7860 (Efl_Io_Copier) [0.0057]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35df980 obj_id=0x40000000a6cf3918 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0058]
DBG:eo_lifecycle lib/eo/eo.c:2665 _eo_log_obj_new() new obj=0x563fa35dfc30 obj_id=0x40000000aacf3919 class=0x563fa35d7860 (Efl_Io_Copier) [0.0058]

will efl_class_name_get() with invalid handle:

ERR:eo lib/eo/eo.c:1013 efl_class_name_get() Class (0x2000000000000029) is an invalid ref.
ERR:eo_lifecycle lib/eo/eo.c:1013 efl_class_name_get() obj_id=0x2000000000000029 was neither created or deleted (EO_LIFECYCLE_NO_DEBUG='Efl_Loop_Timer,Efl_Promise,Efl_Future').
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35df980 obj_id=0x40000000a6cf3918 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35dfc30 obj_id=0x40000000aacf3919 class=0x563fa35d7860 (Efl_Io_Copier) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d75b0 obj_id=0x4000000086cf3910 class=0x563fa35d66b0 (Efl_Io_Queue) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d8f70 obj_id=0x400000008acf3911 class=0x563fa35d7860 (Efl_Io_Copier) [0.0061]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d6470 obj_id=0x4000000082cf390f class=0x563fa35d0d60 (Efl_Net_Dialer_Tcp) [0.0063]
DBG:eo_lifecycle lib/eo/eo.c:2688 _eo_log_obj_free() free obj=0x563fa35d61a0 obj_id=0x400000007ecf390e class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0063]

will double free:

ERR:eo ../src/lib/eo/efl_object.eo.c:78 efl_del() EOID 0x400000007ecf390e is not a valid object. EOID domain=0, current_domain=0, local_domain=0. EOID generation=2cf390e, id=1f, ref=1, super=0. Thread self=main. Available domains [0 1    ]. Maybe it has been deleted or does not belong to your thread?
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e created obj=0x563fa35d61a0, class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0054s, 0.0009 ago]:
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d0ea: libeo_dbg.so+0x90ea (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6ca62: _efl_add_internal_start+0x1c2 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc95f: bogus_app+0x295f (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0ace7291: __libc_start_main+0xf1 (in /usr/lib/libc.so.6 0x7f2c0acc7000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc48a: _start+0x2a (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e deleted obj=0x563fa35d61a0, class=0x563fa35d48f0 (Efl_Net_Dialer_Simple) [0.0063s, 0.0000 ago]:
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d8ba: libeo_dbg.so+0x98ba (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6d711: libeo_dbg.so+0x9711 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6beb8: libeo_dbg.so+0x7eb8 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc6c06e: _efl_object_call_end+0x4e (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0bc75725: efl_del+0x105 (in src/lib/eo/.libs/libeo_dbg.so 0x7f2c0bc64000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dcd54: lt-efl_net_dialer_simple_example+0x2d54 (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x007f2c0ace7291: __libc_start_main+0xf1 (in /usr/lib/libc.so.6 0x7f2c0acc7000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del()    0x00563fa15dc48a: _start+0x2a (in /tmp/bogus_app 0x563fa15da000)
ERR:eo_lifecycle ../src/lib/eo/efl_object.eo.c:78 efl_del() obj_id=0x400000007ecf390e was already deleted 0.0000 seconds ago!
```
2016-12-02 21:15:17 -02:00
Gustavo Sverzut Barbieri dfe3a4ad40 eo: improve logs by always showing event source, minor refactor.
Instead of 2 sets of macro, one for HAVE_EO_ID and another without,
use a single set of macros and have the implementation of
_eo_class_pointer_get() and _eo_obj_pointer_get() to do the actual

These functions now take the source information so the logs reflect
that and not always the same function.
2016-12-02 21:15:17 -02:00
Gustavo Sverzut Barbieri 216e6e51e4 eo: better error reporting, always provide caller/source when available.
_eo_pointer_error() was kinda a bitch to debug as it provided a nice
breakpoint location, but did not provide a good output since the file,
line and function were always the same.

Change that to be a thin wrapper on top of eina_log_vprint(), then we
keep the breakpoint location yet provide useful information.

In that sense, change other error messages so they carry as much
information as possible.
2016-12-02 14:50:45 -02:00
Carsten Haitzler 7b3e7ecc1f eo - eo ptr lookup - do some prefetches to get some micro-speedups
prefetching a bit helps.. a bit like 0.2% or so... but it does help. :)
2016-10-01 23:37:34 +09:00
Carsten Haitzler 0f929f5546 eo id and shared domain objects - do locking properly and better
so there were a few issues. one we had a spinlokc on the eoid table
for shared objects AND then had a mutex for accessing those objects
(released on return from any eo function). BUT this missed some funcs
like eo_ref, eo_unref and so on in eo.c ... oops. so fixed. but then i
realized there was a race condition. we locked the eoid table then
unlocked with our pointer THEN locked the sharted object mutex ...
then unlocked it. that was a race condtion gap. so we should share the
same lock anyway - if it's a shared object, grab the shared object
mutex then do a lookup and if the lookup does not fail, KEEP the lock
until it is released by the return from eo function or by some special
macro/funcs that released a matching lock. since its a recursive lock
this is all fine. as its also a universal single lock for all objects
we just need the eoid to know if it's shared and needs locking based
on the domain bits. so now do this locking properly with just a single
mutex, not both a spinlock and mutex and keep the lock around until
totally done with the object. this plugs the race condition holes and
goes from 1 spinlock lock and unlock then a mutex lock and unlokc to
just a single mutex lock and unlock. this means shared objects are
actually truly safe across threads and only have the overhead of a
single recursive mutex to lock and unlock in every api call.
2016-09-28 13:38:46 +09:00
Carsten Haitzler ccbf537191 eo ptr indir - handle unlock on error with shared eoids correctly
this fixes the error handling for shared objects which would fail to
unlock on lookup error.
2016-09-26 09:16:21 +09:00
Carsten Haitzler 50d508866e eo invalid err - make the thread self more useful like main. 2016-09-17 05:49:32 +09:00
Carsten Haitzler 60f84b733a eo - id lookup failure expansive error print for ebbter debug
whenan eoid lookup fails, now print a lot of information on the issue
like the actual id, generation of the id, if its a class or object
(the class bit), if its ref or super bit is set, the actual id (which
includes the table heirachy), which thread id it is, what domain the
object id is and the current and local domains as well as what domains
are mapped in.
2016-09-16 18:51:22 +09:00
Carsten Haitzler 8b159aab68 eo - move eoid lookup to ptr indir file and clean up some code
this improves the readability of some of the new domain related and
ptr indir code..
2016-09-09 18:53:20 +09:00
Carsten Haitzler 09f19c3c73 eo - make eo id table TLS private data for thread safety and speed
This moved all the eoid tables, eoid lookup caches, generation count
information ad eo_isa cache into a TLS segment of memory that is
thread private. There is also a shared domain for EO objects that all
threads can access, but it has an added cost of a lock. This means
objects accessed outside the thread they were created in cannot be
accessed by another thread unless they are adopted in temporarily, or
create4d with the shared domain active at the time of creation. child
objects will use their parent object domain if created with a parent
object passed in. If you were accessing EO (EFL) objects across threads
before then this will actually now cause your code to fail as it was
invalid before to do this as no actual objects were threadsafe in EFL,
so this will force things to "fail early".
ecore_thread_main_loop_begin() and end() still work as this uses the
eo domain adoption features to temporarily adopt a domain during this
section and then return it when done.

This returns speed back to eo brining the overhead in my tests of
lookup for the elm genlist autobounce test in elementary from about
5-7% down to 2.5-2.6%. A steep drop.

This does not mean everything is perfect. Still to do are:

1. Tests in the test suite
2. Some API's to help for sending objects from thread to thread
3. Make the eo call cache TLS data to make it also safe
4. Look at other locks in eo and probably move them to TLS data
5. Make eo resolve and call wrappers that call the real method func do
   recursive mutex wrapping of the given object IF it is a shared object
   to provide threadsafety transparently for shared objects (but adding
   some overhead as a result)
6. Test test est, and that is why this commit is going in now for wider
   testing
7. Decide how to make this work with sending IPC (between threads)
8. Deciding what makes an object sendable (a sendable property in base?)
9. Deciding what makes an object shareable (a sharable property in base?)
2016-09-07 18:17:10 +09:00
Jean-Philippe Andre 0dd9e02df2 Eo: Add internal function call on pointer errors
Useful for GDB: break on this function when things go wrong.
Similar to eina_safety.

I guess we could set some Eina_Error and maybe even have error
callbacks for easier application debugging. Later.
2015-12-29 20:55:50 +09:00
Cedric Bail c435968f69 eo: a little more inlining, give me a 10% speed improvement. 2013-07-01 18:18:40 +09:00
Jérémy Zurcher 6667acf5a2 eo ptr ind: fix comments 2013-05-17 11:39:01 +02:00
Jérémy Zurcher f253cfc12c eo ptr ind: empty tables are freed except 1 kept as spare
- this reduces unused memory usage
- the spare table avoids the free/alloc corner case
2013-05-17 10:35:16 +02:00
Jérémy Zurcher 3e4127da52 eo ptr ind: current_table -> _current_table 2013-05-17 09:23:00 +02:00
Jérémy Zurcher 5244c20118 eo ptr ind: store partial Eo Id in the table
- very small speed up
- maybe later use this to avoid table indexes not NULL checks
  in _eo_id_release and _eo_obj_pointer_get
2013-05-16 15:00:08 +02:00
Jérémy Zurcher f2efa26459 eo ptr ind: use of mprotect when EINA_DEBUG_MALLOC is set
- to enable this feature, compile with --with-profile=debug
- the mid tables and tables are write protected after modifications,
  you will segfault if you mess with them
2013-05-16 13:17:12 +02:00
Jérémy Zurcher 380435abdb eo ptr ind: set generation counter range to [1;max-1]
- so we never generate an Eo Id equal to 0,
  thus don't need to skip the first top table index anymore
2013-05-16 13:17:12 +02:00
Jérémy Zurcher 00af0e77e3 eo ptr ind: minimize amount of wasted memory
- because of mmap PAGE_SIZE alignement and added magic header, almost a
  memory page is wasted per table and mid table allocation.
- reducing the number of tables per mid table and the number of entries
  per table solves this.
2013-05-16 13:17:11 +02:00
Jérémy Zurcher a9e69d519c eo ptr ind: mostly cosmetic
- add and use SHIFT_* macros
- rename queue into fifo
- try to clarify the structure top table -> mid table -> table[entry]
2013-05-16 13:17:11 +02:00
Jérémy Zurcher 4e88ad4dd6 eo ptr in: follow naming convention for static fcts 2013-05-05 18:19:14 +02:00
Jérémy Zurcher 94b6dff74c eo ptr ind: speed up by caching last used table
- keep a reference to the last used table and it's indexes
   - use this table prior to normal search through table arrays
2013-05-05 15:18:01 +02:00
Jérémy Zurcher 10aafd711d eo ptr ind: fix indentation 2013-05-05 15:18:01 +02:00
Jérémy Zurcher f769128dca eo ptr ind: pack memory, use in mmap fifo as recycle trash
- pack active flag and generation nbr in an _Eo_Id_Entry struct
  - replace Eina_Trash with a fifo which lives in mmaped memory owned by eo_id.
  - fifo uses indexes instead of pointers to spare memory
  - never used entries are served first, then those in the fifo
    are reused, thus we ensure that a freed entry won't soon be reused.
2013-05-03 21:28:32 +02:00
Jérémy Zurcher 994318eebe eo_ptr_ind: pack ptr, active flag and generation all together
use of an array of the below struct instead of 3 separate arrays
leads to better cache performance and smaller memory usage
typedef struct
{
  _Eo *ptr;
  unsigned int active     : 1;
  unsigned int generation : BITS_FOR_GENERATION_COUNTER;
} _Eo_Id_Entry;
2013-04-28 00:43:53 +02:00
Jérémy Zurcher 41dc1764f3 eo_ptr_ind: fix hdr->size in _eo_id_mem_alloc 2013-04-28 00:17:07 +02:00
Carsten Haitzler 76a748b08d rejig 32bit eoid allocation to 5.5.12. 2013-04-24 16:20:18 +09:00
Carsten Haitzler 4cf68bf728 eoid -> use mmap for allocating id tables. makes it a separate memory
regions with page separations... this allows us more direct control
over access and visibility.
2013-04-23 23:39:37 +09:00
Carsten Haitzler c9ad644be2 eoid -> rjid 64bit bit allocations for.. not so much bloat. 2013-04-23 23:39:37 +09:00
Daniel Zaoui 337fac0e73 Eo: pointers indirection mechanism for objects and classes
Summary: This feature replaces Eo pointers with ids to prevent bad usage
or reuse of these pointers. It doesn't change API.
The mechanism uses tables storing the real pointers to the objects.
See the src/lib/eo/eo_ptr_indirection.c file for more details on the
mechanism.
2013-04-23 09:50:40 +03:00