00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <dirent.h>
00021 #include <errno.h>
00022 #include <stdio.h>
00023
00024
00025 #include "info.h"
00026
00027
00028
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
00040 if (cpu_node != -1) {
00041 errno = EINVAL;
00042 return -1;
00043 }
00044
00045
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
00061
00062 int _base_spe_count_usable_spes(int cpu_node)
00063 {
00064 return _base_spe_count_physical_spes(cpu_node);
00065 }
00066
00067
00068
00069
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
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
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;
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 }