tools/testing/radix-tree/iteration_check.c

Source file repositories/reference/linux-study-clean/tools/testing/radix-tree/iteration_check.c

File Facts

System
Linux kernel
Corpus path
tools/testing/radix-tree/iteration_check.c
Extension
.c
Size
4203 bytes
Lines
211
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

xas_for_each_marked(&xas, entry, ULONG_MAX, TAG) {
			if (xas_retry(&xas, entry))
				continue;

			if (rand_r(&seeds[0]) % 50 == 0) {
				xas_pause(&xas);
				rcu_read_unlock();
				rcu_barrier();
				rcu_read_lock();
			}
		}
		rcu_read_unlock();
	}

	rcu_unregister_thread();

	return NULL;
}

/*
 * Iterate over the entries, retrying when we find ourselves in a deleted
 * node and randomly pausing the iteration.
 */
static void *untagged_iteration_fn(void *arg)
{
	XA_STATE(xas, &array, 0);
	void *entry;

	rcu_register_thread();

	while (!test_complete) {
		xas_set(&xas, 0);
		rcu_read_lock();
		xas_for_each(&xas, entry, ULONG_MAX) {
			if (xas_retry(&xas, entry))
				continue;

			if (rand_r(&seeds[1]) % 50 == 0) {
				xas_pause(&xas);
				rcu_read_unlock();
				rcu_barrier();
				rcu_read_lock();
			}
		}
		rcu_read_unlock();
	}

	rcu_unregister_thread();

	return NULL;
}

/*
 * Randomly remove entries to help induce retries in the
 * two iteration functions.
 */
static void *remove_entries_fn(void *arg)
{
	rcu_register_thread();

	while (!test_complete) {
		int pgoff;
		struct item *item;

		pgoff = rand_r(&seeds[2]) % MAX_IDX;

		item = xa_erase(&array, pgoff);
		if (item)
			item_free(item, pgoff);
	}

	rcu_unregister_thread();

	return NULL;
}

static void *tag_entries_fn(void *arg)
{
	rcu_register_thread();

	while (!test_complete) {
		tag_tagged_items(&array, 0, MAX_IDX, 10, TAG, NEW_TAG);
	}
	rcu_unregister_thread();
	return NULL;
}

/* This is a unit test for a bug found by the syzkaller tester */
void iteration_test(unsigned order, unsigned test_duration)
{

Annotation

Implementation Notes