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

« back to all changes in this revision

Viewing changes to libsysinfo-0.1.0/Linux/cpuinfo_ia64.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 intel chips on Linux architecture */
3
 
/* by Vince Weaver <vince@deater.net>        */
4
 
/* update for IA-64 architecture             */
5
 
/* by Ludo <lfrancois@mandrakesoft.com>      */
6
 
 
7
 
#include <stdio.h>
8
 
 
9
 
#include <string.h>
10
 
#include <stdlib.h>  /* atof */
11
 
 
12
 
#include "../sysinfo.h"
13
 
#include "../include/generic.h"
14
 
 
15
 
int     get_cpu_info(cpu_info_t *cpu_info) 
16
 
{
17
 
 
18
 
  FILE  *fff;
19
 
  char  temp_string[256];
20
 
  char  vendor_string[256], model_string[256], plain_model[256];
21
 
  char  family_string[256];
22
 
  int   rev_int = 0;
23
 
  int   cpu_count = 0;
24
 
  float megahertz = 0.0, bogomips = 0.0;
25
 
   
26
 
  vendor_string[0] = model_string[0] = plain_model[0] = family_string[0] = 0;
27
 
 
28
 
  /* We get all of our info here from /proc/cpuinfo */
29
 
  if ((fff = fopen(get_cpuinfo_file(), "r")) != NULL) 
30
 
    {
31
 
      while ((fgets(temp_string, 255, fff) != NULL)) 
32
 
        {
33
 
          if (cpu_count == 0) /* Assume all CPU's in SMP system are the same */
34
 
            {
35
 
              if (!(strncmp(temp_string, "vendor", 6)))
36
 
                strncpy(vendor_string, parse_line(temp_string), 255);
37
 
              if (!strncmp(temp_string, "family", strlen("family")))
38
 
                strncpy(family_string, parse_line(temp_string), 255);
39
 
              /*
40
 
              ** note for later check the model line
41
 
              ** now this line is useless
42
 
              */
43
 
              if (!(strncmp(temp_string, "model", strlen("model")))) 
44
 
                 strncpy(model_string, parse_line(temp_string), 255);          
45
 
              if (!(strncmp(temp_string, "revision", strlen("revision"))))
46
 
                rev_int = atoi(parse_line(temp_string));
47
 
              if (!(strncmp(temp_string, "cpu MHz", 6)))
48
 
                megahertz = atof(parse_line(temp_string));
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
 
              cpu_count++;  /* Cheating way to detect number of intel CPU's */
57
 
            }
58
 
        }
59
 
    }
60
 
       
61
 
  /* Re-arrange some of the strings for best results  */
62
 
  if (family_string[0] == 0) 
63
 
    strncpy(cpu_info->chip_type, "Unknown", 9);
64
 
  else 
65
 
    strncpy(cpu_info->chip_type, family_string, 63);
66
 
   
67
 
  strncpy(cpu_info->chip_vendor, "Unknown", 9);
68
 
  
69
 
  cpu_info->num_cpus = cpu_count;
70
 
  cpu_info->bogomips = bogomips;
71
 
   
72
 
  /*********************************************************/
73
 
  /* Vendor specific fixups                                */
74
 
  /*********************************************************/
75
 
   
76
 
       
77
 
  /* *************** */
78
 
  /* Intel Chips     */
79
 
  /* *************** */
80
 
  if (!strncmp(vendor_string,"GenuineIntel",12)) 
81
 
    {
82
 
      strncpy(cpu_info->chip_vendor,"Intel",6);
83
 
      if (rev_int >= 1 && rev_int <= 4)
84
 
        sprintf(cpu_info->chip_type, 
85
 
                "%s [B%i]", 
86
 
                clip_lf(family_string, 255), rev_int - 1);
87
 
      else if (rev_int == 5)
88
 
        sprintf(cpu_info->chip_type, 
89
 
                "%s [C0]", 
90
 
                clip_lf(family_string, 255));
91
 
      else
92
 
        sprintf(cpu_info->chip_type, 
93
 
                "%s", 
94
 
                clip_lf(family_string, 255));
95
 
    }
96
 
   
97
 
  cpu_info->megahertz = 0.0;
98
 
   
99
 
  /* Handle Pretty_printing */
100
 
  if (get_pretty_printing()) 
101
 
    {
102
 
      /* Fix MHz */
103
 
      if (megahertz > 0.0)
104
 
        cpu_info->megahertz = fix_megahertz(25, megahertz);
105
 
    }
106
 
  else 
107
 
    {
108
 
      /* restore RAW vendor string.  Do we want this? */
109
 
      strncpy(cpu_info->chip_type, model_string, 64);
110
 
      cpu_info->megahertz = megahertz;
111
 
    }
112
 
 
113
 
  return 0;   
114
 
}
115
 
 
116
 
    /* Not implemented on ix86 nor on ia64 */
117
 
int get_hardware_info(char hardware_string[256]) 
118
 
{
119
 
   
120
 
    return 0;
121
 
}
122
 
 
123
 
    /* Some architectures might have better ways of detecting RAM size */
124
 
long int get_arch_specific_mem_size(void) {
125
 
       /* We have no special way of detecting RAM */
126
 
       return -1;
127
 
}