Merge pull request #5 from bogdanadnan/dev

Dev
This commit is contained in:
bogdanadnan 2019-08-28 00:58:18 +03:00 committed by GitHub
commit dfb9b2c4f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 198 additions and 39 deletions

17
hiveos/h-config.sh Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
[[ -z $CUSTOM_TEMPLATE ]] && echo -e "${YELLOW}CUSTOM_TEMPLATE is empty${NOCOLOR}" && return 1
[[ -z $CUSTOM_URL ]] && echo -e "${YELLOW}CUSTOM_URL is empty${NOCOLOR}" && return 1
conf="-o ${CUSTOM_URL} -u ${CUSTOM_TEMPLATE} -p $WORKER_NAME --api-port ${CUSTOM_API_PORT} ${CUSTOM_USER_CONFIG}"
#replace tpl values in whole file
[[ ! -z $EWAL ]] && conf=$(sed "s/%EWAL%/$EWAL/g" <<< "$conf")
[[ ! -z $DWAL ]] && conf=$(sed "s/%DWAL%/$DWAL/g" <<< "$conf")
[[ ! -z $ZWAL ]] && conf=$(sed "s/%ZWAL%/$ZWAL/g" <<< "$conf")
[[ ! -z $EMAIL ]] && conf=$(sed "s/%EMAIL%/$EMAIL/g" <<< "$conf")
[[ ! -z $WORKER_NAME ]] && conf=$(sed "s/%WORKER_NAME%/$WORKER_NAME/g" <<< "$conf")
echo "$conf" > $MINER_DIR/$CUSTOM_MINER/$CUSTOM_NAME.conf

20
hiveos/h-manifest.conf Normal file
View file

@ -0,0 +1,20 @@
#
# NinjaRig by Haifa Bogdan Adnan
#
# GitHub src: https://github.com/bogdanadnan/ninjarig
#
# HiveOS adaptation by Haifa Bogdan Adnan
#
CUSTOM_NAME=ninjarig
CUSTOM_VERSION=1.0.0
CUSTOM_CONFIG_FILENAME=/hive/miners/custom/${CUSTOM_NAME}/${CUSTOM_NAME}.conf
CUSTOM_LOG_BASENAME=/var/log/miner/$CUSTOM_NAME/$CUSTOM_NAME
CUSTOM_LOG_FOLDER=/var/log/miner/$CUSTOM_NAME
CUSTOM_API_PORT=10000

20
hiveos/h-run.sh Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
. h-manifest.conf
CUSTOM_API_PORT=`./parse-api-port.sh`
#try to release TIME_WAIT sockets
while true; do
for con in `netstat -anp | grep TIME_WAIT | grep ${CUSTOM_API_PORT} | awk '{print $5}'`; do
killcx $con lo
done
netstat -anp | grep TIME_WAIT | grep ${CUSTOM_API_PORT} &&
continue ||
break
done
mkdir -p $CUSTOM_LOG_FOLDER
echo -e "Running ${CYAN}iximiner${NOCOLOR}" | tee ${CUSTOM_LOG_FOLDER}/${CUSTOM_NAME}.log
./ninjarig $(< $CUSTOM_NAME.conf)$@ 2>&1 | tee ${CUSTOM_LOG_FOLDER}/${CUSTOM_NAME}.log

59
hiveos/h-stats.sh Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env bash
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
. $MINER_DIR/$CUSTOM_MINER/parse-api-port.sh
json_data=`curl -s http://localhost:${CUSTOM_API_PORT}`
algo=`echo $json_data | jq -c ".algo" | sed 's/"//g'`
hashrates=`echo $json_data | jq -c ".hashers[].hashrate[0]"`
shares=`echo $json_data | jq -c ".results.shares_good"`
totalShares=`echo $json_data | jq -c ".results.shares_total"`
total_hashrate=`echo $json_data | jq -c ".hashrate.total[0]"`
total_hashrate=`echo $total_hashrate/1000 | jq -nf /dev/stdin`
rejects=$((totalShares-shares))
gpu_data=`gpu-stats`
busids_data=`echo $gpu_data | jq -r ".busids[]"`
busids=($busids_data)
temp_data=`echo $gpu_data | jq -r ".temp[]"`
temp_local=($temp_data)
fan_data=`echo $gpu_data | jq -r ".fan[]"`
fan_local=($fan_data)
device_bus_data=`echo $json_data | jq -c ".hashers[].bus_id"`
device_bus=($device_bus_data)
stats_temp=""
stats_fan=""
bus_numbers=""
for i in "${!device_bus[@]}"; do
found=0
for j in "${!busids[@]}"; do
if [ "${device_bus[$i],,}" == "\"${busids[$j],,}\"" ]; then
stats_temp="$stats_temp ${temp_local[$j]}"
stats_fan="$stats_fan ${fan_local[$j]}"
bus_number=$(echo ${busids[$j]} | cut -d ':' -f 1 | awk '{printf("%d\n", "0x"$1)}')
bus_numbers="$bus_numbers $bus_number"
found=1
break
fi
done
if [ $found -eq 0 ]; then
stats_temp="$stats_temp 0"
stats_fan="$stats_fan 0"
bus_numbers="$bus_numbers 0"
fi
done
khs=$total_hashrate
hashrates=$hashrates
stats=$(jq -nc \
--argjson hashrates "`echo "$hashrates" | tr " " "\n" | jq -cs '.'`" \
--argjson hs "`echo "$hashrates" | tr " " "\n" | jq -cs '.'`" \
--arg hs_units "hs" \
--argjson temp "`echo "$stats_temp" | tr " " "\n" | jq -cs '.'`" \
--argjson fan "`echo "$stats_fan" | tr " " "\n" | jq -cs '.'`" \
--arg ac "$shares" --arg rj "$rejects" \
--argjson bus_numbers "`echo "$bus_numbers" | tr " " "\n" | jq -cs '.'`" \
--arg algo $algo \
'{$hashrates, $hs, $hs_units, $temp, $fan, ar: [$ac, $rj], $bus_numbers, $algo}')

31
hiveos/parse-api-port.sh Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
if [ -z "$MINER_DIR" ]
then
. ./h-manifest.conf
args=$(getopt -q -u -l "api-port:" -o "l:" -- `cat ./$CUSTOM_NAME.conf`)
else
. $MINER_DIR/$CUSTOM_MINER/h-manifest.conf
args=$(getopt -q -u -l "api-port:" -o "l:" -- `cat $MINER_DIR/$CUSTOM_MINER/$CUSTOM_NAME.conf`)
fi
eval set -- "$args"
while [ $# -ge 1 ]; do
case "$1" in
--)
shift
break
;;
--api-port)
CUSTOM_API_PORT="$2"
shift
;;
esac
shift
done
if [ -z "$MINER_DIR" ]
then
echo $CUSTOM_API_PORT
fi

View file

@ -59,7 +59,7 @@ rapidjson::Value ApiRouter::normalize(double d)
return Value(kNullType);
}
return Value(floor(d * 100.0) / 100.0);
return Value((int)floor(d));
}
@ -93,16 +93,11 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
return finalize(reply, doc);
}
if (req.match("/1/threads")) {
getThreads(doc);
return finalize(reply, doc);
}
doc.SetObject();
getIdentify(doc);
getMiner(doc);
getThreads(doc);
getHashrate(doc);
getResults(doc);
getConnection(doc);
@ -208,7 +203,6 @@ void ApiRouter::getHashrate(rapidjson::Document &doc) const
rapidjson::Value hashrate(rapidjson::kObjectType);
rapidjson::Value total(rapidjson::kArrayType);
rapidjson::Value threads(rapidjson::kArrayType);
const Hashrate *hr = Workers::hashrate();
@ -216,21 +210,8 @@ void ApiRouter::getHashrate(rapidjson::Document &doc) const
total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
vector<Handle *> workers = Workers::workers();
for (size_t i = 0; i < workers.size(); i++) {
for(size_t j = 0; j < workers[i]->hasher()->deviceCount(); j++) {
rapidjson::Value thread(rapidjson::kArrayType);
thread.PushBack(normalize(hr->calc(i, j, Hashrate::ShortInterval)), allocator);
thread.PushBack(normalize(hr->calc(i, j, Hashrate::MediumInterval)), allocator);
thread.PushBack(normalize(hr->calc(i, j, Hashrate::LargeInterval)), allocator);
threads.PushBack(thread, allocator);
}
}
hashrate.AddMember("total", total, allocator);
hashrate.AddMember("highest", normalize(hr->highest()), allocator);
hashrate.AddMember("threads", threads, allocator);
doc.AddMember("hashrate", hashrate, allocator);
}
@ -281,9 +262,6 @@ void ApiRouter::getResults(rapidjson::Document &doc) const
void ApiRouter::getThreads(rapidjson::Document &doc) const
{
doc.SetObject();
auto &allocator = doc.GetAllocator();
Workers::hashersSummary(doc);
}

View file

@ -28,6 +28,7 @@ public:
virtual int compute(int threadIdx, uint8_t *input, size_t size, uint8_t *output) = 0;
virtual size_t parallelism(int workerIdx) = 0;
virtual size_t deviceCount() = 0;
virtual DeviceInfo &device(int workerIdx) = 0;
string type();
string subType(bool shortName = false);

View file

@ -224,4 +224,8 @@ size_t CpuHasher::deviceCount() {
return computingThreads();
}
DeviceInfo &CpuHasher::device(int workerIdx) {
return devices()[0];
}
REGISTER_HASHER(CpuHasher);

View file

@ -22,6 +22,7 @@ public:
virtual int compute(int threadIdx, uint8_t *input, size_t size, uint8_t *output);
virtual size_t parallelism(int workerIdx);
virtual size_t deviceCount();
virtual DeviceInfo &device(int workerIdx);
private:
string detectFeaturesAndMakeDescription();

View file

@ -119,7 +119,8 @@ CudaDeviceInfo *CudaHasher::getDeviceInfo(int device_index) {
}
bool CudaHasher::configure(xmrig::HasherConfig &config) {
int index = config.getGPUCardsCount();
int deviceOffset = config.getGPUCardsCount();
int index = deviceOffset;
double intensity = 0;
int total_threads = 0;
@ -165,7 +166,7 @@ bool CudaHasher::configure(xmrig::HasherConfig &config) {
ss << endl;
double device_intensity = config.getGPUIntensity((*d)->deviceIndex);
double device_intensity = config.getGPUIntensity(deviceOffset + m_enabledDevices.size());
m_description += ss.str();
@ -335,6 +336,15 @@ size_t CudaHasher::deviceCount() {
return m_enabledDevices.size();
}
DeviceInfo &CudaHasher::device(int workerIdx) {
workerIdx /= 2;
if(workerIdx < 0 || workerIdx > m_enabledDevices.size())
return devices().begin()->second;
return devices()[m_enabledDevices[workerIdx]->deviceIndex];
}
REGISTER_HASHER(CudaHasher);
#endif //WITH_CUDA

View file

@ -99,6 +99,7 @@ public:
virtual int compute(int threadIdx, uint8_t *input, size_t size, uint8_t *output);
virtual size_t parallelism(int workerIdx);
virtual size_t deviceCount();
virtual DeviceInfo &device(int workerIdx);
private:
CudaDeviceInfo *getDeviceInfo(int device_index);

View file

@ -217,7 +217,8 @@ OpenCLDeviceInfo *OpenCLHasher::getDeviceInfo(cl_platform_id platform, cl_device
}
bool OpenCLHasher::configure(xmrig::HasherConfig &config) {
int index = config.getGPUCardsCount();
int deviceOffset = config.getGPUCardsCount();
int index = deviceOffset;
double intensity = 0;
int total_threads = 0;
@ -264,7 +265,7 @@ bool OpenCLHasher::configure(xmrig::HasherConfig &config) {
ss << endl;
double device_intensity = config.getGPUIntensity((*d)->deviceIndex);
double device_intensity = config.getGPUIntensity(deviceOffset + m_enabledDevices.size());
m_description += ss.str();
@ -307,7 +308,7 @@ bool OpenCLHasher::configure(xmrig::HasherConfig &config) {
intensity += device_intensity;
}
config.addGPUCardsCount(index - config.getGPUCardsCount());
config.addGPUCardsCount(index - deviceOffset);
if(!cards_selected) {
m_intensity = 0;
@ -883,6 +884,15 @@ size_t OpenCLHasher::deviceCount() {
return m_enabledDevices.size();
}
DeviceInfo &OpenCLHasher::device(int workerIdx) {
workerIdx /= 2;
if(workerIdx < 0 || workerIdx > m_enabledDevices.size())
return devices().begin()->second;
return devices()[m_enabledDevices[workerIdx]->deviceIndex];
}
REGISTER_HASHER(OpenCLHasher);
#endif // WITH_OPENCL

View file

@ -91,6 +91,7 @@ public:
virtual int compute(int threadIdx, uint8_t *input, size_t size, uint8_t *output);
virtual size_t parallelism(int workerIdx);
virtual size_t deviceCount();
virtual DeviceInfo &device(int workerIdx);
private:
OpenCLDeviceInfo *getDeviceInfo(cl_platform_id platform, cl_device_id device);

View file

@ -27,7 +27,7 @@ string OpenCLKernel = R"OCL(
#define OUT_BYTES 16
#define G(m, r, i, a, b, c, d) \
do { \
{ \
a = a + b + m[blake2b_sigma[r][2 * i + 0]]; \
d = rotr64(d ^ a, 32); \
c = c + d; \
@ -36,10 +36,10 @@ do { \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \
} while ((void)0, 0)
}
#define G_S(m, a, b, c, d) \
do { \
{ \
a = a + b + m; \
d = rotr64(d ^ a, 32); \
c = c + d; \
@ -48,10 +48,10 @@ do { \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \
} while ((void)0, 0)
}
#define ROUND(m, t, r, shfl) \
do { \
{ \
G(m, r, t, v0, v1, v2, v3); \
shfl[t + 4] = v1; \
shfl[t + 8] = v2; \
@ -68,10 +68,10 @@ do { \
v1 = shfl[t + 4]; \
v2 = shfl[t + 8]; \
v3 = shfl[t + 12]; \
} while ((void)0, 0)
}
#define ROUND_S(m, t, shfl) \
do { \
{ \
G_S(m, v0, v1, v2, v3); \
shfl[t + 4] = v1; \
shfl[t + 8] = v2; \
@ -88,7 +88,7 @@ do { \
v1 = shfl[t + 4]; \
v2 = shfl[t + 8]; \
v3 = shfl[t + 12]; \
} while ((void)0, 0)
}
ulong rotr64(ulong x, ulong n)
{

View file

@ -174,8 +174,8 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, Va
switch(variant) {
case VARIANT_CHUKWA:
algoEntry = "turtle";
devPool = "pool.turtle.hashvault.pro";
devPort = 3333;
devPool = "trtl.muxdux.com";
devPort = 5555;
devUser = "TRTLuxUdNNphJcrVfH27HMZumtFuJrmHG8B5ky3tzuAcZk7UcEdis2dAQbaQ2aVVGnGEqPtvDhMgWjZdfq8HenxKPEkrR43K618";
devPassword = m_devId;
break;

View file

@ -228,12 +228,18 @@ void Workers::hashersSummary(rapidjson::Document &doc)
Handle *worker = m_workers[i];
for(int j=0; j < worker->hasher()->deviceCount(); j++) {
rapidjson::Value hasherDoc(rapidjson::kObjectType);
int multiplier = worker->hasher()->computingThreads() / worker->hasher()->deviceCount();
xmrig::String type = worker->hasher()->type().data();
xmrig::String id = (worker->hasher()->subType(true) + to_string(j)).data();
DeviceInfo &deviceInfo = worker->hasher()->device(j * multiplier);
xmrig::String device = deviceInfo.name.data();
xmrig::String busId = deviceInfo.bus_id.data();
hasherDoc.AddMember("type", type.toJSON(doc), allocator);
hasherDoc.AddMember("id", id.toJSON(doc), allocator);
hasherDoc.AddMember("device", device.toJSON(doc), allocator);
hasherDoc.AddMember("bus_id", busId.toJSON(doc), allocator);
rapidjson::Value hashrateEntry(rapidjson::kArrayType);
hashrateEntry.PushBack(ApiRouter::normalize(m_hashrate->calc(i, j, Hashrate::ShortInterval)), allocator);