Skip to content

wip: feat: multi-thread - #2847

Open
ekoops wants to merge 18 commits into
masterfrom
ekoops/multi-thread
Open

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

Conversation

@ekoops

@ekoops ekoops commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

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

poiana commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

[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

github-actions Bot commented Feb 19, 2026

Copy link
Copy Markdown

Perf diff from master - unit tests

    11.86%     -2.49%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    19.57%     +1.76%  [.] 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)
     8.35%     +0.97%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     4.35%     +0.84%  [.] thread_group_info::get_first_thread() const
    10.89%     -0.56%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
    12.20%     +0.52%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)
    15.72%     -0.40%  [.] sinsp_threadinfo::get_main_thread()
     4.21%     -0.37%  [.] sinsp_threadinfo::get_fd_table()
     0.66%     -0.16%  [.] sinsp_thread_manager::clear()
     0.02%     +0.15%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose()@plt

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.0024         +0.0025           290           290           289           290
BM_sinsp_split_median                                                                -0.0026         -0.0024           291           291           291           290
BM_sinsp_split_stddev                                                                -0.3139         -0.3093             6             4             6             4
BM_sinsp_split_cv                                                                    -0.3155         -0.3111             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                        -0.0438         -0.0437            81            78            81            78
BM_sinsp_concatenate_paths_relative_path_median                                      -0.0427         -0.0425            81            78            81            78
BM_sinsp_concatenate_paths_relative_path_stddev                                      -0.6142         -0.6140             1             0             1             0
BM_sinsp_concatenate_paths_relative_path_cv                                          -0.5965         -0.5963             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                           -0.0465         -0.0466            46            44            46            44
BM_sinsp_concatenate_paths_empty_path_median                                         -0.0447         -0.0447            46            44            46            44
BM_sinsp_concatenate_paths_empty_path_stddev                                        +19.8592        +20.3395             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                                            +20.8774        +21.3820             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                        -0.0446         -0.0444            81            78            81            77
BM_sinsp_concatenate_paths_absolute_path_median                                      -0.0186         -0.0179            79            77            79            77
BM_sinsp_concatenate_paths_absolute_path_stddev                                      -0.8641         -0.8624             4             0             4             0
BM_sinsp_concatenate_paths_absolute_path_cv                                          -0.8577         -0.8560             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_mean                                  -0.0013         -0.0011            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_median                                -0.0013         -0.0010            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_stddev                                +0.3028         +0.4545             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_cv                                    +0.3045         +0.4562             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_mean                                   +0.0009         +0.0010           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_median                                 +0.0007         +0.0008           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_stddev                                 +0.3850         +0.5553             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_cv                                     +0.3836         +0.5538             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_mean                              +0.0781         +0.0781            14            15            14            15
BM_sinsp_sanitize_string_fast_path_multibyte_short_median                            +0.0835         +0.0834            14            15            14            15
BM_sinsp_sanitize_string_fast_path_multibyte_short_stddev                            -0.9759         -0.9771             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_cv                                -0.9777         -0.9787             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_long_mean                               +0.1391         +0.1392          4938          5625          4936          5623
BM_sinsp_sanitize_string_fast_path_multibyte_long_median                             +0.1409         +0.1408          4930          5624          4928          5622
BM_sinsp_sanitize_string_fast_path_multibyte_long_stddev                             -0.9371         -0.9421            34             2            34             2
BM_sinsp_sanitize_string_fast_path_multibyte_long_cv                                 -0.9447         -0.9492             0             0             0             0
BM_sinsp_sanitize_string_fast_path_mixed_long_mean                                   -0.0765         -0.0765          2371          2190          2370          2189
BM_sinsp_sanitize_string_fast_path_mixed_long_median                                 -0.0751         -0.0751          2371          2193          2370          2192
BM_sinsp_sanitize_string_fast_path_mixed_long_stddev                                 -0.6351         -0.6326            49            18            49            18
BM_sinsp_sanitize_string_fast_path_mixed_long_cv                                     -0.6049         -0.6022             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_mean                       -0.0291         -0.0291          6005          5830          6002          5827
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_median                     -0.0577         -0.0575          6072          5722          6069          5719
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_stddev                     +0.5141         +0.5117           153           231           153           231
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_cv                         +0.5595         +0.5571             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_mean                     -0.0507         -0.0507          6017          5712          6015          5710
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_median                   -0.0682         -0.0681          6017          5606          6014          5605
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_stddev                  +86.5497        +80.1506             2           149             2           150
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_cv                      +91.2294        +84.4855             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_mean                    +0.0068         +0.0067           326           328           326           328
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_median                  +0.0069         +0.0069           325           327           325           327
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_stddev                  -0.3420         -0.3315             2             2             2             2
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_cv                      -0.3464         -0.3360             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_mean                  +0.0414         +0.0414           218           227           218           227
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_median                +0.0415         +0.0415           218           227           218           227
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_stddev                -0.5879         -0.5969             1             0             1             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_cv                    -0.6043         -0.6129             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_mean                       +0.0112         +0.0112         12464         12604         12460         12600
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_median                     +0.0199         +0.0201         12463         12711         12459         12709
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_stddev                    +23.9265        +26.4322             8           206             8           206
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_cv                        +23.6497        +26.1272             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_mean                     -0.0065         -0.0065         12265         12186         12261         12182
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_median                   -0.0204         -0.0205         12269         12019         12265         12014
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_stddev                  +16.8381        +16.6680            13           237            13           238
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_cv                      +16.9541        +16.7833             0             0             0             0

@codecov

codecov Bot commented Feb 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.84874% with 253 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.38%. Comparing base (af6e6f2) to head (d804508).

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.65%   75.38%   -0.28%     
==========================================
  Files         299      301       +2     
  Lines       32936    33096     +160     
  Branches     5118     5170      +52     
==========================================
+ Hits        24919    24950      +31     
- Misses       8017     8146     +129     
Flag Coverage Δ
libsinsp 75.38% <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 May 29, 2026 16:07
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.

5 participants