add force usage of cpu instructions, update GH actions

This commit is contained in:
R4SAS 2020-11-13 17:26:15 +03:00
parent faf04def31
commit ee8d5e9a0c
10 changed files with 51 additions and 37 deletions

View file

@ -1,20 +0,0 @@
name: Build on Ubuntu
on: [push, pull_request]
jobs:
build:
name: With QT GUI
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v2
- name: install packages
run: |
sudo add-apt-repository ppa:mhier/libboost-latest
sudo apt-get update
sudo apt-get install build-essential qt5-default libqt5gui5 libboost1.74-dev libminiupnpc-dev libssl-dev zlib1g-dev
- name: build application
run: |
cd qt/i2pd_qt
qmake I2PDMAKE+="USE_AESNI=no"
make -j3

View file

@ -2,10 +2,12 @@ name: Build on Ubuntu
on: [push, pull_request] on: [push, pull_request]
defaults:
runs-on: ubuntu-16.04
jobs: jobs:
build: build:
name: With USE_UPNP=${{ matrix.with_upnp }} name: With USE_UPNP=${{ matrix.with_upnp }}
runs-on: ubuntu-16.04
strategy: strategy:
fail-fast: true fail-fast: true
matrix: matrix:
@ -18,4 +20,19 @@ jobs:
sudo apt-get update sudo apt-get update
sudo apt-get install build-essential libboost1.74-dev libminiupnpc-dev libssl-dev zlib1g-dev sudo apt-get install build-essential libboost1.74-dev libminiupnpc-dev libssl-dev zlib1g-dev
- name: build application - name: build application
run: make USE_AESNI=no USE_UPNP=${{ matrix.with_upnp }} -j3 run: make USE_UPNP=${{ matrix.with_upnp }} -j3
build_qt:
name: With QT GUI
steps:
- uses: actions/checkout@v2
- name: install packages
run: |
sudo add-apt-repository ppa:mhier/libboost-latest
sudo apt-get update
sudo apt-get install build-essential qt5-default libqt5gui5 libboost1.74-dev libminiupnpc-dev libssl-dev zlib1g-dev
- name: build application
run: |
cd qt/i2pd_qt
qmake
make -j3

View file

@ -229,3 +229,12 @@ verify = true
[persist] [persist]
## Save peer profiles on disk (default: true) ## Save peer profiles on disk (default: true)
# profiles = true # profiles = true
[cpuext]
## Use CPU AES-NI instructions set when work with cryptography when available (default: true)
# aesni = true
## Use CPU AVX instructions set when work with cryptography when available (default: true)
# avx = true
## Force usage of CPU instructions set, even if they not found
## DO NOT TOUCH that option if you really don't know what are you doing!
# force = false

View file

@ -128,9 +128,10 @@ namespace i2p
LogPrint(eLogDebug, "FS: data directory: ", datadir); LogPrint(eLogDebug, "FS: data directory: ", datadir);
bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation); bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation);
bool aesni; i2p::config::GetOption("aesni", aesni); bool aesni; i2p::config::GetOption("cpuext.aesni", aesni);
bool avx; i2p::config::GetOption("avx", avx); bool avx; i2p::config::GetOption("cpuext.avx", avx);
i2p::crypto::InitCrypto (precomputation, aesni, avx); bool forceCpuExt; i2p::config::GetOption("cpuext.force", forceCpuExt);
i2p::crypto::InitCrypto (precomputation, aesni, avx, forceCpuExt);
int netID; i2p::config::GetOption("netid", netID); int netID; i2p::config::GetOption("netid", netID);
i2p::context.SetNetID (netID); i2p::context.SetNetID (netID);

View file

@ -27,17 +27,17 @@ namespace cpu
bool aesni = false; bool aesni = false;
bool avx = false; bool avx = false;
void Detect(bool AesSwitch, bool AvxSwitch) void Detect(bool AesSwitch, bool AvxSwitch, bool force)
{ {
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
int info[4]; int info[4];
__cpuid(0, info[0], info[1], info[2], info[3]); __cpuid(0, info[0], info[1], info[2], info[3]);
if (info[0] >= 0x00000001) { if (info[0] >= 0x00000001) {
__cpuid(0x00000001, info[0], info[1], info[2], info[3]); __cpuid(0x00000001, info[0], info[1], info[2], info[3]);
if (info[2] & bit_AES && AesSwitch) { if ((info[2] & bit_AES && AesSwitch) || (AesSwitch && force)) {
aesni = true; aesni = true;
} }
if (info[2] & bit_AVX && AvxSwitch) { if ((info[2] & bit_AVX && AvxSwitch) || (AvxSwitch && force)) {
avx = true; avx = true;
} }
} }

View file

@ -16,7 +16,7 @@ namespace cpu
extern bool aesni; extern bool aesni;
extern bool avx; extern bool avx;
void Detect(bool AesSwitch, bool AvxSwitch); void Detect(bool AesSwitch, bool AvxSwitch, bool force);
} }
} }

View file

@ -62,8 +62,6 @@ namespace config {
("ntcp", bool_switch()->default_value(false), "Ignored. Always false") ("ntcp", bool_switch()->default_value(false), "Ignored. Always false")
("ssu", bool_switch()->default_value(true), "Enable SSU transport (default: enabled)") ("ssu", bool_switch()->default_value(true), "Enable SSU transport (default: enabled)")
("ntcpproxy", value<std::string>()->default_value(""), "Ignored") ("ntcpproxy", value<std::string>()->default_value(""), "Ignored")
("aesni", bool_switch()->default_value(true), "Use auto detection for AESNI CPU extensions. If false, AESNI will be not used")
("avx", bool_switch()->default_value(true), "Use auto detection for AVX CPU extensions. If false, AVX will be not used")
#ifdef _WIN32 #ifdef _WIN32
("svcctl", value<std::string>()->default_value(""), "Windows service management ('install' or 'remove')") ("svcctl", value<std::string>()->default_value(""), "Windows service management ('install' or 'remove')")
("insomnia", bool_switch()->default_value(false), "Prevent system from sleeping (default: disabled)") ("insomnia", bool_switch()->default_value(false), "Prevent system from sleeping (default: disabled)")
@ -268,6 +266,13 @@ namespace config {
("persist.addressbook", value<bool>()->default_value(true), "Persist full addresses (default: true)") ("persist.addressbook", value<bool>()->default_value(true), "Persist full addresses (default: true)")
; ;
options_description cpuext("CPU encryption extensions options");
cpuext.add_options()
("cpuext.aesni", bool_switch()->default_value(true), "Use auto detection for AESNI CPU extensions. If false, AESNI will be not used")
("cpuext.avx", bool_switch()->default_value(true), "Use auto detection for AVX CPU extensions. If false, AVX will be not used")
("cpuext.force", bool_switch()->default_value(false), "Force usage of CPU extensions. Useful when cpuinfo is not available on virtual machines")
;
m_OptionsDesc m_OptionsDesc
.add(general) .add(general)
.add(limits) .add(limits)
@ -288,6 +293,7 @@ namespace config {
.add(ntcp2) .add(ntcp2)
.add(nettime) .add(nettime)
.add(persist) .add(persist)
.add(cpuext)
; ;
} }

View file

@ -1345,9 +1345,9 @@ namespace crypto
} }
}*/ }*/
void InitCrypto (bool precomputation, bool aesni, bool avx) void InitCrypto (bool precomputation, bool aesni, bool avx, bool force)
{ {
i2p::cpu::Detect (aesni, avx); i2p::cpu::Detect (aesni, avx, force);
#if LEGACY_OPENSSL #if LEGACY_OPENSSL
SSL_library_init (); SSL_library_init ();
#endif #endif

View file

@ -319,7 +319,7 @@ namespace crypto
}; };
// init and terminate // init and terminate
void InitCrypto (bool precomputation, bool aesni, bool avx); void InitCrypto (bool precomputation, bool aesni, bool avx, bool force);
void TerminateCrypto (); void TerminateCrypto ();
} }
} }

View file

@ -37,9 +37,10 @@ namespace api
i2p::fs::Init(); i2p::fs::Init();
bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation); bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation);
bool aesni; i2p::config::GetOption("aesni", aesni); bool aesni; i2p::config::GetOption("cpuext.aesni", aesni);
bool avx; i2p::config::GetOption("avx", avx); bool avx; i2p::config::GetOption("cpuext.avx", avx);
i2p::crypto::InitCrypto (precomputation, aesni, avx); bool forceCpuExt; i2p::config::GetOption("cpuext.force", forceCpuExt);
i2p::crypto::InitCrypto (precomputation, aesni, avx, forceCpuExt);
int netID; i2p::config::GetOption("netid", netID); int netID; i2p::config::GetOption("netid", netID);
i2p::context.SetNetID (netID); i2p::context.SetNetID (netID);