libspe2 0.9a
|
00001 /* 00002 * libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS 00003 * Copyright (C) 2005 IBM Corp. 00004 * 00005 * This library is free software; you can redistribute it and/or modify it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, 00008 * or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this library; if not, write to the Free Software Foundation, 00017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #include <dirent.h> 00021 #include <errno.h> 00022 #include <stdio.h> 00023 00024 00025 #include "info.h" 00026 00027 /* 00028 * For the moment, we count the numbers of cpus and devide by 2. 00029 */ 00030 int _base_spe_count_physical_cpus(int cpu_node) 00031 { 00032 const char *buff = "/sys/devices/system/cpu"; 00033 DIR *dirp; 00034 int ret = -2; 00035 struct dirent *dptr; 00036 00037 DEBUG_PRINTF ("spe_count_physical_cpus()\n"); 00038 00039 // make sure, cpu_node is in the correct range 00040 if (cpu_node != -1) { 00041 errno = EINVAL; 00042 return -1; 00043 } 00044 00045 // Count number of CPUs in /sys/devices/system/cpu 00046 if((dirp=opendir(buff))==NULL) { 00047 fprintf(stderr,"Error opening %s ",buff); 00048 perror("dirlist"); 00049 errno = EINVAL; 00050 return -1; 00051 } 00052 while((dptr=readdir(dirp))) { 00053 ret++; 00054 } 00055 closedir(dirp); 00056 return ret/THREADS_PER_BE; 00057 } 00058 00059 /* 00060 * For the moment, we use all spes which are controlled by linux 00061 */ 00062 int _base_spe_count_usable_spes(int cpu_node) 00063 { 00064 return _base_spe_count_physical_spes(cpu_node); // FIXME 00065 } 00066 00067 /* 00068 * For the moment, we assume all SPEs are evenly distributed over the 00069 * physical cpsus. 00070 */ 00071 int _base_spe_count_physical_spes(int cpu_node) 00072 { 00073 const char *buff = "/sys/devices/system/spu"; 00074 DIR *dirp; 00075 int ret = -2; 00076 struct dirent *dptr; 00077 int no_of_bes; 00078 00079 DEBUG_PRINTF ("spe_count_physical_spes()\n"); 00080 00081 // make sure, cpu_node is in the correct range 00082 no_of_bes = _base_spe_count_physical_cpus(-1); 00083 if (cpu_node < -1 || cpu_node >= no_of_bes ) { 00084 errno = EINVAL; 00085 return -1; 00086 } 00087 00088 // Count number of SPUs in /sys/devices/system/spu 00089 if((dirp=opendir(buff))==NULL) { 00090 fprintf(stderr,"Error opening %s ",buff); 00091 perror("dirlist"); 00092 errno = EINVAL; 00093 return -1; 00094 } 00095 while((dptr=readdir(dirp))) { 00096 ret++; 00097 } 00098 closedir(dirp); 00099 00100 if(cpu_node != -1) ret /= no_of_bes; // FIXME 00101 return ret; 00102 } 00103 00104 00105 int _base_spe_cpu_info_get(int info_requested, int cpu_node) { 00106 int ret = 0; 00107 errno = 0; 00108 00109 switch (info_requested) { 00110 case SPE_COUNT_PHYSICAL_CPU_NODES: 00111 ret = _base_spe_count_physical_cpus(cpu_node); 00112 break; 00113 case SPE_COUNT_PHYSICAL_SPES: 00114 ret = _base_spe_count_physical_spes(cpu_node); 00115 break; 00116 case SPE_COUNT_USABLE_SPES: 00117 ret = _base_spe_count_usable_spes(cpu_node); 00118 break; 00119 default: 00120 errno = EINVAL; 00121 ret = -1; 00122 } 00123 return ret; 00124 }