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

« back to all changes in this revision

Viewing changes to libsysinfo-0.2.1/Linux/cpuinfo_alpha.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 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);
 
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);  
 
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
             /* Older cpuinfo */
 
41
          if (!(strncmp(temp_string,"CPUs probed",11))) {
 
42
             sscanf(temp_string,"%*s %*s %i",&cpu_count);  
 
43
          }
 
44
          
 
45
          if (!(strncmp(temp_string,"cycle frequency",15))) {
 
46
             megahertz=atof(parse_line(temp_string));  
 
47
          }
 
48
          
 
49
             /* Ugh why must people play with capitalization */
 
50
          if ( !(strncmp(temp_string,"bogomips",8)) ||
 
51
               !(strncmp(temp_string,"BogoMips",8)) ||
 
52
               !(strncmp(temp_string,"BogoMIPS",8))) {
 
53
             bogomips+=atof(parse_line(temp_string));
 
54
             cpu_count++;  /* Cheating way to detect number of intel CPU's */
 
55
          }
 
56
       }
 
57
    }
 
58
  
 
59
    strncpy(cpu_info->chip_vendor,vendor_string,SYSINFO_CHIP_VENDOR_SIZE);
 
60
    strncpy(cpu_info->chip_type,model_string,SYSINFO_CHIP_TYPE_SIZE);
 
61
  
 
62
       /* Sanity check.  You can't run Linux w/o a cpu can you? */
 
63
       /* an ev5 cpuinfo I have says "cpus detected: 0"         */
 
64
    if (cpu_count==0) cpu_count=1;
 
65
   
 
66
    cpu_info->num_cpus=cpu_count;
 
67
    cpu_info->megahertz=megahertz/1000000.0;
 
68
    cpu_info->bogomips=bogomips;
 
69
 
 
70
    return 0;
 
71
   
 
72
}
 
73
 
 
74
int get_hardware(char *hardware_string) {
 
75
    
 
76
    char temp_string[BUFSIZ];
 
77
    FILE *fff;
 
78
   
 
79
    if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
 
80
       
 
81
       while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) {
 
82
                  
 
83
          if (!(strncmp(temp_string,"platform string",15))) {
 
84
             strncpy(hardware_string,parse_line(temp_string),
 
85
                     SYSINFO_HARDWARE_STRING_SIZE);
 
86
          }
 
87
 
 
88
       }
 
89
    }
 
90
    return 1;
 
91
}
 
92
 
 
93
    /* Some architectures might have better ways of detecting RAM size */
 
94
long int get_arch_specific_mem_size(void) {
 
95
    /* We have no special way of detecting RAM */
 
96
    return -1;
 
97
}