1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  */
9 
10 #include "proc.h"
11 #include "procfs.h"
12 
13 #include <rthw.h>
14 #include <rtdbg.h>
15 
16 #include <fcntl.h>
17 #include <errno.h>
18 
19 #include <dfs_dentry.h>
20 #include <mm_page.h>
21 
22 
23 extern void rt_memory_info(rt_size_t *total,
24                             rt_size_t *used,
25                             rt_size_t *max_used);
26 
single_show(struct dfs_seq_file * seq,void * data)27 static int single_show(struct dfs_seq_file *seq, void *data)
28 {
29     rt_size_t total, used, max_used, freed;
30     rt_size_t total_sum = 0;
31     rt_size_t total_freed = 0;
32 
33     rt_memory_info(&total, &used, &max_used);
34     total_sum = total_sum + total;
35     total_freed = total_freed + total - used;
36 
37     dfs_seq_printf(seq, "%-16s%8d KB\n", "MemMaxUsed:", max_used / 1024);
38     dfs_seq_printf(seq, "%-16s%8d KB\n", "MemAvailable:", (total - used) / 1024);
39     dfs_seq_printf(seq, "%-16s%8d KB\n", "Cached:", 0);
40     dfs_seq_printf(seq, "%-16s%8d KB\n", "SReclaimable:", 0);
41 
42     rt_page_get_info(&total, &freed);
43     total_sum = total_sum + total * RT_MM_PAGE_SIZE;
44     total_freed = total_freed + freed * RT_MM_PAGE_SIZE;
45 
46     dfs_seq_printf(seq, "%-16s%8d KB\n", "MemTotal:", total_sum / 1024);
47     dfs_seq_printf(seq, "%-16s%8d KB\n", "MemFree:", total_freed / 1024);
48     dfs_seq_printf(seq, "%-16s%8d KB\n", "LowPageTotal:", total * RT_MM_PAGE_SIZE / 1024);
49     dfs_seq_printf(seq, "%-16s%8d KB\n", "lowPageFree:", freed * RT_MM_PAGE_SIZE/ 1024);
50 
51     rt_page_high_get_info(&total, &freed);
52 
53     dfs_seq_printf(seq, "%-16s%8d KB\n", "HighPageTotal:", total * RT_MM_PAGE_SIZE / 1024);
54     dfs_seq_printf(seq, "%-16s%8d KB\n", "HighPageFree:", freed * RT_MM_PAGE_SIZE / 1024);
55 
56     return 0;
57 }
58 
proc_meminfo_init(void)59 int proc_meminfo_init(void)
60 {
61     struct proc_dentry *dentry = proc_create_single_data("meminfo", 0, NULL, single_show, NULL);
62     proc_release(dentry);
63 
64     return 0;
65 }
66 INIT_ENV_EXPORT(proc_meminfo_init);
67