how to find number of cpu (cores) available for application?
Alexander Tormasov
a.tormasov at innopolis.ru
Fri Jul 24 10:56:05 CEST 2020
I am trying to understand how many cpu or/and cored are available for running application.
I check code related to sysctl in libports/src/lib/libc/sysctl.cc<http://sysctl.cc>
and found
extern "C" int __sysctl(const int *name, u_int namelen,
void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
{
…
/* fallback values */
{
switch(index_a) {
…
case CTL_HW: switch(index_b) {
case HW_MACHINE:
*oldlenp = 0;
return 0;
case HW_NCPU:
*(int*)oldp = 1;
*oldlenp = sizeof(int);
return 0;
} break;
…
in short, if I used standardised for BSD code (like below in golang) it always return 1!
int32
getproccount(void)
{
int mib[2], out;
size_t len;
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(out);
if(sysctl(mib, 2, &out, &len, NULL, 0) >= 0)
return (int32)out;
else
return 0;
}
Any suggestions? How I can have portable code for Genode to obtain at least NCPU?
Sincerely,
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.genode.org/pipermail/users/attachments/20200724/f9023135/attachment.html>
More information about the users
mailing list