diff --git a/osdep/BSDEthernetTap.cpp b/osdep/BSDEthernetTap.cpp index 2a8aac0fb..1a240c1a1 100644 --- a/osdep/BSDEthernetTap.cpp +++ b/osdep/BSDEthernetTap.cpp @@ -65,6 +65,7 @@ namespace ZeroTier { BSDEthernetTap::BSDEthernetTap( const char *homePath, unsigned int concurrency, + bool pinning, const MAC &mac, unsigned int mtu, unsigned int metric, @@ -74,6 +75,7 @@ BSDEthernetTap::BSDEthernetTap( void *arg) : _handler(handler), _concurrency(concurrency), + _pinning(pinning), _arg(arg), _nwid(nwid), _mtu(mtu), @@ -425,25 +427,16 @@ void BSDEthernetTap::setMtu(unsigned int mtu) void BSDEthernetTap::threadMain() throw() { - bool _enablePinning = false; - char* envvar = std::getenv("ZT_CPU_PINNING"); - if (envvar) { - int tmp = atoi(envvar); - if (tmp > 0) { - _enablePinning = true; - } - } - // Wait for a moment after startup -- wait for Network to finish // constructing itself. Thread::sleep(500); for (unsigned int i = 0; i < _concurrency; ++i) { - _rxThreads.push_back(std::thread([this, i, _enablePinning] { + _rxThreads.push_back(std::thread([this, i, _pinning] { - if (_enablePinning) { + if (_pinning) { int pinCore = i % _concurrency; - fprintf(stderr, "pinning thread %d to core %d\n", i, pinCore); + fprintf(stderr, "Pinning thread %d to core %d\n", i, pinCore); pthread_t self = pthread_self(); cpu_set_t cpuset; CPU_ZERO(&cpuset); @@ -452,7 +445,7 @@ void BSDEthernetTap::threadMain() int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset); if (rc != 0) { - fprintf(stderr, "failed to pin thread %d to core %d: %s\n", i, pinCore, strerror(errno)); + fprintf(stderr, "Failed to pin thread %d to core %d: %s\n", i, pinCore, strerror(errno)); exit(1); } } diff --git a/osdep/BSDEthernetTap.hpp b/osdep/BSDEthernetTap.hpp index 4d1a42429..50e2e6e8b 100644 --- a/osdep/BSDEthernetTap.hpp +++ b/osdep/BSDEthernetTap.hpp @@ -36,6 +36,7 @@ public: BSDEthernetTap( const char *homePath, unsigned int concurrency, + bool pinning, const MAC &mac, unsigned int mtu, unsigned int metric, @@ -65,6 +66,7 @@ private: void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int); void *_arg; unsigned int _concurrency; + bool _pinning; uint64_t _nwid; Thread _thread; std::string _dev;