From f6eb3cfb172a21b3143da1ad895d8a761968fc75 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 7 Oct 2008 16:33:02 +0000 Subject: [PATCH] 2008-10-07 18:32 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbstack.h * harbour/source/vm/estack.c * harbour/source/vm/hvm.c % moved static USHORT uiPolls to HVM stack to not reduce the HVM performance in MT mode. In multi CPU environment if many threads try to change the same memory variable in the same time the overall performance is strongly reduced on most of tested hardware - probably some random CPU delay used to resolve the conflict. --- harbour/ChangeLog | 10 ++++++++++ harbour/include/hbstack.h | 4 ++++ harbour/source/vm/estack.c | 11 +++++++++++ harbour/source/vm/hvm.c | 8 ++++---- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 944f6dd3a8..e6b46932c1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,16 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-07 18:32 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbstack.h + * harbour/source/vm/estack.c + * harbour/source/vm/hvm.c + % moved static USHORT uiPolls to HVM stack to not reduce the HVM + performance in MT mode. In multi CPU environment if many threads + try to change the same memory variable in the same time the overall + performance is strongly reduced on most of tested hardware - probably + some random CPU delay used to resolve the conflict. + 2008-10-07 16:33 UTC+0200 Maurilio Longo (maurilio.longo@libero.it) * harbour/source/rtl/seconds.c + Added OS/2 section to secondsCPU(), but it does not work as expected :) diff --git a/harbour/include/hbstack.h b/harbour/include/hbstack.h index 0deb59e9a9..701ba02c0b 100644 --- a/harbour/include/hbstack.h +++ b/harbour/include/hbstack.h @@ -177,6 +177,7 @@ typedef struct PHB_TSD_HOLDER pTSD; /* thread specific data holder */ HB_PRIVATE_STACK privates; /* private variables stack */ HB_SET_STRUCT set; + int iKeyPoll; /* counter for GT/keyboard polling */ #if defined( HB_MT_VM ) int iUnlocked; /* counter for nested hb_vmUnlock() calls */ PHB_DYN_HANDLES pDynH; /* dynamic symbol handles */ @@ -308,6 +309,8 @@ extern PHB_ITEM hb_stackWithObjectItem( void ); extern LONG hb_stackWithObjectOffset( void ); extern void hb_stackWithObjectSetOffset( LONG ); +extern int * hb_stackKeyPolls( void ); + extern void hb_stackDestroyTSD( void ); extern PHB_PRIVATE_STACK hb_stackGetPrivateStack( void ); @@ -442,6 +445,7 @@ extern void hb_stackIsStackRef( void *, PHB_TSD_FUNC ); #define hb_stackGetPrivateStack( ) ( &hb_stack.privates ) #define hb_stackSetStruct( ) ( &hb_stack.set ) +#define hb_stackKeyPolls( ) ( &hb_stack.iKeyPoll ) #endif diff --git a/harbour/source/vm/estack.c b/harbour/source/vm/estack.c index a8aa77a6af..52c64c4ff0 100644 --- a/harbour/source/vm/estack.c +++ b/harbour/source/vm/estack.c @@ -181,6 +181,7 @@ static void hb_stack_init( PHB_STACK pStack ) ( * pStack->pItems )->item.asSymbol.stackstate = &pStack->state; pStack->rdd.uiCurrArea = 1; + hb_stack.iKeyPoll = 1; } static void hb_stack_destroy_TSD( PHB_STACK pStack ) @@ -421,6 +422,16 @@ int hb_stackLock( void ) } #endif +#undef hb_stackKeyPolls +int * hb_stackKeyPolls( void ) +{ + HB_STACK_TLS_PRELOAD + + HB_TRACE(HB_TR_DEBUG, ("hb_stackKeyPolls()")); + + return &hb_stack.iKeyPoll; +} + #undef hb_stackGetPrivateStack PHB_PRIVATE_STACK hb_stackGetPrivateStack( void ) { diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 457e7fb32c..3f2c5ad6f5 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -1064,7 +1064,7 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) ULONG ulPastClock = 0; /* opcodes profiler support */ #endif #if !defined( HB_GUI ) - static unsigned short uiPolls = 1; + int * piKeyPolls = hb_stackKeyPolls(); #endif HB_TRACE(HB_TR_DEBUG, ("hb_vmExecute(%p, %p)", pCode, pSymbols)); @@ -1089,10 +1089,10 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) #endif #if !defined( HB_GUI ) - if( ! --uiPolls ) + if( ! --( *piKeyPolls ) ) { hb_inkeyPoll(); - /* uiPolls = 255; */ + *piKeyPolls = 65536; /* IMHO we should have a _SET_ controlled by user * sth like: @@ -1100,7 +1100,7 @@ HB_EXPORT void hb_vmExecute( const BYTE * pCode, PHB_SYMB pSymbols ) if( hb_stackSetStruct()->HB_SET_KEYPOLL ) { hb_inkeyPoll(); - uiPolls = hb_stackSetStruct()->HB_SET_KEYPOLL; + *piKeyPolls = hb_stackSetStruct()->HB_SET_KEYPOLL; } for some GTs which can work in assynchrous mode user may