Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libsysinfo-0.3.0/Linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ifneq (,$(findstring mips,$(ARCH)))
ARCH := mips
endif

ifneq (,$(findstring loongarch,$(ARCH)))
ARCH := loongarch
endif

all: cpuinfo.o sysinfo_linux.o

Expand All @@ -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

Expand Down
69 changes: 69 additions & 0 deletions libsysinfo-0.3.0/Linux/cpuinfo_loongarch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Handles loongarch chips on Linux architecture */
/* by JiaLing Zhang <zhangjialing@loongson.cn> */

#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* 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;
}