-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathras-poison-page-stat.c
More file actions
41 lines (32 loc) · 887 Bytes
/
ras-poison-page-stat.c
File metadata and controls
41 lines (32 loc) · 887 Bytes
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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2025 Alibaba Inc
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syslog.h>
#include "ras-logger.h"
#include "ras-poison-page-stat.h"
#include "types.h"
unsigned long long poison_stat_threshold;
int ras_poison_page_stat(void)
{
FILE *fp;
char line[MAX_PATH];
unsigned long long corrupted_kb = 0;
fp = fopen("/proc/meminfo", "r");
if (!fp) {
log(ALL, LOG_ERR, "Failed to open /proc/meminfo");
return EXIT_FAILURE;
}
while (fgets(line, sizeof(line), fp))
if (strstr(line, "HardwareCorrupted"))
if (sscanf(line, "%*s %llukB", &corrupted_kb) == 1)
break;
fclose(fp);
if (corrupted_kb > poison_stat_threshold)
log(ALL, LOG_WARNING, "Poison page statistics exceeded threshold: %lld kB (threshold: %lld kB)\n",
corrupted_kb, poison_stat_threshold);
return 0;
}