Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * iteration_check_2.c: Check that deleting a tagged entry doesn't cause
0004  * an RCU walker to finish early.
0005  * Copyright (c) 2020 Oracle
0006  * Author: Matthew Wilcox <willy@infradead.org>
0007  */
0008 #include <pthread.h>
0009 #include "test.h"
0010 
0011 static volatile bool test_complete;
0012 
0013 static void *iterator(void *arg)
0014 {
0015     XA_STATE(xas, arg, 0);
0016     void *entry;
0017 
0018     rcu_register_thread();
0019 
0020     while (!test_complete) {
0021         xas_set(&xas, 0);
0022         rcu_read_lock();
0023         xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0)
0024             ;
0025         rcu_read_unlock();
0026         assert(xas.xa_index >= 100);
0027     }
0028 
0029     rcu_unregister_thread();
0030     return NULL;
0031 }
0032 
0033 static void *throbber(void *arg)
0034 {
0035     struct xarray *xa = arg;
0036 
0037     rcu_register_thread();
0038 
0039     while (!test_complete) {
0040         int i;
0041 
0042         for (i = 0; i < 100; i++) {
0043             xa_store(xa, i, xa_mk_value(i), GFP_KERNEL);
0044             xa_set_mark(xa, i, XA_MARK_0);
0045         }
0046         for (i = 0; i < 100; i++)
0047             xa_erase(xa, i);
0048     }
0049 
0050     rcu_unregister_thread();
0051     return NULL;
0052 }
0053 
0054 void iteration_test2(unsigned test_duration)
0055 {
0056     pthread_t threads[2];
0057     DEFINE_XARRAY(array);
0058     int i;
0059 
0060     printv(1, "Running iteration test 2 for %d seconds\n", test_duration);
0061 
0062     test_complete = false;
0063 
0064     xa_store(&array, 100, xa_mk_value(100), GFP_KERNEL);
0065     xa_set_mark(&array, 100, XA_MARK_0);
0066 
0067     if (pthread_create(&threads[0], NULL, iterator, &array)) {
0068         perror("create iterator thread");
0069         exit(1);
0070     }
0071     if (pthread_create(&threads[1], NULL, throbber, &array)) {
0072         perror("create throbber thread");
0073         exit(1);
0074     }
0075 
0076     sleep(test_duration);
0077     test_complete = true;
0078 
0079     for (i = 0; i < 2; i++) {
0080         if (pthread_join(threads[i], NULL)) {
0081             perror("pthread_join");
0082             exit(1);
0083         }
0084     }
0085 
0086     xa_destroy(&array);
0087 }