drivers/net/netdevsim/psample.c
Source file repositories/reference/linux-study-clean/drivers/net/netdevsim/psample.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/netdevsim/psample.c- Extension
.c- Size
- 6579 bytes
- Lines
- 266
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/debugfs.hlinux/err.hlinux/etherdevice.hlinux/inet.hlinux/kernel.hlinux/random.hlinux/slab.hnet/devlink.hnet/ip.hnet/psample.huapi/linux/ip.huapi/linux/udp.hnetdevsim.h
Detected Declarations
struct nsim_dev_psamplefunction nsim_dev_psample_md_preparefunction nsim_dev_psample_report_workfunction nsim_dev_psample_enablefunction nsim_dev_psample_disablefunction nsim_dev_psample_enable_writefunction nsim_dev_psample_initfunction nsim_dev_psample_exit
Annotated Snippet
static const struct file_operations nsim_psample_enable_fops = {
.open = simple_open,
.write = nsim_dev_psample_enable_write,
.llseek = generic_file_llseek,
.owner = THIS_MODULE,
};
int nsim_dev_psample_init(struct nsim_dev *nsim_dev)
{
struct nsim_dev_psample *psample;
int err;
psample = kzalloc_obj(*psample);
if (!psample)
return -ENOMEM;
nsim_dev->psample = psample;
INIT_DELAYED_WORK(&psample->psample_dw, nsim_dev_psample_report_work);
psample->ddir = debugfs_create_dir("psample", nsim_dev->ddir);
if (IS_ERR(psample->ddir)) {
err = PTR_ERR(psample->ddir);
goto err_psample_free;
}
/* Populate sampling parameters with sane defaults. */
psample->rate = 100;
debugfs_create_u32("rate", 0600, psample->ddir, &psample->rate);
psample->group_num = 10;
debugfs_create_u32("group_num", 0600, psample->ddir,
&psample->group_num);
psample->trunc_size = 0;
debugfs_create_u32("trunc_size", 0600, psample->ddir,
&psample->trunc_size);
psample->in_ifindex = 1;
debugfs_create_u32("in_ifindex", 0600, psample->ddir,
&psample->in_ifindex);
psample->out_ifindex = 2;
debugfs_create_u32("out_ifindex", 0600, psample->ddir,
&psample->out_ifindex);
psample->out_tc = 0;
debugfs_create_u16("out_tc", 0600, psample->ddir, &psample->out_tc);
psample->out_tc_occ_max = 10000;
debugfs_create_u64("out_tc_occ_max", 0600, psample->ddir,
&psample->out_tc_occ_max);
psample->latency_max = 50;
debugfs_create_u64("latency_max", 0600, psample->ddir,
&psample->latency_max);
debugfs_create_file("enable", 0200, psample->ddir, nsim_dev,
&nsim_psample_enable_fops);
return 0;
err_psample_free:
kfree(nsim_dev->psample);
return err;
}
void nsim_dev_psample_exit(struct nsim_dev *nsim_dev)
{
debugfs_remove_recursive(nsim_dev->psample->ddir);
if (nsim_dev->psample->is_active) {
cancel_delayed_work_sync(&nsim_dev->psample->psample_dw);
psample_group_put(nsim_dev->psample->group);
}
kfree(nsim_dev->psample);
}
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/err.h`, `linux/etherdevice.h`, `linux/inet.h`, `linux/kernel.h`, `linux/random.h`, `linux/slab.h`, `net/devlink.h`.
- Detected declarations: `struct nsim_dev_psample`, `function nsim_dev_psample_md_prepare`, `function nsim_dev_psample_report_work`, `function nsim_dev_psample_enable`, `function nsim_dev_psample_disable`, `function nsim_dev_psample_enable_write`, `function nsim_dev_psample_init`, `function nsim_dev_psample_exit`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern 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.