X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11concurrency-benchmarks.git;a=blobdiff_plain;f=silo%2Fcore.cc;fp=silo%2Fcore.cc;h=8f91fded129c6bca69f53404154a80039fbb1278;hp=0000000000000000000000000000000000000000;hb=19b84c667216ff74f1b747e18b5542444dc54716;hpb=72045f68e6d1ad46133bdc507b409b676ce64957 diff --git a/silo/core.cc b/silo/core.cc new file mode 100644 index 0000000..8f91fde --- /dev/null +++ b/silo/core.cc @@ -0,0 +1,35 @@ +#include + +#include "amd64.h" +#include "core.h" +#include "util.h" + +using namespace std; +using namespace util; + +int +coreid::allocate_contiguous_aligned_block(unsigned n, unsigned alignment) +{ +retry: + unsigned current = g_core_count.load(memory_order_acquire); + const unsigned rounded = slow_round_up(current, alignment); + const unsigned replace = rounded + n; + if (unlikely(replace > NMaxCores)) + return -1; + if (!g_core_count.compare_exchange_strong(current, replace, memory_order_acq_rel)) { + nop_pause(); + goto retry; + } + return rounded; +} + +unsigned +coreid::num_cpus_online() +{ + const long nprocs = sysconf(_SC_NPROCESSORS_ONLN); + ALWAYS_ASSERT(nprocs >= 1); + return nprocs; +} + +__thread int coreid::tl_core_id = -1; +atomic coreid::g_core_count(0);