From 7b4e122027eac90ba76da2eb6a4703a3f76813c4 Mon Sep 17 00:00:00 2001 From: Alessio Balsini Date: Mon, 4 Mar 2024 14:18:02 +0000 Subject: Move SchedAttr__ to syscall As part of a refactoring required to implement functions not yet available in the libraries provided by Kleaf's sysroot, move the data structure that mimicks sched_attr in sched/types.h into the syscall-related code. Test: build Bug: 322744630 Change-Id: I05ca8ffb2ef36b29708dfc0340635fb2c2162037 Signed-off-by: Alessio Balsini --- include/ditto/multithreading_utils.h | 18 +----------------- include/ditto/syscall.h | 17 +++++++++++++++++ src/multithreading_utils.cpp | 15 --------------- src/syscall.cpp | 11 +++++++++++ 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/include/ditto/multithreading_utils.h b/include/ditto/multithreading_utils.h index b1ca472..b8295be 100644 --- a/include/ditto/multithreading_utils.h +++ b/include/ditto/multithreading_utils.h @@ -21,6 +21,7 @@ #endif #include +#include #include #include @@ -37,23 +38,6 @@ enum SchedPolicy { SchedDeadline = 6, }; -struct SchedAttr__ { - uint32_t size; /* Size of this structure */ - uint32_t sched_policy; /* Policy (SCHED_*) */ - uint64_t sched_flags; /* Flags */ - - int32_t sched_nice; /* Nice value (SCHED_OTHER, - SCHED_BATCH) */ - uint32_t sched_priority; /* Static priority (SCHED_FIFO, - SCHED_RR) */ - /* Remaining fields are for SCHED_DEADLINE */ - uint64_t sched_runtime; - uint64_t sched_deadline; - uint64_t sched_period; -}; - -std::string to_string(const SchedAttr__& attr); - class SchedAttr { bool initialized_ = false; SchedAttr__ sched_attr_; diff --git a/include/ditto/syscall.h b/include/ditto/syscall.h index c7e3af8..e51cc95 100644 --- a/include/ditto/syscall.h +++ b/include/ditto/syscall.h @@ -25,6 +25,23 @@ namespace dittosuite { +struct SchedAttr__ { + uint32_t size; /* Size of this structure */ + uint32_t sched_policy; /* Policy (SCHED_*) */ + uint64_t sched_flags; /* Flags */ + + int32_t sched_nice; /* Nice value (SCHED_OTHER, + SCHED_BATCH) */ + uint32_t sched_priority; /* Static priority (SCHED_FIFO, + SCHED_RR) */ + /* Remaining fields are for SCHED_DEADLINE */ + uint64_t sched_runtime; + uint64_t sched_deadline; + uint64_t sched_period; +}; + +std::string to_string(const SchedAttr__& attr); + class SyscallInterface { public: virtual ~SyscallInterface() {} diff --git a/src/multithreading_utils.cpp b/src/multithreading_utils.cpp index 9b9716f..b3355d6 100644 --- a/src/multithreading_utils.cpp +++ b/src/multithreading_utils.cpp @@ -19,21 +19,6 @@ namespace dittosuite { -std::string to_string(const SchedAttr__& attr) { - std::string ret; - - ret += "size: " + std::to_string(attr.size); - ret += ", policy: " + std::to_string(attr.sched_policy); - ret += ", flags: " + std::to_string(attr.sched_flags); - ret += ", nice: " + std::to_string(attr.sched_nice); - ret += ", priority: " + std::to_string(attr.sched_priority); - ret += ", runtime: " + std::to_string(attr.sched_runtime); - ret += ", deadline: " + std::to_string(attr.sched_deadline); - ret += ", period: " + std::to_string(attr.sched_period); - - return ret; -} - bool SchedAttr::IsSet() const { return initialized_; } void SchedAttr::Set() const { diff --git a/src/syscall.cpp b/src/syscall.cpp index 83e6cee..13d81e0 100644 --- a/src/syscall.cpp +++ b/src/syscall.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include namespace dittosuite { @@ -85,4 +87,13 @@ int64_t Syscall::Write(int fd, char* buf, int64_t count, int64_t offset) { return pwrite64(fd, buf, count, offset); } +std::string to_string(const SchedAttr__& attr) { + std::stringstream ss; + ss << "size: " << attr.size << ", policy: " << attr.sched_policy + << ", flags: " << attr.sched_flags << ", nice: " << attr.sched_nice + << ", priority: " << attr.sched_priority << ", runtime: " << attr.sched_runtime + << ", deadline: " << attr.sched_deadline << ", period: " << attr.sched_period; + return ss.str(); +} + } // namespace dittosuite -- cgit v1.2.3