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.

Dependency Surface

Detected Declarations

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

Implementation Notes