net/core/gen_stats.c
Source file repositories/reference/linux-study-clean/net/core/gen_stats.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/gen_stats.c- Extension
.c- Size
- 13674 bytes
- Lines
- 485
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/kernel.hlinux/module.hlinux/interrupt.hlinux/socket.hlinux/rtnetlink.hlinux/gen_stats.hnet/netlink.hnet/gen_stats.hnet/sch_generic.h
Detected Declarations
function gnet_stats_copyfunction gnet_stats_copy_XXXfunction gnet_stats_start_copyfunction gnet_stats_basic_sync_initfunction gnet_stats_add_basic_cpufunction for_each_possible_cpufunction gnet_stats_add_basicfunction gnet_stats_read_basicfunction for_each_possible_cpufunction ___gnet_stats_copy_basicfunction gnet_stats_start_copyfunction gnet_stats_start_copyfunction gnet_stats_start_copyfunction gnet_stats_add_queue_cpufunction for_each_possible_cpufunction gnet_stats_add_queuefunction gnet_stats_start_copyfunction gnet_stats_start_copyfunction gnet_stats_copy_XXXexport gnet_stats_start_copy_compatexport gnet_stats_start_copyexport gnet_stats_basic_sync_initexport gnet_stats_add_basicexport gnet_stats_copy_basicexport gnet_stats_copy_basic_hwexport gnet_stats_copy_rate_estexport gnet_stats_add_queueexport gnet_stats_copy_queueexport gnet_stats_copy_appexport gnet_stats_finish_copy
Annotated Snippet
for_each_possible_cpu(i) {
const struct gnet_stats_basic_sync *bcpu = per_cpu_ptr(cpu, i);
u64 bytes, packets;
do {
start = u64_stats_fetch_begin(&bcpu->syncp);
bytes = u64_stats_read(&bcpu->bytes);
packets = u64_stats_read(&bcpu->packets);
} while (u64_stats_fetch_retry(&bcpu->syncp, start));
t_bytes += bytes;
t_packets += packets;
}
*ret_bytes = t_bytes;
*ret_packets = t_packets;
return;
}
do {
if (running)
start = u64_stats_fetch_begin(&b->syncp);
*ret_bytes = u64_stats_read(&b->bytes);
*ret_packets = u64_stats_read(&b->packets);
} while (running && u64_stats_fetch_retry(&b->syncp, start));
}
static int
___gnet_stats_copy_basic(struct gnet_dump *d,
const struct gnet_stats_basic_sync __percpu *cpu,
const struct gnet_stats_basic_sync *b,
int type, bool running)
{
u64 bstats_bytes, bstats_packets;
gnet_stats_read_basic(&bstats_bytes, &bstats_packets, cpu, b, running);
if (d->compat_tc_stats && type == TCA_STATS_BASIC) {
d->tc_stats.bytes = bstats_bytes;
d->tc_stats.packets = bstats_packets;
}
if (d->tail) {
struct gnet_stats_basic sb;
int res;
memset(&sb, 0, sizeof(sb));
sb.bytes = bstats_bytes;
sb.packets = bstats_packets;
res = gnet_stats_copy(d, type, &sb, sizeof(sb), TCA_STATS_PAD);
if (res < 0 || sb.packets == bstats_packets)
return res;
/* emit 64bit stats only if needed */
return gnet_stats_copy(d, TCA_STATS_PKT64, &bstats_packets,
sizeof(bstats_packets), TCA_STATS_PAD);
}
return 0;
}
/**
* gnet_stats_copy_basic - copy basic statistics into statistic TLV
* @d: dumping handle
* @cpu: copy statistic per cpu
* @b: basic statistics
* @running: true if @b represents a running qdisc, thus @b's
* internal values might change during basic reads.
* Only used if @cpu is NULL
*
* Context: task; must not be run from IRQ or BH contexts
*
* Appends the basic statistics to the top level TLV created by
* gnet_stats_start_copy().
*
* Returns 0 on success or -1 with the statistic lock released
* if the room in the socket buffer was not sufficient.
*/
int
gnet_stats_copy_basic(struct gnet_dump *d,
const struct gnet_stats_basic_sync __percpu *cpu,
const struct gnet_stats_basic_sync *b,
bool running)
{
return ___gnet_stats_copy_basic(d, cpu, b, TCA_STATS_BASIC, running);
}
EXPORT_SYMBOL(gnet_stats_copy_basic);
/**
* gnet_stats_copy_basic_hw - copy basic hw statistics into statistic TLV
* @d: dumping handle
* @cpu: copy statistic per cpu
* @b: basic statistics
* @running: true if @b represents a running qdisc, thus @b's
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/module.h`, `linux/interrupt.h`, `linux/socket.h`, `linux/rtnetlink.h`, `linux/gen_stats.h`, `net/netlink.h`.
- Detected declarations: `function gnet_stats_copy`, `function gnet_stats_copy_XXX`, `function gnet_stats_start_copy`, `function gnet_stats_basic_sync_init`, `function gnet_stats_add_basic_cpu`, `function for_each_possible_cpu`, `function gnet_stats_add_basic`, `function gnet_stats_read_basic`, `function for_each_possible_cpu`, `function ___gnet_stats_copy_basic`.
- 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.