1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_TESTS_MSGQ_V1_0_BENCHMARKMSGQ_H
18#define ANDROID_HARDWARE_TESTS_MSGQ_V1_0_BENCHMARKMSGQ_H
19
20#include <android/hardware/tests/msgq/1.0/IBenchmarkMsgQ.h>
21#include <hidl/MQDescriptor.h>
22#include <hidl/Status.h>
23#include <fmq/MessageQueue.h>
24
25namespace android {
26namespace hardware {
27namespace tests {
28namespace msgq {
29namespace V1_0 {
30namespace implementation {
31
32using ::android::hardware::tests::msgq::V1_0::IBenchmarkMsgQ;
33using ::android::hidl::base::V1_0::DebugInfo;
34using ::android::hidl::base::V1_0::IBase;
35using ::android::hardware::hidl_array;
36using ::android::hardware::hidl_memory;
37using ::android::hardware::hidl_string;
38using ::android::hardware::hidl_vec;
39using ::android::hardware::Return;
40using ::android::hardware::Void;
41using ::android::sp;
42
43using android::hardware::kSynchronizedReadWrite;
44using android::hardware::MQFlavor;
45
46struct BenchmarkMsgQ : public IBenchmarkMsgQ {
47    /*
48     * The various packet sizes used are as follows.
49     */
50    enum PacketSizes {
51        kPacketSize64 = 64,
52        kPacketSize128 = 128,
53        kPacketSize256 = 256,
54        kPacketSize512 = 512,
55        kPacketSize1024 = 1024
56    };
57    // Methods from ::android::hardware::tests::msgq::V1_0::IBenchmarkMsgQ follow.
58    Return<void> configureClientInboxSyncReadWrite(configureClientInboxSyncReadWrite_cb _hidl_cb) override;
59    Return<void> configureClientOutboxSyncReadWrite(configureClientOutboxSyncReadWrite_cb _hidl_cb) override;
60    Return<bool> requestWrite(int32_t count) override;
61    Return<bool> requestRead(int32_t count) override;
62    Return<void> benchmarkPingPong(uint32_t numIter) override;
63    Return<void> benchmarkServiceWriteClientRead(uint32_t numIter) override;
64    Return<void> sendTimeData(const hidl_vec<int64_t>& timeData) override;
65
66     /*
67     * This method writes numIter packets into the mFmqOutbox queue
68     * and notes the time before each write in the mTimeData array. It will
69     * be used to calculate the average server to client write to read delay.
70     */
71    template <MQFlavor flavor>
72    static void QueueWriter(android::hardware::MessageQueue<uint8_t, flavor>*
73                     mFmqOutbox, int64_t* mTimeData, uint32_t numIter);
74    /*
75     * The method reads a packet from the inbox queue and writes the same
76     * into the outbox queue. The client will calculate the average time taken
77     * for each iteration which consists of two write and two read operations.
78     */
79    template <MQFlavor flavor>
80    static void QueuePairReadWrite(
81            android::hardware::MessageQueue<uint8_t, flavor>* mFmqInbox,
82            android::hardware::MessageQueue<uint8_t, flavor>* mFmqOutbox,
83            uint32_t numIter);
84
85private:
86    android::hardware::MessageQueue<uint8_t, kSynchronizedReadWrite>* mFmqInbox;
87    android::hardware::MessageQueue<uint8_t, kSynchronizedReadWrite>* mFmqOutbox;
88    int64_t* mTimeData;
89};
90
91extern "C" IBenchmarkMsgQ* HIDL_FETCH_IBenchmarkMsgQ(const char* name);
92
93}  // namespace implementation
94}  // namespace V1_0
95}  // namespace msgq
96}  // namespace tests
97}  // namespace hardware
98}  // namespace android
99
100#endif  // ANDROID_HARDWARE_TESTS_MSGQ_V1_0_BENCHMARKMSGQ_H
101