From: Nathan Bronson Date: Wed, 17 Feb 2016 22:20:19 +0000 (-0800) Subject: clang-format some code in preparation for real changes X-Git-Tag: deprecate-dynamic-initializer~63 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3e4e50d50a4f003d998ba054a6561e17a07c4088;p=folly.git clang-format some code in preparation for real changes Reviewed By: djwatson Differential Revision: D2945770 fb-gh-sync-id: 9e4ee3b052b0bbb33ef796b8070edd24c6942589 shipit-source-id: 9e4ee3b052b0bbb33ef796b8070edd24c6942589 --- diff --git a/folly/detail/CacheLocality.cpp b/folly/detail/CacheLocality.cpp index 8667b34f..6f7657f5 100644 --- a/folly/detail/CacheLocality.cpp +++ b/folly/detail/CacheLocality.cpp @@ -28,7 +28,8 @@ #include #include -namespace folly { namespace detail { +namespace folly { +namespace detail { ///////////// CacheLocality @@ -84,11 +85,11 @@ const CacheLocality& CacheLocality::system() { /// '\n', or eos. static size_t parseLeadingNumber(const std::string& line) { auto raw = line.c_str(); - char *end; + char* end; unsigned long val = strtoul(raw, &end, 10); if (end == raw || (*end != ',' && *end != '-' && *end != '\n' && *end != 0)) { - throw std::runtime_error(to( - "error parsing list '", line, "'").c_str()); + throw std::runtime_error( + to("error parsing list '", line, "'").c_str()); } return val; } @@ -107,9 +108,10 @@ CacheLocality CacheLocality::readFromSysfsTree( while (true) { auto cpu = cpus.size(); std::vector levels; - for (size_t index = 0; ; ++index) { - auto dir = format("/sys/devices/system/cpu/cpu{}/cache/index{}/", - cpu, index).str(); + for (size_t index = 0;; ++index) { + auto dir = + format("/sys/devices/system/cpu/cpu{}/cache/index{}/", cpu, index) + .str(); auto cacheType = mapping(dir + "type"); auto equivStr = mapping(dir + "shared_cpu_list"); if (cacheType.size() == 0 || equivStr.size() == 0) { @@ -146,22 +148,26 @@ CacheLocality CacheLocality::readFromSysfsTree( throw std::runtime_error("unable to load cache sharing info"); } - std::sort(cpus.begin(), cpus.end(), [&](size_t lhs, size_t rhs) -> bool { - // sort first by equiv class of cache with highest index, direction - // doesn't matter. If different cpus have different numbers of - // caches then this code might produce a sub-optimal ordering, but - // it won't crash - auto& lhsEquiv = equivClassesByCpu[lhs]; - auto& rhsEquiv = equivClassesByCpu[rhs]; - for (int i = std::min(lhsEquiv.size(), rhsEquiv.size()) - 1; i >= 0; --i) { - if (lhsEquiv[i] != rhsEquiv[i]) { - return lhsEquiv[i] < rhsEquiv[i]; - } - } - - // break ties deterministically by cpu - return lhs < rhs; - }); + std::sort(cpus.begin(), + cpus.end(), + [&](size_t lhs, size_t rhs) -> bool { + // sort first by equiv class of cache with highest index, + // direction doesn't matter. If different cpus have + // different numbers of caches then this code might produce + // a sub-optimal ordering, but it won't crash + auto& lhsEquiv = equivClassesByCpu[lhs]; + auto& rhsEquiv = equivClassesByCpu[rhs]; + for (int i = std::min(lhsEquiv.size(), rhsEquiv.size()) - 1; + i >= 0; + --i) { + if (lhsEquiv[i] != rhsEquiv[i]) { + return lhsEquiv[i] < rhsEquiv[i]; + } + } + + // break ties deterministically by cpu + return lhs < rhs; + }); // the cpus are now sorted by locality, with neighboring entries closer // to each other than entries that are far away. For striping we want @@ -172,7 +178,7 @@ CacheLocality CacheLocality::readFromSysfsTree( } return CacheLocality{ - cpus.size(), std::move(numCachesByLevel), std::move(indexes) }; + cpus.size(), std::move(numCachesByLevel), std::move(indexes)}; } CacheLocality CacheLocality::readFromSysfs() { @@ -184,7 +190,6 @@ CacheLocality CacheLocality::readFromSysfs() { }); } - CacheLocality CacheLocality::uniform(size_t numCpus) { CacheLocality rv; @@ -235,28 +240,26 @@ Getcpu::Func Getcpu::vdsoFunc() { #ifdef FOLLY_TLS /////////////// SequentialThreadId -template<> +template <> std::atomic SequentialThreadId::prevId(0); -template<> +template <> FOLLY_TLS size_t SequentialThreadId::currentId(0); #endif /////////////// AccessSpreader -template<> -const AccessSpreader -AccessSpreader::stripeByCore( +template <> +const AccessSpreader AccessSpreader::stripeByCore( CacheLocality::system<>().numCachesByLevel.front()); -template<> -const AccessSpreader -AccessSpreader::stripeByChip( +template <> +const AccessSpreader AccessSpreader::stripeByChip( CacheLocality::system<>().numCachesByLevel.back()); -template<> -AccessSpreaderArray -AccessSpreaderArray::sharedInstance = {}; +template <> +AccessSpreaderArray + AccessSpreaderArray::sharedInstance = {}; /// Always claims to be on CPU zero, node zero static int degenerateGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) { @@ -269,7 +272,7 @@ static int degenerateGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) { return 0; } -template<> +template <> Getcpu::Func AccessSpreader::pickGetcpuFunc(size_t numStripes) { if (numStripes == 1) { // there's no need to call getcpu if there is only one stripe. @@ -282,5 +285,5 @@ Getcpu::Func AccessSpreader::pickGetcpuFunc(size_t numStripes) { return best ? best : &FallbackGetcpuType::getcpu; } } - -} } // namespace folly::detail +} +} // namespace folly::detail diff --git a/folly/detail/CacheLocality.h b/folly/detail/CacheLocality.h index d6fd4d51..ac9de657 100644 --- a/folly/detail/CacheLocality.h +++ b/folly/detail/CacheLocality.h @@ -30,7 +30,8 @@ #include #include -namespace folly { namespace detail { +namespace folly { +namespace detail { // This file contains several classes that might be useful if you are // trying to dynamically optimize cache locality: CacheLocality reads @@ -73,7 +74,6 @@ struct CacheLocality { /// cache and cpus with a locality index >= 16 will share the other. std::vector localityIndexByCpu; - /// Returns the best CacheLocality information available for the current /// system, cached for fast access. This will be loaded from sysfs if /// possible, otherwise it will be correct in the number of CPUs but @@ -88,10 +88,9 @@ struct CacheLocality { /// that transitively uses it, all components select between the default /// sysfs implementation and a deterministic implementation by keying /// off the type of the underlying atomic. See DeterministicScheduler. - template class Atom = std::atomic> + template