samples/bpf/lwt_len_hist_user.c

Source file repositories/reference/linux-study-clean/samples/bpf/lwt_len_hist_user.c

File Facts

System
Linux kernel
Corpus path
samples/bpf/lwt_len_hist_user.c
Extension
.c
Size
1653 bytes
Lines
78
Domain
Support Tooling And Documentation
Bucket
samples
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

if (next_key >= MAX_INDEX) {
			fprintf(stderr, "Key %lu out of bounds\n", next_key);
			continue;
		}

		bpf_map_lookup_elem(map_fd, &next_key, values);

		sum = 0;
		for (i = 0; i < nr_cpus; i++)
			sum += values[i];

		data[next_key] = sum;
		if (sum && next_key > max_key)
			max_key = next_key;

		if (sum > max_value)
			max_value = sum;

		key = next_key;
	}

	for (i = 1; i <= max_key + 1; i++) {
		stars(starstr, data[i - 1], max_value, MAX_STARS);
		printf("%8ld -> %-8ld : %-8ld |%-*s|\n",
		       (1l << i) >> 1, (1l << i) - 1, data[i - 1],
		       MAX_STARS, starstr);
	}

	close(map_fd);

	return 0;
}

Annotation

Implementation Notes