Re: [PATCH bpf-next v2 4/4] selftests/bpf: Test concurrent updates on bpf_task_storage_busy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 01, 2022 at 02:19:38PM +0800, Hou Tao wrote:
> +void test_task_storage_map_stress_lookup(void)
> +{
> +#define MAX_NR_THREAD 4096
> +	unsigned int i, nr = 256, loop = 8192, cpu = 0;
> +	struct read_bpf_task_storage_busy *skel;
> +	pthread_t tids[MAX_NR_THREAD];
> +	struct lookup_ctx ctx;
> +	cpu_set_t old, new;
> +	const char *cfg;
> +	int err;
> +
> +	cfg = getenv("TASK_STORAGE_MAP_NR_THREAD");
> +	if (cfg) {
> +		nr = atoi(cfg);
> +		if (nr > MAX_NR_THREAD)
> +			nr = MAX_NR_THREAD;
> +	}
> +	cfg = getenv("TASK_STORAGE_MAP_NR_LOOP");
> +	if (cfg)
> +		loop = atoi(cfg);
> +	cfg = getenv("TASK_STORAGE_MAP_PIN_CPU");
> +	if (cfg)
> +		cpu = atoi(cfg);
> +
> +	skel = read_bpf_task_storage_busy__open_and_load();
> +	err = libbpf_get_error(skel);
> +	CHECK(err, "open_and_load", "error %d\n", err);
> +
> +	/* Only for a fully preemptible kernel */
> +	if (!skel->kconfig->CONFIG_PREEMPT)
> +		return;
> +
> +	/* Save the old affinity setting */
> +	sched_getaffinity(getpid(), sizeof(old), &old);
> +
> +	/* Pinned on a specific CPU */
> +	CPU_ZERO(&new);
> +	CPU_SET(cpu, &new);
> +	sched_setaffinity(getpid(), sizeof(new), &new);
> +
> +	ctx.start = false;
> +	ctx.stop = false;
> +	ctx.pid_fd = sys_pidfd_open(getpid(), 0);
> +	ctx.map_fd = bpf_map__fd(skel->maps.task);
> +	ctx.loop = loop;
> +	for (i = 0; i < nr; i++) {
> +		err = pthread_create(&tids[i], NULL, lookup_fn, &ctx);
> +		if (err) {
> +			abort_lookup(&ctx, tids, i);
> +			CHECK(err, "pthread_create", "error %d\n", err);
> +			goto out;
> +		}
> +	}
> +
> +	ctx.start = true;
> +	for (i = 0; i < nr; i++)
> +		pthread_join(tids[i], NULL);
> +
> +	skel->bss->pid = getpid();
> +	err = read_bpf_task_storage_busy__attach(skel);
> +	CHECK(err, "attach", "error %d\n", err);
> +
> +	/* Trigger program */
> +	syscall(SYS_gettid);
> +	skel->bss->pid = 0;
> +
> +	CHECK(skel->bss->busy != 0, "bad bpf_task_storage_busy", "got %d\n", skel->bss->busy);
Applied.  One nit.
Please follow up with a test PASS or SKIP printf.
There is a 'skips' counter in test_maps.c that
is good to bump also.



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux