File: cpufreqd.h

package info (click to toggle)
cpufreqd 1.2.3-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,648 kB
  • ctags: 210
  • sloc: sh: 8,665; ansic: 1,648; makefile: 120
file content (170 lines) | stat: -rw-r--r-- 4,799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 *  Copyright (C) 2002-2005  Mattia Dongili<dongili@supereva.it>
 *                           George Staikos <staikos@0wned.org>
 *   
 *  Copyright (C) 2003-2005 Rene Rebe <rene@rocklinux.org>
 *
 *  2003.16.08
 *  - added support for cpu monitoring, base code by Dietz Proepper and minor
 *    fixes by Mattia Dongili
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __CPUFREQD_H
#define __CPUFREQD_H

#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <time.h>
#include <string.h>
#include <syslog.h>
#include <signal.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <libgen.h>

#include "string_list.h"

#define _CPUFREQD_VERSION_ 	"1.2.3"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifndef CPUFREQD_CONFDIR
#define CPUFREQD_CONFDIR  "/etc/"
#endif

#ifndef CPUFREQD_LIBDIR
#define CPUFREQD_LIBDIR   ""
#endif

#ifndef CPUFREQD_STATEDIR
#define CPUFREQD_STATEDIR   "/var/"
#endif

#define CPUFREQD_CONFIG   CPUFREQD_CONFDIR"cpufreqd.conf"
#define CPUFREQD_PIDFILE  CPUFREQD_STATEDIR"run/cpufreqd.pid"
#define APM_PROC_FILE     "/proc/apm"
#define ACPI_PROC_DIR     "/proc/acpi/"
#define ACPI_BATTERY_DIR  "/proc/acpi/battery/"
#define ACPI_AC_DIR       "/proc/acpi/ac_adapter/"
#define PMU_PROC_DIR      "/proc/pmu"
#define CPUINFO_PROC      "/proc/cpuinfo"

#define CPUFREQ_SYSFS_INTERFACE 	      "/sys/devices/system/cpu/cpu0/cpufreq"
#define CPUFREQ_SYSFS_INTERFACE_POLICY  "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_governor"
#define CPUFREQ_SYSFS_INTERFACE_MAX     "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_max_freq"
#define CPUFREQ_SYSFS_INTERFACE_MIN     "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_min_freq"
#define CPUFREQ_SYSFS_INTERFACE_CPUMAX     "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
#define CPUFREQ_SYSFS_INTERFACE_CPUMIN     "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
#define CPUFREQ_PROC_INTERFACE          "/proc/cpufreq"
#define CPUFREQ_PROC_INTERFACE_SPEED    "/proc/sys/cpu/0/speed"
#define CPUFREQ_PROC_INTERFACE_MIN      "/proc/sys/cpu/0/speed-min"
#define CPUFREQ_PROC_INTERFACE_MAX      "/proc/sys/cpu/0/speed-max"

/* kernel version constants */
#define KVER_24 1
#define KVER_26 2

struct interval {
  int min;
  int max;
};

typedef struct interval battery_interval;
typedef struct interval cpu_interval;

typedef struct profile {
  char name[255];
  long int min_freq;
  long int max_freq;
  unsigned char sep;
  char policy_name[255];
  struct profile *next;
} profile;

/* TODO: add precedence factor for rules having he same score */
/* TODO: add a command to be executed after the rule is activated */
typedef struct rule {
  char name[255];
  unsigned int ac;        /* AC power state */
  battery_interval *bat;
  cpu_interval *cpu;  
  float cpu_nice_scale;     /* how much will nice cpu time influence this rule? */
  int delay_cycles;       /* # of cycles this rule can wait before being applyed */
  char profile_name[255];
  struct string_list *program_list;
  profile *prof;
  struct rule *next;
  int hits;
} rule;

typedef struct sys_info {
  int has_battery:1;
  unsigned int ac;
  /*
  int old_weighted_activity;
  int cur_sys_activity;
  int cur_nice_activity;
  */
  int cpu_percent;
  int battery_percent;
  int battery_time;
  int temp;
  unsigned int flags;
	char version[101];
	char time[101];
} sys_info;

#define MATCH_AC       8
#define MATCH_CPU      4
#define MATCH_BATTERY  2
#define MATCH_PROG     1

#define DEFAULT_NICE_SCALE  3
#define DEFAULT_VERBOSITY   4
#define DEFAULT_POLL        1
#define DEFAULT_PMPLUGIN    "acpi"

typedef struct {
  char config_file[512];
  char pidfile[512];
  char pm_plugin[101];
  unsigned int poll_interval;
  int cpu_num;
  unsigned int has_sysfs;
  unsigned int no_daemon;
  unsigned int log_level_overridden;
  unsigned int acpi_workaround;
  long int cpu_min_freq;
  long int cpu_max_freq;
  int log_level;
  int kver;
  rule *rules;
  profile *profiles;
} general;

#endif