tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
Extension
.c
Size
4404 bytes
Lines
210
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 segarr_entry {
	u8 __arena *block;
	size_t sz;
	u8 poison;
};

#define SEGARRLEN (512)
static struct segarr_entry __arena segarr[SEGARRLEN];
static void __arena *ptrs[17];
size_t __arena alloc_sizes[] = { 3, 17, 1025, 129, 16350, 333, 9, 517 };
size_t __arena alloc_multiple_sizes[] = { 3, 17, 1025, 129, 16350, 333, 9, 517, 2099 };
size_t __arena alloc_free_sizes[] = { 3, 17, 64, 129, 256, 333, 512, 517 };
size_t __arena alignment_sizes[] = { 1, 3, 7, 8, 9, 15, 16, 17, 31,
				     32, 64, 100, 128, 255, 256, 512, 1000 };

SEC("syscall")
__weak int test_buddy_create(void)
{
	const int iters = 10;
	int ret, i;

	for (i = zero; i < iters && can_loop; i++) {
		ret = buddy_init(&buddy);
		if (ret)
			return ret;

		ret = buddy_destroy(&buddy);
		if (ret)
			return ret;
	}

	return 0;
}

SEC("syscall")
__weak int test_buddy_alloc(void)
{
	void __arena *mem;
	int ret, i;

	for (i = zero; i < 8 && can_loop; i++) {
		ret = buddy_init(&buddy);
		if (ret)
			return ret;

		mem = buddy_alloc(&buddy, alloc_sizes[i]);
		if (!mem) {
			buddy_destroy(&buddy);
			return -ENOMEM;
		}

		buddy_destroy(&buddy);
	}

	return 0;
}

SEC("syscall")
__weak int test_buddy_alloc_free(void)
{
	const int iters = 800;
	void __arena *mem;
	int ret, i;

	ret = buddy_init(&buddy);
	if (ret)
		return ret;

	for (i = zero; i < iters && can_loop; i++) {
		mem = buddy_alloc(&buddy, alloc_free_sizes[(i * 5) % 8]);
		if (!mem) {
			buddy_destroy(&buddy);
			return -ENOMEM;
		}

		buddy_free(&buddy, mem);
	}

	buddy_destroy(&buddy);

	return 0;
}

SEC("syscall")
__weak int test_buddy_alloc_multiple(void)
{
	int ret, j;
	u32 i, idx;
	u8 __arena *mem;
	size_t sz;

Annotation

Implementation Notes