linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@linux.ibm.com>
To: Peter Xu <peterx@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	David Hildenbrand <david@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Leonardo Bras Soares Passos <lsoaresp@redhat.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Nadav Amit <nadav.amit@gmail.com>,
	Mike Rapoport <rppt@linux.vnet.ibm.com>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Mike Rapoport <rppt@kernel.org>
Subject: Re: [PATCH v2 19/31] selftests/mm: Rename uffd_stats to uffd_args
Date: Thu, 20 Apr 2023 13:55:25 +0300	[thread overview]
Message-ID: <ZEEaHbw200cpBc+7@linux.ibm.com> (raw)
In-Reply-To: <20230412164337.328607-1-peterx@redhat.com>

On Wed, Apr 12, 2023 at 12:43:37PM -0400, Peter Xu wrote:
> Prepare for adding more fields into the struct.
> 
> Suggested-by: Mike Rapoport (IBM) <rppt@kernel.org>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>

> ---
>  tools/testing/selftests/mm/uffd-common.c | 28 ++++++-------
>  tools/testing/selftests/mm/uffd-common.h |  6 +--
>  tools/testing/selftests/mm/uffd-stress.c | 51 ++++++++++++------------
>  3 files changed, 42 insertions(+), 43 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c
> index f02dfcf10714..e746405aa8f3 100644
> --- a/tools/testing/selftests/mm/uffd-common.c
> +++ b/tools/testing/selftests/mm/uffd-common.c
> @@ -186,34 +186,34 @@ struct uffd_test_ops hugetlb_uffd_test_ops = {
>  	.check_pmd_mapping = NULL,
>  };
> 
> -void uffd_stats_report(struct uffd_stats *stats, int n_cpus)
> +void uffd_stats_report(struct uffd_args *args, int n_cpus)
>  {
>  	int i;
>  	unsigned long long miss_total = 0, wp_total = 0, minor_total = 0;
> 
>  	for (i = 0; i < n_cpus; i++) {
> -		miss_total += stats[i].missing_faults;
> -		wp_total += stats[i].wp_faults;
> -		minor_total += stats[i].minor_faults;
> +		miss_total += args[i].missing_faults;
> +		wp_total += args[i].wp_faults;
> +		minor_total += args[i].minor_faults;
>  	}
> 
>  	printf("userfaults: ");
>  	if (miss_total) {
>  		printf("%llu missing (", miss_total);
>  		for (i = 0; i < n_cpus; i++)
> -			printf("%lu+", stats[i].missing_faults);
> +			printf("%lu+", args[i].missing_faults);
>  		printf("\b) ");
>  	}
>  	if (wp_total) {
>  		printf("%llu wp (", wp_total);
>  		for (i = 0; i < n_cpus; i++)
> -			printf("%lu+", stats[i].wp_faults);
> +			printf("%lu+", args[i].wp_faults);
>  		printf("\b) ");
>  	}
>  	if (minor_total) {
>  		printf("%llu minor (", minor_total);
>  		for (i = 0; i < n_cpus; i++)
> -			printf("%lu+", stats[i].minor_faults);
> +			printf("%lu+", args[i].minor_faults);
>  		printf("\b)");
>  	}
>  	printf("\n");
> @@ -397,7 +397,7 @@ int uffd_read_msg(int ufd, struct uffd_msg *msg)
>  	return 0;
>  }
> 
> -void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats)
> +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args)
>  {
>  	unsigned long offset;
> 
> @@ -407,7 +407,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats)
>  	if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP) {
>  		/* Write protect page faults */
>  		wp_range(uffd, msg->arg.pagefault.address, page_size, false);
> -		stats->wp_faults++;
> +		args->wp_faults++;
>  	} else if (msg->arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_MINOR) {
>  		uint8_t *area;
>  		int b;
> @@ -430,7 +430,7 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats)
>  		for (b = 0; b < page_size; ++b)
>  			area[b] = ~area[b];
>  		continue_range(uffd, msg->arg.pagefault.address, page_size);
> -		stats->minor_faults++;
> +		args->minor_faults++;
>  	} else {
>  		/*
>  		 * Missing page faults.
> @@ -460,14 +460,14 @@ void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats)
>  		offset &= ~(page_size-1);
> 
>  		if (copy_page(uffd, offset))
> -			stats->missing_faults++;
> +			args->missing_faults++;
>  	}
>  }
> 
>  void *uffd_poll_thread(void *arg)
>  {
> -	struct uffd_stats *stats = (struct uffd_stats *)arg;
> -	unsigned long cpu = stats->cpu;
> +	struct uffd_args *args = (struct uffd_args *)arg;
> +	unsigned long cpu = args->cpu;
>  	struct pollfd pollfd[2];
>  	struct uffd_msg msg;
>  	struct uffdio_register uffd_reg;
> @@ -502,7 +502,7 @@ void *uffd_poll_thread(void *arg)
>  			err("unexpected msg event %u\n", msg.event);
>  			break;
>  		case UFFD_EVENT_PAGEFAULT:
> -			uffd_handle_page_fault(&msg, stats);
> +			uffd_handle_page_fault(&msg, args);
>  			break;
>  		case UFFD_EVENT_FORK:
>  			close(uffd);
> diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h
> index 47565b2f2dee..f8d2ad178827 100644
> --- a/tools/testing/selftests/mm/uffd-common.h
> +++ b/tools/testing/selftests/mm/uffd-common.h
> @@ -70,7 +70,7 @@
>  						  -  1)))
> 
>  /* Userfaultfd test statistics */
> -struct uffd_stats {
> +struct uffd_args {
>  	int cpu;
>  	unsigned long missing_faults;
>  	unsigned long wp_faults;
> @@ -98,12 +98,12 @@ extern uffd_test_ops_t shmem_uffd_test_ops;
>  extern uffd_test_ops_t hugetlb_uffd_test_ops;
>  extern uffd_test_ops_t *uffd_test_ops;
> 
> -void uffd_stats_report(struct uffd_stats *stats, int n_cpus);
> +void uffd_stats_report(struct uffd_args *args, int n_cpus);
>  void uffd_test_ctx_init(uint64_t features);
>  void userfaultfd_open(uint64_t *features);
>  int uffd_read_msg(int ufd, struct uffd_msg *msg);
>  void wp_range(int ufd, __u64 start, __u64 len, bool wp);
> -void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_stats *stats);
> +void uffd_handle_page_fault(struct uffd_msg *msg, struct uffd_args *args);
>  int __copy_page(int ufd, unsigned long offset, bool retry);
>  int copy_page(int ufd, unsigned long offset);
>  void *uffd_poll_thread(void *arg);
> diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c
> index 54fc9b4ffa3c..ce7251ab93ef 100644
> --- a/tools/testing/selftests/mm/uffd-stress.c
> +++ b/tools/testing/selftests/mm/uffd-stress.c
> @@ -90,16 +90,15 @@ static void usage(void)
>  	exit(1);
>  }
> 
> -static void uffd_stats_reset(struct uffd_stats *uffd_stats,
> -			     unsigned long n_cpus)
> +static void uffd_stats_reset(struct uffd_args *args, unsigned long n_cpus)
>  {
>  	int i;
> 
>  	for (i = 0; i < n_cpus; i++) {
> -		uffd_stats[i].cpu = i;
> -		uffd_stats[i].missing_faults = 0;
> -		uffd_stats[i].wp_faults = 0;
> -		uffd_stats[i].minor_faults = 0;
> +		args[i].cpu = i;
> +		args[i].missing_faults = 0;
> +		args[i].wp_faults = 0;
> +		args[i].minor_faults = 0;
>  	}
>  }
> 
> @@ -163,7 +162,7 @@ pthread_mutex_t uffd_read_mutex = PTHREAD_MUTEX_INITIALIZER;
> 
>  static void *uffd_read_thread(void *arg)
>  {
> -	struct uffd_stats *stats = (struct uffd_stats *)arg;
> +	struct uffd_args *args = (struct uffd_args *)arg;
>  	struct uffd_msg msg;
> 
>  	pthread_mutex_unlock(&uffd_read_mutex);
> @@ -172,7 +171,7 @@ static void *uffd_read_thread(void *arg)
>  	for (;;) {
>  		if (uffd_read_msg(uffd, &msg))
>  			continue;
> -		uffd_handle_page_fault(&msg, stats);
> +		uffd_handle_page_fault(&msg, args);
>  	}
> 
>  	return NULL;
> @@ -210,7 +209,7 @@ static void *background_thread(void *arg)
>  	return NULL;
>  }
> 
> -static int stress(struct uffd_stats *uffd_stats)
> +static int stress(struct uffd_args *args)
>  {
>  	unsigned long cpu;
>  	pthread_t locking_threads[nr_cpus];
> @@ -225,12 +224,12 @@ static int stress(struct uffd_stats *uffd_stats)
>  		if (bounces & BOUNCE_POLL) {
>  			if (pthread_create(&uffd_threads[cpu], &attr,
>  					   uffd_poll_thread,
> -					   (void *)&uffd_stats[cpu]))
> +					   (void *)&args[cpu]))
>  				return 1;
>  		} else {
>  			if (pthread_create(&uffd_threads[cpu], &attr,
>  					   uffd_read_thread,
> -					   (void *)&uffd_stats[cpu]))
> +					   (void *)&args[cpu]))
>  				return 1;
>  			pthread_mutex_lock(&uffd_read_mutex);
>  		}
> @@ -264,7 +263,7 @@ static int stress(struct uffd_stats *uffd_stats)
>  			if (write(pipefd[cpu*2+1], &c, 1) != 1)
>  				err("pipefd write error");
>  			if (pthread_join(uffd_threads[cpu],
> -					 (void *)&uffd_stats[cpu]))
> +					 (void *)&args[cpu]))
>  				return 1;
>  		} else {
>  			if (pthread_cancel(uffd_threads[cpu]))
> @@ -493,7 +492,7 @@ static int userfaultfd_events_test(void)
>  	int err, features;
>  	pid_t pid;
>  	char c;
> -	struct uffd_stats stats = { 0 };
> +	struct uffd_args args = { 0 };
> 
>  	printf("testing events (fork, remap, remove): ");
>  	fflush(stdout);
> @@ -508,7 +507,7 @@ static int userfaultfd_events_test(void)
>  			  true, test_uffdio_wp, false))
>  		err("register failure");
> 
> -	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
> +	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args))
>  		err("uffd_poll_thread create");
> 
>  	pid = fork();
> @@ -526,9 +525,9 @@ static int userfaultfd_events_test(void)
>  	if (pthread_join(uffd_mon, NULL))
>  		return 1;
> 
> -	uffd_stats_report(&stats, 1);
> +	uffd_stats_report(&args, 1);
> 
> -	return stats.missing_faults != nr_pages;
> +	return args.missing_faults != nr_pages;
>  }
> 
>  static int userfaultfd_sig_test(void)
> @@ -538,7 +537,7 @@ static int userfaultfd_sig_test(void)
>  	int err, features;
>  	pid_t pid;
>  	char c;
> -	struct uffd_stats stats = { 0 };
> +	struct uffd_args args = { 0 };
> 
>  	printf("testing signal delivery: ");
>  	fflush(stdout);
> @@ -557,7 +556,7 @@ static int userfaultfd_sig_test(void)
> 
>  	uffd_test_ops->release_pages(area_dst);
> 
> -	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
> +	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args))
>  		err("uffd_poll_thread create");
> 
>  	pid = fork();
> @@ -606,7 +605,7 @@ static int userfaultfd_minor_test(void)
>  	unsigned long p;
>  	pthread_t uffd_mon;
>  	char c;
> -	struct uffd_stats stats = { 0 };
> +	struct uffd_args args = { 0 };
> 
>  	if (!test_uffdio_minor)
>  		return 0;
> @@ -629,7 +628,7 @@ static int userfaultfd_minor_test(void)
>  		       page_size);
>  	}
> 
> -	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &stats))
> +	if (pthread_create(&uffd_mon, &attr, uffd_poll_thread, &args))
>  		err("uffd_poll_thread create");
> 
>  	/*
> @@ -645,7 +644,7 @@ static int userfaultfd_minor_test(void)
>  	if (pthread_join(uffd_mon, NULL))
>  		return 1;
> 
> -	uffd_stats_report(&stats, 1);
> +	uffd_stats_report(&args, 1);
> 
>  	if (test_collapse) {
>  		printf("testing collapse of uffd memory into PMD-mapped THPs:");
> @@ -664,7 +663,7 @@ static int userfaultfd_minor_test(void)
>  		printf(" done.\n");
>  	}
> 
> -	return stats.missing_faults != 0 || stats.minor_faults != nr_pages;
> +	return args.missing_faults != 0 || args.minor_faults != nr_pages;
>  }
> 
>  static int pagemap_open(void)
> @@ -822,7 +821,7 @@ static int userfaultfd_stress(void)
>  {
>  	void *area;
>  	unsigned long nr;
> -	struct uffd_stats uffd_stats[nr_cpus];
> +	struct uffd_args args[nr_cpus];
>  	uint64_t mem_size = nr_pages * page_size;
> 
>  	uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED);
> @@ -894,10 +893,10 @@ static int userfaultfd_stress(void)
>  		 */
>  		uffd_test_ops->release_pages(area_dst);
> 
> -		uffd_stats_reset(uffd_stats, nr_cpus);
> +		uffd_stats_reset(args, nr_cpus);
> 
>  		/* bounce pass */
> -		if (stress(uffd_stats))
> +		if (stress(args))
>  			return 1;
> 
>  		/* Clear all the write protections if there is any */
> @@ -926,7 +925,7 @@ static int userfaultfd_stress(void)
> 
>  		swap(area_src_alias, area_dst_alias);
> 
> -		uffd_stats_report(uffd_stats, nr_cpus);
> +		uffd_stats_report(args, nr_cpus);
>  	}
> 
>  	if (test_type == TEST_ANON) {
> -- 
> 2.39.1
> 

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2023-04-20 10:55 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-12 16:38 [PATCH v2 00/31] selftests/mm: Split / Refactor userfault test Peter Xu
2023-04-12 16:38 ` [PATCH v2 01/31] Revert "userfaultfd: don't fail on unrecognized features" Peter Xu
2023-04-12 16:41 ` [PATCH v2 02/31] selftests/mm: Update .gitignore with two missing tests Peter Xu
2023-04-12 16:41 ` [PATCH v2 03/31] selftests/mm: Dump a summary in run_vmtests.sh Peter Xu
2023-04-12 16:41 ` [PATCH v2 04/31] selftests/mm: Merge util.h into vm_util.h Peter Xu
2023-04-12 16:42 ` [PATCH v2 05/31] selftests/mm: Use TEST_GEN_PROGS where proper Peter Xu
2023-04-15 15:44   ` Lorenzo Stoakes
2023-04-12 16:42 ` [PATCH v2 06/31] selftests/mm: Link vm_util.c always Peter Xu
2023-04-12 16:42 ` [PATCH v2 07/31] selftests/mm: Merge default_huge_page_size() into one Peter Xu
2023-04-12 16:42 ` [PATCH v2 08/31] selftests/mm: Use PM_* macros in vm_utils.h Peter Xu
2023-04-12 16:42 ` [PATCH v2 09/31] selftests/mm: Reuse pagemap_get_entry() in vm_util.h Peter Xu
2023-04-12 16:42 ` [PATCH v2 10/31] selftests/mm: Test UFFDIO_ZEROPAGE only when !hugetlb Peter Xu
2023-04-12 17:07   ` Axel Rasmussen
2023-04-12 16:42 ` [PATCH v2 11/31] selftests/mm: Drop test_uffdio_zeropage_eexist Peter Xu
2023-04-12 16:42 ` [PATCH v2 12/31] selftests/mm: Create uffd-common.[ch] Peter Xu
2023-04-12 17:59   ` Axel Rasmussen
2023-04-12 16:42 ` [PATCH v2 13/31] selftests/mm: Split uffd tests into uffd-stress and uffd-unit-tests Peter Xu
2023-04-12 18:03   ` Axel Rasmussen
2023-04-12 16:42 ` [PATCH v2 14/31] selftests/mm: uffd_[un]register() Peter Xu
2023-04-12 18:20   ` Axel Rasmussen
2023-04-12 19:33     ` Peter Xu
2023-04-12 16:42 ` [PATCH v2 15/31] selftests/mm: uffd_open_{dev|sys}() Peter Xu
2023-04-12 18:25   ` Axel Rasmussen
2023-04-12 16:42 ` [PATCH v2 16/31] selftests/mm: UFFDIO_API test Peter Xu
2023-04-12 19:47   ` Axel Rasmussen
2023-04-12 20:08     ` Peter Xu
2023-04-20 10:54   ` Mike Rapoport
2023-04-12 16:43 ` [PATCH v2 17/31] selftests/mm: Drop global mem_fd in uffd tests Peter Xu
2023-04-12 16:43 ` [PATCH v2 18/31] selftests/mm: Drop global hpage_size " Peter Xu
2023-04-12 16:43 ` [PATCH v2 19/31] selftests/mm: Rename uffd_stats to uffd_args Peter Xu
2023-04-20 10:55   ` Mike Rapoport [this message]
2023-04-12 16:43 ` [PATCH v2 20/31] selftests/mm: Let uffd_handle_page_fault() take wp parameter Peter Xu
2023-04-12 16:43 ` [PATCH v2 21/31] selftests/mm: Allow allocate_area() to fail properly Peter Xu
2023-04-12 16:43 ` [PATCH v2 22/31] selftests/mm: Add framework for uffd-unit-test Peter Xu
2023-04-12 16:43 ` [PATCH v2 23/31] selftests/mm: Move uffd pagemap test to unit test Peter Xu
2023-04-12 16:43 ` [PATCH v2 24/31] selftests/mm: Move uffd minor " Peter Xu
2023-04-12 16:44 ` [PATCH v2 25/31] selftests/mm: Move uffd sig/events tests into uffd unit tests Peter Xu
2023-04-12 16:44 ` [PATCH v2 26/31] selftests/mm: Move zeropage test " Peter Xu
2023-04-12 16:45 ` [PATCH v2 27/31] selftests/mm: Workaround no way to detect uffd-minor + wp Peter Xu
2023-04-12 16:45 ` [PATCH v2 28/31] selftests/mm: Allow uffd test to skip properly with no privilege Peter Xu
2023-04-12 16:45 ` [PATCH v2 29/31] selftests/mm: Drop sys/dev test in uffd-stress test Peter Xu
2023-04-12 16:45 ` [PATCH v2 30/31] selftests/mm: Add shmem-private test to uffd-stress Peter Xu
2023-04-12 16:45 ` [PATCH v2 31/31] selftests/mm: Add uffdio register ioctls test Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZEEaHbw200cpBc+7@linux.ibm.com \
    --to=rppt@linux.ibm.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lsoaresp@redhat.com \
    --cc=mike.kravetz@oracle.com \
    --cc=nadav.amit@gmail.com \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=rppt@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).