Back to index

lshw  02.16
Functions | Variables
cpuinfo.cc File Reference
#include "version.h"
#include "cpuinfo.h"
#include "osutils.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

Go to the source code of this file.

Functions

 __ID ("@(#) $Id: cpuinfo.cc 2433 2012-01-10 22:01:30Z lyonel $")
static hwNodegetcpu (hwNode &node, int n=0)
bool scan_cpuinfo (hwNode &n)

Variables

static int currentcpu = 0

Function Documentation

__ID ( "@(#) $Id: cpuinfo.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
static hwNode* getcpu ( hwNode node,
int  n = 0 
) [static]

Definition at line 16 of file cpuinfo.cc.

{
  char cpubusinfo[10];
  hwNode *cpu = NULL;

  if (n < 0)
    n = 0;

  snprintf(cpubusinfo, sizeof(cpubusinfo), "cpu@%d", n);
  cpu = node.findChildByBusInfo(cpubusinfo);

  if (cpu)
  {
    cpu->addHint("icon", string("cpu"));
    cpu->claim(true);                             // claim the cpu and all its children
    cpu->enable();                                // enable it
    return cpu;
  }

  hwNode *core = node.getChild("core");

  if (core)
  {
    hwNode newcpu("cpu", hw::processor);

    newcpu.setBusInfo(cpubusinfo);
    newcpu.claim();
    return core->addChild(newcpu);
  }
  else
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool scan_cpuinfo ( hwNode n)

Definition at line 369 of file cpuinfo.cc.

{
  hwNode *core = n.getChild("core");
  int cpuinfo = open("/proc/cpuinfo", O_RDONLY);

  if (cpuinfo < 0)
    return false;

  if (!core)
  {
    n.addChild(hwNode("core", hw::bus));
    core = n.getChild("core");
  }

  if (core)
  {
    char buffer[1024];
    size_t count;
    string cpuinfo_str = "";

    while ((count = read(cpuinfo, buffer, sizeof(buffer))) > 0)
    {
      cpuinfo_str += string(buffer, count);
    }
    close(cpuinfo);

    vector < string > cpuinfo_lines;
    splitlines(cpuinfo_str, cpuinfo_lines);
    cpuinfo_str = "";                             // free memory
    currentcpu = -1;

    for (unsigned int i = 0; i < cpuinfo_lines.size(); i++)
    {
      string id = "";
      string value = "";
      size_t pos = 0;

      pos = cpuinfo_lines[i].find(':');

      if (pos != string::npos)
      {
        id = hw::strip(cpuinfo_lines[i].substr(0, pos));
        value = hw::strip(cpuinfo_lines[i].substr(pos + 1));

#if defined(__i386__) || defined(__x86_64__)
        cpuinfo_x86(n, id, value);
#endif
#ifdef __powerpc__
        cpuinfo_ppc(n, id, value);
#endif
#ifdef __hppa__
        cpuinfo_hppa(n, id, value);
#endif
#ifdef __alpha__
        cpuinfo_alpha(n, id, value);
#endif
#ifdef __ia64__
        cpuinfo_ia64(n, id, value);
#endif
      }
    }
  }
  else
  {
    close(cpuinfo);
    return false;
  }

  hwNode *cpu = getcpu(n, 0);
  if(cpu && (n.getWidth()==0))
    n.setWidth(cpu->getWidth());

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int currentcpu = 0 [static]

Definition at line 14 of file cpuinfo.cc.