[gnome-control-center/wip/hadess/fix-ram-size: 17/17] info: Use udev to get the hardware RAM size
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/hadess/fix-ram-size: 17/17] info: Use udev to get the hardware RAM size
- Date: Thu, 27 Jan 2022 09:09:18 +0000 (UTC)
commit 25518a6bca6d84199cfadf4ab0dc49fd86ac3e58
Author: Bastien Nocera <hadess hadess net>
Date: Tue Jan 25 23:12:58 2022 +0100
info: Use udev to get the hardware RAM size
libgtop gets the RAM size as is visible to the OS, so the physical RAM
size minus all the reserved areas listed at the top of your usual Linux
dmesg output.
Use systemd 248's MEMORY_ARRAY_* properties attached to the pseudo-DMI
device to get the size of the RAM sticks/chips as the user expects.
Closes: #1540
panels/info-overview/cc-info-overview-panel.c | 31 +++++++++++++++++++++++++--
panels/info-overview/meson.build | 3 ++-
2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/panels/info-overview/cc-info-overview-panel.c b/panels/info-overview/cc-info-overview-panel.c
index 88aea9900..257436395 100644
--- a/panels/info-overview/cc-info-overview-panel.c
+++ b/panels/info-overview/cc-info-overview-panel.c
@@ -38,6 +38,7 @@
#include <glibtop/mem.h>
#include <glibtop/sysinfo.h>
#include <udisks/udisks.h>
+#include <gudev/gudev.h>
#include <gdk/gdk.h>
@@ -724,7 +725,7 @@ get_windowing_system (void)
}
static guint64
-get_ram_size (void)
+get_ram_size_libgtop (void)
{
glibtop_mem mem;
@@ -732,6 +733,30 @@ get_ram_size (void)
return mem.total;
}
+static guint64
+get_ram_size_dmi (void)
+{
+ g_autoptr(GUdevClient) client = NULL;
+ g_autoptr(GUdevDevice) dmi = NULL;
+ const gchar * const subsystems[] = {"dmi", NULL };
+ guint64 ram_total = 0;
+ guint64 num_ram;
+ guint i;
+
+ client = g_udev_client_new (subsystems);
+ dmi = g_udev_client_query_by_sysfs_path (client, "/sys/devices/virtual/dmi/id");
+ if (!dmi)
+ return 0;
+ num_ram = g_udev_device_get_property_as_uint64 (dmi, "MEMORY_ARRAY_NUM_DEVICES");
+ for (i = 0; i < num_ram ; i++) {
+ g_autofree char *prop = NULL;
+
+ prop = g_strdup_printf ("MEMORY_DEVICE_%d_SIZE", i);
+ ram_total += g_udev_device_get_property_as_uint64 (dmi, prop);
+ }
+ return ram_total;
+}
+
static void
info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
{
@@ -751,7 +776,9 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
get_hardware_model (self);
- ram_size = get_ram_size ();
+ ram_size = get_ram_size_dmi ();
+ if (ram_size == 0)
+ ram_size = get_ram_size_libgtop ();
memory_text = g_format_size_full (ram_size, G_FORMAT_SIZE_IEC_UNITS);
cc_list_row_set_secondary_label (self->memory_row, memory_text);
diff --git a/panels/info-overview/meson.build b/panels/info-overview/meson.build
index 1cc062eee..1a7b2cded 100644
--- a/panels/info-overview/meson.build
+++ b/panels/info-overview/meson.build
@@ -40,7 +40,8 @@ sources += gnome.compile_resources(
deps = common_deps + [
dependency('udisks2', version: '>= 2.8.2'),
- dependency('libgtop-2.0')
+ dependency('libgtop-2.0'),
+ gudev_dep,
]
info_panel_lib = static_library(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]