Question

I am trying to generate various types of data intensity on bus on a multiprocessor environment. Basically I need two patterns - almost negligible traffic on bus and very high traffic on bus. Initially I was thinking about accessing registers and not writing them back to cache/main memory to generate a low bus traffic. But I am not very sure about the idea. Besides I am doing the coding part in Java.

Any hints how to do this?

Architecture: x86_64

EDIT: I have the following code snippet.

    mutex.lock();
    try{
        // Generate Bus traffic
    }
    finally{
        mutex.unlock();
    }

For each thread, I am trying to generate the traffic in the critical section.

Was it helpful?

Solution

Accessing registers generates zero traffic on the bus (unless you mean some CPU-internal bus). To generate maximum traffic on a CPU-memory bus, just read an array bigger than your biggest cache (typically L3 with a few megabytes). Make sure the read data gets actually used, so that DCE doesn't kick in.

long[] data = new long[1<<24]; // 8 * 16MB
volatile long blackhole;

void saturateBus() {
    long sum = 0;
    for (long x : data) sum += x;
    blackhole = sum;
}

This should saturate your memory bus on a modern amd64 architecture as the loop can execute in 1 cycle per element. Assuming some unbelievably fast memory, you could need to unroll manually like this

    long sum0 = 0, sum1 = 0;
    for (int i=0; i<data.length; i+=2) { // assuming even `data.length`
        sum0 += data[i+0];
        sum1 += data[i+1];
    }
    blackhole = sum0 + sum1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top