Apollo 10.0
自动驾驶开放平台
apollo::cyber::scheduler 命名空间参考

class  ChoreographyContext
 
class  ClassicContext
 
class  CvWrapper
 
class  MutexWrapper
 
class  Processor
 
class  ProcessorContext
 
class  Scheduler
 
class  SchedulerChoreography
 
class  SchedulerClassic
 
struct  Snapshot
 

类型定义

using CROUTINE_QUEUE = std::vector< std::shared_ptr< CRoutine > >
 
using MULTI_PRIO_QUEUE = std::array< CROUTINE_QUEUE, MAX_PRIO >
 
using CR_GROUP = std::unordered_map< std::string, MULTI_PRIO_QUEUE >
 
using LOCK_QUEUE = std::array< base::AtomicRWLock, MAX_PRIO >
 
using RQ_LOCK_GROUP = std::unordered_map< std::string, LOCK_QUEUE >
 
using GRP_WQ_MUTEX = std::unordered_map< std::string, MutexWrapper >
 
using GRP_WQ_CV = std::unordered_map< std::string, CvWrapper >
 
using NOTIFY_GRP = std::unordered_map< std::string, int >
 

函数

void ParseCpuset (const std::string &str, std::vector< int > *cpuset)
 
void SetSchedAffinity (std::thread *thread, const std::vector< int > &cpus, const std::string &affinity, int cpu_id)
 
void SetSchedPolicy (std::thread *thread, std::string spolicy, int sched_priority, pid_t tid)
 
SchedulerInstance ()
 
void CleanUp ()
 

类型定义说明

◆ CR_GROUP

using apollo::cyber::scheduler::CR_GROUP = typedef std::unordered_map<std::string, MULTI_PRIO_QUEUE>

在文件 classic_context.h44 行定义.

◆ CROUTINE_QUEUE

using apollo::cyber::scheduler::CROUTINE_QUEUE = typedef std::vector<std::shared_ptr<CRoutine> >

在文件 classic_context.h42 行定义.

◆ GRP_WQ_CV

using apollo::cyber::scheduler::GRP_WQ_CV = typedef std::unordered_map<std::string, CvWrapper>

在文件 classic_context.h49 行定义.

◆ GRP_WQ_MUTEX

using apollo::cyber::scheduler::GRP_WQ_MUTEX = typedef std::unordered_map<std::string, MutexWrapper>

在文件 classic_context.h48 行定义.

◆ LOCK_QUEUE

using apollo::cyber::scheduler::LOCK_QUEUE = typedef std::array<base::AtomicRWLock, MAX_PRIO>

在文件 classic_context.h45 行定义.

◆ MULTI_PRIO_QUEUE

using apollo::cyber::scheduler::MULTI_PRIO_QUEUE = typedef std::array<CROUTINE_QUEUE, MAX_PRIO>

在文件 classic_context.h43 行定义.

◆ NOTIFY_GRP

using apollo::cyber::scheduler::NOTIFY_GRP = typedef std::unordered_map<std::string, int>

在文件 classic_context.h50 行定义.

◆ RQ_LOCK_GROUP

using apollo::cyber::scheduler::RQ_LOCK_GROUP = typedef std::unordered_map<std::string, LOCK_QUEUE>

在文件 classic_context.h46 行定义.

函数说明

◆ CleanUp()

void apollo::cyber::scheduler::CleanUp ( )

在文件 scheduler_factory.cc80 行定义.

80 {
81 Scheduler* obj = instance.load(std::memory_order_acquire);
82 if (obj != nullptr) {
83 obj->Shutdown();
84 }
85}

◆ Instance()

Scheduler * apollo::cyber::scheduler::Instance ( )

在文件 scheduler_factory.cc49 行定义.

49 {
50 Scheduler* obj = instance.load(std::memory_order_acquire);
51 if (obj == nullptr) {
52 std::lock_guard<std::mutex> lock(mutex);
53 obj = instance.load(std::memory_order_relaxed);
54 if (obj == nullptr) {
55 std::string policy("classic");
56 std::string conf("conf/");
57 conf.append(GlobalData::Instance()->ProcessGroup()).append(".conf");
58 auto cfg_file = GetAbsolutePath(WorkRoot(), conf);
60 if (PathExists(cfg_file) && GetProtoFromFile(cfg_file, &cfg)) {
61 policy = cfg.scheduler_conf().policy();
62 } else {
63 AWARN << "Scheduler conf named " << cfg_file
64 << " not found, use default.";
65 }
66 if (!policy.compare("classic")) {
67 obj = new SchedulerClassic();
68 } else if (!policy.compare("choreography")) {
69 obj = new SchedulerChoreography();
70 } else {
71 AWARN << "Invalid scheduler policy: " << policy;
72 obj = new SchedulerClassic();
73 }
74 instance.store(obj, std::memory_order_release);
75 }
76 }
77 return obj;
78}
#define AWARN
Definition log.h:43
optional SchedulerConf scheduler_conf

◆ ParseCpuset()

void apollo::cyber::scheduler::ParseCpuset ( const std::string &  str,
std::vector< int > *  cpuset 
)

在文件 pin_thread.cc26 行定义.

26 {
27 std::vector<std::string> lines;
28 std::stringstream ss(str);
29 std::string l;
30 while (getline(ss, l, ',')) {
31 lines.push_back(l);
32 }
33 for (auto line : lines) {
34 std::stringstream ss(line);
35 std::vector<std::string> range;
36 while (getline(ss, l, '-')) {
37 range.push_back(l);
38 }
39 if (range.size() == 1) {
40 cpuset->push_back(std::stoi(range[0]));
41 } else if (range.size() == 2) {
42 for (int i = std::stoi(range[0]), e = std::stoi(range[1]); i <= e; i++) {
43 cpuset->push_back(i);
44 }
45 } else {
46 ADEBUG << "Parsing cpuset format error.";
47 exit(0);
48 }
49 }
50}
#define ADEBUG
Definition log.h:41

◆ SetSchedAffinity()

void apollo::cyber::scheduler::SetSchedAffinity ( std::thread *  thread,
const std::vector< int > &  cpus,
const std::string &  affinity,
int  cpu_id 
)

在文件 pin_thread.cc52 行定义.

53 {
54 cpu_set_t set;
55 CPU_ZERO(&set);
56
57 if (cpus.size()) {
58 if (!affinity.compare("range")) {
59 for (const auto cpu : cpus) {
60 CPU_SET(cpu, &set);
61 }
62 pthread_setaffinity_np(thread->native_handle(), sizeof(set), &set);
63 AINFO << "thread " << thread->get_id() << " set range affinity";
64 } else if (!affinity.compare("1to1")) {
65 if (cpu_id == -1 || (uint32_t)cpu_id >= cpus.size()) {
66 return;
67 }
68 CPU_SET(cpus[cpu_id], &set);
69 pthread_setaffinity_np(thread->native_handle(), sizeof(set), &set);
70 AINFO << "thread " << thread->get_id() << " set 1to1 affinity";
71 }
72 }
73}
#define AINFO
Definition log.h:42

◆ SetSchedPolicy()

void apollo::cyber::scheduler::SetSchedPolicy ( std::thread *  thread,
std::string  spolicy,
int  sched_priority,
pid_t  tid 
)

在文件 pin_thread.cc75 行定义.

76 {
77 struct sched_param sp;
78 int policy;
79
80 memset(reinterpret_cast<void*>(&sp), 0, sizeof(sp));
81 sp.sched_priority = sched_priority;
82
83 if (!spolicy.compare("SCHED_FIFO")) {
84 policy = SCHED_FIFO;
85 pthread_setschedparam(thread->native_handle(), policy, &sp);
86 AINFO << "thread " << tid << " set sched_policy: " << spolicy;
87 } else if (!spolicy.compare("SCHED_RR")) {
88 policy = SCHED_RR;
89 pthread_setschedparam(thread->native_handle(), policy, &sp);
90 AINFO << "thread " << tid << " set sched_policy: " << spolicy;
91 } else if (!spolicy.compare("SCHED_OTHER")) {
92 setpriority(PRIO_PROCESS, tid, sched_priority);
93 AINFO << "thread " << tid << " set sched_policy: " << spolicy;
94 }
95}