net/core/netpoll.c
Source file repositories/reference/linux-study-clean/net/core/netpoll.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/netpoll.c- Extension
.c- Size
- 16441 bytes
- Lines
- 702
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/moduleparam.hlinux/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/string.hlinux/if_arp.hlinux/inetdevice.hlinux/inet.hlinux/interrupt.hlinux/netpoll.hlinux/sched.hlinux/delay.hlinux/rcupdate.hlinux/workqueue.hlinux/slab.hlinux/export.hlinux/if_vlan.hlinux/udp.hnet/tcp.hnet/addrconf.hnet/ndisc.htrace/events/napi.hlinux/kconfig.h
Detected Declarations
function netpoll_start_xmitfunction queue_processfunction netif_local_xmit_activefunction poll_one_napifunction poll_napifunction list_for_each_entry_rcufunction netpoll_poll_devfunction netpoll_poll_disablefunction netpoll_poll_enablefunction refill_skbsfunction netpoll_zap_completion_queuefunction netpoll_owner_activefunction list_for_each_entry_rcufunction __netpoll_send_skbfunction netpoll_send_skbfunction skb_pool_flushfunction refill_skbs_work_handlerfunction __netpoll_setupfunction netpoll_wait_carrierfunction netpoll_take_ipv6function list_for_each_entryfunction netpoll_take_ipv4function netpoll_setupfunction netpoll_setupfunction rcu_cleanup_netpoll_infofunction __netpoll_cleanupfunction __netpoll_freefunction do_netpoll_cleanupfunction netpoll_cleanupexport netpoll_poll_devexport netpoll_send_skbexport __netpoll_setupexport netpoll_setupexport __netpoll_freeexport do_netpoll_cleanupexport netpoll_cleanup
Annotated Snippet
const struct net_device_ops *ops;
/* Don't do any rx activity if the dev_lock mutex is held
* the dev_open/close paths use this to block netpoll activity
* while changing device state
*/
if (!ni || down_trylock(&ni->dev_lock))
return;
/* Some drivers will take the same locks in poll and xmit,
* we can't poll if local CPU is already in xmit.
*/
if (!netif_running(dev) || netif_local_xmit_active(dev)) {
up(&ni->dev_lock);
return;
}
ops = dev->netdev_ops;
if (ops->ndo_poll_controller)
ops->ndo_poll_controller(dev);
poll_napi(dev);
up(&ni->dev_lock);
netpoll_zap_completion_queue();
}
EXPORT_SYMBOL(netpoll_poll_dev);
void netpoll_poll_disable(struct net_device *dev)
{
struct netpoll_info *ni;
might_sleep();
ni = rtnl_dereference(dev->npinfo);
if (ni)
down(&ni->dev_lock);
}
void netpoll_poll_enable(struct net_device *dev)
{
struct netpoll_info *ni;
ni = rtnl_dereference(dev->npinfo);
if (ni)
up(&ni->dev_lock);
}
static void refill_skbs(struct netpoll *np)
{
struct sk_buff_head *skb_pool;
struct sk_buff *skb;
skb_pool = &np->skb_pool;
while (READ_ONCE(skb_pool->qlen) < MAX_SKBS) {
skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
if (!skb)
break;
skb_queue_tail(skb_pool, skb);
}
}
void netpoll_zap_completion_queue(void)
{
unsigned long flags;
struct softnet_data *sd = &get_cpu_var(softnet_data);
if (sd->completion_queue) {
struct sk_buff *clist;
local_irq_save(flags);
clist = sd->completion_queue;
sd->completion_queue = NULL;
local_irq_restore(flags);
while (clist != NULL) {
struct sk_buff *skb = clist;
clist = clist->next;
if (!skb_irq_freeable(skb)) {
refcount_set(&skb->users, 1);
dev_kfree_skb_any(skb); /* put this one back */
} else {
__kfree_skb(skb);
}
}
}
put_cpu_var(softnet_data);
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/string.h`, `linux/if_arp.h`, `linux/inetdevice.h`, `linux/inet.h`.
- Detected declarations: `function netpoll_start_xmit`, `function queue_process`, `function netif_local_xmit_active`, `function poll_one_napi`, `function poll_napi`, `function list_for_each_entry_rcu`, `function netpoll_poll_dev`, `function netpoll_poll_disable`, `function netpoll_poll_enable`, `function refill_skbs`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.