On Fri, Apr 4, 2025, at 5:04 PM, Serhei Makarov wrote:
> Changes for v2:
>
> - Add locking for elftab. This is needed in addition to the
>   intrinsic locking in dynamicsizehash_concurrent to avoid
>   having cache_elf expose an incomplete dwfltracker_elf_info*
>   entry to other threads while its data is being populated /
>   replaced.
>
> - Tidy dwfl_process_tracker_find_elf.c into the main find_elf
>   callback and two functions to consider (in future) making into
>   a public api for custom cached callbacks.
Note: going to apply one nontrivial change to this patch -- taking dev/ino into 
account in the caching key,
to allow caching modules in container filesystems (which Sysprof accesses via 
/proc/PID/root).
The "/proc/PID/root/MODULE" path is unique per-process, so we need to cache by 
"MODULE+dev+ino"
in order to catch repeated instantiations of a module from a container image.

The concept is fairly clear, but I'm muddled on how to expose it in the public 
API.

Option 1: expose two find_cached_elf functions.

// normal use case
module_name = "/usr/lib/whatever.so";
dwfl_process_tracker_find_cached_elf (tracker, module_name, &file_name, &elf, 
&fd);
/* This will access the file at module_name */

// use case for executable in container
module_name = "/usr/lib/whatever.so";
file_name = "/proc/PID/root/usr/lib/whatever.so";
struct stat sb; stat (file_name, &sb);
dwfl_process_tracker_check_cached_elf_path (tracker, module_name,
    sb.st_dev, sb.st_ino, file_name, &elf, &fd);
/* This will access the file at file_name

Option 2: expose one function, treat file_name and fd as optional input 
parameters.

// normal use case
module_name = "/usr/lib/whatever.so"; /* name of module */
file_name = "/proc/PID/root/usr/lib/whatever.so"; /* actual location of module 
*/
dwfl_process_tracker_find_cached_elf (tracker, module_name, &file_name, &elf, 
&fd);
/* Since file_name is specified, the dwfl_process_tracker
   will access the module at file_name, and cache by
   module_name + dev + ino. */

Either way, Sysprof can include its own version of the 
dwfl_process_tracker_find_elf()
function (sysprof_live_process_find_elf) which calls these as appropriate.
I'm leaning towards Option 2 but wanted to present both for consideration.

Reply via email to