From: "Aneesh Kumar K.V" <aneesh.kumar@linux•vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman•id.au>, linuxppc-dev@ozlabs•org
Cc: aneesh.kumar@in•ibm.com, Paul Mackerras <paulus@samba•org>
Subject: Re: [PATCH 2/2] selftests/powerpc: Test the THP bug we fixed in the previous commit
Date: Wed, 28 May 2014 14:57:23 +0530 [thread overview]
Message-ID: <8738fumex0.fsf@linux.vnet.ibm.com> (raw)
In-Reply-To: <1401265278-29307-2-git-send-email-mpe@ellerman.id.au>
Michael Ellerman <mpe@ellerman•id.au> writes:
> Signed-off-by: Michael Ellerman <mpe@ellerman•id.au>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux•vnet.ibm.com>
> ---
> tools/testing/selftests/powerpc/Makefile | 2 +-
> tools/testing/selftests/powerpc/mm/Makefile | 18 ++++++
> .../selftests/powerpc/mm/hugetlb_vs_thp_test.c | 72 ++++++++++++++++++++++
> 3 files changed, 91 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/powerpc/mm/Makefile
> create mode 100644 tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
>
> diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
> index 316194f..b3dbe9e 100644
> --- a/tools/testing/selftests/powerpc/Makefile
> +++ b/tools/testing/selftests/powerpc/Makefile
> @@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR
>
> export CC CFLAGS
>
> -TARGETS = pmu copyloops
> +TARGETS = pmu copyloops mm
>
> endif
>
> diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
> new file mode 100644
> index 0000000..357ccbd
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/mm/Makefile
> @@ -0,0 +1,18 @@
> +noarg:
> + $(MAKE) -C ../
> +
> +PROGS := hugetlb_vs_thp_test
> +
> +all: $(PROGS)
> +
> +$(PROGS): ../harness.c
> +
> +run_tests: all
> + @-for PROG in $(PROGS); do \
> + ./$$PROG; \
> + done;
> +
> +clean:
> + rm -f $(PROGS)
> +
> +.PHONY: all run_tests clean
> diff --git a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
> new file mode 100644
> index 0000000..3d8e5b0
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
> @@ -0,0 +1,72 @@
> +#include <stdio.h>
> +#include <sys/mman.h>
> +#include <unistd.h>
> +
> +#include "utils.h"
> +
> +/* This must match the huge page & THP size */
> +#define SIZE (16 * 1024 * 1024)
> +
> +static int test_body(void)
> +{
> + void *addr;
> + char *p;
> +
> + addr = (void *)0xa0000000;
> +
> + p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
> + MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> + if (p != MAP_FAILED) {
> + /*
> + * Typically the mmap will fail because no huge pages are
> + * allocated on the system. But if there are huge pages
> + * allocated the mmap will succeed. That's fine too, we just
> + * munmap here before continuing.
> + */
> + munmap(addr, SIZE);
> + }
> +
> + p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
> + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> + if (p == MAP_FAILED) {
> + printf("Mapping failed @ %p\n", addr);
> + perror("mmap");
> + return 1;
> + }
> +
> + /*
> + * Either a user or kernel access is sufficient to trigger the bug.
> + * A kernel access is easier to spot & debug, as it will trigger the
> + * softlockup or RCU stall detectors, and when the system is kicked
> + * into xmon we get a backtrace in the kernel.
> + *
> + * A good option is:
> + * getcwd(p, SIZE);
> + *
> + * For the purposes of this testcase it's preferable to spin in
> + * userspace, so the harness can kill us if we get stuck. That way we
> + * see a test failure rather than a dead system.
> + */
> + *p = 0xf;
> +
> + munmap(addr, SIZE);
> +
> + return 0;
> +}
> +
> +static int test_main(void)
> +{
> + int i;
> +
> + /* 10,000 because it's a "bunch", and completes reasonably quickly */
> + for (i = 0; i < 10000; i++)
> + if (test_body())
> + return 1;
> +
> + return 0;
> +}
> +
> +int main(void)
> +{
> + return test_harness(test_main, "hugetlb_vs_thp");
> +}
> --
> 1.9.1
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists•ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
next prev parent reply other threads:[~2014-05-28 9:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-28 8:21 [PATCH 1/2] powerpc/mm: Check paca psize is up to date for huge mappings Michael Ellerman
2014-05-28 8:21 ` [PATCH 2/2] selftests/powerpc: Test the THP bug we fixed in the previous commit Michael Ellerman
2014-05-28 9:27 ` Aneesh Kumar K.V [this message]
2014-05-28 9:27 ` [PATCH 1/2] powerpc/mm: Check paca psize is up to date for huge mappings Aneesh Kumar K.V
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=8738fumex0.fsf@linux.vnet.ibm.com \
--to=aneesh.kumar@linux$(echo .)vnet.ibm.com \
--cc=aneesh.kumar@in$(echo .)ibm.com \
--cc=linuxppc-dev@ozlabs$(echo .)org \
--cc=mpe@ellerman$(echo .)id.au \
--cc=paulus@samba$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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