kernel/trace/trace_mmiotrace.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_mmiotrace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_mmiotrace.c- Extension
.c- Size
- 8356 bytes
- Lines
- 351
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/mmiotrace.hlinux/pci.hlinux/slab.hlinux/time.hlinux/atomic.htrace.htrace_output.h
Detected Declarations
struct header_iterfunction mmio_reset_datafunction mmio_trace_initfunction mmio_trace_resetfunction mmio_trace_startfunction mmio_print_pcidevfunction destroy_header_iterfunction mmio_pipe_openfunction mmio_closefunction count_overrunsfunction mmio_readfunction mmio_print_rwfunction mmio_print_mapfunction mmio_print_markfunction mmio_print_linefunction init_mmio_tracefunction __trace_mmiotrace_rwfunction mmio_trace_rwfunction __trace_mmiotrace_mapfunction mmio_trace_mappingfunction mmio_trace_printkmodule init init_mmio_trace
Annotated Snippet
const struct pci_driver *drv = pci_dev_driver(dev);
trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x",
dev->bus->number, dev->devfn,
dev->vendor, dev->device, dev->irq);
for (i = 0; i < 7; i++) {
start = dev->resource[i].start;
trace_seq_printf(s, " %llx",
(unsigned long long)(start |
(dev->resource[i].flags & PCI_REGION_FLAG_MASK)));
}
for (i = 0; i < 7; i++) {
start = dev->resource[i].start;
end = dev->resource[i].end;
trace_seq_printf(s, " %llx",
dev->resource[i].start < dev->resource[i].end ?
(unsigned long long)(end - start) + 1 : 0);
}
if (drv)
trace_seq_printf(s, " %s\n", drv->name);
else
trace_seq_puts(s, " \n");
}
static void destroy_header_iter(struct header_iter *hiter)
{
if (!hiter)
return;
pci_dev_put(hiter->dev);
kfree(hiter);
}
static void mmio_pipe_open(struct trace_iterator *iter)
{
struct header_iter *hiter;
struct trace_seq *s = &iter->seq;
trace_seq_puts(s, "VERSION 20070824\n");
hiter = kzalloc_obj(*hiter);
if (!hiter)
return;
hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
iter->private = hiter;
}
/* XXX: This is not called when the pipe is closed! */
static void mmio_close(struct trace_iterator *iter)
{
struct header_iter *hiter = iter->private;
destroy_header_iter(hiter);
iter->private = NULL;
}
static unsigned long count_overruns(struct trace_iterator *iter)
{
unsigned long cnt = atomic_xchg(&dropped_count, 0);
unsigned long over = ring_buffer_overruns(iter->array_buffer->buffer);
if (over > prev_overruns)
cnt += over - prev_overruns;
prev_overruns = over;
return cnt;
}
static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
char __user *ubuf, size_t cnt, loff_t *ppos)
{
ssize_t ret;
struct header_iter *hiter = iter->private;
struct trace_seq *s = &iter->seq;
unsigned long n;
n = count_overruns(iter);
if (n) {
/* XXX: This is later than where events were lost. */
trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n);
if (!overrun_detected)
pr_warn("mmiotrace has lost events\n");
overrun_detected = true;
goto print_out;
}
if (!hiter)
return 0;
mmio_print_pcidev(s, hiter->dev);
hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mmiotrace.h`, `linux/pci.h`, `linux/slab.h`, `linux/time.h`, `linux/atomic.h`, `trace.h`, `trace_output.h`.
- Detected declarations: `struct header_iter`, `function mmio_reset_data`, `function mmio_trace_init`, `function mmio_trace_reset`, `function mmio_trace_start`, `function mmio_print_pcidev`, `function destroy_header_iter`, `function mmio_pipe_open`, `function mmio_close`, `function count_overruns`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.