File: linuxinfo_loongarch.c

package info (click to toggle)
linuxinfo 4.2.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,344 kB
  • sloc: sh: 5,320; ansic: 1,383; makefile: 103; sed: 16
file content (68 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
   linuxinfo_loongarch.c

   Copyright (C) 2023 JiaLing Zhang <zhangjialing@loongson.cn>

   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 */