fireice-uk / xmr-stak-cpu

Monero CPU miner
GNU General Public License v3.0
1.11k stars 478 forks source link

Building under Solaris/SunOS #380

Open acid-jack opened 6 years ago

acid-jack commented 6 years ago

Hello. I'm trying to build this project under Illumos-based OS OpenIndiana Hipster 2017.04. And I got a problem with 64-bit mode.

At first I received this error:

[ 77%] Building CXX object CMakeFiles/xmr-stak-cpu.dir/minethd.cpp.o
In file included from /root/xmr-stak-cpu/minethd.cpp:75:0:
/root/xmr-stak-cpu/crypto/cryptonight_aesni.h:36:2: error: #error You are trying to do a 32-bit build. This will all end in tears. I know it.
 #error You are trying to do a 32-bit build. This will all end in tears. I know it.
  ^
/root/xmr-stak-cpu/minethd.cpp: In function 'void thd_setaffinity(std::thread::native_handle_type, uint64_t)':
/root/xmr-stak-cpu/minethd.cpp:64:2: error: 'cpu_set_t' was not declared in this scope
  cpu_set_t mn;
  ^
[...]

At first sight looks like it is 32-bit OS but it supports 64-bit binaries:

# uname -a
SunOS <my hostname> 5.11 illumos-b9d34b9d78 i86pc i386 i86pc
# isainfo -vk
64-bit amd64 kernel modules

So I tried to add '-m64' flag for gcc:

//Flags used by the compiler during all build types.
CMAKE_CXX_FLAGS:STRING=-m64

After this I moved forward but received this error:

[ 77%] Building CXX object CMakeFiles/xmr-stak-cpu.dir/minethd.cpp.o
/root/xmr-stak-cpu/minethd.cpp: In function 'void thd_setaffinity(std::thread::native_handle_type, uint64_t)':
/root/xmr-stak-cpu/minethd.cpp:64:2: error: 'cpu_set_t' was not declared in this scope
  cpu_set_t mn;
  ^
/root/xmr-stak-cpu/minethd.cpp:65:12: error: 'mn' was not declared in this scope
  CPU_ZERO(&mn);
            ^
/root/xmr-stak-cpu/minethd.cpp:65:14: error: 'CPU_ZERO' was not declared in this scope
  CPU_ZERO(&mn);
              ^
/root/xmr-stak-cpu/minethd.cpp:66:21: error: 'CPU_SET' was not declared in this scope
  CPU_SET(cpu_id, &mn);
                     ^
/root/xmr-stak-cpu/minethd.cpp:67:50: error: 'pthread_setaffinity_np' was not declared in this scope
  pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn);
                                                  ^
*** Error code 1
The following command caused the error:
/usr/bin/c++    -m64 -msse2 -maes -O3 -DNDEBUG   -std=c++11 -o CMakeFiles/xmr-stak-cpu.dir/minethd.cpp.o -c /root/xmr-stak-cpu/minethd.cpp
make: Fatal error: Command failed for target `CMakeFiles/xmr-stak-cpu.dir/minethd.cpp.o'

Can you help me to build this project under Solaris OS?

psychocrypt commented 6 years ago

I have no solaris available. I thought it is dead :-) You can disable all code within the pinning function, than you will have no pinned threads but you should pass maybe the compile process.

acid-jack commented 6 years ago

OK. I commented next in the minethd.cpp:

#else
      cpu_set_t mn;
      CPU_ZERO(&mn);
      CPU_SET(cpu_id, &mn);
      pthread_setaffinity_np(h, sizeof(cpu_set_t), &mn);

Now I received next error:

[ 61%] Building CXX object CMakeFiles/xmr-stak-cpu.dir/crypto/cryptonight_common.cpp.o
/root/xmr-stak-cpu/crypto/cryptonight_common.cpp: In function 'cryptonight_ctx* cryptonight_alloc_ctx(std::size_t, std::size_t, alloc_msg*)':
/root/xmr-stak-cpu/crypto/cryptonight_common.cpp:154:33: error: 'MAP_HUGETLB' was not declared in this scope
   MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
                                 ^
/root/xmr-stak-cpu/crypto/cryptonight_common.cpp:154:47: error: 'MAP_POPULATE' was not declared in this scope
   MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
                                               ^
/root/xmr-stak-cpu/crypto/cryptonight_common.cpp:166:63: error: 'madvise' was not declared in this scope
  if(madvise(ptr->long_state, MEMORY, MADV_RANDOM|MADV_WILLNEED) != 0)
                                                               ^
*** Error code 1
The following command caused the error:
/usr/bin/c++    -m64 -msse2 -maes -O3 -DNDEBUG   -std=c++11 -o CMakeFiles/xmr-stak-cpu.dir/crypto/cryptonight_common.cpp.o -c /root/xmr-stak-cpu/crypto/cryptonight_common.cpp
psychocrypt commented 6 years ago

This is for using huge memory pages in linux. Since you are using solaris you need to add the methods how large pages can be activated in solaris or remove the code snipped :-)

acid-jack commented 6 years ago

Oh. I'm not a programmer. Don't know how to do this :(

psychocrypt commented 6 years ago

In this case you can try to disable the huge page allocation but you should use a more common OS. The uset base of solaris is to small t invest time to it. sry

VolodymyrLavrenchuk commented 6 years ago

I have successfully build this project on SunOS:

# uname -a
SunOS <host name> 5.11 oi_151a9 i86pc i386 i86pc Solaris
# cmake --version
cmake version 3.4.3
# gcc --version
gcc (GCC) 5.2.0

Build command line: rm -Rf CMakeFiles && CC=/opt/csw/bin/gcc-5.2 CXX=/opt/csw/bin/g++-5.2 cmake -DMICROHTTPD_ENABLE=OFF -DHWLOC_ENABLE=OFF . && make

Changes

Trying to fix this error: [2017-10-29 15:05:04] : SOCKET ERROR - PARSE error: Protocol error 3

acid-jack commented 6 years ago

Thx for your help. With these edits I could to build binary. But after starting I received the same protocol error 3.

VolodymyrLavrenchuk commented 6 years ago

I have made some improvements but unfortunately still have protocol error 3. Debug info from here:

8               Value::ConstMemberIterator itr = obj.FindMember(key);
(gdb) p obj
$1 = (const rapidjson::Value &) @0x4d03d8: {static kDefaultArrayCapacity = <optimized out>, static kDefaultObjectCapacity = <optimized out>, data_ = {s = {length = 4, hashcode = 4,
      str = 0x30000005432f8 <error: Cannot access memory at address 0x30000005432f8>}, ss = {str = "\004\000\000\000\004\000\000\000\370\062T\000\000"}, n = {i = {i = 4, padding = "\004\000\000"}, u = {u = 4,
        padding2 = "\004\000\000"}, i64 = 17179869188, u64 = 17179869188, d = 8.4879831658373518e-314}, o = {size = 4, capacity = 4, members = 0x30000005432f8}, a = {size = 4, capacity = 4, elements = 0x30000005432f8}, f = {
      payload = "\004\000\000\000\004\000\000\000\370\062T\000\000", flags = 3}}}

This object does not have "id" so here it will fail :(

VolodymyrLavrenchuk commented 6 years ago

I finally make it works. Do not know why rapidjson is not working with static memory allocation... Hwloc is also working fine:

[2017-11-02 14:52:56] : Starting single thread, affinity: 0.
[2017-11-02 14:52:56] : Starting single thread, affinity: 1.
[2017-11-02 14:52:56] : Connecting to pool cryptonight.usa.nicehash.com:3355 ...
[2017-11-02 14:52:56] : hwloc: memory pinned
[2017-11-02 14:52:56] : hwloc: memory pinned
[2017-11-02 14:52:57] : Connected. Logging in...
[2017-11-02 14:52:57] : Difficulty changed. Now: 160003.
[2017-11-02 14:52:57] : New block detected.
[2017-11-02 14:53:18] : New block detected.
acid-jack commented 6 years ago

Confirm. It's works!

VolodymyrLavrenchuk commented 6 years ago

I have made simple test example to confirm bug with Protocol error 3. It works if I build it without -m64 flag. But with this flag I have "NULL pointer". I am going to ask rapidjson developers.

ghost commented 6 years ago

Very nice work. Any help for making xmr-stak-cpu works also on SPARC Solaris? I have 2 servers with 256 VCPU for testing the portability if needed.

Marco

oforpertainingtothesun commented 6 years ago

I have changed cpuminer-multi to use the Sparc T4 instructions so I should be able to do the same to this. I ended up using cpuminer-multi as I couldn't figure out getting gcc 5.2 on Solaris 11.3 - the package masking system seems to be rather obtuse...

Mind you, I ended up building cmake from source so perhaps I should just do that to gcc?!

If you send me the config you're trying to use I'll duplicate it and have a bash at this. The cpuminer-multi code had lots of bigendian / address alignment problems within the *.c crypto files, so there may be a reasonable amount of churn though.

oforpertainingtothesun commented 6 years ago

@marcofortina @acid-jack I've got a fork that works on Sparc here:

https://github.com/oforpertainingtothesun/xmr-stak-sparc

It turns out you do have to build gcc (5.5) from source as Oracle couldn't devops their way out of a paper bag. I get ~60H/s on 16 threads on my T4, so ~240H/s on full... you might get near 1kH/s on each system if this works for you.

Mind if I ask (part of my day job...) what your Sparc systems do (even vaguely...) for their day job?

acid-jack commented 6 years ago

@oforpertainingtothesun I have no Sparc-station.

oforpertainingtothesun commented 6 years ago

@acid-jack Probably best to keep it that way!