Skip to content

Instantly share code, notes, and snippets.

@aprell
Created May 23, 2012 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprell/2775874 to your computer and use it in GitHub Desktop.
Save aprell/2775874 to your computer and use it in GitHub Desktop.
Updating MPB-allocated objects < cache line size in RCCE
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include "RCCE.h"
#include "RCCE_lib.h"
#define WORKER(i) if (RCCE_ue() == (i))
static int *fool_wcb;
static int MPB_read(int *n)
{
return (RC_cache_invalidate(), *n);
}
static void MPB_write(int *n, int v)
{
(RC_cache_invalidate(), *n = v);
// Fool WCB by writing to a distinct cache line -> flush
*fool_wcb = 42;
}
static int MPB_add(int *n, int v)
{
// Make sure we don't read stale data
int newval = (RC_cache_invalidate(), *n + v);
// We need this second invalidation or otherwise the write would hit in L1
(RC_cache_invalidate(), *n = newval);
// Fool WCB by writing to a distinct cache line -> flush
*fool_wcb = 42;
return newval;
}
int RCCE_APP(int argc, char *argv[])
{
int offset, *shared, i;
t_vcharp p;
dup2(STDOUT_FILENO, STDERR_FILENO);
RCCE_init(&argc, &argv);
p = RCCE_malloc(2 * RCCE_LINE_SIZE);
offset = (long)p - (long)RCCE_comm_buffer[RCCE_ue()];
shared = (int *)(RCCE_comm_buffer[0] + offset);
fool_wcb = (int *)(RCCE_comm_buffer[0] + offset + RCCE_LINE_SIZE);
WORKER(0) MPB_write(shared, 0);
RCCE_barrier(&RCCE_COMM_WORLD);
assert(MPB_read(shared) == 0);
for (i = 0; i < RCCE_num_ues(); i++) {
WORKER(i) {
while (MPB_read(shared) != i) ;
MPB_add(shared, 1);
}
}
RCCE_barrier(&RCCE_COMM_WORLD);
assert(MPB_read(shared) == RCCE_num_ues());
RCCE_finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment