aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Balsini <balsini@google.com>2023-10-13 21:59:38 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-13 21:59:38 +0000
commit5c0a6a391a6b097e573fdb64e8253e5a7c2f428f (patch)
tree54c081dc6b853fdd67e1eb4cd13db347a63cda2d
parentbe36c5e83cee1a259d6e0f017d73c5ab46c5f734 (diff)
parente084b6908d786a36da8a14f5a83038e37d2f9823 (diff)
downloaddittosuite-5c0a6a391a6b097e573fdb64e8253e5a7c2f428f.tar.gz
Introduce CPU work instruction am: 9ebb005bfd am: 82af41ca87 am: 940e1a844d am: e084b6908d
Original change: https://android-review.googlesource.com/c/platform/test/dittosuite/+/2786580 Change-Id: Idde0db4f481b2c25a5d5da8fd547a5e687fdeffc Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--example/cpu_workload.ditto29
-rw-r--r--include/ditto/cpu_work.h55
-rw-r--r--schema/benchmark.proto8
-rw-r--r--src/cpu_work.cpp61
-rw-r--r--src/instruction_factory.cpp20
5 files changed, 173 insertions, 0 deletions
diff --git a/example/cpu_workload.ditto b/example/cpu_workload.ditto
new file mode 100644
index 0000000..d55caa9
--- /dev/null
+++ b/example/cpu_workload.ditto
@@ -0,0 +1,29 @@
+main: {
+ multithreading: {
+ threads: [
+ {
+ name: "Cycles"
+ instruction: {
+ cpu_work: {
+ cycles: 1000000
+ }
+ repeat: 100,
+ period_us: 40000
+ },
+ spawn: 2
+ },
+ {
+ name: "Util"
+ instruction: {
+ cpu_work: {
+ utilization: 0.3,
+ }
+ repeat: 100,
+ period_us: 50000
+ },
+ spawn: 2
+ }
+ ]
+ }
+}
+global: {}
diff --git a/include/ditto/cpu_work.h b/include/ditto/cpu_work.h
new file mode 100644
index 0000000..79c4931
--- /dev/null
+++ b/include/ditto/cpu_work.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma once
+
+#include <ditto/instruction.h>
+
+namespace dittosuite {
+
+class CpuWork : public Instruction {
+ public:
+ inline static const std::string kName;
+
+ explicit CpuWork(const std::string &name, const Params& params);
+
+ private:
+ virtual void RunSingle() = 0;
+};
+
+class CpuWorkCycles : public CpuWork {
+ public:
+ inline static const std::string kName = "cpu_work_cycles";
+
+ explicit CpuWorkCycles(const Params& params, uint64_t cycles);
+
+ private:
+ uint64_t cycles_;
+
+ void RunSingle() override;
+};
+
+class CpuWorkUtilization : public CpuWork {
+ public:
+ inline static const std::string kName = "cpu_work_utilization";
+
+ explicit CpuWorkUtilization(const Params& params, double utilization);
+
+ private:
+ double utilization_;
+
+ void RunSingle() override;
+};
+
+} // namespace dittosuite
diff --git a/schema/benchmark.proto b/schema/benchmark.proto
index 0228a4a..fd2488c 100644
--- a/schema/benchmark.proto
+++ b/schema/benchmark.proto
@@ -19,6 +19,13 @@ enum AccessMode {
READ_WRITE = 3;
}
+message CpuWork {
+ oneof type {
+ uint64 cycles = 1;
+ double utilization = 2;
+ }
+}
+
message BinderService {
optional string name = 1;
optional uint32 threads = 2;
@@ -131,6 +138,7 @@ message Instruction {
InvalidateCache invalidate_cache = 12;
BinderRequest binder_request = 13;
BinderService binder_service = 14;
+ CpuWork cpu_work = 16;
};
optional uint64 period_us = 15 [default = 0];
}
diff --git a/src/cpu_work.cpp b/src/cpu_work.cpp
new file mode 100644
index 0000000..5c34abd
--- /dev/null
+++ b/src/cpu_work.cpp
@@ -0,0 +1,61 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <ditto/cpu_work.h>
+
+#include <ditto/logger.h>
+
+namespace dittosuite {
+
+CpuWork::CpuWork(const std::string& name, const Params& params) : Instruction(name, params) {}
+
+CpuWorkUtilization::CpuWorkUtilization(const Params& params, double utilization)
+ : CpuWork(kName, params), utilization_(utilization) {
+ if (utilization < 0 || utilization > 1) {
+ LOGF("Utilization value must be in the range [0,1]");
+ }
+ if (params.period_us_ <= 0) {
+ LOGF("The period of the instruction must be greater than 0");
+ }
+}
+
+void CpuWorkUtilization::RunSingle() {
+ timespec time_now, time_end, work_time;
+ work_time = MicrosToTimespec(period_us_ * utilization_);
+
+ if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time_now)) {
+ LOGF("Error getting current time");
+ }
+
+ time_end = time_now + work_time;
+
+ do {
+ if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time_now)) {
+ LOGF("Error getting current time");
+ }
+ } while (time_now < time_end);
+}
+
+CpuWorkCycles::CpuWorkCycles(const Params& params, uint64_t cycles)
+ : CpuWork(kName, params), cycles_(cycles) {}
+
+void CpuWorkCycles::RunSingle() {
+ volatile int target = -1;
+
+ for (uint64_t counter = 0; counter < cycles_; ++counter) {
+ target = ~target;
+ }
+}
+
+} // namespace dittosuite
diff --git a/src/instruction_factory.cpp b/src/instruction_factory.cpp
index 3126d1c..456bead 100644
--- a/src/instruction_factory.cpp
+++ b/src/instruction_factory.cpp
@@ -22,6 +22,7 @@
#include <ditto/binder_request.h>
#include <ditto/binder_service.h>
#include <ditto/close_file.h>
+#include <ditto/cpu_work.h>
#include <ditto/delete_file.h>
#include <ditto/instruction_set.h>
#include <ditto/invalidate_cache.h>
@@ -38,6 +39,7 @@
namespace dittosuite {
typedef dittosuiteproto::Instruction::InstructionOneofCase InstructionType;
typedef dittosuiteproto::BinderRequest::ServiceOneofCase RequestService;
+typedef dittosuiteproto::CpuWork::TypeCase CpuWorkType;
std::unique_ptr<InstructionSet> InstructionFactory::CreateFromProtoInstructionSet(
const dittosuite::Instruction::Params& instruction_params, const std::list<int>& thread_ids,
@@ -251,6 +253,24 @@ std::unique_ptr<Instruction> InstructionFactory::CreateFromProtoInstruction(
return std::make_unique<BinderService>(instruction_params, options.name(), options.threads());
}
#endif /*__ANDROID__*/
+ case InstructionType::kCpuWork: {
+ const auto& options = proto_instruction.cpu_work();
+
+ switch (options.type_case()) {
+ case CpuWorkType::kCycles: {
+ return std::make_unique<CpuWorkCycles>(instruction_params, options.cycles());
+ break;
+ }
+ case CpuWorkType::kUtilization: {
+ return std::make_unique<CpuWorkUtilization>(instruction_params, options.utilization());
+ break;
+ }
+ case CpuWorkType::TYPE_NOT_SET: {
+ LOGF("No type specified for CpuWorkload");
+ break;
+ }
+ }
+ }
case InstructionType::INSTRUCTION_ONEOF_NOT_SET: {
LOGF("Instruction was not set in .ditto file");
}