"Fossies" - the Fresh Open Source Software Archive

Member "linux_logo-6.0/libsysinfo-0.3.0/Linux/cpuinfo_alpha.c" (8 May 2020, 2680 Bytes) of package /linux/misc/linux_logo-6.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Re-written from scratch 3 March 2001      */
    2 /* Handles alpha chips on Linux architecture */
    3 /* by Vince Weaver <vince@deater.net>        */
    4 
    5 #include <stdio.h>
    6 #include <string.h>
    7 #include <stdlib.h>  /* atof */
    8 
    9 #include "../sysinfo.h"
   10 #include "../include/generic.h"
   11 
   12 int get_cpu_info(struct cpu_info_type *cpu_info) {
   13 
   14     FILE *fff;
   15     char temp_string[BUFSIZ];
   16     char vendor_string[BUFSIZ],model_string[BUFSIZ],hardware_string[BUFSIZ];
   17     int cpu_count=0;
   18     float megahertz=0.0,bogomips=0.0;
   19 
   20     vendor_string[0]=model_string[0]=hardware_string[0]=0;
   21 
   22     /* We get all of our info here from /proc/cpuinfo */
   23     if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
   24 
   25         while ( (fgets(temp_string,255,fff)!=NULL) ) {
   26 
   27             if ( !(strncmp(temp_string,"cpu model",9))) {
   28                 strncpy(model_string,parse_line(temp_string),BUFSIZ-1);
   29                 clip_lf(model_string,BUFSIZ);
   30             }
   31             else if ( !(strncmp(temp_string,"cpu  ",5)) ||
   32                     !(strncmp(temp_string,"cpu\t",4))) {
   33                 strncpy(vendor_string,parse_line(temp_string),BUFSIZ-1);
   34                 clip_lf(vendor_string,BUFSIZ);
   35             }
   36 
   37             if (!(strncmp(temp_string,"cpus detected",13))) {
   38                 cpu_count=atoi(parse_line(temp_string));
   39             }
   40 
   41             /* Older cpuinfo */
   42             if (!(strncmp(temp_string,"CPUs probed",11))) {
   43                 sscanf(temp_string,"%*s %*s %i",&cpu_count);
   44             }
   45 
   46             if (!(strncmp(temp_string,"cycle frequency",15))) {
   47                 megahertz=atof(parse_line(temp_string));
   48             }
   49 
   50             /* Ugh why must people play with capitalization */
   51             if ( !(strncmp(temp_string,"bogomips",8)) ||
   52                 !(strncmp(temp_string,"BogoMips",8)) ||
   53                 !(strncmp(temp_string,"BogoMIPS",8))) {
   54 
   55                 bogomips+=atof(parse_line(temp_string));
   56                 /* Cheating way to detect number of intel CPUs */
   57                 cpu_count++;
   58             }
   59         }
   60     }
   61 
   62     strncpy_truncate(cpu_info->chip_vendor,vendor_string,SYSINFO_CHIP_VENDOR_SIZE);
   63     strncpy_truncate(cpu_info->chip_type,model_string,SYSINFO_CHIP_TYPE_SIZE);
   64 
   65     /* Sanity check.  You can't run Linux w/o a cpu can you? */
   66     /* an ev5 cpuinfo I have says "cpus detected: 0"         */
   67     if (cpu_count==0) cpu_count=1;
   68 
   69     cpu_info->num_cpus=cpu_count;
   70     cpu_info->megahertz=megahertz/1000000.0;
   71     cpu_info->bogomips=bogomips;
   72 
   73     return 0;
   74 
   75 }
   76 
   77 int get_hardware(char *hardware_string) {
   78 
   79     char temp_string[BUFSIZ];
   80     FILE *fff;
   81 
   82     if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
   83 
   84         while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) {
   85 
   86             if (!(strncmp(temp_string,"platform string",15))) {
   87                 strncpy(hardware_string,parse_line(temp_string),
   88                     SYSINFO_HARDWARE_STRING_SIZE);
   89             }
   90 
   91         }
   92     }
   93     return 1;
   94 }
   95 
   96 /* Some architectures might have better ways of detecting RAM size */
   97 long long get_arch_specific_mem_size(void) {
   98     /* We have no special way of detecting RAM */
   99     return 0;
  100 }