tools/testing/selftests/sched_ext/peek_dsq.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/sched_ext/peek_dsq.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/sched_ext/peek_dsq.c
Extension
.c
Size
6106 bytes
Lines
225
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 (err == 0) {
			if (pid == 0) {
				printf("  Sample %d: NULL peek\n", i);
			} else if (pid > 0) {
				printf("  Sample %d: pid %ld\n", i, pid);
				count++;
			}
		} else {
			printf("  Sample %d: error reading pid (err=%d)\n", i, err);
		}
	}
	printf("Observed ~%ld pids in the %s DSQ(s)\n", count, dsq_name);
	return count;
}

static enum scx_test_status run(void *ctx)
{
	struct peek_dsq *skel = ctx;
	bool failed = false;
	int seconds = 3;
	int err;

	/* Enable the scheduler to test DSQ operations */
	printf("Enabling scheduler to test DSQ insert operations...\n");

	struct bpf_link *link =
		bpf_map__attach_struct_ops(skel->maps.peek_dsq_ops);

	if (!link) {
		SCX_ERR("Failed to attach struct_ops");
		return SCX_TEST_FAIL;
	}

	printf("Starting %d background workload threads...\n", NUM_WORKERS);
	workload_running = true;
	for (int i = 0; i < NUM_WORKERS; i++) {
		err = pthread_create(&workload_threads[i], NULL, workload_thread_fn, NULL);
		if (err) {
			SCX_ERR("Failed to create workload thread %d: %s", i, strerror(err));
			/* Stop already created threads */
			workload_running = false;
			for (int j = 0; j < i; j++)
				pthread_join(workload_threads[j], NULL);
			bpf_link__destroy(link);
			return SCX_TEST_FAIL;
		}
	}

	printf("Waiting for enqueue events.\n");
	sleep(seconds);
	while (skel->data->enqueue_count <= 0) {
		printf(".");
		fflush(stdout);
		sleep(1);
		seconds++;
		if (seconds >= 30) {
			printf("\n\u2717 Timeout waiting for enqueue events\n");
			/* Stop workload threads and cleanup */
			workload_running = false;
			for (int i = 0; i < NUM_WORKERS; i++)
				pthread_join(workload_threads[i], NULL);
			bpf_link__destroy(link);
			return SCX_TEST_FAIL;
		}
	}

	workload_running = false;
	for (int i = 0; i < NUM_WORKERS; i++) {
		err = pthread_join(workload_threads[i], NULL);
		if (err) {
			SCX_ERR("Failed to join workload thread %d: %s", i, strerror(err));
			bpf_link__destroy(link);
			return SCX_TEST_FAIL;
		}
	}
	printf("Background workload threads stopped.\n");

	SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_NONE));

	/* Detach the scheduler */
	bpf_link__destroy(link);

	printf("Enqueue/dispatch count over %d seconds: %d / %d\n", seconds,
		skel->data->enqueue_count, skel->data->dispatch_count);
	printf("Debug: ksym_exists=%d\n",
	       skel->bss->debug_ksym_exists);

	/* Check DSQ insert result */
	printf("DSQ insert test done on cpu: %d\n", skel->data->insert_test_cpu);
	if (skel->data->insert_test_cpu != -1)

Annotation

Implementation Notes