Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:29:54PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> >  
> > +static struct test *tests[] = {
> > +   generic_tests,
> > +   arch_tests,
> > +};
> > +
> >  static bool perf_test__matches(struct test *test, int curr, int argc, 
> > const char *argv[])
> >  {
> > int i;
> > @@ -237,7 +229,11 @@ static int run_test(struct test *test)
> > return err;
> >  }
> >  
> > -#define for_each_test(t)for (t = [0]; t->func; t++)
> > +static unsigned int ___j;  /* This is obviously not thread-safe */
> > +
> > +#define for_each_test(t)   \
> > +   for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> > +   for (t = [___j][0]; t->func; t++)
> >  
> 
> could you also split the change on adding support for arch_tests
> and another actually moving affected tests?

Sure that makes sense.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:28:14PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> >  };
> >  
> > +static struct test *tests[] = {
> > +   generic_tests,
> > +   arch_tests,
> > +};
> > +
> >  static bool perf_test__matches(struct test *test, int curr, int argc, 
> > const char *argv[])
> >  {
> > int i;
> > @@ -237,7 +229,11 @@ static int run_test(struct test *test)
> > return err;
> >  }
> >  
> > -#define for_each_test(t)for (t = [0]; t->func; t++)
> > +static unsigned int ___j;  /* This is obviously not thread-safe */
> > +
> > +#define for_each_test(t)   \
> > +   for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> > +   for (t = [___j][0]; t->func; t++)
> 
> why not have j on stack and pas it into for_each_test
> 
> for_each_test(j, t) 
> ...

Right, I made a conscious decision to not do that because I didn't
want the caller to have to care about providing an iterator variable.
It also makes the diff slightly bigger.

But I don't feel that strongly about it, so I'll make this change.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:23:53PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/tests/builtin-test.c 
> > b/tools/perf/tests/builtin-test.c
> > index 8cf0601d1662..a1b2265eaf55 100644
> > --- a/tools/perf/tests/builtin-test.c
> > +++ b/tools/perf/tests/builtin-test.c
> > @@ -14,10 +14,17 @@
> >  #include "parse-options.h"
> >  #include "symbol.h"
> >  
> > -static struct test {
> > -   const char *desc;
> > -   int (*func)(void);
> > -} tests[] = {
> > +#if defined(__x86_64__) || defined(__i386__)
> > +#include "arch-tests.h"
> > +#else
> > +static struct test arch_tests[] = {
> > +   {
> > +   .func = NULL,
> > +   },
> > +};
> > +#endif
> 
> this could be defined as __weak array so we dont need to have #if above

Yeah, good idea. I'll make that change.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:23:53PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/tests/builtin-test.c 
> > b/tools/perf/tests/builtin-test.c
> > index 8cf0601d1662..a1b2265eaf55 100644
> > --- a/tools/perf/tests/builtin-test.c
> > +++ b/tools/perf/tests/builtin-test.c
> > @@ -14,10 +14,17 @@
> >  #include "parse-options.h"
> >  #include "symbol.h"
> >  
> > -static struct test {
> > -   const char *desc;
> > -   int (*func)(void);
> > -} tests[] = {
> > +#if defined(__x86_64__) || defined(__i386__)
> > +#include "arch-tests.h"
> > +#else
> > +static struct test arch_tests[] = {
> > +   {
> > +   .func = NULL,
> > +   },
> > +};
> > +#endif
> 
> this could be defined as __weak array so we dont need to have #if above

Yeah, good idea. I'll make that change.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:29:54PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> >  
> > +static struct test *tests[] = {
> > +   generic_tests,
> > +   arch_tests,
> > +};
> > +
> >  static bool perf_test__matches(struct test *test, int curr, int argc, 
> > const char *argv[])
> >  {
> > int i;
> > @@ -237,7 +229,11 @@ static int run_test(struct test *test)
> > return err;
> >  }
> >  
> > -#define for_each_test(t)for (t = [0]; t->func; t++)
> > +static unsigned int ___j;  /* This is obviously not thread-safe */
> > +
> > +#define for_each_test(t)   \
> > +   for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> > +   for (t = [___j][0]; t->func; t++)
> >  
> 
> could you also split the change on adding support for arch_tests
> and another actually moving affected tests?

Sure that makes sense.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-12 Thread Matt Fleming
On Mon, 07 Sep, at 02:28:14PM, Jiri Olsa wrote:
> On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:
> 
> SNIP
> 
> >  };
> >  
> > +static struct test *tests[] = {
> > +   generic_tests,
> > +   arch_tests,
> > +};
> > +
> >  static bool perf_test__matches(struct test *test, int curr, int argc, 
> > const char *argv[])
> >  {
> > int i;
> > @@ -237,7 +229,11 @@ static int run_test(struct test *test)
> > return err;
> >  }
> >  
> > -#define for_each_test(t)for (t = [0]; t->func; t++)
> > +static unsigned int ___j;  /* This is obviously not thread-safe */
> > +
> > +#define for_each_test(t)   \
> > +   for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> > +   for (t = [___j][0]; t->func; t++)
> 
> why not have j on stack and pas it into for_each_test
> 
> for_each_test(j, t) 
> ...

Right, I made a conscious decision to not do that because I didn't
want the caller to have to care about providing an iterator variable.
It also makes the diff slightly bigger.

But I don't feel that strongly about it, so I'll make this change.

-- 
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

>  
> +static struct test *tests[] = {
> + generic_tests,
> + arch_tests,
> +};
> +
>  static bool perf_test__matches(struct test *test, int curr, int argc, const 
> char *argv[])
>  {
>   int i;
> @@ -237,7 +229,11 @@ static int run_test(struct test *test)
>   return err;
>  }
>  
> -#define for_each_test(t)  for (t = [0]; t->func; t++)
> +static unsigned int ___j;/* This is obviously not thread-safe */
> +
> +#define for_each_test(t) \
> + for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> + for (t = [___j][0]; t->func; t++)
>  

could you also split the change on adding support for arch_tests
and another actually moving affected tests?

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

>  };
>  
> +static struct test *tests[] = {
> + generic_tests,
> + arch_tests,
> +};
> +
>  static bool perf_test__matches(struct test *test, int curr, int argc, const 
> char *argv[])
>  {
>   int i;
> @@ -237,7 +229,11 @@ static int run_test(struct test *test)
>   return err;
>  }
>  
> -#define for_each_test(t)  for (t = [0]; t->func; t++)
> +static unsigned int ___j;/* This is obviously not thread-safe */
> +
> +#define for_each_test(t) \
> + for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> + for (t = [___j][0]; t->func; t++)

why not have j on stack and pas it into for_each_test

for_each_test(j, t) 
...

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 8cf0601d1662..a1b2265eaf55 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -14,10 +14,17 @@
>  #include "parse-options.h"
>  #include "symbol.h"
>  
> -static struct test {
> - const char *desc;
> - int (*func)(void);
> -} tests[] = {
> +#if defined(__x86_64__) || defined(__i386__)
> +#include "arch-tests.h"
> +#else
> +static struct test arch_tests[] = {
> + {
> + .func = NULL,
> + },
> +};
> +#endif

this could be defined as __weak array so we dont need to have #if above

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

>  
> +static struct test *tests[] = {
> + generic_tests,
> + arch_tests,
> +};
> +
>  static bool perf_test__matches(struct test *test, int curr, int argc, const 
> char *argv[])
>  {
>   int i;
> @@ -237,7 +229,11 @@ static int run_test(struct test *test)
>   return err;
>  }
>  
> -#define for_each_test(t)  for (t = [0]; t->func; t++)
> +static unsigned int ___j;/* This is obviously not thread-safe */
> +
> +#define for_each_test(t) \
> + for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> + for (t = [___j][0]; t->func; t++)
>  

could you also split the change on adding support for arch_tests
and another actually moving affected tests?

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 8cf0601d1662..a1b2265eaf55 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -14,10 +14,17 @@
>  #include "parse-options.h"
>  #include "symbol.h"
>  
> -static struct test {
> - const char *desc;
> - int (*func)(void);
> -} tests[] = {
> +#if defined(__x86_64__) || defined(__i386__)
> +#include "arch-tests.h"
> +#else
> +static struct test arch_tests[] = {
> + {
> + .func = NULL,
> + },
> +};
> +#endif

this could be defined as __weak array so we dont need to have #if above

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/3] perf tests: Add arch tests

2015-09-07 Thread Jiri Olsa
On Sat, Sep 05, 2015 at 08:02:21PM +0100, Matt Fleming wrote:

SNIP

>  };
>  
> +static struct test *tests[] = {
> + generic_tests,
> + arch_tests,
> +};
> +
>  static bool perf_test__matches(struct test *test, int curr, int argc, const 
> char *argv[])
>  {
>   int i;
> @@ -237,7 +229,11 @@ static int run_test(struct test *test)
>   return err;
>  }
>  
> -#define for_each_test(t)  for (t = [0]; t->func; t++)
> +static unsigned int ___j;/* This is obviously not thread-safe */
> +
> +#define for_each_test(t) \
> + for (___j = 0; ___j < ARRAY_SIZE(tests); ___j++)\
> + for (t = [___j][0]; t->func; t++)

why not have j on stack and pas it into for_each_test

for_each_test(j, t) 
...

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] perf tests: Add arch tests

2015-09-05 Thread Matt Fleming
From: Matt Fleming 

Tests that only make sense for some architectures currently live in
the same place as the generic tests. Move out the x86-specific tests
into tools/perf/arch/x86/tests and define an 'arch_tests' array, which
is the list of tests that only apply to the build architecture.

The main idea is to encourage developers to add arch tests to build
out perf's test coverage, without dumping everything in
tools/perf/tests.

We can also now begin to get rid of some of the #ifdef code that is
present in the generic perf tests.

Cc: Peter Zijlstra 
Cc: Jiri Olsa 
Cc: Arnaldo Carvalho de Melo 
Signed-off-by: Matt Fleming 
---
 tools/perf/arch/x86/Build|   2 +-
 tools/perf/arch/x86/include/arch-tests.h |  18 +++
 tools/perf/arch/x86/tests/Build  |   8 +-
 tools/perf/arch/x86/tests/arch-tests.c   |  24 
 tools/perf/arch/x86/tests/dwarf-unwind.c |   1 +
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 163 
 tools/perf/arch/x86/tests/rdpmc.c| 174 ++
 tools/perf/tests/Build   |   3 -
 tools/perf/tests/builtin-test.c  |  46 ---
 tools/perf/tests/dwarf-unwind.c  |   4 +
 tools/perf/tests/perf-time-to-tsc.c  | 162 
 tools/perf/tests/rdpmc.c | 177 ---
 tools/perf/tests/tests.h |   9 +-
 13 files changed, 418 insertions(+), 373 deletions(-)
 create mode 100644 tools/perf/arch/x86/include/arch-tests.h
 create mode 100644 tools/perf/arch/x86/tests/arch-tests.c
 create mode 100644 tools/perf/arch/x86/tests/perf-time-to-tsc.c
 create mode 100644 tools/perf/arch/x86/tests/rdpmc.c
 delete mode 100644 tools/perf/tests/perf-time-to-tsc.c
 delete mode 100644 tools/perf/tests/rdpmc.c

diff --git a/tools/perf/arch/x86/Build b/tools/perf/arch/x86/Build
index 41bf61da476a..db52fa22d3a1 100644
--- a/tools/perf/arch/x86/Build
+++ b/tools/perf/arch/x86/Build
@@ -1,2 +1,2 @@
 libperf-y += util/
-libperf-$(CONFIG_DWARF_UNWIND) += tests/
+libperf-y += tests/
diff --git a/tools/perf/arch/x86/include/arch-tests.h 
b/tools/perf/arch/x86/include/arch-tests.h
new file mode 100644
index ..9e505c5f6947
--- /dev/null
+++ b/tools/perf/arch/x86/include/arch-tests.h
@@ -0,0 +1,18 @@
+#ifndef ARCH_TESTS_H
+#define ARCH_TESTS_H
+
+/* Tests */
+int test__rdpmc(void);
+int test__perf_time_to_tsc(void);
+int test__intel_cqm_count_nmi_context(void);
+
+#ifdef HAVE_DWARF_UNWIND_SUPPORT
+struct thread;
+struct perf_sample;
+int test__arch_unwind_sample(struct perf_sample *sample,
+struct thread *thread);
+#endif
+
+extern struct test arch_tests[];
+
+#endif
diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Build
index b30eff9bcc83..1381525dae06 100644
--- a/tools/perf/arch/x86/tests/Build
+++ b/tools/perf/arch/x86/tests/Build
@@ -1,2 +1,6 @@
-libperf-y += regs_load.o
-libperf-y += dwarf-unwind.o
+libperf-$(CONFIG_DWARF_UNWIND) += regs_load.o
+libperf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
+
+libperf-y += arch-tests.o
+libperf-y += rdpmc.o
+libperf-y += perf-time-to-tsc.o
diff --git a/tools/perf/arch/x86/tests/arch-tests.c 
b/tools/perf/arch/x86/tests/arch-tests.c
new file mode 100644
index ..0004fe48dc7e
--- /dev/null
+++ b/tools/perf/arch/x86/tests/arch-tests.c
@@ -0,0 +1,24 @@
+#include 
+#include "tests/tests.h"
+#include "arch-tests.h"
+
+struct test arch_tests[] = {
+   {
+   .desc = "x86 rdpmc test",
+   .func = test__rdpmc,
+   },
+   {
+   .desc = "Test converting perf time to TSC",
+   .func = test__perf_time_to_tsc,
+   },
+#ifdef HAVE_DWARF_UNWIND_SUPPORT
+   {
+   .desc = "Test dwarf unwind",
+   .func = test__dwarf_unwind,
+   },
+#endif
+   {
+   .func = NULL,
+   },
+
+};
diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c 
b/tools/perf/arch/x86/tests/dwarf-unwind.c
index d8bbf7ad1681..7f209ce827bf 100644
--- a/tools/perf/arch/x86/tests/dwarf-unwind.c
+++ b/tools/perf/arch/x86/tests/dwarf-unwind.c
@@ -5,6 +5,7 @@
 #include "event.h"
 #include "debug.h"
 #include "tests/tests.h"
+#include "arch-tests.h"
 
 #define STACK_SIZE 8192
 
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
new file mode 100644
index ..5880768d1e5c
--- /dev/null
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -0,0 +1,163 @@
+#include 
+#include 
+#include 
+#include 
+
+#include "parse-events.h"
+#include "evlist.h"
+#include "evsel.h"
+#include "thread_map.h"
+#include "cpumap.h"
+#include "tsc.h"
+#include "tests/tests.h"
+#include "arch-tests.h"
+
+#define CHECK__(x) {   \
+   while ((x) < 0) {   \
+   pr_debug(#x " failed!\n");  \
+   goto out_err;   \
+   

[PATCH 2/3] perf tests: Add arch tests

2015-09-05 Thread Matt Fleming
From: Matt Fleming 

Tests that only make sense for some architectures currently live in
the same place as the generic tests. Move out the x86-specific tests
into tools/perf/arch/x86/tests and define an 'arch_tests' array, which
is the list of tests that only apply to the build architecture.

The main idea is to encourage developers to add arch tests to build
out perf's test coverage, without dumping everything in
tools/perf/tests.

We can also now begin to get rid of some of the #ifdef code that is
present in the generic perf tests.

Cc: Peter Zijlstra 
Cc: Jiri Olsa 
Cc: Arnaldo Carvalho de Melo 
Signed-off-by: Matt Fleming 
---
 tools/perf/arch/x86/Build|   2 +-
 tools/perf/arch/x86/include/arch-tests.h |  18 +++
 tools/perf/arch/x86/tests/Build  |   8 +-
 tools/perf/arch/x86/tests/arch-tests.c   |  24 
 tools/perf/arch/x86/tests/dwarf-unwind.c |   1 +
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 163 
 tools/perf/arch/x86/tests/rdpmc.c| 174 ++
 tools/perf/tests/Build   |   3 -
 tools/perf/tests/builtin-test.c  |  46 ---
 tools/perf/tests/dwarf-unwind.c  |   4 +
 tools/perf/tests/perf-time-to-tsc.c  | 162 
 tools/perf/tests/rdpmc.c | 177 ---
 tools/perf/tests/tests.h |   9 +-
 13 files changed, 418 insertions(+), 373 deletions(-)
 create mode 100644 tools/perf/arch/x86/include/arch-tests.h
 create mode 100644 tools/perf/arch/x86/tests/arch-tests.c
 create mode 100644 tools/perf/arch/x86/tests/perf-time-to-tsc.c
 create mode 100644 tools/perf/arch/x86/tests/rdpmc.c
 delete mode 100644 tools/perf/tests/perf-time-to-tsc.c
 delete mode 100644 tools/perf/tests/rdpmc.c

diff --git a/tools/perf/arch/x86/Build b/tools/perf/arch/x86/Build
index 41bf61da476a..db52fa22d3a1 100644
--- a/tools/perf/arch/x86/Build
+++ b/tools/perf/arch/x86/Build
@@ -1,2 +1,2 @@
 libperf-y += util/
-libperf-$(CONFIG_DWARF_UNWIND) += tests/
+libperf-y += tests/
diff --git a/tools/perf/arch/x86/include/arch-tests.h 
b/tools/perf/arch/x86/include/arch-tests.h
new file mode 100644
index ..9e505c5f6947
--- /dev/null
+++ b/tools/perf/arch/x86/include/arch-tests.h
@@ -0,0 +1,18 @@
+#ifndef ARCH_TESTS_H
+#define ARCH_TESTS_H
+
+/* Tests */
+int test__rdpmc(void);
+int test__perf_time_to_tsc(void);
+int test__intel_cqm_count_nmi_context(void);
+
+#ifdef HAVE_DWARF_UNWIND_SUPPORT
+struct thread;
+struct perf_sample;
+int test__arch_unwind_sample(struct perf_sample *sample,
+struct thread *thread);
+#endif
+
+extern struct test arch_tests[];
+
+#endif
diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Build
index b30eff9bcc83..1381525dae06 100644
--- a/tools/perf/arch/x86/tests/Build
+++ b/tools/perf/arch/x86/tests/Build
@@ -1,2 +1,6 @@
-libperf-y += regs_load.o
-libperf-y += dwarf-unwind.o
+libperf-$(CONFIG_DWARF_UNWIND) += regs_load.o
+libperf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
+
+libperf-y += arch-tests.o
+libperf-y += rdpmc.o
+libperf-y += perf-time-to-tsc.o
diff --git a/tools/perf/arch/x86/tests/arch-tests.c 
b/tools/perf/arch/x86/tests/arch-tests.c
new file mode 100644
index ..0004fe48dc7e
--- /dev/null
+++ b/tools/perf/arch/x86/tests/arch-tests.c
@@ -0,0 +1,24 @@
+#include 
+#include "tests/tests.h"
+#include "arch-tests.h"
+
+struct test arch_tests[] = {
+   {
+   .desc = "x86 rdpmc test",
+   .func = test__rdpmc,
+   },
+   {
+   .desc = "Test converting perf time to TSC",
+   .func = test__perf_time_to_tsc,
+   },
+#ifdef HAVE_DWARF_UNWIND_SUPPORT
+   {
+   .desc = "Test dwarf unwind",
+   .func = test__dwarf_unwind,
+   },
+#endif
+   {
+   .func = NULL,
+   },
+
+};
diff --git a/tools/perf/arch/x86/tests/dwarf-unwind.c 
b/tools/perf/arch/x86/tests/dwarf-unwind.c
index d8bbf7ad1681..7f209ce827bf 100644
--- a/tools/perf/arch/x86/tests/dwarf-unwind.c
+++ b/tools/perf/arch/x86/tests/dwarf-unwind.c
@@ -5,6 +5,7 @@
 #include "event.h"
 #include "debug.h"
 #include "tests/tests.h"
+#include "arch-tests.h"
 
 #define STACK_SIZE 8192
 
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
new file mode 100644
index ..5880768d1e5c
--- /dev/null
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -0,0 +1,163 @@
+#include 
+#include 
+#include 
+#include 
+
+#include "parse-events.h"
+#include "evlist.h"
+#include "evsel.h"
+#include "thread_map.h"
+#include "cpumap.h"
+#include "tsc.h"
+#include "tests/tests.h"
+#include "arch-tests.h"
+
+#define CHECK__(x) {   \
+   while ((x) < 0) {