kernel/trace/trace_events_trigger.c

Source file repositories/reference/linux-study-clean/kernel/trace/trace_events_trigger.c

File Facts

System
Linux kernel
Corpus path
kernel/trace/trace_events_trigger.c
Extension
.c
Size
53067 bytes
Lines
1984
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

const struct file_operations event_trigger_fops = {
	.open = event_trigger_open,
	.read = seq_read,
	.write = event_trigger_write,
	.llseek = tracing_lseek,
	.release = event_trigger_release,
};

/*
 * Currently we only register event commands from __init, so mark this
 * __init too.
 */
__init int register_event_command(struct event_command *cmd)
{
	struct event_command *p;

	guard(mutex)(&trigger_cmd_mutex);

	list_for_each_entry(p, &trigger_commands, list) {
		if (strcmp(cmd->name, p->name) == 0)
			return -EBUSY;
	}
	list_add(&cmd->list, &trigger_commands);

	return 0;
}

/*
 * Currently we only unregister event commands from __init, so mark
 * this __init too.
 */
__init int unregister_event_command(struct event_command *cmd)
{
	struct event_command *p, *n;

	guard(mutex)(&trigger_cmd_mutex);

	list_for_each_entry_safe(p, n, &trigger_commands, list) {
		if (strcmp(cmd->name, p->name) == 0) {
			list_del_init(&p->list);
			return 0;
		}
	}

	return -ENODEV;
}

/**
 * event_trigger_count - Optional count function for event triggers
 * @data: Trigger-specific data
 * @buffer: The ring buffer that the event is being written to
 * @rec: The trace entry for the event, NULL for unconditional invocation
 * @event: The event meta data in the ring buffer
 *
 * For triggers that can take a count parameter that doesn't do anything
 * special, they can use this function to assign to their .count_func
 * field.
 *
 * This simply does a count down of the @data->count field.
 *
 * If the @data->count is greater than zero, it will decrement it.
 *
 * Returns false if @data->count is zero, otherwise true.
 */
bool event_trigger_count(struct event_trigger_data *data,
			 struct trace_buffer *buffer,  void *rec,
			 struct ring_buffer_event *event)
{
	if (!data->count)
		return false;

	if (data->count != -1)
		(data->count)--;

	return true;
}

/**
 * event_trigger_print - Generic event_command @print implementation
 * @name: The name of the event trigger
 * @m: The seq_file being printed to
 * @data: Trigger-specific data
 * @filter_str: filter_str to print, if present
 *
 * Common implementation for event triggers to print themselves.
 *
 * Usually wrapped by a function that simply sets the @name of the
 * trigger command and then invokes this.
 *
 * Return: 0 on success, errno otherwise

Annotation

Implementation Notes