Back to index

lshw  02.16
Functions
mem.cc File Reference
#include "version.h"
#include "config.h"
#include "mem.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

Go to the source code of this file.

Functions

 __ID ("@(#) $Id: mem.cc 2433 2012-01-10 22:01:30Z lyonel $")
static unsigned long long get_kcore_size ()
static unsigned long long get_sysconf_size ()
static unsigned long long count_memorybanks_size (hwNode &n)
static void claim_memory (hwNode &n)
bool scan_memory (hwNode &n)

Function Documentation

__ID ( "@(#) $Id: mem.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
static void claim_memory ( hwNode n) [static]

Definition at line 77 of file mem.cc.

{
  hwNode *core = n.getChild("core");

  if (core)
  {
    for (unsigned int i = 0; i < core->countChildren(); i++)
      if (core->getChild(i)->getClass() == hw::memory)
        if(core->getChild(i)->claimed())
          core->getChild(i)->claim(true);         // claim memory and all its children
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned long long count_memorybanks_size ( hwNode n) [static]

Definition at line 55 of file mem.cc.

{
  hwNode *memory = n.getChild("core/memory");

  if (memory)
  {
    unsigned long long size = 0;

    memory->claim(true);                          // claim memory and all its children

    for (unsigned int i = 0; i < memory->countChildren(); i++)
      if (memory->getChild(i)->getClass() == hw::memory)
        size += memory->getChild(i)->getSize();

    memory->setSize(size);
    return size;
  }
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned long long get_kcore_size ( ) [static]

Definition at line 28 of file mem.cc.

{
  struct stat buf;

  if (stat("/proc/kcore", &buf) != 0)
    return 0;
  else
    return buf.st_size;
}

Here is the caller graph for this function:

static unsigned long long get_sysconf_size ( ) [static]

Definition at line 39 of file mem.cc.

{
  long pagesize = 0;
  long physpages = 0;
  unsigned long long logicalmem = 0;

  pagesize = sysconf(_SC_PAGESIZE);
  physpages = sysconf(_SC_PHYS_PAGES);
  if ((pagesize > 0) && (physpages > 0))
    logicalmem =
      (unsigned long long) pagesize *(unsigned long long) physpages;

  return logicalmem;
}

Here is the caller graph for this function:

bool scan_memory ( hwNode n)

Definition at line 91 of file mem.cc.

{
  hwNode *memory = n.getChild("core/memory");
  unsigned long long logicalmem = 0;
  unsigned long long kcore = 0;

  logicalmem = get_sysconf_size();
  kcore = get_kcore_size();
  count_memorybanks_size(n);
  claim_memory(n);

  if (!memory)
  {
    hwNode *core = n.getChild("core");

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

    if (core)
    {
      core->addChild(hwNode("memory", hw::memory));
      memory = core->getChild("memory");
    }
  }

  if (memory)
  {
    memory->claim();
    memory->addHint("icon", string("memory"));

    if (memory->getDescription() == "")
      memory->setDescription(_("System memory"));

    if (memory->getSize() > logicalmem)           // we already have a value
      return true;

    if ((logicalmem == 0)
      || ((kcore > logicalmem) && (kcore < 2 * logicalmem)))
      memory->setSize(kcore);
    else
      memory->setSize(logicalmem);

    return true;
  }

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function: