From ba48d4482e614e990cb4bdc17601fd00869b0f44 Mon Sep 17 00:00:00 2001 From: Warlock-Dalbaeb Date: Wed, 9 Aug 2017 16:55:08 +0700 Subject: [PATCH] affinity --- vanity.hpp | 48 +++++++++++++++++++++++++++++++++ vanitygen.cpp | 73 +++++++++++++++++++++++---------------------------- 2 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 vanity.hpp diff --git a/vanity.hpp b/vanity.hpp new file mode 100644 index 0000000..1da3c8a --- /dev/null +++ b/vanity.hpp @@ -0,0 +1,48 @@ +#pragma once +#include +#include +#include +#include +#include "Crypto.h" +#include "Identity.h" +#include "common/key.hpp" +#include +#include +#include +#include + + +// MARCO +#define INIT_CPUS(count_cpu){\ +cpu = CPU_ALLOC(count_cpu-1);\ +if (cpu == NULL) {\ +return 1;\ +}\ +std::cout << "Succefully CPU_ALLOC" << std::endl;\ +} + + + + +static std::mutex thread_mutex; +static i2p::data::SigningKeyType type; +static i2p::data::PrivateKeys keys; +static bool finded=false; +static size_t padding_size; +static uint8_t * KeyBuf; +static uint8_t * PaddingBuf; +static unsigned long long hash; +static cpu_set_t * cpu; + +//Functions visible and don't need. + + +/* +it does not need, but maybe in future we are can create. +namespace i2p{ +namespace tools{ +namespace vain{ +} +} +} +*/ diff --git a/vanitygen.cpp b/vanitygen.cpp index c2968b0..ef99802 100644 --- a/vanitygen.cpp +++ b/vanitygen.cpp @@ -1,24 +1,9 @@ -#include -#include -#include -#include -#include "Crypto.h" -#include "Identity.h" -#include "common/key.hpp" -#include -#include -#include -#include -static std::mutex thread_mutex; -static i2p::data::SigningKeyType type; -static i2p::data::PrivateKeys keys; -static bool finded=false; -static size_t padding_size; -static uint8_t * KeyBuf; -static uint8_t * PaddingBuf; -static unsigned long long hash; - +#include "vanity.hpp" #define CPU_ONLY + + + + static bool check_prefix(const char * buf){ unsigned short size_str=0; while(*buf) @@ -35,10 +20,10 @@ while(*buf) size_str++; *buf++; } - return true; } + #ifdef CPU_ONLY static inline bool NotThat(const char * a, const char *b){ while(*b) @@ -46,7 +31,7 @@ while(*b) return false; } -inline void twist_cpu(uint8_t * buf,size_t * l0){ +inline void twist_cpu(uint8_t * buf){ //TODO: NORMAL IMPLEMENTATION,\ As in miner... @@ -57,26 +42,35 @@ As in miner... // XXX: make this faster static inline void mutate_keys_cpu( uint8_t * buf, - uint8_t * padding, - size_t * l0) + uint8_t * padding) { - twist_cpu(padding,l0); + twist_cpu(padding); thread_mutex.lock(); keys.RecalculateIdentHash(buf); thread_mutex.unlock(); } -void thread_find(const char * prefix){ +static void thread_find(const char * prefix,int id_thread){ + + + sched_setaffinity(0, sizeof(cpu), cpu); + cpu++; + + std::cout << "Thread " << id_thread << " binded" << std::endl; + while(NotThat(keys.GetPublic()->GetIdentHash().ToBase32().c_str(),prefix) and !finded) { - size_t l0 = 0; + //size_t l0 = 0; \ + in future. - mutate_keys_cpu(KeyBuf,PaddingBuf, (size_t*)&l0); + mutate_keys_cpu(KeyBuf,PaddingBuf); hash++; } } #endif + + int main (int argc, char * argv[]) { if ( argc < 3 ) @@ -141,25 +135,24 @@ TODO: без всех это pthread * orignal has quit (Quit: Leaving) */ +// KeyBuf = new uint8_t[keys.GetFullLen()]; PaddingBuf = keys.GetPadding(); +// unsigned int count_cpu = sysconf(_SC_NPROCESSORS_ONLN); std::vector threads(count_cpu); + INIT_CPUS(count_cpu); +// std::cout << "Start vanity generator in " << count_cpu << " threads" << std::endl; - for ( unsigned int j = count_cpu;j--;){ - threads[j] = std::thread(thread_find,argv[2]); - sched_param sch; - int policy; - pthread_getschedparam(threads[j].native_handle(), &policy, &sch); - sch.sched_priority = 10; - if (pthread_setschedparam(threads[j].native_handle(), SCHED_FIFO, &sch)) { - std::cout << "Failed to setschedparam" << std::endl; - return 1; - } - } +/// + for ( unsigned int j = count_cpu;j--;) + threads[j] = std::thread(thread_find,argv[2],j); + + // SET AFFINITY NOW IN FUNCTION + for(unsigned int j = 0; j < count_cpu;j++) threads[j].join(); - +/// std::cout << "Hashes: " << hash << std::endl; std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);