scoutos / prex-0.9.0 / usr / test / cpufreq / cpufreq.c @ 03e9c04a
History | View | Annotate | Download (2.99 KB)
1 |
/*-
|
---|---|
2 |
* Copyright (c) 2005-2007, Kohsuke Ohtani
|
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 |
* 1. Redistributions of source code must retain the above copyright
|
9 |
* notice, this list of conditions and the following disclaimer.
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
12 |
* documentation and/or other materials provided with the distribution.
|
13 |
* 3. Neither the name of the author nor the names of any co-contributors
|
14 |
* may be used to endorse or promote products derived from this software
|
15 |
* without specific prior written permission.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
18 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
21 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
23 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
24 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
26 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
27 |
* SUCH DAMAGE.
|
28 |
*/
|
29 |
|
30 |
/*
|
31 |
* cpufreq.c - test cpu frequency controll
|
32 |
*/
|
33 |
|
34 |
/*
|
35 |
* This program changes the CPU load periodically. Since the cpufreq driver
|
36 |
* is polling the CPU load, the driver will change the CPU voltage/freqency
|
37 |
* automatically when CPU becomes idle state.
|
38 |
*
|
39 |
* It is recommended to run CPU voltage monitor 'cpumon' with this program.
|
40 |
*/
|
41 |
|
42 |
#include <sys/prex.h> |
43 |
#include <stdio.h> |
44 |
|
45 |
static void |
46 |
set_0_or_100(void)
|
47 |
{ |
48 |
u_long t1, t2; |
49 |
char index[] = "-\\|/"; |
50 |
char bar[] = "*\033[1D"; |
51 |
int i, cnt;
|
52 |
|
53 |
i = 0;
|
54 |
for (cnt = 0; cnt < 2; cnt++) { |
55 |
/*
|
56 |
* Display indicator for 5 sec.
|
57 |
*/
|
58 |
printf("\rCPU Busy:");
|
59 |
sys_time(&t1); |
60 |
for (;;) {
|
61 |
sys_time(&t2); |
62 |
if (t2 > t1 + 5000) |
63 |
break;
|
64 |
/*
|
65 |
* Update indicator per 100 msec.
|
66 |
*/
|
67 |
if ((t2 % 100) == 0) { |
68 |
bar[0] = index[i++ % 4]; |
69 |
printf("%s", bar);
|
70 |
} |
71 |
} |
72 |
/*
|
73 |
* Sleep 5 sec.
|
74 |
*/
|
75 |
printf("\rCPU Idle ");
|
76 |
timer_sleep(5000, 0); |
77 |
} |
78 |
} |
79 |
|
80 |
static void |
81 |
set_50(void)
|
82 |
{ |
83 |
u_long t1, t2; |
84 |
char index[] = "-\\|/"; |
85 |
char bar[] = "*\033[1D"; |
86 |
int i, cnt;
|
87 |
|
88 |
printf("\rCPU half speed:");
|
89 |
i = 0;
|
90 |
for (cnt = 0; cnt < 5000; cnt++) { |
91 |
/*
|
92 |
* Update indicator per 100 msec.
|
93 |
*/
|
94 |
if ((t2 % 100) == 0) { |
95 |
bar[0] = index[i++ % 4]; |
96 |
printf("%s", bar);
|
97 |
} |
98 |
sys_time(&t1); |
99 |
for (;;) {
|
100 |
sys_time(&t2); |
101 |
if (t2 > t1 + 1) |
102 |
break;
|
103 |
} |
104 |
/*
|
105 |
* Sleep 1msec.
|
106 |
*/
|
107 |
timer_sleep(1, 0); |
108 |
} |
109 |
} |
110 |
|
111 |
int
|
112 |
main(int argc, char *argv[]) |
113 |
{ |
114 |
thread_yield(); |
115 |
|
116 |
printf("cpufreq test program\n");
|
117 |
|
118 |
for (;;) {
|
119 |
set_0_or_100(); |
120 |
set_50(); |
121 |
} |
122 |
return 0; |
123 |
} |