[BACK]Return to cpumon.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / sample / cpumon

Annotation of prex-old/usr/sample/cpumon/cpumon.c, Revision 1.1.1.1.2.1

1.1       nbrk        1: /*
                      2:  * Copyright (c) 2005, 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:  * cpumon.c - CPU voltage monitoring program
                     32:  */
                     33:
                     34: #include <prex/prex.h>
                     35: #include <sys/ioctl.h>
                     36: #include <stdio.h>
                     37:
                     38: static struct cpu_info cpu_info;
                     39: static struct cpu_stat cpu_stat;
                     40:
                     41: int
                     42: main(int argc, char *argv[])
                     43: {
                     44:        device_t cpu_dev;
                     45:        int last_mhz = 0;
                     46:        int i, j;
                     47:        static char bar[21];
                     48:
                     49:        /* Boost current prioriy */
                     50:        thread_setprio(thread_self(), 50);
                     51:
                     52:        if (device_open("cpu", 0, &cpu_dev))
                     53:                panic("open error: cpu");
                     54:
                     55:        /* Clear screen */
                     56:        printf("\33[2J");
                     57:
                     58:        printf("CPU voltage monitor\n");
1.1.1.1.2.1! nbrk       59:        device_ioctl(cpu_dev, CPUIOC_GET_INFO, &cpu_info);
1.1       nbrk       60:        if (cpu_info.clock_ctrl == 0)
                     61:                panic("DVS not supported by cpu");
                     62:        if (cpu_info.speed == 0 || cpu_info.power == 0)
                     63:                panic("Invalid cpu power/speed");
                     64:
                     65:        /*
                     66:         * Setup periodic timer for 10msec period
                     67:         */
                     68:        timer_periodic(thread_self(), 100, 10);
                     69:        for (;;) {
                     70:                /*
                     71:                 * Wait next period
                     72:                 */
                     73:                timer_waitperiod();
1.1.1.1.2.1! nbrk       74:                device_ioctl(cpu_dev, CPUIOC_GET_STAT, &cpu_stat);
1.1       nbrk       75:                if (cpu_stat.speed != last_mhz) {
                     76:                        printf("\33[s"); /* save cursor */
                     77:
                     78:                        /*
                     79:                         * Display speed
                     80:                         */
                     81:                        printf("\nSpeed: %4dMHz  0|", cpu_stat.speed);
                     82:                        j = cpu_stat.speed * 100 / cpu_info.speed;
                     83:                        for (i = 0; i < 20; i++)
                     84:                                bar[i] = (i <= j / 5) ? '*' : '-';
                     85:                        bar[i] = '\0';
                     86:                        printf(bar);
                     87:                        printf("|100");
                     88:
                     89:                        /*
                     90:                         * Display power
                     91:                         */
                     92:                        printf("\nPower: %4dmV   0|", cpu_stat.power);
                     93:                        j = cpu_stat.power * 100 / cpu_info.power;
                     94:                        for (i = 0; i < 20; i++)
                     95:                                bar[i] = (i <= j / 5) ? '*' : '-';
                     96:                        bar[i] = '\0';
                     97:                        printf(bar);
                     98:                        printf("|100");
                     99:
                    100:                        printf("\33[u"); /* restore cursor */
                    101:                        last_mhz = cpu_stat.speed;
                    102:                }
                    103:        }
                    104:        return 0;
                    105: }

CVSweb