~ubuntu-branches/ubuntu/trusty/linuxlogo/trusty

« back to all changes in this revision

Viewing changes to libsysinfo-0.2.1/Linux/cpuinfo_mips.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-06-20 09:19:00 UTC
  • mfrom: (4.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080620091900-4xzuv7c7ntxvs7wt
Tags: 5.03-4
* Adding patch to fix FTBFS on s390x.
* Updating to standards 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Re-written from scratch 3 March 2001      */
 
2
/* Handles mips 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],temp[BUFSIZ];
 
17
    int cpu_count=0;
 
18
    float megahertz=0.0,bogomips=0.0;
 
19
   
 
20
    vendor_string[0]=model_string[0]=0;
 
21
 
 
22
    strncpy(vendor_string,"MIPS",5);
 
23
   
 
24
       /* We get all of our info here from /proc/cpuinfo */
 
25
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
 
26
       
 
27
       while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) {
 
28
        
 
29
          if ( !(strncmp(temp_string,"cpu model",9))) {
 
30
             strncpy(model_string,parse_line(temp_string),BUFSIZ);
 
31
             clip_lf(model_string,BUFSIZ);
 
32
          }
 
33
          else if ( !(strncmp(temp_string,"cpu  ",5)) ||
 
34
                    !(strncmp(temp_string,"cpu\t",4))) {
 
35
             strncpy(vendor_string,parse_line(temp_string),BUFSIZ);
 
36
             clip_lf(vendor_string,BUFSIZ);
 
37
          }
 
38
          
 
39
             /* Ugh why must people play with capitalization */
 
40
          if ( !(strncmp(temp_string,"bogomips",8)) ||
 
41
               !(strncmp(temp_string,"BogoMips",8)) ||
 
42
               !(strncmp(temp_string,"BogoMIPS",8))) {
 
43
             bogomips+=atof(parse_line(temp_string));
 
44
             cpu_count++;  /* Cheating way to detect number of intel CPU's */
 
45
          }
 
46
       }
 
47
    }
 
48
 
 
49
    strncpy(cpu_info->chip_vendor,vendor_string,SYSINFO_CHIP_VENDOR_SIZE);
 
50
    strncpy(cpu_info->chip_type,model_string,SYSINFO_CHIP_TYPE_SIZE);
 
51
   
 
52
    if (!strncmp(model_string,"NEC",3)) {
 
53
       sscanf(model_string,"%*s %s",temp);
 
54
       strncpy(cpu_info->chip_type,temp,SYSINFO_CHIP_TYPE_SIZE);
 
55
    }
 
56
    else if (!strncmp(model_string,"MIPS",4)) {
 
57
       sscanf(model_string,"%*s %s",temp);
 
58
       strncpy(cpu_info->chip_type,temp,SYSINFO_CHIP_TYPE_SIZE);        
 
59
    }
 
60
    else {
 
61
       sscanf(model_string,"%s",temp);
 
62
       strncpy(cpu_info->chip_type,temp,SYSINFO_CHIP_TYPE_SIZE);  
 
63
    }
 
64
   
 
65
    cpu_info->num_cpus=cpu_count;
 
66
    cpu_info->megahertz=megahertz/1000000.0;
 
67
    cpu_info->bogomips=bogomips;
 
68
 
 
69
    return 0;
 
70
   
 
71
}
 
72
 
 
73
int get_hardware(char *hardware_string) {
 
74
    
 
75
    char temp_string[BUFSIZ];
 
76
    FILE *fff;
 
77
   
 
78
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
 
79
       
 
80
       while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) {
 
81
                  
 
82
          if (!(strncmp(temp_string,"system type",11))) {
 
83
             strncpy(hardware_string,parse_line(temp_string),
 
84
                     SYSINFO_HARDWARE_STRING_SIZE);
 
85
          }
 
86
       }
 
87
    }
 
88
    return 1;
 
89
}
 
90
 
 
91
    /* Some architectures might have better ways of detecting RAM size */
 
92
long int get_arch_specific_mem_size(void) {
 
93
       /* We have no special way of detecting RAM */
 
94
       return get_mem_size_sysinfo();
 
95
}