mirror of
				https://git.tukaani.org/xz.git
				synced 2025-11-03 23:12:57 +00:00 
			
		
		
		
	tuklib_cpucores: Use HW_NCPUONLINE on OpenBSD.
On OpenBSD the number of cores online is often less than what HW_NCPU would return because OpenBSD disables simultaneous multi-threading (SMT) by default. Thanks to Christian Weisgerber.
This commit is contained in:
		
							parent
							
								
									424ac91c7e
								
							
						
					
					
						commit
						2611c4d905
					
				@ -102,7 +102,12 @@ compile error
 | 
				
			|||||||
int
 | 
					int
 | 
				
			||||||
main(void)
 | 
					main(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					#ifdef HW_NCPUONLINE
 | 
				
			||||||
 | 
						/* This is preferred on OpenBSD, see tuklib_cpucores.c. */
 | 
				
			||||||
 | 
						int name[2] = { CTL_HW, HW_NCPUONLINE };
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
	int name[2] = { CTL_HW, HW_NCPU };
 | 
						int name[2] = { CTL_HW, HW_NCPU };
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	int cpus;
 | 
						int cpus;
 | 
				
			||||||
	size_t cpus_size = sizeof(cpus);
 | 
						size_t cpus_size = sizeof(cpus);
 | 
				
			||||||
	sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
 | 
						sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
 | 
				
			||||||
 | 
				
			|||||||
@ -72,7 +72,16 @@ tuklib_cpucores(void)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#elif defined(TUKLIB_CPUCORES_SYSCTL)
 | 
					#elif defined(TUKLIB_CPUCORES_SYSCTL)
 | 
				
			||||||
 | 
						// On OpenBSD HW_NCPUONLINE tells the number of processor cores that
 | 
				
			||||||
 | 
						// are online so it is preferred over HW_NCPU which also counts cores
 | 
				
			||||||
 | 
						// that aren't currently available. The number of cores online is
 | 
				
			||||||
 | 
						// often less than HW_NCPU because OpenBSD disables simultaneous
 | 
				
			||||||
 | 
						// multi-threading (SMT) by default.
 | 
				
			||||||
 | 
					#	ifdef HW_NCPUONLINE
 | 
				
			||||||
 | 
						int name[2] = { CTL_HW, HW_NCPUONLINE };
 | 
				
			||||||
 | 
					#	else
 | 
				
			||||||
	int name[2] = { CTL_HW, HW_NCPU };
 | 
						int name[2] = { CTL_HW, HW_NCPU };
 | 
				
			||||||
 | 
					#	endif
 | 
				
			||||||
	int cpus;
 | 
						int cpus;
 | 
				
			||||||
	size_t cpus_size = sizeof(cpus);
 | 
						size_t cpus_size = sizeof(cpus);
 | 
				
			||||||
	if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1
 | 
						if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user