Commit d1b9d031 authored by Martin Karsten's avatar Martin Karsten

- add cluster-group affinity to sample/benchmark webserver

parent 589709d2
......@@ -85,6 +85,7 @@ static unsigned int scopeCount = 1;
static unsigned int listenerCount = 1; // 0 -> listener per connection
static unsigned int threadCount = 1;
static bool affinityFlag = false;
static bool groupAffinityFlag = false;
static bool singleServerSocket = true;
static bool eagerRegistration = false;
......@@ -110,7 +111,7 @@ static FibreGarage& CurrGarage() {
// help message
static void usage(const char* prog) {
cerr << "usage: " << prog << " -c <cluster size> -e <event scope count> -l <listener count> -t <system threads> -a -m -r" << endl;
cerr << "usage: " << prog << " -c <cluster size> -e <event scope count> -l <listener count> -t <system threads> -a -g -m -r" << endl;
}
// fibre counting
......@@ -121,6 +122,7 @@ static void exitHandler(int sig) {
if (sig == SIGINT) cout << endl;
cout << "threads: " << threadCount << " cluster size: " << clusterSize << " listeners: " << listenerCount << " event scopes: " << scopeCount;
if (affinityFlag) cout << " affinity";
else if (groupAffinityFlag) cout << " group affinity";
cout << endl << "connections: " << connections << endl;
cout << "fibres: " << connectionFibres << endl;
exit(0);
......@@ -129,7 +131,7 @@ static void exitHandler(int sig) {
// command-line option processing
static void opts(int argc, char** argv) {
for (;;) {
int option = getopt( argc, argv, "c:e:l:t:armh?" );
int option = getopt( argc, argv, "c:e:l:t:agmrh?" );
if ( option < 0 ) break;
switch(option) {
case 'c': clusterSize = atoi(optarg); break;
......@@ -137,6 +139,7 @@ static void opts(int argc, char** argv) {
case 'l': listenerCount = atoi(optarg); break;
case 't': threadCount = atoi(optarg); break;
case 'a': affinityFlag = true; break;
case 'g': groupAffinityFlag = true; break;
case 'm': singleServerSocket = false; break;
case 'r': eagerRegistration = true; break;
case 'h':
......@@ -413,15 +416,13 @@ static void scopemain() {
sproc[t] = new OsProcessor(*cluster[t/clusterSize]);
}
if (affinityFlag) {
if (affinityFlag || groupAffinityFlag) {
// set processor per-core affinity
#if defined __LIBFIBRE__
cpu_set_t clustercpus;
CPU_ZERO(&clustercpus);
#if !TESTING_POLLER_FIBRE
unsigned int cidx = 0;
#endif
#endif
cpu_set_t allcpus;
CPU_ZERO(&allcpus);
......@@ -431,23 +432,35 @@ static void scopemain() {
CPU_ZERO(&onecpu);
for (unsigned int t = 0; t < threadCount; t += 1) {
while (!CPU_ISSET(cpu, &allcpus)) cpu = (cpu + 1) % CPU_SETSIZE;
CPU_SET(cpu, &onecpu);
// cout << "fibre "<< t << " affinity " << cpu << endl;
if (affinityFlag) {
CPU_SET(cpu, &onecpu);
cout << "thread "<< t << " affinity " << cpu << endl;
#if defined __LIBFIBRE__
SYSCALL(pthread_setaffinity_np(sproc[t]->getSysID(), sizeof(onecpu), &onecpu));
SYSCALL(pthread_setaffinity_np(sproc[t]->getSysID(), sizeof(onecpu), &onecpu));
#else
sproc[t]->setAffinity(onecpu);
sproc[t]->setAffinity(onecpu);
#endif
CPU_CLR(cpu, &onecpu);
#if defined __LIBFIBRE__ && !TESTING_POLLER_FIBRE
// set poller thread affinity to group of cores
CPU_CLR(cpu, &onecpu);
}
#if defined __LIBFIBRE__
// set affinity to group of cores
CPU_SET(cpu, &clustercpus);
if (((t % clusterSize) == clusterSize-1) || (t == threadCount-1)) { // end of cluster or end of threads
// cout << "cluster " << cidx << " affinity: ";
// for (int j = 0; j < CPU_SETSIZE; j++) if (CPU_ISSET(j, &clustercpus)) cout << ' ' << j;
// cout << endl;
SYSCALL(pthread_setaffinity_np(cluster[cidx]->getPoller().getSysID(), sizeof(clustercpus), &clustercpus));
cout << "cluster " << cidx << " affinity: ";
for (int j = 0; j < CPU_SETSIZE; j++) if (CPU_ISSET(j, &clustercpus)) cout << ' ' << j;
cout << endl;
if (affinityFlag) {
#if !TESTING_POLLER_FIBRE
SYSCALL(pthread_setaffinity_np(cluster[cidx]->getPoller().getSysID(), sizeof(clustercpus), &clustercpus));
#endif
} else if (groupAffinityFlag) {
cout << "threads:";
for (unsigned int x = t - (clusterSize-1); x <= t; x += 1) {
cout << ' ' << x;
SYSCALL(pthread_setaffinity_np(sproc[t]->getSysID(), sizeof(clustercpus), &clustercpus));
}
cout << endl;
}
CPU_ZERO(&clustercpus);
cidx += 1;
}
......@@ -455,8 +468,7 @@ static void scopemain() {
cpu += 1;
} // loop through CPUs
} // affinityFlag
} // affinityFlag || groupAffinityFlag
#else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment