kernel/trace/trace_seq.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_seq.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_seq.c- Extension
.c- Size
- 11993 bytes
- Lines
- 458
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/uaccess.hlinux/seq_file.hlinux/trace_seq.h
Detected Declarations
function Copyrightfunction trace_print_seqfunction trace_seq_printffunction trace_seq_bitmaskfunction representationfunction bufferfunction trace_seq_bprintffunction bufferfunction bufferfunction strcpyfunction trace_seq_putmemfunction trace_seq_pathfunction bufferfunction trace_seq_hex_dumpexport trace_seq_printfexport trace_seq_bitmaskexport trace_seq_bitmask_listexport trace_seq_vprintfexport trace_seq_bprintfexport trace_seq_putsexport trace_seq_putcexport trace_seq_putmemexport trace_seq_putmem_hexexport trace_seq_pathexport trace_seq_to_userexport trace_seq_hex_dumpexport trace_seq_acquire
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* trace_seq.c
*
* Copyright (C) 2008-2014 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
*
* The trace_seq is a handy tool that allows you to pass a descriptor around
* to a buffer that other functions can write to. It is similar to the
* seq_file functionality but has some differences.
*
* To use it, the trace_seq must be initialized with trace_seq_init().
* This will set up the counters within the descriptor. You can call
* trace_seq_init() more than once to reset the trace_seq to start
* from scratch.
*
* A write to the buffer will either succeed or fail. That is, unlike
* sprintf() there will not be a partial write (well it may write into
* the buffer but it won't update the pointers). This allows users to
* try to write something into the trace_seq buffer and if it fails
* they can flush it and try again.
*
*/
#include <linux/uaccess.h>
#include <linux/seq_file.h>
#include <linux/trace_seq.h>
/* How much buffer is left on the trace_seq? */
#define TRACE_SEQ_BUF_LEFT(s) seq_buf_buffer_left(&(s)->seq)
/*
* trace_seq should work with being initialized with 0s.
*/
static inline void __trace_seq_init(struct trace_seq *s)
{
if (unlikely(!s->seq.size))
trace_seq_init(s);
}
/**
* trace_print_seq - move the contents of trace_seq into a seq_file
* @m: the seq_file descriptor that is the destination
* @s: the trace_seq descriptor that is the source.
*
* Returns 0 on success and non zero on error. If it succeeds to
* write to the seq_file it will reset the trace_seq, otherwise
* it does not modify the trace_seq to let the caller try again.
*/
int trace_print_seq(struct seq_file *m, struct trace_seq *s)
{
int ret;
__trace_seq_init(s);
ret = seq_buf_print_seq(m, &s->seq);
/*
* Only reset this buffer if we successfully wrote to the
* seq_file buffer. This lets the caller try again or
* do something else with the contents.
*/
if (!ret)
trace_seq_init(s);
return ret;
}
/**
* trace_seq_printf - sequence printing of trace information
* @s: trace sequence descriptor
* @fmt: printf format string
*
* The tracer may use either sequence operations or its own
* copy to user routines. To simplify formatting of a trace
* trace_seq_printf() is used to store strings into a special
* buffer (@s). Then the output may be either used by
* the sequencer or pulled into another buffer.
*/
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
{
unsigned int save_len = s->seq.len;
va_list ap;
if (s->full)
return;
__trace_seq_init(s);
va_start(ap, fmt);
seq_buf_vprintf(&s->seq, fmt, ap);
va_end(ap);
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/seq_file.h`, `linux/trace_seq.h`.
- Detected declarations: `function Copyright`, `function trace_print_seq`, `function trace_seq_printf`, `function trace_seq_bitmask`, `function representation`, `function buffer`, `function trace_seq_bprintf`, `function buffer`, `function buffer`, `function strcpy`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.