From: shane Date: Thu, 29 May 2008 20:22:37 +0000 (+0000) Subject: Consolidated inline assembly versions of "hwtime()" into hwtime.h. Provided MSVC... X-Git-Tag: version-3.6.10~999 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9bcbdad2983a5f20438deee53ed6a1c545495771;p=thirdparty%2Fsqlite.git Consolidated inline assembly versions of "hwtime()" into hwtime.h. Provided MSVC version. Modified code for consistent use of hwtime(). Changed implementation to use sqlite_uint64 and sqlite_int64 instead of unsigned long long int and long long int for MSVC compiler support. (CVS 5178) FossilOrigin-Name: 9883b406ce24eae93942ee5e6aab33fb6b05329f --- diff --git a/Makefile.in b/Makefile.in index 7a1aefa7cb..6b3aba7d07 100644 --- a/Makefile.in +++ b/Makefile.in @@ -194,6 +194,7 @@ SRC = \ $(TOP)/src/func.c \ $(TOP)/src/hash.c \ $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ $(TOP)/src/insert.c \ $(TOP)/src/journal.c \ $(TOP)/src/legacy.c \ @@ -362,6 +363,7 @@ HDR = \ $(TOP)/src/btree.h \ $(TOP)/src/btreeInt.h \ $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ $(TOP)/src/sqliteLimit.h \ $(TOP)/src/mutex.h \ opcodes.h \ diff --git a/main.mk b/main.mk index af000f67d6..28bc51f14c 100644 --- a/main.mk +++ b/main.mk @@ -101,6 +101,7 @@ SRC = \ $(TOP)/src/func.c \ $(TOP)/src/hash.c \ $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ $(TOP)/src/insert.c \ $(TOP)/src/journal.c \ $(TOP)/src/legacy.c \ @@ -250,6 +251,7 @@ HDR = \ $(TOP)/src/btree.h \ $(TOP)/src/btreeInt.h \ $(TOP)/src/hash.h \ + $(TOP)/src/hwtime.h \ keywordhash.h \ $(TOP)/src/mutex.h \ opcodes.h \ diff --git a/manifest b/manifest index 1a03951d1a..e4dd7ad24a 100644 --- a/manifest +++ b/manifest @@ -1,7 +1,7 @@ -C Fix\scosmetic\sissues\sspotted\swhile\sworking\son\sticket\s#3146\s(CVS\s5177) -D 2008-05-29T05:23:42 +C Consolidated\sinline\sassembly\sversions\sof\s"hwtime()"\sinto\shwtime.h.\s\sProvided\sMSVC\sversion.\s\sModified\scode\sfor\sconsistent\suse\sof\shwtime().\s\sChanged\simplementation\sto\suse\ssqlite_uint64\sand\ssqlite_int64\sinstead\sof\sunsigned\slong\slong\sint\sand\slong\slong\sint\sfor\sMSVC\scompiler\ssupport.\s(CVS\s5178) +D 2008-05-29T20:22:37 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 -F Makefile.in 62b2a40ff5944dd33c9c3184b21f720ea8e48a44 +F Makefile.in ce92ea8dc7adfb743757794f51c10d1b0d9c55e4 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F README b974cdc3f9f12b87e851b04e75996d720ebf81ac F VERSION 0993b4f2f08c496fab78af42928b6dc745f8a2e1 @@ -76,7 +76,7 @@ F ext/rtree/rtree_util.tcl ee0a0311eb12175319d78bfb37302320496cee6e F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210 -F main.mk 0fdc9417630e829cae994efee59038810f091e33 +F main.mk 254bdf904af5869178e6b333be5729bf24ff3f77 F mkdll.sh 712e74f3efe08a6ba12b2945d018a29a89d7fe3b F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb @@ -109,6 +109,7 @@ F src/fault.c 1f6177188edb00641673e462f3fab8cba9f7422b F src/func.c 77a910a1ca7613d291fd0b5cba3be14c02f0dce0 F src/hash.c fd8cb06fb54c2fe7d48c9195792059a2e5be8b70 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 +F src/hwtime.h 10fae2093aefa2b00be13bcac40c06e90924bc83 F src/insert.c e3277f313352ac27282b5be39972fda4f315d0c6 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c 8f5a2b25d9673b4004287cf2bf51dbf7d0738406 @@ -128,9 +129,9 @@ F src/mutex_unix.c 466d20378a0645fea64c3f2e2669c33b7802df56 F src/mutex_w32.c 133698096a2c4e81cd11ea6f4de7891c66f7b9f7 F src/os.c 541ea39fbacc18483b3aa96cd0242bad2dd0f049 F src/os.h 6e7e5d4efdc907b7a1a8cddb0cf984af01843fad -F src/os_common.h 9da7339466404707af49943fe4c47e608034761b +F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c 1578149e21c4eac42c7f230a6f40500846f8e781 -F src/os_unix.c 06dceb3230249d6e7c6a1d8d602fa6a93f4085b9 +F src/os_unix.c a6b02934fdd4682db47c006cb03baac8694d8b77 F src/os_win.c 812f9ba8cd90c8aa54914a56897fb534494576d8 F src/pager.c d0a77feeaeecaaaec9342a3bb3865ed9a490897a F src/pager.h 1ccde54041195311c2b09b6936404d2192db44da @@ -167,7 +168,7 @@ F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071 F src/test_onefile.c fd994d397b0e9cad103b1a6e1f76c61a90a38752 -F src/test_osinst.c c684ee6d480f30e36cb564dcbc94f5f8467468a8 +F src/test_osinst.c acf306ba86a2963ba69dd87907fae447478a28f1 F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a F src/test_server.c 7e579eb9bf6fbe9cc45e84e4c74d3d06d049a825 F src/test_tclvar.c e99b975614735553fa1c43503d85b0dd988c0e77 @@ -178,8 +179,8 @@ F src/update.c 2d7143b9014e955509cc4f323f9a9584fb898f34 F src/utf.c 8c94fa10efc78c2568d08d436acc59df4df7191b F src/util.c 43277088f8fea4109a640aa46731b8752c3fb4a7 F src/vacuum.c a5c289e561ed72283e97d2485491986bc7d684eb -F src/vdbe.c efe92d0925bc0a6f76c5bbfaf4cfee1665ae8799 -F src/vdbe.h f4bb70962d9c13e0f65b215c90e8acea1ae6e8ee +F src/vdbe.c 37d3237ad5b84c4d4d3a33a49350c2594cac65c3 +F src/vdbe.h 1e3722d471739c2b213c6283b60373290e52f7ea F src/vdbeInt.h ede1a31cfa74d4718f41da491bd1d2b3abc137fc F src/vdbeapi.c 22b01ed175e4d4c613ee82cabc7a44a275641206 F src/vdbeaux.c 7823f1db7f47cf70d86d1901e2030309e1cbfd02 @@ -575,8 +576,8 @@ F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8 F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf F tool/mkkeywordhash.c ef93810fc41fb3d3dbacf9a33a29be88ea99ffa9 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x -F tool/mksqlite3c.tcl da45d6d596f536d361e428874e7071710803de1e -F tool/mksqlite3internalh.tcl 47737a925fb02fce43e2c0a14b3cc17574a4d44a +F tool/mksqlite3c.tcl 927b9d6ccd05690f75eb67bce7cca9a90b65ceeb +F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87 F tool/omittest.tcl 7d1fdf469e2f4d175f70c36e469db64a1626fabb F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816 @@ -586,11 +587,11 @@ F tool/soak1.tcl 85a4a7826c77351bfe1c005ae3cff2ef59123557 F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/spaceanal.tcl b87db46ae29e3116411b1686e136b9b994d7de39 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 -F tool/speedtest16.c 6f5bc019dcf8b6537f379bbac0408a9e1a86f0b6 +F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff -F tool/speedtest8.c e74126bc12178fa29904f711bb100212a5448041 -F tool/speedtest8inst1.c 025879132979a5fdec11218472cba6cf8f6ec854 -P ad6a782e7c408f6c3ebff5f2715c629b75c8002d -R 486eefc4a3f966d0ff0a629a9a11c14c -U drh -Z 38197e0cbfc994144353080aecc69a7d +F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 +F tool/speedtest8inst1.c c65494ca99d1e09c246dfe37a7ca7a354af9990f +P 5f6eab65dba421a736659a6673a51a0e487d68ac +R 458af2184cd56db6e376c81a0c3c302b +U shane +Z a36aff0535891ea4228fb00ae4809b6b diff --git a/manifest.uuid b/manifest.uuid index 7915436e10..9e55a9a5d5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5f6eab65dba421a736659a6673a51a0e487d68ac \ No newline at end of file +9883b406ce24eae93942ee5e6aab33fb6b05329f \ No newline at end of file diff --git a/src/hwtime.h b/src/hwtime.h new file mode 100644 index 0000000000..ba34d385c8 --- /dev/null +++ b/src/hwtime.h @@ -0,0 +1,65 @@ +/* +** 2008 May 27 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +****************************************************************************** +** +** This file contains inline asm code for retrieving "high-performance" +** counters for x86 class CPUs. +** +** $Id: hwtime.h,v 1.1 2008/05/29 20:22:37 shane Exp $ +*/ +#ifndef _HWTIME_H_ +#define _HWTIME_H_ + +/* +** The following routine only works on pentium-class (or newer) processors. +** It uses the RDTSC opcode to read the cycle count value out of the +** processor and returns that value. This can be used for high-res +** profiling. +*/ +#if (defined(__GNUC__) || defined(_MSC_VER)) && \ + (defined(i386) || defined(__i386__) || defined(_M_IX86)) + + #if defined(__GNUC__) + + __inline__ sqlite_uint64 sqlite3Hwtime(void){ + unsigned int lo, hi; + /* We cannot use "=A", since this would use %rax on x86_64 */ + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); + return (sqlite_uint64)hi << 32 | lo; + } + + #elif defined(_MSC_VER) + + __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){ + __asm { + rdtsc + ret ; return value at EDX:EAX + } + } + + #endif + +#else + + #error Need implementation of sqlite3Hwtime() for your platform. + + /* + ** To compile without implementing sqlite3Hwtime() for your platform, + ** you can remove the above #error and use the following + ** stub function. You will lose timing support for many + ** of the debugging and testing utilities, but it should at + ** least compile and run. + */ + sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); } + +#endif + +#endif /* !defined(_HWTIME_H_) */ diff --git a/src/os_common.h b/src/os_common.h index c52c2d8290..5fab7a4642 100644 --- a/src/os_common.h +++ b/src/os_common.h @@ -17,8 +17,10 @@ ** This file should be #included by the os_*.c files only. It is not a ** general purpose header file. ** -** $Id: os_common.h,v 1.36 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: os_common.h,v 1.37 2008/05/29 20:22:37 shane Exp $ */ +#ifndef _OS_COMMON_H_ +#define _OS_COMMON_H_ /* ** At least two bugs have slipped in because we changed the MEMORY_DEBUG @@ -64,22 +66,22 @@ int sqlite3OSTrace = 0; ** on i486 hardware. */ #ifdef SQLITE_PERFORMANCE_TRACE -__inline__ unsigned long long int hwtime(void){ - unsigned long long int x; - __asm__("rdtsc\n\t" - "mov %%edx, %%ecx\n\t" - :"=A" (x)); - return x; -} -static unsigned long long int g_start; -static unsigned int elapse; -#define TIMER_START g_start=hwtime() -#define TIMER_END elapse=hwtime()-g_start -#define TIMER_ELAPSED elapse + +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. +*/ +#include "hwtime.h" + +static sqlite_uint64 g_start; +static sqlite_uint64 g_elapsed; +#define TIMER_START g_start=sqlite3Hwtime() +#define TIMER_END g_elapsed=sqlite3Hwtime()-g_start +#define TIMER_ELAPSED g_elapsed #else #define TIMER_START #define TIMER_END -#define TIMER_ELAPSED 0 +#define TIMER_ELAPSED ((sqlite_uint64)0) #endif /* @@ -131,3 +133,5 @@ int sqlite3_open_file_count = 0; #else #define OpenCounter(X) #endif + +#endif /* !defined(_OS_COMMON_H_) */ diff --git a/src/os_unix.c b/src/os_unix.c index 2f99db4609..45b08d6c63 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -12,7 +12,7 @@ ** ** This file contains code that is specific to Unix systems. ** -** $Id: os_unix.c,v 1.182 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: os_unix.c,v 1.183 2008/05/29 20:22:37 shane Exp $ */ #include "sqliteInt.h" #if OS_UNIX /* This file is used on unix only */ @@ -805,7 +805,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){ got = read(id->h, pBuf, cnt); #endif TIMER_END; - OSTRACE5("READ %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED); + OSTRACE5("READ %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED); return got; } @@ -853,7 +853,7 @@ static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){ got = write(id->h, pBuf, cnt); #endif TIMER_END; - OSTRACE5("WRITE %-3d %5d %7lld %d\n", id->h, got, offset, TIMER_ELAPSED); + OSTRACE5("WRITE %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED); return got; } diff --git a/src/test_osinst.c b/src/test_osinst.c index 35c26b8b85..5966d05581 100644 --- a/src/test_osinst.c +++ b/src/test_osinst.c @@ -14,7 +14,7 @@ ** adds instrumentation to all vfs and file methods. C and Tcl interfaces ** are provided to control the instrumentation. ** -** $Id: test_osinst.c,v 1.11 2008/05/16 04:51:55 danielk1977 Exp $ +** $Id: test_osinst.c,v 1.12 2008/05/29 20:22:37 shane Exp $ */ /* @@ -53,8 +53,8 @@ ** ** * The name of the invoked method - i.e. "xRead". ** -** * The time consumed by the method call as measured by hwtime() (an -** integer value) +** * The time consumed by the method call as measured by +** sqlite3Hwtime() (an integer value) ** ** * A string value with a different meaning for different calls. ** For file methods, the name of the file being operated on. For @@ -82,7 +82,7 @@ ** * The name of the method call - i.e. "xWrite", ** * The total number of calls to the method (an integer). ** * The aggregate time consumed by all calls to the method as -** measured by hwtime() (an integer). +** measured by sqlite3Hwtime() (an integer). */ #include "sqlite3.h" @@ -222,30 +222,19 @@ static sqlite3_io_methods inst_io_methods = { instDeviceCharacteristics /* xDeviceCharacteristics */ }; -/* -** The following routine only works on pentium-class processors. -** It uses the RDTSC opcode to read the cycle count value out of the -** processor and returns that value. This can be used for high-res -** profiling. +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. */ -#if defined(i386) || defined(__i386__) || defined(_M_IX86) -__inline__ unsigned long long int osinst_hwtime(void){ - unsigned int lo, hi; - /* We cannot use "=A", since this would use %rax on x86_64 */ - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - return (unsigned long long int)hi << 32 | lo; -} -#else - static unsigned long long int osinst_hwtime(void){ return 0; } -#endif +#include "hwtime.h" #define OS_TIME_IO(eEvent, A, B, Call) { \ inst_file *p = (inst_file *)pFile; \ InstVfs *pInstVfs = p->pInstVfs; \ int rc; \ - sqlite3_int64 t = osinst_hwtime(); \ + sqlite_uint64 t = sqlite3Hwtime(); \ rc = Call; \ - t = osinst_hwtime() - t; \ + t = sqlite3Hwtime() - t; \ pInstVfs->aTime[eEvent] += t; \ pInstVfs->aCount[eEvent] += 1; \ if( pInstVfs->xCall ){ \ @@ -259,9 +248,9 @@ __inline__ unsigned long long int osinst_hwtime(void){ #define OS_TIME_VFS(eEvent, Z, flags, A, B, Call) { \ InstVfs *pInstVfs = (InstVfs *)pVfs; \ int rc; \ - sqlite3_int64 t = osinst_hwtime(); \ + sqlite_uint64 t = sqlite3Hwtime(); \ rc = Call; \ - t = osinst_hwtime() - t; \ + t = sqlite3Hwtime() - t; \ pInstVfs->aTime[eEvent] += t; \ pInstVfs->aCount[eEvent] += 1; \ if( pInstVfs->xCall ){ \ diff --git a/src/vdbe.c b/src/vdbe.c index 1b65a6f9d1..941d6a9e23 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.743 2008/05/29 05:23:42 drh Exp $ +** $Id: vdbe.c,v 1.744 2008/05/29 20:22:37 shane Exp $ */ #include "sqliteInt.h" #include @@ -465,18 +465,13 @@ static void registerTrace(FILE *out, int iReg, Mem *p){ #ifdef VDBE_PROFILE -/* -** The following routine only works on pentium-class processors. -** It uses the RDTSC opcode to read the cycle count value out of the -** processor and returns that value. This can be used for high-res -** profiling. -*/ -__inline__ unsigned long long int hwtime(void){ - unsigned int lo, hi; - /* We cannot use "=A", since this would use %rax on x86_64 */ - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - return (unsigned long long int)hi << 32 | lo; -} + +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. +*/ +#include "hwtime.h" + #endif /* @@ -536,7 +531,7 @@ int sqlite3VdbeExec( Mem *pOut; /* Output operand */ u8 opProperty; #ifdef VDBE_PROFILE - unsigned long long start; /* CPU clock count at start of opcode */ + u64 start; /* CPU clock count at start of opcode */ int origPc; /* Program counter at start of opcode */ #endif #ifndef SQLITE_OMIT_PROGRESS_CALLBACK @@ -580,7 +575,7 @@ int sqlite3VdbeExec( if( db->mallocFailed ) goto no_mem; #ifdef VDBE_PROFILE origPc = pc; - start = hwtime(); + start = sqlite3Hwtime(); #endif pOp = &p->aOp[pc]; @@ -4876,11 +4871,11 @@ default: { /* This is really OP_Noop and OP_Explain */ #ifdef VDBE_PROFILE { - long long elapse = hwtime() - start; - pOp->cycles += elapse; + u64 elapsed = sqlite3Hwtime() - start; + pOp->cycles += elapsed; pOp->cnt++; #if 0 - fprintf(stdout, "%10lld ", elapse); + fprintf(stdout, "%10llu ", elapsed); sqlite3VdbePrintOp(stdout, origPc, &p->aOp[origPc]); #endif } diff --git a/src/vdbe.h b/src/vdbe.h index eb7dfd01bb..9a1e4a2de9 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -15,7 +15,7 @@ ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** -** $Id: vdbe.h,v 1.131 2008/05/01 17:03:49 drh Exp $ +** $Id: vdbe.h,v 1.132 2008/05/29 20:22:37 shane Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ @@ -63,11 +63,11 @@ struct VdbeOp { KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ } p4; #ifdef SQLITE_DEBUG - char *zComment; /* Comment to improve readability */ + char *zComment; /* Comment to improve readability */ #endif #ifdef VDBE_PROFILE - int cnt; /* Number of times this instruction was executed */ - long long cycles; /* Total time spend executing this instruction */ + int cnt; /* Number of times this instruction was executed */ + u64 cycles; /* Total time spent executing this instruction */ #endif }; typedef struct VdbeOp VdbeOp; diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl index fd0ea4a414..04c17e66f6 100644 --- a/tool/mksqlite3c.tcl +++ b/tool/mksqlite3c.tcl @@ -92,6 +92,7 @@ foreach hdr { fts3_hash.h fts3_tokenizer.h hash.h + hwtime.h keywordhash.h mutex.h opcodes.h @@ -146,7 +147,7 @@ proc copy_file {filename} { if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { if {[info exists available_hdr($hdr)]} { if {$available_hdr($hdr)} { - if {$hdr!="os_common.h"} { + if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { set available_hdr($hdr) 0 } section_comment "Include $hdr in the middle of $tail" @@ -229,7 +230,7 @@ foreach file { bitvec.c pager.c - btmutex.c + btmutex.c btree.c vdbefifo.c diff --git a/tool/mksqlite3internalh.tcl b/tool/mksqlite3internalh.tcl index cacd7cbe18..f02a62df73 100644 --- a/tool/mksqlite3internalh.tcl +++ b/tool/mksqlite3internalh.tcl @@ -56,6 +56,7 @@ foreach hdr { btree.h btreeInt.h hash.h + hwtime.h keywordhash.h opcodes.h os_common.h diff --git a/tool/speedtest16.c b/tool/speedtest16.c index f5190fa511..e81f1a6dba 100644 --- a/tool/speedtest16.c +++ b/tool/speedtest16.c @@ -15,7 +15,7 @@ ** Then link against this program. But to do optimize this program ** because that defeats the hi-res timer. ** -** gcc speedtest16.c sqlite3.o -ldl +** gcc speedtest16.c sqlite3.o -ldl -I../src ** ** Then run this program with a single argument which is the name of ** a file containing SQL script that you want to test: @@ -29,19 +29,11 @@ #include #include "sqlite3.h" - -/* -** The following routine only works on pentium-class processors. -** It uses the RDTSC opcode to read the cycle count value out of the -** processor and returns that value. This can be used for high-res -** profiling. +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. */ -__inline__ unsigned long long int hwtime(void){ - unsigned int lo, hi; - /* We cannot use "=A", since this would use %rax on x86_64 */ - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - return (unsigned long long int)hi << 32 | lo; -} +#include "hwtime.h" /* ** Convert a zero-terminated ASCII string into a zero-terminated @@ -64,9 +56,9 @@ static void *asciiToUtf16le(const char *z){ /* ** Timers */ -static unsigned long long int prepTime = 0; -static unsigned long long int runTime = 0; -static unsigned long long int finalizeTime = 0; +static sqlite_uint64 prepTime = 0; +static sqlite_uint64 runTime = 0; +static sqlite_uint64 finalizeTime = 0; /* ** Prepare and run a single statement of SQL. @@ -75,28 +67,28 @@ static void prepareAndRun(sqlite3 *db, const char *zSql){ void *utf16; sqlite3_stmt *pStmt; const void *stmtTail; - unsigned long long int iStart, iElapse; + sqlite_uint64 iStart, iElapse; int rc; printf("****************************************************************\n"); printf("SQL statement: [%s]\n", zSql); utf16 = asciiToUtf16le(zSql); - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_prepare16_v2(db, utf16, -1, &pStmt, &stmtTail); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; prepTime += iElapse; printf("sqlite3_prepare16_v2() returns %d in %llu cycles\n", rc, iElapse); if( rc==SQLITE_OK ){ int nRow = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; runTime += iElapse; printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", rc, nRow, iElapse); - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_finalize(pStmt); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; finalizeTime += iElapse; printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); } @@ -111,8 +103,8 @@ int main(int argc, char **argv){ char *zSql; int i, j; FILE *in; - unsigned long long int iStart, iElapse; - unsigned long long int iSetup = 0; + sqlite_uint64 iStart, iElapse; + sqlite_uint64 iSetup = 0; int nStmt = 0; int nByte = 0; @@ -133,9 +125,9 @@ int main(int argc, char **argv){ printf("SQLite version: %d\n", sqlite3_libversion_number()); unlink(argv[1]); utf16 = asciiToUtf16le(argv[1]); - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_open16(utf16, &db); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; iSetup = iElapse; printf("sqlite3_open16() returns %d in %llu cycles\n", rc, iElapse); free(utf16); @@ -159,9 +151,9 @@ int main(int argc, char **argv){ } } } - iStart = hwtime(); + iStart = sqlite3Hwtime(); sqlite3_close(db); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; iSetup += iElapse; printf("sqlite3_close() returns in %llu cycles\n", iElapse); printf("\n"); diff --git a/tool/speedtest8.c b/tool/speedtest8.c index 0ee2fa2ff5..5972947f57 100644 --- a/tool/speedtest8.c +++ b/tool/speedtest8.c @@ -14,7 +14,7 @@ ** Then link against this program. But to do optimize this program ** because that defeats the hi-res timer. ** -** gcc speedtest8.c sqlite3.o -ldl +** gcc speedtest8.c sqlite3.o -ldl -I../src ** ** Then run this program with a single argument which is the name of ** a file containing SQL script that you want to test: @@ -25,32 +25,30 @@ #include #include #include +#include + +#if defined(_MSC_VER) +#include +#else #include #include -#include #include +#endif #include "sqlite3.h" -/* -** The following routine only works on pentium-class processors. -** It uses the RDTSC opcode to read the cycle count value out of the -** processor and returns that value. This can be used for high-res -** profiling. +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. */ -__inline__ unsigned long long int hwtime(void){ - unsigned int lo, hi; - /* We cannot use "=A", since this would use %rax on x86_64 */ - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - return (unsigned long long int)hi << 32 | lo; -} +#include "hwtime.h" /* ** Timers */ -static unsigned long long int prepTime = 0; -static unsigned long long int runTime = 0; -static unsigned long long int finalizeTime = 0; +static sqlite_uint64 prepTime = 0; +static sqlite_uint64 runTime = 0; +static sqlite_uint64 finalizeTime = 0; /* ** Prepare and run a single statement of SQL. @@ -58,33 +56,33 @@ static unsigned long long int finalizeTime = 0; static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){ sqlite3_stmt *pStmt; const char *stmtTail; - unsigned long long int iStart, iElapse; + sqlite_uint64 iStart, iElapse; int rc; if (!bQuiet){ printf("***************************************************************\n"); } if (!bQuiet) printf("SQL statement: [%s]\n", zSql); - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; prepTime += iElapse; if (!bQuiet){ printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse); } if( rc==SQLITE_OK ){ int nRow = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; runTime += iElapse; if (!bQuiet){ printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", rc, nRow, iElapse); } - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_finalize(pStmt); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; finalizeTime += iElapse; if (!bQuiet){ printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); @@ -182,14 +180,16 @@ int main(int argc, char **argv){ char *zSql; int i, j; FILE *in; - unsigned long long int iStart, iElapse; - unsigned long long int iSetup = 0; + sqlite_uint64 iStart, iElapse; + sqlite_uint64 iSetup = 0; int nStmt = 0; int nByte = 0; const char *zArgv0 = argv[0]; int bQuiet = 0; +#if !defined(_MSC_VER) struct tms tmsStart, tmsEnd; clock_t clkStart, clkEnd; +#endif #ifdef HAVE_OSINST extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *); @@ -223,6 +223,18 @@ int main(int argc, char **argv){ ** equates to "Normal". */ if( argc>4 && (strcmp(argv[1], "-priority")==0) ){ +#if defined(_MSC_VER) + int new_priority = atoi(argv[2]); + if(!SetPriorityClass(GetCurrentProcess(), + (new_priority<=-5) ? HIGH_PRIORITY_CLASS : + (new_priority<=0) ? ABOVE_NORMAL_PRIORITY_CLASS : + (new_priority==0) ? NORMAL_PRIORITY_CLASS : + (new_priority<5) ? BELOW_NORMAL_PRIORITY_CLASS : + IDLE_PRIORITY_CLASS)){ + printf ("error setting priority\n"); + exit(2); + } +#else struct sched_param myParam; sched_getparam(0, &myParam); printf ("Current process priority is %d.\n", (int)myParam.sched_priority); @@ -232,6 +244,7 @@ int main(int argc, char **argv){ printf ("error setting priority\n"); exit(2); } +#endif argv += 2; argc -= 2; continue; @@ -271,10 +284,12 @@ int main(int argc, char **argv){ printf("SQLite version: %d\n", sqlite3_libversion_number()); unlink(argv[1]); +#if !defined(_MSC_VER) clkStart = times(&tmsStart); - iStart = hwtime(); +#endif + iStart = sqlite3Hwtime(); rc = sqlite3_open(argv[1], &db); - iElapse = hwtime() - iStart; + iElapse = sqlite3Hwtime() - iStart; iSetup = iElapse; if (!bQuiet) printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse); for(i=j=0; j #include "sqlite3.h" -/* -** The following routine only works on pentium-class processors. -** It uses the RDTSC opcode to read the cycle count value out of the -** processor and returns that value. This can be used for high-res -** profiling. -*/ -__inline__ sqlite3_uint64 hwtime(void){ - unsigned int lo, hi; - /* We cannot use "=A", since this would use %rax on x86_64 */ - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - return (sqlite3_uint64)hi << 32 | lo; -} +/* +** hwtime.h contains inline assembler code for implementing +** high-performance timing routines. +*/ +#include "hwtime.h" /* ** Send a message to the log file. @@ -136,24 +129,25 @@ static sqlite3_io_methods inst_io_methods = { }; #define OS_TIME_IO(MESSAGE, A, B, CALL) \ - int rc; sqlite3_uint64 t1, t2; \ + int rc; \ + sqlite_uint64 t1, t2; \ inst_file *p = (inst_file*)pFile; \ - t1 = hwtime(); \ + t1 = sqlite3Hwtime(); \ rc = CALL; \ - t2 = hwtime(); \ + t2 = sqlite3Hwtime(); \ logMessage(MESSAGE, A, B, t2-t1); \ - instTime += hwtime() - t2; \ + instTime += sqlite3Hwtime() - t2; \ return rc; #define OS_TIME_VFS(MESSAGE, A, B, CALL) \ int rc; \ - sqlite3_uint64 t1, t2; \ + sqlite_uint64 t1, t2; \ sqlite3_vfs *pRealVfs = (sqlite3_vfs*)pVfs->pAppData; \ - t1 = hwtime(); \ + t1 = sqlite3Hwtime(); \ rc = CALL; \ - t2 = hwtime(); \ + t2 = sqlite3Hwtime(); \ logMessage(MESSAGE, A, B, t2-t1); \ - instTime += hwtime() - t2; \ + instTime += sqlite3Hwtime() - t2; \ return rc; @@ -437,32 +431,32 @@ static void setupInstrumentedVfs(void){ static void prepareAndRun(sqlite3 *db, const char *zSql){ sqlite3_stmt *pStmt; const char *stmtTail; - sqlite3_uint64 iStart, iElapse; + sqlite_uint64 iStart, iElapse; int rc; printf("****************************************************************\n"); printf("SQL statement: [%s]\n", zSql); instTime = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail); - iElapse = hwtime(); + iElapse = sqlite3Hwtime(); iElapse -= iStart + instTime; prepTime += iElapse; printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse); if( rc==SQLITE_OK ){ int nRow = 0; instTime = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } - iElapse = hwtime(); + iElapse = sqlite3Hwtime(); iElapse -= iStart + instTime; runTime += iElapse; printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", rc, nRow, iElapse); instTime = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_finalize(pStmt); - iElapse = hwtime(); + iElapse = sqlite3Hwtime(); iElapse -= iStart + instTime; finalizeTime += iElapse; printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); @@ -476,8 +470,8 @@ int main(int argc, char **argv){ char *zSql; int i, j; FILE *in; - sqlite3_uint64 iStart, iElapse; - sqlite3_uint64 iSetup = 0; + sqlite_uint64 iStart, iElapse; + sqlite_uint64 iSetup = 0; int nStmt = 0; int nByte = 0; @@ -499,9 +493,9 @@ int main(int argc, char **argv){ unlink(argv[1]); setupInstrumentedVfs(); instTime = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); rc = sqlite3_open(argv[1], &db); - iElapse = hwtime(); + iElapse = sqlite3Hwtime(); iElapse -= iStart + instTime; iSetup = iElapse; printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse); @@ -526,9 +520,9 @@ int main(int argc, char **argv){ } } instTime = 0; - iStart = hwtime(); + iStart = sqlite3Hwtime(); sqlite3_close(db); - iElapse = hwtime(); + iElapse = sqlite3Hwtime(); iElapse -= iStart + instTime; iSetup += iElapse; printf("sqlite3_close() returns in %llu cycles\n", iElapse);