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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c
Extension
.c
Size
13249 bytes
Lines
670
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

if (test_abort) {
			err = -EINTR;
			break;
		}

		cur = smp_load_acquire(&stealer_epoch);
		if (cur > target) {
			err = -EINVAL;
			test_abort = true;
			break;
		}

		if (cur == target)
			return 0;
	}

	test_abort = true;

	return err;
}

static int spmc_update_stats(u64 val, bool owner)
{
	u64 total;

	total = expected_total;
	if (val >= total || val >= TEST_SPMC_MAX_VALUES) {
		test_abort = true;
		return -EINVAL;
	}

	if (__sync_fetch_and_add(&seen[val], 1) != 0) {
		test_abort = true;
		return -EINVAL;
	}

	__sync_fetch_and_add(&total_seen, 1);
	if (owner)
		__sync_fetch_and_add(&pops, 1);
	else
		__sync_fetch_and_add(&steals, 1);

	return 0;
}

static int spmc_validate_owner_empty(void)
{
	u64 val;
	int ret;

	ret = spmc_owned_remove(spmc, &val);
	if (ret != -ENOENT) {
		test_abort = true;
		/* Change a 0 return value into -EINVAL. */
		return ret ?: -EINVAL;
	}

	return 0;
}

__weak
int spmc_validate_all_seen(void)
{
	u64 i, total;

	total = expected_total;
	if (total_seen != total)
		goto err;

	if (pops + steals != total)
		goto err;

	for (i = zero; i < total && can_loop; i++) {
		if (seen[i % TEST_SPMC_MAX_VALUES] != 1)
			goto err;
	}

	return 0;

err:
	test_abort = true;

	return -EINVAL;
}

/*
 * Single value benchmark. The owner adds an item then races with
 * the stealers for it. This way directly race between owner and
 * stealers on the same slot.
 */

Annotation

Implementation Notes