Browse Source

Remove some CPU DAG management code

We don't have CPU mining anyway...
cl-refactor
Paweł Bylica 8 years ago
parent
commit
d4ec491cda
No known key found for this signature in database GPG Key ID: 7A0C037434FE77EF
  1. 89
      libethcore/EthashAux.cpp
  2. 15
      libethcore/EthashAux.h

89
libethcore/EthashAux.cpp

@ -44,15 +44,12 @@ const char* DAGChannel::name() { return EthGreen "DAG"; }
EthashAux* dev::eth::EthashAux::s_this = nullptr;
char dev::eth::EthashAux::s_dagDirName[256] = "";
dev::eth::DAGEraseMode dev::eth::EthashAux::s_dagEraseMode = DAGEraseMode::None;
const unsigned EthashProofOfWork::defaultLocalWorkSize = 64;
const unsigned EthashProofOfWork::defaultGlobalWorkSizeMultiplier = 4096; // * CL_DEFAULT_LOCAL_WORK_SIZE
const unsigned EthashProofOfWork::defaultMSPerBatch = 0;
const EthashProofOfWork::WorkPackage EthashProofOfWork::NullWorkPackage = EthashProofOfWork::WorkPackage();
//unsigned EthashProofOfWork::s_dagLoadMode = 0;
EthashAux::~EthashAux()
{
}
@ -64,82 +61,11 @@ EthashAux* EthashAux::get()
return s_this;
}
uint64_t EthashAux::cacheSize(BlockInfo const& _header)
{
return ethash_get_cachesize((uint64_t)_header.number());
}
uint64_t EthashAux::dataSize(uint64_t _blockNumber)
{
return ethash_get_datasize(_blockNumber);
}
void EthashAux::setDAGDirName(const char * custom_dir_name)
{
char strbuf[256];
if (strcmp(custom_dir_name, "") != 0)
strcpy(strbuf, custom_dir_name);
else
ethash_get_default_dirname(strbuf, 256);
strcpy(s_dagDirName, strbuf);
}
char * EthashAux::dagDirName()
{
return s_dagDirName;
}
void EthashAux::setDAGEraseMode(DAGEraseMode mode)
{
s_dagEraseMode = mode;
}
void EthashAux::eraseDAGs()
{
if (s_dagEraseMode == DAGEraseMode::None) return;
path p(s_dagDirName);
if (!is_directory(p))
{
cnote << "Can't clean up DAG directory:" << s_dagDirName << "does not exist (yet).";
return;
}
vector<path> files;
directory_iterator end_itr;
for (directory_iterator itr(p); itr != end_itr; ++itr)
{
if (is_regular_file(itr->path())) {
files.push_back(itr->path());
}
}
std::sort(files.begin(), files.end(),
[](const path& p1, const path& p2)
{
return file_size(p1) < file_size(p2);
});
size_t dagcount = files.size();
size_t dagcounter = 0;
for (std::vector<path>::const_iterator path = files.begin(); path != files.end(); ++path)
{
if (s_dagEraseMode == DAGEraseMode::Bench && path->filename() == "full-R23-0000000000000000") {}
else if ((s_dagEraseMode == DAGEraseMode::Old || s_dagEraseMode == DAGEraseMode::Bench) && dagcount - dagcounter <= 2) {}
else
{
cnote << "Deleting DAG file " << path->string();
remove(*path);
}
dagcounter++;
}
}
h256 EthashAux::seedHash(unsigned _number)
{
unsigned epoch = _number / ETHASH_EPOCH_LENGTH;
@ -185,12 +111,6 @@ uint64_t EthashAux::number(h256 const& _seedHash)
return epoch * ETHASH_EPOCH_LENGTH;
}
void EthashAux::killCache(h256 const& _s)
{
WriteGuard l(x_lights);
m_lights.erase(_s);
}
EthashAux::LightType EthashAux::light(h256 const& _seedHash)
{
UpgradableGuard l(get()->x_lights);
@ -255,20 +175,15 @@ EthashAux::FullType EthashAux::full(h256 const& _seedHash, bool _createIfMissing
DEV_GUARDED(get()->x_fulls)
if ((ret = get()->m_fulls[_seedHash].lock()))
{
get()->m_lastUsedFull = ret;
return ret;
}
if (_createIfMissing || computeFull(_seedHash, false) == 100)
{
s_dagCallback = _f;
// cnote << "Loading from libethash...";
ret = make_shared<FullAllocation>(l->light, dagCallbackShim);
// cnote << "Done loading.";
DEV_GUARDED(get()->x_fulls)
get()->m_fulls[_seedHash] = get()->m_lastUsedFull = ret;
get()->m_fulls[_seedHash] = ret;
}
return ret;
@ -286,7 +201,6 @@ unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing)
if (FullType ret = get()->m_fulls[_seedHash].lock())
{
get()->m_lastUsedFull = ret;
return 100;
}
@ -297,7 +211,6 @@ unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing)
get()->m_fullGenerator = unique_ptr<thread>(new thread([=](){
cnote << "Loading full DAG of seedhash: " << _seedHash;
get()->full(_seedHash, true, [](unsigned p){ get()->m_fullProgress = p; return 0; });
eraseDAGs();
cnote << "Full DAG loaded";
get()->m_fullProgress = 0;
get()->m_generatingFullNumber = NotGenerating;

15
libethcore/EthashAux.h

@ -65,7 +65,7 @@ struct EthashProofOfWork
h256 headerHash; ///< When h256() means "pause until notified a new work package is available".
h256 seedHash;
uint64_t startNonce = 0;
uint64_t startNonce = 0;
int exSizeBits = -1;
};
@ -120,14 +120,8 @@ public:
static h256 seedHash(unsigned _number);
static uint64_t number(h256 const& _seedHash);
static uint64_t cacheSize(BlockInfo const& _header);
static uint64_t dataSize(uint64_t _blockNumber);
static void setDAGDirName(const char * custom_dir_name);
static char * dagDirName();
static void setDAGEraseMode(DAGEraseMode mode);
static void eraseDAGs();
static LightType light(h256 const& _seedHash);
static const uint64_t NotGenerating = (uint64_t)-1;
@ -145,21 +139,14 @@ public:
private:
EthashAux() {}
/// Kicks off generation of DAG for @a _blocknumber and blocks until ready; @returns result.
void killCache(h256 const& _s);
static EthashAux* s_this;
static char s_dagDirName[256];
static DAGEraseMode s_dagEraseMode;
SharedMutex x_lights;
std::unordered_map<h256, std::shared_ptr<LightAllocation>> m_lights;
Mutex x_fulls;
std::condition_variable m_fullsChanged;
std::unordered_map<h256, std::weak_ptr<FullAllocation>> m_fulls;
FullType m_lastUsedFull;
std::unique_ptr<std::thread> m_fullGenerator;
uint64_t m_generatingFullNumber = NotGenerating;
unsigned m_fullProgress;

Loading…
Cancel
Save