-
Notifications
You must be signed in to change notification settings - Fork 174
refactor(libsinsp): export static fields via static methods in threadinfo
and fdinfo
#2296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
07d4552
to
1cf9116
Compare
/approve |
Perf diff from master - unit tests
Heap diff from master - unit tests
Heap diff from master - scap file
Benchmarks diff from master
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2296 +/- ##
==========================================
- Coverage 77.17% 77.16% -0.02%
==========================================
Files 224 224
Lines 30133 30136 +3
Branches 4605 4605
==========================================
- Hits 23256 23255 -1
- Misses 6877 6881 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1cf9116
to
782ed13
Compare
@ekoops I took a look at how offsetof manages not to hit ubsan and it turns out that at least in my stdlib headers, it's a compiler builtin:
So I guess we'd have to explicitly pass the offset rather than a pointer inside a NULL-based struct. The downside is that offsetof doesn't have any type information. In my (unrelated) experiments, the best I came up with was a macro using |
Hi @gnosek , thank you for the help! I conducted similar experiments and approximately came out with the same conclusions. I'll still try to investigate the macro path, hoping there's a possible way to avoid creating and object. I'll also explore the other suggestion and update you |
I conducted some experiments and reached the following conclusions:
template<typename T>
constexpr static const field_info& define_static_field(field_infos& fields, size_t offset, const std::string& name, bool readonly = false)
define_static_field<int64_t>(ret, reinterpret_cast<size_t>(&static_cast<sinsp_threadinfo*>(0)->m_tid), "tid"); Notice: I stil don't understand why ubsan complains with auto ptr = static_cast<sinsp_threadinfo*>(0);
define_static_field<int64_t>(ret, reinterpret_cast<size_t>(&ptr->m_tid), "tid"); but doesn't complain for the aforementioned "inlined" approach...
define_static_field<decltype(static_cast<sinsp_threadinfo*>(0)->m_tid)>(...)
#define DEFINE_STATIC_FIELD_READONLY(field_infos, container_type, container_field, name, readonly) \
define_static_field<decltype(static_cast<container_type*>(0)->container_field)>( \
field_infos, \
reinterpret_cast<size_t>(&static_cast<container_type*>(0)->container_field), \
name, \
readonly);
#define DEFINE_STATIC_FIELD(field_infos, container_type, container_field, name) \
DEFINE_STATIC_FIELD_READONLY(field_infos, container_type, container_field, name, false)
DEFINE_STATIC_FIELD(ret, sinsp_threadinfo, m_pid, "tid"); |
3ae89e9
to
1fdc4ef
Compare
Make `define_static_field` constexpr static and directly provide the field offset. Introduce `OFFSETOF_STATIC_FIELD`, `DEFINE_STATIC_FIELD_READONLY` and `DEFINE_STATIC_FIELD` macros to hide the complexicity behind extracting the field type and offset needed for `define_static_field`. Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
1fdc4ef
to
c9b4cd4
Compare
threadinfo
and fdinfo
/cc @jasondellaluce FYI |
@FedeDP: GitHub didn't allow me to request PR reviews from the following users: FYI. Note that only falcosecurity members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: bc49dc98d5c1ced2d95d24d15ae52927df0f0849
|
a716131
to
32a5bdc
Compare
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
Signed-off-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com>
32a5bdc
to
48f0507
Compare
LGTM label has been added. Git tree hash: 0121213b94180658824f33b2a5c1346ce2c5c8c9
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, FedeDP, gnosek The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area libsinsp
Does this PR require a change in the driver versions?
What this PR does / why we need it:
This PR makes
define_static_field
constexpr static and allows to directly the field offset. It introducesOFFSETOF_STATIC_FIELD
,DEFINE_STATIC_FIELD_READONLY
andDEFINE_STATIC_FIELD
macros to hide the complexity behind extracting the field type and offset needed fordefine_static_field
. This foundation is used to define two additional static methods an additional static methodsinsp_threadinfo::get_static_fields()
that can be used for the global initialization ofs_threadinfo_static_fields
inthreadinfo.cpp
. This is useful to avoid instantiating asinsp_threadinfo
object to initializes_threadinfo_static_fields
, a preliminary step needed before isolating thesinsp_thread_manager
dependencies and passing them directly to its constructor. Moreover, to align the fdinfo implementation, this PR adds the static methodsinsp_fdinfo::get_static_fields()
to the fdinfo implementation.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: