Skip to content

Commit 0d6281c

Browse files
2 parents 05b9424 + 72396d5 commit 0d6281c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+612
-293
lines changed

configure.ac

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ AC_ARG_WITH([bdb],
132132
[use_bdb=$withval],
133133
[use_bdb=auto])
134134

135+
AC_ARG_ENABLE([ebpf],
136+
[AS_HELP_STRING([--enable-ebpf],
137+
[enable eBPF tracing (default is yes if sys/sdt.h is found)])],
138+
[use_ebpf=$enableval],
139+
[use_ebpf=yes])
140+
135141
AC_ARG_WITH([miniupnpc],
136142
[AS_HELP_STRING([--with-miniupnpc],
137143
[enable UPNP (default is yes if libminiupnpc is found)])],
@@ -1368,6 +1374,16 @@ if test x$enable_wallet != xno; then
13681374
fi
13691375
fi
13701376

1377+
if test x$use_ebpf != xno; then
1378+
AC_CHECK_HEADER([sys/sdt.h], [have_sdt=yes], [have_sdt=no])
1379+
else
1380+
have_sdt=no
1381+
fi
1382+
1383+
if test x$have_sdt = xyes; then
1384+
AC_DEFINE([ENABLE_TRACING], [1], [Define to 1 to enable eBPF user static defined tracepoints])
1385+
fi
1386+
13711387
dnl Check for libminiupnpc (optional)
13721388
if test x$use_upnp != xno; then
13731389
AC_CHECK_HEADERS(
@@ -1740,6 +1756,7 @@ AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
17401756
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
17411757
AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
17421758
AM_CONDITIONAL([USE_BDB], [test "x$use_bdb" = "xyes"])
1759+
AM_CONDITIONAL([ENABLE_TRACING],[test x$have_sdt = xyes])
17431760
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
17441761
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
17451762
AM_CONDITIONAL([ENABLE_FUZZ_BINARY],[test x$enable_fuzz_binary = xyes])
@@ -1905,6 +1922,7 @@ echo " with bench = $use_bench"
19051922
echo " with upnp = $use_upnp"
19061923
echo " with natpmp = $use_natpmp"
19071924
echo " use asm = $use_asm"
1925+
echo " ebpf tracing = $have_sdt"
19081926
echo " sanitizers = $use_sanitizers"
19091927
echo " debug enabled = $enable_debug"
19101928
echo " stacktraces enabled = $enable_stacktraces"

src/Makefile.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ BITCOIN_CORE_H = \
310310
util/check.h \
311311
util/enumerate.h \
312312
util/error.h \
313+
util/fastrange.h \
313314
util/fees.h \
314315
util/golombrice.h \
316+
util/hasher.h \
315317
util/hash_type.h \
316318
util/irange.h \
317319
util/spanparsing.h \
@@ -321,6 +323,7 @@ BITCOIN_CORE_H = \
321323
util/macros.h \
322324
util/message.h \
323325
util/moneystr.h \
326+
util/overflow.h \
324327
util/ranges.h \
325328
util/readwritefile.h \
326329
util/underlying.h \
@@ -330,7 +333,9 @@ BITCOIN_CORE_H = \
330333
util/sock.h \
331334
util/string.h \
332335
util/time.h \
336+
util/thread.h \
333337
util/threadnames.h \
338+
util/trace.h \
334339
util/translation.h \
335340
util/vector.h \
336341
util/url.h \
@@ -735,8 +740,10 @@ libbitcoin_util_a_SOURCES = \
735740
util/asmap.cpp \
736741
util/bip32.cpp \
737742
util/bytevectorhash.cpp \
743+
util/check.cpp \
738744
util/error.cpp \
739745
util/fees.cpp \
746+
util/hasher.cpp \
740747
util/getuniquepath.cpp \
741748
util/sock.cpp \
742749
util/system.cpp \
@@ -750,6 +757,7 @@ libbitcoin_util_a_SOURCES = \
750757
util/time.cpp \
751758
util/serfloat.cpp \
752759
util/string.cpp \
760+
util/thread.cpp \
753761
util/threadnames.cpp \
754762
$(BITCOIN_CORE_H)
755763

src/bench/bench.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#ifndef BITCOIN_BENCH_BENCH_H
66
#define BITCOIN_BENCH_BENCH_H
77

8+
#include <util/macros.h>
9+
810
#include <chrono>
911
#include <functional>
1012
#include <map>
1113
#include <string>
1214
#include <vector>
1315

1416
#include <bench/nanobench.h>
15-
#include <boost/preprocessor/cat.hpp>
16-
#include <boost/preprocessor/stringize.hpp>
1717

1818
/*
1919
* Usage:
@@ -56,8 +56,8 @@ class BenchRunner
5656
static void RunAll(const Args& args);
5757
};
5858
}
59-
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo");
59+
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo);
6060
#define BENCHMARK(n) \
61-
benchmark::BenchRunner BOOST_PP_CAT(bench_, BOOST_PP_CAT(__LINE__, n))(BOOST_PP_STRINGIZE(n), n);
61+
benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n);
6262

6363
#endif // BITCOIN_BENCH_BENCH_H

src/blockfilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ uint64_t GCSFilter::HashToRange(const Element& element) const
2929
uint64_t hash = CSipHasher(m_params.m_siphash_k0, m_params.m_siphash_k1)
3030
.Write(element.data(), element.size())
3131
.Finalize();
32-
return MapIntoRange(hash, m_F);
32+
return FastRange64(hash, m_F);
3333
}
3434

3535
std::vector<uint64_t> GCSFilter::BuildHashedSet(const ElementSet& elements) const

src/bloom.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <script/standard.h>
1515
#include <random.h>
1616
#include <streams.h>
17+
#include <util/fastrange.h>
1718

1819
#include <math.h>
1920
#include <stdlib.h>
@@ -307,14 +308,6 @@ static inline uint32_t RollingBloomHash(unsigned int nHashNum, uint32_t nTweak,
307308
return MurmurHash3(nHashNum * 0xFBA4C795 + nTweak, vDataToHash);
308309
}
309310

310-
311-
// A replacement for x % n. This assumes that x and n are 32bit integers, and x is a uniformly random distributed 32bit value
312-
// which should be the case for a good hash.
313-
// See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
314-
static inline uint32_t FastMod(uint32_t x, size_t n) {
315-
return ((uint64_t)x * (uint64_t)n) >> 32;
316-
}
317-
318311
void CRollingBloomFilter::insert(const std::vector<unsigned char>& vKey)
319312
{
320313
if (nEntriesThisGeneration == nEntriesPerGeneration) {
@@ -339,7 +332,7 @@ void CRollingBloomFilter::insert(const std::vector<unsigned char>& vKey)
339332
uint32_t h = RollingBloomHash(n, nTweak, vKey);
340333
int bit = h & 0x3F;
341334
/* FastMod works with the upper bits of h, so it is safe to ignore that the lower bits of h are already used for bit. */
342-
uint32_t pos = FastMod(h, data.size());
335+
uint32_t pos = FastRange32(h, data.size());
343336
/* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */
344337
data[pos & ~1] = (data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit;
345338
data[pos | 1] = (data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit;
@@ -357,7 +350,7 @@ bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
357350
for (int n = 0; n < nHashFuncs; n++) {
358351
uint32_t h = RollingBloomHash(n, nTweak, vKey);
359352
int bit = h & 0x3F;
360-
uint32_t pos = FastMod(h, data.size());
353+
uint32_t pos = FastRange32(h, data.size());
361354
/* If the relevant bit is not set in either data[pos & ~1] or data[pos | 1], the filter does not contain vKey */
362355
if (!(((data[pos & ~1] | data[pos | 1]) >> bit) & 1)) {
363356
return false;

src/clientversion.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BITCOIN_CLIENTVERSION_H
66
#define BITCOIN_CLIENTVERSION_H
77

8+
#include <util/macros.h>
9+
810
#if defined(HAVE_CONFIG_H)
911
#include <config/bitcoin-config.h>
1012
#endif //HAVE_CONFIG_H
@@ -14,13 +16,6 @@
1416
#error Client version information missing: version is not defined by bitcoin-config.h or in any other way
1517
#endif
1618

17-
/**
18-
* Converts the parameter X to a string after macro replacement on X has been performed.
19-
* Don't merge these into one macro!
20-
*/
21-
#define STRINGIZE(X) DO_STRINGIZE(X)
22-
#define DO_STRINGIZE(X) #X
23-
2419
//! Copyright string used in Windows .rc files
2520
#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " The Bitcoin Core Developers, 2014-" STRINGIZE(COPYRIGHT_YEAR) " " COPYRIGHT_HOLDERS_FINAL
2621

src/coins.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
3131
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); }
3232
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
3333

34-
SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
35-
3634
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), cachedCoinsUsage(0) {}
3735

3836
size_t CCoinsViewCache::DynamicMemoryUsage() const {

src/coins.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#include <compressor.h>
1010
#include <core_memusage.h>
11-
#include <crypto/siphash.h>
1211
#include <memusage.h>
1312
#include <primitives/transaction.h>
1413
#include <serialize.h>
1514
#include <uint256.h>
15+
#include <util/hasher.h>
1616

1717
#include <assert.h>
1818
#include <stdint.h>
@@ -85,33 +85,6 @@ class Coin
8585
}
8686
};
8787

88-
class SaltedOutpointHasher
89-
{
90-
private:
91-
/** Salt */
92-
const uint64_t k0, k1;
93-
94-
public:
95-
SaltedOutpointHasher();
96-
97-
/**
98-
* This *must* return size_t. With Boost 1.46 on 32-bit systems the
99-
* unordered_map will behave unpredictably if the custom hasher returns a
100-
* uint64_t, resulting in failures when syncing the chain (#4634).
101-
*
102-
* Having the hash noexcept allows libstdc++'s unordered_map to recalculate
103-
* the hash during rehash, so it does not have to cache the value. This
104-
* reduces node's memory by sizeof(size_t). The required recalculation has
105-
* a slight performance penalty (around 1.6%), but this is compensated by
106-
* memory savings of about 9% which allow for a larger dbcache setting.
107-
*
108-
* @see https://gcc.gnu.org/onlinedocs/gcc-9.2.0/libstdc++/manual/manual/unordered_associative.html
109-
*/
110-
size_t operator()(const COutPoint& id) const noexcept {
111-
return SipHashUint256Extra(k0, k1, id.hash, id.n);
112-
}
113-
};
114-
11588
/**
11689
* A Coin in one level of the coins database caching hierarchy.
11790
*

src/cuckoocache.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BITCOIN_CUCKOOCACHE_H
66
#define BITCOIN_CUCKOOCACHE_H
77

8+
#include <util/fastrange.h>
9+
810
#include <array>
911
#include <algorithm> // std::find
1012
#include <atomic>
@@ -219,13 +221,8 @@ class cache
219221
* One option would be to implement the same trick the compiler uses and compute the
220222
* constants for exact division based on the size, as described in "{N}-bit Unsigned
221223
* Division via {N}-bit Multiply-Add" by Arch D. Robison in 2005. But that code is
222-
* somewhat complicated and the result is still slower than other options:
223-
*
224-
* Instead we treat the 32-bit random number as a Q32 fixed-point number in the range
225-
* [0, 1) and simply multiply it by the size. Then we just shift the result down by
226-
* 32-bits to get our bucket number. The result has non-uniformity the same as a
227-
* mod, but it is much faster to compute. More about this technique can be found at
228-
* http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ .
224+
* somewhat complicated and the result is still slower than an even simpler option:
225+
* see the FastRange32 function in util/fastrange.h.
229226
*
230227
* The resulting non-uniformity is also more equally distributed which would be
231228
* advantageous for something like linear probing, though it shouldn't matter
@@ -241,14 +238,14 @@ class cache
241238
*/
242239
inline std::array<uint32_t, 8> compute_hashes(const Element& e) const
243240
{
244-
return {{(uint32_t)(((uint64_t)hash_function.template operator()<0>(e) * (uint64_t)size) >> 32),
245-
(uint32_t)(((uint64_t)hash_function.template operator()<1>(e) * (uint64_t)size) >> 32),
246-
(uint32_t)(((uint64_t)hash_function.template operator()<2>(e) * (uint64_t)size) >> 32),
247-
(uint32_t)(((uint64_t)hash_function.template operator()<3>(e) * (uint64_t)size) >> 32),
248-
(uint32_t)(((uint64_t)hash_function.template operator()<4>(e) * (uint64_t)size) >> 32),
249-
(uint32_t)(((uint64_t)hash_function.template operator()<5>(e) * (uint64_t)size) >> 32),
250-
(uint32_t)(((uint64_t)hash_function.template operator()<6>(e) * (uint64_t)size) >> 32),
251-
(uint32_t)(((uint64_t)hash_function.template operator()<7>(e) * (uint64_t)size) >> 32)}};
241+
return {{FastRange32(hash_function.template operator()<0>(e), size),
242+
FastRange32(hash_function.template operator()<1>(e), size),
243+
FastRange32(hash_function.template operator()<2>(e), size),
244+
FastRange32(hash_function.template operator()<3>(e), size),
245+
FastRange32(hash_function.template operator()<4>(e), size),
246+
FastRange32(hash_function.template operator()<5>(e), size),
247+
FastRange32(hash_function.template operator()<6>(e), size),
248+
FastRange32(hash_function.template operator()<7>(e), size)}};
252249
}
253250

254251
/** invalid returns a special index that can never be inserted to

src/index/base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <shutdown.h>
99
#include <tinyformat.h>
1010
#include <ui_interface.h>
11+
#include <util/thread.h>
1112
#include <util/translation.h>
1213
#include <validation.h> // For g_chainman
1314
#include <warnings.h>
@@ -353,8 +354,7 @@ bool BaseIndex::Start(CChainState& active_chainstate)
353354
return false;
354355
}
355356

356-
m_thread_sync = std::thread(&TraceThread<std::function<void()>>, GetName(),
357-
std::bind(&BaseIndex::ThreadSync, this));
357+
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { ThreadSync(); });
358358
return true;
359359
}
360360

0 commit comments

Comments
 (0)