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
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

    16.52%     +4.13%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    17.68%     -2.69%  [.] sinsp_threadinfo::get_main_thread()
     3.27%     +2.47%  [.] sinsp_threadinfo::get_fd_table()
    16.89%     -1.68%  [.] 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)
     6.44%     -1.46%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     9.71%     -0.85%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)
     5.07%     +0.67%  [.] thread_group_info::get_first_thread() const
    10.88%     -0.29%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
     0.13%     -0.08%  [.] strlen@plt
     6.98%     -0.08%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)

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.0278         +0.0280           271           278           271           278
BM_sinsp_split_median                                                                +0.0307         +0.0311           270           278           270           278
BM_sinsp_split_stddev                                                                -0.4341         -0.4355             3             2             3             2
BM_sinsp_split_cv                                                                    -0.4494         -0.4509             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                        -0.0623         -0.0622            79            74            79            74
BM_sinsp_concatenate_paths_relative_path_median                                      -0.0701         -0.0700            79            73            79            73
BM_sinsp_concatenate_paths_relative_path_stddev                                      +3.8112         +3.8619             0             2             0             2
BM_sinsp_concatenate_paths_relative_path_cv                                          +4.1307         +4.1845             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                           +0.0135         +0.0135            45            46            45            46
BM_sinsp_concatenate_paths_empty_path_median                                         +0.0135         +0.0135            45            46            45            46
BM_sinsp_concatenate_paths_empty_path_stddev                                         +0.4680         +0.6285             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                                             +0.4484         +0.6068             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                        -0.0383         -0.0383            78            75            78            75
BM_sinsp_concatenate_paths_absolute_path_median                                      -0.0183         -0.0182            78            76            77            76
BM_sinsp_concatenate_paths_absolute_path_stddev                                      +3.0283         +3.0604             1             2             1             2
BM_sinsp_concatenate_paths_absolute_path_cv                                          +3.1887         +3.2222             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_mean                                  +0.0300         +0.0299            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_median                                +0.0024         +0.0020            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_stddev                                +5.7495         +5.7234             0             1             0             1
BM_sinsp_sanitize_string_fast_path_ascii_short_cv                                    +5.5527         +5.5284             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_mean                                   +0.0038         +0.0040           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_median                                 +0.0038         +0.0040           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_stddev                                 -0.1830         +0.0555             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_cv                                     -0.1861         +0.0512             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_mean                              +0.0842         +0.0842            14            15            14            15
BM_sinsp_sanitize_string_fast_path_multibyte_short_median                            +0.0645         +0.0644            14            15            14            15
BM_sinsp_sanitize_string_fast_path_multibyte_short_stddev                            -0.4022         -0.4002             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_cv                                -0.4486         -0.4468             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_long_mean                               +0.1351         +0.1351          4954          5623          4952          5621
BM_sinsp_sanitize_string_fast_path_multibyte_long_median                             +0.1389         +0.1389          4935          5620          4933          5618
BM_sinsp_sanitize_string_fast_path_multibyte_long_stddev                             -0.6800         -0.6742            36            11            36            12
BM_sinsp_sanitize_string_fast_path_multibyte_long_cv                                 -0.7181         -0.7129             0             0             0             0
BM_sinsp_sanitize_string_fast_path_mixed_long_mean                                   -0.0724         -0.0724          2341          2172          2340          2171
BM_sinsp_sanitize_string_fast_path_mixed_long_median                                 -0.0680         -0.0677          2335          2176          2334          2176
BM_sinsp_sanitize_string_fast_path_mixed_long_stddev                                 -0.3470         -0.3425            18            12            18            12
BM_sinsp_sanitize_string_fast_path_mixed_long_cv                                     -0.2961         -0.2912             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_mean                       +0.0330         +0.0328          5941          6137          5939          6134
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_median                     -0.0177         -0.0180          6136          6028          6135          6025
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_stddev                     -0.4568         -0.4559           285           155           285           155
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_cv                         -0.4741         -0.4732             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_mean                     +0.0319         +0.0318          6019          6211          6017          6208
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_median                   +0.0319         +0.0318          6019          6211          6017          6208
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_stddev                   -0.1521         +0.0803             2             2             1             1
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_cv                       -0.1784         +0.0471             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_mean                    -0.0023         -0.0023           328           327           328           327
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_median                  -0.0030         -0.0031           327           326           327           326
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_stddev                  +0.3989         +0.3804             2             2             2             2
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_cv                      +0.4022         +0.3836             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_mean                  +0.0473         +0.0473           220           231           220           230
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_median                +0.0478         +0.0477           220           231           220           231
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_stddev                -0.3739         -0.3746             1             1             1             1
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_cv                    -0.4022         -0.4028             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_mean                       +0.0208         +0.0208         12455         12714         12451         12710
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_median                     +0.0216         +0.0217         12454         12723         12450         12720
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_stddev                    +49.5665        +53.9287             6           317             6           316
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_cv                        +48.5365        +52.8099             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_mean                     -0.0630         -0.0631         12244         11474         12240         11468
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_median                   -0.0657         -0.0665         12243         11439         12239         11426
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_stddev                  +48.8251        +60.0907             5           248             4           249
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_cv                      +52.1725        +64.2029             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 75.49%. Comparing base (b1e3a8b) to head (c3ab57b).

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.76%   75.49%   -0.28%     
==========================================
  Files         299      301       +2     
  Lines       33099    33259     +160     
  Branches     5126     5178      +52     
==========================================
+ Hits        25079    25110      +31     
- Misses       8020     8149     +129     
Flag Coverage Δ
libsinsp 75.49% <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 19, 2026 17:29
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