blob: 6b3eab8ff1111c87c6ef9e38a6332c040d16d5d8 [file] [log] [blame]
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THERMALD_CPUFREQ_DEVICE_H_
#define THERMALD_CPUFREQ_DEVICE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
namespace thermald {
// Class to interface with the Linux kernel cpufreq driver.
//
// A CpufreqDevice object represents the cpufreq interface of one
// core of the system.
class CpufreqDevice {
public:
// Constructs an object corresponding to the cpufreq interface of the given
// CPU id.
explicit CpufreqDevice(int cpu_id);
// Set the maximum frequency of the CPU.
bool SetMaximumFrequency(int max_frequency);
// Get the list of the frequencies at which the CPU can operate.
// If a failure occurs, GetAvailableFrequencies returns false and does not
// modify available_frequencies.
bool GetAvailableFrequencies(std::vector<int> *available_frequencies);
int cpu_id() const { return cpu_id_; }
// Get CpufreqDevice objects for all cores of the system with cpufreq support.
// Returns true on success, otherwise false.
static bool
GetDevices(std::vector<std::unique_ptr<CpufreqDevice>> *cpufreq_devices);
private:
const int cpu_id_;
const base::FilePath sysfs_base_path_;
DISALLOW_COPY_AND_ASSIGN(CpufreqDevice);
};
} // namespace thermald
#endif // THERMALD_CPUFREQ_DEVICE_H_