Skip to content

Commit

Permalink
Merge 9245 via ionice
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Jul 30, 2018
3 parents 52dfb47 + 8b25097 + 250ed07 commit 3400eeb
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 10 deletions.
40 changes: 40 additions & 0 deletions configure.ac
Expand Up @@ -659,6 +659,44 @@ AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,


AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll]) 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 dnl Check for MSG_NOSIGNAL
AC_MSG_CHECKING(for MSG_NOSIGNAL) AC_MSG_CHECKING(for MSG_NOSIGNAL)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
Expand Down Expand Up @@ -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_LIBEVENT], [test x$use_libevent = xyes])
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes]) AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = 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([HARDEN],[test x$use_hardening = xyes])
AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes]) AM_CONDITIONAL([ENABLE_HWCRC32],[test x$enable_hwcrc32 = xyes])
AM_CONDITIONAL([USE_ASM],[test x$use_asm = xyes]) AM_CONDITIONAL([USE_ASM],[test x$use_asm = xyes])
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -161,6 +161,7 @@ BITCOIN_CORE_H = \
ui_interface.h \ ui_interface.h \
undo.h \ undo.h \
util.h \ util.h \
utilioprio.h \
utilmoneystr.h \ utilmoneystr.h \
utiltime.h \ utiltime.h \
validation.h \ validation.h \
Expand Down Expand Up @@ -372,6 +373,7 @@ libbitcoin_util_a_SOURCES = \
sync.cpp \ sync.cpp \
threadinterrupt.cpp \ threadinterrupt.cpp \
util.cpp \ util.cpp \
utilioprio.cpp \
utilmoneystr.cpp \ utilmoneystr.cpp \
utilstrencodings.cpp \ utilstrencodings.cpp \
utiltime.cpp \ utiltime.cpp \
Expand Down
7 changes: 4 additions & 3 deletions src/net_processing.cpp
Expand Up @@ -1114,8 +1114,9 @@ void static ProcessGetBlockData(CNode* pfrom, const Consensus::Params& consensus
} else { } else {
// Send block from disk // Send block from disk
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>(); 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"); assert(!"cannot load block from disk");
}
pblock = pblockRead; pblock = pblockRead;
} }
if (inv.type == MSG_BLOCK) if (inv.type == MSG_BLOCK)
Expand Down Expand Up @@ -2035,7 +2036,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
} }


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


SendBlockTransactions(block, req, pfrom, connman); SendBlockTransactions(block, req, pfrom, connman);
Expand Down Expand Up @@ -3359,7 +3360,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
} }
if (!fGotBlockFromCache) { if (!fGotBlockFromCache) {
CBlock block; CBlock block;
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams); bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams, true);
assert(ret); assert(ret);
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness); CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock)); connman->PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
Expand Down
57 changes: 57 additions & 0 deletions src/utilioprio.cpp
@@ -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
57 changes: 57 additions & 0 deletions src/utilioprio.h
@@ -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
16 changes: 11 additions & 5 deletions src/validation.cpp
Expand Up @@ -35,6 +35,7 @@
#include <ui_interface.h> #include <ui_interface.h>
#include <undo.h> #include <undo.h>
#include <util.h> #include <util.h>
#include <utilioprio.h>
#include <utilmoneystr.h> #include <utilmoneystr.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <validationinterface.h> #include <validationinterface.h>
Expand Down Expand Up @@ -1104,10 +1105,13 @@ static bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMes
return true; 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(); block.SetNull();


{
IOPRIO_IDLER(lowprio);

// Open history file to read // Open history file to read
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION); CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull()) if (filein.IsNull())
Expand All @@ -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()); return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
} }


} // end IOPRIO_IDLER scope

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


return true; 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; CDiskBlockPos blockPos;
{ {
LOCK(cs_main); LOCK(cs_main);
blockPos = pindex->GetBlockPos(); blockPos = pindex->GetBlockPos();
} }


if (!ReadBlockFromDisk(block, blockPos, consensusParams)) if (!ReadBlockFromDisk(block, blockPos, consensusParams, lowprio))
return false; return false;
if (block.GetHash() != pindex->GetBlockHash()) if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
Expand Down Expand Up @@ -3891,7 +3897,7 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
} }
CBlock block; CBlock block;
// check level 0: read from disk // 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()); return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
// check level 1: verify block validity // check level 1: verify block validity
if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus())) if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus()))
Expand Down Expand Up @@ -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); 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); pindex = chainActive.Next(pindex);
CBlock block; 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()); return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!g_chainstate.ConnectBlock(block, state, pindex, coins, chainparams)) if (!g_chainstate.ConnectBlock(block, state, pindex, coins, chainparams))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
Expand Down
4 changes: 2 additions & 2 deletions src/validation.h
Expand Up @@ -396,8 +396,8 @@ void InitScriptExecutionCache();




/** Functions for disk access for blocks */ /** Functions for disk access for blocks */
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, 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 ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool lowprio = false);


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


Expand Down

0 comments on commit 3400eeb

Please sign in to comment.