Hi !

    I've created a patch for this bug, but I'm uncertain about how hw->hw_cpuinfo should be handled. I've utilized the CPU Family and Model Name. Hope this patch might provide some assistance in addressing this bug.

thanks,

JiaLing

>From 4765a45585bb247a591719ee732b755f98d2ba0c Mon Sep 17 00:00:00 2001
From: JiaLing Zhang <[email protected]>
Date: Tue, 19 Sep 2023 09:16:58 +0000
Subject: [PATCH] Add LoongArch support.

Signed-off-by: JiaLing Zhang <[email protected]>
---
 Makefile.am           |  2 +-
 linuxinfo.h           |  4 +++
 linuxinfo_loongarch.c | 68 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 linuxinfo_loongarch.c

diff --git a/Makefile.am b/Makefile.am
index 95070fa..9a43ff4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,7 @@ linuxinfo_SOURCES = linuxinfo.c linuxinfo.h \
 		    linuxinfo_m68k.c linuxinfo_ppc.c linuxinfo_sh.c \
 		    linuxinfo_hppa.c linuxinfo_s390.c linuxinfo_avr.c \
 		    linuxinfo_sparc.c linuxinfo_mips.c linuxinfo_riscv.c \
-		    linuxinfo_unknown.c
+		    linuxinfo_loongarch.c linuxinfo_unknown.c
 man_MANS          = po4a/linuxinfo.1
 EXTRA_DIST        = config.rpath CREDITS
 VERSION	          = 4.1.2
diff --git a/linuxinfo.h b/linuxinfo.h
index fc7b55f..5c317a0 100644
--- a/linuxinfo.h
+++ b/linuxinfo.h
@@ -108,6 +108,10 @@
 #define system_riscv
 #endif
 
+#if defined(__loongarch__)
+#define system_loongarch
+#endif
+
 #if (SIZEOF_LONG > 4)
 #define LONGLONG long int
 #define LONGSPEC "%ld"
diff --git a/linuxinfo_loongarch.c b/linuxinfo_loongarch.c
new file mode 100644
index 0000000..70fab3e
--- /dev/null
+++ b/linuxinfo_loongarch.c
@@ -0,0 +1,68 @@
+/*
+   linuxinfo_loongarch.c
+
+   Copyright (C) 2023 JiaLing Zhang <[email protected]>
+
+   This is the LoongArch port of linuxinfo
+   */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "linuxinfo.h"
+
+#ifdef system_loongarch
+
+void GetHardwareInfo(int fd, struct hw_stat *hw)
+{
+	int processors = 0;
+	float bogomips = 0.0;
+	float tempMHz = 0.0;
+	char temp_string[BUFSIZ], temp_string2[BUFSIZ];
+	char family[BUFSIZ]="Unknown";
+	char model[BUFSIZ]="Unknown";
+
+	while (read_line(fd, temp_string, BUFSIZ) != 0)
+	{
+		if(splitstring(temp_string, temp_string2)){
+
+			/* CPU count */
+			if ( !strncmp(temp_string, "processor", strlen("processor")))
+				processors++;
+
+			/* CPU Family */
+			if ( !strncmp(temp_string, "CPU Family", strlen("CPU Family")))
+				strcpy(family, temp_string2);
+
+			if ( !strncmp(temp_string, "Model Name", strlen("Model Name")))
+				strcpy(model, temp_string2);
+
+			if ( !strncmp(temp_string, "CPU MHz", strlen("CPU MHz"))) {
+				if (atol(temp_string2) > tempMHz){
+					tempMHz = atol(temp_string2);
+				}
+			}
+
+			if ( !(strncmp(temp_string,"BogoMIPS",8))) 
+				bogomips = bogomips + atof(temp_string2);
+		}
+	}
+
+	sprintf(hw->hw_memory, LONGSPEC, getphysicalmemory());
+	hw->hw_processors = processors;
+
+	sprintf(hw->hw_cpuinfo, "%s %s", family,model);
+
+	if (bogomips == 0.0)
+		sprintf(hw->hw_bogomips, "?");
+	else
+		sprintf(hw->hw_bogomips, "%0.2f", bogomips);
+
+	if (tempMHz == 0.0)
+		sprintf(hw->hw_megahertz, "?");
+	else
+		sprintf(hw->hw_megahertz, "%d", (int)tempMHz);
+
+}
+#endif /* system_loongarch */
-- 
2.40.1

Reply via email to