File: throttle_interface.h

package info (click to toggle)
powersave 0.14.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,764 kB
  • ctags: 999
  • sloc: sh: 11,357; cpp: 8,103; ansic: 2,631; makefile: 388
file content (93 lines) | stat: -rw-r--r-- 3,647 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
 *                                                                         *
 *                         Powersave Daemon                                *
 *                                                                         *
 *          Copyright (C) 2004,2005 SUSE Linux Products GmbH               *
 *                                                                         *
 *               Author(s): Holger Macht <hmacht@suse.de>                  *
 *                                                                         *
 * 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 you   *
 * 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., *
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                  *
 *                                                                         *
 ***************************************************************************/

#ifndef THROTTLE_INTERFACE_H
#define THROTTLE_INTERFACE_H

class EventManagement;

/** @brief used to evaluate whether to throw a processor.idle or
 * processor.busy event */
enum PROCESSOR_EVENT_STATE { PROCESSOR_BUSY_THROWN,
			     PROCESSOR_IDLE_THROWN,
			     NO_PROCESSOR_EVENT_THROWN };

/** @brief class caring about throttling the cpu while load changes */
class ThrottleInterface {
public:
	/** @brief constructor */
	ThrottleInterface();

	/** @brief checks all cpus whether they should get throttled
	 *
	 * @return false if something went wrong, true otherwise */
	bool updateCPUState(EventManagement *eM);

	/** @brief throttles cpus
	 *
	 * @param percent throttle cpus to that percentage
	 *        -1 means maximum throttling
	 * @return true if throttling supported, false otherwise
	 */
	bool throttle(int percent = -1);

	/** @brief dethrottles cpus
	 *
	 * @return true if throttling supported, false otherwise
	 */
	bool dethrottle();

	/** @brief resets the object and clears all local values
	 *
	 * this may be used to start evaluating from the beginning */
	void restart();

	/** @brief disables throttling */
	void disableThrottling();

private:
	/** @brief timeout when processor.low event should be thrown
	 * if it stays under the limit for this time */
	unsigned long _msecs_cpu_idle;

	/** @brief whether cpu is currently idle
	 *
	 * this does not reflect whether the cpu is throttled. This
	 * variable has to be true long enough for the cpu being throttled
	 */
	bool _cpu_is_idle;

	/** @brief indicates whether an processor event was thrown
	 *
	 * value of 1 indicates that processor.low event
	 * has been thrown, value of 0 indicates, that it
	 * has not thrown till now
	 */
	PROCESSOR_EVENT_STATE _event_state;

	/** @brief defines whether throttling is supported */
	bool _throttling_supported;
};

#endif // THROTTLE_INTERFACE_H