1 /*
2 * Copyright (c) 2011, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 #include <xdc/std.h>
34 #include <xdc/cfg/global.h>
35 #include <xdc/runtime/System.h>
37 #include <ti/sysbios/BIOS.h>
38 #include <ti/sysbios/knl/Task.h>
39 #include <ti/sysbios/utils/Load.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stdlib.h>
45 /*
46 * Time to sleep between load reporting attempts, in ticks.
47 * On TI platforms, 1 tick == 1 ms.
48 */
49 #define SLEEP_TICKS 1000
51 /*
52 * Load reporting "threshold". When the new load is within previous reported
53 * load +- this value, we do not report it.
54 */
55 #define THRESHOLD 1
57 /* Monitor load and trace any change. */
58 static Void loadTaskFxn(UArg arg0, UArg arg1)
59 {
60 UInt32 prev_load = 0;
62 /* Suppress warnings. */
63 (void)arg0;
64 (void)arg1;
66 System_printf(
67 "loadTask: started\n"
68 " SLEEP_TICKS: %u\n"
69 " Load_hwiEnabled: %d\n"
70 " Load_swiEnabled: %d\n"
71 " Load_taskEnabled: %d\n"
72 " Load_updateInIdle: %d\n"
73 " Load_windowInMs: %u\n"
74 ,
75 SLEEP_TICKS,
76 Load_hwiEnabled,
77 Load_swiEnabled,
78 Load_taskEnabled,
79 Load_updateInIdle,
80 Load_windowInMs
81 );
83 /* Infinite loop to trace load. */
84 for (;;) {
85 UInt32 load;
86 unsigned delta;
88 /* Get load. */
89 load = Load_getCPULoad();
91 /* Trace if changed and delta above threshold. */
92 delta = abs((int)load - (int)prev_load);
94 if (delta > THRESHOLD) {
95 System_printf("loadTask: cpu load = %u%%\n", load);
96 prev_load = load;
97 }
99 /* Delay. */
100 Task_sleep(SLEEP_TICKS);
101 }
102 }
104 void start_load_task(void)
105 {
106 Task_Params params;
108 /* Monitor load and trace any change. */
109 Task_Params_init(¶ms);
110 params.instance->name = "loadtsk";
111 params.priority = 1;
113 if(!Task_create(loadTaskFxn, ¶ms, NULL))
114 System_printf("Could not create load task!\n");
115 }