|
|
99c779 |
From 702382ac8b5385ce15f807016582b54793141c4b Mon Sep 17 00:00:00 2001
|
|
|
99c779 |
From: Dan Callaghan <dcallagh@redhat.com>
|
|
|
99c779 |
Date: Mon, 13 Jul 2015 15:06:59 +1000
|
|
|
99c779 |
Subject: [PATCH 18/26] guess memory size from memory hotplug info (#694)
|
|
|
99c779 |
|
|
|
99c779 |
---
|
|
|
99c779 |
src/core/Makefile | 2 +-
|
|
|
99c779 |
src/core/mem.cc | 35 +++++++++++++++++++++++++++++++++--
|
|
|
99c779 |
src/core/sysfs.cc | 16 ++++++++++++++++
|
|
|
99c779 |
src/core/sysfs.h | 2 ++
|
|
|
99c779 |
4 files changed, 52 insertions(+), 3 deletions(-)
|
|
|
99c779 |
|
|
|
99c779 |
diff --git a/src/core/Makefile b/src/core/Makefile
|
|
|
99c779 |
index 2d95a80..884a963 100644
|
|
|
99c779 |
--- a/src/core/Makefile
|
|
|
99c779 |
+++ b/src/core/Makefile
|
|
|
99c779 |
@@ -39,7 +39,7 @@ main.o: device-tree.h pci.h pcmcia.h pcmcia-legacy.h ide.h scsi.h spd.h
|
|
|
99c779 |
main.o: network.h isapnp.h fb.h usb.h sysfs.h display.h parisc.h cpufreq.h
|
|
|
99c779 |
main.o: ideraid.h mounts.h smp.h abi.h s390.h virtio.h pnp.h vio.h
|
|
|
99c779 |
print.o: print.h hw.h options.h version.h osutils.h config.h
|
|
|
99c779 |
-mem.o: version.h config.h mem.h hw.h
|
|
|
99c779 |
+mem.o: version.h config.h mem.h hw.h sysfs.h
|
|
|
99c779 |
dmi.o: version.h config.h dmi.h hw.h osutils.h
|
|
|
99c779 |
device-tree.o: version.h device-tree.h hw.h osutils.h
|
|
|
99c779 |
cpuinfo.o: version.h cpuinfo.h hw.h osutils.h
|
|
|
99c779 |
diff --git a/src/core/mem.cc b/src/core/mem.cc
|
|
|
99c779 |
index 686cc16..72bfb35 100644
|
|
|
99c779 |
--- a/src/core/mem.cc
|
|
|
99c779 |
+++ b/src/core/mem.cc
|
|
|
99c779 |
@@ -5,9 +5,10 @@
|
|
|
99c779 |
* sources:
|
|
|
99c779 |
* - the size of /proc/kcore
|
|
|
99c779 |
* - the value returned by the sysconf libc function
|
|
|
99c779 |
+ * - the sum of sizes of kernel hotplug memory blocks
|
|
|
99c779 |
* - the sum of sizes of individual memory banks
|
|
|
99c779 |
*
|
|
|
99c779 |
- * NOTE: Except in last case, this guess can be widely inaccurate, as the
|
|
|
99c779 |
+ * NOTE: In the first two cases this guess can be widely inaccurate, as the
|
|
|
99c779 |
* kernel itself limits the memory addressable by userspace processes.
|
|
|
99c779 |
* Because of that, this module reports the biggest value found if it can't
|
|
|
99c779 |
* access the size of individual memory banks (information filled in by other
|
|
|
99c779 |
@@ -17,6 +18,7 @@
|
|
|
99c779 |
|
|
|
99c779 |
#include "version.h"
|
|
|
99c779 |
#include "config.h"
|
|
|
99c779 |
+#include "sysfs.h"
|
|
|
99c779 |
#include "mem.h"
|
|
|
99c779 |
#include <sys/types.h>
|
|
|
99c779 |
#include <sys/stat.h>
|
|
|
99c779 |
@@ -52,6 +54,31 @@ static unsigned long long get_sysconf_size()
|
|
|
99c779 |
}
|
|
|
99c779 |
|
|
|
99c779 |
|
|
|
99c779 |
+static unsigned long long get_hotplug_size()
|
|
|
99c779 |
+{
|
|
|
99c779 |
+ vector < sysfs::entry > entries = sysfs::entries_by_bus("memory");
|
|
|
99c779 |
+
|
|
|
99c779 |
+ if (entries.empty())
|
|
|
99c779 |
+ return 0;
|
|
|
99c779 |
+
|
|
|
99c779 |
+ unsigned long long memblocksize =
|
|
|
99c779 |
+ sysfs::entry::byPath("/system/memory").hex_attr("block_size_bytes");
|
|
|
99c779 |
+ if (memblocksize == 0)
|
|
|
99c779 |
+ return 0;
|
|
|
99c779 |
+
|
|
|
99c779 |
+ unsigned long long totalsize = 0;
|
|
|
99c779 |
+ for (vector < sysfs::entry >::iterator it = entries.begin();
|
|
|
99c779 |
+ it != entries.end(); ++it)
|
|
|
99c779 |
+ {
|
|
|
99c779 |
+ const sysfs::entry & e = *it;
|
|
|
99c779 |
+ if (e.string_attr("online") != "1")
|
|
|
99c779 |
+ continue;
|
|
|
99c779 |
+ totalsize += memblocksize;
|
|
|
99c779 |
+ }
|
|
|
99c779 |
+ return totalsize;
|
|
|
99c779 |
+}
|
|
|
99c779 |
+
|
|
|
99c779 |
+
|
|
|
99c779 |
static unsigned long long count_memorybanks_size(hwNode & n)
|
|
|
99c779 |
{
|
|
|
99c779 |
hwNode *memory = n.getChild("core/memory");
|
|
|
99c779 |
@@ -93,9 +120,11 @@ bool scan_memory(hwNode & n)
|
|
|
99c779 |
hwNode *memory = n.getChild("core/memory");
|
|
|
99c779 |
unsigned long long logicalmem = 0;
|
|
|
99c779 |
unsigned long long kcore = 0;
|
|
|
99c779 |
+ unsigned long long hotplug_size = 0;
|
|
|
99c779 |
|
|
|
99c779 |
logicalmem = get_sysconf_size();
|
|
|
99c779 |
kcore = get_kcore_size();
|
|
|
99c779 |
+ hotplug_size = get_hotplug_size();
|
|
|
99c779 |
count_memorybanks_size(n);
|
|
|
99c779 |
claim_memory(n);
|
|
|
99c779 |
|
|
|
99c779 |
@@ -127,7 +156,9 @@ bool scan_memory(hwNode & n)
|
|
|
99c779 |
if (memory->getSize() > logicalmem) // we already have a value
|
|
|
99c779 |
return true;
|
|
|
99c779 |
|
|
|
99c779 |
- if ((logicalmem == 0)
|
|
|
99c779 |
+ if (hotplug_size > logicalmem)
|
|
|
99c779 |
+ memory->setSize(hotplug_size);
|
|
|
99c779 |
+ else if ((logicalmem == 0)
|
|
|
99c779 |
|| ((kcore > logicalmem) && (kcore < 2 * logicalmem)))
|
|
|
99c779 |
memory->setSize(kcore);
|
|
|
99c779 |
else
|
|
|
99c779 |
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
|
|
|
99c779 |
index fb7f2bb..d17d33d 100644
|
|
|
99c779 |
--- a/src/core/sysfs.cc
|
|
|
99c779 |
+++ b/src/core/sysfs.cc
|
|
|
99c779 |
@@ -239,6 +239,13 @@ entry entry::byClass(string devclass, string devname)
|
|
|
99c779 |
}
|
|
|
99c779 |
|
|
|
99c779 |
|
|
|
99c779 |
+entry entry::byPath(string path)
|
|
|
99c779 |
+{
|
|
|
99c779 |
+ entry e(fs.path + "/devices" + path);
|
|
|
99c779 |
+ return e;
|
|
|
99c779 |
+}
|
|
|
99c779 |
+
|
|
|
99c779 |
+
|
|
|
99c779 |
entry::entry(const string & devpath)
|
|
|
99c779 |
{
|
|
|
99c779 |
This = new entry_i;
|
|
|
99c779 |
@@ -318,6 +325,15 @@ string entry::string_attr(const string & name, const string & def) const
|
|
|
99c779 |
}
|
|
|
99c779 |
|
|
|
99c779 |
|
|
|
99c779 |
+unsigned long long entry::hex_attr(const string & name, unsigned long long def) const
|
|
|
99c779 |
+{
|
|
|
99c779 |
+ string val = string_attr(name, "");
|
|
|
99c779 |
+ if (val.empty())
|
|
|
99c779 |
+ return def;
|
|
|
99c779 |
+ return strtoull(val.c_str(), NULL, 16);
|
|
|
99c779 |
+}
|
|
|
99c779 |
+
|
|
|
99c779 |
+
|
|
|
99c779 |
vector < string > entry::multiline_attr(const string & name) const
|
|
|
99c779 |
{
|
|
|
99c779 |
vector < string > lines;
|
|
|
99c779 |
diff --git a/src/core/sysfs.h b/src/core/sysfs.h
|
|
|
99c779 |
index 7ceb395..a6d69ed 100644
|
|
|
99c779 |
--- a/src/core/sysfs.h
|
|
|
99c779 |
+++ b/src/core/sysfs.h
|
|
|
99c779 |
@@ -15,6 +15,7 @@ namespace sysfs
|
|
|
99c779 |
|
|
|
99c779 |
static entry byBus(string devbus, string devname);
|
|
|
99c779 |
static entry byClass(string devclass, string devname);
|
|
|
99c779 |
+ static entry byPath(string path);
|
|
|
99c779 |
|
|
|
99c779 |
entry & operator =(const entry &);
|
|
|
99c779 |
entry(const entry &);
|
|
|
99c779 |
@@ -28,6 +29,7 @@ namespace sysfs
|
|
|
99c779 |
entry parent() const;
|
|
|
99c779 |
string name_in_class(const string &) const;
|
|
|
99c779 |
string string_attr(const string & name, const string & def = "") const;
|
|
|
99c779 |
+ unsigned long long hex_attr(const string & name, unsigned long long def = 0) const;
|
|
|
99c779 |
vector < string > multiline_attr(const string & name) const;
|
|
|
99c779 |
|
|
|
99c779 |
struct entry_i * This;
|
|
|
99c779 |
--
|
|
|
99c779 |
2.10.2
|
|
|
99c779 |
|