Skip to content

Commit b222565

Browse files
paolonighaxtibal
authored andcommitted
tracing: add kernel documentation for trace_array_set_clr_event, trace_set_clr_event and supporting functions
As per Linux Kernel documentation guidelines (https://docs.kernel.org/doc-guide/kernel-doc.html), <<Every function that is exported to loadable modules using EXPORT_SYMBOL or EXPORT_SYMBOL_GPL should have a kernel-doc comment>>; hence this patch adds detailed kernel-doc headers documentation for trace_array_set_clr_event(), trace_set_clr_event() and the main functions in the respective call-trees that support their functionalities. For each of the documented functions, as part of the extensive description, a set of "Function's expectations" and "Assumptions of Use" are described in a way that facilitate: 1) evaluating the current code and any proposed modification to behave as described; 2) writing kernel tests to verify the code to behave as described. Signed-off-by: Gabriele Paoloni <gpaoloni@redhat.com>
1 parent 6786dbd commit b222565

1 file changed

Lines changed: 133 additions & 17 deletions

File tree

kernel/trace/trace_events.c

Lines changed: 133 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,58 @@ void trace_event_enable_tgid_record(bool enable)
763763
} while_for_each_event_file();
764764
}
765765

766+
/**
767+
* __ftrace_event_enable_disable - enable or disable a trace event
768+
* @file: trace event file associated with the event.
769+
* @enable: 0 or 1 respectively to disable/enable the event.
770+
* @soft_disable: 1 or 0 respectively to mark if the enable parameter IS or
771+
* IS NOT a soft enable/disable.
772+
*
773+
* Function's expectations:
774+
* - If soft_disable is 1 a soft mode reference counter associated with the
775+
* trace event shall be increased or decreased according to the enable
776+
* parameter being 1 (enable) or 0 (disable) respectively.
777+
* If the soft mode reference counter is > 0 before the increase or after
778+
* the decrease, no other actions shall be taken.
779+
*
780+
* - if soft_disable is 1 and the soft mode reference counter is 0 before
781+
* the increase or after the decrease, an enable value set to 0 or 1 shall
782+
* result in disabling or enabling the use of trace_buffered_event
783+
* respectively.
784+
*
785+
* - If soft_disable is 1 and enable is 0 and the soft mode reference counter
786+
* reaches zero and if the soft disabled flag is set (i.e. if the event was
787+
* previously enabled with soft_disable = 1), tracing for the trace point
788+
* event shall be disabled and the soft disabled flag shall be cleared.
789+
*
790+
* - If soft_disable is 0 and enable is 0, tracing for the trace point event
791+
* shall be disabled only if the soft mode reference counter is 0.
792+
* Additionally the soft disabled flag shall be set or cleared according to
793+
* the soft mode reference counter being greater than 0 or 0 respectively.
794+
*
795+
* - If enable is 1, tracing for the trace point event shall be enabled (if
796+
* previously disabled); in addition, if soft_disable is 1 and the soft mode
797+
* reference counter is 0 before the increase, the soft disabled flag shall
798+
* be set.
799+
*
800+
* - When enabling or disabling tracing for the trace point event
801+
* the flags associated with comms and tgids shall be checked and, if set,
802+
* respectively tracing of comms and tgdis at sched_switch shall be
803+
* enabled/disabled.
804+
*
805+
* Assumptions of Use:
806+
* - for thread-safe execution, event_mutex shall be locked before calling
807+
* this function;
808+
* - the file input pointer is assumed to be a valid one;
809+
* - the enable input parameter shall not be set to any value other than 0
810+
* or 1.
811+
*
812+
* Context: process context.
813+
*
814+
* Return:
815+
* * 0 on success
816+
* * any error returned by the event register or unregister callbacks
817+
*/
766818
static int __ftrace_event_enable_disable(struct trace_event_file *file,
767819
int enable, int soft_disable)
768820
{
@@ -1296,8 +1348,46 @@ static void remove_event_file_dir(struct trace_event_file *file)
12961348
event_file_put(file);
12971349
}
12981350

1299-
/*
1300-
* __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
1351+
/**
1352+
* __ftrace_set_clr_event_nolock - enable or disable an event within a system.
1353+
* @tr: target trace_array containing the events list.
1354+
* @match: target system or event name (NULL for any).
1355+
* @sub: target system name (NULL for any).
1356+
* @event: target event name (NULL for any).
1357+
* @set: 1 to enable, 0 to disable.
1358+
* @mod: target module name (NULL for any).
1359+
*
1360+
* Function's expectations:
1361+
* - If mod is set, the mod name shall be sanitized by replacing all '-' with
1362+
* '_' to match the modules' naming convention used in the Kernel.
1363+
*
1364+
* - From the events' list in the input tr, the ensemble of events to be enabled
1365+
* or disabled shall be selected according to the input match, sub, event and
1366+
* mod parameters. Each of these parameters, if set, shall restrict the events
1367+
* ensemble to those with a matching parameter's name.
1368+
*
1369+
* - For each of the selected events the IGNORE_ENABLE flag shall be checked,
1370+
* and, if not set, ftrace_event_enable_disable shall be invoked passing the
1371+
* input set parameter to either enable or disable the event.
1372+
*
1373+
* Assumptions of Use:
1374+
* - for thread-safe execution, event_mutex shall be locked before calling
1375+
* this function;
1376+
* - the tr input pointer is assumed to be a valid one;
1377+
* - the set input parameter shall not be set to any value other than 0
1378+
* or 1.
1379+
*
1380+
* NOTE: __ftrace_set_clr_event_nolock(NULL, NULL, NULL, set, NULL) will
1381+
* set/unset all events.
1382+
*
1383+
* Context: process context.
1384+
*
1385+
* Return:
1386+
* * 0 on success
1387+
* * %-EINVAL - the input parameters do not match any registered event
1388+
* * %-ENOMEM - memory allocation fails for the module pointer
1389+
* * any value returned by the first call to ftrace_event_enable_disable that
1390+
* returned an error
13011391
*/
13021392
static int
13031393
__ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match,
@@ -1440,16 +1530,32 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
14401530
}
14411531

14421532
/**
1443-
* trace_set_clr_event - enable or disable an event
1444-
* @system: system name to match (NULL for any system)
1445-
* @event: event name to match (NULL for all events, within system)
1446-
* @set: 1 to enable, 0 to disable
1533+
* trace_set_clr_event - enable or disable an event within a system.
1534+
* @system: system name (NULL for any system).
1535+
* @event: event name (NULL for all events, within system).
1536+
* @set: 1 to enable, 0 to disable.
14471537
*
14481538
* This is a way for other parts of the kernel to enable or disable
14491539
* event recording.
14501540
*
1451-
* Returns 0 on success, -EINVAL if the parameters do not match any
1452-
* registered events.
1541+
* Function's expectations:
1542+
* - This function shall retrieve the pointer of the global trace array (global
1543+
* tracer) and pass it, along the rest of input parameters, to
1544+
* __ftrace_set_clr_event_nolock.
1545+
*
1546+
* - This function shall properly lock/unlock the global event_mutex
1547+
* before/after invoking ftrace_set_clr_event_nolock.
1548+
*
1549+
* Assumptions of Use:
1550+
* - the set input parameter shall not be set to any value other than 0
1551+
* or 1.
1552+
*
1553+
* Context: process context, locks and unlocks event_mutex.
1554+
*
1555+
* Return:
1556+
* * 0 on success
1557+
* * %-ENODEV - the global tracer cannot be retrieved
1558+
* * any other error condition returned by __ftrace_set_clr_event_nolock
14531559
*/
14541560
int trace_set_clr_event(const char *system, const char *event, int set)
14551561
{
@@ -1463,17 +1569,27 @@ int trace_set_clr_event(const char *system, const char *event, int set)
14631569
EXPORT_SYMBOL_GPL(trace_set_clr_event);
14641570

14651571
/**
1466-
* trace_array_set_clr_event - enable or disable an event for a trace array.
1467-
* @tr: concerned trace array.
1468-
* @system: system name to match (NULL for any system)
1469-
* @event: event name to match (NULL for all events, within system)
1470-
* @enable: true to enable, false to disable
1572+
* trace_array_set_clr_event - enable or disable an event within a system for
1573+
* a trace array.
1574+
* @tr: input trace array.
1575+
* @system: system name (NULL for any system).
1576+
* @event: event name (NULL for all events, within system).
1577+
* @enable: true to enable, false to disable.
14711578
*
1472-
* This is a way for other parts of the kernel to enable or disable
1473-
* event recording.
1579+
* This is a way for other parts of the kernel to enable or disable event
1580+
* recording.
1581+
*
1582+
* Function's expectations:
1583+
* - This function shall properly lock/unlock the global event_mutex
1584+
* before/after invoking ftrace_set_clr_event_nolock passing along the same
1585+
* input parameters.
1586+
*
1587+
* Context: process context, locks and unlocks event_mutex.
14741588
*
1475-
* Returns 0 on success, -EINVAL if the parameters do not match any
1476-
* registered events.
1589+
* Return:
1590+
* * 0 on success
1591+
* * %-ENOENT - the input tr is NULL
1592+
* * any other error condition returned by __ftrace_set_clr_event_nolock
14771593
*/
14781594
int trace_array_set_clr_event(struct trace_array *tr, const char *system,
14791595
const char *event, bool enable)

0 commit comments

Comments
 (0)