1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-07 16:05:05 -05:00

Compare commits

..

52 Commits

Author SHA1 Message Date
XMRig
c0143b90ce v6.19.0 2023-02-02 11:51:11 +07:00
XMRig
c3cdffe86d Merge branch 'dev' 2023-02-02 11:50:29 +07:00
XMRig
8a4da33bea Update scripts/build.*.sh. 2023-01-30 00:19:55 +07:00
XMRig
1c7a339527 v6.19.0-dev (new config options added). 2023-01-29 11:16:37 +07:00
xmrig
490acd6e55 Update CHANGELOG.md 2023-01-29 11:13:28 +07:00
xmrig
6ecf57959b Merge pull request #3202 from SChernykh/dev
Solo mining: added job timeout (default is 15 seconds)
2023-01-29 11:12:22 +07:00
SChernykh
e2c58126e9 Solo mining: added job timeout (default is 15 seconds)
It's important to update jobs frequently to get new transactions into the block template. See https://rucknium.me/posts/monero-pool-transaction-delay/ for more details.
2023-01-28 19:42:02 +01:00
XMRig
0ed4b35cd3 Update hwloc for MSVC builds to 2.9.0. 2023-01-27 01:07:58 +07:00
xmrig
afe2aa4402 Update CHANGELOG.md 2023-01-23 20:54:46 +07:00
XMRig
3f7533a645 Update to latest sse2neon.h. 2023-01-23 20:45:02 +07:00
xmrig
6ef0409086 Merge pull request #3198 from SChernykh/dev
Fixed broken RandomX light mode mining
2023-01-21 22:05:25 +07:00
SChernykh
64b0d9562e Fixed broken RandomX light mode mining
RandomX VMs didn't get updated properly in light mode.
2023-01-21 16:02:47 +01:00
XMRig
770b71c69a #3185 Fixed macOS DMI reader. 2023-01-19 22:09:59 +07:00
xmrig
44642643f8 Merge pull request #3196 from SChernykh/dev
Show IP address for failed connections
2023-01-11 17:02:15 +07:00
SChernykh
273bb84df8 Show IP address for failed connections 2023-01-11 09:28:16 +01:00
xmrig
4d0b8c9daf Merge pull request #3182 from SChernykh/dev
DragonflyBSD compilation fixes
2022-12-17 20:24:01 +07:00
SChernykh
7d4d48e83b DragonflyBSD compilation fixes 2022-12-17 13:11:14 +01:00
xmrig
2ea37cdf37 Merge pull request #3180 from SChernykh/dev
Added ifdefs for DragonflyBSD
2022-12-16 21:29:24 +07:00
SChernykh
a02afe6d4f Added ifdefs for DragonflyBSD
Possible fix for #3179
2022-12-16 15:26:37 +01:00
XMRig
6e86dddc65 Bump the minimum CMake version in other places too. 2022-12-09 16:07:42 +07:00
xmrig
0171faffe7 Merge pull request #3176 from SChernykh/dev
Update cmake required version to 3.1
2022-12-09 15:24:54 +07:00
SChernykh
25decd1b7f Update cmake required version to 3.1
`set(CMAKE_CXX_STANDARD 11)` only works properly starting from cmake 3.1, see #3174
2022-12-09 09:21:40 +01:00
xmrig
354b9ddb34 Merge pull request #3163 from SChernykh/dev
Improved Zen 3 MSR mod
2022-11-18 11:38:45 +07:00
SChernykh
3ad6ab56a5 Improved Zen 3 MSR mod
+0.5% speedup on Ryzen 5 5600X
2022-11-17 23:32:36 +01:00
xmrig
1aa0e37b54 Merge pull request #3161 from SChernykh/dev
MSVC build: enabled parallel compilation
2022-11-15 13:20:41 +06:30
SChernykh
807c64ddb1 MSVC build: enabled parallel compilation 2022-11-15 07:45:54 +01:00
XMRig
5bf90704a6 #2869 2022-10-29 23:51:42 +07:00
xmrig
912d1e362b Merge pull request #3144 from Spudz76/dev-updateSSE2NEON
Update to latest sse2neon.h from github:DLTcollab/sse2neon
2022-10-24 13:50:54 +07:00
Tony Butler
eeb459506c Update to latest sse2neon.h from github:DLTcollab/sse2neon 2022-10-23 15:27:14 -06:00
XMRig
f4ec0287c4 v6.18.2-dev 2022-10-23 23:19:50 +07:00
XMRig
483d6ada3d Merge branch 'master' into dev 2022-10-23 23:19:06 +07:00
XMRig
28e81bd7c0 v6.18.1 2022-10-23 17:44:24 +07:00
XMRig
54e75bc7c4 Merge branch 'dev' 2022-10-23 17:43:38 +07:00
xmrig
c388113a30 Update CHANGELOG.md 2022-10-23 17:14:57 +07:00
xmrig
36afeec225 Merge pull request #3134 from SChernykh/dev
Added Zen4 to randomx_boost.sh
2022-10-10 03:37:06 +07:00
SChernykh
4b5e56416d Added Zen4 to randomx_boost.sh 2022-10-09 22:02:50 +02:00
xmrig
0d314d0469 Merge pull request #3132 from SChernykh/dev
RandomX: added MSR mod for Zen 4
2022-10-01 23:40:04 +07:00
SChernykh
7fc45dfb2d RandomX: added MSR mod for Zen 4
+0.8% faster on Ryzen 9 7950X
2022-10-01 18:33:04 +02:00
xmrig
2ba40edee0 Update CHANGELOG.md 2022-09-25 17:01:33 +07:00
xmrig
bc4dd11761 Merge pull request #3129 from SChernykh/dev
Fix: protectRX flushed CPU cache only on MacOS/iOS
2022-09-22 07:02:28 +07:00
SChernykh
7b52a41459 Fix: protectRX flushed CPU cache only on MacOS/iOS 2022-09-21 15:18:06 +02:00
xmrig
b5de214ff9 Merge pull request #3126 from SChernykh/dev
Don't reset when pool sends the same job blob
2022-09-19 19:03:17 +07:00
SChernykh
8bd3b393ef Update m_size only if blob was set successfully 2022-09-19 10:42:08 +02:00
SChernykh
9223c2f027 Don't reset when pool sends the same job blob 2022-09-19 10:35:36 +02:00
xmrig
6346d36d1b Merge pull request #3120 from SChernykh/dev
RandomX: optimized CFROUND elimination more
2022-09-16 22:50:51 +07:00
SChernykh
93c07e1d34 RandomX: optimized CFROUND elimination more 2022-09-16 14:11:27 +02:00
xmrig
0ba3000982 Merge pull request #3119 from SChernykh/dev
RandomX: optimized CFROUND elimination
2022-09-16 01:04:32 +07:00
SChernykh
f0e7de8c71 RandomX: optimized CFROUND elimination 2022-09-15 19:57:34 +02:00
xmrig
1c4eb6c5fe Merge pull request #3109 from SChernykh/dev
RandomX: added Blake2 AVX2 version
2022-08-26 01:52:22 +07:00
SChernykh
63e21dfe63 RandomX: added Blake2 AVX2 version
+0.1% speedup on AMD Zen2/Zen3 and Intel CPUs which support AVX2.
2022-08-25 20:39:54 +02:00
xmrig
b2d9dab2e3 Merge pull request #3075 from dev-0x7C6/master
Recognize armv7ve as valid ARMv7 target.
2022-08-19 02:30:27 +07:00
Bartłomiej Burdukiewicz
7e49fc828d Recognize armv7ve as valid ARMv7 target.
Docs: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

'armv7ve' - The extended version of the ARMv7-A architecture with support for virtualization.

Signed-off-by: Bartłomiej Burdukiewicz <bartlomiej.burdukiewicz@gmail.com>
2022-06-21 18:31:24 +02:00
246 changed files with 12041 additions and 10475 deletions

View File

@@ -1,3 +1,24 @@
# v6.19.0
- [#3144](https://github.com/xmrig/xmrig/pull/3144) Update to latest `sse2neon.h`.
- [#3161](https://github.com/xmrig/xmrig/pull/3161) MSVC build: enabled parallel compilation.
- [#3163](https://github.com/xmrig/xmrig/pull/3163) Improved Zen 3 MSR mod.
- [#3176](https://github.com/xmrig/xmrig/pull/3176) Update cmake required version to 3.1.
- [#3182](https://github.com/xmrig/xmrig/pull/3182) DragonflyBSD compilation fixes.
- [#3196](https://github.com/xmrig/xmrig/pull/3196) Show IP address for failed connections.
- [#3185](https://github.com/xmrig/xmrig/issues/3185) Fixed macOS DMI reader.
- [#3198](https://github.com/xmrig/xmrig/pull/3198) Fixed broken RandomX light mode mining.
- [#3202](https://github.com/xmrig/xmrig/pull/3202) Solo mining: added job timeout (default is 15 seconds).
# v6.18.1
- [#3129](https://github.com/xmrig/xmrig/pull/3129) Fix: protectRX flushed CPU cache only on MacOS/iOS.
- [#3126](https://github.com/xmrig/xmrig/pull/3126) Don't reset when pool sends the same job blob.
- [#3120](https://github.com/xmrig/xmrig/pull/3120) RandomX: optimized `CFROUND` elimination.
- [#3109](https://github.com/xmrig/xmrig/pull/3109) RandomX: added Blake2 AVX2 version.
- [#3082](https://github.com/xmrig/xmrig/pull/3082) Fixed GCC 12 warnings.
- [#3075](https://github.com/xmrig/xmrig/pull/3075) Recognize `armv7ve` as valid ARMv7 target.
- [#3132](https://github.com/xmrig/xmrig/pull/3132) RandomX: added MSR mod for Zen 4.
- [#3134](https://github.com/xmrig/xmrig/pull/3134) Added Zen4 to `randomx_boost.sh`.
# v6.18.0
- [#3067](https://github.com/xmrig/xmrig/pull/3067) Monero v15 network upgrade support and more house keeping.
- Removed deprecated AstroBWTv1 and v2.

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(xmrig)
option(WITH_HWLOC "Enable hwloc support" ON)
@@ -27,6 +27,7 @@ option(WITH_STRICT_CACHE "Enable strict checks for OpenCL cache" ON)
option(WITH_INTERLEAVE_DEBUG_LOG "Enable debug log for threads interleave" OFF)
option(WITH_PROFILING "Enable profiling for developers" OFF)
option(WITH_SSE4_1 "Enable SSE 4.1 for Blake2" ON)
option(WITH_AVX2 "Enable AVX2 for Blake2" ON)
option(WITH_VAES "Enable VAES instructions for Cryptonight" ON)
option(WITH_BENCHMARK "Enable builtin RandomX benchmark and stress test" ON)
option(WITH_SECURE_JIT "Enable secure access to JIT memory" OFF)
@@ -156,12 +157,14 @@ endif()
if (XMRIG_OS_WIN)
list(APPEND SOURCES_OS
res/app.rc
src/App_win.cpp
src/crypto/common/VirtualMemory_win.cpp
)
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
elseif (XMRIG_OS_APPLE)
list(APPEND SOURCES_OS
src/App_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp
)
@@ -170,6 +173,7 @@ elseif (XMRIG_OS_APPLE)
set(EXTRA_LIBS ${IOKIT_LIBRARY} ${CORESERVICES_LIBRARY})
else()
list(APPEND SOURCES_OS
src/App_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp
)
@@ -187,7 +191,7 @@ else()
endif()
endif()
add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_LEGACY -DXMRIG_JSON_SINGLE_LINE_ARRAY)
add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_JSON_SINGLE_LINE_ARRAY)
add_definitions(-D__STDC_FORMAT_MACROS -DUNICODE -D_FILE_OFFSET_BITS=64)
find_package(UV REQUIRED)

View File

@@ -25,13 +25,14 @@ if (XMRIG_64_BIT AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
add_definitions(-DRAPIDJSON_SSE2)
else()
set(WITH_SSE4_1 OFF)
set(WITH_AVX2 OFF)
set(WITH_VAES OFF)
endif()
if (NOT ARM_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8-a)$")
set(ARM_TARGET 8)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l|armv7ve)$")
set(ARM_TARGET 7)
endif()
endif()
@@ -57,3 +58,7 @@ endif()
if (WITH_SSE4_1)
add_definitions(-DXMRIG_FEATURE_SSE4_1)
endif()
if (WITH_AVX2)
add_definitions(-DXMRIG_FEATURE_AVX2)
endif()

View File

@@ -61,11 +61,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
add_definitions(/DHAVE_BUILTIN_CLEAR_CACHE)
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_C_FLAGS_RELEASE "/MP /MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_CXX_FLAGS_RELEASE "/MP /MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Ob1 /Zi /DRELWITHDEBINFO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Ob1 /Zi /DRELWITHDEBINFO")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/MP /Ob1 /Zi /DRELWITHDEBINFO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MP /Ob1 /Zi /DRELWITHDEBINFO")
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)

View File

@@ -15,7 +15,7 @@ else()
set(XMRIG_OS_ANDROID ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(XMRIG_OS_LINUX ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL DragonFly)
set(XMRIG_OS_FREEBSD ON)
endif()
endif()

View File

@@ -76,7 +76,15 @@ if (WITH_RANDOMX)
list(APPEND SOURCES_CRYPTO src/crypto/randomx/blake2/blake2b_sse41.c)
if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/randomx/blake2/blake2b_sse41.c PROPERTIES COMPILE_FLAGS -msse4.1)
set_source_files_properties(src/crypto/randomx/blake2/blake2b_sse41.c PROPERTIES COMPILE_FLAGS "-Ofast -msse4.1")
endif()
endif()
if (WITH_AVX2)
list(APPEND SOURCES_CRYPTO src/crypto/randomx/blake2/avx2/blake2b_avx2.c)
if (CMAKE_C_COMPILER_ID MATCHES GNU OR CMAKE_C_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/randomx/blake2/avx2/blake2b_avx2.c PROPERTIES COMPILE_FLAGS "-Ofast -mavx2")
endif()
endif()

View File

@@ -20,7 +20,7 @@ VS_VERSION_INFO VERSIONINFO
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "CompanyName", APP_DOMAIN
VALUE "CompanyName", APP_SITE
VALUE "FileDescription", APP_DESC
VALUE "FileVersion", APP_VERSION
VALUE "LegalCopyright", APP_COPYRIGHT

View File

@@ -1,8 +1,8 @@
#!/bin/bash -e
HWLOC_VERSION_MAJOR="2"
HWLOC_VERSION_MINOR="7"
HWLOC_VERSION_PATCH="1"
HWLOC_VERSION_MINOR="9"
HWLOC_VERSION_PATCH="0"
HWLOC_VERSION="${HWLOC_VERSION_MAJOR}.${HWLOC_VERSION_MINOR}.${HWLOC_VERSION_PATCH}"

View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
OPENSSL_VERSION="1.1.1o"
OPENSSL_VERSION="1.1.1s"
mkdir -p deps
mkdir -p deps/include

View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
OPENSSL_VERSION="3.0.3"
OPENSSL_VERSION="3.0.7"
mkdir -p deps
mkdir -p deps/include

View File

@@ -1,6 +1,6 @@
#!/bin/bash -e
UV_VERSION="1.44.1"
UV_VERSION="1.44.2"
mkdir -p deps
mkdir -p deps/include

View File

@@ -10,14 +10,24 @@ fi
if grep -E 'AMD Ryzen|AMD EPYC' /proc/cpuinfo > /dev/null;
then
if grep "cpu family[[:space:]]:[[:space:]]25" /proc/cpuinfo > /dev/null;
if grep "cpu family[[:space:]]\{1,\}:[[:space:]]25" /proc/cpuinfo > /dev/null;
then
if grep "model[[:space:]]\{1,\}:[[:space:]]97" /proc/cpuinfo > /dev/null;
then
echo "Detected Zen4 CPU"
wrmsr -a 0xc0011020 0x4400000000000
wrmsr -a 0xc0011021 0x4000000000040
wrmsr -a 0xc0011022 0x8680000401570000
wrmsr -a 0xc001102b 0x2040cc10
echo "MSR register values for Zen4 applied"
else
echo "Detected Zen3 CPU"
wrmsr -a 0xc0011020 0x4480000000000
wrmsr -a 0xc0011021 0x1c000200000040
wrmsr -a 0xc0011022 0xc000000401500000
wrmsr -a 0xc001102b 0x2000cc14
wrmsr -a 0xc0011022 0xc000000401570000
wrmsr -a 0xc001102b 0x2000cc10
echo "MSR register values for Zen3 applied"
fi
else
echo "Detected Zen1/Zen2 CPU"
wrmsr -a 0xc0011020 0

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project(argon2 C)
set(CMAKE_C_STANDARD 99)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project (hwloc C)
include_directories(include)

View File

@@ -17,6 +17,50 @@ bug fixes (and other actions) for each version of hwloc since version
0.9.
Version 2.9.0
-------------
* Backends
+ Expose the memory size of CXL memory devices (Type 3) on Linux.
+ The LevelZero backend now reports the "XeLinkBandwidth" distance
matrix between L0 devices (and subdevices) when available.
+ Add support for CUDA compute capability up to 9.0.
* Tools
+ lstopo now switches to console mode when its output is redirected.
Graphical window mode may be forced back with --of window.
+ hwloc-calc now accepts "numa" in -H, and I/O subtypes such as "gpu"
in -I and -N.
Version 2.8.0
-------------
* API
+ Add HWLOC_TOPOLOGY_FLAG_NO_DISTANCES, _NO_MEMATTRS and _NO_CPUKINDS
to reduce the overhead when unneeded.
+ Add separate Read/Write Bandwidth/Latency memory attributes and
implement them on Linux.
* Backends
+ NUMA nodes may now have a subtype such as DRAM, HBM, SPM, or NVM
on heterogeneous memory platforms on Linux.
- Add DAXType and DAXParent attributes on Linux to tell where a
DAX device or its corresponding NUMA node come from (SPM for
Specific-Purpose or NVM for Non-Volatile Memory).
+ Detect heterogeneous caches in hybrid CPUs on MacOS X,
thanks to Paul Bone for the help.
+ Max frequencies are not ignored in Linux cpukinds anymore (they were
ignored in hwloc 2.7.0), but they may be slightly adjusted to avoid
reporting hybrid CPUs because Intel Turbo Boost Max 3.0.
- See the documentation of environment variable HWLOC_CPUKINDS_MAXFREQ.
+ Hardwire the PCI locality of HPE Cray EX235a nodes.
* Tools
+ lstopo and other tools may now load Linux and x86 cpuid topology files
from a tarball.
+ lstopo may now replace the P# and L# index prefixes with custom strings
thanks to --os-index-prefix and --logical-index-prefix options.
* Misc
+ Add --disable-readme to avoid regenerating the top-level hwloc README
file from the documentation.
Version 2.7.1
-------------
* Workaround crashes when virtual machines report incoherent x86 CPUID

View File

@@ -78,7 +78,7 @@ debug and report issues.
Questions may be sent to the users or developers mailing lists (https://
www.open-mpi.org/community/lists/hwloc.php).
There is also a #hwloc IRC channel on Freenode (irc.freenode.net).
There is also a #hwloc IRC channel on Libera Chat (irc.libera.chat).

View File

@@ -8,8 +8,8 @@
# Please update HWLOC_VERSION* in contrib/windows/hwloc_config.h too.
major=2
minor=7
release=1
minor=9
release=0
# greek is used for alpha or beta release tags. If it is non-empty,
# it will be appended to the version number. It does not have to be
@@ -22,7 +22,7 @@ greek=
# The date when this release was created
date="Mar 20, 2022"
date="Dec 14, 2022"
# If snapshot=1, then use the value from snapshot_version as the
# entire hwloc version (i.e., ignore major, minor, release, and
@@ -41,7 +41,7 @@ snapshot_version=${major}.${minor}.${release}${greek}-git
# 2. Version numbers are described in the Libtool current:revision:age
# format.
libhwloc_so_version=20:3:5
libhwloc_so_version=21:1:6
libnetloc_so_version=0:0:0
# Please also update the <TargetName> lines in contrib/windows/libhwloc.vcxproj

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2020 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -93,7 +93,7 @@ extern "C" {
* Two stable releases of the same series usually have the same ::HWLOC_API_VERSION
* even if their HWLOC_VERSION are different.
*/
#define HWLOC_API_VERSION 0x00020500
#define HWLOC_API_VERSION 0x00020800
/** \brief Indicate at runtime which hwloc API version was used at build time.
*
@@ -971,7 +971,7 @@ HWLOC_DECLSPEC const char * hwloc_obj_type_string (hwloc_obj_type_t type) __hwlo
*
* If \p size is 0, \p string may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_t size,
@@ -986,7 +986,7 @@ HWLOC_DECLSPEC int hwloc_obj_type_snprintf(char * __hwloc_restrict string, size_
*
* If \p size is 0, \p string may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
HWLOC_DECLSPEC int hwloc_obj_attr_snprintf(char * __hwloc_restrict string, size_t size,
@@ -2060,7 +2060,26 @@ enum hwloc_topology_flags_e {
* not change to due thread binding changes on Windows
* (see ::HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING).
*/
HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING = (1UL<<6)
HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING = (1UL<<6),
/** \brief Ignore distances.
*
* Ignore distance information from the operating systems (and from XML)
* and hence do not use distances for grouping.
*/
HWLOC_TOPOLOGY_FLAG_NO_DISTANCES = (1UL<<7),
/** \brief Ignore memory attributes.
*
* Ignore memory attribues from the operating systems (and from XML).
*/
HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS = (1UL<<8),
/** \brief Ignore CPU Kinds.
*
* Ignore CPU kind information from the operating systems (and from XML).
*/
HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS = (1UL<<9)
};
/** \brief Set OR'ed flags to non-yet-loaded topology.

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -11,10 +11,10 @@
#ifndef HWLOC_CONFIG_H
#define HWLOC_CONFIG_H
#define HWLOC_VERSION "2.7.1"
#define HWLOC_VERSION "2.9.0"
#define HWLOC_VERSION_MAJOR 2
#define HWLOC_VERSION_MINOR 7
#define HWLOC_VERSION_RELEASE 1
#define HWLOC_VERSION_MINOR 9
#define HWLOC_VERSION_RELEASE 0
#define HWLOC_VERSION_GREEK ""
#define __hwloc_restrict

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -112,7 +112,7 @@ HWLOC_DECLSPEC int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t sr
*
* If \p buflen is 0, \p buf may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
@@ -137,7 +137,7 @@ HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwl
*
* If \p buflen is 0, \p buf may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
HWLOC_DECLSPEC int hwloc_bitmap_list_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
@@ -161,7 +161,7 @@ HWLOC_DECLSPEC int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char *
*
* If \p buflen is 0, \p buf may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
@@ -357,11 +357,11 @@ HWLOC_DECLSPEC int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap) __hwloc_
* The loop must start with hwloc_bitmap_foreach_begin() and end
* with hwloc_bitmap_foreach_end() followed by a terminating ';'.
*
* \p index is the loop variable; it should be an unsigned int. The
* first iteration will set \p index to the lowest index in the bitmap.
* \p id is the loop variable; it should be an unsigned int. The
* first iteration will set \p id to the lowest index in the bitmap.
* Successive iterations will iterate through, in order, all remaining
* indexes set in the bitmap. To be specific: each iteration will return a
* value for \p index such that hwloc_bitmap_isset(bitmap, index) is true.
* value for \p id such that hwloc_bitmap_isset(bitmap, id) is true.
*
* The assert prevents the loop from being infinite if the bitmap is infinitely set.
*

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -55,7 +55,7 @@ hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj
*
* If \p size is 0, \p string may safely be \c NULL.
*
* \return the number of character that were actually written if not truncating,
* \return the number of characters that were actually written if not truncating,
* or that would have been written (not including the ending \\0).
*/
static __hwloc_inline int

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2010-2021 Inria. All rights reserved.
* Copyright © 2010-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -35,8 +35,8 @@ extern "C" {
* from a core in another node.
* The corresponding kind is ::HWLOC_DISTANCES_KIND_FROM_OS | ::HWLOC_DISTANCES_KIND_FROM_USER.
* The name of this distances structure is "NUMALatency".
* Others distance structures include and "XGMIBandwidth", "XGMIHops"
* and "NVLinkBandwidth".
* Others distance structures include and "XGMIBandwidth", "XGMIHops",
* "XeLinkBandwidth" and "NVLinkBandwidth".
*
* The matrix may also contain bandwidths between random sets of objects,
* possibly provided by the user, as specified in the \p kind attribute.
@@ -160,7 +160,8 @@ hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type,
* Usually only one distances structure may match a given name.
*
* The name of the most common structure is "NUMALatency".
* Others include "XGMIBandwidth", "XGMIHops" and "NVLinkBandwidth".
* Others include "XGMIBandwidth", "XGMIHops", "XeLinkBandwidth",
* and "NVLinkBandwidth".
*/
HWLOC_DECLSPEC int
hwloc_distances_get_by_name(hwloc_topology_t topology, const char *name,

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012 Université Bordeaux
* Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -886,9 +886,6 @@ enum hwloc_distrib_flags_e {
* \p flags should be 0 or a OR'ed set of ::hwloc_distrib_flags_e.
*
* \note This function requires the \p roots objects to have a CPU set.
*
* \note This function replaces the now deprecated hwloc_distribute()
* and hwloc_distributev() functions.
*/
static __hwloc_inline int
hwloc_distrib(hwloc_topology_t topology,

View File

@@ -1,136 +0,0 @@
/*
* Copyright © 2013-2016 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
/** \file
* \brief Macros to help interaction between hwloc and Intel Xeon Phi (MIC).
*
* Applications that use both hwloc and Intel Xeon Phi (MIC) may want to
* include this file so as to get topology information for MIC devices.
*/
#ifndef HWLOC_INTEL_MIC_H
#define HWLOC_INTEL_MIC_H
#include "hwloc.h"
#include "hwloc/autogen/config.h"
#include "hwloc/helper.h"
#ifdef HWLOC_LINUX_SYS
#include "hwloc/linux.h"
#include <dirent.h>
#include <string.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup hwlocality_intel_mic Interoperability with Intel Xeon Phi (MIC)
*
* This interface offers ways to retrieve topology information about
* Intel Xeon Phi (MIC) devices.
*
* @{
*/
/** \brief Get the CPU set of logical processors that are physically
* close to MIC device whose index is \p idx.
*
* Return the CPU set describing the locality of the MIC device whose index is \p idx.
*
* Topology \p topology and device index \p idx must match the local machine.
* I/O devices detection is not needed in the topology.
*
* The function only returns the locality of the device.
* If more information about the device is needed, OS objects should
* be used instead, see hwloc_intel_mic_get_device_osdev_by_index().
*
* This function is currently only implemented in a meaningful way for
* Linux; other systems will simply get a full cpuset.
*/
static __hwloc_inline int
hwloc_intel_mic_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
int idx __hwloc_attribute_unused,
hwloc_cpuset_t set)
{
#ifdef HWLOC_LINUX_SYS
/* If we're on Linux, use the sysfs mechanism to get the local cpus */
#define HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX 128
char path[HWLOC_INTEL_MIC_DEVICE_SYSFS_PATH_MAX];
DIR *sysdir = NULL;
struct dirent *dirent;
unsigned pcibus, pcidev, pcifunc;
if (!hwloc_topology_is_thissystem(topology)) {
errno = EINVAL;
return -1;
}
sprintf(path, "/sys/class/mic/mic%d", idx);
sysdir = opendir(path);
if (!sysdir)
return -1;
while ((dirent = readdir(sysdir)) != NULL) {
if (sscanf(dirent->d_name, "pci_%02x:%02x.%02x", &pcibus, &pcidev, &pcifunc) == 3) {
sprintf(path, "/sys/class/mic/mic%d/pci_%02x:%02x.%02x/local_cpus", idx, pcibus, pcidev, pcifunc);
if (hwloc_linux_read_path_as_cpumask(path, set) < 0
|| hwloc_bitmap_iszero(set))
hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
break;
}
}
closedir(sysdir);
#else
/* Non-Linux systems simply get a full cpuset */
hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
#endif
return 0;
}
/** \brief Get the hwloc OS device object corresponding to the
* MIC device for the given index.
*
* Return the OS device object describing the MIC device whose index is \p idx.
* Return NULL if there is none.
*
* The topology \p topology does not necessarily have to match the current
* machine. For instance the topology may be an XML import of a remote host.
* I/O devices detection must be enabled in the topology.
*
* \note The corresponding PCI device object can be obtained by looking
* at the OS device parent object.
*/
static __hwloc_inline hwloc_obj_t
hwloc_intel_mic_get_device_osdev_by_index(hwloc_topology_t topology,
unsigned idx)
{
hwloc_obj_t osdev = NULL;
while ((osdev = hwloc_get_next_osdev(topology, osdev)) != NULL) {
if (HWLOC_OBJ_OSDEV_COPROC == osdev->attr->osdev.type
&& osdev->name
&& !strncmp("mic", osdev->name, 3)
&& atoi(osdev->name + 3) == (int) idx)
return osdev;
}
return NULL;
}
/** @} */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* HWLOC_INTEL_MIC_H */

View File

@@ -54,6 +54,8 @@ extern "C" {
* Attribute values for these nodes, if any, may then be obtained with
* hwloc_memattr_get_value() and manually compared with the desired criteria.
*
* \sa An example is available in doc/examples/memory-attributes.c in the source tree.
*
* \note The API also supports specific objects as initiator,
* but it is currently not used internally by hwloc.
* Users may for instance use it to provide custom performance
@@ -65,19 +67,19 @@ extern "C" {
/** \brief Memory node attributes. */
enum hwloc_memattr_id_e {
/** \brief "Capacity".
* The capacity is returned in bytes
* (local_memory attribute in objects).
/** \brief
* The \"Capacity\" is returned in bytes (local_memory attribute in objects).
*
* Best capacity nodes are nodes with <b>higher capacity</b>.
*
* No initiator is involved when looking at this attribute.
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_CAPACITY = 0,
/** \brief "Locality".
* The locality is returned as the number of PUs in that locality
/** \brief
* The \"Locality\" is returned as the number of PUs in that locality
* (e.g. the weight of its cpuset).
*
* Best locality nodes are nodes with <b>smaller locality</b>
@@ -87,26 +89,87 @@ enum hwloc_memattr_id_e {
*
* No initiator is involved when looking at this attribute.
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_LOCALITY = 1,
/** \brief "Bandwidth".
* The bandwidth is returned in MiB/s, as seen from the given initiator location.
/** \brief
* The \"Bandwidth\" is returned in MiB/s, as seen from the given initiator location.
*
* Best bandwidth nodes are nodes with <b>higher bandwidth</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
*
* This is the average bandwidth for read and write accesses. If the platform
* provides individual read and write bandwidths but no explicit average value,
* hwloc computes and returns the average.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_BANDWIDTH = 2,
/** \brief "Latency".
* The latency is returned as nanoseconds, as seen from the given initiator location.
/** \brief
* The \"ReadBandwidth\" is returned in MiB/s, as seen from the given initiator location.
*
* Best bandwidth nodes are nodes with <b>higher bandwidth</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_READ_BANDWIDTH = 4,
/** \brief
* The \"WriteBandwidth\" is returned in MiB/s, as seen from the given initiator location.
*
* Best bandwidth nodes are nodes with <b>higher bandwidth</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_WRITE_BANDWIDTH = 5,
/** \brief
* The \"Latency\" is returned as nanoseconds, as seen from the given initiator location.
*
* Best latency nodes are nodes with <b>smaller latency</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_LOWER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
*
* This is the average latency for read and write accesses. If the platform
* provides individual read and write latencies but no explicit average value,
* hwloc computes and returns the average.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_LATENCY = 3
HWLOC_MEMATTR_ID_LATENCY = 3,
/* TODO read vs write, persistence? */
/** \brief
* The \"ReadLatency\" is returned as nanoseconds, as seen from the given initiator location.
*
* Best latency nodes are nodes with <b>smaller latency</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_LOWER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_READ_LATENCY = 6,
/** \brief
* The \"WriteLatency\" is returned as nanoseconds, as seen from the given initiator location.
*
* Best latency nodes are nodes with <b>smaller latency</b>.
*
* The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_LOWER_FIRST
* and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
* \hideinitializer
*/
HWLOC_MEMATTR_ID_WRITE_LATENCY = 7,
/* TODO persistence? */
HWLOC_MEMATTR_ID_MAX /**< \private Sentinel value */
};
/** \brief A memory attribute identifier.

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2021 Inria. All rights reserved.
* Copyright © 2013-2022 Inria. All rights reserved.
* Copyright © 2016 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -338,9 +338,15 @@ struct hwloc_component {
* This function return 1 by default (show critical only),
* 0 in lstopo (show all),
* or anything set in HWLOC_HIDE_ERRORS in the environment.
*
* Use macros HWLOC_SHOW_CRITICAL_ERRORS() and HWLOC_SHOW_ALL_ERRORS()
* for clarity.
*/
HWLOC_DECLSPEC int hwloc_hide_errors(void);
#define HWLOC_SHOW_CRITICAL_ERRORS() (hwloc_hide_errors() < 2)
#define HWLOC_SHOW_ALL_ERRORS() (hwloc_hide_errors() == 0)
/** \brief Add an object to the topology.
*
* Insert new object \p obj in the topology starting under existing object \p root
@@ -501,6 +507,7 @@ hwloc_filter_check_pcidev_subtype_important(unsigned classid)
|| baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */
|| classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */
|| classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */
|| classid == 0x0502 /* PCI_CLASS_MEMORY_CXL */
|| baseclass == 0x06 /* PCI_BASE_CLASS_BRIDGE with non-PCI downstream. the core will drop the useless ones later */
|| baseclass == 0x12 /* Processing Accelerators */);
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2010-2021 Inria. All rights reserved.
* Copyright © 2010-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -123,6 +123,9 @@ extern "C" {
#define HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING)
#define HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING)
#define HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_DONT_CHANGE_BINDING)
#define HWLOC_TOPOLOGY_FLAG_NO_DISTANCES HWLOC_NAME_CAPS(TOPOLOGY_FLAG_NO_DISTANCES)
#define HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS HWLOC_NAME_CAPS(TOPOLOGY_FLAG_NO_MEMATTRS)
#define HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS HWLOC_NAME_CAPS(TOPOLOGY_FLAG_NO_CPUKINDS)
#define hwloc_topology_set_pid HWLOC_NAME(topology_set_pid)
#define hwloc_topology_set_synthetic HWLOC_NAME(topology_set_synthetic)
@@ -381,6 +384,11 @@ extern "C" {
#define HWLOC_MEMATTR_ID_LOCALITY HWLOC_NAME_CAPS(MEMATTR_ID_LOCALITY)
#define HWLOC_MEMATTR_ID_BANDWIDTH HWLOC_NAME_CAPS(MEMATTR_ID_BANDWIDTH)
#define HWLOC_MEMATTR_ID_LATENCY HWLOC_NAME_CAPS(MEMATTR_ID_LATENCY)
#define HWLOC_MEMATTR_ID_READ_BANDWIDTH HWLOC_NAME_CAPS(MEMATTR_ID_READ_BANDWIDTH)
#define HWLOC_MEMATTR_ID_WRITE_BANDWIDTH HWLOC_NAME_CAPS(MEMATTR_ID_WRITE_BANDWIDTH)
#define HWLOC_MEMATTR_ID_READ_LATENCY HWLOC_NAME_CAPS(MEMATTR_ID_READ_LATENCY)
#define HWLOC_MEMATTR_ID_WRITE_LATENCY HWLOC_NAME_CAPS(MEMATTR_ID_WRITE_LATENCY)
#define HWLOC_MEMATTR_ID_MAX HWLOC_NAME_CAPS(MEMATTR_ID_MAX)
#define hwloc_memattr_id_t HWLOC_NAME(memattr_id_t)
#define hwloc_memattr_get_by_name HWLOC_NAME(memattr_get_by_name)
@@ -862,6 +870,7 @@ extern "C" {
#define hwloc_internal_memattrs_destroy HWLOC_NAME(internal_memattrs_destroy)
#define hwloc_internal_memattrs_need_refresh HWLOC_NAME(internal_memattrs_need_refresh)
#define hwloc_internal_memattrs_refresh HWLOC_NAME(internal_memattrs_refresh)
#define hwloc_internal_memattrs_guess_memory_tiers HWLOC_NAME(internal_memattrs_guess_memory_tiers)
#define hwloc_internal_cpukind_s HWLOC_NAME(internal_cpukind_s)
#define hwloc_internal_cpukinds_init HWLOC_NAME(internal_cpukinds_init)

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012, 2020 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
*
@@ -259,6 +259,7 @@ struct hwloc_topology {
unsigned bus_first, bus_last;
hwloc_bitmap_t cpuset;
} * pci_forced_locality;
hwloc_uint64_t pci_locality_quirks;
/* component blacklisting */
unsigned nr_blacklisted_components;
@@ -419,6 +420,7 @@ extern void hwloc_internal_memattrs_need_refresh(hwloc_topology_t topology);
extern void hwloc_internal_memattrs_refresh(hwloc_topology_t topology);
extern int hwloc_internal_memattrs_dup(hwloc_topology_t new, hwloc_topology_t old);
extern int hwloc_internal_memattr_set_value(hwloc_topology_t topology, hwloc_memattr_id_t id, hwloc_obj_type_t target_type, hwloc_uint64_t target_gp_index, unsigned target_os_index, struct hwloc_internal_location_s *initiator, hwloc_uint64_t value);
extern int hwloc_internal_memattrs_guess_memory_tiers(hwloc_topology_t topology);
extern void hwloc_internal_cpukinds_init(hwloc_topology_t topology);
extern int hwloc_internal_cpukinds_rank(hwloc_topology_t topology);

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 Université Bordeaux
* Copyright © 2020 Inria. All rights reserved.
* Copyright © 2020-2022 Inria. All rights reserved.
*
* See COPYING in top-level directory.
*/
@@ -8,13 +8,22 @@
#ifndef HWLOC_PRIVATE_WINDOWS_H
#define HWLOC_PRIVATE_WINDOWS_H
#ifndef _ANONYMOUS_UNION
#ifdef __GNUC__
#define _ANONYMOUS_UNION __extension__
#define _ANONYMOUS_STRUCT __extension__
#else
#define _ANONYMOUS_UNION
#endif /* __GNUC__ */
#endif /* _ANONYMOUS_UNION */
#ifndef _ANONYMOUS_STRUCT
#ifdef __GNUC__
#define _ANONYMOUS_STRUCT __extension__
#else
#define _ANONYMOUS_STRUCT
#endif /* __GNUC__ */
#endif /* _ANONYMOUS_STRUCT */
#define DUMMYUNIONNAME
#define DUMMYSTRUCTNAME

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2012 Université Bordeaux
* See COPYING in top-level directory.
*/
@@ -386,7 +386,7 @@ hwloc_disc_component_register(struct hwloc_disc_component *component,
|HWLOC_DISC_PHASE_MISC
|HWLOC_DISC_PHASE_ANNOTATE
|HWLOC_DISC_PHASE_TWEAK))) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Cannot register discovery component `%s' with invalid phases 0x%x\n",
component->name, component->phases);
return -1;
@@ -476,7 +476,7 @@ hwloc_components_init(void)
/* hwloc_static_components is created by configure in static-components.h */
for(i=0; NULL != hwloc_static_components[i]; i++) {
if (hwloc_static_components[i]->flags) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Ignoring static component with invalid flags %lx\n",
hwloc_static_components[i]->flags);
continue;
@@ -505,7 +505,7 @@ hwloc_components_init(void)
#ifdef HWLOC_HAVE_PLUGINS
for(desc = hwloc_plugins; NULL != desc; desc = desc->next) {
if (desc->component->flags) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Ignoring plugin `%s' component with invalid flags %lx\n",
desc->name, desc->component->flags);
continue;
@@ -738,7 +738,7 @@ hwloc_disc_component_try_enable(struct hwloc_topology *topology,
backend = comp->instantiate(topology, comp, topology->backend_excluded_phases | blacklisted_phases,
NULL, NULL, NULL);
if (!backend) {
if (hwloc_components_verbose || (envvar_forced && hwloc_hide_errors() < 2))
if (hwloc_components_verbose || (envvar_forced && HWLOC_SHOW_CRITICAL_ERRORS()))
fprintf(stderr, "hwloc: Failed to instantiate discovery component `%s'\n", comp->name);
return -1;
}
@@ -835,7 +835,7 @@ hwloc_disc_components_enable_others(struct hwloc_topology *topology)
if (comp->phases & ~blacklisted_phases)
hwloc_disc_component_try_enable(topology, comp, 1 /* envvar forced */, blacklisted_phases);
} else {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Cannot find discovery component `%s'\n", name);
}
@@ -967,7 +967,7 @@ hwloc_backend_enable(struct hwloc_backend *backend)
/* check backend flags */
if (backend->flags) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Cannot enable discovery component `%s' phases 0x%x with unknown flags %lx\n",
backend->component->name, backend->component->phases, backend->flags);
return -1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2020-2021 Inria. All rights reserved.
* Copyright © 2020-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -504,7 +504,7 @@ hwloc_internal_cpukinds_rank(struct hwloc_topology *topology)
heuristics = HWLOC_CPUKINDS_RANKING_FORCED_EFFICIENCY;
else if (!strcmp(env, "no_forced_efficiency"))
heuristics = HWLOC_CPUKINDS_RANKING_NO_FORCED_EFFICIENCY;
else if (hwloc_hide_errors() < 2)
else if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Failed to recognize HWLOC_CPUKINDS_RANKING value %s\n", env);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2013-2020 Inria. All rights reserved.
* Copyright © 2013-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -218,7 +218,7 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
struct hwloc_info_s *info1 = &obj1->infos[i], *info2 = &obj2->infos[i];
if (strcmp(info1->name, info2->name))
goto out_too_complex;
if (strcmp(obj1->infos[i].value, obj2->infos[i].value)) {
if (strcmp(info1->value, info2->value)) {
err = hwloc_append_diff_obj_attr_string(obj1,
HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO,
info1->name,

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2010-2021 Inria. All rights reserved.
* Copyright © 2010-2022 Inria. All rights reserved.
* Copyright © 2011-2012 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -860,7 +860,7 @@ struct hwloc_distances_container_s {
struct hwloc_distances_s distances;
};
#define HWLOC_DISTANCES_CONTAINER_OFFSET ((char*)&((struct hwloc_distances_container_s*)NULL)->distances - (char*)NULL)
#define HWLOC_DISTANCES_CONTAINER_OFFSET ((uintptr_t)(&((struct hwloc_distances_container_s*)NULL)->distances) - (uintptr_t)NULL)
#define HWLOC_DISTANCES_CONTAINER(_d) (struct hwloc_distances_container_s *) ( ((char*)_d) - HWLOC_DISTANCES_CONTAINER_OFFSET )
static struct hwloc_internal_distances_s *

View File

@@ -1,11 +1,12 @@
/*
* Copyright © 2020-2021 Inria. All rights reserved.
* Copyright © 2020-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
#include "private/autogen/config.h"
#include "hwloc.h"
#include "private/private.h"
#include "private/debug.h"
/*****************************
@@ -49,36 +50,51 @@ hwloc__setup_memattr(struct hwloc_internal_memattr_s *imattr,
void
hwloc_internal_memattrs_prepare(struct hwloc_topology *topology)
{
#define NR_DEFAULT_MEMATTRS 4
topology->memattrs = malloc(NR_DEFAULT_MEMATTRS * sizeof(*topology->memattrs));
topology->memattrs = malloc(HWLOC_MEMATTR_ID_MAX * sizeof(*topology->memattrs));
if (!topology->memattrs)
return;
assert(HWLOC_MEMATTR_ID_CAPACITY < NR_DEFAULT_MEMATTRS);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_CAPACITY],
(char *) "Capacity",
HWLOC_MEMATTR_FLAG_HIGHER_FIRST,
HWLOC_IMATTR_FLAG_STATIC_NAME|HWLOC_IMATTR_FLAG_CONVENIENCE);
assert(HWLOC_MEMATTR_ID_LOCALITY < NR_DEFAULT_MEMATTRS);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_LOCALITY],
(char *) "Locality",
HWLOC_MEMATTR_FLAG_LOWER_FIRST,
HWLOC_IMATTR_FLAG_STATIC_NAME|HWLOC_IMATTR_FLAG_CONVENIENCE);
assert(HWLOC_MEMATTR_ID_BANDWIDTH < NR_DEFAULT_MEMATTRS);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_BANDWIDTH],
(char *) "Bandwidth",
HWLOC_MEMATTR_FLAG_HIGHER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
assert(HWLOC_MEMATTR_ID_LATENCY < NR_DEFAULT_MEMATTRS);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_READ_BANDWIDTH],
(char *) "ReadBandwidth",
HWLOC_MEMATTR_FLAG_HIGHER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_WRITE_BANDWIDTH],
(char *) "WriteBandwidth",
HWLOC_MEMATTR_FLAG_HIGHER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_LATENCY],
(char *) "Latency",
HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
topology->nr_memattrs = NR_DEFAULT_MEMATTRS;
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_READ_LATENCY],
(char *) "ReadLatency",
HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
hwloc__setup_memattr(&topology->memattrs[HWLOC_MEMATTR_ID_WRITE_LATENCY],
(char *) "WriteLatency",
HWLOC_MEMATTR_FLAG_LOWER_FIRST|HWLOC_MEMATTR_FLAG_NEED_INITIATOR,
HWLOC_IMATTR_FLAG_STATIC_NAME);
topology->nr_memattrs = HWLOC_MEMATTR_ID_MAX;
}
static void
@@ -1197,3 +1213,214 @@ hwloc_get_local_numanode_objs(hwloc_topology_t topology,
*nrp = i;
return 0;
}
/**************************************
* Using memattrs to identify HBM/DRAM
*/
struct hwloc_memory_tier_s {
hwloc_obj_t node;
uint64_t local_bw;
enum hwloc_memory_tier_type_e {
/* warning the order is important for guess_memory_tiers() after qsort() */
HWLOC_MEMORY_TIER_UNKNOWN,
HWLOC_MEMORY_TIER_DRAM,
HWLOC_MEMORY_TIER_HBM,
HWLOC_MEMORY_TIER_SPM, /* Specific-Purpose Memory is usually HBM, we'll use BW to confirm */
HWLOC_MEMORY_TIER_NVM,
HWLOC_MEMORY_TIER_GPU,
} type;
};
static int compare_tiers(const void *_a, const void *_b)
{
const struct hwloc_memory_tier_s *a = _a, *b = _b;
/* sort by type of tier first */
if (a->type != b->type)
return a->type - b->type;
/* then by bandwidth */
if (a->local_bw > b->local_bw)
return -1;
else if (a->local_bw < b->local_bw)
return 1;
return 0;
}
int
hwloc_internal_memattrs_guess_memory_tiers(hwloc_topology_t topology)
{
struct hwloc_internal_memattr_s *imattr;
struct hwloc_memory_tier_s *tiers;
unsigned i, j, n;
const char *env;
int spm_is_hbm = -1; /* -1 will guess from BW, 0 no, 1 forced */
int mark_dram = 1;
unsigned first_spm, first_nvm;
hwloc_uint64_t max_unknown_bw, min_spm_bw;
env = getenv("HWLOC_MEMTIERS_GUESS");
if (env) {
if (!strcmp(env, "none")) {
return 0;
} else if (!strcmp(env, "default")) {
/* nothing */
} else if (!strcmp(env, "spm_is_hbm")) {
hwloc_debug("Assuming SPM-tier is HBM, ignore bandwidth\n");
spm_is_hbm = 1;
} else if (HWLOC_SHOW_CRITICAL_ERRORS()) {
fprintf(stderr, "hwloc: Failed to recognize HWLOC_MEMTIERS_GUESS value %s\n", env);
}
}
imattr = &topology->memattrs[HWLOC_MEMATTR_ID_BANDWIDTH];
if (!(imattr->iflags & HWLOC_IMATTR_FLAG_CACHE_VALID))
hwloc__imattr_refresh(topology, imattr);
n = hwloc_get_nbobjs_by_depth(topology, HWLOC_TYPE_DEPTH_NUMANODE);
assert(n);
tiers = malloc(n * sizeof(*tiers));
if (!tiers)
return -1;
for(i=0; i<n; i++) {
hwloc_obj_t node;
const char *daxtype;
struct hwloc_internal_location_s iloc;
struct hwloc_internal_memattr_target_s *imtg = NULL;
struct hwloc_internal_memattr_initiator_s *imi;
node = hwloc_get_obj_by_depth(topology, HWLOC_TYPE_DEPTH_NUMANODE, i);
assert(node);
tiers[i].node = node;
/* defaults */
tiers[i].type = HWLOC_MEMORY_TIER_UNKNOWN;
tiers[i].local_bw = 0; /* unknown */
daxtype = hwloc_obj_get_info_by_name(node, "DAXType");
/* mark NVM, SPM and GPU nodes */
if (daxtype && !strcmp(daxtype, "NVM"))
tiers[i].type = HWLOC_MEMORY_TIER_NVM;
if (daxtype && !strcmp(daxtype, "SPM"))
tiers[i].type = HWLOC_MEMORY_TIER_SPM;
if (node->subtype && !strcmp(node->subtype, "GPUMemory"))
tiers[i].type = HWLOC_MEMORY_TIER_GPU;
if (spm_is_hbm == -1) {
for(j=0; j<imattr->nr_targets; j++)
if (imattr->targets[j].obj == node) {
imtg = &imattr->targets[j];
break;
}
if (imtg && !hwloc_bitmap_iszero(node->cpuset)) {
iloc.type = HWLOC_LOCATION_TYPE_CPUSET;
iloc.location.cpuset = node->cpuset;
imi = hwloc__memattr_target_get_initiator(imtg, &iloc, 0);
if (imi)
tiers[i].local_bw = imi->value;
}
}
}
/* sort tiers */
qsort(tiers, n, sizeof(*tiers), compare_tiers);
hwloc_debug("Sorting memory tiers...\n");
for(i=0; i<n; i++)
hwloc_debug(" tier %u = node L#%u P#%u with tier type %d and local BW #%llu\n",
i,
tiers[i].node->logical_index, tiers[i].node->os_index,
tiers[i].type, (unsigned long long) tiers[i].local_bw);
/* now we have UNKNOWN tiers (sorted by BW), then SPM tiers (sorted by BW), then NVM, then GPU */
/* iterate over UNKNOWN tiers, and find their BW */
for(i=0; i<n; i++) {
if (tiers[i].type > HWLOC_MEMORY_TIER_UNKNOWN)
break;
}
first_spm = i;
/* get max BW from first */
if (first_spm > 0)
max_unknown_bw = tiers[0].local_bw;
else
max_unknown_bw = 0;
/* there are no DRAM or HBM tiers yet */
/* iterate over SPM tiers, and find their BW */
for(i=first_spm; i<n; i++) {
if (tiers[i].type > HWLOC_MEMORY_TIER_SPM)
break;
}
first_nvm = i;
/* get min BW from last */
if (first_nvm > first_spm)
min_spm_bw = tiers[first_nvm-1].local_bw;
else
min_spm_bw = 0;
/* FIXME: if there's more than 10% between some sets of nodes inside a tier, split it? */
/* FIXME: if there are cpuset-intersecting nodes in same tier, abort? */
if (spm_is_hbm == -1) {
/* if we have BW for all SPM and UNKNOWN
* and all SPM BW are 2x superior to all UNKNOWN BW
*/
hwloc_debug("UNKNOWN-memory-tier max bandwidth %llu\n", (unsigned long long) max_unknown_bw);
hwloc_debug("SPM-memory-tier min bandwidth %llu\n", (unsigned long long) min_spm_bw);
if (max_unknown_bw > 0 && min_spm_bw > 0 && max_unknown_bw*2 < min_spm_bw) {
hwloc_debug("assuming SPM means HBM and !SPM means DRAM since bandwidths are very different\n");
spm_is_hbm = 1;
} else {
hwloc_debug("cannot assume SPM means HBM\n");
spm_is_hbm = 0;
}
}
if (spm_is_hbm) {
for(i=0; i<first_spm; i++)
tiers[i].type = HWLOC_MEMORY_TIER_DRAM;
for(i=first_spm; i<first_nvm; i++)
tiers[i].type = HWLOC_MEMORY_TIER_HBM;
}
if (first_spm == n)
mark_dram = 0;
/* now apply subtypes */
for(i=0; i<n; i++) {
const char *type = NULL;
if (tiers[i].node->subtype) /* don't overwrite the existing subtype */
continue;
switch (tiers[i].type) {
case HWLOC_MEMORY_TIER_DRAM:
if (mark_dram)
type = "DRAM";
break;
case HWLOC_MEMORY_TIER_HBM:
type = "HBM";
break;
case HWLOC_MEMORY_TIER_SPM:
type = "SPM";
break;
case HWLOC_MEMORY_TIER_NVM:
type = "NVM";
break;
default:
/* GPU memory is already marked with subtype="GPUMemory",
* UNKNOWN doesn't deserve any subtype
*/
break;
}
if (type) {
hwloc_debug("Marking node L#%u P#%u as %s\n", tiers[i].node->logical_index, tiers[i].node->os_index, type);
tiers[i].node->subtype = strdup(type);
}
}
free(tiers);
return 0;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* See COPYING in top-level directory.
*/
@@ -119,6 +119,13 @@ hwloc_pci_discovery_init(struct hwloc_topology *topology)
topology->pci_forced_locality = NULL;
topology->first_pci_locality = topology->last_pci_locality = NULL;
#define HWLOC_PCI_LOCALITY_QUIRK_CRAY_EX235A (1ULL<<0)
#define HWLOC_PCI_LOCALITY_QUIRK_FAKE (1ULL<<62)
topology->pci_locality_quirks = (uint64_t) -1;
/* -1 is unknown, 0 is disabled, >0 is bitmask of enabled quirks.
* bit 63 should remain unused so that -1 is unaccessible as a bitmask.
*/
}
void
@@ -146,7 +153,7 @@ hwloc_pci_discovery_prepare(struct hwloc_topology *topology)
}
free(buffer);
} else {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc/pci: Ignoring HWLOC_PCI_LOCALITY file `%s' too large (%lu bytes)\n",
env, (unsigned long) st.st_size);
}
@@ -333,7 +340,7 @@ hwloc_pci_add_object(struct hwloc_obj *parent, struct hwloc_obj **parent_io_firs
}
case HWLOC_PCI_BUSID_EQUAL: {
static int reported = 0;
if (!reported && hwloc_hide_errors() < 2) {
if (!reported && HWLOC_SHOW_CRITICAL_ERRORS()) {
fprintf(stderr, "*********************************************************\n");
fprintf(stderr, "* hwloc %s received invalid PCI information.\n", HWLOC_VERSION);
fprintf(stderr, "*\n");
@@ -442,13 +449,90 @@ hwloc_pcidisc_add_hostbridges(struct hwloc_topology *topology,
return new;
}
static struct hwloc_obj *
hwloc_pci_fixup_busid_parent(struct hwloc_topology *topology __hwloc_attribute_unused,
struct hwloc_pcidev_attr_s *busid __hwloc_attribute_unused,
struct hwloc_obj *parent __hwloc_attribute_unused)
/* return 1 if a quirk was applied */
static int
hwloc__pci_find_busid_parent_quirk(struct hwloc_topology *topology,
struct hwloc_pcidev_attr_s *busid,
hwloc_cpuset_t cpuset)
{
/* no quirk for now */
return parent;
if (topology->pci_locality_quirks == (uint64_t)-1 /* unknown */) {
const char *dmi_board_name, *env;
/* first invokation, detect which quirks are needed */
topology->pci_locality_quirks = 0; /* no quirk yet */
dmi_board_name = hwloc_obj_get_info_by_name(hwloc_get_root_obj(topology), "DMIBoardName");
if (dmi_board_name && !strcmp(dmi_board_name, "HPE CRAY EX235A")) {
hwloc_debug("enabling for PCI locality quirk for HPE Cray EX235A\n");
topology->pci_locality_quirks |= HWLOC_PCI_LOCALITY_QUIRK_CRAY_EX235A;
}
env = getenv("HWLOC_PCI_LOCALITY_QUIRK_FAKE");
if (env && atoi(env)) {
hwloc_debug("enabling for PCI locality fake quirk (attaching everything to last PU)\n");
topology->pci_locality_quirks |= HWLOC_PCI_LOCALITY_QUIRK_FAKE;
}
}
if (topology->pci_locality_quirks & HWLOC_PCI_LOCALITY_QUIRK_FAKE) {
unsigned last = hwloc_bitmap_last(hwloc_topology_get_topology_cpuset(topology));
hwloc_bitmap_set(cpuset, last);
return 1;
}
if (topology->pci_locality_quirks & HWLOC_PCI_LOCALITY_QUIRK_CRAY_EX235A) {
/* AMD Trento has xGMI ports connected to individual CCDs (8 cores + L3)
* instead of NUMA nodes (pairs of CCDs within Trento) as is usual in AMD EPYC CPUs.
* This is not described by the ACPI tables, hence we need to manually hardwire
* the xGMI locality for the (currently single) server that currently uses that CPU.
* It's not clear if ACPI tables can/will ever be fixed (would require one initiator
* proximity domain per CCD), or if Linux can/will work around the issue.
*/
if (busid->domain == 0) {
if (busid->bus >= 0xd0 && busid->bus <= 0xd1) {
hwloc_bitmap_set_range(cpuset, 0, 7);
hwloc_bitmap_set_range(cpuset, 64, 71);
return 1;
}
if (busid->bus >= 0xd4 && busid->bus <= 0xd6) {
hwloc_bitmap_set_range(cpuset, 8, 15);
hwloc_bitmap_set_range(cpuset, 72, 79);
return 1;
}
if (busid->bus >= 0xc8 && busid->bus <= 0xc9) {
hwloc_bitmap_set_range(cpuset, 16, 23);
hwloc_bitmap_set_range(cpuset, 80, 87);
return 1;
}
if (busid->bus >= 0xcc && busid->bus <= 0xce) {
hwloc_bitmap_set_range(cpuset, 24, 31);
hwloc_bitmap_set_range(cpuset, 88, 95);
return 1;
}
if (busid->bus >= 0xd8 && busid->bus <= 0xd9) {
hwloc_bitmap_set_range(cpuset, 32, 39);
hwloc_bitmap_set_range(cpuset, 96, 103);
return 1;
}
if (busid->bus >= 0xdc && busid->bus <= 0xde) {
hwloc_bitmap_set_range(cpuset, 40, 47);
hwloc_bitmap_set_range(cpuset, 104, 111);
return 1;
}
if (busid->bus >= 0xc0 && busid->bus <= 0xc1) {
hwloc_bitmap_set_range(cpuset, 48, 55);
hwloc_bitmap_set_range(cpuset, 112, 119);
return 1;
}
if (busid->bus >= 0xc4 && busid->bus <= 0xc6) {
hwloc_bitmap_set_range(cpuset, 56, 63);
hwloc_bitmap_set_range(cpuset, 120, 127);
return 1;
}
}
}
return 0;
}
static struct hwloc_obj *
@@ -457,7 +541,7 @@ hwloc__pci_find_busid_parent(struct hwloc_topology *topology, struct hwloc_pcide
hwloc_bitmap_t cpuset = hwloc_bitmap_alloc();
hwloc_obj_t parent;
int forced = 0;
int noquirks = 0;
int noquirks = 0, got_quirked = 0;
unsigned i;
int err;
@@ -490,7 +574,7 @@ hwloc__pci_find_busid_parent(struct hwloc_topology *topology, struct hwloc_pcide
if (env) {
static int reported = 0;
if (!topology->pci_has_forced_locality && !reported) {
if (!hwloc_hide_errors())
if (HWLOC_SHOW_ALL_ERRORS())
fprintf(stderr, "hwloc/pci: Environment variable %s is deprecated, please use HWLOC_PCI_LOCALITY instead.\n", env);
reported = 1;
}
@@ -505,7 +589,13 @@ hwloc__pci_find_busid_parent(struct hwloc_topology *topology, struct hwloc_pcide
}
}
if (!forced) {
if (!forced && !noquirks && topology->pci_locality_quirks /* either quirks are unknown yet, or some are enabled */) {
err = hwloc__pci_find_busid_parent_quirk(topology, busid, cpuset);
if (err > 0)
got_quirked = 1;
}
if (!forced && !got_quirked) {
/* get the cpuset by asking the backend that provides the relevant hook, if any. */
struct hwloc_backend *backend = topology->get_pci_busid_cpuset_backend;
if (backend)
@@ -520,11 +610,7 @@ hwloc__pci_find_busid_parent(struct hwloc_topology *topology, struct hwloc_pcide
hwloc_debug_bitmap(" will attach PCI bus to cpuset %s\n", cpuset);
parent = hwloc_find_insert_io_parent_by_complete_cpuset(topology, cpuset);
if (parent) {
if (!noquirks)
/* We found a valid parent. Check that the OS didn't report invalid locality */
parent = hwloc_pci_fixup_busid_parent(topology, busid, parent);
} else {
if (!parent) {
/* Fallback to root */
parent = hwloc_get_root_obj(topology);
}
@@ -805,19 +891,28 @@ hwloc_pcidisc_find_linkspeed(const unsigned char *config,
memcpy(&linksta, &config[offset + HWLOC_PCI_EXP_LNKSTA], 4);
speed = linksta & HWLOC_PCI_EXP_LNKSTA_SPEED; /* PCIe generation */
width = (linksta & HWLOC_PCI_EXP_LNKSTA_WIDTH) >> 4; /* how many lanes */
/* PCIe Gen1 = 2.5GT/s signal-rate per lane with 8/10 encoding = 0.25GB/s data-rate per lane
* PCIe Gen2 = 5 GT/s signal-rate per lane with 8/10 encoding = 0.5 GB/s data-rate per lane
* PCIe Gen3 = 8 GT/s signal-rate per lane with 128/130 encoding = 1 GB/s data-rate per lane
* PCIe Gen4 = 16 GT/s signal-rate per lane with 128/130 encoding = 2 GB/s data-rate per lane
* PCIe Gen5 = 32 GT/s signal-rate per lane with 128/130 encoding = 4 GB/s data-rate per lane
* PCIe Gen6 = 64 GT/s signal-rate per lane with 128/130 encoding = 8 GB/s data-rate per lane
/*
* These are single-direction bandwidths only.
*
* Gen1 used NRZ with 8/10 encoding.
* PCIe Gen1 = 2.5GT/s signal-rate per lane x 8/10 = 0.25GB/s data-rate per lane
* PCIe Gen2 = 5 GT/s signal-rate per lane x 8/10 = 0.5 GB/s data-rate per lane
* Gen3 switched to NRZ with 128/130 encoding.
* PCIe Gen3 = 8 GT/s signal-rate per lane x 128/130 = 1 GB/s data-rate per lane
* PCIe Gen4 = 16 GT/s signal-rate per lane x 128/130 = 2 GB/s data-rate per lane
* PCIe Gen5 = 32 GT/s signal-rate per lane x 128/130 = 4 GB/s data-rate per lane
* Gen6 switched to PAM with with 242/256 FLIT (242B payload protected by 8B CRC + 6B FEC).
* PCIe Gen6 = 64 GT/s signal-rate per lane x 242/256 = 8 GB/s data-rate per lane
* PCIe Gen7 = 128GT/s signal-rate per lane x 242/256 = 16 GB/s data-rate per lane
*/
/* lanespeed in Gbit/s */
if (speed <= 2)
lanespeed = 2.5f * speed * 0.8f;
else if (speed <= 5)
lanespeed = 8.0f * (1<<(speed-3)) * 128/130;
else
lanespeed = 8.0f * (1<<(speed-3)) * 128/130; /* assume Gen7 will be 128 GT/s and so on */
lanespeed = 8.0f * (1<<(speed-3)) * 242/256; /* assume Gen8 will be 256 GT/s and so on */
/* linkspeed in GB/s */
*linkspeed = lanespeed * width / 8;
@@ -944,6 +1039,7 @@ hwloc_pci_class_string(unsigned short class_id)
switch (class_id) {
case 0x0500: return "RAM";
case 0x0501: return "Flash";
case 0x0502: return "CXLMem";
}
return "Memory";
case 0x06:

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2020 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2010 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -323,17 +323,29 @@ hwloc_synthetic_parse_memory_attr(const char *attr, const char **endp)
hwloc_uint64_t size;
size = strtoull(attr, (char **) &endptr, 0);
if (!hwloc_strncasecmp(endptr, "TB", 2)) {
size *= 1000ULL*1000ULL*1000ULL*1000ULL;
endptr += 2;
} else if (!hwloc_strncasecmp(endptr, "TiB", 3)) {
size <<= 40;
endptr += 2;
endptr += 3;
} else if (!hwloc_strncasecmp(endptr, "GB", 2)) {
size *= 1000ULL*1000ULL*1000ULL;
endptr += 2;
} else if (!hwloc_strncasecmp(endptr, "GiB", 3)) {
size <<= 30;
endptr += 2;
endptr += 3;
} else if (!hwloc_strncasecmp(endptr, "MB", 2)) {
size *= 1000ULL*1000ULL;
endptr += 2;
} else if (!hwloc_strncasecmp(endptr, "MiB", 3)) {
size <<= 20;
endptr += 2;
endptr += 3;
} else if (!hwloc_strncasecmp(endptr, "kB", 2)) {
size <<= 10;
size *= 1000ULL;
endptr += 2;
} else if (!hwloc_strncasecmp(endptr, "kiB", 3)) {
size <<= 10;
endptr += 3;
}
*endp = endptr;
return size;
@@ -802,15 +814,15 @@ hwloc_backend_synthetic_init(struct hwloc_synthetic_backend_data_s *data,
} else if (hwloc__obj_type_is_cache(type)) {
if (!curlevel->attr.memorysize) {
if (1 == curlevel->attr.depth)
/* 32Kb in L1 */
/* 32KiB in L1 */
curlevel->attr.memorysize = 32*1024;
else
/* *4 at each level, starting from 1MB for L2, unified */
/* *4 at each level, starting from 1MiB for L2, unified */
curlevel->attr.memorysize = 256ULL*1024 << (2*curlevel->attr.depth);
}
} else if (type == HWLOC_OBJ_NUMANODE && !curlevel->attr.memorysize) {
/* 1GB in memory nodes. */
/* 1GiB in memory nodes. */
curlevel->attr.memorysize = 1024*1024*1024;
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012, 2020 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -366,7 +366,7 @@ hwloc_win_get_processor_groups(void)
hwloc_debug("found %lu windows processor groups\n", nr_processor_groups);
if (nr_processor_groups > 1 && SIZEOF_VOID_P == 4) {
if (!hwloc_hide_errors())
if (HWLOC_SHOW_ALL_ERRORS())
fprintf(stderr, "hwloc: multiple processor groups found on 32bits Windows, topology may be invalid/incomplete.\n");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2010-2021 Inria. All rights reserved.
* Copyright © 2010-2022 Inria. All rights reserved.
* Copyright © 2010-2013 Université Bordeaux
* Copyright © 2010-2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -1349,7 +1349,7 @@ look_procs(struct hwloc_backend *backend, struct procinfo *infos, unsigned long
if (data->apicid_unique) {
summarize(backend, infos, flags);
if (has_hybrid(features)) {
if (has_hybrid(features) && !(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS)) {
/* use hybrid info for cpukinds */
hwloc_bitmap_t atomset = hwloc_bitmap_alloc();
hwloc_bitmap_t coreset = hwloc_bitmap_alloc();

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2011, 2020 Université Bordeaux
* Copyright © 2009-2018 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
@@ -123,6 +123,17 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology,
fprintf(stderr, "%s: unexpected zero gp_index, topology may be invalid\n", state->global->msgprefix);
if (obj->gp_index >= topology->next_gp_index)
topology->next_gp_index = obj->gp_index + 1;
} else if (!strcmp(name, "id")) { /* forward compat */
if (!strncmp(value, "obj", 3)) {
obj->gp_index = strtoull(value+3, NULL, 10);
if (!obj->gp_index && hwloc__xml_verbose())
fprintf(stderr, "%s: unexpected zero id, topology may be invalid\n", state->global->msgprefix);
if (obj->gp_index >= topology->next_gp_index)
topology->next_gp_index = obj->gp_index + 1;
} else {
if (hwloc__xml_verbose())
fprintf(stderr, "%s: unexpected id `%s' not-starting with `obj', ignoring\n", state->global->msgprefix, value);
}
} else if (!strcmp(name, "cpuset")) {
if (!obj->cpuset)
obj->cpuset = hwloc_bitmap_alloc();
@@ -263,7 +274,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology,
#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN
} else if (domain > 0xffff) {
static int warned = 0;
if (!warned && hwloc_hide_errors() < 2)
if (!warned && HWLOC_SHOW_ALL_ERRORS())
fprintf(stderr, "hwloc/xml: Ignoring PCI device with non-16bit domain.\nPass --enable-32bits-pci-domain to configure to support such devices\n(warning: it would break the library ABI, don't enable unless really needed).\n");
warned = 1;
*ignore = 1;
@@ -363,7 +374,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology,
#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN
} else if (domain > 0xffff) {
static int warned = 0;
if (!warned && hwloc_hide_errors() < 2)
if (!warned && HWLOC_SHOW_ALL_ERRORS())
fprintf(stderr, "hwloc/xml: Ignoring bridge to PCI with non-16bit domain.\nPass --enable-32bits-pci-domain to configure to support such devices\n(warning: it would break the library ABI, don't enable unless really needed).\n");
warned = 1;
*ignore = 1;
@@ -1235,7 +1246,7 @@ hwloc__xml_import_object(hwloc_topology_t topology,
/* next should be before cur */
if (!childrengotignored) {
static int reported = 0;
if (!reported && hwloc_hide_errors() < 2) {
if (!reported && HWLOC_SHOW_CRITICAL_ERRORS()) {
hwloc__xml_import_report_outoforder(topology, next, cur);
reported = 1;
}
@@ -1568,6 +1579,9 @@ hwloc__xml_v2import_distances(hwloc_topology_t topology,
}
}
if (topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES)
goto out_ignore;
hwloc_internal_distances_add_by_index(topology, name, unique_type, different_types, nbobjs, indexes, u64values, kind, 0 /* assume grouping was applied when this matrix was discovered before exporting to XML */);
/* prevent freeing below */
@@ -1722,7 +1736,8 @@ hwloc__xml_import_memattr(hwloc_topology_t topology,
}
}
if (name && flags != (unsigned long) -1) {
if (name && flags != (unsigned long) -1
&& !(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS)) {
hwloc_memattr_id_t _id;
ret = hwloc_memattr_get_by_name(topology, name, &_id);
@@ -1833,7 +1848,13 @@ hwloc__xml_import_cpukind(hwloc_topology_t topology,
goto error;
}
if (topology->flags & HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS) {
hwloc__free_infos(infos, nr_infos);
hwloc_bitmap_free(cpuset);
} else {
hwloc_internal_cpukinds_register(topology, cpuset, forced_efficiency, infos, nr_infos, HWLOC_CPUKINDS_REGISTER_FLAG_OVERWRITE_FORCED_EFFICIENCY);
hwloc__free_infos(infos, nr_infos);
}
return state->global->close_tag(state);
@@ -2168,7 +2189,8 @@ done:
* but it would require to have those objects in the original XML order (like the first_numanode cousin-list).
* because the topology order can be different if some parents are ignored during load.
*/
if (nbobjs == data->nbnumanodes) {
if (nbobjs == data->nbnumanodes
&& !(topology->flags & HWLOC_TOPOLOGY_FLAG_NO_DISTANCES)) {
hwloc_obj_t *objs = malloc(nbobjs*sizeof(hwloc_obj_t));
uint64_t *values = malloc(nbobjs*nbobjs*sizeof(*values));
assert(data->nbnumanodes > 0); /* v1dist->nbobjs is >0 after import */
@@ -2650,7 +2672,7 @@ hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topolo
logical_to_v2array = malloc(nbobjs * sizeof(*logical_to_v2array));
if (!logical_to_v2array) {
if (!hwloc_hide_errors())
if (HWLOC_SHOW_ALL_ERRORS())
fprintf(stderr, "hwloc/xml/export/v1: failed to allocated logical_to_v2array\n");
continue;
}
@@ -3124,9 +3146,11 @@ hwloc__xml_export_memattrs(hwloc__xml_export_state_t state, hwloc_topology_t top
continue;
imattr = &topology->memattrs[id];
if ((id == HWLOC_MEMATTR_ID_LATENCY || id == HWLOC_MEMATTR_ID_BANDWIDTH)
&& !imattr->nr_targets)
/* no need to export target-less attributes for initial attributes, no release support attributes without those definitions */
if (id < HWLOC_MEMATTR_ID_MAX && !imattr->nr_targets)
/* no need to export standard attributes without any target,
* their definition is now standardized,
* the old hwloc importing this XML may recreate these attributes just like it would for a non-imported topology.
*/
continue;
state->new_child(state, &mstate, "memattr");

View File

@@ -1,6 +1,6 @@
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2021 Inria. All rights reserved.
* Copyright © 2009-2022 Inria. All rights reserved.
* Copyright © 2009-2012, 2020 Université Bordeaux
* Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
* Copyright © 2022 IBM Corporation. All rights reserved.
@@ -114,14 +114,25 @@ int hwloc_topology_abi_check(hwloc_topology_t topology)
return topology->topology_abi != HWLOC_TOPOLOGY_ABI ? -1 : 0;
}
/* callers should rather use wrappers HWLOC_SHOW_ALL_ERRORS() and HWLOC_SHOW_CRITICAL_ERRORS() for clarity */
int hwloc_hide_errors(void)
{
static int hide = 1; /* only show critical errors by default. lstopo will show others */
static int checked = 0;
if (!checked) {
const char *envvar = getenv("HWLOC_HIDE_ERRORS");
if (envvar)
if (envvar) {
hide = atoi(envvar);
#ifdef HWLOC_DEBUG
} else {
/* if debug is enabled and HWLOC_DEBUG_VERBOSE isn't forced to 0,
* show all errors jus like we show all debug messages.
*/
envvar = getenv("HWLOC_DEBUG_VERBOSE");
if (!envvar || atoi(envvar))
hide = 0;
#endif
}
checked = 1;
}
return hide;
@@ -158,7 +169,7 @@ static void report_insert_error(hwloc_obj_t new, hwloc_obj_t old, const char *ms
{
static int reported = 0;
if (reason && !reported && hwloc_hide_errors() < 2) {
if (reason && !reported && HWLOC_SHOW_CRITICAL_ERRORS()) {
char newstr[512];
char oldstr[512];
report_insert_error_format_obj(newstr, sizeof(newstr), new);
@@ -3178,7 +3189,7 @@ hwloc_connect_levels(hwloc_topology_t topology)
tmpnbobjs = realloc(topology->level_nbobjects,
2 * topology->nb_levels_allocated * sizeof(*topology->level_nbobjects));
if (!tmplevels || !tmpnbobjs) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: failed to realloc level arrays to %u\n", topology->nb_levels_allocated * 2);
/* if one realloc succeeded, make sure the caller will free the new buffer */
@@ -3536,6 +3547,8 @@ hwloc_discover(struct hwloc_topology *topology,
/*
* Additional discovery
*/
hwloc_pci_discovery_prepare(topology);
if (topology->backend_phases & HWLOC_DISC_PHASE_PCI) {
dstatus->phase = HWLOC_DISC_PHASE_PCI;
hwloc_discover_by_phase(topology, dstatus, "PCI");
@@ -3553,6 +3566,8 @@ hwloc_discover(struct hwloc_topology *topology,
hwloc_discover_by_phase(topology, dstatus, "ANNOTATE");
}
hwloc_pci_discovery_exit(topology); /* pci needed up to annotate */
if (getenv("HWLOC_DEBUG_SORT_CHILDREN"))
hwloc_debug_sort_children(topology->levels[0][0]);
@@ -3565,17 +3580,17 @@ hwloc_discover(struct hwloc_topology *topology,
hwloc_debug("%s", "\nRemoving empty objects\n");
remove_empty(topology, &topology->levels[0][0]);
if (!topology->levels[0][0]) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Topology became empty, aborting!\n");
return -1;
}
if (hwloc_bitmap_iszero(topology->levels[0][0]->cpuset)) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Topology does not contain any PU, aborting!\n");
return -1;
}
if (hwloc_bitmap_iszero(topology->levels[0][0]->nodeset)) {
if (hwloc_hide_errors() < 2)
if (HWLOC_SHOW_CRITICAL_ERRORS())
fprintf(stderr, "hwloc: Topology does not contain any NUMA node, aborting!\n");
return -1;
}
@@ -3811,7 +3826,16 @@ hwloc_topology_set_flags (struct hwloc_topology *topology, unsigned long flags)
return -1;
}
if (flags & ~(HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED|HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM|HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES|HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT|HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING|HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING|HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING)) {
if (flags & ~(HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED
|HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM
|HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES
|HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT
|HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING
|HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING
|HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING
|HWLOC_TOPOLOGY_FLAG_NO_DISTANCES
|HWLOC_TOPOLOGY_FLAG_NO_MEMATTRS
|HWLOC_TOPOLOGY_FLAG_NO_CPUKINDS)) {
errno = EINVAL;
return -1;
}
@@ -4076,15 +4100,11 @@ hwloc_topology_load (struct hwloc_topology *topology)
*/
hwloc_set_binding_hooks(topology);
hwloc_pci_discovery_prepare(topology);
/* actual topology discovery */
err = hwloc_discover(topology, &dstatus);
if (err < 0)
goto out;
hwloc_pci_discovery_exit(topology);
#ifndef HWLOC_DEBUG
if (getenv("HWLOC_DEBUG_CHECK"))
#endif
@@ -4106,6 +4126,7 @@ hwloc_topology_load (struct hwloc_topology *topology)
/* Same for memattrs */
hwloc_internal_memattrs_need_refresh(topology);
hwloc_internal_memattrs_refresh(topology);
hwloc_internal_memattrs_guess_memory_tiers(topology);
topology->is_loaded = 1;

View File

@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)
project (ethash C)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os")

View File

@@ -1,6 +1,13 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,15 +21,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include <cstdlib>
#include <uv.h>
@@ -33,6 +34,7 @@
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/io/Signals.h"
#include "base/kernel/Platform.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "Summary.h"
@@ -61,7 +63,12 @@ int xmrig::App::exec()
m_signals = std::make_shared<Signals>(this);
int rc = m_controller->init();
int rc = 0;
if (background(rc)) {
return rc;
}
rc = m_controller->init();
if (rc != 0) {
return rc;
}

View File

@@ -1,6 +1,13 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,13 +21,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_APP_H
@@ -60,6 +60,7 @@ protected:
void onSignal(int signum) override;
private:
bool background(int &rc);
void close();
std::shared_ptr<Console> m_console;

68
src/App_unix.cpp Normal file
View File

@@ -0,0 +1,68 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <csignal>
#include <cerrno>
#include <unistd.h>
#include "App.h"
#include "base/io/log/Log.h"
#include "core/Controller.h"
bool xmrig::App::background(int &rc)
{
if (!m_controller->isBackground()) {
return false;
}
int i = fork();
if (i < 0) {
rc = 1;
return true;
}
if (i > 0) {
rc = 0;
return true;
}
i = setsid();
if (i < 0) {
LOG_ERR("setsid() failed (errno = %d)", errno);
}
i = chdir("/");
if (i < 0) {
LOG_ERR("chdir() failed (errno = %d)", errno);
}
return false;
}

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,15 +22,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <winsock2.h>
#include <windows.h>
#include "base/kernel/Entry.h"
#include "App.h"
#include "core/Controller.h"
bool xmrig::Entry::background(int &)
bool xmrig::App::background(int &)
{
if (!m_controller->isBackground()) {
return false;
}
HWND hcon = GetConsoleWindow();
if (hcon) {
ShowWindow(hcon, SW_HIDE);

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -18,7 +18,7 @@
#include "backend/common/Worker.h"
#include "base/kernel/OS.h"
#include "base/kernel/Platform.h"
#include "crypto/common/VirtualMemory.h"
@@ -28,6 +28,6 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
{
m_node = VirtualMemory::bindToNUMANode(affinity);
OS::trySetThreadAffinity(affinity);
OS::setThreadPriority(priority);
Platform::trySetThreadAffinity(affinity);
Platform::setThreadPriority(priority);
}

View File

@@ -33,6 +33,7 @@
#include "crypto/common/Nonce.h"
#include "crypto/common/VirtualMemory.h"
#include "crypto/rx/Rx.h"
#include "crypto/rx/RxCache.h"
#include "crypto/rx/RxDataset.h"
#include "crypto/rx/RxVm.h"
#include "crypto/ghostrider/ghostrider.h"
@@ -77,8 +78,11 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
{
# ifdef XMRIG_ALGO_CN_HEAVY
// cn-heavy optimization for Zen3 CPUs
const bool is_vermeer = (Cpu::info()->arch() == ICpuInfo::ARCH_ZEN3) && (Cpu::info()->model() == 0x21);
if ((N == 1) && (m_av == CnHash::AV_SINGLE) && (m_algorithm.family() == Algorithm::CN_HEAVY) && (m_assembly != Assembly::NONE) && is_vermeer) {
const auto arch = Cpu::info()->arch();
const uint32_t model = Cpu::info()->model();
const bool is_vermeer = (arch == ICpuInfo::ARCH_ZEN3) && (model == 0x21);
const bool is_raphael = (arch == ICpuInfo::ARCH_ZEN4) && (model == 0x61);
if ((N == 1) && (m_av == CnHash::AV_SINGLE) && (m_algorithm.family() == Algorithm::CN_HEAVY) && (m_assembly != Assembly::NONE) && (is_vermeer || is_raphael)) {
std::lock_guard<std::mutex> lock(cn_heavyZen3MemoryMutex);
if (!cn_heavyZen3Memory) {
// Round up number of threads to the multiple of 8
@@ -142,6 +146,11 @@ void xmrig::CpuWorker<N>::allocateRandomX_VM()
uint8_t* scratchpad = m_memory->isHugePages() ? m_memory->scratchpad() : dataset->tryAllocateScrathpad();
m_vm = RxVm::create(dataset, scratchpad ? scratchpad : m_memory->scratchpad(), !m_hwAES, m_assembly, node());
}
else if (!dataset->get() && (m_job.currentJob().seed() != m_seed)) {
// Update RandomX light VM with the new seed
randomx_vm_set_cache(m_vm, dataset->cache()->get());
}
m_seed = m_job.currentJob().seed();
}
#endif

View File

@@ -97,6 +97,7 @@ private:
# ifdef XMRIG_ALGO_RANDOMX
randomx_vm *m_vm = nullptr;
Buffer m_seed;
# endif
# ifdef XMRIG_ALGO_GHOSTRIDER

View File

@@ -45,19 +45,21 @@ public:
ARCH_ZEN,
ARCH_ZEN_PLUS,
ARCH_ZEN2,
ARCH_ZEN3
ARCH_ZEN3,
ARCH_ZEN4
};
enum MsrMod : uint32_t {
MSR_MOD_NONE,
MSR_MOD_RYZEN_17H,
MSR_MOD_RYZEN_19H,
MSR_MOD_RYZEN_19H_ZEN4,
MSR_MOD_INTEL,
MSR_MOD_CUSTOM,
MSR_MOD_MAX
};
# define MSR_NAMES_LIST "none", "ryzen_17h", "ryzen_19h", "intel", "custom"
# define MSR_NAMES_LIST "none", "ryzen_17h", "ryzen_19h", "ryzen_19h_zen4", "intel", "custom"
enum Flag : uint32_t {
FLAG_AES,

View File

@@ -64,7 +64,7 @@ static_assert(kCpuFlagsSize == ICpuInfo::FLAG_MAX, "kCpuFlagsSize and FLAG_MAX m
#ifdef XMRIG_FEATURE_MSR
constexpr size_t kMsrArraySize = 5;
constexpr size_t kMsrArraySize = 6;
static const std::array<const char *, kMsrArraySize> msrNames = { MSR_NAMES_LIST };
static_assert(kMsrArraySize == ICpuInfo::MSR_MOD_MAX, "kMsrArraySize and MSR_MOD_MAX mismatch");
#endif
@@ -250,8 +250,14 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
break;
case 0x19:
if (m_model == 0x61) {
m_arch = ARCH_ZEN4;
m_msrMod = MSR_MOD_RYZEN_19H_ZEN4;
}
else {
m_arch = ARCH_ZEN3;
m_msrMod = MSR_MOD_RYZEN_19H;
}
break;
default:

View File

@@ -27,7 +27,7 @@
#if __ARM_FEATURE_CRYPTO && !defined(__APPLE__)
# include <sys/auxv.h>
# ifndef __FreeBSD__
# if !defined(XMRIG_OS_FREEBSD)
# include <asm/hwcap.h>
# else
# include <stdint.h>
@@ -71,7 +71,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
# if __ARM_FEATURE_CRYPTO
# if defined(__APPLE__)
m_flags.set(FLAG_AES, true);
# elif defined(__FreeBSD__)
# elif defined(XMRIG_OS_FREEBSD)
uint64_t isar0 = READ_SPECIALREG(id_aa64isar0_el1);
m_flags.set(FLAG_AES, ID_AA64ISAR0_AES_VAL(isar0) >= ID_AA64ISAR0_AES_BASE);
# else

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -25,7 +25,7 @@
#include "base/crypto/keccak.h"
#include "base/io/Env.h"
#include "base/io/json/Json.h"
#include "base/kernel/OS.h"
#include "base/kernel/Base.h"
#include "base/tools/Chrono.h"
#include "base/tools/Cvt.h"
#include "core/config/Config.h"
@@ -232,6 +232,6 @@ void xmrig::Api::genWorkerId(const String &id)
{
m_workerId = Env::expand(id);
if (m_workerId.isEmpty()) {
m_workerId = OS::hostname();
m_workerId = Env::hostname();
}
}

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,6 +22,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/api/requests/ApiRequest.h"

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,6 +22,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_APIREQUEST_H
#define XMRIG_APIREQUEST_H

View File

@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/api/requests/HttpApiRequest.h"
#include "3rdparty/llhttp/llhttp.h"
#include "3rdparty/rapidjson/error/en.h"

View File

@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTPAPIREQUEST_H
#define XMRIG_HTTPAPIREQUEST_H

View File

@@ -18,9 +18,10 @@ set(HEADERS_BASE
src/base/io/log/Tags.h
src/base/io/Signals.h
src/base/io/Watcher.h
src/base/kernel/v6/Base.h
src/base/kernel/v6/config/BaseConfig.h
src/base/kernel/v6/config/BaseTransform.h
src/base/kernel/Base.h
src/base/kernel/config/BaseConfig.h
src/base/kernel/config/BaseTransform.h
src/base/kernel/config/Title.h
src/base/kernel/constants.h
src/base/kernel/Entry.h
src/base/kernel/interfaces/IAsyncListener.h
@@ -28,6 +29,7 @@ set(HEADERS_BASE
src/base/kernel/interfaces/IClient.h
src/base/kernel/interfaces/IClientListener.h
src/base/kernel/interfaces/IConfig.h
src/base/kernel/interfaces/IConfigListener.h
src/base/kernel/interfaces/IConfigTransform.h
src/base/kernel/interfaces/IConsoleListener.h
src/base/kernel/interfaces/IDnsBackend.h
@@ -39,13 +41,10 @@ set(HEADERS_BASE
src/base/kernel/interfaces/IStrategyListener.h
src/base/kernel/interfaces/ITimerListener.h
src/base/kernel/interfaces/IWatcherListener.h
src/base/kernel/Lib.h
src/base/kernel/OS.h
src/base/kernel/private/DnsConfig.h
src/base/kernel/private/Title.h
src/base/kernel/Platform.h
src/base/kernel/Process.h
src/base/kernel/Versions.h
src/base/net/dns/Dns.h
src/base/net/dns/DnsConfig.h
src/base/net/dns/DnsRecord.h
src/base/net/dns/DnsRecords.h
src/base/net/dns/DnsRequest.h
@@ -107,17 +106,15 @@ set(SOURCES_BASE
src/base/io/log/Tags.cpp
src/base/io/Signals.cpp
src/base/io/Watcher.cpp
src/base/kernel/v6/Base.cpp
src/base/kernel/v6/config/BaseConfig.cpp
src/base/kernel/v6/config/BaseTransform.cpp
src/base/kernel/Base.cpp
src/base/kernel/config/BaseConfig.cpp
src/base/kernel/config/BaseTransform.cpp
src/base/kernel/config/Title.cpp
src/base/kernel/Entry.cpp
src/base/kernel/Lib.cpp
src/base/kernel/OS.cpp
src/base/kernel/private/DnsConfig.cpp
src/base/kernel/private/Title.cpp
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp
src/base/kernel/Versions.cpp
src/base/net/dns/Dns.cpp
src/base/net/dns/DnsConfig.cpp
src/base/net/dns/DnsRecord.cpp
src/base/net/dns/DnsRecords.cpp
src/base/net/dns/DnsUvBackend.cpp
@@ -151,22 +148,19 @@ set(SOURCES_BASE
if (WIN32)
set(SOURCES_OS
src/base/io/json/Json_win.cpp
src/base/kernel/Entry_win.cpp
src/base/kernel/OS_win.cpp
src/base/kernel/Platform_win.cpp
src/base/kernel/Process_win.cpp
)
elseif (APPLE)
set(SOURCES_OS
src/base/io/json/Json_unix.cpp
src/base/kernel/Entry_unix.cpp
src/base/kernel/OS_mac.cpp
src/base/kernel/Platform_mac.cpp
src/base/kernel/Process_unix.cpp
)
else()
set(SOURCES_OS
src/base/io/json/Json_unix.cpp
src/base/kernel/Entry_unix.cpp
src/base/kernel/OS_unix.cpp
src/base/kernel/Platform_unix.cpp
src/base/kernel/Process_unix.cpp
)
endif()
@@ -174,7 +168,7 @@ endif()
if (WITH_HWLOC)
list(APPEND SOURCES_OS
src/base/kernel/OS_hwloc.cpp
src/base/kernel/Platform_hwloc.cpp
)
endif()

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -209,7 +209,7 @@ private:
using Algorithms = std::vector<Algorithm>;
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_ALGORITHM_H
#endif /* XMRIG_ALGORITHM_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -82,7 +82,7 @@ private:
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_COIN_H
#endif /* XMRIG_COIN_H */

View File

@@ -1,7 +1,13 @@
/* XMRig
* Copyright (c) 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -17,6 +23,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory.h>

View File

@@ -1,7 +1,13 @@
/* XMRig
* Copyright (c) 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,8 +1,8 @@
/* XMRig
* Copyright (c) 2015-2020 libuv project contributors.
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,8 +1,8 @@
/* XMRig
* Copyright (c) 2015-2020 libuv project contributors.
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,98 +14,16 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include "base/io/Console.h"
#include "base/io/log/Log.h"
#include "base/io/Signals.h"
#include "base/kernel/interfaces/IConsoleListener.h"
#include "base/kernel/private/Title.h"
#include "base/kernel/Process.h"
#include "base/tools/Cvt.h"
#include "base/tools/Handle.h"
#ifdef XMRIG_FEATURE_EVENTS
# include "base/kernel/Events.h"
# include "base/kernel/events/ConsoleEvent.h"
#endif
namespace xmrig {
class Console::Private : public IConsoleListener
xmrig::Console::Console(IConsoleListener *listener)
: m_listener(listener)
{
public:
XMRIG_DISABLE_COPY_MOVE(Private)
Private();
~Private() override;
# ifdef XMRIG_OS_WIN
std::wstring title;
# endif
IConsoleListener *listener = nullptr;
protected:
void onConsoleCommand(char command) override;
private:
static bool isSupported();
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
char m_buf[1] = { 0 };
uv_tty_t *m_tty = nullptr;
};
} // namespace xmrig
xmrig::Console::Console() :
d(std::make_shared<Private>())
{
d->listener = d.get();
}
xmrig::Console::Console(IConsoleListener *listener) :
d(std::make_shared<Private>())
{
d->listener = listener;
}
#ifdef XMRIG_OS_WIN
void xmrig::Console::setTitle(const Title &title) const
{
SetConsoleTitleW(title.isEnabled() ? Cvt::toUtf16(title.value()).c_str() : d->title.c_str());
}
#endif
xmrig::Console::Private::Private()
{
# ifdef XMRIG_OS_WIN
{
constexpr size_t kMaxTitleLength = 8192;
wchar_t title_w[kMaxTitleLength]{};
title = { title_w, GetConsoleTitleW(title_w, kMaxTitleLength) };
}
# endif
if (!isSupported()) {
return;
}
@@ -119,11 +37,11 @@ xmrig::Console::Private::Private()
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_RAW);
uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), onAllocBuffer, onRead);
uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), Console::onAllocBuffer, Console::onRead);
}
xmrig::Console::Private::~Private()
xmrig::Console::~Console()
{
uv_tty_reset_mode();
@@ -131,45 +49,28 @@ xmrig::Console::Private::~Private()
}
void xmrig::Console::Private::onConsoleCommand(char command)
{
# ifdef XMRIG_FEATURE_EVENTS
if (command == 3) {
LOG_WARN("%s " YELLOW_BOLD("Ctrl+C ") YELLOW("received, exiting"), Signals::tag());
Process::exit(0);
}
else {
Process::events().send<ConsoleEvent>(command);
}
# else
assert(!command);
# endif
}
bool xmrig::Console::Private::isSupported()
bool xmrig::Console::isSupported()
{
const uv_handle_type type = uv_guess_handle(0);
return type == UV_TTY || type == UV_NAMED_PIPE;
}
void xmrig::Console::Private::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
{
auto console = static_cast<Private *>(handle->data);
auto console = static_cast<Console*>(handle->data);
buf->len = 1;
buf->base = console->m_buf;
}
void xmrig::Console::Private::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
void xmrig::Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
{
if (nread < 0) {
return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);
}
if (nread == 1) {
static_cast<Private *>(stream->data)->listener->onConsoleCommand(*buf->base);
static_cast<Console*>(stream->data)->m_listener->onConsoleCommand(buf->base[0]);
}
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,13 +14,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_CONSOLE_H
@@ -30,32 +23,45 @@
#include "base/tools/Object.h"
using uv_buf_t = struct uv_buf_t;
using uv_handle_t = struct uv_handle_s;
using uv_stream_t = struct uv_stream_s;
using uv_tty_t = struct uv_tty_s;
#ifdef XMRIG_OS_WIN
using ssize_t = intptr_t;
#else
# include <sys/types.h>
#endif
namespace xmrig {
class Title;
class IConsoleListener;
class Console
{
public:
XMRIG_DISABLE_COPY_MOVE(Console)
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Console)
Console();
explicit Console(IConsoleListener *listener);
~Console() = default;
# ifdef XMRIG_OS_WIN
void setTitle(const Title &title) const;
# endif
Console(IConsoleListener *listener);
~Console();
private:
XMRIG_DECL_PRIVATE()
static bool isSupported();
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
char m_buf[1] = { 0 };
IConsoleListener *m_listener;
uv_tty_t *m_tty = nullptr;
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_CONSOLE_H
#endif /* XMRIG_CONSOLE_H */

View File

@@ -17,15 +17,29 @@
*/
#include "base/io/Env.h"
#include "base/kernel/OS.h"
#include "base/kernel/Process.h"
#include "version.h"
#include <regex>
#include <uv.h>
#include <map>
#ifndef _WIN32
# include <unistd.h>
#endif
#ifndef UV_MAXHOSTNAMESIZE
# ifdef MAXHOSTNAMELEN
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
# else
# define UV_MAXHOSTNAMESIZE 256
# endif
#endif
namespace xmrig {
@@ -37,17 +51,17 @@ static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_KIND", APP_KIND });
variables.insert({ "XMRIG_HOSTNAME", OS::hostname() });
variables.insert({ "XMRIG_EXE", Process::locate(Process::ExePathLocation) });
variables.insert({ "XMRIG_EXE_DIR", Process::locate(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::locate(Process::CwdLocation) });
variables.insert({ "XMRIG_HOME_DIR", Process::locate(Process::HomeLocation) });
variables.insert({ "XMRIG_TEMP_DIR", Process::locate(Process::TempLocation) });
variables.insert({ "XMRIG_DATA_DIR", Process::locate(Process::DataLocation) });
variables.insert({ "XMRIG_HOSTNAME", Env::hostname() });
variables.insert({ "XMRIG_EXE", Process::exepath() });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
String hostname = "HOSTNAME";
if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe)
variables.insert({ std::move(hostname), OS::hostname() });
variables.insert({ std::move(hostname), Env::hostname() });
}
}
#endif
@@ -124,3 +138,15 @@ xmrig::String xmrig::Env::get(const String &name, const std::map<String, String>
return static_cast<const char *>(getenv(name)); // NOLINT(concurrency-mt-unsafe)
}
xmrig::String xmrig::Env::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
if (gethostname(buf, sizeof(buf)) == 0) {
return static_cast<const char *>(buf);
}
return {};
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -34,6 +34,7 @@ class Env
public:
static String expand(const char *in, const std::map<String, String> &extra = {});
static String get(const String &name, const std::map<String, String> &extra = {});
static String hostname();
};

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,113 +14,25 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include "base/io/Signals.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/ISignalListener.h"
#include "base/kernel/Process.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/io/Signals.h"
#include "base/tools/Handle.h"
#ifdef XMRIG_FEATURE_EVENTS
# include "base/kernel/Events.h"
# include "base/kernel/events/SignalEvent.h"
#endif
#include <csignal>
namespace xmrig {
#ifdef SIGUSR1
constexpr static const size_t kSignalsCount = 4;
constexpr static const int signums[kSignalsCount] = { SIGHUP, SIGINT, SIGTERM, SIGUSR1 };
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM, SIGUSR1 };
#else
constexpr static const size_t kSignalsCount = 3;
constexpr static const int signums[kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
#endif
#ifdef XMRIG_FEATURE_EVENTS
static const char *signame(int signum)
{
switch (signum) {
case SIGHUP:
return "SIGHUP";
case SIGINT:
return "SIGINT";
case SIGTERM:
return "SIGTERM";
default:
break;
}
return nullptr;
}
#endif
class Signals::Private : public ISignalListener
{
public:
XMRIG_DISABLE_COPY_MOVE(Private)
Private();
~Private() override;
ISignalListener *listener = nullptr;
protected:
void onSignal(int signum) override;
private:
static void onSignal(uv_signal_t *handle, int signum);
uv_signal_t *signals[kSignalsCount]{};
};
} // namespace xmrig
xmrig::Signals::Signals() :
d(std::make_shared<Private>())
{
d->listener = d.get();
}
xmrig::Signals::Signals(ISignalListener *listener) :
d(std::make_shared<Private>())
{
d->listener = listener;
}
const char *xmrig::Signals::tag()
{
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
return tag;
}
xmrig::Signals::Private::Private()
xmrig::Signals::Signals(ISignalListener *listener)
: m_listener(listener)
{
# ifndef XMRIG_OS_WIN
signal(SIGPIPE, SIG_IGN);
@@ -130,44 +42,47 @@ xmrig::Signals::Private::Private()
auto signal = new uv_signal_t;
signal->data = this;
signals[i] = signal;
m_signals[i] = signal;
uv_signal_init(uv_default_loop(), signal);
uv_signal_start(signal, onSignal, signums[i]);
uv_signal_start(signal, Signals::onSignal, signums[i]);
}
}
xmrig::Signals::Private::~Private()
xmrig::Signals::~Signals()
{
for (auto signal : signals) {
for (auto signal : m_signals) {
Handle::close(signal);
}
}
void xmrig::Signals::Private::onSignal(int signum)
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
{
# ifdef XMRIG_FEATURE_EVENTS
Process::events().send<SignalEvent>(signum);
switch (signum)
{
case SIGHUP:
case SIGTERM:
case SIGINT:
LOG_WARN("%s " YELLOW_BOLD("%s ") YELLOW("received, exiting"), tag(), signame(signum));
Process::exit(128 + signum);
LOG_WARN("%s " YELLOW("SIGHUP received, exiting"), Tags::signal());
break;
case SIGTERM:
LOG_WARN("%s " YELLOW("SIGTERM received, exiting"), Tags::signal());
break;
case SIGINT:
LOG_WARN("%s " YELLOW("SIGINT received, exiting"), Tags::signal());
break;
# ifdef SIGUSR1
case SIGUSR1:
LOG_V5("%s " WHITE_BOLD("SIGUSR1 received"), Tags::signal());
break;
# endif
default:
break;
}
# endif
}
void xmrig::Signals::Private::onSignal(uv_signal_t *handle, int signum)
{
static_cast<Private *>(handle->data)->listener->onSignal(signum);
static_cast<Signals *>(handle->data)->m_listener->onSignal(signum);
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,13 +14,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_SIGNALS_H
@@ -30,6 +23,13 @@
#include "base/tools/Object.h"
#include <csignal>
#include <cstddef>
using uv_signal_t = struct uv_signal_s;
namespace xmrig {
@@ -39,20 +39,28 @@ class ISignalListener;
class Signals
{
public:
XMRIG_DISABLE_COPY_MOVE(Signals)
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Signals)
Signals();
explicit Signals(ISignalListener *listener);
~Signals() = default;
# ifdef SIGUSR1
constexpr static const size_t kSignalsCount = 4;
# else
constexpr static const size_t kSignalsCount = 3;
# endif
static const char *tag();
Signals(ISignalListener *listener);
~Signals();
private:
XMRIG_DECL_PRIVATE()
void close(int signum);
static void onSignal(uv_signal_t *handle, int signum);
ISignalListener *m_listener;
uv_signal_t *m_signals[kSignalsCount]{};
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_SIGNALS_H
#endif /* XMRIG_SIGNALS_H */

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,45 +20,37 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include "base/io/Watcher.h"
#include <uv.h>
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/io/Watcher.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) :
m_path(path),
m_listener(listener)
m_listener(listener),
m_path(path)
{
m_timer = std::make_shared<Timer>(this);
m_timer = new Timer(this);
startTimer();
m_fsEvent = new uv_fs_event_t;
m_fsEvent->data = this;
uv_fs_event_init(uv_default_loop(), m_fsEvent);
start();
}
xmrig::Watcher::~Watcher()
{
Handle::close(m_event);
}
delete m_timer;
void xmrig::Watcher::onTimer(const Timer * /*timer*/)
{
if (m_event) {
reload();
}
else {
start();
}
Handle::close(m_fsEvent);
}
@@ -62,7 +60,14 @@ void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int,
return;
}
static_cast<Watcher *>(handle->data)->startTimer();
static_cast<Watcher *>(handle->data)->queueUpdate();
}
void xmrig::Watcher::queueUpdate()
{
m_timer->stop();
m_timer->start(kDelay, 0);
}
@@ -70,8 +75,8 @@ void xmrig::Watcher::reload()
{
m_listener->onFileChanged(m_path);
# ifndef XMRIG_OS_WIN
stop();
# ifndef _WIN32
uv_fs_event_stop(m_fsEvent);
start();
# endif
}
@@ -79,23 +84,5 @@ void xmrig::Watcher::reload()
void xmrig::Watcher::start()
{
if (!m_event) {
m_event = new uv_fs_event_t;
m_event->data = this;
uv_fs_event_init(uv_default_loop(), m_event);
}
uv_fs_event_start(m_event, onFsEvent, m_path, 0);
}
void xmrig::Watcher::startTimer()
{
m_timer->singleShot(kDelay);
}
void xmrig::Watcher::stop()
{
uv_fs_event_stop(m_event);
uv_fs_event_start(m_fsEvent, xmrig::Watcher::onFsEvent, m_path, 0);
}

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -14,13 +20,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_WATCHER_H
@@ -31,10 +30,7 @@
#include "base/tools/String.h"
#include <memory>
using uv_fs_event_t = struct uv_fs_event_s;
typedef struct uv_fs_event_s uv_fs_event_t;
namespace xmrig {
@@ -47,32 +43,29 @@ class Timer;
class Watcher : public ITimerListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Watcher)
Watcher(const String &path, IWatcherListener *listener);
~Watcher() override;
protected:
void onTimer(const Timer *timer) override;
inline void onTimer(const Timer *) override { reload(); }
private:
constexpr static int kDelay = 500;
static void onFsEvent(uv_fs_event_t *handle, const char *filename, int events, int status);
void queueUpdate();
void reload();
void start();
void startTimer();
void stop();
const String m_path;
IWatcherListener *m_listener;
std::shared_ptr<Timer> m_timer;
uv_fs_event_t *m_event = nullptr;
String m_path;
Timer *m_timer;
uv_fs_event_t *m_fsEvent;
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_WATCHER_H
#endif /* XMRIG_WATCHER_H */

View File

@@ -34,21 +34,37 @@
#include "3rdparty/rapidjson/istreamwrapper.h"
#include "3rdparty/rapidjson/ostreamwrapper.h"
#include "3rdparty/rapidjson/prettywriter.h"
#include "base/tools/Cvt.h"
namespace xmrig {
#if defined(_MSC_VER) || defined (__GNUC__)
static std::wstring toUtf16(const char *str)
{
const int size = static_cast<int>(strlen(str));
std::wstring ret;
int len = MultiByteToWideChar(CP_UTF8, 0, str, size, nullptr, 0);
if (len > 0) {
ret.resize(static_cast<size_t>(len));
MultiByteToWideChar(CP_UTF8, 0, str, size, &ret[0], len);
}
return ret;
}
#endif
#if defined(_MSC_VER)
# define OPEN_IFS(name) \
std::ifstream ifs(Cvt::toUtf16(name), std::ios_base::in | std::ios_base::binary); \
std::ifstream ifs(toUtf16(name), std::ios_base::in | std::ios_base::binary); \
if (!ifs.is_open()) { \
return false; \
}
#elif defined(__GNUC__)
# define OPEN_IFS(name) \
const int fd = _wopen(Cvt::toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \
const int fd = _wopen(toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \
if (fd == -1) { \
return false; \
} \
@@ -83,12 +99,12 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
constexpr const std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary | std::ios_base::trunc;
# if defined(_MSC_VER)
std::ofstream ofs(Cvt::toUtf16(fileName), mode);
std::ofstream ofs(toUtf16(fileName), mode);
if (!ofs.is_open()) {
return false;
}
# elif defined(__GNUC__)
const int fd = _wopen(Cvt::toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IWRITE);
const int fd = _wopen(toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IWRITE);
if (fd == -1) {
return false;
}

View File

@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/log/FileLogWriter.h"
#include "base/io/Env.h"

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -15,16 +15,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifdef XMRIG_OS_WIN
#ifdef WIN32
# include <winsock2.h>
# include <windows.h>
#endif
@@ -32,93 +25,103 @@
#include <algorithm>
#include <cassert>
#include <cstdarg>
#include <cstring>
#include <ctime>
#include <mutex>
#include <string>
#include <uv.h>
#include <vector>
#include "base/io/log/Log.h"
#include "base/tools/Chrono.h"
#ifdef XMRIG_FEATURE_EVENTS
# include "base/kernel/Events.h"
# include "base/kernel/events/LogEvent.h"
# include "base/kernel/private/LogConfig.h"
# include "base/kernel/Process.h"
#else
#include "base/kernel/interfaces/ILogBackend.h"
#endif
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
namespace xmrig {
bool Log::m_background = false;
bool Log::m_colors = true;
LogPrivate *Log::d = nullptr;
uint32_t Log::m_verbose = 0;
static char buf[Log::kMaxBufferSize]{};
static std::mutex mutex;
static const char *colors_map[] = {
RED_BOLD_S "E ", // EMERG
RED_BOLD_S "A ", // ALERT
RED_BOLD_S "C ", // CRIT
RED_S "E ", // ERR
YELLOW_S "W ", // WARNING
WHITE_BOLD_S "N ", // NOTICE
"I ", // INFO
"1 ", // V1
"2 ", // V2
"3 ", // V3
"4 ", // V4
# ifdef XMRIG_OS_WIN
BLACK_BOLD_S "5 ", // V5
BLACK_BOLD_S "D " // DEBUG
RED_BOLD_S, // EMERG
RED_BOLD_S, // ALERT
RED_BOLD_S, // CRIT
RED_S, // ERR
YELLOW_S, // WARNING
WHITE_BOLD_S, // NOTICE
nullptr, // INFO
# ifdef WIN32
BLACK_BOLD_S // DEBUG
# else
BRIGHT_BLACK_S "5 ", // V5
BRIGHT_BLACK_S "D " // DEBUG
BRIGHT_BLACK_S // DEBUG
# endif
};
static void log_endl(size_t &size)
class LogPrivate
{
# ifdef XMRIG_OS_WIN
memcpy(buf + size, CLEAR "\r\n", 7);
size += 6;
# else
memcpy(buf + size, CLEAR "\n", 6);
size += 5;
# endif
public:
XMRIG_DISABLE_COPY_MOVE(LogPrivate)
LogPrivate() = default;
inline ~LogPrivate()
{
for (auto backend : m_backends) {
delete backend;
}
}
static void log_color(Log::Level level, size_t &size)
inline void add(ILogBackend *backend) { m_backends.push_back(backend); }
void print(Log::Level level, const char *fmt, va_list args)
{
if (level == Log::NONE) {
size_t size = 0;
size_t offset = 0;
std::lock_guard<std::mutex> lock(m_mutex);
if (Log::isBackground() && m_backends.empty()) {
return;
}
const char *color = colors_map[level];
if (color == nullptr) {
const uint64_t ts = timestamp(level, size, offset);
color(level, size);
const int rc = vsnprintf(m_buf + size, sizeof (m_buf) - offset - 32, fmt, args);
if (rc < 0) {
return;
}
const size_t s = strlen(color);
memcpy(buf + size, color, s); // NOLINT(bugprone-not-null-terminated-result)
size += std::min(static_cast<size_t>(rc), sizeof (m_buf) - offset - 32);
endl(size);
size += s;
std::string txt(m_buf);
size_t i = 0;
while ((i = txt.find(CSI)) != std::string::npos) {
txt.erase(i, txt.find('m', i) - i + 1);
}
if (!m_backends.empty()) {
for (auto backend : m_backends) {
backend->print(ts, level, m_buf, offset, size, true);
backend->print(ts, level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
}
}
else {
fputs(txt.c_str(), stdout);
fflush(stdout);
}
}
static uint64_t log_timestamp(Log::Level level, size_t &size, size_t &offset)
private:
inline uint64_t timestamp(Log::Level level, size_t &size, size_t &offset)
{
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
@@ -129,13 +132,13 @@ static uint64_t log_timestamp(Log::Level level, size_t &size, size_t &offset)
time_t now = ms / 1000;
tm stime{};
# ifdef XMRIG_OS_WIN
# ifdef _WIN32
localtime_s(&stime, &now);
# else
localtime_r(&now, &stime);
# endif
const int rc = snprintf(buf, sizeof(buf) - 1, "[%d-%02d-%02d %02d:%02d:%02d" BLACK_BOLD(".%03d") "] ",
const int rc = snprintf(m_buf, sizeof(m_buf) - 1, "[%d-%02d-%02d %02d:%02d:%02d" BLACK_BOLD(".%03d") "] ",
stime.tm_year + 1900,
stime.tm_mon + 1,
stime.tm_mday,
@@ -153,101 +156,58 @@ static uint64_t log_timestamp(Log::Level level, size_t &size, size_t &offset)
}
#ifdef XMRIG_FEATURE_EVENTS
static void log_print(Log::Level level, const char *fmt, va_list args)
inline void color(Log::Level level, size_t &size)
{
size_t size = 0;
size_t offset = 0;
std::lock_guard<std::mutex> lock(mutex);
const uint64_t ts = log_timestamp(level, size, offset);
log_color(level, size);
const int rc = vsnprintf(buf + size, sizeof(buf) - offset - 32, fmt, args);
if (rc < 0) {
if (level == Log::NONE) {
return;
}
size += std::min(static_cast<size_t>(rc), sizeof(buf) - offset - 32);
log_endl(size);
Process::events().post<LogEvent>(ts, level, buf, offset, size);
const char *color = colors_map[level];
if (color == nullptr) {
return;
}
const size_t s = strlen(color);
memcpy(m_buf + size, color, s);
size += s;
}
inline void endl(size_t &size)
{
# ifdef _WIN32
memcpy(m_buf + size, CLEAR "\r\n", 7);
size += 6;
# else
class LogPrivate
{
public:
XMRIG_DISABLE_COPY_MOVE(LogPrivate)
LogPrivate() = default;
inline ~LogPrivate()
{
for (auto backend : backends) {
delete backend;
}
}
void print(Log::Level level, const char *fmt, va_list args)
{
size_t size = 0;
size_t offset = 0;
std::lock_guard<std::mutex> lock(mutex);
if (Log::isBackground() && backends.empty()) {
return;
}
const uint64_t ts = log_timestamp(level, size, offset);
log_color(level, size);
const int rc = vsnprintf(buf + size, sizeof (buf) - offset - 32, fmt, args);
if (rc < 0) {
return;
}
size += std::min(static_cast<size_t>(rc), sizeof (buf) - offset - 32);
log_endl(size);
std::string txt(buf);
size_t i = 0;
while ((i = txt.find(CSI)) != std::string::npos) {
txt.erase(i, txt.find('m', i) - i + 1);
}
if (!backends.empty()) {
for (auto backend : backends) {
backend->print(ts, level, buf, offset, size, true);
backend->print(ts, level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
}
}
else {
fputs(txt.c_str(), stdout);
fflush(stdout);
}
}
std::vector<ILogBackend*> backends;
};
memcpy(m_buf + size, CLEAR "\n", 6);
size += 5;
# endif
}
} // namespace xmrig
char m_buf[Log::kMaxBufferSize]{};
std::mutex m_mutex;
std::vector<ILogBackend*> m_backends;
};
bool Log::m_background = false;
bool Log::m_colors = true;
LogPrivate *Log::d = nullptr;
uint32_t Log::m_verbose = 0;
} /* namespace xmrig */
#ifndef XMRIG_FEATURE_EVENTS
void xmrig::Log::add(ILogBackend *backend)
{
assert(d != nullptr);
if (d) {
d->backends.push_back(backend);
d->add(backend);
}
}
@@ -263,25 +223,18 @@ void xmrig::Log::init()
{
d = new LogPrivate();
}
#endif
void xmrig::Log::print(const char *fmt, ...)
{
# ifndef XMRIG_FEATURE_EVENTS
if (!d) {
return;
}
# endif
va_list args{};
va_start(args, fmt);
# ifdef XMRIG_FEATURE_EVENTS
log_print(NONE, fmt, args);
# else
d->print(NONE, fmt, args);
# endif
va_end(args);
}
@@ -289,33 +242,14 @@ void xmrig::Log::print(const char *fmt, ...)
void xmrig::Log::print(Level level, const char *fmt, ...)
{
# ifndef XMRIG_FEATURE_EVENTS
if (!d) {
return;
}
# endif
va_list args{};
va_start(args, fmt);
# ifdef XMRIG_FEATURE_EVENTS
log_print(level, fmt, args);
# else
d->print(level, fmt, args);
# endif
va_end(args);
}
void xmrig::Log::setVerbose(uint32_t verbose)
{
static constexpr uint32_t kMaxVerbose =
# ifdef XMRIG_FEATURE_EVENTS
LogConfig::kMaxVerbose;
# else
5U;
# endif
m_verbose = std::min(verbose, kMaxVerbose);
}

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -15,13 +15,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_LOG_H
@@ -51,25 +44,16 @@ public:
WARNING, // warning conditions
NOTICE, // normal but significant condition
INFO, // informational
V1, // Verbose
V2, // Verbose
V3, // Verbose
V4, // Verbose
V5, // Verbose
DEBUG, // debug-level messages
};
constexpr static size_t kMaxBufferSize = 16384;
# ifndef XMRIG_FEATURE_EVENTS
static void add(ILogBackend *backend);
static void destroy();
static void init();
# endif
static void print(const char *fmt, ...);
static void print(Level level, const char *fmt, ...);
static void setVerbose(uint32_t verbose);
static inline bool isBackground() { return m_background; }
static inline bool isColors() { return m_colors; }
@@ -77,6 +61,7 @@ public:
static inline uint32_t verbose() { return m_verbose; }
static inline void setBackground(bool background) { m_background = background; }
static inline void setColors(bool colors) { m_colors = colors; }
static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; }
private:
static bool m_background;
@@ -158,12 +143,12 @@ private:
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::V1, x, ##__VA_ARGS__); }
#define LOG_V1(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::V1, x, ##__VA_ARGS__); }
#define LOG_V2(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::V2, x, ##__VA_ARGS__); }
#define LOG_V3(x, ...) if (xmrig::Log::verbose() > 2) { xmrig::Log::print(xmrig::Log::V3, x, ##__VA_ARGS__); }
#define LOG_V4(x, ...) if (xmrig::Log::verbose() > 3) { xmrig::Log::print(xmrig::Log::V4, x, ##__VA_ARGS__); }
#define LOG_V5(x, ...) if (xmrig::Log::verbose() > 4) { xmrig::Log::print(xmrig::Log::V5, x, ##__VA_ARGS__); }
#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V1(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V2(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V3(x, ...) if (xmrig::Log::verbose() > 2) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V4(x, ...) if (xmrig::Log::verbose() > 3) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V5(x, ...) if (xmrig::Log::verbose() > 4) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)
@@ -180,7 +165,7 @@ private:
#endif
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_LOG_H
#endif /* XMRIG_LOG_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,27 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/log/Tags.h"
#include "base/io/log/Log.h"
#ifndef XMRIG_FEATURE_EVENTS
namespace xmrig {
const char *tls_tag()
{
static const char *tag = GREEN_BG_BOLD(WHITE_BOLD_S " tls ");
return tag;
}
} // namespace xmrig
#endif
#ifdef XMRIG_LEGACY
const char *xmrig::Tags::config()
{
static const char *tag = CYAN_BG_BOLD(WHITE_BOLD_S " config ");
@@ -45,15 +29,6 @@ const char *xmrig::Tags::config()
}
const char *xmrig::Tags::signal()
{
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
return tag;
}
#endif
const char *xmrig::Tags::network()
{
static const char *tag = BLUE_BG_BOLD(WHITE_BOLD_S " net ");
@@ -70,6 +45,14 @@ const char* xmrig::Tags::origin()
}
const char *xmrig::Tags::signal()
{
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
return tag;
}
#ifdef XMRIG_MINER_PROJECT
const char *xmrig::Tags::cpu()
{

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -30,13 +30,10 @@ namespace xmrig {
class Tags
{
public:
# ifdef XMRIG_LEGACY
static const char *config();
static const char *signal();
# endif
static const char *network();
static const char *origin();
static const char *signal();
# ifdef XMRIG_MINER_PROJECT
static const char *cpu();

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -15,46 +15,47 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#include "base/io/log/backends/ConsoleLog.h"
#include "base/io/log/Log.h"
#include "base/kernel/private/Title.h"
#include "base/tools/Cvt.h"
#include "base/kernel/config/Title.h"
#include "base/tools/Handle.h"
#include <cstdio>
xmrig::ConsoleLog::ConsoleLog()
{
if (!init()) {
return;
}
# ifdef XMRIG_OS_WIN
SetConsoleOutputCP(65001);
# endif
}
xmrig::ConsoleLog::ConsoleLog(const Title &title)
{
if (!init()) {
if (!isSupported()) {
Log::setColors(false);
return;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
Log::setColors(false);
return;
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
DWORD mode = 0;
if (GetConsoleMode(handle, &mode)) {
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
}
if (title.isEnabled()) {
SetConsoleTitleW(Cvt::toUtf16(title.value().data()).c_str());
SetConsoleTitleA(title.value());
}
# endif
}
@@ -96,37 +97,6 @@ bool xmrig::ConsoleLog::isSupported()
}
bool xmrig::ConsoleLog::init()
{
if (!isSupported()) {
return false;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
return false;
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
DWORD mode = 0;
if (GetConsoleMode(handle, &mode)) {
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
}
# endif
return true;
}
#ifdef XMRIG_OS_WIN
bool xmrig::ConsoleLog::isWritable() const
{

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -15,13 +15,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining
* it with OpenSSL (or a modified version of that library), containing parts
* covered by the terms of OpenSSL License and SSLeay License, the licensors
* of this Program grant you additional permission to convey the resulting work.
*/
#ifndef XMRIG_CONSOLELOG_H
@@ -47,7 +40,6 @@ class ConsoleLog : public ILogBackend
public:
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
ConsoleLog();
ConsoleLog(const Title &title);
~ConsoleLog() override;
@@ -57,8 +49,6 @@ protected:
private:
static bool isSupported();
bool init();
uv_tty_t *m_tty = nullptr;
# ifdef XMRIG_OS_WIN
@@ -69,7 +59,7 @@ private:
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_CONSOLELOG_H
#endif /* XMRIG_CONSOLELOG_H */

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/log/backends/FileLog.h"

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <syslog.h>
@@ -43,5 +43,5 @@ void xmrig::SysLog::print(uint64_t, int level, const char *line, size_t offset,
return;
}
syslog(level == -1 ? LOG_INFO : std::min(level, LOG_DEBUG), "%s", line + offset);
syslog(level == -1 ? LOG_INFO : level, "%s", line + offset);
}

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -20,7 +20,7 @@
#include <memory>
#include "base/kernel/v6/Base.h"
#include "base/kernel/Base.h"
#include "base/io/json/Json.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/backends/ConsoleLog.h"
@@ -29,7 +29,7 @@
#include "base/io/log/Tags.h"
#include "base/io/Watcher.h"
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/OS.h"
#include "base/kernel/Platform.h"
#include "base/kernel/Process.h"
#include "base/net/tools/NetBuffer.h"
#include "core/config/Config.h"
@@ -130,17 +130,17 @@ private:
return config.release();
}
chain.addFile(Process::locate(Process::DataLocation, "config.json"));
chain.addFile(Process::location(Process::DataLocation, "config.json"));
if (read(chain, config)) {
return config.release();
}
chain.addFile(Process::locate(Process::HomeLocation, "." APP_ID ".json"));
chain.addFile(Process::location(Process::HomeLocation, "." APP_ID ".json"));
if (read(chain, config)) {
return config.release();
}
chain.addFile(Process::locate(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json"));
chain.addFile(Process::location(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json"));
if (read(chain, config)) {
return config.release();
}
@@ -164,6 +164,7 @@ private:
xmrig::Base::Base(Process *process)
: d_ptr(new BasePrivate(process))
{
}
@@ -186,7 +187,7 @@ int xmrig::Base::init()
d_ptr->api->addListener(this);
# endif
Process::setUserAgent(config()->userAgent());
Platform::init(config()->userAgent());
if (isBackground()) {
Log::setBackground(true);
@@ -220,7 +221,7 @@ void xmrig::Base::start()
}
if (config()->isWatch()) {
d_ptr->watcher = new Watcher(config()->path(), this);
d_ptr->watcher = new Watcher(config()->fileName(), this);
}
}
@@ -258,7 +259,7 @@ bool xmrig::Base::reload(const rapidjson::Value &json)
}
auto config = new Config();
if (!config->read(reader, d_ptr->config->path())) {
if (!config->read(reader, d_ptr->config->fileName())) {
delete config;
return false;

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -22,6 +22,7 @@
#include "3rdparty/rapidjson/fwd.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/tools/Object.h"
@@ -67,7 +68,7 @@ private:
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_BASE_H
#endif /* XMRIG_BASE_H */

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,93 +22,92 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Entry.h"
#include "base/io/log/Log.h"
#include "base/kernel/OS.h"
#include "base/kernel/Process.h"
#include "base/kernel/Versions.h"
#include "base/tools/Arguments.h"
#include "version.h"
#include <cstdio>
#include <uv.h>
#include <iostream>
#ifdef XMRIG_FEATURE_OPENCL
# include "backend/opencl/wrappers/OclLib.h"
# include "backend/opencl/wrappers/OclPlatform.h"
#ifdef XMRIG_FEATURE_TLS
# include <openssl/opensslv.h>
#endif
#ifdef XMRIG_FEATURE_HWLOC
# include <hwloc.h>
#endif
#ifdef XMRIG_FEATURE_OPENCL
# include "backend/opencl/wrappers/OclLib.h"
# include "backend/opencl/wrappers/OclPlatform.h"
#endif
#include "base/kernel/Entry.h"
#include "base/kernel/Process.h"
#include "core/config/usage.h"
#include "version.h"
namespace xmrig {
static bool showVersion(int &/*rc*/)
static int showVersion()
{
if (!Process::arguments().contains("-V", "--version")) {
return false;
}
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
std::cout << APP_NAME " v" << Process::version() << std::endl
<< " built on " __DATE__ " with " << Versions::kCompiler << "/" << Process::versions().get(Versions::kCompiler)
<< " (" << OS::arch << ")" << std::endl;
# ifdef XMRIG_LEGACY
std::cout << std::endl << "uv/" << Process::versions().get(Versions::kUv) << std::endl;
# ifdef XMRIG_FEATURE_TLS
std::cout << Versions::kTls << "/" << Process::versions().get(Versions::kTls) << std::endl;
# if defined(__clang__)
" with clang " __clang_version__);
# elif defined(__GNUC__)
" with GCC");
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER)
" with MSVC");
printf(" %d", MSVC_VERSION);
# else
);
# endif
# ifdef XMRIG_FEATURE_HWLOC
std::cout << "hwloc/" << Process::versions().get(Versions::kHwloc) << std::endl;
printf("\n features:"
# if defined(__i386__) || defined(_M_IX86)
" 32-bit"
# elif defined(__x86_64__) || defined(_M_AMD64)
" 64-bit"
# endif
# if defined(__AES__) || defined(_MSC_VER)
" AES"
# endif
"\n");
printf("\nlibuv/%s\n", uv_version_string());
# if defined(XMRIG_FEATURE_TLS)
{
# if defined(LIBRESSL_VERSION_TEXT)
printf("LibreSSL/%s\n", LIBRESSL_VERSION_TEXT + 9);
# elif defined(OPENSSL_VERSION_TEXT)
constexpr const char *v = &OPENSSL_VERSION_TEXT[8];
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
# endif
}
# endif
# if defined(XMRIG_FEATURE_HWLOC)
# if defined(HWLOC_VERSION)
printf("hwloc/%s\n", HWLOC_VERSION);
# elif HWLOC_API_VERSION >= 0x20000
printf("hwloc/2\n");
# else
printf("hwloc/1\n");
# endif
# endif
return true;
}
static bool showVersions(int &/*rc*/)
{
if (Process::arguments().contains("--versions")) {
for (const auto &kv : Process::versions().get()) {
std::cout << kv.first << "/" << kv.second << std::endl;;
}
return true;
}
return false;
}
static bool userAgent(int &/*rc*/)
{
Process::setUserAgent(Process::arguments().value("--user-agent"));
if (Process::arguments().contains("--print-user-agent")) {
std::cout << Process::userAgent() << std::endl;
return true;
}
return false;
return 0;
}
#ifdef XMRIG_FEATURE_HWLOC
static bool exportTopology(int &rc)
static int exportTopology(const Process &)
{
if (!Process::arguments().contains("--export-topology")) {
return false;
}
const auto path = Process::locate(Process::DataLocation, "topology.xml");
const String path = Process::location(Process::ExeLocation, "topology.xml");
hwloc_topology_t topology = nullptr;
hwloc_topology_init(&topology);
@@ -113,16 +118,15 @@ static bool exportTopology(int &rc)
# else
if (hwloc_topology_export_xml(topology, path) == -1) {
# endif
rc = 1;
std::cout << "failed to export hwloc topology" << std::endl;
printf("failed to export hwloc topology.\n");
}
else {
std::cout << "hwloc topology successfully exported to \"" << path << '"' << std::endl;
printf("hwloc topology successfully exported to \"%s\"\n", path.data());
}
hwloc_topology_destroy(topology);
return true;
return 0;
}
#endif
@@ -130,97 +134,59 @@ static bool exportTopology(int &rc)
} // namespace xmrig
xmrig::Entry::Entry(const Usage &usage)
xmrig::Entry::Id xmrig::Entry::get(const Process &process)
{
add(showVersion);
add(showVersions);
add(userAgent);
# ifdef XMRIG_FEATURE_HWLOC
add(exportTopology);
# endif
add([usage](int &/*rc*/) {
if (!Process::arguments().contains("-h", "--help")) {
return false;
const Arguments &args = process.arguments();
if (args.hasArg("-h") || args.hasArg("--help")) {
return Usage;
}
std::cout << "Usage: " APP_ID " [OPTIONS]\n";
std::cout << usage();
# ifndef XMRIG_LEGACY
std::cout << "\nBase:\n";
std::cout << " -h, --help print this help and exit\n";
std::cout << " -V, --version print " APP_ID " version and exit\n";
std::cout << " --versions print versions and exit\n";
std::cout << " -d, --data-dir=<PATH> alternative working directory\n";
std::cout << " -c, --config=<FILE> load a JSON-format configuration file\n";
std::cout << " -B, --background run " APP_ID " in the background\n";
std::cout << " --no-color disable colored output\n";
std::cout << " --verbose=[LEVEL] verbose level (0-5)\n";
std::cout << " --print-time=<N> print report every N seconds\n";
std::cout << " -l, --log-file=<FILE> log all output to a file\n";
# ifdef HAVE_SYSLOG_H
std::cout << " -S, --syslog use system log for output messages\n";
# endif
# ifdef XMRIG_OS_WIN
std::cout << " --title=[TITLE] set custom console window title\n";
# endif
std::cout << " --user-agent=<UA> set custom user agent string\n";
std::cout << " --print-user-agent print current user agent and exit\n";
std::cout << " --dns-ipv6 prefer IPv6 records from DNS responses\n";
std::cout << " --dns-ttl=<N> N seconds (default: 30) TTL for internal DNS cache\n";
if (args.hasArg("-V") || args.hasArg("--version") || args.hasArg("--versions")) {
return Version;
}
# ifdef XMRIG_FEATURE_HWLOC
std::cout << " --export-topology export hwloc topology to a XML file and exit\n";
if (args.hasArg("--export-topology")) {
return Topo;
}
# endif
# endif
return true;
});
# ifdef XMRIG_FEATURE_OPENCL
add([](int &/*rc*/) {
if (Process::arguments().contains("--print-platforms")) {
if (args.hasArg("--print-platforms")) {
return Platforms;
}
# endif
return Default;
}
int xmrig::Entry::exec(const Process &process, Id id)
{
switch (id) {
case Usage:
printf("%s\n", usage().c_str());
return 0;
case Version:
return showVersion();
# ifdef XMRIG_FEATURE_HWLOC
case Topo:
return exportTopology(process);
# endif
# ifdef XMRIG_FEATURE_OPENCL
case Platforms:
if (OclLib::init()) {
OclPlatform::print();
}
return true;
}
return false;
});
return 0;
# endif
add([](int &rc) {
if (Process::arguments().contains("-B", "--background")) {
Log::setBackground(true);
return background(rc);
default:
break;
}
return false;
});
}
bool xmrig::Entry::exec(int &rc) const
{
for (const auto &fn : m_entries) {
if (fn(rc)) {
return true;
}
}
return false;
}
void xmrig::Entry::add(Fn &&fn)
{
m_entries.emplace_back(std::move(fn));
return 1;
}

View File

@@ -1,6 +1,12 @@
/* XMRig
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -20,38 +26,29 @@
#define XMRIG_ENTRY_H
#include "base/tools/Object.h"
#include <functional>
#include <string>
#include <vector>
namespace xmrig {
class Process;
class Entry
{
public:
XMRIG_DISABLE_COPY_MOVE(Entry)
enum Id {
Default,
Usage,
Version,
Topo,
Platforms
};
using Fn = std::function<bool(int &rc)>;
using Usage = std::function<std::string()>;
Entry(const Usage &usage);
bool exec(int &rc) const;
void add(Fn &&fn);
private:
static bool background(int &rc);
std::vector<Fn> m_entries;
static Id get(const Process &process);
static int exec(const Process &process, Id id);
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_ENTRY_H
#endif /* XMRIG_ENTRY_H */

View File

@@ -1,99 +0,0 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/kernel/OS.h"
#include "3rdparty/fmt/core.h"
#include "base/kernel/Process.h"
#include "base/kernel/Versions.h"
#include "version.h"
#ifndef XMRIG_OS_WIN
# include <unistd.h>
#endif
#ifndef UV_MAXHOSTNAMESIZE
# ifdef MAXHOSTNAMELEN
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
# else
# define UV_MAXHOSTNAMESIZE 256
# endif
#endif
namespace xmrig {
#if (XMRIG_ARM == 8 || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64))
const char *OS::arch = "arm64";
#elif (XMRIG_ARM == 7 || defined(__arm__) || defined(_M_ARM))
const char *OS::arch = "arm";
#elif (defined(__x86_64__) || defined(_M_AMD64))
const char *OS::arch = "x86_64";
#elif (defined(_X86_) || defined(_M_IX86))
const char *OS::arch = "x86";
#else
static_assert (false, "Unsupported CPU or compiler");
#endif
} // namespace xmrig
std::string xmrig::OS::userAgent()
{
return fmt::format("{}/{} ({}; {}) uv/{} {}/{}",
APP_NAME,
APP_VERSION,
name(),
arch,
Process::versions()[Versions::kUv],
Versions::kCompiler,
Process::versions()[Versions::kCompiler]
);
}
#ifndef XMRIG_OS_WIN
xmrig::String xmrig::OS::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
if (gethostname(buf, sizeof(buf)) == 0) {
return static_cast<const char *>(buf);
}
return {};
}
#endif
uint64_t xmrig::OS::freemem()
{
return uv_get_free_memory();
}
uint64_t xmrig::OS::totalmem()
{
return uv_get_total_memory();
}

View File

@@ -1,5 +1,5 @@
/* XMRig
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -16,63 +16,42 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Lib.h"
#include "base/kernel/Platform.h"
#include <cassert>
#include <cstring>
#include <uv.h>
#ifdef XMRIG_FEATURE_TLS
# include <openssl/ssl.h>
# include <openssl/err.h>
#endif
namespace xmrig {
class Lib::Private
{
public:
bool open = false;
uv_lib_t lib{};
};
String Platform::m_userAgent;
} // namespace xmrig
xmrig::Lib::Lib() :
d(std::make_shared<Private>())
void xmrig::Platform::init(const char *userAgent)
{
# ifdef XMRIG_FEATURE_TLS
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
ERR_load_crypto_strings();
SSL_load_error_strings();
OpenSSL_add_all_digests();
# endif
if (userAgent) {
m_userAgent = userAgent;
}
bool xmrig::Lib::isOpen() const
{
return d->open;
}
bool xmrig::Lib::open(const char *filename)
{
assert(!isOpen());
return (d->open = uv_dlopen(filename, &d->lib) == 0);
}
bool xmrig::Lib::sym(const char *name, void **ptr)
{
return isOpen() && uv_dlsym(&d->lib, name, ptr);
}
const char *xmrig::Lib::lastError() const
{
return uv_dlerror(&d->lib);
}
void xmrig::Lib::close()
{
if (isOpen()) {
uv_dlclose(&d->lib);
d->open = false;
else {
m_userAgent = createUserAgent();
}
}

View File

@@ -16,43 +16,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_OS_H
#define XMRIG_OS_H
#ifndef XMRIG_PLATFORM_H
#define XMRIG_PLATFORM_H
#include <cstdint>
#include "base/tools/String.h"
#include <string>
namespace xmrig {
class OS
class Platform
{
public:
static const char *arch;
static inline bool trySetThreadAffinity(int64_t cpu_id)
{
if (cpu_id < 0) {
return false;
}
static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
static inline bool trySetThreadAffinity(int64_t cpu_id) { return cpu_id >= 0 && setThreadAffinity(static_cast<uint64_t>(cpu_id)); }
return setThreadAffinity(static_cast<uint64_t>(cpu_id));
}
static bool isOnBatteryPower();
static bool setThreadAffinity(uint64_t cpu_id);
static std::string name();
static std::string userAgent();
static String hostname();
static uint64_t freemem();
static uint64_t idleTime();
static uint64_t totalmem();
static void destroy();
static void init();
static void init(const char *userAgent);
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);
static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
static inline const String &userAgent() { return m_userAgent; }
static bool isOnBatteryPower();
static uint64_t idleTime();
private:
static char *createUserAgent();
static String m_userAgent;
};
} // namespace xmrig
#endif // XMRIG_OS_H
#endif /* XMRIG_PLATFORM_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/OS.h"
#include "base/kernel/Platform.h"
#include "backend/cpu/platform/HwlocCpuInfo.h"
#include "backend/cpu/Cpu.h"
@@ -26,7 +27,7 @@
#ifndef XMRIG_OS_APPLE
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(cpu_id));

View File

@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPowerSources.h>
#include <stdio.h>
@@ -26,58 +27,46 @@
#include <fstream>
#include "base/kernel/OS.h"
#include "base/kernel/Platform.h"
#include "version.h"
bool xmrig::OS::isOnBatteryPower()
char *xmrig::Platform::createUserAgent()
{
return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
constexpr const size_t max = 256;
char *buf = new char[max]();
int length = snprintf(buf, max,
"%s/%s (Macintosh; macOS"
# ifdef XMRIG_ARM
"; arm64"
# else
"; x86_64"
# endif
") libuv/%s", APP_NAME, APP_VERSION, uv_version_string());
# ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
return buf;
}
bool xmrig::OS::setThreadAffinity(uint64_t /*cpu_id*/)
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
return true;
}
std::string xmrig::OS::name()
{
return "macOS";
}
uint64_t xmrig::OS::idleTime()
{
uint64_t idle_time = 0;
const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"));
const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time);
CFRelease(property);
IOObjectRelease(service);
return idle_time / 1000000U;
}
void xmrig::OS::destroy()
void xmrig::Platform::setProcessPriority(int)
{
}
void xmrig::OS::init()
{
}
void xmrig::OS::setProcessPriority(int)
{
}
void xmrig::OS::setThreadPriority(int priority)
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
@@ -112,3 +101,24 @@ void xmrig::OS::setThreadPriority(int priority)
setpriority(PRIO_PROCESS, 0, prio);
}
bool xmrig::Platform::isOnBatteryPower()
{
return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
}
uint64_t xmrig::Platform::idleTime()
{
uint64_t idle_time = 0;
const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"));
const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time);
CFRelease(property);
IOObjectRelease(service);
return idle_time / 1000000U;
}

View File

@@ -16,10 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef __FreeBSD__
#ifdef XMRIG_OS_FREEBSD
# include <sys/types.h>
# include <sys/param.h>
# ifndef __DragonFly__
# include <sys/cpuset.h>
# endif
# include <pthread_np.h>
#endif
@@ -37,32 +39,52 @@
#include <limits>
#include "base/kernel/OS.h"
#include "base/kernel/Platform.h"
#include "version.h"
#ifdef __FreeBSD__
typedef cpuset_t cpu_set_t;
char *xmrig::Platform::createUserAgent()
{
constexpr const size_t max = 256;
char *buf = new char[max]();
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
# if defined(__x86_64__)
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
# elif defined(__aarch64__)
length += snprintf(buf + length, max - length, "aarch64) libuv/%s", uv_version_string());
# elif defined(__arm__)
length += snprintf(buf + length, max - length, "arm) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif
# ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
bool xmrig::OS::isOnBatteryPower()
{
for (int i = 0; i <= 1; ++i) {
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
return buf;
}
#ifndef XMRIG_FEATURE_HWLOC
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
#ifdef __DragonFly__
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
return true;
}
#else
#ifdef XMRIG_OS_FREEBSD
typedef cpuset_t cpu_set_t;
#endif
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
cpu_set_t mn;
CPU_ZERO(&mn);
@@ -77,41 +99,17 @@ bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}
#endif
#endif // __DragonFly__
#endif // XMRIG_FEATURE_HWLOC
std::string xmrig::OS::name()
{
# ifdef __FreeBSD__
return "FreeBSD";
# else
return "Linux";
# endif
}
uint64_t xmrig::OS::idleTime()
{
return std::numeric_limits<uint64_t>::max();
}
void xmrig::OS::destroy()
void xmrig::Platform::setProcessPriority(int)
{
}
void xmrig::OS::init()
{
}
void xmrig::OS::setProcessPriority(int)
{
}
void xmrig::OS::setThreadPriority(int priority)
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
@@ -157,3 +155,25 @@ void xmrig::OS::setThreadPriority(int priority)
}
# endif
}
bool xmrig::Platform::isOnBatteryPower()
{
for (int i = 0; i <= 1; ++i) {
char buf[64];
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
std::ifstream f(buf);
if (f.is_open()) {
std::string status;
f >> status;
return (status == "Discharging");
}
}
return false;
}
uint64_t xmrig::Platform::idleTime()
{
return std::numeric_limits<uint64_t>::max();
}

View File

@@ -16,28 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <winsock2.h>
#include <windows.h>
#include <uv.h>
#include <limits>
#include "base/kernel/OS.h"
#include "3rdparty/fmt/core.h"
#include "base/kernel/Lib.h"
#include "base/tools/Cvt.h"
#ifndef UV_MAXHOSTNAMESIZE
# define UV_MAXHOSTNAMESIZE 256
#endif
namespace xmrig {
typedef int (WSAAPI *GetHostNameW_t)(PWSTR, int); // NOLINT(modernize-use-using)
static Lib ws2_32;
static GetHostNameW_t pGetHostNameW = nullptr;
#include "base/kernel/Platform.h"
#include "version.h"
static inline OSVERSIONINFOEX winOsVersion()
@@ -58,21 +46,32 @@ static inline OSVERSIONINFOEX winOsVersion()
}
} // namespace xmrig
bool xmrig::OS::isOnBatteryPower()
char *xmrig::Platform::createUserAgent()
{
SYSTEM_POWER_STATUS st;
if (GetSystemPowerStatus(&st)) {
return (st.ACLineStatus == 0);
}
return false;
const auto osver = winOsVersion();
constexpr const size_t max = 256;
char *buf = new char[max]();
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
# if defined(__x86_64__) || defined(_M_AMD64)
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
# endif
# ifdef __GNUC__
snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif _MSC_VER
snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
# endif
return buf;
}
#ifndef XMRIG_FEATURE_HWLOC
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0);
Sleep(1);
@@ -81,70 +80,7 @@ bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
#endif
std::string xmrig::OS::name()
{
const auto osver = winOsVersion();
return fmt::format("Windows {}.{}", osver.dwMajorVersion, osver.dwMinorVersion);
}
xmrig::String xmrig::OS::hostname()
{
if (pGetHostNameW) {
WCHAR buf[UV_MAXHOSTNAMESIZE]{};
if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) == 0) {
return Cvt::toUtf8(buf).c_str();
}
}
char buf[UV_MAXHOSTNAMESIZE]{};
if (gethostname(buf, sizeof(buf)) == 0) {
return static_cast<const char *>(buf);
}
return {};
}
uint64_t xmrig::OS::idleTime()
{
LASTINPUTINFO info{};
info.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&info)) {
return std::numeric_limits<uint64_t>::max();
}
return static_cast<uint64_t>(GetTickCount() - info.dwTime);
}
void xmrig::OS::destroy()
{
# ifdef XMRIG_FEATURE_COM
CoUninitialize();
# endif
ws2_32.close();
}
void xmrig::OS::init()
{
# ifdef XMRIG_FEATURE_COM
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
# endif
if (ws2_32.open("Ws2_32.dll")) {
ws2_32.sym("GetHostNameW", &pGetHostNameW);
}
}
void xmrig::OS::setProcessPriority(int priority)
void xmrig::Platform::setProcessPriority(int priority)
{
if (priority == -1) {
return;
@@ -181,7 +117,7 @@ void xmrig::OS::setProcessPriority(int priority)
}
void xmrig::OS::setThreadPriority(int priority)
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
@@ -216,3 +152,26 @@ void xmrig::OS::setThreadPriority(int priority)
SetThreadPriority(GetCurrentThread(), prio);
}
bool xmrig::Platform::isOnBatteryPower()
{
SYSTEM_POWER_STATUS st;
if (GetSystemPowerStatus(&st)) {
return (st.ACLineStatus == 0);
}
return false;
}
uint64_t xmrig::Platform::idleTime()
{
LASTINPUTINFO info{};
info.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&info)) {
return std::numeric_limits<uint64_t>::max();
}
return static_cast<uint64_t>(GetTickCount() - info.dwTime);
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -23,25 +23,10 @@
#include "base/kernel/Process.h"
#include "3rdparty/fmt/core.h"
#include "base/kernel/OS.h"
#include "base/kernel/Versions.h"
#include "base/tools/Arguments.h"
#include "base/tools/Chrono.h"
#include "version.h"
#ifdef XMRIG_FEATURE_EVENTS
# include "base/kernel/Events.h"
# include "base/kernel/events/ExitEvent.h"
#endif
#ifdef XMRIG_FEATURE_TLS
# include <openssl/ssl.h>
# include <openssl/err.h>
#endif
#ifdef XMRIG_OS_WIN
# ifdef _MSC_VER
# include <direct.h>
@@ -57,22 +42,62 @@
namespace xmrig {
class Process::Private
static char pathBuf[520];
static std::string dataDir;
static std::string getPath(Process::Location location)
{
public:
Private(int argc, char **argv) : arguments(argc, argv)
{
# ifdef XMRIG_FEATURE_TLS
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
ERR_load_crypto_strings();
SSL_load_error_strings();
OpenSSL_add_all_digests();
size_t size = sizeof(pathBuf);
if (location == Process::DataLocation) {
if (!dataDir.empty()) {
return dataDir;
}
location = Process::ExeLocation;
}
if (location == Process::HomeLocation) {
# if UV_VERSION_HEX >= 0x010600
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
void setDataDir(const char *path)
if (location == Process::TempLocation) {
# if UV_VERSION_HEX >= 0x010900
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
if (location == Process::ExeLocation) {
if (uv_exepath(pathBuf, &size) < 0) {
return {};
}
auto path = std::string(pathBuf, size);
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
if (pos != std::string::npos) {
return path.substr(0, pos);
}
return path;
}
if (location == Process::CwdLocation) {
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
}
return {};
}
static void setDataDir(const char *path)
{
if (path == nullptr) {
return;
@@ -84,100 +109,32 @@ public:
}
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
dataDir = { dir.data(), dir.size() };
dataDir = dir;
}
}
Arguments arguments;
const char *version = APP_VERSION;
int exitCode = 0;
String dataDir;
String userAgent;
Versions versions;
# ifndef XMRIG_LEGACY
Events events;
# endif
};
Process::Private *Process::d = nullptr;
} // namespace xmrig
xmrig::Process::Process(int argc, char **argv)
xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
d = new Private(argc, argv);
OS::init();
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
d_fn()->setDataDir(arguments().value("--data-dir", "-d"));
setDataDir(m_arguments.value("--data-dir", "-d"));
# ifdef XMRIG_SHARED_DATADIR
if (d_fn()->dataDir.isEmpty()) {
auto dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, locate(HomeLocation));
if (dataDir.empty()) {
dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, location(HomeLocation));
MKDIR(dataDir);
dataDir += APP_KIND;
MKDIR(dataDir);
if (uv_chdir(dataDir.c_str()) == 0) {
d_fn()->dataDir = { dataDir.c_str(), dataDir.size() };
}
uv_chdir(dataDir.c_str());
}
# endif
if (d_fn()->dataDir.isEmpty()) {
d_fn()->dataDir = locate(ExeLocation);
}
}
xmrig::Process::~Process()
{
OS::destroy();
delete d;
d = nullptr;
}
const xmrig::Arguments &xmrig::Process::arguments()
{
return d_fn()->arguments;
}
const char *xmrig::Process::version()
{
return d_fn()->version;
}
const xmrig::String &xmrig::Process::userAgent()
{
if (d_fn()->userAgent.isEmpty()) {
d_fn()->userAgent = OS::userAgent().c_str();
}
return d_fn()->userAgent;
}
const xmrig::Versions &xmrig::Process::versions()
{
return d_fn()->versions;
}
int xmrig::Process::exitCode()
{
return d_fn()->exitCode;
}
@@ -191,94 +148,20 @@ int xmrig::Process::ppid()
}
xmrig::String xmrig::Process::locate(Location location, const char *fileName)
xmrig::String xmrig::Process::exepath()
{
auto path = locate(location);
if (path.isNull() || fileName == nullptr) {
return path;
size_t size = sizeof(pathBuf);
return uv_exepath(pathBuf, &size) < 0 ? String("") : String(pathBuf, size);
}
xmrig::String xmrig::Process::location(Location location, const char *fileName)
{
auto path = getPath(location);
if (path.empty() || fileName == nullptr) {
return path.c_str();
}
return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str();
}
xmrig::String xmrig::Process::locate(Location location)
{
char buf[520]{};
size_t size = sizeof(buf);
if (location == ExePathLocation && uv_exepath(buf, &size) >= 0) {
return { buf, size };
}
if (location == Process::DataLocation && !d_fn()->dataDir.isEmpty()) {
return d_fn()->dataDir;
}
# if UV_VERSION_HEX >= 0x010600
if (location == Process::HomeLocation && uv_os_homedir(buf, &size) >= 0) {
return { buf, size };
}
# endif
# if UV_VERSION_HEX >= 0x010900
if (location == Process::TempLocation && uv_os_tmpdir(buf, &size) >= 0) {
return { buf, size };
}
# endif
if (location == Process::CwdLocation && uv_cwd(buf, &size) >= 0) {
return { buf, size };
}
if (location == Process::ExeLocation) {
if (uv_exepath(buf, &size) < 0) {
return {};
}
auto path = std::string(buf, size);
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
if (pos != std::string::npos) {
return path.substr(0, pos).c_str();
}
return { buf, size };
}
return location != ExeLocation ? locate(ExeLocation) : String();
}
void xmrig::Process::exit(int code)
{
if (code != -1) {
d_fn()->exitCode = code;
}
# ifdef XMRIG_FEATURE_EVENTS
events().post<ExitEvent>(exitCode());
# endif
}
void xmrig::Process::setUserAgent(const String &userAgent)
{
d_fn()->userAgent = userAgent;
}
#ifdef XMRIG_FEATURE_EVENTS
xmrig::Events &xmrig::Process::events()
{
return d_fn()->events;
}
#endif
xmrig::Process::Private *xmrig::Process::d_fn()
{
assert(d);
return d;
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -20,8 +20,7 @@
#define XMRIG_PROCESS_H
#include "base/tools/Object.h"
#include "base/tools/String.h"
#include "base/tools/Arguments.h"
#ifdef WIN32
@@ -34,18 +33,10 @@
namespace xmrig {
class Arguments;
class Events;
class Versions;
class Process
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Process)
enum Location {
ExePathLocation,
ExeLocation,
CwdLocation,
DataLocation,
@@ -54,34 +45,20 @@ public:
};
Process(int argc, char **argv);
~Process();
static const Arguments &arguments();
static const char *version();
static const String &userAgent();
static const Versions &versions();
static int exitCode();
static int pid();
static int ppid();
static String locate(Location location, const char *fileName);
static String locate(Location location);
static void exit(int code = -1);
static void setUserAgent(const String &userAgent);
static String exepath();
static String location(Location location, const char *fileName = nullptr);
# ifdef XMRIG_FEATURE_EVENTS
static Events &events();
# endif
inline const Arguments &arguments() const { return m_arguments; }
private:
class Private;
static Private *d_fn();
static Private *d;
Arguments m_arguments;
};
} // namespace xmrig
} /* namespace xmrig */
#endif // XMRIG_PROCESS_H
#endif /* XMRIG_PROCESS_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include <unistd.h>

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>

View File

@@ -1,203 +0,0 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Versions.h"
#include "3rdparty/fmt/core.h"
#include "3rdparty/rapidjson/document.h"
#include "version.h"
#include <uv.h>
#ifdef XMRIG_FEATURE_HTTP
# include "3rdparty/llhttp/llhttp.h"
#endif
#ifdef XMRIG_FEATURE_TLS
# include <openssl/opensslv.h>
#endif
#ifdef XMRIG_FEATURE_SODIUM
# include <sodium.h>
#endif
#ifdef XMRIG_FEATURE_SQLITE
# include "3rdparty/sqlite/sqlite3.h"
#endif
#ifdef XMRIG_FEATURE_HWLOC
# include "backend/cpu/Cpu.h"
#endif
#ifdef XMRIG_FEATURE_POSTGRESQL
# include <libpq-fe.h>
#endif
namespace xmrig {
const char *Versions::kApp = "app";
const char *Versions::kBase = "base";
const char *Versions::kFmt = "fmt";
const char *Versions::kRapidjson = "rapidjson";
const char *Versions::kUv = "uv";
#if defined (__INTEL_LLVM_COMPILER)
const char *Versions::kCompiler = "icx";
#elif defined(__INTEL_COMPILER)
const char *Versions::kCompiler = "icc";
#elif defined(__clang__)
const char *Versions::kCompiler = "clang";
#elif defined(__GNUC__)
const char *Versions::kCompiler = "gcc";
#elif defined(_MSC_VER)
# if (_MSC_VER >= 1930)
# define MSVC_VERSION 2022
# elif (_MSC_VER >= 1920 && _MSC_VER < 1930)
# define MSVC_VERSION 2019
# elif (_MSC_VER >= 1910 && _MSC_VER < 1920)
# define MSVC_VERSION 2017
# elif _MSC_VER == 1900
# define MSVC_VERSION 2015
# else
# define MSVC_VERSION 0
# endif
const char *Versions::kCompiler = "MSVC";
#else
const char *Versions::kCompiler = "unknown";
#endif
#ifdef XMRIG_FEATURE_HTTP
const char *Versions::kLlhttp = "llhttp";
#endif
#ifdef XMRIG_FEATURE_TLS
# if defined(LIBRESSL_VERSION_TEXT)
const char *Versions::kTls = "libressl";
# else
const char *Versions::kTls = "openssl";
# endif
#endif
#ifdef XMRIG_FEATURE_SODIUM
const char *Versions::kSodium = "sodium";
#endif
#ifdef XMRIG_FEATURE_SQLITE
const char *Versions::kSqlite = "sqlite";
#endif
#ifdef XMRIG_FEATURE_HWLOC
const char *Versions::kHwloc = "hwloc";
#endif
#ifdef XMRIG_FEATURE_POSTGRESQL
const char *kPq = "pq";
#endif
} // namespace xmrig
xmrig::Versions::Versions()
{
m_data.insert({ kApp, APP_VERSION });
m_data.insert({ kBase, fmt::format("{}.{}.{}", XMRIG_BASE_VERSION / 10000, XMRIG_BASE_VERSION / 100 % 100, XMRIG_BASE_VERSION % 100).c_str() });
m_data.insert({ kUv, uv_version_string() });
m_data.insert({ kRapidjson, RAPIDJSON_VERSION_STRING });
m_data.insert({ kFmt, fmt::format("{}.{}.{}", FMT_VERSION / 10000, FMT_VERSION / 100 % 100, FMT_VERSION % 100).c_str() });
# if defined (__INTEL_LLVM_COMPILER)
m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_LLVM_COMPILER / 10000, __INTEL_LLVM_COMPILER / 100 % 100, __INTEL_LLVM_COMPILER % 100).c_str() });
# elif defined (__INTEL_COMPILER)
# if (__INTEL_COMPILER >= 2020)
m_data.insert({ kCompiler, XMRIG_TOSTRING(__INTEL_COMPILER) });
# else
m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_COMPILER / 100, __INTEL_COMPILER / 10 % 10, __INTEL_COMPILER % 10).c_str() });
# endif
# elif defined(__clang__)
m_data.insert({ kCompiler, XMRIG_TOSTRING(__clang_major__.__clang_minor__.__clang_patchlevel__) });
# elif defined(__GNUC__)
m_data.insert({ kCompiler, XMRIG_TOSTRING(__GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__) });
# elif defined(_MSC_VER)
m_data.insert({ kCompiler, XMRIG_TOSTRING(MSVC_VERSION) });
# endif
# ifdef XMRIG_FEATURE_HTTP
m_data.insert({ kLlhttp, XMRIG_TOSTRING(LLHTTP_VERSION_MAJOR.LLHTTP_VERSION_MINOR.LLHTTP_VERSION_PATCH) });
# endif
# ifdef XMRIG_FEATURE_TLS
# if defined(LIBRESSL_VERSION_TEXT)
m_data.insert({ kTls, String(LIBRESSL_VERSION_TEXT).split(' ')[1] });
# elif defined(OPENSSL_VERSION_TEXT)
m_data.insert({ kTls, String(OPENSSL_VERSION_TEXT).split(' ')[1] });
# endif
# endif
# ifdef XMRIG_FEATURE_SODIUM
m_data.insert({ kSodium, sodium_version_string() });
# endif
# ifdef XMRIG_FEATURE_SQLITE
m_data.insert({ kSqlite, sqlite3_libversion() });
# endif
# if defined(XMRIG_FEATURE_HWLOC) && defined(XMRIG_LEGACY)
m_data.insert({ kHwloc, String(Cpu::info()->backend()).split('/')[1] });
# endif
# ifdef XMRIG_FEATURE_POSTGRESQL
m_data.insert({ kPq, fmt::format("{}.{}", PQlibVersion() / 10000, PQlibVersion() % 100).c_str() });
# endif
}
const xmrig::String &xmrig::Versions::get(const char *key) const
{
static const String empty;
const auto it = m_data.find(key);
return it != m_data.end() ? it->second : empty;
}
rapidjson::Value xmrig::Versions::toJSON(rapidjson::Document &doc) const
{
using namespace rapidjson;
Value out(kObjectType);
toJSON(out, doc);
return out;
}
void xmrig::Versions::toJSON(rapidjson::Value &out, rapidjson::Document &doc) const
{
auto &allocator = doc.GetAllocator();
const auto &data = get();
for (const auto &kv : data) {
out.AddMember(kv.first.toJSON(), kv.second.toJSON(), allocator);
}
}

Some files were not shown because too many files have changed in this diff Show More