cleanup: drop capture_enabled flag from driver#709
Conversation
|
@FedeDP: The label(s) DetailsIn 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/test-infra repository. |
capture_enabled flag from drivercapture_enabled flag from driver
capture_enabled flag from drivercapture_enabled flag from driver
| @@ -1 +1 @@ | |||
| 2.0.0 | |||
| 3.0.0 | |||
There was a problem hiding this comment.
We changed how scap tells drivers to start/stop the capture.
| struct scap_bpf_settings *settings, | ||
| enum syscall_flags drop_flags) | ||
| { | ||
| struct scap_bpf_settings *settings; |
There was a problem hiding this comment.
Moved the retrieval of bpf settings down to call_filler as it is now unused in attached programs.
| uint16_t statsd_port; | ||
| unsigned long buffer_bytes_dim; /* Every consumer will have its per-CPU buffer dim in bytes. */ | ||
| DECLARE_BITMAP(events_mask, PPM_EVENT_MAX); | ||
| u32 tracepoints_attached; |
There was a problem hiding this comment.
Every consumer owns its own tracepoint mask.
|
|
||
| #ifndef UDIG | ||
| struct ppm_consumer_t { | ||
| unsigned int id; // numeric id for the consumer (ie: registration index) |
There was a problem hiding this comment.
This is the consumer index (ie: the first added will have 0, the second 1...).
| m_event_type = event_type; | ||
| switch(event_type) | ||
| m_event_direction = BOTH_EVENT; | ||
| switch(m_event_type) |
There was a problem hiding this comment.
Now it is enable_capture job to attach required tracepoints.
| event_data.event_info.context_data.sched_next = (void *)0; | ||
|
|
||
| record_event_consumer(consumer, PPME_SCAPEVENT_E, UF_NEVER_DROP, ppm_nsecs(), &event_data); | ||
| record_event_consumer(consumer, PPME_SCAPEVENT_E, UF_NEVER_DROP, ppm_nsecs(), &event_data, TP_VAL_INTERNAL); |
There was a problem hiding this comment.
Internal event; use canary value for tp.
| struct event_data_t event_data = {0}; | ||
|
|
||
| if (record_event_consumer(consumer, PPME_DROP_E, UF_NEVER_DROP, ns, &event_data) == 0) { | ||
| if (record_event_consumer(consumer, PPME_DROP_E, UF_NEVER_DROP, ns, &event_data, TP_VAL_INTERNAL) == 0) { |
There was a problem hiding this comment.
Internal event; use canary value for tp.
| struct event_data_t event_data = {0}; | ||
|
|
||
| if (record_event_consumer(consumer, PPME_DROP_X, UF_NEVER_DROP, ns, &event_data) == 0) { | ||
| if (record_event_consumer(consumer, PPME_DROP_X, UF_NEVER_DROP, ns, &event_data, TP_VAL_INTERNAL) == 0) { |
There was a problem hiding this comment.
Internal event; use canary value for tp.
| int32_t cbres = PPM_SUCCESS; | ||
| int cpu; | ||
|
|
||
| if (tp_type < TP_VAL_INTERNAL && !(consumer->tracepoints_attached & (1 << tp_type))) |
There was a problem hiding this comment.
Check if the consumer is attached to the tracepoint, or if the tracepoint is a canary value.
| event_data.event_info.context_data.sched_prev = (void *)cpu; | ||
| event_data.event_info.context_data.sched_next = (void *)sd_action; | ||
| record_event_all_consumers(PPME_CPU_HOTPLUG_E, UF_NEVER_DROP, &event_data); | ||
| record_event_all_consumers(PPME_CPU_HOTPLUG_E, UF_NEVER_DROP, &event_data, TP_VAL_INTERNAL); |
There was a problem hiding this comment.
Internal event; use canary value for tp.
|
Most of the interesting stuff (and the locs) is in kmod; i highlighted relevant changes in the self-review. |
|
Updated kmod code: This just means that we won't be able to disable them anymore because we will have some zombie references to those tracepoints. /cc @gnosek @Andreagit97 |
| u32 idx; | ||
| u32 new_val; | ||
| u32 curr_val; | ||
| int ret = 0; | ||
|
|
||
| if (new_tp_set == g_tracepoints_attached) | ||
| { | ||
| // ok already equal | ||
| return ret; | ||
| } | ||
| int cpu; | ||
| int ret; |
There was a problem hiding this comment.
I would initialize all these variables just to be future proof
There was a problem hiding this comment.
We can't mix declaration and code in c89/90 :) I mean, we actually can but then any added variable must be initialized.
We try to avoid doing that in kmod!
…dropped `capture_enabled` from modern bpf probe. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…er in headers that can be included by other engines. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Moreover, made tracepoint dynamic management per-consumer. Tracepoints will be attached using a ref-counted method, so that a tracepoint that is not requested by any consumer, gets detached. Moreover, now kmod follows other drivers behavior: as soon as it is started, no tracepoint is attached. Instead, tracepoints must be manually set by userspace consumer, using the PPM_IOCTL_MANAGE_TP ioctl. All of the above, also means that an inserted kmod won't steal any resource until any consumer is actually using it, in a way much similar to other drivers. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…nimum driver api version. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…heir original position. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
It now **can't** have desynced `g_tracepoints_attached` and `g_tracepoints_refs`. Only thing that can happens is that when destroying a consumer (that is the only one present), for any reason, not all tracepoints can be detached; so we end up with some refs/attached tracepoints that are not properly cleaned, even if no consumer exists. This just means that we won't be able to disable them anymore because we will have some zombie references to those tracepoints. Not a big deal, and i think it should really never happen. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
8227fb4 to
7e391c5
Compare
|
Rebased on top of master. |
|
LGTM label has been added. DetailsGit tree hash: 11e47c318daf26b0f0d946b8d0e56d33564f127b |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Andreagit97, FedeDP, leogr The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/milestone 4.0.0+driver |
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area API-version
/area driver-kmod
/area driver-bpf
/area driver-modern-bpf
/area libscap-engine-bpf
/area libscap-engine-kmod
/area libscap-engine-modern-bpf
/area libscap
/area libpman
/area tests
Does this PR require a change in the driver versions?
/version driver-API-version-major
We changed how libscap starts the capture for the driver.
What this PR does / why we need it:
This PR drops useless
capture_enabled, by leveraging new runtime tracepoint management feature.Basically, instead of stopping the capture by setting the flag, but keeping everything running (so, every tracepoint is still called but it just checks if capture is enabled and leaves), we detach every tracepoint.
Moreover, made tracepoint dynamic management per-consumer in kmod.
Tracepoints will be attached using a ref-counted method, so that a tracepoint that is not requested by any consumer, gets detached.
Moreover, now kmod follows other drivers behavior: as soon as it is started, no tracepoint is attached. Instead, tracepoints must be manually set by userspace consumer, using the PPM_IOCTL_MANAGE_TP ioctl.
As a side effect of the above, this also means that an inserted kmod won't steal any resource until any consumer is actually using it, in a way much similar to other drivers.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: