1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include "msg_utilib.h"
#if defined(NECSX4) || defined(NECSX5)
# include <sys/rsg.h>
# include <sys/types.h>
# include <fcntl.h>
# include <sys/syssx.h>
#endif
#if defined(DARWIN)
# include <mach/host_info.h>
# include <mach/mach_host.h>
# include <mach/mach_init.h>
# include <mach/machine.h>
#endif
#if defined(__sgi)
# include <sys/types.h>
# include <sys/sysmp.h>
#endif
#if defined(ALPHA)
# include <sys/sysinfo.h>
# include <machine/hal_sysinfo.h>
#endif
#if defined(SOLARIS) || defined(AIX) || defined(LINUX)
# include <unistd.h>
#endif
#if defined(__hpux)
/* needs to be copiled with std C compiler ==> no -Aa switch no gcc */
# include <stdlib.h>
# include <sys/pstat.h>
# include <unistd.h>
#endif
#if defined(CRAY)
# include <unistd.h>
#endif
#if defined(FREEBSD)
# include <sys/types.h>
# include <sys/sysctl.h>
#endif
#if defined(NETBSD)
# include <sys/param.h>
# include <sys/sysctl.h>
#endif
#ifdef NPROCS_TEST
# include <stdio.h>
# include <unistd.h>
void main(int, char**);
#endif
#ifndef NPROCS_TEST
#include "sge_os.h"
#else
int sge_nprocs (void);
#endif
#if defined(NECSX4) || defined(NECSX5)
int sge_nprocs_rsg(rsg_id) {
int nprocs;
int fd;
rsg_info_t info;
char fsg_dev_string[256];
nprocs = 0;
sprintf(fsg_dev_string, "/dev/rsg/%d", rsg_id);
fd = open(fsg_dev_string, O_RDONLY);
if (fd > 0) {
if (ioctl(fd, RSG_INFO, &info) == -1) {
close(fd);
return 0;
}
close(fd);
nprocs += info.cprb.init_cpu;
}
return nprocs;
}
#endif
/****** uti/os/sge_nprocs() ***************************************************
* NAME
* sge_nprocs() -- Number of processors in this machine
*
* SYNOPSIS
* int sge_nprocs()
*
* FUNCTION
* Use this function to get the number of processors in
* this machine
*
* RESULT
* int - number of procs
*
* NOTES
* MT-NOTE: sge_nprocs() is MT safe (SOLARIS, NEC, IRIX, ALPHA, HPUX, LINUX)
******************************************************************************/
int sge_nprocs()
{
int nprocs=1; /* default */
#if defined(NECSX4) || defined(NECSX5)
int fd;
int fsg_id;
rsg_info_t info;
char fsg_dev_string[256];
#endif
/* NEC SX 4/16, NEC SX 4/32 */
#if defined(NECSX4) || defined(NECSX5)
/*
* Using RSG values alone is unreliable.
*/
#if 0
nprocs = 0;
for (fsg_id=0; fsg_id<32; fsg_id++) {
sprintf(fsg_dev_string, "/dev/rsg/%d", fsg_id);
fd = open(fsg_dev_string, O_RDONLY);
if (fd > 0) {
if (ioctl(fd, RSG_INFO, &info) == -1) {
close(fd);
continue;
}
close(fd);
nprocs += info.cprb.init_cpu;
}
}
if (nprocs == 0) {
nprocs=1;
}
#elif 1
#if defined(CNFGAPNUM)
/*
* SUPER-UX >= 11.x provides a function.
*/
nprocs = syssx(CNFGAPNUM);
#else
{
/*
* As with sge_loadmem(), get RB info and tally
* it up.
*/
char fsg_dev_string[256];
int fd, fsg_id;
rsg_id_t id;
rsg_info_t info;
cpurb_t cpurbs[MAXRBNUM];
int i;
/* initialize */
for (i = 0; i < MAXRBNUM; i++) {
memset(&cpurbs[i], 0, sizeof(cpurb_t));
}
/* read in RB info (don't be fooled by RSG names) */
for (fsg_id = 0; fsg_id < MAXRSGNUM; fsg_id++) {
sprintf(fsg_dev_string, "/dev/rsg/%d", fsg_id);
fd = open(fsg_dev_string, O_RDONLY);
if (fd >= 0) {
if ((ioctl(fd, RSG_ID, &id) == -1) ||
(ioctl(fd, RSG_INFO, &info) == -1)) {
close(fd);
continue;
}
close(fd);
/* copy for later use */
memcpy(&cpurbs[id.cprbid], &info.cprb, sizeof(cpurb_t));
}
}
nprocs = 0;
for (i = 0; i < MAXRBNUM; i++) {
nprocs += cpurbs[i].init_cpu;
}
}
#endif /* CNFGAPNUM */
#endif
#endif
#if defined(DARWIN)
struct host_basic_info cpu_load_data;
mach_msg_type_number_t host_count = sizeof(cpu_load_data)/sizeof(integer_t);
mach_port_t host_priv_port = mach_host_self();
host_info(host_priv_port, HOST_BASIC_INFO , (host_info_t)&cpu_load_data, &host_count);
nprocs = cpu_load_data.avail_cpus;
#endif
#ifdef __sgi
nprocs = sysmp(MP_NPROCS);
#endif
#if defined(ALPHA)
int start=0;
getsysinfo(GSI_CPUS_IN_BOX,(char*)&nprocs,sizeof(nprocs),&start);
#endif
#if defined(SOLARIS) || defined(AIX) || defined(LINUX)
nprocs = sysconf(_SC_NPROCESSORS_ONLN);
#endif
#if defined(__hpux)
union pstun pstatbuf;
struct pst_dynamic dinfo;
pstatbuf.pst_dynamic = &dinfo;
if (pstat(PSTAT_DYNAMIC,pstatbuf,sizeof(dinfo),NULL,NULL)==-1) {
perror(MSG_PERROR_PSTATDYNAMIC);
exit(1);
}
nprocs = dinfo.psd_proc_cnt;
#endif
#ifdef CRAY
nprocs = sysconf(_SC_CRAY_NCPU);
#endif
#if defined(FREEBSD)
size_t nprocs_len = sizeof(nprocs);
if (sysctlbyname("hw.ncpu", &nprocs, &nprocs_len, NULL, 0) == -1) {
nprocs = -1;
}
#endif
#if defined(NETBSD)
int mib[2];
size_t nprocs_len;
nprocs_len = sizeof(nprocs);
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
if (sysctl(mib, sizeof(mib)/sizeof(int), &nprocs, &nprocs_len, NULL, 0) == -1) {
nprocs = -1;
}
#endif
#if defined(INTERIX)
/* TODO: HP: don't set nprocs==-1 to 0, overwrite it with value from
* external load sensor.
*/
nprocs = -1;
#endif
if (nprocs <= 0) {
nprocs = 1;
}
return nprocs;
}
#ifdef NPROCS_TEST
void main(
int argc,
char **argv
) {
printf(MSG_INFO_NUMBOFPROCESSORS_I, sge_nprocs());
printf("\n");
exit(0);
}
#endif
|