Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "libts.h"
00032 #include "ink_platform.h"
00033 #if defined(linux) || defined(freebsd) || defined(darwin)
00034 #include <sys/types.h>
00035 #include <sys/param.h>
00036 #include <sys/sysctl.h>
00037 #endif
00038 #if defined(linux)
00039 #include <sys/utsname.h>
00040 #endif
00041
00042 int off = 0;
00043 int on = 1;
00044
00045 #if TS_USE_HWLOC
00046
00047 #include <hwloc.h>
00048
00049
00050 static hwloc_topology_t
00051 setup_hwloc()
00052 {
00053 hwloc_topology_t topology;
00054
00055 hwloc_topology_init(&topology);
00056 hwloc_topology_load(topology);
00057
00058 return topology;
00059 }
00060
00061
00062 hwloc_topology_t
00063 ink_get_topology()
00064 {
00065 static hwloc_topology_t topology = setup_hwloc();
00066 return topology;
00067 }
00068
00069 #endif
00070
00071 int
00072 ink_sys_name_release(char *name, int namelen, char *release, int releaselen)
00073 {
00074 *name = 0;
00075 *release = 0;
00076 #if defined(freebsd) || defined(darwin)
00077 int mib[2];
00078 size_t len = namelen;
00079 mib[0] = CTL_KERN;
00080 mib[1] = KERN_OSTYPE;
00081
00082 if (sysctl(mib, 2, name, &len, NULL, 0) == -1)
00083 return -1;
00084
00085 len = releaselen;
00086 mib[0] = CTL_KERN;
00087 mib[1] = KERN_OSRELEASE;
00088
00089 if (sysctl(mib, 2, release, &len, NULL, 0) == -1)
00090 return -1;
00091
00092 return 0;
00093 #elif defined(linux)
00094 struct utsname buf;
00095 int n;
00096
00097 if (uname(&buf))
00098 return -1;
00099
00100 n = strlen(buf.sysname);
00101 if (namelen <= n)
00102 n = namelen - 1;
00103 memcpy(name, buf.sysname, n);
00104 name[n] = 0;
00105
00106 n = strlen(buf.release);
00107 if (releaselen <= n)
00108 n = releaselen - 1;
00109 memcpy(release, buf.release, n);
00110 release[n] = 0;
00111
00112 return 0;
00113 #else
00114 return -1;
00115 #endif
00116 }
00117
00118 int
00119 ink_number_of_processors()
00120 {
00121 #if TS_USE_HWLOC
00122 #if HAVE_HWLOC_OBJ_PU
00123 return hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_PU);
00124 #else
00125 return hwloc_get_nbobjs_by_type(ink_get_topology(), HWLOC_OBJ_CORE);
00126 #endif
00127 #elif defined(freebsd)
00128 int mib[2], n;
00129 mib[0] = CTL_HW;
00130 mib[1] = HW_NCPU;
00131 size_t len = sizeof(n);
00132 if (sysctl(mib, 2, &n, &len, NULL, 0) == -1)
00133 return 1;
00134 return n;
00135 #else
00136 return sysconf(_SC_NPROCESSORS_ONLN);
00137 #endif
00138 }