Commit 19a8b495 authored by Jack Doerner's avatar Jack Doerner

Minor changes. Replaced OMP locks with gcc atomic builtins.

parent d95fb025
......@@ -47,7 +47,7 @@ $(ACKLIB): $(OBJS:%=$(SRC_PATH)/%)
%.fssl.oo: %.oc
$(OBLIVCC) -c $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FSSL $*.oc -o $*.sqrt.oo
cpp -MM $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FSSL $*.oc -MT $*.sqrt.oo > $*.sqrt.od
$(CPP) -MM $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_FSSL $*.oc -MT $*.sqrt.oo > $*.sqrt.od
%.sqrt.oo: %.oc
$(OBLIVCC) -c $(CFLAGS) -DORAM_OVERRIDE=ORAM_TYPE_SQRT $*.oc -o $*.sqrt.oo
......
......@@ -15,21 +15,19 @@ struct bitpropagator_offline {
void * level_bits;
void * keyL;
void * keyR;
omp_lock_t * locks;
uint32_t readycount;
};
void bitpropagator_offline_start(bitpropagator_offline * bpo, uint8_t * blocks) {
memcpy(bpo->level_data, blocks, (1ll<<bpo->startlevel) * BLOCKSIZE);
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_set_lock(&bpo->locks[ii]);
}
bpo->readycount = 0;
}
void bitpropagator_offline_push_Z(bitpropagator_offline * bpo, uint8_t * Z, bool advicebit_l, bool advicebit_r, size_t level) {
memcpy(&bpo->Z[(level- bpo->startlevel - 1)*BLOCKSIZE], Z, BLOCKSIZE);
bpo->advicebits_l[level- bpo->startlevel - 1] = advicebit_l;
bpo->advicebits_r[level- bpo->startlevel - 1] = advicebit_r;
omp_unset_lock(&bpo->locks[level- bpo->startlevel - 1]);
floram_atomic_inc(&bpo->readycount);
}
void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_bit_output, bitpropagator_offline * bpo) {
......@@ -41,6 +39,7 @@ void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_
size_t thislevelblocks = (1ll<<bpo->startlevel);
size_t nextlevelblocks = (bpo->size + (1ll<<(bpo->endlevel - thislevel -1)) - 1) / (1ll<<(bpo->endlevel - thislevel -1));
size_t expansion_stride;
uint32_t readycount_cache=0;
uint64_t* a = (uint64_t *)bpo->level_data;
uint8_t* a2 = (uint8_t *)bpo->level_data;
......@@ -96,8 +95,9 @@ void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_
#endif
for (thislevel = bpo->startlevel +1; thislevel < bpo->endlevel; thislevel++) {
#pragma omp single
omp_set_lock(&bpo->locks[thislevel- bpo->startlevel -1 ]);
if (readycount_cache < thislevel - bpo->startlevel) {
while ((readycount_cache = floram_atomic_read(&bpo->readycount)) < thislevel - bpo->startlevel) floram_usleep(SLEEP_TIME);
}
#ifdef ORAM_PROFILE_SCHEDULING
#pragma omp single nowait
......@@ -178,13 +178,12 @@ void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_
}
#ifdef ORAM_PROFILE_SCHEDULING
#pragma omp single nowait
printf("END FSS OFFLINE LEVEL %d %lld\n", thislevel,current_timestamp());
#pragma omp single nowait
printf("END FSS OFFLINE LEVEL %d %lld\n", thislevel,current_timestamp());
#endif
}
#pragma omp single
omp_set_lock(&bpo->locks[thislevel- bpo->startlevel -1 ]);
while (floram_atomic_read(&bpo->readycount) < thislevel - bpo->startlevel) floram_usleep(SLEEP_TIME);
#ifdef ORAM_PROFILE_SCHEDULING
#pragma omp single nowait
......@@ -291,10 +290,6 @@ void bitpropagator_offline_readblockvector(uint8_t * local_output, bool * local_
printf("END FSS LEVEL %d %lld\n", thislevel,current_timestamp());
#endif
}
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_unset_lock(&bpo->locks[ii]);
}
}
void bitpropagator_offline_parallelizer(void* bp, bitpropagator_offline * bpo, void* indexp, void * local_output, void * local_bit_output, void* pd, bp_traverser_fn fn, bp_pusher_fn fn2, facb_fn cbfn, void* cbpass) {
......@@ -335,7 +330,6 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t blockmulti
bpo->endlevel = LOG2LL(size) + (((1 << LOG2LL(size)) < size)? 1:0);
posix_memalign(&bpo->level_data,16,(1ll<<bpo->endlevel) * BLOCKSIZE);
posix_memalign(&bpo->Z,16,(bpo->endlevel - bpo->startlevel) * BLOCKSIZE);
bpo->locks = malloc((bpo->endlevel - bpo->startlevel) * sizeof(omp_lock_t));
bpo->advicebits_l = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->advicebits_r = malloc((bpo->endlevel - bpo->startlevel) * sizeof(bool));
bpo->level_bits = malloc(size * sizeof(bool));
......@@ -344,16 +338,10 @@ bitpropagator_offline * bitpropagator_offline_new(size_t size, size_t blockmulti
bpo->keyL = offline_prg_keyschedule(keyL);
bpo->keyR = offline_prg_keyschedule(keyR);
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_init_lock(&bpo->locks[ii]);
}
return bpo;
}
void bitpropagator_offline_free(bitpropagator_offline * bpo) {
for (int ii = 0; ii < (bpo->endlevel - bpo->startlevel); ii++) {
omp_destroy_lock(&bpo->locks[ii]);
}
free(bpo->level_data);
free(bpo->level_bits);
free(bpo->advicebits_l);
......@@ -361,6 +349,5 @@ void bitpropagator_offline_free(bitpropagator_offline * bpo) {
free(bpo->Z);
free(bpo->keyL);
free(bpo->keyR);
free(bpo->locks);
free(bpo);
}
\ No newline at end of file
......@@ -2,7 +2,6 @@
#include "bitpropagate.h"
#include "floram_util.oh"
#include "ackutil.h"
#include <omp.h>
#include <obliv.h>
struct bitpropagator {
......@@ -24,7 +23,7 @@ struct bitpropagator {
obliv uint8_t * keyL;
obliv uint8_t * keyR;
ProtocolDesc * pd2;
omp_lock_t * locks;
uint32_t readycount;
bitpropagator_offline * bpo;
};
......@@ -32,24 +31,29 @@ void bitpropagator_Z_pusher(bitpropagator * bp, bitpropagator_offline * bpo, Pro
if (pd != NULL) ocSetCurrentProto(pd);
uint32_t readycount_cache = 0;
bool advicebit_local_l, advicebit_local_r;
uint8_t * Z_local = malloc(BLOCKSIZE);
for (size_t ii = bp->startlevel+1; ii <= bp->endlevel; ii++) {
size_t thislevel = ii- bp->startlevel -1;
omp_set_lock(&bp->locks[thislevel]);
for (size_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)Z_local)[jj], ((obliv uint64_t *)(&bp->Z[thislevel*BLOCKSIZE]))[jj], 1);
revealOblivBool(&advicebit_local_l, bp->advicebits[thislevel*2+0], 1);
revealOblivBool(&advicebit_local_r, bp->advicebits[thislevel*2+1], 1);
if (readycount_cache < thislevel + 1) {
while ((readycount_cache = floram_atomic_read(&bp->readycount)) < thislevel + 1) floram_usleep(SLEEP_TIME);
}
for (size_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)Z_local)[jj], ((obliv uint64_t *)(&bp->Z[thislevel*BLOCKSIZE]))[jj], 2);
revealOblivBool(&advicebit_local_l, bp->advicebits[thislevel*2+0], 2);
revealOblivBool(&advicebit_local_r, bp->advicebits[thislevel*2+1], 2);
bitpropagator_offline_push_Z(bpo, Z_local, advicebit_local_l, advicebit_local_r, ii);
for (size_t jj = 0; jj < BLOCKSIZE/sizeof(uint64_t); jj++) revealOblivLLong(&((uint64_t *)Z_local)[jj], ((obliv uint64_t *)(&bp->Z[thislevel*BLOCKSIZE]))[jj], 1);
revealOblivBool(&advicebit_local_l, bp->advicebits[thislevel*2+0], 1);
revealOblivBool(&advicebit_local_r, bp->advicebits[thislevel*2+1], 1);
//Other threads may depend on the fact that we've pushed successfully
if (pd != NULL) oflush(pd);
oflush(ocCurrentProto());
bitpropagator_offline_push_Z(bpo, Z_local, advicebit_local_l, advicebit_local_r, ii);
}
free(Z_local);
......@@ -97,7 +101,8 @@ void bitpropagator_traverselevels(bitpropagator * bp, obliv size_t * indexp) {
bitpropagator_getadvice(&bp->advicebits[(ii - bp->startlevel - 1)*2], bp->expanded_A, bp->expanded_B, levelindex);
omp_unset_lock(&bp->locks[ii - bp->startlevel - 1]);
oflush(ocCurrentProto());
floram_atomic_inc(&bp->readycount);
control_bit_A_next = control_bit_A;
control_bit_B_next = control_bit_B;
......@@ -174,6 +179,7 @@ void bitpropagator_getblockvector_with_callback(obliv uint8_t * activeblock_delt
#endif
bitpropagator_offline_start(bp->bpo, bp->toplevel_local);
bp->readycount = 0;
#ifdef _OPENMP
//This is a hack to work around the fact that openmp and obliv-c are incompatible.
......@@ -233,11 +239,7 @@ bitpropagator * bitpropagator_new(size_t size, size_t blockmultiple, uint32_t st
free(keyL);
free(keyR);
bp->locks = malloc((bp->endlevel - bp->startlevel) * sizeof(omp_lock_t));
for (size_t ii = 0; ii < bp->endlevel - bp->startlevel; ii++) {
omp_init_lock(&bp->locks[ii]);
omp_set_lock(&bp->locks[ii]);
}
bp->readycount = 0;
#ifdef _OPENMP
bp->pd2 = calloc(1, sizeof(ProtocolDesc));
......@@ -267,11 +269,6 @@ void bitpropagator_free(bitpropagator * bp) {
free(bp->pd2);
#endif
for (int ii = 0; ii < (bp->endlevel - bp->startlevel); ii++) {
omp_destroy_lock(&bp->locks[ii]);
}
free(bp->locks);
online_expand_deinit();
free(bp);
}
\ No newline at end of file
......@@ -11,6 +11,7 @@
#define BLOCKSIZE 16
#define CACHE_PER_CORE (1024*1024)
#define SLEEP_TIME 1000
//#define SCANROM_DISABLE_ENCRYPTION
//#define FLORAM_DISABLE_AUTO_THREAD_COUNT
......
......@@ -87,7 +87,7 @@ void floram_scan_callback(facb_pass * input, ProtocolDesc *pd) {
input->found=found;
// this protocol may not do anything else for a while, but other threads could be waiting for it
if (pd != NULL) oflush(pd);
oflush(ocCurrentProto());
#ifdef ORAM_PROFILE_SCHEDULING
printf("END STASH SCAN %lld\n", current_timestamp());
......
#include "floram_util.h"
#include <omp.h>
#include <unistd.h>
void get_random_bytes(void *buf, size_t bytes) {
//only supported on recent linuxes, unfortunately.
......@@ -24,6 +25,19 @@ int floram_zpma(void** dst, size_t alignment, size_t size) {
return res;
}
uint32_t floram_atomic_read(uint32_t * x) {
return __atomic_load_n(x, __ATOMIC_RELAXED);
}
void floram_atomic_inc(uint32_t * x) {
return __atomic_fetch_add(x, 1, __ATOMIC_RELAXED);
}
int floram_usleep(uint64_t x) {
return usleep(x);
}
void floram_set_procs_for_data_size(size_t dsize) {
#ifndef FLORAM_DISABLE_AUTO_THREAD_COUNT
size_t recommended_cores = (dsize + CACHE_PER_CORE - 1) / CACHE_PER_CORE;
......
......@@ -18,6 +18,11 @@ void get_random_bytes(void *buf, size_t bytes);
int floram_pma(void** dst, size_t alignment, size_t size);
int floram_zpma(void** dst, size_t alignment, size_t size);
uint32_t floram_atomic_read(uint32_t *);
void floram_atomic_inc(uint32_t *);
int floram_usleep(uint64_t x);
void offline_expand(uint8_t * dest, uint8_t * src, size_t n);
void offline_expand_from(uint8_t * dest, uint8_t * src, size_t i, size_t n);
......
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