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

Commit 97dd0d52 authored by Chris Manton's avatar Chris Manton
Browse files

legacy: Add osi::thread_scheduler

Allows a layer of indirection for handling OS specific
real time thread schedule operation.

Bug: 193830619
Tag: #refactor
Test: gd/cert/run

Change-Id: I7d4c03c0ba8a117a40d1dc02ead776fe3b87a674
parent 94e8ecb6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ cc_library_static {
        "src/socket_utils/socket_local_client.cc",
        "src/socket_utils/socket_local_server.cc",
        "src/thread.cc",
        "src/thread_scheduler.cc",
        "src/wakelock.cc",
    ],
    shared_libs: [
+20 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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

bool thread_scheduler_enable_real_time(pid_t pid);
bool thread_scheduler_get_priority_range(int& min, int& max);
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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 <sched.h>
#include <sys/types.h>

namespace {
constexpr int kRealTimeFifoSchedulingPriority = 1;
}  // namespace

bool thread_scheduler_enable_real_time(pid_t linux_tid) {
  struct sched_param rt_params = {.sched_priority =
                                      kRealTimeFifoSchedulingPriority};
  return sched_setscheduler(linux_tid, SCHED_FIFO, &rt_params) == 0;
}

bool thread_scheduler_get_priority_range(int& min, int& max) {
  min = sched_get_priority_min(SCHED_FIFO);
  max = sched_get_priority_max(SCHED_FIFO);
  return (min != -1 && max != -1) ? true : false;
}
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

/*
 * Generated mock file from original source file
 *   Functions generated:2
 *
 *  mockcify.pl ver 0.3.0
 */

#include <cstdint>
#include <functional>
#include <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;

// Mock include file to share data between tests and mock
#include "test/mock/mock_osi_thread_scheduler.h"

// Mocked internal structures, if any

namespace test {
namespace mock {
namespace osi_thread_scheduler {

// Function state capture and return values, if needed
struct thread_scheduler_enable_real_time thread_scheduler_enable_real_time;
struct thread_scheduler_get_priority_range thread_scheduler_get_priority_range;

}  // namespace osi_thread_scheduler
}  // namespace mock
}  // namespace test

// Mocked functions, if any
bool thread_scheduler_enable_real_time(pid_t linux_tid) {
  mock_function_count_map[__func__]++;
  return test::mock::osi_thread_scheduler::thread_scheduler_enable_real_time(
      linux_tid);
}
bool thread_scheduler_get_priority_range(int& min, int& max) {
  mock_function_count_map[__func__]++;
  return test::mock::osi_thread_scheduler::thread_scheduler_get_priority_range(
      min, max);
}
// Mocked functions complete
// END mockcify generation
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

/*
 * Generated mock file from original source file
 *   Functions generated:2
 *
 *  mockcify.pl ver 0.3.0
 */

#include <cstdint>
#include <functional>
#include <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;

// Original included files, if any
// NOTE: Since this is a mock file with mock definitions some number of
//       include files may not be required.  The include-what-you-use
//       still applies, but crafting proper inclusion is out of scope
//       for this effort.  This compilation unit may compile as-is, or
//       may need attention to prune from (or add to ) the inclusion set.

// Mocked compile conditionals, if any

namespace test {
namespace mock {
namespace osi_thread_scheduler {

// Shared state between mocked functions and tests
// Name: osi_enable_real_time_scheduling
// Params: pid_t linux_tid
// Return: bool
struct thread_scheduler_enable_real_time {
  bool return_value{false};
  std::function<bool(pid_t linux_tid)> body{
      [this](pid_t linux_tid) { return return_value; }};
  bool operator()(pid_t linux_tid) { return body(linux_tid); };
};
extern struct thread_scheduler_enable_real_time
    thread_scheduler_enable_real_time;

// Name: osi_fifo_scheduing_priority_range
// Params: int& min, int& max
// Return: bool
struct thread_scheduler_get_priority_range {
  bool return_value{false};
  std::function<bool(int& min, int& max)> body{
      [this](int& min, int& max) { return return_value; }};
  bool operator()(int& min, int& max) { return body(min, max); };
};
extern struct thread_scheduler_get_priority_range
    thread_scheduler_get_priority_range;

}  // namespace osi_thread_scheduler
}  // namespace mock
}  // namespace test

// END mockcify generation