• Home
  • Raw
  • Download

Lines Matching +full:cpu +full:- +full:nr

1 // SPDX-License-Identifier: GPL-2.0-only
11 * There are three threads running per CPU:
13 * 1) one per-CPU thread takes a per-page pthread_mutex in a random
15 * area_src), and increments a per-page counter in the same page,
18 * 2) another per-CPU thread handles the userfaults generated by
22 * 3) one last per-CPU thread transfers the memory in the background
24 * 2). Each cpu thread takes cares of transferring a portion of the
32 * per-CPU threads 1 by triggering userfaults inside
80 /* Whether to test uffd write-protection */
94 int cpu; member
104 * to avoid non alignment faults on non-x86 archs.
110 sizeof(unsigned long long) - 1) & \
112 - 1)))
123 "# 10MiB-~6GiB 999 bounces anonymous test, "
144 uffd_stats[i].cpu = i; in uffd_stats_reset()
184 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); in anon_allocate_area()
263 * MADV_DONTEED won't work. So exercise -EEXIST on a alias in hugetlb_alias_mapping()
265 * this way we'll exercise the -EEXEC at the fs level. in hugetlb_alias_mapping()
286 MAP_ANONYMOUS | MAP_SHARED, -1, 0); in shmem_allocate_area()
348 /* Undo write-protect, do wakeup after that */ in wp_range()
359 unsigned long cpu = (unsigned long) arg; in locking_thread() local
369 seed = (unsigned int) time(NULL) - bounces; in locking_thread()
371 seed += cpu; in locking_thread()
379 page_nr = -bounces; in locking_thread()
381 page_nr += cpu * nr_pages_per_cpu; in locking_thread()
447 page_nr, cpu, area_dst + page_nr * page_size, in locking_thread()
467 if (time(NULL) - start > 1) in locking_thread()
471 time(NULL) - start); in locking_thread()
480 uffd_test_ops->alias_mapping(&uffdio_copy->dst, in retry_copy_page()
481 uffdio_copy->len, in retry_copy_page()
485 if (uffdio_copy->copy != -EEXIST) { in retry_copy_page()
487 uffdio_copy->copy); in retry_copy_page()
492 uffdio_copy->copy); exit(1); in retry_copy_page()
514 if (uffdio_copy.copy != -EEXIST) { in __copy_page()
565 if (msg->event != UFFD_EVENT_PAGEFAULT) { in uffd_handle_page_fault()
566 fprintf(stderr, "unexpected msg event %u\n", msg->event); in uffd_handle_page_fault()
570 if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) { in uffd_handle_page_fault()
571 wp_range(uffd, msg->arg.pagefault.address, page_size, false); in uffd_handle_page_fault()
572 stats->wp_faults++; in uffd_handle_page_fault()
576 msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WRITE) { in uffd_handle_page_fault()
581 offset = (char *)(unsigned long)msg->arg.pagefault.address - area_dst; in uffd_handle_page_fault()
582 offset &= ~(page_size-1); in uffd_handle_page_fault()
585 stats->missing_faults++; in uffd_handle_page_fault()
592 unsigned long cpu = stats->cpu; in uffd_poll_thread() local
601 pollfd[1].fd = pipefd[cpu*2]; in uffd_poll_thread()
605 ret = poll(pollfd, 2, -1); in uffd_poll_thread()
643 uffd_reg.range.len = msg.arg.remove.end - in uffd_poll_thread()
680 unsigned long cpu = (unsigned long) arg; in background_thread() local
683 start_nr = cpu * nr_pages_per_cpu; in background_thread()
684 end_nr = (cpu+1) * nr_pages_per_cpu; in background_thread()
692 * If we need to test uffd-wp, set it up now. Then we'll have in background_thread()
694 * can be write-protected for testing in background_thread()
712 unsigned long cpu; in stress() local
718 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
719 if (pthread_create(&locking_threads[cpu], &attr, in stress()
720 locking_thread, (void *)cpu)) in stress()
723 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
725 (void *)&uffd_stats[cpu])) in stress()
728 if (pthread_create(&uffd_threads[cpu], &attr, in stress()
730 (void *)&uffd_stats[cpu])) in stress()
734 if (pthread_create(&background_threads[cpu], &attr, in stress()
735 background_thread, (void *)cpu)) in stress()
738 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
739 if (pthread_join(background_threads[cpu], NULL)) in stress()
747 * area_src (but they're guaranteed to get -EEXIST from in stress()
751 if (uffd_test_ops->release_pages(area_src)) in stress()
756 for (cpu = 0; cpu < nr_cpus; cpu++) in stress()
757 if (pthread_join(locking_threads[cpu], NULL)) in stress()
760 for (cpu = 0; cpu < nr_cpus; cpu++) { in stress()
763 if (write(pipefd[cpu*2+1], &c, 1) != 1) { in stress()
767 if (pthread_join(uffd_threads[cpu], in stress()
768 (void *)&uffd_stats[cpu])) in stress()
771 if (pthread_cancel(uffd_threads[cpu])) in stress()
773 if (pthread_join(uffd_threads[cpu], NULL)) in stress()
819 * For non-cooperative userfaultfd test we fork() a process that will
834 * test robustness use case - we release monitored area, fork a process
841 unsigned long nr; in faulting_process() local
862 lastnr = (unsigned long)-1; in faulting_process()
865 for (nr = 0; nr < split_nr_pages; nr++) { in faulting_process()
867 unsigned long offset = nr * page_size; in faulting_process()
871 if (steps == 1 && nr == lastnr) { in faulting_process()
876 lastnr = nr; in faulting_process()
898 count = *area_count(area_dst, nr); in faulting_process()
899 if (count != count_verify[nr]) { in faulting_process()
901 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
902 nr, count, in faulting_process()
903 count_verify[nr]); in faulting_process()
909 *area_count(area_dst, nr) = count; in faulting_process()
925 for (; nr < nr_pages; nr++) { in faulting_process()
926 count = *area_count(area_dst, nr); in faulting_process()
927 if (count != count_verify[nr]) { in faulting_process()
929 "nr %lu memory corruption %Lu %Lu\n", in faulting_process()
930 nr, count, in faulting_process()
931 count_verify[nr]); exit(1); in faulting_process()
937 *area_count(area_dst, nr) = count; in faulting_process()
940 if (uffd_test_ops->release_pages(area_dst)) in faulting_process()
943 for (nr = 0; nr < nr_pages; nr++) { in faulting_process()
944 if (my_bcmp(area_dst + nr * page_size, zeropage, page_size)) { in faulting_process()
945 fprintf(stderr, "nr %lu is not zero\n", nr); in faulting_process()
957 uffd_test_ops->alias_mapping(&uffdio_zeropage->range.start, in retry_uffdio_zeropage()
958 uffdio_zeropage->range.len, in retry_uffdio_zeropage()
961 if (uffdio_zeropage->zeropage != -EEXIST) { in retry_uffdio_zeropage()
963 uffdio_zeropage->zeropage); in retry_uffdio_zeropage()
968 uffdio_zeropage->zeropage); exit(1); in retry_uffdio_zeropage()
978 has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE); in __uffdio_zeropage()
991 if (uffdio_zeropage.zeropage == -EEXIST) { in __uffdio_zeropage()
992 fprintf(stderr, "UFFDIO_ZEROPAGE -EEXIST\n"); in __uffdio_zeropage()
1000 if (uffdio_zeropage.zeropage != -EINVAL) { in __uffdio_zeropage()
1002 "UFFDIO_ZEROPAGE not -EINVAL %Ld\n", in __uffdio_zeropage()
1042 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_zeropage_test()
1057 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_zeropage_test()
1090 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_events_test()
1109 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_events_test()
1163 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1181 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_sig_test()
1192 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_sig_test()
1234 unsigned long nr; in userfaultfd_stress() local
1236 unsigned long cpu; in userfaultfd_stress() local
1240 uffd_test_ops->allocate_area((void **)&area_src); in userfaultfd_stress()
1243 uffd_test_ops->allocate_area((void **)&area_dst); in userfaultfd_stress()
1256 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1257 *area_mutex(area_src, nr) = (pthread_mutex_t) in userfaultfd_stress()
1259 count_verify[nr] = *area_count(area_src, nr) = 1; in userfaultfd_stress()
1263 * zero, so leave a placeholder below always non-zero in userfaultfd_stress()
1267 *(area_count(area_src, nr) + 1) = 1; in userfaultfd_stress()
1275 for (cpu = 0; cpu < nr_cpus; cpu++) { in userfaultfd_stress()
1276 if (pipe2(&pipefd[cpu*2], O_CLOEXEC | O_NONBLOCK)) { in userfaultfd_stress()
1295 while (bounces--) { in userfaultfd_stress()
1325 expected_ioctls = uffd_test_ops->expected_ioctls; in userfaultfd_stress()
1350 * return -EEXIST). The problem comes at the next in userfaultfd_stress()
1355 * area_src would lead to -EEXIST failure during the in userfaultfd_stress()
1366 if (uffd_test_ops->release_pages(area_dst)) in userfaultfd_stress()
1396 for (nr = 0; nr < nr_pages; nr++) { in userfaultfd_stress()
1397 if (*area_count(area_dst, nr) != count_verify[nr]) { in userfaultfd_stress()
1400 *area_count(area_src, nr), in userfaultfd_stress()
1401 count_verify[nr], in userfaultfd_stress()
1402 nr); in userfaultfd_stress()
1430 * Copied from mlock2-tests.c
1458 /* Only enable write-protect test for anonymous test */ in set_test_type()