Skip to content
Permalink
Browse files

Merge 9245 via ionice

  • Loading branch information...
luke-jr committed Jul 30, 2018
3 parents 52dfb47 + 8b25097 + 250ed07 commit 3400eeb80d5b4d9c5ba3aa134c28700c996e8fa9
Showing with 173 additions and 10 deletions.
  1. +40 −0 configure.ac
  2. +2 −0 src/Makefile.am
  3. +4 −3 src/net_processing.cpp
  4. +57 −0 src/utilioprio.cpp
  5. +57 −0 src/utilioprio.h
  6. +11 −5 src/validation.cpp
  7. +2 −2 src/validation.h
@@ -659,6 +659,44 @@ AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,

AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll])

AC_MSG_CHECKING(for iopolicy functions)
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <sys/resource.h>
]],[[
int x = getiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD);
setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, x);
]])
],[
have_iopolicy=yes
AC_DEFINE(HAVE_IOPOLICY,1,[Define this symbol if you have iopolicy functions])
],[
have_iopolicy=no
])
AC_MSG_RESULT($have_iopolicy)

if test x$have_iopolicy = xno; then
AC_MSG_CHECKING(for ioprio syscalls)
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
]],[[
int x = syscall(SYS_ioprio_get, 1, 0);
syscall(SYS_ioprio_set, 1, 0, x);
]])
],[
have_ioprio_syscall=yes
AC_DEFINE(HAVE_IOPRIO_SYSCALL,1,[Define this symbol if you have ioprio syscalls])
],[
have_ioprio_syscall=no
])
AC_MSG_RESULT($have_ioprio_syscall)
else
have_ioprio_syscall=no
fi

dnl Check for MSG_NOSIGNAL
AC_MSG_CHECKING(for MSG_NOSIGNAL)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
@@ -1401,6 +1439,8 @@ AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
AM_CONDITIONAL([USE_LIBEVENT], [test x$use_libevent = xyes])
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
AM_CONDITIONAL([HAVE_IOPOLICY],[test x$have_iopolicy = xyes])
AM_CONDITIONAL([HAVE_IOPRIO_SYSCALL],[test x$have_ioprio_syscall = xyes])
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
AM_CONDITIONAL([USE_ASM],[test x$use_asm = xyes])
@@ -161,6 +161,7 @@ BITCOIN_CORE_H = \
ui_interface.h \
undo.h \
util.h \
utilioprio.h \
utilmoneystr.h \
utiltime.h \
validation.h \
@@ -372,6 +373,7 @@ libbitcoin_util_a_SOURCES = \
sync.cpp \
threadinterrupt.cpp \
util.cpp \
utilioprio.cpp \
utilmoneystr.cpp \
utilstrencodings.cpp \
utiltime.cpp \
@@ -1114,8 +1114,9 @@ void static ProcessGetBlockData(CNode* pfrom, const Consensus::Params& consensus
} else {
// Send block from disk
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>();
if (!ReadBlockFromDisk(*pblockRead, (*mi).second, consensusParams))
if (!ReadBlockFromDisk(*pblockRead, (*mi).second, consensusParams, true)) {
assert(!"cannot load block from disk");
}
pblock = pblockRead;
}
if (inv.type == MSG_BLOCK)
@@ -2035,7 +2036,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
}

CBlock block;
bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus());
bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus(), true);
assert(ret);

SendBlockTransactions(block, req, pfrom, connman);
@@ -3359,7 +3360,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
}
if (!fGotBlockFromCache) {
CBlock block;
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams, true);
assert(ret);
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
@@ -0,0 +1,57 @@
// Copyright (c) 2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#include <utilioprio.h>

#ifdef HAVE_IOPRIO_SYSCALL

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#include <sys/syscall.h>

#ifndef IOPRIO_WHO_PROCESS
#define IOPRIO_WHO_PROCESS 1
#endif
#ifndef IOPRIO_CLASS_IDLE
#define IOPRIO_CLASS_IDLE 3
#endif
#ifndef IOPRIO_CLASS_SHIFT
#define IOPRIO_CLASS_SHIFT 13
#endif

int ioprio_get() {
return syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, 0);
}

int ioprio_set(const int ioprio) {
return syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, ioprio);
}

int ioprio_set_idle() {
return ioprio_set(7 | (IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT));
}

#elif HAVE_IOPOLICY

#include <sys/resource.h>

int ioprio_get() {
return getiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD);
}

int ioprio_set(const int ioprio) {
return setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, ioprio);
}

int ioprio_set_idle() {
return ioprio_set(IOPOL_UTILITY);
}

#endif
@@ -0,0 +1,57 @@
// Copyright (c) 2016 Satoshi Nakamoto
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_UTIL_IOPRIO_H
#define BITCOIN_UTIL_IOPRIO_H

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

#include <util.h>

#if defined(HAVE_IOPRIO_SYSCALL) || defined(HAVE_IOPOLICY)
int ioprio_get();
int ioprio_set(int ioprio);
int ioprio_set_idle();

class ioprio_idler {
private:
int orig;

public:
ioprio_idler(const bool actually_idle) {
if (!actually_idle) {
orig = -1;
return;
}

orig = ioprio_get();
if (orig == -1) {
return;
}
if (ioprio_set_idle() == -1) {
orig = -1;
}
}

~ioprio_idler() {
if (orig == -1) {
return;
}
if (ioprio_set(orig) == -1) {
LogPrintf("failed to restore ioprio\n");
}
}
};
#define IOPRIO_IDLER(actually_idle) ioprio_idler ioprio_idler_(actually_idle)

#else
#define ioprio_get() ((void)-1)
#define ioprio_set(ioprio) ((void)-1)
#define ioprio_set_idle() ((void)-1)
#define IOPRIO_IDLER(actually_idle) (void)actually_idle;
#endif

#endif // BITCOIN_UTIL_IOPRIO_H
@@ -35,6 +35,7 @@
#include <ui_interface.h>
#include <undo.h>
#include <util.h>
#include <utilioprio.h>
#include <utilmoneystr.h>
#include <utilstrencodings.h>
#include <validationinterface.h>
@@ -1104,10 +1105,13 @@ static bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMes
return true;
}

bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams)
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, const bool lowprio)
{
block.SetNull();

{
IOPRIO_IDLER(lowprio);

// Open history file to read
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
@@ -1121,22 +1125,24 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus:
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
}

} // end IOPRIO_IDLER scope

// Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());

return true;
}

bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, const bool lowprio)
{
CDiskBlockPos blockPos;
{
LOCK(cs_main);
blockPos = pindex->GetBlockPos();
}

if (!ReadBlockFromDisk(block, blockPos, consensusParams))
if (!ReadBlockFromDisk(block, blockPos, consensusParams, lowprio))
return false;
if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
@@ -3891,7 +3897,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
}
CBlock block;
// check level 0: read from disk
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus(), true))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
// check level 1: verify block validity
if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus()))
@@ -3935,7 +3941,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))), false);
pindex = chainActive.Next(pindex);
CBlock block;
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus(), true))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!g_chainstate.ConnectBlock(block, state, pindex, coins, chainparams))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
@@ -396,8 +396,8 @@ void InitScriptExecutionCache();


/** Functions for disk access for blocks */
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, bool lowprio = false);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool lowprio = false);

/** Functions for validating blocks and updating the block tree */

0 comments on commit 3400eeb

Please sign in to comment.
You can’t perform that action at this time.