Back to index

glibc  2.9
getsysstats.c
Go to the documentation of this file.
00001 /* System dependent pieces of sysconf; Mach version
00002    Copyright (C) 1996,97,99,2001,02 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <mach.h>
00022 #include <hurd.h>
00023 #include <sys/sysinfo.h>
00024 
00025 
00026 /* Return the number of processors configured on the system. */
00027 int
00028 __get_nprocs_conf ()
00029 {
00030   struct host_basic_info hbi;
00031   kern_return_t err;
00032   mach_msg_type_number_t cnt = HOST_BASIC_INFO_COUNT;
00033 
00034   err = __host_info (__mach_host_self (), HOST_BASIC_INFO,
00035                    (host_info_t) &hbi, &cnt);
00036   if (err)
00037     return __hurd_fail (err);
00038   else if (cnt != HOST_BASIC_INFO_COUNT)
00039     return __hurd_fail (EIEIO);
00040 
00041   return hbi.max_cpus;
00042 }
00043 
00044 /* Return the number of processors currently available on the system. */
00045 int
00046 __get_nprocs ()
00047 {
00048   struct host_basic_info hbi;
00049   kern_return_t err;
00050   mach_msg_type_number_t cnt = HOST_BASIC_INFO_COUNT;
00051 
00052   err = __host_info (__mach_host_self (), HOST_BASIC_INFO,
00053                    (host_info_t) &hbi, &cnt);
00054   if (err)
00055     return __hurd_fail (err);
00056   else if (cnt != HOST_BASIC_INFO_COUNT)
00057     return __hurd_fail (EIEIO);
00058 
00059   return hbi.avail_cpus;
00060 }
00061 
00062 /* Return the number of physical pages on the system. */
00063 long int
00064 __get_phys_pages ()
00065 {
00066   struct host_basic_info hbi;
00067   kern_return_t err;
00068   mach_msg_type_number_t cnt = HOST_BASIC_INFO_COUNT;
00069 
00070   err = __host_info (__mach_host_self (), HOST_BASIC_INFO,
00071                    (host_info_t) &hbi, &cnt);
00072   if (err)
00073     return __hurd_fail (err);
00074   else if (cnt != HOST_BASIC_INFO_COUNT)
00075     return __hurd_fail (EIEIO);
00076 
00077   return hbi.memory_size / __vm_page_size;
00078 }
00079 
00080 /* Return the number of available physical pages */
00081 long int
00082 __get_avphys_pages ()
00083 {
00084   vm_statistics_data_t vs;
00085   kern_return_t err;
00086 
00087 #ifdef HOST_VM_INFO
00088   {
00089     mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
00090     err = __host_info (__mach_host_self (), HOST_VM_INFO,
00091                      (host_info_t) &vs, &count);
00092     if (!err && count < HOST_VM_INFO_COUNT)
00093       err = EGRATUITOUS;
00094   }
00095 #else
00096   err = __vm_statistics (__mach_task_self (), &vs);
00097 #endif
00098   if (err)
00099     return __hurd_fail (err);
00100 
00101   return vs.free_count;
00102 }