Re: [PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-10-12 Thread Simon Guo
On Fri, Oct 07, 2016 at 08:44:48AM +1100, Michael Ellerman wrote:
> wei.guo.si...@gmail.com writes:
> 
> > From: Anshuman Khandual 
> >
> > This patch adds ptrace interface test for EBB/PMU specific
> > registers. This also adds some generic ptrace interface
> > based helper functions to be used by other patches later
> > on in the series.
> 
> This is consistently failing for me on a P8 Tuleta (pvr 004b 0201):
> 
> # ./ptrace-ebb 
> test: ptrace_ebb_pmu
> tags: git_version:v4.8-rc5-176-g89cf1de0ae90
> EBBRR: 100059f8
> EBBHR: 100053cc; expected: 100053cc
> BESCR: 8001
> SIAR:  100012d0
> SDAR:  3fff7e4cc000
> SIER:  300; expected: 200
> MMCR2: 0; expected: 0
> MMCR0: 18080; expected: 18080
> failure: ptrace_ebb_pmu
> 
> cheers
Michael,

Yes.. SIER has different value in baremetal and virtual machine
due to different MSR[HV] value.  I will correct it. Originally I only
tested in virtual BE/LE machines.

Currently all tests cases (with fix) passed on one baremetal P8 machine 
with LE OS installed.  And I will try to find another baremetal with BE 
OS installed to test.

Thanks for indicating it.

BR,
Simon


Re: [PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-10-12 Thread Simon Guo
On Fri, Oct 07, 2016 at 08:44:48AM +1100, Michael Ellerman wrote:
> wei.guo.si...@gmail.com writes:
> 
> > From: Anshuman Khandual 
> >
> > This patch adds ptrace interface test for EBB/PMU specific
> > registers. This also adds some generic ptrace interface
> > based helper functions to be used by other patches later
> > on in the series.
> 
> This is consistently failing for me on a P8 Tuleta (pvr 004b 0201):
> 
> # ./ptrace-ebb 
> test: ptrace_ebb_pmu
> tags: git_version:v4.8-rc5-176-g89cf1de0ae90
> EBBRR: 100059f8
> EBBHR: 100053cc; expected: 100053cc
> BESCR: 8001
> SIAR:  100012d0
> SDAR:  3fff7e4cc000
> SIER:  300; expected: 200
> MMCR2: 0; expected: 0
> MMCR0: 18080; expected: 18080
> failure: ptrace_ebb_pmu
> 
> cheers
Michael,

Yes.. SIER has different value in baremetal and virtual machine
due to different MSR[HV] value.  I will correct it. Originally I only
tested in virtual BE/LE machines.

Currently all tests cases (with fix) passed on one baremetal P8 machine 
with LE OS installed.  And I will try to find another baremetal with BE 
OS installed to test.

Thanks for indicating it.

BR,
Simon


Re: [PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-10-06 Thread Michael Ellerman
wei.guo.si...@gmail.com writes:

> From: Anshuman Khandual 
>
> This patch adds ptrace interface test for EBB/PMU specific
> registers. This also adds some generic ptrace interface
> based helper functions to be used by other patches later
> on in the series.

This is consistently failing for me on a P8 Tuleta (pvr 004b 0201):

# ./ptrace-ebb 
test: ptrace_ebb_pmu
tags: git_version:v4.8-rc5-176-g89cf1de0ae90
EBBRR: 100059f8
EBBHR: 100053cc; expected: 100053cc
BESCR: 8001
SIAR:  100012d0
SDAR:  3fff7e4cc000
SIER:  300; expected: 200
MMCR2: 0; expected: 0
MMCR0: 18080; expected: 18080
failure: ptrace_ebb_pmu

cheers


Re: [PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-10-06 Thread Michael Ellerman
wei.guo.si...@gmail.com writes:

> From: Anshuman Khandual 
>
> This patch adds ptrace interface test for EBB/PMU specific
> registers. This also adds some generic ptrace interface
> based helper functions to be used by other patches later
> on in the series.

This is consistently failing for me on a P8 Tuleta (pvr 004b 0201):

# ./ptrace-ebb 
test: ptrace_ebb_pmu
tags: git_version:v4.8-rc5-176-g89cf1de0ae90
EBBRR: 100059f8
EBBHR: 100053cc; expected: 100053cc
BESCR: 8001
SIAR:  100012d0
SDAR:  3fff7e4cc000
SIER:  300; expected: 200
MMCR2: 0; expected: 0
MMCR0: 18080; expected: 18080
failure: ptrace_ebb_pmu

cheers


[PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-09-29 Thread wei . guo . simon
From: Anshuman Khandual 

This patch adds ptrace interface test for EBB/PMU specific
registers. This also adds some generic ptrace interface
based helper functions to be used by other patches later
on in the series.

Signed-off-by: Anshuman Khandual 
Signed-off-by: Simon Guo 
---
 tools/testing/selftests/powerpc/Makefile   |   3 +-
 tools/testing/selftests/powerpc/ptrace/Makefile|  11 +
 .../testing/selftests/powerpc/ptrace/ptrace-ebb.c  | 187 +
 .../testing/selftests/powerpc/ptrace/ptrace-ebb.h  |  99 +
 tools/testing/selftests/powerpc/ptrace/ptrace.h| 225 +
 5 files changed, 524 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/ptrace/Makefile
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-ebb.h
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace.h

diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
index b6eb817..2fe383c 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -25,7 +25,8 @@ SUB_DIRS = alignment  \
   syscalls \
   tm   \
   vphn \
-  math
+  math \
+  ptrace
 
 endif
 
diff --git a/tools/testing/selftests/powerpc/ptrace/Makefile 
b/tools/testing/selftests/powerpc/ptrace/Makefile
new file mode 100644
index 000..84c1c01
--- /dev/null
+++ b/tools/testing/selftests/powerpc/ptrace/Makefile
@@ -0,0 +1,11 @@
+TEST_PROGS := ptrace-ebb
+
+include ../../lib.mk
+
+all: $(TEST_PROGS)
+CFLAGS += -m64
+$(TEST_PROGS): ../harness.c ../utility/utils.c ptrace.h
+ptrace-ebb: ../pmu/event.c ../pmu/lib.c ../pmu/ebb/ebb_handler.S 
../pmu/ebb/busy_loop.S
+ptrace-ebb: CFLAGS += -I../pmu/ebb
+clean:
+   rm -f $(TEST_PROGS) *.o
diff --git a/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c 
b/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
new file mode 100644
index 000..1ec4a6b
--- /dev/null
+++ b/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
@@ -0,0 +1,187 @@
+/*
+ * Ptrace interface test for EBB
+ *
+ * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#include "ebb.h"
+#include "ptrace.h"
+#include "ptrace-ebb.h"
+
+/* Tracer and Tracee Shared Data */
+int shm_id;
+int *cptr, *pptr;
+
+void ebb(void)
+{
+   struct event event;
+
+   cptr = (int *)shmat(shm_id, NULL, 0);
+
+   event_init_named(, 0x1001e, "cycles");
+   event.attr.config |= (1ull << 63);
+   event.attr.exclusive = 1;
+   event.attr.pinned = 1;
+   event.attr.exclude_kernel = 1;
+   event.attr.exclude_hv = 1;
+   event.attr.exclude_idle = 1;
+
+   if (event_open()) {
+   perror("event_open() failed");
+   exit(1);
+   }
+
+   setup_ebb_handler(standard_ebb_callee);
+   mtspr(SPRN_BESCR, 0x8001ull);
+
+   /*
+* make sure BESCR has been set before continue
+*/
+   mb();
+
+   if (ebb_event_enable()) {
+   perror("ebb_event_handler() failed");
+   exit(1);
+   }
+
+   mtspr(SPRN_PMC1, pmc_sample_period(SAMPLE_PERIOD));
+   core_busy_loop();
+   cptr[0] = 1;
+   while (1)
+   asm volatile("" : : : "memory");
+
+   exit(0);
+}
+
+int validate_ebb(struct ebb_regs *regs)
+{
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   struct opd *opd = (struct opd *) ebb_handler;
+   #endif
+
+   printf("EBBRR: %lx\n", regs->ebbrr);
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   printf("EBBHR: %lx; expected: %lx\n",
+   regs->ebbhr, (unsigned long)opd->entry);
+   #else
+   printf("EBBHR: %lx; expected: %lx\n",
+   regs->ebbhr, (unsigned long)ebb_handler);
+   #endif
+   printf("BESCR: %lx\n", regs->bescr);
+
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   if (regs->ebbhr != opd->entry)
+   return TEST_FAIL;
+   #else
+   if (regs->ebbhr != (unsigned long) ebb_handler)
+   return TEST_FAIL;
+   #endif
+
+   return TEST_PASS;
+}
+
+int validate_pmu(struct pmu_regs *regs)
+{
+   printf("SIAR:  %lx\n", regs->siar);
+   printf("SDAR:  %lx\n", regs->sdar);
+   printf("SIER:  %lx; expected: %lx\n",
+   regs->sier, (unsigned long)SIER_EXP);
+   printf("MMCR2: %lx; expected: %lx\n",
+   regs->mmcr2, (unsigned long)MMCR2_EXP);
+   printf("MMCR0: %lx; 

[PATCH v15 03/15] selftests/powerpc: Add ptrace tests for EBB

2016-09-29 Thread wei . guo . simon
From: Anshuman Khandual 

This patch adds ptrace interface test for EBB/PMU specific
registers. This also adds some generic ptrace interface
based helper functions to be used by other patches later
on in the series.

Signed-off-by: Anshuman Khandual 
Signed-off-by: Simon Guo 
---
 tools/testing/selftests/powerpc/Makefile   |   3 +-
 tools/testing/selftests/powerpc/ptrace/Makefile|  11 +
 .../testing/selftests/powerpc/ptrace/ptrace-ebb.c  | 187 +
 .../testing/selftests/powerpc/ptrace/ptrace-ebb.h  |  99 +
 tools/testing/selftests/powerpc/ptrace/ptrace.h| 225 +
 5 files changed, 524 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/ptrace/Makefile
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-ebb.h
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace.h

diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
index b6eb817..2fe383c 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -25,7 +25,8 @@ SUB_DIRS = alignment  \
   syscalls \
   tm   \
   vphn \
-  math
+  math \
+  ptrace
 
 endif
 
diff --git a/tools/testing/selftests/powerpc/ptrace/Makefile 
b/tools/testing/selftests/powerpc/ptrace/Makefile
new file mode 100644
index 000..84c1c01
--- /dev/null
+++ b/tools/testing/selftests/powerpc/ptrace/Makefile
@@ -0,0 +1,11 @@
+TEST_PROGS := ptrace-ebb
+
+include ../../lib.mk
+
+all: $(TEST_PROGS)
+CFLAGS += -m64
+$(TEST_PROGS): ../harness.c ../utility/utils.c ptrace.h
+ptrace-ebb: ../pmu/event.c ../pmu/lib.c ../pmu/ebb/ebb_handler.S 
../pmu/ebb/busy_loop.S
+ptrace-ebb: CFLAGS += -I../pmu/ebb
+clean:
+   rm -f $(TEST_PROGS) *.o
diff --git a/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c 
b/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
new file mode 100644
index 000..1ec4a6b
--- /dev/null
+++ b/tools/testing/selftests/powerpc/ptrace/ptrace-ebb.c
@@ -0,0 +1,187 @@
+/*
+ * Ptrace interface test for EBB
+ *
+ * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#include "ebb.h"
+#include "ptrace.h"
+#include "ptrace-ebb.h"
+
+/* Tracer and Tracee Shared Data */
+int shm_id;
+int *cptr, *pptr;
+
+void ebb(void)
+{
+   struct event event;
+
+   cptr = (int *)shmat(shm_id, NULL, 0);
+
+   event_init_named(, 0x1001e, "cycles");
+   event.attr.config |= (1ull << 63);
+   event.attr.exclusive = 1;
+   event.attr.pinned = 1;
+   event.attr.exclude_kernel = 1;
+   event.attr.exclude_hv = 1;
+   event.attr.exclude_idle = 1;
+
+   if (event_open()) {
+   perror("event_open() failed");
+   exit(1);
+   }
+
+   setup_ebb_handler(standard_ebb_callee);
+   mtspr(SPRN_BESCR, 0x8001ull);
+
+   /*
+* make sure BESCR has been set before continue
+*/
+   mb();
+
+   if (ebb_event_enable()) {
+   perror("ebb_event_handler() failed");
+   exit(1);
+   }
+
+   mtspr(SPRN_PMC1, pmc_sample_period(SAMPLE_PERIOD));
+   core_busy_loop();
+   cptr[0] = 1;
+   while (1)
+   asm volatile("" : : : "memory");
+
+   exit(0);
+}
+
+int validate_ebb(struct ebb_regs *regs)
+{
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   struct opd *opd = (struct opd *) ebb_handler;
+   #endif
+
+   printf("EBBRR: %lx\n", regs->ebbrr);
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   printf("EBBHR: %lx; expected: %lx\n",
+   regs->ebbhr, (unsigned long)opd->entry);
+   #else
+   printf("EBBHR: %lx; expected: %lx\n",
+   regs->ebbhr, (unsigned long)ebb_handler);
+   #endif
+   printf("BESCR: %lx\n", regs->bescr);
+
+   #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+   if (regs->ebbhr != opd->entry)
+   return TEST_FAIL;
+   #else
+   if (regs->ebbhr != (unsigned long) ebb_handler)
+   return TEST_FAIL;
+   #endif
+
+   return TEST_PASS;
+}
+
+int validate_pmu(struct pmu_regs *regs)
+{
+   printf("SIAR:  %lx\n", regs->siar);
+   printf("SDAR:  %lx\n", regs->sdar);
+   printf("SIER:  %lx; expected: %lx\n",
+   regs->sier, (unsigned long)SIER_EXP);
+   printf("MMCR2: %lx; expected: %lx\n",
+   regs->mmcr2, (unsigned long)MMCR2_EXP);
+   printf("MMCR0: %lx; expected: %lx\n",
+   regs->mmcr0, (unsigned long)MMCR0_EXP);
+