system/extras
Revision | 23fa94128f73282f62a410a37bdcd415265a62f7 (tree) |
---|---|
Time | 2018-09-29 02:49:51 |
Author | Wei Wang <wvw@goog...> |
Commiter | Wei Wang |
libperfmgr: Update nodes in 2 passes
Some nodes have dependency in each other: e.g cpufreq min/max
Bug: 116855734
Test: libperfmgr_test pass
Change-Id: Ica639b94e78d40fd0f21fb8f241dc1887a6756fc
@@ -66,7 +66,7 @@ bool Node::RemoveRequest(const std::string& hint_type) { | ||
66 | 66 | return ret; |
67 | 67 | } |
68 | 68 | |
69 | -std::chrono::milliseconds Node::Update() { | |
69 | +std::chrono::milliseconds Node::Update(bool log_error) { | |
70 | 70 | std::size_t value_index = default_val_index_; |
71 | 71 | std::chrono::milliseconds expire_time = std::chrono::milliseconds::max(); |
72 | 72 |
@@ -86,8 +86,10 @@ std::chrono::milliseconds Node::Update() { | ||
86 | 86 | open(node_path_.c_str(), O_WRONLY | O_CLOEXEC | O_TRUNC))); |
87 | 87 | |
88 | 88 | if (fd_ == -1 || !android::base::WriteStringToFd(req_value, fd_)) { |
89 | - LOG(ERROR) << "Failed to write to node: " << node_path_ | |
90 | - << " with value: " << req_value << ", fd: " << fd_; | |
89 | + if (log_error) { | |
90 | + LOG(WARNING) << "Failed to write to node: " << node_path_ | |
91 | + << " with value: " << req_value << ", fd: " << fd_; | |
92 | + } | |
91 | 93 | // Retry in 500ms or sooner |
92 | 94 | expire_time = std::min(expire_time, std::chrono::milliseconds(500)); |
93 | 95 | } else { |
@@ -98,9 +98,15 @@ void NodeLooperThread::DumpToFd(int fd) { | ||
98 | 98 | bool NodeLooperThread::threadLoop() { |
99 | 99 | ::android::AutoMutex _l(lock_); |
100 | 100 | std::chrono::milliseconds timeout_ms = kMaxUpdatePeriod; |
101 | + | |
102 | + // Update 2 passes: some node may have dependency in other node | |
103 | + // e.g. update cpufreq min to VAL while cpufreq max still set to | |
104 | + // a value lower than VAL, is expected to fail in first pass | |
105 | + for (auto& n : nodes_) { | |
106 | + n->Update(false); | |
107 | + } | |
101 | 108 | for (auto& n : nodes_) { |
102 | - auto t = n->Update(); | |
103 | - timeout_ms = std::min(t, timeout_ms); | |
109 | + timeout_ms = std::min(n->Update(), timeout_ms); | |
104 | 110 | } |
105 | 111 | |
106 | 112 | nsecs_t sleep_timeout_ns = std::numeric_limits<nsecs_t>::max(); |
@@ -61,7 +61,7 @@ class Node { | ||
61 | 61 | // std::chrono::milliseconds::max() if no active request on Node; update |
62 | 62 | // node's controlled file node value and the current value index based on |
63 | 63 | // active request. |
64 | - std::chrono::milliseconds Update(); | |
64 | + std::chrono::milliseconds Update(bool log_error = true); | |
65 | 65 | |
66 | 66 | std::string GetName() const; |
67 | 67 | std::string GetPath() const; |