iteration_check_2.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * iteration_check_2.c: Check that deleting a tagged entry doesn't cause
  4. * an RCU walker to finish early.
  5. * Copyright (c) 2020 Oracle
  6. * Author: Matthew Wilcox <[email protected]>
  7. */
  8. #include <pthread.h>
  9. #include "test.h"
  10. static volatile bool test_complete;
  11. static void *iterator(void *arg)
  12. {
  13. XA_STATE(xas, arg, 0);
  14. void *entry;
  15. rcu_register_thread();
  16. while (!test_complete) {
  17. xas_set(&xas, 0);
  18. rcu_read_lock();
  19. xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0)
  20. ;
  21. rcu_read_unlock();
  22. assert(xas.xa_index >= 100);
  23. }
  24. rcu_unregister_thread();
  25. return NULL;
  26. }
  27. static void *throbber(void *arg)
  28. {
  29. struct xarray *xa = arg;
  30. rcu_register_thread();
  31. while (!test_complete) {
  32. int i;
  33. for (i = 0; i < 100; i++) {
  34. xa_store(xa, i, xa_mk_value(i), GFP_KERNEL);
  35. xa_set_mark(xa, i, XA_MARK_0);
  36. }
  37. for (i = 0; i < 100; i++)
  38. xa_erase(xa, i);
  39. }
  40. rcu_unregister_thread();
  41. return NULL;
  42. }
  43. void iteration_test2(unsigned test_duration)
  44. {
  45. pthread_t threads[2];
  46. DEFINE_XARRAY(array);
  47. int i;
  48. printv(1, "Running iteration test 2 for %d seconds\n", test_duration);
  49. test_complete = false;
  50. xa_store(&array, 100, xa_mk_value(100), GFP_KERNEL);
  51. xa_set_mark(&array, 100, XA_MARK_0);
  52. if (pthread_create(&threads[0], NULL, iterator, &array)) {
  53. perror("create iterator thread");
  54. exit(1);
  55. }
  56. if (pthread_create(&threads[1], NULL, throbber, &array)) {
  57. perror("create throbber thread");
  58. exit(1);
  59. }
  60. sleep(test_duration);
  61. test_complete = true;
  62. for (i = 0; i < 2; i++) {
  63. if (pthread_join(threads[i], NULL)) {
  64. perror("pthread_join");
  65. exit(1);
  66. }
  67. }
  68. xa_destroy(&array);
  69. }