net/sched/sch_generic.c
Source file repositories/reference/linux-study-clean/net/sched/sch_generic.c
File Facts
- System
- Linux kernel
- Corpus path
net/sched/sch_generic.c- Extension
.c- Size
- 40786 bytes
- Lines
- 1645
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/bitops.hlinux/module.hlinux/types.hlinux/kernel.hlinux/sched.hlinux/string.hlinux/errno.hlinux/netdevice.hlinux/skbuff.hlinux/rtnetlink.hlinux/init.hlinux/rcupdate.hlinux/list.hlinux/slab.hlinux/if_vlan.hlinux/skb_array.hlinux/if_macvlan.hlinux/bpf.htrace/events/qdisc.hnet/sch_generic.hnet/pkt_sched.hnet/dst.hnet/hotdata.htrace/events/net.hnet/xfrm.h
Detected Declarations
struct pfifo_fast_privfunction __tcf_kfree_skb_listfunction qdisc_maybe_clear_missedfunction qdisc_lockfunction qdisc_enqueue_skb_bad_txqfunction dev_requeue_skbfunction try_bulk_dequeue_skbfunction try_bulk_dequeue_skb_slowfunction skbfunction sch_direct_xmitfunction qdisc_lockfunction __qdisc_runfunction dev_trans_startfunction netif_freeze_queuesfunction netif_tx_lockfunction netif_unfreeze_queuesfunction netif_tx_unlockfunction dev_watchdogfunction netdev_watchdog_upfunction round_jiffiesfunction netdev_watchdog_downfunction netif_carrier_onfunction netif_carrier_offfunction eventsfunction noop_enqueuefunction noqueue_initfunction pfifo_fast_enqueuefunction READ_ONCEfunction pfifo_fast_resetfunction pfifo_fast_dumpfunction pfifo_fast_initfunction pfifo_fast_destroyfunction pfifo_fast_change_tx_queue_lenfunction qdisc_resetfunction qdisc_freefunction qdisc_free_cbfunction __qdisc_destroyfunction qdisc_destroyfunction qdisc_putfunction qdisc_put_unlockedfunction shutdown_scheduler_queuefunction attach_one_default_qdiscfunction attach_default_qdiscsfunction transition_one_qdiscfunction dev_activatefunction qdisc_deactivatefunction dev_deactivate_queuefunction some_qdisc_is_busy
Annotated Snippet
struct pfifo_fast_priv {
struct skb_array q[PFIFO_FAST_BANDS];
};
static inline struct skb_array *band2list(struct pfifo_fast_priv *priv,
int band)
{
return &priv->q[band];
}
static int pfifo_fast_enqueue(struct sk_buff *skb, struct Qdisc *qdisc,
struct sk_buff **to_free)
{
int band = sch_default_prio2band[skb->priority & TC_PRIO_MAX];
struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
struct skb_array *q = band2list(priv, band);
unsigned int pkt_len = qdisc_pkt_len(skb);
int err;
err = skb_array_produce(q, skb);
if (unlikely(err)) {
tcf_set_qdisc_drop_reason(skb, QDISC_DROP_OVERLIMIT);
if (qdisc_is_percpu_stats(qdisc))
return qdisc_drop_cpu(skb, qdisc, to_free);
else
return qdisc_drop(skb, qdisc, to_free);
}
qdisc_update_stats_at_enqueue(qdisc, pkt_len);
return NET_XMIT_SUCCESS;
}
static struct sk_buff *pfifo_fast_dequeue(struct Qdisc *qdisc)
{
struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
struct sk_buff *skb = NULL;
bool need_retry = true;
int band;
retry:
for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) {
struct skb_array *q = band2list(priv, band);
if (__skb_array_empty(q))
continue;
skb = __skb_array_consume(q);
}
if (likely(skb)) {
qdisc_update_stats_at_dequeue(qdisc, skb);
} else if (need_retry &&
READ_ONCE(qdisc->state) & QDISC_STATE_NON_EMPTY) {
/* Delay clearing the STATE_MISSED here to reduce
* the overhead of the second spin_trylock() in
* qdisc_run_begin() and __netif_schedule() calling
* in qdisc_run_end().
*/
clear_bit(__QDISC_STATE_MISSED, &qdisc->state);
clear_bit(__QDISC_STATE_DRAINING, &qdisc->state);
/* Make sure dequeuing happens after clearing
* STATE_MISSED.
*/
smp_mb__after_atomic();
need_retry = false;
goto retry;
}
return skb;
}
static struct sk_buff *pfifo_fast_peek(struct Qdisc *qdisc)
{
struct pfifo_fast_priv *priv = qdisc_priv(qdisc);
struct sk_buff *skb = NULL;
int band;
for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) {
struct skb_array *q = band2list(priv, band);
skb = __skb_array_peek(q);
}
return skb;
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/sched.h`, `linux/string.h`, `linux/errno.h`, `linux/netdevice.h`.
- Detected declarations: `struct pfifo_fast_priv`, `function __tcf_kfree_skb_list`, `function qdisc_maybe_clear_missed`, `function qdisc_lock`, `function qdisc_enqueue_skb_bad_txq`, `function dev_requeue_skb`, `function try_bulk_dequeue_skb`, `function try_bulk_dequeue_skb_slow`, `function skb`, `function sch_direct_xmit`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.