~ubuntu-branches/ubuntu/precise/yacpi/precise

« back to all changes in this revision

Viewing changes to get_cpu.c

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2007-10-28 02:21:27 UTC
  • mfrom: (2.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20071028022127-y0e218hukkc1qqrr
Tags: 3.0-2
* Added 02_fixacstate to add missing call to read_acpi_acstate
  which causes yacpi to not recognize a change of the ac
  state (Closes: #448305).
* Switched from Homepage tag to the new Homepage control field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <stdio.h>
20
 
#include <stdlib.h>
21
20
#include <string.h>
22
 
#include <ncurses.h>
23
 
#include "libacpi.h"
24
 
 
25
 
int get_cpu_cur()
26
 
{
27
 
    FILE *cpuinfo;
28
 
    int freq=0;
29
 
    if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq","r"))==NULL){
30
 
        return freq;
31
 
    }
32
 
    fscanf(cpuinfo,"%d",&freq);
33
 
    fclose(cpuinfo);
34
 
    return freq;
35
 
}
36
 
 
37
 
int get_cpu_max()
38
 
{
39
 
    FILE *cpuinfo;
40
 
    int freq=0;
41
 
    if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq","r"))==NULL){
42
 
        return freq;
43
 
    }
44
 
    fscanf(cpuinfo,"%d",&freq);
45
 
    fclose(cpuinfo);
46
 
    return freq;
47
 
}
48
 
 
49
 
char *get_cpu_gov()
50
 
{
51
 
    FILE *cpuinfo;
52
 
    char buffer[128];
53
 
    char *error="not supported";
54
 
    if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor","r"))==NULL){
55
 
        bzero(buffer,128);
56
 
        strncpy(buffer,error,128);
57
 
        return strdup(buffer); 
58
 
    }
59
 
    fgets(buffer,sizeof(buffer),cpuinfo);
60
 
    fclose(cpuinfo);
61
 
    endwin();
62
 
    return strdup(buffer);
 
21
 
 
22
int
 
23
get_cpu_cur() {
 
24
        FILE *cpuinfo;
 
25
        int freq = 0;
 
26
        if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq","r"))==NULL){
 
27
                return freq;
 
28
        }
 
29
        fscanf(cpuinfo,"%d",&freq);
 
30
        fclose(cpuinfo);
 
31
        return freq;
 
32
}
 
33
 
 
34
int
 
35
get_cpu_max() {
 
36
        FILE *cpuinfo;
 
37
        int freq = 0;
 
38
        if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq","r"))==NULL){
 
39
                return freq;
 
40
        }
 
41
        fscanf(cpuinfo,"%d",&freq);
 
42
        fclose(cpuinfo);
 
43
        return freq;
 
44
}
 
45
 
 
46
char *
 
47
get_cpu_gov() {
 
48
        FILE *cpuinfo;
 
49
        char buffer[128];
 
50
        if((cpuinfo=fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor","r"))==NULL){
 
51
                return strdup("not supported"); 
 
52
        }
 
53
        fgets(buffer,sizeof(buffer),cpuinfo);
 
54
        buffer[strlen(buffer) - 1]='\0';
 
55
        fclose(cpuinfo);
 
56
        return strdup(buffer);
63
57
}
64
58