Bug fix by Ingo Molnar, taken from
http://marc.info/?l=linux-kernel&m=
119088670113210&w=2
This reduces CPU usage a lot - confirmed in individual tests.
void thread_rest ( void ) {
#if defined( HAVE_THREAD )
#if defined( HAVE_POSIX_THREAD )
void thread_rest ( void ) {
#if defined( HAVE_THREAD )
#if defined( HAVE_POSIX_THREAD )
- // TODO add checks for sched_yield or pthread_yield and call that
- // if available
- usleep( 0 );
#else // Win32
SwitchToThread( );
#endif
#else // Win32
SwitchToThread( );
#endif
char buffer[64]; // Buffer for printing
ReportHeader *ReportRoot = NULL;
extern Condition ReportCond;
char buffer[64]; // Buffer for printing
ReportHeader *ReportRoot = NULL;
extern Condition ReportCond;
+extern Condition ReportDoneCond;
int reporter_process_report ( ReportHeader *report );
void process_report ( ReportHeader *report );
int reporter_handle_packet( ReportHeader *report );
int reporter_process_report ( ReportHeader *report );
void process_report ( ReportHeader *report );
int reporter_handle_packet( ReportHeader *report );
// item
while ( index == 0 ) {
Condition_Signal( &ReportCond );
// item
while ( index == 0 ) {
Condition_Signal( &ReportCond );
+ Condition_Wait( &ReportDoneCond );
index = agent->reporterindex;
}
agent->agentindex = 0;
index = agent->reporterindex;
}
agent->agentindex = 0;
// Need to make sure that reporter is not about to be "lapped"
while ( index - 1 == agent->agentindex ) {
Condition_Signal( &ReportCond );
// Need to make sure that reporter is not about to be "lapped"
while ( index - 1 == agent->agentindex ) {
Condition_Signal( &ReportCond );
+ Condition_Wait( &ReportDoneCond );
index = agent->reporterindex;
}
index = agent->reporterindex;
}
}
Condition_Unlock ( ReportCond );
}
Condition_Unlock ( ReportCond );
if ( ReportRoot != NULL ) {
ReportHeader *temp = ReportRoot;
//Condition_Unlock ( ReportCond );
if ( ReportRoot != NULL ) {
ReportHeader *temp = ReportRoot;
//Condition_Unlock ( ReportCond );
// finished with report so free it
free( temp );
Condition_Unlock ( ReportCond );
// finished with report so free it
free( temp );
Condition_Unlock ( ReportCond );
+ Condition_Signal( &ReportDoneCond );
+ if (ReportRoot)
+ goto again;
- // yield control of CPU is another thread is waiting
- thread_rest();
+ Condition_Signal( &ReportDoneCond );
+ usleep(10000);
} else {
//Condition_Unlock ( ReportCond );
}
} else {
//Condition_Unlock ( ReportCond );
}
// records being accessed in a report and also to
// serialize modification of the report list
Condition ReportCond;
// records being accessed in a report and also to
// serialize modification of the report list
Condition ReportCond;
+ Condition ReportDoneCond;
}
// global variables only accessed within this file
}
// global variables only accessed within this file
// Initialize global mutexes and conditions
Condition_Initialize ( &ReportCond );
// Initialize global mutexes and conditions
Condition_Initialize ( &ReportCond );
+ Condition_Initialize ( &ReportDoneCond );
Mutex_Initialize( &groupCond );
Mutex_Initialize( &clients_mutex );
Mutex_Initialize( &groupCond );
Mutex_Initialize( &clients_mutex );