/* XMRig * Copyright 2010 Jeff Garzik * Copyright 2012-2014 pooler * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2016-2017 XMRig * * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include "crypto/CryptoNight.h" #include "Mem.h" bool Mem::m_useHugePages = true; size_t Mem::m_hashFactor = 1; int Mem::m_flags = 0; Options::Algo Mem::m_algo = Options::ALGO_CRYPTONIGHT; Mem::ThreadBitSet Mem::m_multiHashThreadMask = Mem::ThreadBitSet(-1L); ScratchPadMem Mem::create(ScratchPad** scratchPads, int threadId) { size_t scratchPadSize; switch (m_algo) { case Options::ALGO_CRYPTONIGHT_LITE: scratchPadSize = MEMORY_LITE; break; case Options::ALGO_CRYPTONIGHT_HEAVY: scratchPadSize = MEMORY_HEAVY; break; case Options::ALGO_CRYPTONIGHT: default: scratchPadSize = MEMORY; break; } ScratchPadMem scratchPadMem; scratchPadMem.realSize = scratchPadSize * getThreadHashFactor(threadId); scratchPadMem.size = scratchPadSize * getThreadHashFactor(threadId); scratchPadMem.size += scratchPadMem.size % MEMORY; scratchPadMem.pages = scratchPadMem.size / MEMORY; allocate(scratchPadMem, m_useHugePages); for (size_t i = 0; i < getThreadHashFactor(threadId); ++i) { ScratchPad* scratchPad = static_cast(_mm_malloc(sizeof(ScratchPad), 4096)); scratchPad->memory = scratchPadMem.memory + (i * scratchPadSize); scratchPads[i] = scratchPad; } return scratchPadMem; } void Mem::release(ScratchPad** scratchPads, ScratchPadMem& scratchPadMem, int threadId) { release(scratchPadMem); for (size_t i = 0; i < getThreadHashFactor(threadId); ++i) { _mm_free(scratchPads[i]); } }