summaryrefslogtreecommitdiff
path: root/examples/kernel/cpuusage.c
diff options
context:
space:
mode:
authorliukangcc <[email protected]>2021-12-15 10:09:31 +0800
committerBernard Xiong <[email protected]>2021-12-17 10:24:48 +0800
commit0c4e7337373821161e171057b081767a60c2f892 (patch)
tree1329255115c1e099c52cadf244011261655e2910 /examples/kernel/cpuusage.c
parent7af733fa3fbfbf161ef2f265d851e5296cc216ac (diff)
[update] remove RT_USING_TC
Diffstat (limited to 'examples/kernel/cpuusage.c')
-rw-r--r--examples/kernel/cpuusage.c78
1 files changed, 0 insertions, 78 deletions
diff --git a/examples/kernel/cpuusage.c b/examples/kernel/cpuusage.c
deleted file mode 100644
index 5f9d480139..0000000000
--- a/examples/kernel/cpuusage.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- *
- */
-#include <rtthread.h>
-#include <rthw.h>
-
-#define CPU_USAGE_CALC_TICK 10
-#define CPU_USAGE_LOOP 100
-
-static rt_uint8_t cpu_usage_major = 0, cpu_usage_minor= 0;
-static rt_uint32_t total_count = 0;
-
-static void cpu_usage_idle_hook()
-{
- rt_tick_t tick;
- rt_uint32_t count;
- volatile rt_uint32_t loop;
-
- if (total_count == 0)
- {
- /* get total count */
- rt_enter_critical();
- tick = rt_tick_get();
- while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
- {
- total_count ++;
- loop = 0;
- while (loop < CPU_USAGE_LOOP) loop ++;
- }
- rt_exit_critical();
- }
-
- count = 0;
- /* get CPU usage */
- tick = rt_tick_get();
- while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
- {
- count ++;
- loop = 0;
- while (loop < CPU_USAGE_LOOP) loop ++;
- }
-
- /* calculate major and minor */
- if (count < total_count)
- {
- count = total_count - count;
- cpu_usage_major = (count * 100) / total_count;
- cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
- }
- else
- {
- total_count = count;
-
- /* no CPU usage */
- cpu_usage_major = 0;
- cpu_usage_minor = 0;
- }
-}
-
-void cpu_usage_get(rt_uint8_t *major, rt_uint8_t *minor)
-{
- RT_ASSERT(major != RT_NULL);
- RT_ASSERT(minor != RT_NULL);
-
- *major = cpu_usage_major;
- *minor = cpu_usage_minor;
-}
-
-void cpu_usage_init()
-{
- /* set idle thread hook */
- rt_thread_idle_sethook(cpu_usage_idle_hook);
-}