ethereum-mining / ethminer

Ethereum miner with OpenCL, CUDA and stratum support
GNU General Public License v3.0
5.96k stars 2.28k forks source link

Linux binary throws 'std::regex_error' on API command miner_getstathr on AMD Ubuntu #1031

Closed deathmarine closed 6 years ago

deathmarine commented 6 years ago

Environment: 16.04.1-Ubuntu

What Happened: My Client

[Client] Sending: {"id":0,"jsonrpc":"2.0","method": "miner_getstat1"}
[Client] Receiving: {"id":0,"jsonrpc":"2.0","result":["0.14.0rc5","2","69754;0;0","29262;29159;11334","0;0;0","off;off;off","63;26; 63;26; 55;34","us1.ethermine.org:4444","0;0;0;0"]}
[Client] Sending: {"id":0,"jsonrpc":"2.0","method": "miner_getstathr"}
[Client] Receiving: null
java.net.ConnectException: Connection refused: connect

Ethminer Server Instance

m  11:34:31|ethminer|  Speed  69.84 Mh/s    gpu/0 29.26 62C 26%   gpu/1 29.26 63C 26%   gpu/2 11.33 54C 34%   [A0+0:R0+0:F0] Time: 00:02
terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)

Exact same client software sending command to a ethminer windows instance doesn't seem to have issues.

AndreaLanfranchi commented 6 years ago

Please test with proper casing

[Client] Sending: {"id":0,"jsonrpc":"2.0","method": "miner_getstatHR"}

and report

deathmarine commented 6 years ago
[Client] Sending: {"id":0,"jsonrpc":"2.0","method": "miner_getstatHR"}
[Client] Receiving: {"error":{"code":-32601,"message":"METHOD_NOT_FOUND: The method being requested is not available on this server"},"id":0,"jsonrpc":"2.0"}

I've only just recently began playing with the API considering trying to pipe and parse the output around a wrapper is a pain. A wiki would be nice considering I have no idea what claymore's api looks like.

AndreaLanfranchi commented 6 years ago

Which version are you on ?

deathmarine commented 6 years ago

14.0 RC5 which I'm assuming is a release candidate.

deathmarine commented 6 years ago

Considering this is an AMD based linux setup and after scrubbing the source this could be the cause considering it is the only use of a regular expression? https://github.com/ethereum-mining/ethminer/blob/e9061af34aec374af2e346f0c4c1314a18b58580/libhwmon/wrapamdsysfs.cpp#L334 I have the latest AMD drivers.

smurfy commented 6 years ago

@danielhams yea, thought that too.

smurfy commented 6 years ago

Also could you test if -HWMON 1 causes a crash too?

deathmarine commented 6 years ago

ethminer is ran as root. -HWMON 1 removes the status 10 sec update. And after pinging it, it failed same as before. Also with the HWMON 1 argument, SIGTERM no longer works. Had to kill-9.

deathmarine commented 6 years ago
root@miner-desktop:/home/miner/Miner/Ethminer/bin# for i in 0 1 2; do cat /sys/kernel/debug/dri/$i/amdgpu_pm_info | grep W; done
        56.137 W (VDDC)
        16.0 W (VDDCI)
        85.254 W (max GPU)
        84.239 W (average GPU)
        58.202 W (VDDC)
        16.0 W (VDDCI)
        85.215 W (max GPU)
        87.48 W (average GPU)
        37.226 W (VDDC)
        2.79 W (VDDCI)
        44.225 W (max GPU)
        45.49 W (average GPU)

average GPU Matches with

([0-9.]*)(?:\sW\s\(average\sGPU\))
chfast commented 6 years ago

It might be related to different implementation of regex in C++ standard library.

AndreaLanfranchi commented 6 years ago

@deathmarine

try removing that "R" so it gets

std::regex regex("(([\d|\.]+) W \(average GPU\))");

deathmarine commented 6 years ago

@AndreaLanfranchi No luck, :(

/home/miner/Miner/ethminer/libhwmon/wrapamdsysfs.cpp: In function ‘int wrap_amdsysfs_get_power_usage(wrap_amdsysfs_handle*, int, unsigned int*)’:
/home/miner/Miner/ethminer/libhwmon/wrapamdsysfs.cpp:334:20: warning: unknown escape sequence: '\d'
   std::regex regex("(([\d|\.]+) W \(average GPU\))");
                    ^
/home/miner/Miner/ethminer/libhwmon/wrapamdsysfs.cpp:334:20: warning: unknown escape sequence: '\.'
/home/miner/Miner/ethminer/libhwmon/wrapamdsysfs.cpp:334:20: warning: unknown escape sequence: '\('
/home/miner/Miner/ethminer/libhwmon/wrapamdsysfs.cpp:334:20: warning: unknown escape sequence: '\)'

When compiling. No change from the output with -HWMON 1, however when making the api call it no longer crashes. Assuming there are no matches in the search. I've tried a few different expressions and matches with no success, however when and if I come up with something, I'll make a PR.

If you guys are interested I'm slapping a little GUI together from the API. https://github.com/deathmarine/EthMonitor

chfast commented 6 years ago

Let's see what's inside the error. Can you test this branch? https://github.com/ethereum-mining/ethminer/pull/1091

deathmarine commented 6 years ago

So i checked out that branch, built it, and it works...

  m  08:36:32|ethminer|  Speed  98.84 Mh/s    gpu/0 29.19 62C 37% 88W  gpu/1 11.27 65C 35% 45W  gpu/2 29.28 62C 33% 84W  gpu/3 29.10 62C 37% 81W  [A1+0:R0+0:F0] Time: 00:00
  m  08:36:37|ethminer|  Speed  98.89 Mh/s    gpu/0 29.20 63C 37% 89W  gpu/1 11.29 65C 35% 45W  gpu/2 29.28 62C 33% 86W  gpu/3 29.12 62C 37% 84W  [A1+0:R0+0:F0] Time: 00:00
  m  08:36:42|ethminer|  Speed  98.97 Mh/s    gpu/0 29.28 63C 36% 86W  gpu/1 11.29 65C 35% 45W  gpu/2 29.28 62C 32% 84W  gpu/3 29.12 62C 36% 83W  [A1+0:R0+0:F0] Time: 00:00
  m  08:36:48|ethminer|  Speed  98.77 Mh/s    gpu/0 29.16 63C 36% 85W  gpu/1 11.29 65C 34% 45W  gpu/2 29.24 63C 32% 86W  gpu/3 29.08 62C 36% 82W  [A1+0:R0+0:F0] Time: 00:00

I don't know why 'trying' makes a difference but it compiles, no errors and runs. I checked that I was reset and even

miner@miner-desktop:~/Miner/git/ethminer/libhwmon$ tail -20  wrapamdsysfs.cpp
            std::smatch sm;
            std::regex regex(R"(([\d|\.]+) W \(average GPU\))");
            if (std::regex_search(line, sm, regex))
            {
                if (sm.size() == 2)
                {
                    double watt = atof(sm.str(1).c_str());
                    *milliwatts = (unsigned int)(watt * 1000);
                    return 0;
                }
            }
        }
    }
    catch (const std::exception& ex)
    {
        cwarn << "Error in amdsysfs_get_power_usage: " << ex.what();
    }

    return -1;
}
miner@miner-desktop:~/Miner/git/ethminer/libhwmon$

I checked the api...

{"id":0,"jsonrpc":"2.0","result":{"ethhashrate":99923013,"ethhashrates":[29550692,11460364,29550692,29361264],"ethinvalid":0,"ethpoolsw":0,"ethrejected":0,"ethshares":2,"fanpercentages":[31,36,30,30],"pooladdrs":"us1.ethermine.org:4444","powerusages":[87.186999999999998,43.200000000000003,85.253,83.920000000000002],"runtime":"1","temperatures":[62,54,60,60],"version":"0.15.0.dev8-3+commit.a6bf159e"}}

was returned.

"version":"0.15.0.dev8-3+commit.a6bf159e" a6bf159e works. I'll let you guys close this if you plan to merge with #1091.

Btw, you guys do awesome work. Thanks @AndreaLanfranchi , @chfast, @smurfy.

chfast commented 6 years ago

@deathmarine previously, did you also build from source?

deathmarine commented 6 years ago

@chfast I'll revert to 6e52de9206d4ee02e569f274ce3904926f751527 and build...

There is no issue,

{"id":0,"jsonrpc":"2.0","result":{"ethhashrate":99100342,"ethhashrates":[29258196,11430621,29258196,29153328],"ethinvalid":0,"ethpoolsw":0,"ethrejected":0,"ethshares":0,"fanpercentages":[29,35,29,28],"pooladdrs":"us1.ethermine.org:4444","powerusages":[84.206000000000003,39.131,84.510000000000005,80.111000000000004],"runtime":"0","temperatures":[50,42,47,47],"version":"0.15.0.dev4-15+commit.6e52de92.dirty"}}

"version":"0.15.0.dev4-15+commit.6e52de92.dirty"

I feel somewhat foolish, I guess it only fails with the binaries that are downloaded.

From binaries = Segmentation fault (core dumped) with "-HWMON 1" arguments

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)

Regex error, If I make the api-call on the downloaded binary.

deathmarine commented 6 years ago

Tried 15.0 dev9

  ✘  10:33:56|ethminer|  Error in amdsysfs_get_power_usage: regex_error

Every poll, per card, however it doesn't crash. Building from source still works great.

AndreaLanfranchi commented 6 years ago

API interfaces and data collection has undergone a deep revisit.

Please try latest master and report.

Closing for now. (feel free to reopen if needed).