diff options
Diffstat (limited to 'libperfmgr/include/perfmgr')
-rw-r--r-- | libperfmgr/include/perfmgr/FileNode.h | 56 | ||||
-rw-r--r-- | libperfmgr/include/perfmgr/HintManager.h | 98 | ||||
-rw-r--r-- | libperfmgr/include/perfmgr/Node.h | 92 | ||||
-rw-r--r-- | libperfmgr/include/perfmgr/NodeLooperThread.h | 104 | ||||
-rw-r--r-- | libperfmgr/include/perfmgr/PropertyNode.h | 48 | ||||
-rw-r--r-- | libperfmgr/include/perfmgr/RequestGroup.h | 67 |
6 files changed, 0 insertions, 465 deletions
diff --git a/libperfmgr/include/perfmgr/FileNode.h b/libperfmgr/include/perfmgr/FileNode.h deleted file mode 100644 index b8f2db6e..00000000 --- a/libperfmgr/include/perfmgr/FileNode.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_FILENODE_H_ -#define ANDROID_LIBPERFMGR_FILENODE_H_ - -#include <android-base/unique_fd.h> - -#include <cstddef> -#include <string> -#include <vector> - -#include "perfmgr/Node.h" - -namespace android { -namespace perfmgr { - -// FileNode represents file -class FileNode : public Node { - public: - FileNode(std::string name, std::string node_path, - std::vector<RequestGroup> req_sorted, std::size_t default_val_index, - bool reset_on_init, bool hold_fd = false); - - std::chrono::milliseconds Update(bool log_error) override; - - bool GetHoldFd() const; - - void DumpToFd(int fd) const override; - - private: - FileNode(const Node& other) = delete; - FileNode& operator=(Node const&) = delete; - - const bool hold_fd_; - const std::chrono::milliseconds warn_timeout_; - android::base::unique_fd fd_; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_FILENODE_H_ diff --git a/libperfmgr/include/perfmgr/HintManager.h b/libperfmgr/include/perfmgr/HintManager.h deleted file mode 100644 index bfb96fde..00000000 --- a/libperfmgr/include/perfmgr/HintManager.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_HINTMANAGER_H_ -#define ANDROID_LIBPERFMGR_HINTMANAGER_H_ - -#include <cstddef> -#include <map> -#include <memory> -#include <string> -#include <utility> -#include <vector> - -#include "perfmgr/NodeLooperThread.h" - -namespace android { -namespace perfmgr { - -// HintManager is the external interface of the library to be used by PowerHAL -// to do power hints with sysfs nodes. HintManager maintains a representation of -// the actions that are parsed from the configuration file as a mapping from a -// PowerHint to the set of actions that are performed for that PowerHint. -class HintManager { - public: - HintManager(sp<NodeLooperThread> nm, - const std::map<std::string, std::vector<NodeAction>>& actions) - : nm_(std::move(nm)), actions_(actions) {} - ~HintManager() { - if (nm_.get() != nullptr) nm_->Stop(); - } - - // Return true if the sysfs manager thread is running. - bool IsRunning() const; - - // Do hint based on hint_type which defined as PowerHint in the actions - // section of the JSON config. Return true with valid hint_type and also - // NodeLooperThread::Request succeeds; otherwise return false. - bool DoHint(const std::string& hint_type); - - // Do hint with the override time for all actions defined for the given - // hint_type. Return true with valid hint_type and also - // NodeLooperThread::Request succeeds; otherwise return false. - bool DoHint(const std::string& hint_type, - std::chrono::milliseconds timeout_ms_override); - - // End hint early. Return true with valid hint_type and also - // NodeLooperThread::Cancel succeeds; otherwise return false. - bool EndHint(const std::string& hint_type); - - // Query if given hint supported. - bool IsHintSupported(const std::string& hint_type) const; - - // Static method to construct HintManager from the JSON config file. - static std::unique_ptr<HintManager> GetFromJSON( - const std::string& config_path, bool start = true); - - // Return available hints managed by HintManager - std::vector<std::string> GetHints() const; - - // Dump internal status to fd - void DumpToFd(int fd); - - // Start thread loop - bool Start(); - - protected: - static std::vector<std::unique_ptr<Node>> ParseNodes( - const std::string& json_doc); - static std::map<std::string, std::vector<NodeAction>> ParseActions( - const std::string& json_doc, - const std::vector<std::unique_ptr<Node>>& nodes); - - private: - HintManager(HintManager const&) = delete; - void operator=(HintManager const&) = delete; - bool ValidateHint(const std::string& hint_type) const; - - sp<NodeLooperThread> nm_; - const std::map<std::string, std::vector<NodeAction>> actions_; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_HINTMANAGER_H_ diff --git a/libperfmgr/include/perfmgr/Node.h b/libperfmgr/include/perfmgr/Node.h deleted file mode 100644 index e0db0777..00000000 --- a/libperfmgr/include/perfmgr/Node.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_NODE_H_ -#define ANDROID_LIBPERFMGR_NODE_H_ - -#include <android-base/unique_fd.h> - -#include <cstddef> -#include <string> -#include <vector> - -#include "perfmgr/RequestGroup.h" - -namespace android { -namespace perfmgr { - -// The Node class provides an interface for adding and cancelling powerhint -// requests, as well as checking the next time that an in-progress powerhint -// request will expire. There are additional methods for getting the Node’s name -// and the index of a value, which may be used for initialization, debugging, -// and request management. The core of the Node class is a vector of -// RequestGroups named req_sorted_, which is used to track the in-progress -// requests on the node. Each entry in the vector corresponds to a possible -// value for the node, in priority order. For example, the first entry in the -// vector for the cpu0 cluster represents the in-progress requests to boost the -// cluster’s frequency to the highest available value. The next entry represents -// the in-progress requests to boost the cluster’s frequency to the next highest -// value. For each value, there may be multiple requests because different -// powerhints may request the same value, and the requests may have different -// expiration times. All of the in-progress powerhints for a given value are -// collected in a RequestGroup. Node class is not thread safe so it needs -// protection from caller e.g. NodeLooperThread. -class Node { - public: - virtual ~Node() {} - - // Return true if successfully add a request - bool AddRequest(std::size_t value_index, const std::string& hint_type, - ReqTime end_time); - - // Return true if successfully remove a request - bool RemoveRequest(const std::string& hint_type); - - // Return the nearest expire time of active requests; return - // std::chrono::milliseconds::max() if no active request on Node; update - // node's controlled file node value and the current value index based on - // active request. - virtual std::chrono::milliseconds Update(bool log_error) = 0; - - const std::string& GetName() const; - const std::string& GetPath() const; - std::vector<std::string> GetValues() const; - std::size_t GetDefaultIndex() const; - bool GetResetOnInit() const; - bool GetValueIndex(const std::string& value, std::size_t* index) const; - virtual void DumpToFd(int fd) const = 0; - - protected: - Node(std::string name, std::string node_path, - std::vector<RequestGroup> req_sorted, std::size_t default_val_index, - bool reset_on_init); - Node(const Node& other) = delete; - Node& operator=(Node const&) = delete; - - const std::string name_; - const std::string node_path_; - // request vector, one entry per possible value, sorted by priority. - std::vector<RequestGroup> req_sorted_; - const std::size_t default_val_index_; - // node will be explicitly initialized when first time called Update(). - bool reset_on_init_; - std::size_t current_val_index_; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_NODE_H_ diff --git a/libperfmgr/include/perfmgr/NodeLooperThread.h b/libperfmgr/include/perfmgr/NodeLooperThread.h deleted file mode 100644 index eba0fc7f..00000000 --- a/libperfmgr/include/perfmgr/NodeLooperThread.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_NODELOOPERTHREAD_H_ -#define ANDROID_LIBPERFMGR_NODELOOPERTHREAD_H_ - -#include <utils/Thread.h> - -#include <cstddef> -#include <memory> -#include <string> -#include <utility> -#include <vector> - -#include "perfmgr/Node.h" - -namespace android { -namespace perfmgr { - -// The NodeAction specifies the sysfs node, the value to be assigned, and the -// timeout for this action: -struct NodeAction { - NodeAction(std::size_t node_index, std::size_t value_index, - std::chrono::milliseconds timeout_ms) - : node_index(node_index), - value_index(value_index), - timeout_ms(timeout_ms) {} - std::size_t node_index; - std::size_t value_index; - std::chrono::milliseconds timeout_ms; // 0ms for forever -}; - -// The NodeLooperThread is responsible for managing each of the sysfs nodes -// specified in the configuration. At initialization, the NodeLooperThrea holds -// a vector containing the nodes defined in the configuration. The NodeManager -// gets powerhint requests and cancellations from the HintManager, maintains -// state about the current set of powerhint requests on each sysfs node, and -// decides how to apply the requests. The NodeLooperThread contains a ThreadLoop -// to maintain the sysfs nodes, and that thread is woken up both to handle -// powerhint requests and when the timeout expires for an in-progress powerhint. -class NodeLooperThread : public ::android::Thread { - public: - explicit NodeLooperThread(std::vector<std::unique_ptr<Node>> nodes) - : Thread(false), nodes_(std::move(nodes)) {} - virtual ~NodeLooperThread() { Stop(); } - - // Need call Stop() as the threadloop will hold a strong pointer - // itself and wait for Condition fired or timeout (60s) before - // the out looper can call deconstructor to Stop() thread - void Stop(); - - // Return true when successfully adds request from actions for the hint_type - // in each individual node. Return false if any of the actions has either - // invalid node index or value index. - bool Request(const std::vector<NodeAction>& actions, - const std::string& hint_type); - // Return when successfully cancels request from actions for the hint_type - // in each individual node. Return false if any of the actions has invalid - // node index. - bool Cancel(const std::vector<NodeAction>& actions, - const std::string& hint_type); - - // Dump all nodes to fd - void DumpToFd(int fd); - - // Return true when successfully started the looper thread - bool Start(); - - private: - NodeLooperThread(NodeLooperThread const&) = delete; - void operator=(NodeLooperThread const&) = delete; - bool threadLoop() override; - - static constexpr auto kMaxUpdatePeriod = std::chrono::milliseconds::max(); - - std::vector<std::unique_ptr<Node>> nodes_; // parsed from Config - - // conditional variable from C++ standard library can be affected by wall - // time change as it is using CLOCK_REAL (b/35756266). The component should - // not be impacted by wall time, thus need use Android specific Condition - // class for waking up threadloop. - ::android::Condition wake_cond_; - - // lock to protect nodes_ - ::android::Mutex lock_; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_NODELOOPERTHREAD_H_ diff --git a/libperfmgr/include/perfmgr/PropertyNode.h b/libperfmgr/include/perfmgr/PropertyNode.h deleted file mode 100644 index feaf85fa..00000000 --- a/libperfmgr/include/perfmgr/PropertyNode.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_PROPERTYNODE_H_ -#define ANDROID_LIBPERFMGR_PROPERTYNODE_H_ - -#include <cstddef> -#include <string> -#include <vector> - -#include "perfmgr/Node.h" - -namespace android { -namespace perfmgr { - -// PropertyNode represents managed system properties -class PropertyNode : public Node { - public: - PropertyNode(std::string name, std::string node_path, - std::vector<RequestGroup> req_sorted, - std::size_t default_val_index, bool reset_on_init); - - std::chrono::milliseconds Update(bool log_error) override; - - void DumpToFd(int fd) const override; - - private: - PropertyNode(const Node& other) = delete; - PropertyNode& operator=(Node const&) = delete; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_PROPERTYNODE_H_ diff --git a/libperfmgr/include/perfmgr/RequestGroup.h b/libperfmgr/include/perfmgr/RequestGroup.h deleted file mode 100644 index 698a8216..00000000 --- a/libperfmgr/include/perfmgr/RequestGroup.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specic language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_LIBPERFMGR_REQUESTGROUP_H_ -#define ANDROID_LIBPERFMGR_REQUESTGROUP_H_ - -#include <chrono> -#include <map> -#include <string> -#include <utility> - -namespace android { -namespace perfmgr { - -using ReqTime = std::chrono::time_point<std::chrono::steady_clock>; - -// The RequestGroup type represents the set of requests for a given value on a -// particular sysfs node, and the interface is simple: there is a function to -// add requests, a function to remove requests, and a function to check for the -// next expiration time if there is an outstanding request, and a function to -// check the requested value. There may only be one request per PowerHint, so -// the representation is simple: a map from PowerHint to the expiration time for -// that hint. -class RequestGroup { - public: - RequestGroup(std::string request_value) // NOLINT(runtime/explicit) - : request_value_(std::move(request_value)) {} - - // Remove expired request in the map and return true when request_map_ is - // not empty, false when request_map_ is empty; also update expire_time with - // nearest timeout in request_map_ or std::chrono::milliseconds::max() when - // request_map_ is empty. - bool GetExpireTime(std::chrono::milliseconds* expire_time); - // Return the request value. - const std::string& GetRequestValue() const; - // Return true for adding request, false for extending expire time of - // existing active request on given hint_type. - bool AddRequest(const std::string& hint_type, ReqTime end_time); - // Return true for removing request, false if request is not active on given - // hint_type. If request exits and the new end_time is less than the active - // time, expire time will not be updated; also returns false. - bool RemoveRequest(const std::string& hint_type); - // Dump internal status to fd - void DumpToFd(int fd, const std::string& prefix) const; - - private: - const std::string request_value_; - std::map<std::string, ReqTime> request_map_; -}; - -} // namespace perfmgr -} // namespace android - -#endif // ANDROID_LIBPERFMGR_REQUESTGROUP_H_ |