blob: 5da9e9952d366486e97ea668a81b04d969f7dc25 (
plain)
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
|
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include "proc.h"
#include "procfs.h"
#include <rthw.h>
#include <rtdbg.h>
#include <fcntl.h>
#include <errno.h>
#include <dfs_dentry.h>
static int single_show(struct dfs_seq_file *seq, void *data)
{
rt_tick_t ticks = rt_tick_get();
rt_uint64_t uptime_ms;
rt_uint64_t idle_ticks = 0;
#ifdef RT_USING_SMP
int index;
#endif
uptime_ms = ((rt_uint64_t)ticks * 1000U) / RT_TICK_PER_SECOND;
#ifdef RT_USING_SMP
for (index = 0; index < RT_CPUS_NR; index++)
{
idle_ticks += rt_cpu_index(index)->cpu_stat.idle;
}
#else
idle_ticks = rt_cpu_index(0)->cpu_stat.idle;
#endif
dfs_seq_printf(seq, "%llu.%02llu %llu.%02llu\n",
uptime_ms / 1000U, (uptime_ms % 1000U) / 10U,
((rt_uint64_t)idle_ticks * 1000U) / RT_TICK_PER_SECOND / 1000U,
(((rt_uint64_t)idle_ticks * 1000U) / RT_TICK_PER_SECOND % 1000U) / 10U);
return 0;
}
int proc_uptime_init(void)
{
struct proc_dentry *dentry = proc_create_single_data("uptime", 0, NULL, single_show, NULL);
proc_release(dentry);
return 0;
}
INIT_ENV_EXPORT(proc_uptime_init);
|