summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-05-28 21:23:34 +0100
committerAndreas Kling <kling@serenityos.org>2022-05-29 15:23:57 +0200
commitbf5caf254fa1047dc42b3758b6717167ef2db166 (patch)
tree1c1e1a1c47d6529550c1c3c745145305c7534e34 /Userland
parent20e2e39fcc044a633d321ff5afaa4208d0d26f0e (diff)
downloadserenity-bf5caf254fa1047dc42b3758b6717167ef2db166.zip
lscpu: Show size of L1 data/instruction, L2, and L3 CPU caches
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/lscpu.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/Userland/Utilities/lscpu.cpp b/Userland/Utilities/lscpu.cpp
index 1e98f8f4f2..26b39ecee4 100644
--- a/Userland/Utilities/lscpu.cpp
+++ b/Userland/Utilities/lscpu.cpp
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 2022, Undefine <undefine@undefine.pl>.
+ * Copyright (c) 2022, Undefine <undefine@undefine.pl>
+ * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -7,10 +8,18 @@
#include <AK/Format.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
+#include <AK/NumberFormat.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
+static void print_cache_info(StringView description, JsonObject const& cache_object)
+{
+ outln("\t{}:", description);
+ outln("\t\tSize: {}", human_readable_size(cache_object.get("size").as_u32()));
+ outln("\t\tLine size: {}", human_readable_size(cache_object.get("line_size").as_u32()));
+};
+
static void print_cpu_info(JsonObject const& value)
{
outln("CPU {}:", value.get("processor").as_u32());
@@ -22,6 +31,17 @@ static void print_cpu_info(JsonObject const& value)
outln("\tModel: {}", value.get("model").as_u32());
outln("\tStepping: {}", value.get("stepping").as_u32());
outln("\tType: {}", value.get("type").as_u32());
+
+ auto& caches = value.get("caches").as_object();
+ if (caches.has("l1_data"))
+ print_cache_info("L1 data cache", caches.get("l1_data").as_object());
+ if (caches.has("l1_instruction"))
+ print_cache_info("L1 instruction cache", caches.get("l1_instruction").as_object());
+ if (caches.has("l2"))
+ print_cache_info("L2 cache", caches.get("l2").as_object());
+ if (caches.has("l3"))
+ print_cache_info("L3 cache", caches.get("l3").as_object());
+
out("\tFeatures: ");
auto& features = value.get("features").as_array();