From 48750dc0f366911b8d2c4c39fc915b4beaef5aa8 Mon Sep 17 00:00:00 2001 From: Philip Cuadra Date: Tue, 11 Jul 2017 15:26:53 -0700 Subject: [PATCH] Add powerHintAsync functionality Add an async version of powerHint called powerHintAsync. Bug: 62377008 Test: Take systrace, confirm powerHint is now an async HIDL transaction Change-Id: I7c4d850ef17c909977675771d6c2b8a3fa1609d2 --- current.txt | 2 +- power/1.1/IPower.hal | 14 ++++++++ power/1.1/default/Power.cpp | 5 +++ power/1.1/default/Power.h | 1 + .../functional/VtsHalPowerV1_1TargetTest.cpp | 36 +++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/current.txt b/current.txt index 986e0ecdf5..d93352a608 100644 --- a/current.txt +++ b/current.txt @@ -197,7 +197,7 @@ fe3c3c2f572b72f15f8594c538b0577bd5c28722c31879cfe6231330cddb6747 android.hardwar 4b65763663a94a3920134011691f8fbb42ccb7b7795589efddc049a9106047d6 android.hardware.oemlock@1.0::IOemLock e02cd3722cb5e8fa51179f5defacb4f7866f903c9c7c51dc01a3148473a71525 android.hardware.oemlock@1.0::types -9f69e783fa2c482d90b2f799ddd33378a92d22a261983df6b492358e01f4d791 android.hardware.power@1.1::IPower +224f9d22a367a0016f09b6dc676f53f1446697d9dc747163032329e5da552de5 android.hardware.power@1.1::IPower 574fd9758b7cab4922c72cc5a9f36d1cd48ffd3425fdd776426653280d3d4138 android.hardware.power@1.1::types f79edf50a378a9c9bb737f93f205dab91b4c63ea49723afc6f856c138203ea81 android.hardware.radio@1.1::IRadio fcc5c8c88b85a9f63fba67d9e674da466c72a98ca287f343fb5721d098713f86 android.hardware.radio@1.1::IRadioIndication diff --git a/power/1.1/IPower.hal b/power/1.1/IPower.hal index 0c0f211173..086904ee6f 100644 --- a/power/1.1/IPower.hal +++ b/power/1.1/IPower.hal @@ -33,4 +33,18 @@ interface IPower extends android.hardware.power@1.0::IPower { */ getSubsystemLowPowerStats() generates (vec subsystems, Status retval); + + /** + * powerHintAsync() is called to pass hints on power requirements which + * may result in adjustment of power/performance parameters of the + * cpufreq governor and other controls. + * + * A particular platform may choose to ignore any hint. + * + * @param hint PowerHint which is passed + * @param data contains additional information about the hint + * and is described along with the comments for each of the hints. + */ + oneway powerHintAsync(PowerHint hint, int32_t data); + }; diff --git a/power/1.1/default/Power.cpp b/power/1.1/default/Power.cpp index bf7c1fc655..b5d0c84bcc 100644 --- a/power/1.1/default/Power.cpp +++ b/power/1.1/default/Power.cpp @@ -165,6 +165,11 @@ Return Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl return Void(); } +Return Power::powerHintAsync(PowerHint hint, int32_t data) { + // just call the normal power hint in this oneway function + return powerHint(hint, data); +} + } // namespace implementation } // namespace V1_1 } // namespace power diff --git a/power/1.1/default/Power.h b/power/1.1/default/Power.h index ea9e8c3154..e779d64d37 100644 --- a/power/1.1/default/Power.h +++ b/power/1.1/default/Power.h @@ -46,6 +46,7 @@ struct Power : public IPower { // Methods from ::android::hardware::power::V1_1::IPower follow. Return getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override; + Return powerHintAsync(PowerHint hint, int32_t data) override; // Methods from ::android::hidl::base::V1_0::IBase follow. diff --git a/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp b/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp index 1d0d50fd45..dc843f49d8 100644 --- a/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp +++ b/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp @@ -23,6 +23,7 @@ using ::android::hardware::power::V1_1::IPower; using ::android::hardware::power::V1_1::PowerStateSubsystem; using ::android::hardware::power::V1_0::Status; +using ::android::hardware::power::V1_0::PowerHint; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::sp; @@ -54,6 +55,41 @@ TEST_F(PowerHidlTest, GetSubsystemLowPowerStats) { ASSERT_TRUE(s == Status::SUCCESS || s == Status::FILESYSTEM_ERROR); } +// Sanity check Power::powerHintAsync on good and bad inputs. +TEST_F(PowerHidlTest, PowerHintAsync) { + PowerHint badHint = static_cast(0xA); + auto hints = {PowerHint::VSYNC, PowerHint::INTERACTION, PowerHint::VIDEO_ENCODE, + PowerHint::VIDEO_DECODE, PowerHint::LOW_POWER, PowerHint::SUSTAINED_PERFORMANCE, + PowerHint::VR_MODE, PowerHint::LAUNCH, badHint}; + Return ret; + for (auto hint : hints) { + ret = power->powerHintAsync(hint, 30000); + ASSERT_TRUE(ret.isOk()); + + ret = power->powerHintAsync(hint, 0); + ASSERT_TRUE(ret.isOk()); + } + + // Turning these hints on in different orders triggers different code paths, + // so iterate over possible orderings. + std::vector hints2 = {PowerHint::LAUNCH, PowerHint::VR_MODE, + PowerHint::SUSTAINED_PERFORMANCE, PowerHint::INTERACTION}; + auto compareHints = [](PowerHint l, PowerHint r) { + return static_cast(l) < static_cast(r); + }; + std::sort(hints2.begin(), hints2.end(), compareHints); + do { + for (auto iter = hints2.begin(); iter != hints2.end(); iter++) { + ret = power->powerHintAsync(*iter, 0); + ASSERT_TRUE(ret.isOk()); + } + for (auto iter = hints2.begin(); iter != hints2.end(); iter++) { + ret = power->powerHintAsync(*iter, 30000); + ASSERT_TRUE(ret.isOk()); + } + } while (std::next_permutation(hints2.begin(), hints2.end(), compareHints)); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); int status = RUN_ALL_TESTS();