summaryrefslogtreecommitdiff
path: root/unittest/mysys
diff options
context:
space:
mode:
authorMarc Alff <marc.alff@sun.com>2009-11-24 16:36:31 -0700
committerMarc Alff <marc.alff@sun.com>2009-11-24 16:36:31 -0700
commite2a34cbf706926e10016079a094a2877eb2f4f18 (patch)
tree06a753b068f7fb21faaa840cf0808981acaaabb2 /unittest/mysys
parent23159440504311372b2c081c1b5f2cb2f7d98ef3 (diff)
downloadmariadb-git-e2a34cbf706926e10016079a094a2877eb2f4f18.tar.gz
WL#2373 Use cycle counter for timing
Diffstat (limited to 'unittest/mysys')
-rw-r--r--unittest/mysys/CMakeLists.txt35
-rw-r--r--unittest/mysys/Makefile.am5
-rw-r--r--unittest/mysys/my_rdtsc-t.c229
3 files changed, 266 insertions, 3 deletions
diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt
new file mode 100644
index 00000000000..a4c79afbf8b
--- /dev/null
+++ b/unittest/mysys/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright (C) 2007 MySQL AB, 2008-2009 Sun Microsystems, Inc
+#
+# 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; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
+ ${CMAKE_SOURCE_DIR}/sql
+ ${CMAKE_SOURCE_DIR}/regex
+ ${CMAKE_SOURCE_DIR}/extra/yassl/include
+ ${CMAKE_SOURCE_DIR}/unittest/mytap)
+ADD_EXECUTABLE(bitmap-t bitmap-t.c)
+TARGET_LINK_LIBRARIES(bitmap-t mytap mysys dbug strings)
+
+ADD_EXECUTABLE(base64-t base64-t.c)
+TARGET_LINK_LIBRARIES(base64-t mytap mysys dbug strings)
+
+ADD_EXECUTABLE(my_atomic-t my_atomic-t.c)
+TARGET_LINK_LIBRARIES(my_atomic-t mytap mysys dbug strings)
+
+ADD_EXECUTABLE(lf-t lf-t.c)
+TARGET_LINK_LIBRARIES(lf-t mytap mysys dbug strings)
+
+ADD_EXECUTABLE(my_rdtsc-t my_rdtsc-t.c)
+TARGET_LINK_LIBRARIES(my_rdtsc-t mytap mysys dbug strings)
+
diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am
index d83b2909048..25b30e331b0 100644
--- a/unittest/mysys/Makefile.am
+++ b/unittest/mysys/Makefile.am
@@ -23,7 +23,7 @@ LDADD = $(top_builddir)/unittest/mytap/libmytap.a \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/strings/libmystrings.a
-noinst_PROGRAMS = bitmap-t base64-t lf-t my_vsnprintf-t
+noinst_PROGRAMS = bitmap-t base64-t lf-t my_rdtsc-t my_vsnprintf-t
if NEED_THREAD
# my_atomic-t is used to check thread functions, so it is safe to
@@ -32,5 +32,4 @@ if NEED_THREAD
noinst_PROGRAMS += my_atomic-t
endif
-# Don't update the files from bitkeeper
-%::SCCS/s.%
+EXTRA_DIST = CMakeLists.txt
diff --git a/unittest/mysys/my_rdtsc-t.c b/unittest/mysys/my_rdtsc-t.c
new file mode 100644
index 00000000000..286ff29fbfc
--- /dev/null
+++ b/unittest/mysys/my_rdtsc-t.c
@@ -0,0 +1,229 @@
+/* Copyright (C) 2008-2009 Sun Microsystems, Inc
+
+ 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; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ rdtsc3 -- multi-platform timer code
+ pgulutzan@mysql.com, 2005-08-29
+ modified 2008-11-02
+
+ When you run rdtsc3, it will print the contents of
+ "my_timer_info". The display indicates
+ what timer routine is best for a given platform.
+
+ For example, this is the display on production.mysql.com,
+ a 2.8GHz Xeon with Linux 2.6.17, gcc 3.3.3:
+
+ cycles nanoseconds microseconds milliseconds ticks
+------------- ------------- ------------- ------------- -------------
+ 1 11 13 18 17
+ 2815019607 1000000000 1000000 1049 102
+ 1 1000 1 1 1
+ 88 4116 3888 4092 2044
+
+ The first line shows routines, e.g. 1 = MY_TIMER_ROUTINE_ASM_X86.
+ The second line shows frequencies, e.g. 2815019607 is nearly 2.8GHz.
+ The third line shows resolutions, e.g. 1000 = very poor resolution.
+ The fourth line shows overheads, e.g. ticks takes 2044 cycles.
+*/
+
+#include "my_global.h"
+#include "my_rdtsc.h"
+#include "tap.h"
+
+#define LOOP_COUNT 100
+
+MY_TIMER_INFO myt;
+
+void test_init()
+{
+ my_timer_init(&myt);
+
+ diag("----- Routine ---------------");
+ diag("myt.cycles.routine : %13llu", myt.cycles.routine);
+ diag("myt.nanoseconds.routine : %13llu", myt.nanoseconds.routine);
+ diag("myt.microseconds.routine : %13llu", myt.microseconds.routine);
+ diag("myt.milliseconds.routine : %13llu", myt.milliseconds.routine);
+ diag("myt.ticks.routine : %13llu", myt.ticks.routine);
+
+ diag("----- Frequency -------------");
+ diag("myt.cycles.frequency : %13llu", myt.cycles.frequency);
+ diag("myt.nanoseconds.frequency : %13llu", myt.nanoseconds.frequency);
+ diag("myt.microseconds.frequency : %13llu", myt.microseconds.frequency);
+ diag("myt.milliseconds.frequency : %13llu", myt.milliseconds.frequency);
+ diag("myt.ticks.frequency : %13llu", myt.ticks.frequency);
+
+ diag("----- Resolution ------------");
+ diag("myt.cycles.resolution : %13llu", myt.cycles.resolution);
+ diag("myt.nanoseconds.resolution : %13llu", myt.nanoseconds.resolution);
+ diag("myt.microseconds.resolution : %13llu", myt.microseconds.resolution);
+ diag("myt.milliseconds.resolution : %13llu", myt.milliseconds.resolution);
+ diag("myt.ticks.resolution : %13llu", myt.ticks.resolution);
+
+ diag("----- Overhead --------------");
+ diag("myt.cycles.overhead : %13llu", myt.cycles.overhead);
+ diag("myt.nanoseconds.overhead : %13llu", myt.nanoseconds.overhead);
+ diag("myt.microseconds.overhead : %13llu", myt.microseconds.overhead);
+ diag("myt.milliseconds.overhead : %13llu", myt.milliseconds.overhead);
+ diag("myt.ticks.overhead : %13llu", myt.ticks.overhead);
+
+ ok(1, "my_timer_init() did not crash");
+}
+
+void test_cycle()
+{
+ ulonglong t1= my_timer_cycles();
+ ulonglong t2;
+ int i;
+ int backward= 0;
+ int nonzero= 0;
+
+ for (i=0 ; i < LOOP_COUNT ; i++)
+ {
+ t2= my_timer_cycles();
+ if (t1 >= t2)
+ backward++;
+ if (t2 != 0)
+ nonzero++;
+ t1= t2;
+ }
+
+ /* Expect at most 1 backward, the cycle value can overflow */
+ ok((backward <= 1), "The cycle timer is strictly increasing");
+
+ if (myt.cycles.routine != 0)
+ ok((nonzero != 0), "The cycle timer is implemented");
+ else
+ ok((nonzero == 0), "The cycle timer is not implemented and returns 0");
+}
+
+void test_nanosecond()
+{
+ ulonglong t1= my_timer_nanoseconds();
+ ulonglong t2;
+ int i;
+ int backward= 0;
+ int nonzero= 0;
+
+ for (i=0 ; i < LOOP_COUNT ; i++)
+ {
+ t2= my_timer_nanoseconds();
+ if (t1 > t2)
+ backward++;
+ if (t2 != 0)
+ nonzero++;
+ t1= t2;
+ }
+
+ ok((backward == 0), "The nanosecond timer is increasing");
+
+ if (myt.nanoseconds.routine != 0)
+ ok((nonzero != 0), "The nanosecond timer is implemented");
+ else
+ ok((nonzero == 0), "The nanosecond timer is not implemented and returns 0");
+}
+
+void test_microsecond()
+{
+ ulonglong t1= my_timer_microseconds();
+ ulonglong t2;
+ int i;
+ int backward= 0;
+ int nonzero= 0;
+
+ for (i=0 ; i < LOOP_COUNT ; i++)
+ {
+ t2= my_timer_microseconds();
+ if (t1 > t2)
+ backward++;
+ if (t2 != 0)
+ nonzero++;
+ t1= t2;
+ }
+
+ ok((backward == 0), "The microsecond timer is increasing");
+
+ if (myt.microseconds.routine != 0)
+ ok((nonzero != 0), "The microsecond timer is implemented");
+ else
+ ok((nonzero == 0), "The microsecond timer is not implemented and returns 0");
+}
+
+void test_millisecond()
+{
+ ulonglong t1= my_timer_milliseconds();
+ ulonglong t2;
+ int i;
+ int backward= 0;
+ int nonzero= 0;
+
+ for (i=0 ; i < LOOP_COUNT ; i++)
+ {
+ t2= my_timer_milliseconds();
+ if (t1 > t2)
+ backward++;
+ if (t2 != 0)
+ nonzero++;
+ t1= t2;
+ }
+
+ ok((backward == 0), "The millisecond timer is increasing");
+
+ if (myt.milliseconds.routine != 0)
+ ok((nonzero != 0), "The millisecond timer is implemented");
+ else
+ ok((nonzero == 0), "The millisecond timer is not implemented and returns 0");
+}
+
+void test_tick()
+{
+ ulonglong t1= my_timer_ticks();
+ ulonglong t2;
+ int i;
+ int backward= 0;
+ int nonzero= 0;
+
+ for (i=0 ; i < LOOP_COUNT ; i++)
+ {
+ t2= my_timer_ticks();
+ if (t1 > t2)
+ backward++;
+ if (t2 != 0)
+ nonzero++;
+ t1= t2;
+ }
+
+ ok((backward == 0), "The tick timer is increasing");
+
+ if (myt.ticks.routine != 0)
+ ok((nonzero != 0), "The tick timer is implemented");
+ else
+ ok((nonzero == 0), "The tick timer is not implemented and returns 0");
+}
+
+int main(int argc __attribute__((unused)),
+ char ** argv __attribute__((unused)))
+{
+ plan(11);
+
+ test_init();
+ test_cycle();
+ test_nanosecond();
+ test_microsecond();
+ test_millisecond();
+ test_tick();
+
+ return 0;
+}
+