Fix terrible Linux SHM performance on single-core

develop
Petr Mrázek 2010-02-28 18:08:44 +01:00
parent 05250b4eb5
commit fa878f2e9d
5 changed files with 15 additions and 23 deletions

@ -16,17 +16,6 @@ int main (void)
time_t start, end;
double time_diff;
DFHack::API DF("Memory.xml");
//if(!DF.Attach())
//{
// cerr << "DF not found" << endl;
// return 1;
//}
//if(!DF.Detach())
//{
// cerr << "Can't detach from DF" << endl;
// return 1;
//}
try
{
DF.Attach();
@ -77,11 +66,11 @@ int main (void)
cout << "Testing suspend/resume" << endl;
DF.Attach();
time(&start);
for (int i = 0; i < 1000000; i++)
for (int i = 0; i < 1000; i++)
{
DF.Suspend();
if(i%10000 == 0)
cout << i / 10000 << "%" << endl;
if(i%10 == 0)
cout << i / 10 << "%" << endl;
DF.Resume();
}
time(&end);

@ -29,15 +29,15 @@ int main (void)
}
time(&start);
for(uint32_t i = 0; i< 1000;i++)
for(uint32_t i = 0; i< 10000;i++)
{
if(!DF.InitMap())
break;
DF.getSize(x_max,y_max,z_max);
if((i % 10) == 0)
if((i % 100) == 0)
{
int percentage = i / 10;
cout << percentage << endl;
int percentage = i / 100;
cout << percentage << " %" << endl;
}
for(uint32_t x = 0; x< x_max;x++)
{

@ -30,6 +30,8 @@ distribution.
#include "../shmserver/shms.h"
#include <sys/time.h>
#include <time.h>
#include <sched.h>
using namespace DFHack;
// a full memory barrier! better be safe than sorry.
@ -74,6 +76,7 @@ bool SHMProcess::Private::waitWhile (DF_PINGPONG state)
{
if(cnt == 10000)
{
shmctl(my_shmid, IPC_STAT, &descriptor);
if(descriptor.shm_nattch == 1)// DF crashed?
{
@ -87,6 +90,7 @@ bool SHMProcess::Private::waitWhile (DF_PINGPONG state)
cnt = 0;
}
}
SCHED_YIELD
cnt++;
}
if(((shm_cmd *)my_shm)->pingpong == DFPP_SV_ERROR)
@ -254,10 +258,6 @@ SHMProcess::~SHMProcess()
{
delete d->my_window;
}
if(d->my_shm)
{
fprintf(stderr,"detach: %d",shmdt(d->my_shm));
}
delete d;
}
@ -411,6 +411,7 @@ bool SHMProcess::detach()
{
d->attached = false;
d->suspended = false;
d->my_shm = 0;
g_pProcess = 0;
return true;
}

Binary file not shown.

@ -12,7 +12,9 @@
#ifdef LINUX_BUILD
// a full memory barrier! better be safe than sorry.
#define full_barrier asm volatile("" ::: "memory"); __sync_synchronize();
#define SCHED_YIELD
#define SCHED_YIELD sched_yield(); // slow but allows the SHM to work on single-core
// #define SCHED_YIELD usleep(0); // extremely slow
// #define SCHED_YIELD // works only on multi-core
#else
// we need windows.h for Sleep()
#define _WIN32_WINNT 0x0501 // needed for INPUT struct