Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e13e8a94 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11292102 from fc37ec5d to 24Q2-release

Change-Id: I8dd16a327f49ef501f84396073821b99168c9ad3
parents 27ebe80a fc37ec5d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public:
            flags = O_RDWR;
            checkRead = checkWrite = true;
        } else {
            mErrorLog << "Invalid mode requested: " << mode.c_str() << endl;
            mErrorLog << "Invalid mode requested: " << mode << endl;
            return -EINVAL;
        }
        int fd = open(fullPath.c_str(), flags, S_IRWXU|S_IRWXG);
+110 −84
Original line number Diff line number Diff line
@@ -49,6 +49,63 @@ public:
    }
};

static uint64_t warn_latency = std::numeric_limits<uint64_t>::max();

struct ProcResults {
    vector<uint64_t> data;

    ProcResults(size_t capacity) { data.reserve(capacity); }

    void add_time(uint64_t time) { data.push_back(time); }
    void combine_with(const ProcResults& append) {
        data.insert(data.end(), append.data.begin(), append.data.end());
    }
    uint64_t worst() {
        return *max_element(data.begin(), data.end());
    }
    void dump() {
        if (data.size() == 0) {
            // This avoids index-out-of-bounds below.
            cout << "error: no data\n" << endl;
            return;
        }

        size_t num_long_transactions = 0;
        for (uint64_t elem : data) {
            if (elem > warn_latency) {
                num_long_transactions += 1;
            }
        }

        if (num_long_transactions > 0) {
            cout << (double)num_long_transactions / data.size() << "% of transactions took longer "
                "than estimated max latency. Consider setting -m to be higher than "
                << worst() / 1000 << " microseconds" << endl;
        }

        sort(data.begin(), data.end());

        uint64_t total_time = 0;
        for (uint64_t elem : data) {
            total_time += elem;
        }

        double best = (double)data[0] / 1.0E6;
        double worst = (double)data.back() / 1.0E6;
        double average = (double)total_time / data.size() / 1.0E6;
        cout << "average:" << average << "ms worst:" << worst << "ms best:" << best << "ms" << endl;

        double percentile_50 = data[(50 * data.size()) / 100] / 1.0E6;
        double percentile_90 = data[(90 * data.size()) / 100] / 1.0E6;
        double percentile_95 = data[(95 * data.size()) / 100] / 1.0E6;
        double percentile_99 = data[(99 * data.size()) / 100] / 1.0E6;
        cout << "50%: " << percentile_50 << " ";
        cout << "90%: " << percentile_90 << " ";
        cout << "95%: " << percentile_95 << " ";
        cout << "99%: " << percentile_99 << endl;
    }
};

class Pipe {
    int m_readFd;
    int m_writeFd;
@@ -79,13 +136,37 @@ public:
        int error = read(m_readFd, &val, sizeof(val));
        ASSERT_TRUE(error >= 0);
    }
    template <typename T> void send(const T& v) {
        int error = write(m_writeFd, &v, sizeof(T));
    void send(const ProcResults& v) {
        size_t num_elems = v.data.size();

        int error = write(m_writeFd, &num_elems, sizeof(size_t));
        ASSERT_TRUE(error >= 0);

        char* to_write = (char*)v.data.data();
        size_t num_bytes = sizeof(uint64_t) * num_elems;

        while (num_bytes > 0) {
            int ret = write(m_writeFd, to_write, num_bytes);
            ASSERT_TRUE(ret >= 0);
            num_bytes -= ret;
            to_write += ret;
        }
    }
    template <typename T> void recv(T& v) {
        int error = read(m_readFd, &v, sizeof(T));
    void recv(ProcResults& v) {
        size_t num_elems = 0;
        int error = read(m_readFd, &num_elems, sizeof(size_t));
        ASSERT_TRUE(error >= 0);

        v.data.resize(num_elems);
        char* read_to = (char*)v.data.data();
        size_t num_bytes = sizeof(uint64_t) * num_elems;

        while (num_bytes > 0) {
            int ret = read(m_readFd, read_to, num_bytes);
            ASSERT_TRUE(ret >= 0);
            num_bytes -= ret;
            read_to += ret;
        }
    }
    static tuple<Pipe, Pipe> createPipePair() {
        int a[2];
@@ -100,74 +181,6 @@ public:
    }
};

static const uint32_t num_buckets = 128;
static uint64_t max_time_bucket = 50ull * 1000000;
static uint64_t time_per_bucket = max_time_bucket / num_buckets;

struct ProcResults {
    uint64_t m_worst = 0;
    uint32_t m_buckets[num_buckets] = {0};
    uint64_t m_transactions = 0;
    uint64_t m_long_transactions = 0;
    uint64_t m_total_time = 0;
    uint64_t m_best = max_time_bucket;

    void add_time(uint64_t time) {
        if (time > max_time_bucket) {
            m_long_transactions++;
        }
        m_buckets[min((uint32_t)(time / time_per_bucket), num_buckets - 1)] += 1;
        m_best = min(time, m_best);
        m_worst = max(time, m_worst);
        m_transactions += 1;
        m_total_time += time;
    }
    static ProcResults combine(const ProcResults& a, const ProcResults& b) {
        ProcResults ret;
        for (int i = 0; i < num_buckets; i++) {
            ret.m_buckets[i] = a.m_buckets[i] + b.m_buckets[i];
        }
        ret.m_worst = max(a.m_worst, b.m_worst);
        ret.m_best = min(a.m_best, b.m_best);
        ret.m_transactions = a.m_transactions + b.m_transactions;
        ret.m_long_transactions = a.m_long_transactions + b.m_long_transactions;
        ret.m_total_time = a.m_total_time + b.m_total_time;
        return ret;
    }
    void dump() {
        if (m_long_transactions > 0) {
            cout << (double)m_long_transactions / m_transactions << "% of transactions took longer "
                "than estimated max latency. Consider setting -m to be higher than "
                 << m_worst / 1000 << " microseconds" << endl;
        }

        double best = (double)m_best / 1.0E6;
        double worst = (double)m_worst / 1.0E6;
        double average = (double)m_total_time / m_transactions / 1.0E6;
        cout << "average:" << average << "ms worst:" << worst << "ms best:" << best << "ms" << endl;

        uint64_t cur_total = 0;
        float time_per_bucket_ms = time_per_bucket / 1.0E6;
        for (int i = 0; i < num_buckets; i++) {
            float cur_time = time_per_bucket_ms * i + 0.5f * time_per_bucket_ms;
            if ((cur_total < 0.5f * m_transactions) && (cur_total + m_buckets[i] >= 0.5f * m_transactions)) {
                cout << "50%: " << cur_time << " ";
            }
            if ((cur_total < 0.9f * m_transactions) && (cur_total + m_buckets[i] >= 0.9f * m_transactions)) {
                cout << "90%: " << cur_time << " ";
            }
            if ((cur_total < 0.95f * m_transactions) && (cur_total + m_buckets[i] >= 0.95f * m_transactions)) {
                cout << "95%: " << cur_time << " ";
            }
            if ((cur_total < 0.99f * m_transactions) && (cur_total + m_buckets[i] >= 0.99f * m_transactions)) {
                cout << "99%: " << cur_time << " ";
            }
            cur_total += m_buckets[i];
        }
        cout << endl;
    }
};

String16 generateServiceName(int num)
{
    char num_str[32];
@@ -208,7 +221,8 @@ void worker_fx(int num,
    }

    // Run the benchmark if client
    ProcResults results;
    ProcResults results(iterations);

    chrono::time_point<chrono::high_resolution_clock> start, end;
    for (int i = 0; (!cs_pair || num >= server_count) && i < iterations; i++) {
        Parcel data, reply;
@@ -302,11 +316,10 @@ void run_main(int iterations,
    // Collect all results from the workers.
    cout << "collecting results" << endl;
    signal_all(pipes);
    ProcResults tot_results;
    ProcResults tot_results(0), tmp_results(0);
    for (int i = 0; i < workers; i++) {
        ProcResults tmp_results;
        pipes[i].recv(tmp_results);
        tot_results = ProcResults::combine(tot_results, tmp_results);
        tot_results.combine_with(tmp_results);
    }

    // Kill all the workers.
@@ -320,11 +333,9 @@ void run_main(int iterations,
        }
    }
    if (training_round) {
        // sets max_time_bucket to 2 * m_worst from the training round.
        // Also needs to adjust time_per_bucket accordingly.
        max_time_bucket = 2 * tot_results.m_worst;
        time_per_bucket = max_time_bucket / num_buckets;
        cout << "Max latency during training: " << tot_results.m_worst / 1.0E6 << "ms" << endl;
        // Sets warn_latency to 2 * worst from the training round.
        warn_latency = 2 * tot_results.worst();
        cout << "Max latency during training: " << tot_results.worst() / 1.0E6 << "ms" << endl;
    } else {
        tot_results.dump();
    }
@@ -352,16 +363,28 @@ int main(int argc, char *argv[])
            return 0;
        }
        if (string(argv[i]) == "-w") {
            if (i + 1 == argc) {
                cout << "-w requires an argument\n" << endl;
                exit(EXIT_FAILURE);
            }
            workers = atoi(argv[i+1]);
            i++;
            continue;
        }
        if (string(argv[i]) == "-i") {
            if (i + 1 == argc) {
                cout << "-i requires an argument\n" << endl;
                exit(EXIT_FAILURE);
            }
            iterations = atoi(argv[i+1]);
            i++;
            continue;
        }
        if (string(argv[i]) == "-s") {
            if (i + 1 == argc) {
                cout << "-s requires an argument\n" << endl;
                exit(EXIT_FAILURE);
            }
            payload_size = atoi(argv[i+1]);
            i++;
            continue;
@@ -380,6 +403,10 @@ int main(int argc, char *argv[])
            continue;
        }
        if (string(argv[i]) == "-m") {
            if (i + 1 == argc) {
                cout << "-m requires an argument\n" << endl;
                exit(EXIT_FAILURE);
            }
            // Caller specified the max latency in microseconds.
            // No need to run training round in this case.
            max_time_us = atoi(argv[i+1]);
@@ -387,8 +414,7 @@ int main(int argc, char *argv[])
                cout << "Max latency -m must be positive." << endl;
                exit(EXIT_FAILURE);
            }
            max_time_bucket = max_time_us * 1000ull;
            time_per_bucket = max_time_bucket / num_buckets;
            warn_latency = max_time_us * 1000ull;
            i++;
            continue;
        }
+2 −2
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ private:
class InputDeviceContext {
public:
    InputDeviceContext(InputDevice& device, int32_t eventHubId);
    ~InputDeviceContext();
    virtual ~InputDeviceContext();

    inline InputReaderContext* getContext() { return mContext; }
    inline int32_t getId() { return mDeviceId; }
@@ -450,7 +450,7 @@ public:
    inline std::optional<std::string> getDeviceTypeAssociation() const {
        return mDevice.getDeviceTypeAssociation();
    }
    inline std::optional<DisplayViewport> getAssociatedViewport() const {
    virtual std::optional<DisplayViewport> getAssociatedViewport() const {
        return mDevice.getAssociatedViewport();
    }
    [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
+306 −13

File changed.

Preview size limit exceeded, changes collapsed.

+97 −10
Original line number Diff line number Diff line
@@ -1093,9 +1093,10 @@ public:
    FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle,
                     const std::unique_ptr<InputDispatcher>& dispatcher, const std::string name,
                     int32_t displayId, std::optional<sp<IBinder>> token = std::nullopt)
                     int32_t displayId, bool createInputChannel = true)
          : mName(name) {
        if (token == std::nullopt) {
        sp<IBinder> token;
        if (createInputChannel) {
            base::Result<std::unique_ptr<InputChannel>> channel =
                    dispatcher->createInputChannel(name);
            token = (*channel)->getConnectionToken();
@@ -1105,7 +1106,7 @@ public:
        inputApplicationHandle->updateInfo();
        mInfo.applicationInfo = *inputApplicationHandle->getInfo();
        mInfo.token = *token;
        mInfo.token = token;
        mInfo.id = sId++;
        mInfo.name = name;
        mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT;
@@ -2370,7 +2371,7 @@ TEST_F(InputDispatcherTest, HoverWhileWindowAppears) {
    sp<FakeWindowHandle> obscuringWindow =
            sp<FakeWindowHandle>::make(application, mDispatcher, "Obscuring window",
                                       ADISPLAY_ID_DEFAULT,
                                       /*token=*/std::make_optional<sp<IBinder>>(nullptr));
                                       /*createInputChannel=*/false);
    obscuringWindow->setFrame(Rect(0, 0, 200, 200));
    obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED);
    obscuringWindow->setOwnerInfo(SECONDARY_WINDOW_PID, SECONDARY_WINDOW_UID);
@@ -2419,7 +2420,7 @@ TEST_F(InputDispatcherTest, HoverMoveWhileWindowAppears) {
    sp<FakeWindowHandle> obscuringWindow =
            sp<FakeWindowHandle>::make(application, mDispatcher, "Obscuring window",
                                       ADISPLAY_ID_DEFAULT,
                                       /*token=*/std::make_optional<sp<IBinder>>(nullptr));
                                       /*createInputChannel=*/false);
    obscuringWindow->setFrame(Rect(0, 0, 200, 200));
    obscuringWindow->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED);
    obscuringWindow->setOwnerInfo(SECONDARY_WINDOW_PID, SECONDARY_WINDOW_UID);
@@ -7332,6 +7333,94 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CancelTouch_MultiDisplay) {
    monitorInSecondary.assertNoEvents();
}
/**
 * Send a key to the primary display and to the secondary display.
 * Then cause the key on the primary display to be canceled by sending in a stale key.
 * Ensure that the key on the primary display is canceled, and that the key on the secondary display
 * does not get canceled.
 */
TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropKeyEvent_OnlyCancelCorrespondingKeyGesture) {
    // Send a key down on primary display
    mDispatcher->notifyKey(
            KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD)
                    .displayId(ADISPLAY_ID_DEFAULT)
                    .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT)
                    .build());
    windowInPrimary->consumeKeyEvent(
            AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithDisplayId(ADISPLAY_ID_DEFAULT)));
    windowInSecondary->assertNoEvents();
    // Send a key down on second display
    mDispatcher->notifyKey(
            KeyArgsBuilder(AKEY_EVENT_ACTION_DOWN, AINPUT_SOURCE_KEYBOARD)
                    .displayId(SECOND_DISPLAY_ID)
                    .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT)
                    .build());
    windowInSecondary->consumeKeyEvent(
            AllOf(WithKeyAction(AKEY_EVENT_ACTION_DOWN), WithDisplayId(SECOND_DISPLAY_ID)));
    windowInPrimary->assertNoEvents();
    // Send a valid key up event on primary display that will be dropped because it is stale
    NotifyKeyArgs staleKeyUp =
            KeyArgsBuilder(AKEY_EVENT_ACTION_UP, AINPUT_SOURCE_KEYBOARD)
                    .displayId(ADISPLAY_ID_DEFAULT)
                    .policyFlags(DEFAULT_POLICY_FLAGS | POLICY_FLAG_DISABLE_KEY_REPEAT)
                    .build();
    static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms;
    mFakePolicy->setStaleEventTimeout(STALE_EVENT_TIMEOUT);
    std::this_thread::sleep_for(STALE_EVENT_TIMEOUT);
    mDispatcher->notifyKey(staleKeyUp);
    // Only the key gesture corresponding to the dropped event should receive the cancel event.
    // Therefore, windowInPrimary should get the cancel event and windowInSecondary should not
    // receive any events.
    windowInPrimary->consumeKeyEvent(AllOf(WithKeyAction(AKEY_EVENT_ACTION_UP),
                                           WithDisplayId(ADISPLAY_ID_DEFAULT),
                                           WithFlags(AKEY_EVENT_FLAG_CANCELED)));
    windowInSecondary->assertNoEvents();
}
/**
 * Similar to 'WhenDropKeyEvent_OnlyCancelCorrespondingKeyGesture' but for motion events.
 */
TEST_F(InputDispatcherFocusOnTwoDisplaysTest, WhenDropMotionEvent_OnlyCancelCorrespondingGesture) {
    // Send touch down on primary display.
    mDispatcher->notifyMotion(
            MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
                    .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200))
                    .displayId(ADISPLAY_ID_DEFAULT)
                    .build());
    windowInPrimary->consumeMotionEvent(
            AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(ADISPLAY_ID_DEFAULT)));
    windowInSecondary->assertNoEvents();
    // Send touch down on second display.
    mDispatcher->notifyMotion(
            MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
                    .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200))
                    .displayId(SECOND_DISPLAY_ID)
                    .build());
    windowInPrimary->assertNoEvents();
    windowInSecondary->consumeMotionEvent(
            AllOf(WithMotionAction(ACTION_DOWN), WithDisplayId(SECOND_DISPLAY_ID)));
    // inject a valid MotionEvent on primary display that will be stale when it arrives.
    NotifyMotionArgs staleMotionUp =
            MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN)
                    .displayId(ADISPLAY_ID_DEFAULT)
                    .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200))
                    .build();
    static constexpr std::chrono::duration STALE_EVENT_TIMEOUT = 10ms;
    mFakePolicy->setStaleEventTimeout(STALE_EVENT_TIMEOUT);
    std::this_thread::sleep_for(STALE_EVENT_TIMEOUT);
    mDispatcher->notifyMotion(staleMotionUp);
    // For stale motion events, we let the gesture to complete. This behaviour is different from key
    // events, where we would cancel the current keys instead.
    windowInPrimary->consumeMotionEvent(WithMotionAction(ACTION_UP));
    windowInSecondary->assertNoEvents();
}
class InputFilterTest : public InputDispatcherTest {
protected:
    void testNotifyMotion(int32_t displayId, bool expectToBeFiltered,
@@ -7654,8 +7743,7 @@ class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest {
                                              ADISPLAY_ID_DEFAULT);
        mWindow1->setFrame(Rect(0, 0, 100, 100));
        mWindow2 = sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window 2",
                                              ADISPLAY_ID_DEFAULT, mWindow1->getToken());
        mWindow2 = mWindow1->clone(ADISPLAY_ID_DEFAULT);
        mWindow2->setFrame(Rect(100, 100, 200, 200));
        mDispatcher->onWindowInfosChanged({{*mWindow1->getInfo(), *mWindow2->getInfo()}, {}, 0, 0});
@@ -8922,7 +9010,7 @@ class InputDispatcherMultiWindowOcclusionTests : public InputDispatcherTest {
        mNoInputWindow =
                sp<FakeWindowHandle>::make(mApplication, mDispatcher,
                                           "Window without input channel", ADISPLAY_ID_DEFAULT,
                                           /*token=*/std::make_optional<sp<IBinder>>(nullptr));
                                           /*createInputChannel=*/false);
        mNoInputWindow->setNoInputChannel(true);
        mNoInputWindow->setFrame(Rect(0, 0, 100, 100));
        // It's perfectly valid for this window to not have an associated input channel
@@ -8990,8 +9078,7 @@ protected:
        InputDispatcherTest::SetUp();
        mApp = std::make_shared<FakeApplicationHandle>();
        mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT);
        mMirror = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindowMirror",
                                             ADISPLAY_ID_DEFAULT, mWindow->getToken());
        mMirror = mWindow->clone(ADISPLAY_ID_DEFAULT);
        mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp);
        mWindow->setFocusable(true);
        mMirror->setFocusable(true);
Loading