Browse Source

More platform-related build fixes

Joseph Henry 1 year ago
parent
commit
e734019216

+ 6 - 4
osdep/EthernetTap.cpp

@@ -57,6 +57,8 @@ namespace ZeroTier {
 
 
 std::shared_ptr<EthernetTap> EthernetTap::newInstance(
 std::shared_ptr<EthernetTap> EthernetTap::newInstance(
 	const char *tapDeviceType, // OS-specific, NULL for default
 	const char *tapDeviceType, // OS-specific, NULL for default
+	unsigned int concurrency,
+	bool pinning,
 	const char *homePath,
 	const char *homePath,
 	const MAC &mac,
 	const MAC &mac,
 	unsigned int mtu,
 	unsigned int mtu,
@@ -92,7 +94,7 @@ std::shared_ptr<EthernetTap> EthernetTap::newInstance(
 #endif // __APPLE__
 #endif // __APPLE__
 
 
 #ifdef __LINUX__
 #ifdef __LINUX__
-	return std::shared_ptr<EthernetTap>(new LinuxEthernetTap(homePath,mac,mtu,metric,nwid,friendlyName,handler,arg));
+	return std::shared_ptr<EthernetTap>(new LinuxEthernetTap(homePath,concurrency,pinning,mac,mtu,metric,nwid,friendlyName,handler,arg));
 #endif // __LINUX__
 #endif // __LINUX__
 
 
 #ifdef __WINDOWS__
 #ifdef __WINDOWS__
@@ -126,15 +128,15 @@ std::shared_ptr<EthernetTap> EthernetTap::newInstance(
 			_comInit = true;
 			_comInit = true;
 		}
 		}
 	}
 	}
-	return std::shared_ptr<EthernetTap>(new WindowsEthernetTap(homePath,concurrency,mac,mtu,metric,nwid,friendlyName,handler,arg));
+	return std::shared_ptr<EthernetTap>(new WindowsEthernetTap(homePath,mac,mtu,metric,nwid,friendlyName,handler,arg));
 #endif // __WINDOWS__
 #endif // __WINDOWS__
 
 
 #ifdef __FreeBSD__
 #ifdef __FreeBSD__
-	return std::shared_ptr<EthernetTap>(new BSDEthernetTap(homePath,concurrency,mac,mtu,metric,nwid,friendlyName,handler,arg));
+	return std::shared_ptr<EthernetTap>(new BSDEthernetTap(homePath,concurrency,pinning,mac,mtu,metric,nwid,friendlyName,handler,arg));
 #endif // __FreeBSD__
 #endif // __FreeBSD__
 
 
 #ifdef __NetBSD__
 #ifdef __NetBSD__
-	return std::shared_ptr<EthernetTap>(new NetBSDEthernetTap(homePath,concurrency,mac,mtu,metric,nwid,friendlyName,handler,arg));
+	return std::shared_ptr<EthernetTap>(new NetBSDEthernetTap(homePath,mac,mtu,metric,nwid,friendlyName,handler,arg));
 #endif // __NetBSD__
 #endif // __NetBSD__
 
 
 #ifdef __OpenBSD__
 #ifdef __OpenBSD__

+ 2 - 0
osdep/EthernetTap.hpp

@@ -32,6 +32,8 @@ class EthernetTap
 public:
 public:
 	static std::shared_ptr<EthernetTap> newInstance(
 	static std::shared_ptr<EthernetTap> newInstance(
 		const char *tapDeviceType, // OS-specific, NULL for default
 		const char *tapDeviceType, // OS-specific, NULL for default
+		unsigned int concurrency,
+		bool pinning,
 		const char *homePath,
 		const char *homePath,
 		const MAC &mac,
 		const MAC &mac,
 		unsigned int mtu,
 		unsigned int mtu,

+ 8 - 30
osdep/LinuxEthernetTap.cpp

@@ -111,6 +111,8 @@ static void _base32_5_to_8(const uint8_t *in,char *out)
 
 
 LinuxEthernetTap::LinuxEthernetTap(
 LinuxEthernetTap::LinuxEthernetTap(
 	const char *homePath,
 	const char *homePath,
+	unsigned int concurrency,
+	bool pinning,
 	const MAC &mac,
 	const MAC &mac,
 	unsigned int mtu,
 	unsigned int mtu,
 	unsigned int metric,
 	unsigned int metric,
@@ -220,36 +222,12 @@ LinuxEthernetTap::LinuxEthernetTap(
 
 
 	(void)::pipe(_shutdownSignalPipe);
 	(void)::pipe(_shutdownSignalPipe);
 
 
-	bool _enablePinning = false;
-	char* envvar = std::getenv("ZT_CORE_PINNING");
-	if (envvar) {
-		int tmp = atoi(envvar);
-		if (tmp > 0) {
-			_enablePinning = true;
-		}
-	}
-
-	int _concurrency = 1;
-	char* concurrencyVar = std::getenv("ZT_PACKET_PROCESSING_CONCURRENCY");
-	if (concurrencyVar) {
-		int tmp = atoi(concurrencyVar);
-		if (tmp > 0) {
-			_concurrency = tmp;
-		}
-		else {
-			_concurrency = std::max((unsigned int)1,std::thread::hardware_concurrency() / 2);
-		}
-	}
-	else {
-		_concurrency = std::max((unsigned int)1,std::thread::hardware_concurrency() / 2);
-	}
-
-	for (unsigned int i = 0; i < _concurrency; ++i) {
-		_rxThreads.push_back(std::thread([this, i, _concurrency, _enablePinning] {
+	for (unsigned int i = 0; i < concurrency; ++i) {
+		_rxThreads.push_back(std::thread([this, i, concurrency, pinning] {
 
 
-			if (_enablePinning) {
-				int pinCore = i % _concurrency;
-				fprintf(stderr, "pinning tap thread %d to core %d\n", i, pinCore);
+			if (pinning) {
+				int pinCore = i % concurrency;
+				fprintf(stderr, "Pinning tap thread %d to core %d\n", i, pinCore);
 				pthread_t self = pthread_self();
 				pthread_t self = pthread_self();
 				cpu_set_t cpuset;
 				cpu_set_t cpuset;
 				CPU_ZERO(&cpuset);
 				CPU_ZERO(&cpuset);
@@ -257,7 +235,7 @@ LinuxEthernetTap::LinuxEthernetTap(
 				int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
 				int rc = pthread_setaffinity_np(self, sizeof(cpu_set_t), &cpuset);
 				if (rc != 0)
 				if (rc != 0)
 				{
 				{
-					fprintf(stderr, "failed to pin tap thread %d to core %d: %s\n", i, pinCore, strerror(errno));
+					fprintf(stderr, "Failed to pin tap thread %d to core %d: %s\n", i, pinCore, strerror(errno));
 					exit(1);
 					exit(1);
 				}
 				}
 			}
 			}

+ 2 - 0
osdep/LinuxEthernetTap.hpp

@@ -35,6 +35,8 @@ class LinuxEthernetTap : public EthernetTap
 public:
 public:
 	LinuxEthernetTap(
 	LinuxEthernetTap(
 		const char *homePath,
 		const char *homePath,
+		unsigned int concurrency,
+		bool pinning,
 		const MAC &mac,
 		const MAC &mac,
 		unsigned int mtu,
 		unsigned int mtu,
 		unsigned int metric,
 		unsigned int metric,

+ 2 - 0
service/OneService.cpp

@@ -3239,6 +3239,8 @@ public:
 
 
 						n.setTap(EthernetTap::newInstance(
 						n.setTap(EthernetTap::newInstance(
 							nullptr,
 							nullptr,
+							_concurrency,
+							_cpuPinningEnabled,
 							_homePath.c_str(),
 							_homePath.c_str(),
 							MAC(nwc->mac),
 							MAC(nwc->mac),
 							nwc->mtu,
 							nwc->mtu,