Signed-off-by: Wink Saville <[EMAIL PROTECTED]>
---
  test/ace_test/Makefile   |   19 ++++
  test/ace_test/ace_test.c |  224 ++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 243 insertions(+), 0 deletions(-)
  create mode 100644 test/ace_test/Makefile
  create mode 100644 test/ace_test/ace_test.c

Index: linux-2.6/test/ace_test/Makefile
===================================================================
--- /dev/null
+++ linux-2.6/test/ace_test/Makefile
@@ -0,0 +1,19 @@
+CFLAGS=-m64 -O2 -Wall -g -DDEBUG=0
+INCLUDE= -I../../include
+
+.PHONY: all
+all: ace_test
+
+ace_test: ace_test.c ace.o
+       gcc ${CFLAGS} ${INCLUDE} ace_test.c ace.o -o ace_test -lpthread -lrt
+       objdump -d ace_test > ace_test.dis
+
+ace.o: ace.S
+       gcc ${CFLAGS} ${INCLUDE} -c ace.S -o ace.o
+
+ace.S: ../../arch/x86_64/kernel/ace.S
+       cp ../../arch/x86_64/kernel/ace.S .
+
+clean:
+       rm -f ace_test.o ace.S ace.o ace_test.dis ace_test
+
Index: linux-2.6/test/ace_test/ace_test.c
===================================================================
--- /dev/null
+++ linux-2.6/test/ace_test/ace_test.c
@@ -0,0 +1,234 @@
+/**
+ * @file:   ace_test.c
+ *
+ * Copyright (C) 2006, Saville Software, Inc.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <time.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include <linux/wait.h>
+
+#include <asm/ace.h>
+
+#ifndef DEBUG
+#define DEBUG 0
+#endif
+
+#define countof(x)     ((sizeof(x))/sizeof(x[0]))
+
+#if DEBUG
+       #define DPRINTF(fmt, args...) do { printf(fmt, ## args); } while (0)
+#else
+       #define DPRINTF(fmt, args...) do { } while (0)
+#endif
+
+uint64_t       start_time_us;
+uint64_t       end_time_us;
+
+uint64_t inline gtod_us(void)
+{
+       struct timeval tv;
+
+       gettimeofday(&tv, NULL);
+
+       return ((uint64_t)tv.tv_sec * 1000000) + (uint64_t)tv.tv_usec;
+}
+
+/**
+ * Test ace_atomic
+ */
+void test_ace_atomic(void)
+{
+       int     total = 0;
+       int     failed = 0;
+       int     i = 0;
+       int     result;
+
+       total += 1;
+       ace_inc(&i);
+       if (i != 1) {
+               printf("test_ace_atomic: ace_inc didn't work was %d expected 
1\n", i);
+               failed += 1;
+       }
+
+       total += 1;
+       ace_dec(&i);
+       if (i != 0) {
+               printf("test_ace_atomic: ace_dec didn't work was %d expected 
0\n", i);
+               failed += 1;
+       }
+
+       total += 1;
+       i = 10;
+       result = ace_dec_and_test(&i);
+       if (result || (i != 9)) {
+               printf("test_ace_atomic: ace_dec_and_test didn't work result 
was %s i was %d expected false and 9\n",
+                               result ? "true" : "false", i);
+               failed += 1;
+       }
+       total += 1;
+       i = 1;
+       result = ace_dec_and_test(&i);
+       if (!result || (i != 0)) {
+               printf("test_ace_atomic: ace_dec_and_test didn't work result 
was %s i was %d expected true and 0\n",
+                               result ? "true" : "false", i);
+               failed += 1;
+       }
+       total += 1;
+       i = 0;
+       result = ace_dec_and_test(&i);
+       if (result || (i != -1)) {
+               printf("test_ace_atomic: ace_dec_and_test didn't work result 
was %s i was %d expected false and -1\n",
+                               result ? "true" : "false", i);
+               failed += 1;
+       }
+
+       total += 1;
+       i = 0;
+       ace_cmpxchg(&i, 0, 1);
+       if (i != 1) {
+               printf("test_ace_atomic: ace_cmpxchg didn't work was %d 
expected 1\n", i);
+               failed += 1;
+       }
+
+       total += 1;
+       i = 8;
+       ace_cmpxchg(&i, 8, 1);
+       if (i != 1) {
+               printf("test_ace_atomic: ace_cmpxchg didn't work was %d 
expected 1\n", i);
+               failed += 1;
+       }
+
+       total += 1;
+       i = 3;
+       ace_cmpxchg(&i, 0, 2);
+       if (i != 3) {
+               printf("test_ace_atomic: ace_cmpxchg didn't work was %d 
expected 3\n", i);
+               failed += 1;
+       }
+
+       if (failed) {
+               printf("test_ace_atomic: failed %d tests of %d\n", failed, 
total);
+       } else {
+               printf("test_ace_atomic: PASSED %d tests\n", total);
+       }
+}
+
+void display_counters(uint64_t *initial, uint64_t *final)
+{
+       int i;
+
+       printf("%20s   %20s\n", "initial value", "final value");
+       for (i = 0; i < ACE_TEST_NUM_COUNTERS; i++) {
+               printf("%20ld %20ld\n", initial[i], final[i]);
+       }
+}
+
+int main(int argc, char *argv[])
+{
+       long int        loops;
+       long int        i;
+       int             fd = -1;
+       void            *pAceCode = NULL;
+       char            *file_name = "/dev/ace";
+       int             counter_index;
+       uint64_t        ace_counters_initial[ACE_TEST_NUM_COUNTERS];
+       uint64_t        ace_counters_final[ACE_TEST_NUM_COUNTERS];
+       int             quiet;
+
+       if (argc < 3) {
+               printf("Usage: ace_test loops counter_index [q]\n");
+               return 1;
+       }
+
+       if (sscanf(argv[1], "%li", &loops) != 1) {
+               printf("Usage: ace_test loops counter_index [q]\n");
+               return 1;
+       }
+
+       if (sscanf(argv[2], "%i", &counter_index) != 1) {
+               printf("Usage: ace_test loops counter_index [q]\n");
+               return 1;
+       }
+
+       if (argc == 4) {
+               quiet = argv[3][0] == 'q';
+       } else {
+               quiet = false;
+       }
+
+       fd = open(file_name, O_RDWR);
+       if (fd < 0) {
+               printf("Error opening %s err=%s\n", file_name, strerror(errno));
+               return 1;
+       }
+       pAceCode = (void *)ACE_CODE_ADDR;
+
+       if (mlockall(MCL_CURRENT) != 0)
+       {
+               perror("Couldn't lock memory");
+               return 1;
+       }
+
+       if (!quiet) {
+               test_ace_atomic();
+               printf("Running %ld loops...", loops);
+               fflush(stdout);
+       }
+       start_time_us = gtod_us();
+       ace_get_counters_snapshot(ace_counters_initial);
+       for (i = 0; i < loops; i++)
+       {
+               ace_inc_two_counters(0, counter_index);
+       }
+       ace_get_counters_snapshot(ace_counters_final);
+       end_time_us = gtod_us();
+       if (!quiet) {
+               printf(" done\n");
+       }
+
+       if (pAceCode != NULL) {
+               uint64_t        duration = end_time_us - start_time_us;
+               double          secs = (double)duration / 1000000.0;
+               uint64_t        expected_value = 0;
+
+               for (i = 1; i < ACE_TEST_NUM_COUNTERS; i++) {
+                       expected_value += ace_counters_final[i];
+               }
+
+               if (!quiet) {
+                       display_counters(ace_counters_initial, 
ace_counters_final);
+
+                       printf("      expected_value=%ld\n", expected_value);
+                       printf("               loops=%ld\n", loops);
+                       printf("       duration secs=%.2lf\n", secs);
+                       printf("        rate per sec=%.0lf\n", loops ? 
loops/secs : 0);
+                       printf("            secs per=%.9lf\n", loops ? 
secs/loops : 0.0);
+                       printf("              result=%s\n", expected_value == 
ace_counters_final[0] ? "success" : "failure");
+               } else {
+                       printf("%s\n", expected_value == ace_counters_final[0] 
? "success" : "failure");
+               }
+       }
+
+       if (fd >= 0)
+               close(fd);
+
+
+       return 0;
+}
+


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to