Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 1cf4c0732db3c ("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/20250702111908.03759998@batman.local.home/

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Gabriele Paoloni <gpaoloni@redhat.com>
Link: https://lore.kernel.org/20250702143657.18dd1882@batman.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+12 -15
-3
include/linux/trace_events.h
··· 480 480 EVENT_FILE_FL_RECORDED_TGID_BIT, 481 481 EVENT_FILE_FL_FILTERED_BIT, 482 482 EVENT_FILE_FL_NO_SET_FILTER_BIT, 483 - EVENT_FILE_FL_SOFT_MODE_BIT, 484 483 EVENT_FILE_FL_SOFT_DISABLED_BIT, 485 484 EVENT_FILE_FL_TRIGGER_MODE_BIT, 486 485 EVENT_FILE_FL_TRIGGER_COND_BIT, ··· 617 618 * RECORDED_TGID - The tgids should be recorded at sched_switch 618 619 * FILTERED - The event has a filter attached 619 620 * NO_SET_FILTER - Set when filter has error and is to be ignored 620 - * SOFT_MODE - The event is enabled/disabled by SOFT_DISABLED 621 621 * SOFT_DISABLED - When set, do not trace the event (even though its 622 622 * tracepoint may be enabled) 623 623 * TRIGGER_MODE - When set, invoke the triggers associated with the event ··· 631 633 EVENT_FILE_FL_RECORDED_TGID = (1 << EVENT_FILE_FL_RECORDED_TGID_BIT), 632 634 EVENT_FILE_FL_FILTERED = (1 << EVENT_FILE_FL_FILTERED_BIT), 633 635 EVENT_FILE_FL_NO_SET_FILTER = (1 << EVENT_FILE_FL_NO_SET_FILTER_BIT), 634 - EVENT_FILE_FL_SOFT_MODE = (1 << EVENT_FILE_FL_SOFT_MODE_BIT), 635 636 EVENT_FILE_FL_SOFT_DISABLED = (1 << EVENT_FILE_FL_SOFT_DISABLED_BIT), 636 637 EVENT_FILE_FL_TRIGGER_MODE = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT), 637 638 EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),
+12 -12
kernel/trace/trace_events.c
··· 768 768 { 769 769 struct trace_event_call *call = file->event_call; 770 770 struct trace_array *tr = file->tr; 771 + bool soft_mode = atomic_read(&file->sm_ref) != 0; 771 772 int ret = 0; 772 773 int disable; 773 774 ··· 783 782 * is set we do not want the event to be enabled before we 784 783 * clear the bit. 785 784 * 786 - * When soft_disable is not set but the SOFT_MODE flag is, 785 + * When soft_disable is not set but the soft_mode is, 787 786 * we do nothing. Do not disable the tracepoint, otherwise 788 787 * "soft enable"s (clearing the SOFT_DISABLED bit) wont work. 789 788 */ ··· 791 790 if (atomic_dec_return(&file->sm_ref) > 0) 792 791 break; 793 792 disable = file->flags & EVENT_FILE_FL_SOFT_DISABLED; 794 - clear_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags); 793 + soft_mode = false; 795 794 /* Disable use of trace_buffered_event */ 796 795 trace_buffered_event_disable(); 797 796 } else 798 - disable = !(file->flags & EVENT_FILE_FL_SOFT_MODE); 797 + disable = !soft_mode; 799 798 800 799 if (disable && (file->flags & EVENT_FILE_FL_ENABLED)) { 801 800 clear_bit(EVENT_FILE_FL_ENABLED_BIT, &file->flags); ··· 813 812 814 813 WARN_ON_ONCE(ret); 815 814 } 816 - /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */ 817 - if (file->flags & EVENT_FILE_FL_SOFT_MODE) 815 + /* If in soft mode, just set the SOFT_DISABLE_BIT, else clear it */ 816 + if (soft_mode) 818 817 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); 819 818 else 820 819 clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); ··· 824 823 * When soft_disable is set and enable is set, we want to 825 824 * register the tracepoint for the event, but leave the event 826 825 * as is. That means, if the event was already enabled, we do 827 - * nothing (but set SOFT_MODE). If the event is disabled, we 826 + * nothing (but set soft_mode). If the event is disabled, we 828 827 * set SOFT_DISABLED before enabling the event tracepoint, so 829 828 * it still seems to be disabled. 830 829 */ ··· 833 832 else { 834 833 if (atomic_inc_return(&file->sm_ref) > 1) 835 834 break; 836 - set_bit(EVENT_FILE_FL_SOFT_MODE_BIT, &file->flags); 835 + soft_mode = true; 837 836 /* Enable use of trace_buffered_event */ 838 837 trace_buffered_event_enable(); 839 838 } ··· 841 840 if (!(file->flags & EVENT_FILE_FL_ENABLED)) { 842 841 bool cmd = false, tgid = false; 843 842 844 - /* Keep the event disabled, when going to SOFT_MODE. */ 843 + /* Keep the event disabled, when going to soft mode. */ 845 844 if (soft_disable) 846 845 set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags); 847 846 ··· 1793 1792 !(flags & EVENT_FILE_FL_SOFT_DISABLED)) 1794 1793 strcpy(buf, "1"); 1795 1794 1796 - if (flags & EVENT_FILE_FL_SOFT_DISABLED || 1797 - flags & EVENT_FILE_FL_SOFT_MODE) 1795 + if (atomic_read(&file->sm_ref) != 0) 1798 1796 strcat(buf, "*"); 1799 1797 1800 1798 strcat(buf, "\n"); ··· 3584 3584 continue; 3585 3585 /* 3586 3586 * 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 3588 3588 * TRACE_REG_UNREGISTER. 3589 3589 */ 3590 3590 if (file->flags & EVENT_FILE_FL_ENABLED) ··· 3997 3997 3998 3998 edata->ref--; 3999 3999 if (!edata->ref) { 4000 - /* Remove the SOFT_MODE flag */ 4000 + /* Remove soft mode */ 4001 4001 __ftrace_event_enable_disable(edata->file, 0, 1); 4002 4002 trace_event_put_ref(edata->file->event_call); 4003 4003 kfree(edata);