Skip to content

Commit 07c3f39

Browse files
committed
tracing: Remove EVENT_FILE_FL_SOFT_MODE flag
When soft disabling of trace events was first created, it needed to have a way to know if a file had a user that was using it with soft disabled (for triggers that need to enable or disable events from a context that can not really enable or disable the event, it would set SOFT_DISABLED to state it is disabled). The flag SOFT_MODE was used to denote that an event had a user that would enable or disable it via the SOFT_DISABLED flag. Commit 1cf4c07 ("tracing: Modify soft-mode only if there's no other referrer") fixed a bug where if two users were using the SOFT_DISABLED flag the accounting would get messed up as the SOFT_MODE flag could only handle one user. That commit added the sm_ref counter which kept track of how many users were using the event in "soft mode". This made the SOFT_MODE flag redundant as it should only be set if the sm_ref counter is non zero. Remove the SOFT_MODE flag and just use the sm_ref counter to know the event is in soft mode or not. This makes the code a bit simpler. Link: https://lore.kernel.org/all/[email protected]/ Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Gabriele Paoloni <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent c897c1e commit 07c3f39

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

include/linux/trace_events.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ enum {
480480
EVENT_FILE_FL_RECORDED_TGID_BIT,
481481
EVENT_FILE_FL_FILTERED_BIT,
482482
EVENT_FILE_FL_NO_SET_FILTER_BIT,
483-
EVENT_FILE_FL_SOFT_MODE_BIT,
484483
EVENT_FILE_FL_SOFT_DISABLED_BIT,
485484
EVENT_FILE_FL_TRIGGER_MODE_BIT,
486485
EVENT_FILE_FL_TRIGGER_COND_BIT,
@@ -618,7 +617,6 @@ extern int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...);
618617
* RECORDED_TGID - The tgids should be recorded at sched_switch
619618
* FILTERED - The event has a filter attached
620619
* NO_SET_FILTER - Set when filter has error and is to be ignored
621-
* SOFT_MODE - The event is enabled/disabled by SOFT_DISABLED
622620
* SOFT_DISABLED - When set, do not trace the event (even though its
623621
* tracepoint may be enabled)
624622
* TRIGGER_MODE - When set, invoke the triggers associated with the event
@@ -633,7 +631,6 @@ enum {
633631
EVENT_FILE_FL_RECORDED_TGID = (1 << EVENT_FILE_FL_RECORDED_TGID_BIT),
634632
EVENT_FILE_FL_FILTERED = (1 << EVENT_FILE_FL_FILTERED_BIT),
635633
EVENT_FILE_FL_NO_SET_FILTER = (1 << EVENT_FILE_FL_NO_SET_FILTER_BIT),
636-
EVENT_FILE_FL_SOFT_MODE = (1 << EVENT_FILE_FL_SOFT_MODE_BIT),
637634
EVENT_FILE_FL_SOFT_DISABLED = (1 << EVENT_FILE_FL_SOFT_DISABLED_BIT),
638635
EVENT_FILE_FL_TRIGGER_MODE = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT),
639636
EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),

kernel/trace/trace_events.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
768768
{
769769
struct trace_event_call *call = file->event_call;
770770
struct trace_array *tr = file->tr;
771+
bool soft_mode = atomic_read(&file->sm_ref) != 0;
771772
int ret = 0;
772773
int disable;
773774

@@ -782,19 +783,19 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
782783
* is set we do not want the event to be enabled before we
783784
* clear the bit.
784785
*
785-
* When soft_disable is not set but the SOFT_MODE flag is,
786+
* When soft_disable is not set but the soft_mode is,
786787
* we do nothing. Do not disable the tracepoint, otherwise
787788
* "soft enable"s (clearing the SOFT_DISABLED bit) wont work.
788789
*/
789790
if (soft_disable) {
790791
if (atomic_dec_return(&file->sm_ref) > 0)
791792
break;
792793
disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED;
793-
clear_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
794+
soft_mode = false;
794795
/* Disable use of trace_buffered_event */
795796
trace_buffered_event_disable();
796797
} else
797-
disable = !(file->flags & EVENT_FILE_FL_SOFT_MODE);
798+
disable = !soft_mode;
798799

799800
if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) {
800801
clear_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags);
@@ -812,8 +813,8 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
812813

813814
WARN_ON_ONCE(ret);
814815
}
815-
/* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */
816-
if (file->flags & EVENT_FILE_FL_SOFT_MODE)
816+
/* If in soft mode, just set the SOFT_DISABLE_BIT, else clear it */
817+
if (soft_mode)
817818
set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
818819
else
819820
clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
@@ -823,7 +824,7 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
823824
* When soft_disable is set and enable is set, we want to
824825
* register the tracepoint for the event, but leave the event
825826
* as is. That means, if the event was already enabled, we do
826-
* nothing (but set SOFT_MODE). If the event is disabled, we
827+
* nothing (but set soft_mode). If the event is disabled, we
827828
* set SOFT_DISABLED before enabling the event tracepoint, so
828829
* it still seems to be disabled.
829830
*/
@@ -832,15 +833,15 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
832833
else {
833834
if (atomic_inc_return(&file->sm_ref) > 1)
834835
break;
835-
set_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags);
836+
soft_mode = true;
836837
/* Enable use of trace_buffered_event */
837838
trace_buffered_event_enable();
838839
}
839840

840841
if (!(file->flags & EVENT_FILE_FL_ENABLED)) {
841842
bool cmd = false, tgid = false;
842843

843-
/* Keep the event disabled, when going to SOFT_MODE. */
844+
/* Keep the event disabled, when going to soft mode. */
844845
if (soft_disable)
845846
set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
846847

@@ -1792,8 +1793,7 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
17921793
!(flags & EVENT_FILE_FL_SOFT_DISABLED))
17931794
strcpy(buf, "1");
17941795

1795-
if (flags & EVENT_FILE_FL_SOFT_DISABLED ||
1796-
flags & EVENT_FILE_FL_SOFT_MODE)
1796+
if (atomic_read(&file->sm_ref) != 0)
17971797
strcat(buf, "*");
17981798

17991799
strcat(buf, "\n");
@@ -3584,7 +3584,7 @@ static int probe_remove_event_call(struct trace_event_call *call)
35843584
continue;
35853585
/*
35863586
* We can't rely on ftrace_event_enable_disable(enable => 0)
3587-
* we are going to do, EVENT_FILE_FL_SOFT_MODE can suppress
3587+
* we are going to do, soft mode can suppress
35883588
* TRACE_REG_UNREGISTER.
35893589
*/
35903590
if (file->flags & EVENT_FILE_FL_ENABLED)
@@ -3997,7 +3997,7 @@ static int free_probe_data(void *data)
39973997

39983998
edata->ref--;
39993999
if (!edata->ref) {
4000-
/* Remove the SOFT_MODE flag */
4000+
/* Remove soft mode */
40014001
__ftrace_event_enable_disable(edata->file, 0, 1);
40024002
trace_event_put_ref(edata->file->event_call);
40034003
kfree(edata);

0 commit comments

Comments
 (0)