• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_defs.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   ink_defs.h
00027   Some small general interest definitions
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      /* MAGIC_EDITING_TAG */
00041 
00042 int off = 0;
00043 int on = 1;
00044 
00045 #if TS_USE_HWLOC
00046 
00047 #include <hwloc.h>
00048 
00049 // Little helper to initialize the hwloc topology, once.
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 // Get the topology
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); // number of processing units (includes Hyper Threading)
00137 #endif
00138 }

Generated by  doxygen 1.7.1