// SPDX-License-Identifier: GPL-2.0-only /* * iteration_check.c: test races having to do with xarray iteration * Copyright (c) 2016 Intel Corporation * Author: Ross Zwisler <ross.zwisler@linux.intel.com>
*/ #include <pthread.h> #include"test.h"
/* * Iterate over tagged entries, retrying when we find ourselves in a deleted * node and randomly pausing the iteration.
*/ staticvoid *tagged_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_marked(&xas, entry, ULONG_MAX, TAG) { if (xas_retry(&xas, entry)) continue;
/* * Iterate over the entries, retrying when we find ourselves in a deleted * node and randomly pausing the iteration.
*/ staticvoid *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;
/* * Randomly remove entries to help induce retries in the * two iteration functions.
*/ staticvoid *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);
}
/* This is a unit test for a bug found by the syzkaller tester */ void iteration_test(unsigned order, unsigned test_duration)
{ int i;
printv(1, "Running %siteration tests for %d seconds\n",
order > 0 ? "multiorder " : "", test_duration);
max_order = order;
test_complete = false;
for (i = 0; i < 3; i++)
seeds[i] = rand();
if (pthread_create(&threads[0], NULL, tagged_iteration_fn, NULL)) {
perror("create tagged iteration thread"); exit(1);
} if (pthread_create(&threads[1], NULL, untagged_iteration_fn, NULL)) {
perror("create untagged iteration thread"); exit(1);
} if (pthread_create(&threads[2], NULL, add_entries_fn, NULL)) {
perror("create add entry thread"); exit(1);
} if (pthread_create(&threads[3], NULL, remove_entries_fn, NULL)) {
perror("create remove entry thread"); exit(1);
} if (pthread_create(&threads[4], NULL, tag_entries_fn, NULL)) {
perror("create tag entry thread"); exit(1);
}
sleep(test_duration);
test_complete = true;
for (i = 0; i < NUM_THREADS; i++) { if (pthread_join(threads[i], NULL)) {
perror("pthread_join"); exit(1);
}
}
item_kill_tree(&array);
}
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.