Skip to content

wip: feat: multi-thread#2847

Open
ekoops wants to merge 18 commits intomasterfrom
ekoops/multi-thread
Open

wip: feat: multi-thread#2847
ekoops wants to merge 18 commits intomasterfrom
ekoops/multi-thread

Conversation

@ekoops
Copy link
Copy Markdown
Contributor

@ekoops ekoops commented Feb 19, 2026

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind test

/kind feature

/kind sync

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-modern-bpf

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Initial attempt for multi-thread support.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Feb 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana requested a review from hbrueckner February 19, 2026 13:09
@poiana poiana added the kind/test PRs increasing the test coverage without fixing any failing test label Feb 19, 2026
@poiana poiana requested a review from terror96 February 19, 2026 13:09
@github-actions
Copy link
Copy Markdown

Please double check driver/API_VERSION file. See versioning.

/hold

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 19, 2026

Perf diff from master - unit tests

    11.01%     -1.38%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    13.65%     +1.23%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
    11.42%     +0.57%  [.] sinsp_threadinfo::get_main_thread()
     9.59%     -0.43%  [.] sinsp_threadinfo::update_main_fdtable()
     9.62%     -0.41%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
     7.76%     +0.37%  [.] sinsp_threadinfo::get_fd_table()
     3.67%     -0.33%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)
     6.69%     +0.22%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
    15.57%     +0.18%  [.] std::__shared_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     0.20%     -0.11%  [.] void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag)

Heap diff from master - unit tests

peak heap memory consumption: -355B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: -923B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                                       Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                                          -0.0072         -0.0072           240           238           240           238
BM_sinsp_split_median                                                        -0.0062         -0.0059           240           239           240           238
BM_sinsp_split_stddev                                                        +0.0730         +0.0503             2             2             2             2
BM_sinsp_split_cv                                                            +0.0808         +0.0580             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                -0.0683         -0.0683            80            75            80            75
BM_sinsp_concatenate_paths_relative_path_median                              -0.0679         -0.0680            80            75            80            75
BM_sinsp_concatenate_paths_relative_path_stddev                              +0.2151         +0.1802             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_cv                                  +0.3042         +0.2668             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                   -0.0179         -0.0180            44            43            44            43
BM_sinsp_concatenate_paths_empty_path_median                                 +0.0001         +0.0004            44            44            44            44
BM_sinsp_concatenate_paths_empty_path_stddev                                +66.5509        +75.2484             0             1             0             1
BM_sinsp_concatenate_paths_empty_path_cv                                    +67.7826        +76.6464             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                -0.0672         -0.0672            84            78            84            78
BM_sinsp_concatenate_paths_absolute_path_median                              -0.0661         -0.0660            84            78            84            78
BM_sinsp_concatenate_paths_absolute_path_stddev                              -0.2221         -0.2246             1             0             0             0
BM_sinsp_concatenate_paths_absolute_path_cv                                  -0.1661         -0.1687             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_mean                          -0.0016         -0.0017            16            16            16            16
BM_sinsp_sanitize_string_fast_path_ascii_short_median                        -0.0010         -0.0009            16            16            16            16
BM_sinsp_sanitize_string_fast_path_ascii_short_stddev                        -0.7621         -0.7883             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_cv                            -0.7617         -0.7879             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_mean                           -0.0045         -0.0043           164           164           164           164
BM_sinsp_sanitize_string_fast_path_ascii_long_median                         -0.0054         -0.0053           165           164           164           164
BM_sinsp_sanitize_string_fast_path_ascii_long_stddev                         -0.7078         -0.7097             1             0             1             0
BM_sinsp_sanitize_string_fast_path_ascii_long_cv                             -0.7065         -0.7084             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_mean                      +0.0076         +0.0074            12            12            12            12
BM_sinsp_sanitize_string_fast_path_multibyte_short_median                    -0.0001         -0.0000            12            12            12            12
BM_sinsp_sanitize_string_fast_path_multibyte_short_stddev                    +0.0281         +0.0221             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_cv                        +0.0204         +0.0146             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_long_mean                       +0.0007         +0.0007          4862          4865          4860          4864
BM_sinsp_sanitize_string_fast_path_multibyte_long_median                     +0.0005         +0.0007          4862          4864          4860          4863
BM_sinsp_sanitize_string_fast_path_multibyte_long_stddev                     +0.2330         +0.1796             2             3             2             2
BM_sinsp_sanitize_string_fast_path_multibyte_long_cv                         +0.2322         +0.1788             0             0             0             0
BM_sinsp_sanitize_string_fast_path_mixed_long_mean                           -0.0007         -0.0007          2052          2050          2051          2050
BM_sinsp_sanitize_string_fast_path_mixed_long_median                         -0.0040         -0.0041          2052          2044          2051          2043
BM_sinsp_sanitize_string_fast_path_mixed_long_stddev                         +9.7919         +9.4942             4            43             4            43
BM_sinsp_sanitize_string_fast_path_mixed_long_cv                             +9.7996         +9.5015             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_mean                     +0.0168         +0.0171          6921          7038          6925          7044
BM_sinsp_sanitize_string_slow_path_c1_controls_long_median                   -0.0003         -0.0001          7112          7110          7117          7116
BM_sinsp_sanitize_string_slow_path_c1_controls_long_stddev                   -0.5417         -0.5406           281           129           281           129
BM_sinsp_sanitize_string_slow_path_c1_controls_long_cv                       -0.5492         -0.5484             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_mean                  -0.0028         -0.0017          1068          1064          1073          1071
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_median                -0.0036         -0.0025          1070          1066          1076          1073
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_stddev                -0.1112         -0.0746            11            10            12            11
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_cv                    -0.1087         -0.0730             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_mean                     -0.0002         -0.0000         13904         13900         13904         13903
BM_sinsp_sanitize_string_slow_path_all_invalid_long_median                   +0.0008         +0.0009         13904         13915         13905         13919
BM_sinsp_sanitize_string_slow_path_all_invalid_long_stddev                   +0.0127         +0.0371            33            33            32            33
BM_sinsp_sanitize_string_slow_path_all_invalid_long_cv                       +0.0129         +0.0371             0             0             0             0

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 46.84874% with 253 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.79%. Comparing base (01e1503) to head (7b47680).

Files with missing lines Patch % Lines
userspace/libsinsp/examples/test.cpp 0.00% 199 Missing ⚠️
userspace/libsinsp/sinsp.cpp 71.42% 26 Missing ⚠️
userspace/libsinsp/parsers.cpp 82.78% 21 Missing ⚠️
userspace/libsinsp/examples/perftest.cpp 0.00% 2 Missing ⚠️
userspace/libsinsp/sinsp.h 66.66% 2 Missing ⚠️
userspace/libsinsp/sinsp_buffer.h 92.00% 2 Missing ⚠️
userspace/libsinsp/parsers.h 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2847      +/-   ##
==========================================
- Coverage   75.07%   74.79%   -0.28%     
==========================================
  Files         297      299       +2     
  Lines       31800    31960     +160     
  Branches     5013     5065      +52     
==========================================
+ Hits        23875    23906      +31     
- Misses       7925     8054     +129     
Flag Coverage Δ
libsinsp 74.79% <46.84%> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@irozzo-1A irozzo-1A force-pushed the ekoops/multi-thread branch 6 times, most recently from a5a9e97 to f012841 Compare February 20, 2026 09:30
@ekoops ekoops force-pushed the ekoops/multi-thread branch 8 times, most recently from 44bd717 to c6f6d4c Compare March 19, 2026 09:50
@ekoops ekoops force-pushed the ekoops/multi-thread branch 2 times, most recently from 79332df to 2cb8232 Compare March 20, 2026 13:07
@ekoops ekoops force-pushed the ekoops/multi-thread branch 2 times, most recently from d99382b to a4acc62 Compare March 31, 2026 09:12
ekoops and others added 18 commits April 23, 2026 16:33
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
guard scap_modern_bpf_engine with HAS_ENGINE_MODERN_BPF, fix atomic_fetch_add
to use address of counter, add missing return for is_multiple_workers_mode_enabled

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Add missing terminating quotes to buffers-num option description string literals

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
/home/runner/work/libs/libs/userspace/libsinsp/parsers.h:39:1: error: 'sinsp_parser_shared_params' defined as a struct here but previously declared as a class; this is valid, but may result in linker errors under the Microsoft C++ ABI [-Werror,-Wmismatched-tags]
   39 | struct sinsp_parser_shared_params {
      | ^
/home/runner/work/libs/libs/userspace/libsinsp/sinsp.h:96:1: note: did you mean struct here?
   96 | class sinsp_parser_shared_params;
      | ^~~~~
      | struct
/home/runner/work/libs/libs/userspace/libsinsp/sinsp_buffer.h:27:1: note: did you mean struct here?
   27 | class sinsp_parser_shared_params;
      | ^~~~~
      | struct
1 error generated

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
open_common() called init() before allocating m_buffers. init() runs
consume_initialstate_events() when is_capture(), which uses
m_buffers.at(SINSP_INVALID_BUFFER_HANDLE). With an empty m_buffers this
threw std::out_of_range when opening a savefile (e.g. in plugin_dump test).

Move the m_buffers allocation block to before init() so the default buffer
exists when consume_initialstate_events() runs.

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Force reset of last_access_time in remove_inactive_threads method of
sinsp_with_test_input.

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
error:  "C atomics require C11 or later"

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Signed-off-by: irozzo-1A <iacopo@sysdig.com>
Extend BPF iterator logic to be useful in multi-thread mode.
Specifically, BPF iterator maps have different shapes depending on the
number of "maximum allowed iterator threads" (that is specified at
probe initialization through a `iters_num` parameter):
- if there is at most a single iterator, these will be array maps with
  a single entry;
- otherwise, they will be hash maps with an entry for each iterator,
  indexed by the thread id of the iterator thread.

Before starting event fetching, the implementation checks if it is the
first time that the calling thread uses one of the `pman_fetch_*`
APIs and, if it is, initializes maps to take the new ecountered thread
into account (specifically, this means that both `iter_auxiliary_map`
and `iter_counters_map` are initialized).

Iterator maps initialization is done from userspace, and leverages
thread local flags and atomic counters to ensure maps are not
initialized twice for the same thread, and that no more than
`iters_num` different threads will ever call `pman_fetch_*` APIs.

In multi-thread mode, iterator maps initialization is done by adding a
new entry for each encountered new thread to each map. Entries' values
are initialized leveraging zeroed values allocated in static memory.

In single-thread mode, the array map has simply a pre-initialized
single entry, and no additional work is required when the single
thread is encountered for the first time.

The whole design makes the switch between single- and multi-thread
mode transparent to users, apart from the `iters_num` probe parameter:
this must be evaluated in advance, and include any thread that will
ever use any `fetch_*` API.

Each iterator metric is the result of the sum of the corresponding
counters on each `iter_counters_map` entry.

Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants