tools/net/ynl/ynltool/page-pool.c
Source file repositories/reference/linux-study-clean/tools/net/ynl/ynltool/page-pool.c
File Facts
- System
- Linux kernel
- Corpus path
tools/net/ynl/ynltool/page-pool.c- Extension
.c- Size
- 11479 bytes
- Lines
- 464
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstring.herrno.hnet/if.hynl.hnetdev-user.hmain.h
Detected Declarations
struct pp_statstruct pp_stats_arrayfunction count_poolfunction print_json_recycling_statsfunction print_plain_recycling_statsfunction print_json_statsfunction print_plain_statsfunction find_pool_stat_in_listfunction print_json_pool_listfunction ynl_dump_foreachfunction print_plain_pool_listfunction aggregate_device_statsfunction ynl_dump_foreachfunction do_statsfunction is_prefixfunction do_helpfunction do_page_pool
Annotated Snippet
struct pp_stat {
unsigned int ifc;
struct {
unsigned int cnt;
size_t refs, bytes;
} live[2];
size_t alloc_slow, alloc_fast, recycle_ring, recycle_cache;
};
struct pp_stats_array {
unsigned int i, max;
struct pp_stat *s;
};
static struct pp_stat *find_ifc(struct pp_stats_array *a, unsigned int ifindex)
{
unsigned int i;
for (i = 0; i < a->i; i++) {
if (a->s[i].ifc == ifindex)
return &a->s[i];
}
a->i++;
if (a->i == a->max) {
a->max *= 2;
a->s = reallocarray(a->s, a->max, sizeof(*a->s));
}
a->s[i].ifc = ifindex;
return &a->s[i];
}
static void count_pool(struct pp_stat *s, unsigned int l,
struct netdev_page_pool_get_rsp *pp)
{
s->live[l].cnt++;
if (pp->_present.inflight)
s->live[l].refs += pp->inflight;
if (pp->_present.inflight_mem)
s->live[l].bytes += pp->inflight_mem;
}
/* We don't know how many pages are sitting in cache and ring
* so we will under-count the recycling rate a bit.
*/
static void print_json_recycling_stats(struct pp_stat *s)
{
double recycle;
if (s->alloc_fast + s->alloc_slow) {
recycle = (double)(s->recycle_ring + s->recycle_cache) /
(s->alloc_fast + s->alloc_slow) * 100;
jsonw_float_field(json_wtr, "recycling_pct", recycle);
}
jsonw_name(json_wtr, "alloc");
jsonw_start_object(json_wtr);
jsonw_uint_field(json_wtr, "slow", s->alloc_slow);
jsonw_uint_field(json_wtr, "fast", s->alloc_fast);
jsonw_end_object(json_wtr);
jsonw_name(json_wtr, "recycle");
jsonw_start_object(json_wtr);
jsonw_uint_field(json_wtr, "ring", s->recycle_ring);
jsonw_uint_field(json_wtr, "cache", s->recycle_cache);
jsonw_end_object(json_wtr);
}
static void print_plain_recycling_stats(struct pp_stat *s)
{
double recycle;
if (s->alloc_fast + s->alloc_slow) {
recycle = (double)(s->recycle_ring + s->recycle_cache) /
(s->alloc_fast + s->alloc_slow) * 100;
printf("recycling: %.1lf%% (alloc: %zu:%zu recycle: %zu:%zu)",
recycle, s->alloc_slow, s->alloc_fast,
s->recycle_ring, s->recycle_cache);
}
}
static void print_json_stats(struct pp_stats_array *a)
{
jsonw_start_array(json_wtr);
for (unsigned int i = 0; i < a->i; i++) {
char ifname[IF_NAMESIZE];
struct pp_stat *s = &a->s[i];
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `net/if.h`, `ynl.h`, `netdev-user.h`, `main.h`.
- Detected declarations: `struct pp_stat`, `struct pp_stats_array`, `function count_pool`, `function print_json_recycling_stats`, `function print_plain_recycling_stats`, `function print_json_stats`, `function print_plain_stats`, `function find_pool_stat_in_list`, `function print_json_pool_list`, `function ynl_dump_foreach`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.