diff --git a/libsysinfo-0.3.0/Linux/Makefile b/libsysinfo-0.3.0/Linux/Makefile index 3ab7156..4cb9667 100644 --- a/libsysinfo-0.3.0/Linux/Makefile +++ b/libsysinfo-0.3.0/Linux/Makefile @@ -32,6 +32,9 @@ ifneq (,$(findstring mips,$(ARCH))) ARCH := mips endif +ifneq (,$(findstring loongarch,$(ARCH))) + ARCH := loongarch +endif all: cpuinfo.o sysinfo_linux.o @@ -55,6 +58,9 @@ frv: cpuinfo_frv.c ia64: cpuinfo_ia64.c $(CROSS)$(CC) $(CFLAGS) -o cpuinfo.o -c cpuinfo_ia64.c +loongarch: cpuinfo_loongarch.c + $(CROSS)$(CC) $(CFLAGS) -o cpuinfo.o -c cpuinfo_loongarch.c + m32r: cpuinfo_m32r.c $(CROSS)$(CC) $(CFLAGS) -o cpuinfo.o -c cpuinfo_m32r.c diff --git a/libsysinfo-0.3.0/Linux/cpuinfo_loongarch.c b/libsysinfo-0.3.0/Linux/cpuinfo_loongarch.c new file mode 100644 index 0000000..6ad020e --- /dev/null +++ b/libsysinfo-0.3.0/Linux/cpuinfo_loongarch.c @@ -0,0 +1,69 @@ +/* Handles loongarch chips on Linux architecture */ +/* by JiaLing Zhang */ + +#include +#include +#include /* atof */ + +#include "../sysinfo.h" +#include "../include/generic.h" + +int get_cpu_info(struct cpu_info_type *cpu_info) { + + FILE *fff; + char temp_string[BUFSIZ]; + char vendor_string[BUFSIZ],model_string[BUFSIZ]; + int cpu_count=0; + float megahertz=0.0,bogomips=0.0; + + vendor_string[0]=model_string[0]=0; + + strncpy(vendor_string,"Loongson",9); + + /* We get all of our info here from /proc/cpuinfo */ + if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) { + + while ( (fgets(temp_string,BUFSIZ,fff)!=NULL) ) { + + if (cpu_count==0) { + + if ( !(strncmp(temp_string,"Model Name",10))) { + strncpy(model_string,parse_line(temp_string),BUFSIZ-1); + clip_lf(model_string,BUFSIZ); + } + + if ( !(strncmp(temp_string,"CPU MHz",7))) { + megahertz=atof(parse_line(temp_string)); + } + } + + /* Ugh why must people play with capitalization */ + if ( !(strncmp(temp_string,"bogomips",8)) || + !(strncmp(temp_string,"BogoMips",8)) || + !(strncmp(temp_string,"BogoMIPS",8))) { + bogomips+=atof(parse_line(temp_string)); + cpu_count++; /* Cheating way to detect number of CPUs */ + } + } + } + + strncpy_truncate(cpu_info->chip_vendor,vendor_string,SYSINFO_CHIP_VENDOR_SIZE); + strncpy_truncate(cpu_info->chip_type,model_string,SYSINFO_CHIP_TYPE_SIZE); + + cpu_info->num_cpus=cpu_count; + cpu_info->megahertz=megahertz; + cpu_info->bogomips=bogomips; + + return 0; +} + +int get_hardware(char *hardware_string) { + + return -1; +} + + /* Some architectures might have better ways of detecting RAM size */ +long long get_arch_specific_mem_size(void) { + /* We have no special way of detecting RAM */ + return 0; +}