OSDN Git Service

libperfmgr: Update nodes in 2 passes
authorWei Wang <wvw@google.com>
Wed, 6 Jun 2018 18:20:36 +0000 (11:20 -0700)
committerWei Wang <wvw@google.com>
Fri, 28 Sep 2018 17:49:51 +0000 (17:49 +0000)
Some nodes have dependency in each other: e.g cpufreq min/max

Bug: 116855734
Test: libperfmgr_test pass
Change-Id: Ica639b94e78d40fd0f21fb8f241dc1887a6756fc

libperfmgr/Node.cc
libperfmgr/NodeLooperThread.cc
libperfmgr/include/perfmgr/Node.h

index 63cf8aa..c35c3ca 100644 (file)
@@ -66,7 +66,7 @@ bool Node::RemoveRequest(const std::string& hint_type) {
     return ret;
 }
 
-std::chrono::milliseconds Node::Update() {
+std::chrono::milliseconds Node::Update(bool log_error) {
     std::size_t value_index = default_val_index_;
     std::chrono::milliseconds expire_time = std::chrono::milliseconds::max();
 
@@ -86,8 +86,10 @@ std::chrono::milliseconds Node::Update() {
             open(node_path_.c_str(), O_WRONLY | O_CLOEXEC | O_TRUNC)));
 
         if (fd_ == -1 || !android::base::WriteStringToFd(req_value, fd_)) {
-            LOG(ERROR) << "Failed to write to node: " << node_path_
-                       << " with value: " << req_value << ", fd: " << fd_;
+            if (log_error) {
+                LOG(WARNING) << "Failed to write to node: " << node_path_
+                             << " with value: " << req_value << ", fd: " << fd_;
+            }
             // Retry in 500ms or sooner
             expire_time = std::min(expire_time, std::chrono::milliseconds(500));
         } else {
index e7a63cc..b4a27a9 100644 (file)
@@ -98,9 +98,15 @@ void NodeLooperThread::DumpToFd(int fd) {
 bool NodeLooperThread::threadLoop() {
     ::android::AutoMutex _l(lock_);
     std::chrono::milliseconds timeout_ms = kMaxUpdatePeriod;
+
+    // Update 2 passes: some node may have dependency in other node
+    // e.g. update cpufreq min to VAL while cpufreq max still set to
+    // a value lower than VAL, is expected to fail in first pass
+    for (auto& n : nodes_) {
+        n->Update(false);
+    }
     for (auto& n : nodes_) {
-        auto t = n->Update();
-        timeout_ms = std::min(t, timeout_ms);
+        timeout_ms = std::min(n->Update(), timeout_ms);
     }
 
     nsecs_t sleep_timeout_ns = std::numeric_limits<nsecs_t>::max();
index ea4c3e3..560979b 100644 (file)
@@ -61,7 +61,7 @@ class Node {
     // 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.
-    std::chrono::milliseconds Update();
+    std::chrono::milliseconds Update(bool log_error = true);
 
     std::string GetName() const;
     std::string GetPath() const;