* [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup
@ 2014-03-17 8:13 Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 2/3] performance_counters/performance_counter02.c: cleanup Xiaoguang Wang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Xiaoguang Wang @ 2014-03-17 8:13 UTC (permalink / raw)
To: ltp-list
Create ltp-perf_event_open.m4 to check perf_event_open syscall.
And according to perf_event_open()'s manpage, the official way of knowing
if perf_event_open() support is enabled is checking for the existence
of the file /proc/sys/kernel/perf_event_paranoid, so add this check.
According to this perf_event_open API description, rewrite this test
case to test hardware CPU events.
int perf_event_open(struct perf_event_attr *attr,
pid_t pid, int cpu, int group_fd,
unsigned long flags);
Some cleanup.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
configure.ac | 1 +
m4/ltp-perf_event_open.m4 | 38 +++++
.../performance_counters/performance_counter01.c | 184 +++++++++++++++------
3 files changed, 175 insertions(+), 48 deletions(-)
create mode 100644 m4/ltp-perf_event_open.m4
diff --git a/configure.ac b/configure.ac
index 0004a55..8941d5c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,5 +173,6 @@ LTP_CHECK_CLONE_SUPPORTS_7_ARGS
LTP_CHECK_MKDIRAT
LTP_CHECK_FCHOWNAT
LTP_CHECK_FALLOCATE
+LTP_CHECK_SYSCALL_PERF_EVENT_OPEN
AC_OUTPUT
diff --git a/m4/ltp-perf_event_open.m4 b/m4/ltp-perf_event_open.m4
new file mode 100644
index 0000000..6944870
--- /dev/null
+++ b/m4/ltp-perf_event_open.m4
@@ -0,0 +1,38 @@
+dnl
+dnl Copyright (c) Linux Test Project, 2014
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+dnl the GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+dnl
+
+dnl
+dnl LTP_CHECK_SYSCALL_PERF_EVENT_OPEN
+dnl ----------------------------
+dnl
+AC_DEFUN([LTP_CHECK_SYSCALL_PERF_EVENT_OPEN],[AC_LINK_IFELSE([AC_LANG_SOURCE([
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <linux/perf_event.h>
+int main(void) {
+ struct perf_event_attr pe;
+ syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
+ return 0;
+}])],[has_perf_event_open_syscall="yes"])
+if test "x$has_perf_event_open_syscall" = "xyes"; then
+ AC_DEFINE(HAVE_PERF_EVENT_OPEN_SYSCALL,1,[Define to 1 if you have the perf_event_open syscall support on your system])
+else
+ AC_DEFINE(HAVE_PERF_EVENT_OPEN_SYSCALL,0,[Define to 0 if you do not have the perf_event_open syscall support on your system])
+fi
+])
diff --git a/testcases/kernel/performance_counters/performance_counter01.c b/testcases/kernel/performance_counters/performance_counter01.c
index 6d7cbc9..4641701 100644
--- a/testcases/kernel/performance_counters/performance_counter01.c
+++ b/testcases/kernel/performance_counters/performance_counter01.c
@@ -22,13 +22,13 @@
* Very simple performance counter testcase.
* Picked up from: http://lkml.org/lkml/2008/12/5/17
*/
+
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <linux/unistd.h>
-
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
@@ -36,73 +36,161 @@
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
+#include "config.h"
+#if HAVE_PERF_EVENT_OPEN_SYSCALL
+#include <linux/perf_event.h>
+#endif
-/* Harness Specific Include Files. */
#include "test.h"
#include "usctest.h"
#include "linux_syscall_numbers.h"
-
-/* Extern Global Variables */
-extern int tst_count;
-extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */
-/* Global Variables */
-char *TCID = "performance_counter01"; /* test program identifier. */
-int TST_TOTAL = 1;
-
-enum hw_event_types {
- PERF_COUNT_CYCLES,
- PERF_COUNT_INSTRUCTIONS,
- PERF_COUNT_CACHE_REFERENCES,
- PERF_COUNT_CACHE_MISSES,
- PERF_COUNT_BRANCH_INSTRUCTIONS,
- PERF_COUNT_BRANCH_MISSES,
+#include "safe_macros.h"
+
+char *TCID = "performance_counter01";
+int TST_TOTAL = 6;
+
+#if HAVE_PERF_EVENT_OPEN_SYSCALL
+static void setup(void);
+static void cleanup(void);
+
+static struct test_case_t {
+ const char *name;
+ unsigned long long val;
+} hw_event_types[] = {
+ { "PERF_COUNT_HW_CPU_CYCLES", PERF_COUNT_HW_CPU_CYCLES },
+ { "PERF_COUNT_HW_INSTRUCTIONS", PERF_COUNT_HW_INSTRUCTIONS },
+ { "PERF_COUNT_HW_CACHE_REFERENCES", PERF_COUNT_HW_CACHE_REFERENCES },
+ { "PERF_COUNT_HW_CACHE_MISSES", PERF_COUNT_HW_CACHE_MISSES },
+ { "PERF_COUNT_HW_BRANCH_INSTRUCTIONS",
+ PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
+ { "PERF_COUNT_HW_BRANCH_MISSES", PERF_COUNT_HW_BRANCH_MISSES },
};
-void cleanup(void)
-{ /* Stub function. */
+static void verify(struct test_case_t *tc);
+static struct perf_event_attr pe;
+
+int main(int ac, char **av)
+{
+ int i, lc;
+ char *msg;
+
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (i = 0; i < TST_TOTAL; i++)
+ verify(&hw_event_types[i]);
+ }
+
+ cleanup();
+ tst_exit();
}
-int main(void)
+static void setup(void)
{
+ /*
+ * According to perf_event_open's manpage, the official way of
+ * knowing if perf_event_open() support is enabled is checking for
+ * the existence of the file /proc/sys/kernel/perf_event_paranoid.
+ */
+ if (access("/proc/sys/kernel/perf_event_paranoid", F_OK) == -1)
+ tst_brkm(TCONF, NULL, "Kernel doesn't have perf_event support");
+
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ TEST_PAUSE;
+
+ pe.type = PERF_TYPE_HARDWARE;
+ pe.size = sizeof(struct perf_event_attr);
+ pe.disabled = 1;
+ pe.exclude_kernel = 1;
+ pe.exclude_hv = 1;
+}
+
+
+static int perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
+ int cpu, int group_fd, unsigned long flags)
+{
+ int ret;
+
+ ret = ltp_syscall(__NR_perf_event_open, hw_event, pid, cpu,
+ group_fd, flags);
+ return ret;
+}
- unsigned long long count1, count2;
- int fd1, fd2, ret;
+/* do_work() is copied form performance_counter02.c */
+#define LOOPS 1000000000
- fd1 = ltp_syscall(__NR_perf_event_open,
- PERF_COUNT_INSTRUCTIONS, 0, 0, 0, -1);
- if (fd1 < 0) {
- tst_brkm(TBROK | TERRNO, cleanup,
- "Failed to create PERF_COUNT_INSTRUCTIONS fd");
+static void do_work(void)
+{
+ int i;
+
+ for (i = 0; i < LOOPS; ++i)
+ asm volatile ("" : : "g" (i));
+}
+
+static void verify(struct test_case_t *tc)
+{
+ unsigned long long count;
+ int fd, ret;
+
+ pe.config = tc->val;
+
+ TEST(perf_event_open(&pe, 0, -1, -1, 0));
+ if (TEST_RETURN == -1) {
+ tst_brkm(TFAIL | TTERRNO, cleanup,
+ "perf_event_open failed unexpectedly");
+ return;
}
- fd2 = ltp_syscall(__NR_perf_event_open,
- PERF_COUNT_CACHE_MISSES, 0, 0, 0, -1);
- if (fd2 < 0) {
- tst_brkm(TBROK | TERRNO, cleanup,
- "Failed to create PERF_COUNT_CACHE_MISSES fd");
+
+ fd = TEST_RETURN;
+
+ if (ioctl(fd, PERF_EVENT_IOC_RESET, 0) == -1) {
+ tst_brkm(TFAIL | TTERRNO, cleanup,
+ "ioctl set PERF_EVENT_IOC_RESET failed");
}
- do {
+ if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) == -1) {
+ tst_brkm(TFAIL | TTERRNO, cleanup,
+ "ioctl set PERF_EVENT_IOC_ENABLE failed");
+ }
- ret = read(fd1, &count1, sizeof(count1));
+ do_work();
- if (ret == sizeof(count1)) {
+ if (ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) == -1) {
+ tst_brkm(TFAIL | TTERRNO, cleanup,
+ "ioctl set PERF_EVENT_IOC_RESET failed");
+ }
- ret = read(fd2, &count2, sizeof(count2));
+ ret = read(fd, &count, sizeof(count));
+ if (ret == sizeof(count)) {
+ tst_resm(TINFO, "read event counter succeeded, "
+ "value: %llu", count);
+ tst_resm(TPASS, "test PERF_TYPE_HARDWARE: %s succeeded",
+ tc->name);
+ } else {
+ tst_resm(TFAIL | TERRNO, "read event counter failed");
+ }
- if (ret == sizeof(count2)) {
- tst_resm(TINFO,
- "counter1 value: %Ld instructions",
- count1);
- tst_resm(TINFO,
- "counter2 value: %Ld cachemisses",
- count2);
- sleep(1);
- }
+ SAFE_CLOSE(cleanup, fd);
- }
+}
- } while (ret == sizeof(unsigned long long));
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+}
- tst_exit();
+#else
+int main(void)
+{
+ tst_brkm(TCONF, NULL, "This system doesn't have "
+ "required perf_event_open syscall support");
}
+#endif
--
1.8.2.1
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 2/3] performance_counters/performance_counter02.c: cleanup
2014-03-17 8:13 [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup Xiaoguang Wang
@ 2014-03-17 8:13 ` Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 3/3] performance_counters: make performance_counters run default Xiaoguang Wang
2014-03-31 14:59 ` [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup chrubis
2 siblings, 0 replies; 7+ messages in thread
From: Xiaoguang Wang @ 2014-03-17 8:13 UTC (permalink / raw)
To: ltp-list
According to perf_event_open()'s manpage, the official way of knowing
if perf_event_open() support is enabled is checking for the existence
of the file /proc/sys/kernel/perf_event_paranoid, so add this check.
According to this perf_event_open API description, rewrite this test.
int perf_event_open(struct perf_event_attr *attr,
pid_t pid, int cpu, int group_fd,
unsigned long flags);
Some cleanup.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
.../performance_counters/performance_counter02.c | 247 ++++++++++++---------
1 file changed, 143 insertions(+), 104 deletions(-)
diff --git a/testcases/kernel/performance_counters/performance_counter02.c b/testcases/kernel/performance_counters/performance_counter02.c
index 5402b81..d31c28a 100644
--- a/testcases/kernel/performance_counters/performance_counter02.c
+++ b/testcases/kernel/performance_counters/performance_counter02.c
@@ -47,9 +47,9 @@ counter->prev_count in arch/powerpc/kernel/perf_counter.c, and I think
that means that enabling/disabling a group with a task clock counter
in it won't work correctly (I'll do a test program for that next).
-Usage is: ./performance_counter02 [-c num-hw-counters] [-v]
+Usage is: ./performance_counter02 [-C num-hw-counters] [-v]
-Use -c N if you have more than 8 hardware counters. The -v flag makes
+Use -C N if you have more than 8 hardware counters. The -v flag makes
it print out the values of each counter.
*/
@@ -65,69 +65,82 @@ it print out the values of each counter.
#include <sys/prctl.h>
#include <sys/types.h>
#include <linux/types.h>
+#if HAVE_PERF_EVENT_OPEN_SYSCALL
+#include <linux/perf_event.h>
+#endif
-/* Harness Specific Include Files. */
#include "test.h"
#include "usctest.h"
#include "linux_syscall_numbers.h"
-#define PR_TASK_PERF_COUNTERS_DISABLE 31
-#define PR_TASK_PERF_COUNTERS_ENABLE 32
+char *TCID = "performance_counter02";
+int TST_TOTAL = 1;
-/* Global Variables */
-char *TCID = "performance_counter02"; /* test program identifier. */
-int TST_TOTAL = 1; /* total number of tests in this file. */
+#if HAVE_PERF_EVENT_OPEN_SYSCALL
-typedef unsigned int u32;
-typedef unsigned long long u64;
-typedef long long s64;
+#define MAX_CTRS 50
+#define LOOPS 1000000000
+
+static void setup(void);
+static void verify(void);
+static void cleanup(void);
+static void help(void);
+
+static int nhw = 8;
+static int n;
+static int verbose;
+static char *nhw_str;
+static option_t options[] = {
+ {"C:", NULL, &nhw_str},
+ {"v", &verbose, NULL},
+ {NULL, NULL, NULL},
+};
-struct perf_counter_hw_event {
- s64 type;
- u64 irq_period;
- u32 record_type;
+static int tsk0;
+static int hwfd[MAX_CTRS], tskfd[MAX_CTRS];
- u32 disabled:1, /* off by default */
- nmi:1, /* NMI sampling */
- raw:1, /* raw event type */
- __reserved_1:29;
- u64 __reserved_2;
-};
+int main(int ac, char **av)
+{
+ int i, lc;
+ char *msg;
+
+ msg = parse_opts(ac, av, options, help);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ if (nhw_str) {
+ nhw = atoi(nhw_str);
+ if (nhw < 0 || nhw > MAX_CTRS - 4) {
+ tst_brkm(TCONF, NULL, "invalid number of "
+ "hw counters specified: %d", nhw);
+ }
+ }
-enum hw_event_types {
- PERF_COUNT_CYCLES = 0,
- PERF_COUNT_INSTRUCTIONS = 1,
- PERF_COUNT_CACHE_REFERENCES = 2,
- PERF_COUNT_CACHE_MISSES = 3,
- PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
- PERF_COUNT_BRANCH_MISSES = 5,
+ setup();
- /*
- * Special "software" counters provided by the kernel, even if
- * the hardware does not support performance counters. These
- * counters measure various physical and sw events of the
- * kernel (and allow the profiling of them as well):
- */
- PERF_COUNT_CPU_CLOCK = -1,
- PERF_COUNT_TASK_CLOCK = -2,
- /*
- * Future software events:
- */
- /* PERF_COUNT_PAGE_FAULTS = -3,
- PERF_COUNT_CONTEXT_SWITCHES = -4, */
-};
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ for (i = 0; i < TST_TOTAL; i++)
+ verify();
+ }
+
+ cleanup();
+ tst_exit();
+}
-int sys_perf_counter_open(struct perf_counter_hw_event *hw_event,
- pid_t pid, int cpu, int group_fd, unsigned long flags)
+static int perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
+ int cpu, int group_fd, unsigned long flags)
{
- return ltp_syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd,
- flags);
+ int ret;
+
+ ret = ltp_syscall(__NR_perf_event_open, hw_event, pid, cpu,
+ group_fd, flags);
+ return ret;
}
-#define MAX_CTRS 50
-#define LOOPS 1000000000
-void do_work(void)
+static void do_work(void)
{
int i;
@@ -135,81 +148,93 @@ void do_work(void)
asm volatile (""::"g" (i));
}
-void cleanup(void)
-{ /* Stub function. */
-}
-
-int main(int ac, char **av)
+static void setup(void)
{
- int tsk0;
- int hwfd[MAX_CTRS], tskfd[MAX_CTRS];
- struct perf_counter_hw_event tsk_event;
- struct perf_counter_hw_event hw_event;
- unsigned long long vt0, vt[MAX_CTRS], vh[MAX_CTRS], vtsum, vhsum;
- int i, n, nhw;
- int verbose = 0;
- double ratio;
+ int i;
+ static struct perf_event_attr tsk_event, hw_event;
- nhw = 8;
- while ((i = getopt(ac, av, "c:v")) != -1) {
- switch (i) {
- case 'c':
- n = atoi(optarg);
- break;
- case 'v':
- verbose = 1;
- break;
- case '?':
- fprintf(stderr, "Usage: %s [-c #hwctrs] [-v]\n", av[0]);
- exit(1);
- }
- }
+ /*
+ * According to perf_event_open's manpage, the official way of
+ * knowing if perf_event_open() support is enabled is checking for
+ * the existence of the file /proc/sys/kernel/perf_event_paranoid.
+ */
+ if (access("/proc/sys/kernel/perf_event_paranoid", F_OK) == -1)
+ tst_brkm(TCONF, NULL, "Kernel doesn't have perf_event support");
- if (nhw < 0 || nhw > MAX_CTRS - 4) {
- fprintf(stderr, "invalid number of hw counters specified: %d\n",
- nhw);
- exit(1);
- }
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ TEST_PAUSE;
n = nhw + 4;
- memset(&tsk_event, 0, sizeof(tsk_event));
- tsk_event.type = PERF_COUNT_TASK_CLOCK;
+ tsk_event.type = PERF_TYPE_SOFTWARE;
+ tsk_event.size = sizeof(struct perf_event_attr);
tsk_event.disabled = 1;
+ tsk_event.config = PERF_COUNT_SW_TASK_CLOCK;
- memset(&hw_event, 0, sizeof(hw_event));
+ hw_event.type = PERF_TYPE_HARDWARE;
+ hw_event.size = sizeof(struct perf_event_attr);
hw_event.disabled = 1;
- hw_event.type = PERF_COUNT_INSTRUCTIONS;
+ hw_event.config = PERF_COUNT_HW_INSTRUCTIONS;
- tsk0 = sys_perf_counter_open(&tsk_event, 0, -1, -1, 0);
+ tsk0 = perf_event_open(&tsk_event, 0, -1, -1, 0);
if (tsk0 == -1) {
- tst_brkm(TBROK | TERRNO, cleanup,
- "perf_counter_open failed (1)");
+ tst_brkm(TBROK | TERRNO, cleanup, "perf_event_open failed");
} else {
-
tsk_event.disabled = 0;
for (i = 0; i < n; ++i) {
- hwfd[i] = sys_perf_counter_open(&hw_event, 0, -1,
- -1, 0);
- tskfd[i] = sys_perf_counter_open(&tsk_event, 0, -1,
- hwfd[i], 0);
+ hwfd[i] = perf_event_open(&hw_event, 0, -1, -1, 0);
+ tskfd[i] = perf_event_open(&tsk_event, 0, -1,
+ hwfd[i], 0);
if (tskfd[i] == -1 || hwfd[i] == -1) {
tst_brkm(TBROK | TERRNO, cleanup,
- "perf_counter_open failed (2)");
+ "perf_event_open failed");
}
}
}
+}
+
+static void cleanup(void)
+{
+ int i;
+
+ TEST_CLEANUP;
+
+ for (i = 0; i < n; i++) {
+ if (hwfd[i] > 0 && close(hwfd[i]) == -1)
+ tst_resm(TWARN | TERRNO, "close(%d) failed", hwfd[i]);
+ if (tskfd[i] > 0 && close(tskfd[i]) == -1)
+ tst_resm(TWARN | TERRNO, "close(%d) failed", tskfd[i]);
+ }
+
+ if (tsk0 > 0 && close(tsk0) == -1)
+ tst_resm(TWARN | TERRNO, "close(%d) failed", tsk0);
+}
+
+static void verify(void)
+{
+ unsigned long long vt0, vt[MAX_CTRS], vh[MAX_CTRS];
+ unsigned long long vtsum = 0, vhsum = 0;
+ int i;
+ double ratio;
+
+ if (prctl(PR_TASK_PERF_EVENTS_ENABLE) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "prctl(PR_TASK_PERF_EVENTS_ENABLE) failed");
+ }
- prctl(PR_TASK_PERF_COUNTERS_ENABLE);
do_work();
- prctl(PR_TASK_PERF_COUNTERS_DISABLE);
+
+ if (prctl(PR_TASK_PERF_EVENTS_DISABLE) == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "prctl(PR_TASK_PERF_EVENTS_DISABLE) failed");
+ }
if (read(tsk0, &vt0, sizeof(vt0)) != sizeof(vt0)) {
tst_brkm(TBROK | TERRNO, cleanup,
"error reading task clock counter");
}
- vtsum = vhsum = 0;
for (i = 0; i < n; ++i) {
if (read(tskfd[i], &vt[i], sizeof(vt[i])) != sizeof(vt[i]) ||
read(hwfd[i], &vh[i], sizeof(vh[i])) != sizeof(vh[i])) {
@@ -220,23 +245,37 @@ int main(int ac, char **av)
vhsum += vh[i];
}
- tst_resm(TINFO, "overall task clock: %lld", vt0);
- tst_resm(TINFO, "hw sum: %lld, task clock sum: %lld", vhsum, vtsum);
- if (verbose) {
+ tst_resm(TINFO, "overall task clock: %llu", vt0);
+ tst_resm(TINFO, "hw sum: %llu, task clock sum: %llu", vhsum, vtsum);
+
+ if (verbose == 1) {
printf("hw counters:");
for (i = 0; i < n; ++i)
- printf(" %lld", vh[i]);
+ printf(" %llu", vh[i]);
printf("\ntask clock counters:");
for (i = 0; i < n; ++i)
- printf(" %lld", vt[i]);
+ printf(" %llu", vt[i]);
printf("\n");
}
+
ratio = (double)vtsum / vt0;
tst_resm(TINFO, "ratio: %.2f", ratio);
if (ratio > nhw + 0.0001) {
tst_resm(TFAIL, "test failed (ratio was greater than )");
} else {
- tst_resm(TINFO, "test passed");
+ tst_resm(TPASS, "test passed");
}
- tst_exit();
}
+
+static void help(void)
+{
+ printf("-C number of hardware counters\n");
+}
+#else
+
+int main(void)
+{
+ tst_brkm(TCONF, NULL, "This system doesn't have "
+ "required perf_event_open syscall support");
+}
+#endif
--
1.8.2.1
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 3/3] performance_counters: make performance_counters run default
2014-03-17 8:13 [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 2/3] performance_counters/performance_counter02.c: cleanup Xiaoguang Wang
@ 2014-03-17 8:13 ` Xiaoguang Wang
2014-03-31 15:08 ` chrubis
2014-03-31 14:59 ` [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup chrubis
2 siblings, 1 reply; 7+ messages in thread
From: Xiaoguang Wang @ 2014-03-17 8:13 UTC (permalink / raw)
To: ltp-list
Make performance_counter01 run default. This performance_counter01 case
is to use perf_event_open() to test hardware CPU events.
Do not let performance_counter02 run defalult. This test need to know
an upper bound on the number of hardware counters, which varies in
different platforms. So if knowing this value, user can execute:
./performance_counter02 -C (upper bound) to run this test.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
runtest/perfcounters | 3 +--
scenario_groups/default | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/runtest/perfcounters b/runtest/perfcounters
index 73cd1d2..65d18e1 100644
--- a/runtest/perfcounters
+++ b/runtest/perfcounters
@@ -1,5 +1,4 @@
# Test some Basic Performance Counters
performance_counter01 performance_counter01
-performance_counter02 performance_counter02
-
+#performance_counter02 performance_counter02
diff --git a/scenario_groups/default b/scenario_groups/default
index ff23c7c..ef597b5 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -26,3 +26,4 @@ commands
hyperthreading
kernel_misc
modules
+perfcounters
--
1.8.2.1
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup
2014-03-17 8:13 [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 2/3] performance_counters/performance_counter02.c: cleanup Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 3/3] performance_counters: make performance_counters run default Xiaoguang Wang
@ 2014-03-31 14:59 ` chrubis
2 siblings, 0 replies; 7+ messages in thread
From: chrubis @ 2014-03-31 14:59 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
> +#define _GNU_SOURCE
> +#include <unistd.h>
> +#include <sys/syscall.h>
> +#include <linux/perf_event.h>
> +int main(void) {
> + struct perf_event_attr pe;
> + syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
> + return 0;
> +}])],[has_perf_event_open_syscall="yes"])
> +if test "x$has_perf_event_open_syscall" = "xyes"; then
> + AC_DEFINE(HAVE_PERF_EVENT_OPEN_SYSCALL,1,[Define to 1 if you have the perf_event_open syscall support on your system])
> +else
> + AC_DEFINE(HAVE_PERF_EVENT_OPEN_SYSCALL,0,[Define to 0 if you do not have the perf_event_open syscall support on your system])
> +fi
> +])
This is wrong, we have linux_syscall_numbers.h in
testcases/kernel/include/ in order to make sure syscall numbers are
defined.
Looking at the code it should rather be check for
struct perf_event_attr in /usr/include/linux/perf_event.h, right?
> +static void do_work(void)
> +{
> + int i;
> +
> + for (i = 0; i < LOOPS; ++i)
> + asm volatile ("" : : "g" (i));
> +}
What is the exact purpose of the asm snippet here?
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 3/3] performance_counters: make performance_counters run default
2014-03-17 8:13 ` [LTP] [PATCH 3/3] performance_counters: make performance_counters run default Xiaoguang Wang
@ 2014-03-31 15:08 ` chrubis
[not found] ` <533A864A.4040109@cn.fujitsu.com>
0 siblings, 1 reply; 7+ messages in thread
From: chrubis @ 2014-03-31 15:08 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
> Make performance_counter01 run default. This performance_counter01 case
> is to use perf_event_open() to test hardware CPU events.
>
> Do not let performance_counter02 run defalult. This test need to know
> an upper bound on the number of hardware counters, which varies in
> different platforms. So if knowing this value, user can execute:
> ./performance_counter02 -C (upper bound) to run this test.
The test seems to default to 8. Can we just make it return TCONF if
there are less than 8 hw counters? Having tests that are not executed by
default is pointless.
Also what about moving these tests to syscalls? I see no reason not to.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 3/3] performance_counters: make performance_counters run default
[not found] ` <533A864A.4040109@cn.fujitsu.com>
@ 2014-04-01 11:58 ` chrubis
[not found] ` <5344EA26.8010209@cn.fujitsu.com>
0 siblings, 1 reply; 7+ messages in thread
From: chrubis @ 2014-04-01 11:58 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
> >> Make performance_counter01 run default. This performance_counter01 case
> >> is to use perf_event_open() to test hardware CPU events.
> >>
> >> Do not let performance_counter02 run defalult. This test need to know
> >> an upper bound on the number of hardware counters, which varies in
> >> different platforms. So if knowing this value, user can execute:
> >> ./performance_counter02 -C (upper bound) to run this test.
> > The test seems to default to 8. Can we just make it return TCONF if
> > there are less than 8 hw counters? Having tests that are not executed by
> > default is pointless.
> Here I actually do not know how to get the number of hardware counters.
> I had googled this issue, but do not find any method to get the number.
Hmm. I've looked at the interface and I wonder if we can do something as
setting on the exclusive bit and create HW perf counters untill the
perf_event_open() starts to fail, but that is just guess, the perf
interface looks quite complicated.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 3/3] performance_counters: make performance_counters run default
[not found] ` <5344EA26.8010209@cn.fujitsu.com>
@ 2014-04-09 17:04 ` chrubis
0 siblings, 0 replies; 7+ messages in thread
From: chrubis @ 2014-04-09 17:04 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
Hi!
> The Number Hardware Counters is 7, But according to above ./perf_event_open02 in RHEL7.0beta, the output is 5.
> Whether two slots in PMU has been used, or the output of papi_avail is not correct :-) .
I would guess that these are used by kernel or system for something else.
> I tried to figure out how papi_avail gets the number of hardware counters, It seems that it just predefines some const values for
> specific cpus, but I am not very sure, I do not have much time to read the papi_library source code.
>
> And I afraid that this library does not support enough kinds of cpus. I also met some compilation errors in Fedora19 about this library.
>
> So whether we can use the first method I mentioned. I think it is more reasonable, at least according to perf_even_open()'s manpage
> and the intent of perf_event_open02 case.
Your method is better, because the testcase only cares if perf events
are multiplexed or not which is implied by different time_enabled and
time_running fields.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-04-09 17:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-17 8:13 [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 2/3] performance_counters/performance_counter02.c: cleanup Xiaoguang Wang
2014-03-17 8:13 ` [LTP] [PATCH 3/3] performance_counters: make performance_counters run default Xiaoguang Wang
2014-03-31 15:08 ` chrubis
[not found] ` <533A864A.4040109@cn.fujitsu.com>
2014-04-01 11:58 ` chrubis
[not found] ` <5344EA26.8010209@cn.fujitsu.com>
2014-04-09 17:04 ` chrubis
2014-03-31 14:59 ` [LTP] [PATCH 1/3] performance_counters/performance_counter01.c: cleanup chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox