From 5e31ce485184c202175ca95d03c17389694bd6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Fri, 21 Jun 2024 19:12:37 +0900 Subject: =?UTF-8?q?Linux:=20CPU=E6=83=85=E5=A0=B1=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cpu.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/cpu.c b/src/cpu.c index 780cba1..f479517 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -20,36 +20,17 @@ const char *display_cpu() { "sed 's/ CPU//' | sed 's/^ *//' && " "echo \" (\" && psrinfo -p && echo \" core)\""); #elif defined(__linux__) - char buf[20]; - long int val; - double fmt; - FILE *fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit", "r"); - if (fp == NULL) { - fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r"); - } - - if (fp == NULL) { - perror("失敗"); - return NULL; - } - - if (fgets(buf, sizeof(buf), fp) != NULL) { - val = strtol(buf, NULL, 10); - fmt = val / 1000000.0; - printf("%.2f", fmt); - } else { - perror("失敗"); - fclose(fp); - return NULL; - } - - fclose(fp); - return run_command_s("cat /proc/cpuinfo | awk -F '\\\\s*: | @' " "'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { " "cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | " "sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | " "sed 's/ [0-9]-Core//' && echo \" @ \" && " + "if [ \"$(LC_ALL=C cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit 2>&1)\"" + " != \"cat: /sys/devices/system/cpu/cpu0/cpufreq/bios_limit: " + "No such file or directory\" ]; then " + "cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit; else " + "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq | " + "awk '{printf \"%.2f\", $1/1000000}'; fi && " "echo \"GHz (\" && nproc && echo \" core)\""); #endif return NULL; -- cgit v1.2.3 From 2bf59440d96ea29f04b3964db7b78367620432c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Fri, 21 Jun 2024 19:15:29 +0900 Subject: =?UTF-8?q?=E3=81=93=E3=81=93=E3=82=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cpu.c b/src/cpu.c index f479517..b9bb7de 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -28,7 +28,8 @@ const char *display_cpu() { "if [ \"$(LC_ALL=C cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit 2>&1)\"" " != \"cat: /sys/devices/system/cpu/cpu0/cpufreq/bios_limit: " "No such file or directory\" ]; then " - "cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit; else " + "cat /sys/devices/system/cpu/cpu0/cpufreq/bios_limit | " + "awk '{printf \"%.2f\", $1/1000000}'; else " "cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq | " "awk '{printf \"%.2f\", $1/1000000}'; fi && " "echo \"GHz (\" && nproc && echo \" core)\""); -- cgit v1.2.3 From 5518c6e98d218d72889160458a3b577007f5e131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Fri, 21 Jun 2024 19:24:12 +0900 Subject: =?UTF-8?q?Linux:=20=E3=83=9B=E3=82=B9=E3=83=88=E5=90=8D=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/host.c b/src/host.c index 77020ae..716a823 100644 --- a/src/host.c +++ b/src/host.c @@ -106,12 +106,12 @@ void display_host_model() { cmd1 = "getprop ro.product.brand"; cmd2 = "getprop ro.product.model"; } else if ( - access("/sys/devices/virtual/dmi/id/product_name", F_OK) != -1 || + access("/sys/devices/virtual/dmi/id/product_name", F_OK) != -1 && access("/sys/devices/virtual/dmi/id/product_version", F_OK) != 1 ) { cmd1 = "cat /sys/devices/virtual/dmi/id/product_name"; cmd2 = "cat /sys/devices/virtual/dmi/id/product_version"; - } else if (access("/sys/firmware/base/model", F_OK) != -1) { + } else if (access("/sys/firmware/devicetree/base/model", F_OK) != -1) { cmd1 = "cat /sys/firmware/devicetree/base/model"; } else if (access("/tmp/sysinfo/model", F_OK) != 1) { cmd1 = "cat /tmp/sysinfo/model"; -- cgit v1.2.3