the number of online cpu

sysctl hw.ncpu?
I need a API or method in kernel space. Such as num_online_cpus(), which is a Linux kernel API.
 
Code:
#include <sys/param.h>
#include <sys/sysctl.h>

#include <stdio.h>


int main(int argc, char **argv) {
	int error, ncpu, req[2];
	size_t len;
	
	req[0] = CTL_HW;
	req[1] = HW_NCPU;
	
	len = sizeof(ncpu);
	error = sysctl(req, 2, &ncpu, &len, NULL, 0);
	if (error < 0)
		return;
	
	printf("Number of CPU's you have: %d\n", ncpu);
	
	return 0;
}
I hope this help, more information.
 
SIFE said:
Code:
#include <sys/param.h>
#include <sys/sysctl.h>

#include <stdio.h>


int main(int argc, char **argv) {
	int error, ncpu, req[2];
	size_t len;
	
	req[0] = CTL_HW;
	req[1] = HW_NCPU;
	
	len = sizeof(ncpu);
	error = sysctl(req, 2, &ncpu, &len, NULL, 0);
	if (error < 0)
		return;
	
	printf("Number of CPU's you have: %d\n", ncpu);
	
	return 0;
}
I hope this help, more information.

thanks
 
I want it in kernel module. So I need a KPI to find number of online cpu> Also I need a per cpu variable?

Thanks
 
Back
Top