Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
f0cdf6a8
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f0cdf6a8
编写于
11月 23, 2018
作者:
Z
zaxon
提交者:
Jiangtao Hu
12月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
framework: code clean in sched (#1943)
上级
ff6b235f
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
82 addition
and
60 deletion
+82
-60
cyber/scheduler/policy/choreography.cc
cyber/scheduler/policy/choreography.cc
+5
-4
cyber/scheduler/policy/choreography.h
cyber/scheduler/policy/choreography.h
+6
-3
cyber/scheduler/policy/classic.cc
cyber/scheduler/policy/classic.cc
+5
-3
cyber/scheduler/policy/classic.h
cyber/scheduler/policy/classic.h
+8
-3
cyber/scheduler/policy/scheduler_choreography.cc
cyber/scheduler/policy/scheduler_choreography.cc
+3
-2
cyber/scheduler/policy/scheduler_choreography.h
cyber/scheduler/policy/scheduler_choreography.h
+12
-4
cyber/scheduler/policy/scheduler_classic.cc
cyber/scheduler/policy/scheduler_classic.cc
+5
-4
cyber/scheduler/policy/scheduler_classic.h
cyber/scheduler/policy/scheduler_classic.h
+5
-0
cyber/scheduler/processor.h
cyber/scheduler/processor.h
+6
-3
cyber/scheduler/processor_context.cc
cyber/scheduler/processor_context.cc
+1
-5
cyber/scheduler/processor_context.h
cyber/scheduler/processor_context.h
+8
-13
cyber/scheduler/scheduler.cc
cyber/scheduler/scheduler.cc
+18
-14
cyber/scheduler/scheduler.h
cyber/scheduler/scheduler.h
+0
-2
未找到文件。
cyber/scheduler/policy/choreography.cc
浏览文件 @
f0cdf6a8
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include <vector>
#include <vector>
#include "cyber/common/types.h"
#include "cyber/common/types.h"
#include "cyber/croutine/croutine.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/scheduler/processor.h"
#include "cyber/scheduler/processor.h"
#include "cyber/scheduler/scheduler.h"
#include "cyber/scheduler/scheduler.h"
...
@@ -30,9 +29,9 @@ namespace apollo {
...
@@ -30,9 +29,9 @@ namespace apollo {
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
RoutineState
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
croutine
::
RoutineState
;
std
::
shared_ptr
<
CRoutine
>
ChoreographyContext
::
NextRoutine
()
{
std
::
shared_ptr
<
CRoutine
>
ChoreographyContext
::
NextRoutine
()
{
if
(
unlikely
(
stop_
))
{
if
(
unlikely
(
stop_
))
{
...
@@ -51,11 +50,14 @@ std::shared_ptr<CRoutine> ChoreographyContext::NextRoutine() {
...
@@ -51,11 +50,14 @@ std::shared_ptr<CRoutine> ChoreographyContext::NextRoutine() {
it
=
cr_queue_
.
erase
(
it
);
it
=
cr_queue_
.
erase
(
it
);
continue
;
continue
;
}
}
if
(
cr
->
UpdateState
()
==
RoutineState
::
READY
)
{
if
(
cr
->
UpdateState
()
==
RoutineState
::
READY
)
{
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
NEXT_RT
,
cr
->
id
(),
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
NEXT_RT
,
cr
->
id
(),
cr
->
processor_id
());
cr
->
processor_id
());
return
cr
;
return
cr
;
}
}
cr
->
Release
();
cr
->
Release
();
++
it
;
++
it
;
}
}
...
@@ -67,7 +69,6 @@ std::shared_ptr<CRoutine> ChoreographyContext::NextRoutine() {
...
@@ -67,7 +69,6 @@ std::shared_ptr<CRoutine> ChoreographyContext::NextRoutine() {
bool
ChoreographyContext
::
Enqueue
(
const
std
::
shared_ptr
<
CRoutine
>
cr
)
{
bool
ChoreographyContext
::
Enqueue
(
const
std
::
shared_ptr
<
CRoutine
>
cr
)
{
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
RT_CREATE
,
cr
->
id
(),
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
RT_CREATE
,
cr
->
id
(),
cr
->
processor_id
());
cr
->
processor_id
());
std
::
lock_guard
<
std
::
mutex
>
lk
(
mtx_cr_queue_
);
std
::
lock_guard
<
std
::
mutex
>
lk
(
mtx_cr_queue_
);
cr_queue_
.
insert
(
cr_queue_
.
insert
(
std
::
pair
<
uint32_t
,
std
::
shared_ptr
<
CRoutine
>>
(
cr
->
priority
(),
cr
));
std
::
pair
<
uint32_t
,
std
::
shared_ptr
<
CRoutine
>>
(
cr
->
priority
(),
cr
));
...
...
cyber/scheduler/policy/choreography.h
浏览文件 @
f0cdf6a8
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
* limitations under the License.
* limitations under the License.
*****************************************************************************/
*****************************************************************************/
#ifndef CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_H_
#ifndef CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_
CONTEXT_
H_
#define CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_H_
#define CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_
CONTEXT_
H_
#include <functional>
#include <functional>
#include <map>
#include <map>
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
#include "cyber/base/atomic_rw_lock.h"
#include "cyber/croutine/croutine.h"
#include "cyber/scheduler/processor_context.h"
#include "cyber/scheduler/processor_context.h"
namespace
apollo
{
namespace
apollo
{
...
@@ -39,6 +41,7 @@ class ChoreographyContext : public ProcessorContext {
...
@@ -39,6 +41,7 @@ class ChoreographyContext : public ProcessorContext {
public:
public:
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
override
;
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
override
;
void
Wait
()
override
;
void
Wait
()
override
;
bool
Enqueue
(
const
std
::
shared_ptr
<
CRoutine
>
);
bool
Enqueue
(
const
std
::
shared_ptr
<
CRoutine
>
);
void
Notify
();
void
Notify
();
...
@@ -55,4 +58,4 @@ class ChoreographyContext : public ProcessorContext {
...
@@ -55,4 +58,4 @@ class ChoreographyContext : public ProcessorContext {
}
// namespace cyber
}
// namespace cyber
}
// namespace apollo
}
// namespace apollo
#endif // CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_H_
#endif // CYBER_SCHEDULER_POLICY_CHOREOGRAPHY_
CONTEXT_
H_
cyber/scheduler/policy/classic.cc
浏览文件 @
f0cdf6a8
...
@@ -17,13 +17,12 @@
...
@@ -17,13 +17,12 @@
#include "cyber/scheduler/policy/classic.h"
#include "cyber/scheduler/policy/classic.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/scheduler/policy/scheduler_classic.h"
#include "cyber/scheduler/processor.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
RoutineState
;
using
apollo
::
cyber
::
base
::
ReadLockGuard
;
using
apollo
::
cyber
::
base
::
ReadLockGuard
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
...
@@ -43,11 +42,14 @@ std::shared_ptr<CRoutine> ClassicContext::NextRoutine() {
...
@@ -43,11 +42,14 @@ std::shared_ptr<CRoutine> ClassicContext::NextRoutine() {
ReadLockGuard
<
AtomicRWLock
>
lk
(
rq_locks_
[
i
]);
ReadLockGuard
<
AtomicRWLock
>
lk
(
rq_locks_
[
i
]);
for
(
auto
it
=
rq_
[
i
].
begin
();
it
!=
rq_
[
i
].
end
();
++
it
)
{
for
(
auto
it
=
rq_
[
i
].
begin
();
it
!=
rq_
[
i
].
end
();
++
it
)
{
auto
cr
=
(
*
it
);
auto
cr
=
(
*
it
);
if
(
!
cr
->
Acquire
())
{
if
(
!
cr
->
Acquire
())
{
continue
;
continue
;
}
}
if
(
cr
->
UpdateState
()
==
RoutineState
::
READY
)
{
if
(
cr
->
UpdateState
()
==
RoutineState
::
READY
)
{
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
NEXT_RT
,
cr
->
id
(),
PerfEventCache
::
Instance
()
->
AddSchedEvent
(
SchedPerf
::
NEXT_RT
,
cr
->
id
(),
cr
->
processor_id
());
cr
->
processor_id
());
return
cr
;
return
cr
;
}
}
...
...
cyber/scheduler/policy/classic.h
浏览文件 @
f0cdf6a8
...
@@ -14,20 +14,24 @@
...
@@ -14,20 +14,24 @@
* limitations under the License.
* limitations under the License.
*****************************************************************************/
*****************************************************************************/
#ifndef CYBER_SCHEDULER_POLICY_CLASSIC_H_
#ifndef CYBER_SCHEDULER_POLICY_CLASSIC_
CONTEXT_
H_
#define CYBER_SCHEDULER_POLICY_CLASSIC_H_
#define CYBER_SCHEDULER_POLICY_CLASSIC_
CONTEXT_
H_
#include <array>
#include <array>
#include <functional>
#include <functional>
#include <memory>
#include <memory>
#include <mutex>
#include <vector>
#include <vector>
#include "cyber/base/atomic_rw_lock.h"
#include "cyber/croutine/croutine.h"
#include "cyber/scheduler/processor_context.h"
#include "cyber/scheduler/processor_context.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
base
::
AtomicRWLock
;
using
croutine
::
CRoutine
;
using
croutine
::
CRoutine
;
#define MAX_PRIO 20
#define MAX_PRIO 20
...
@@ -36,6 +40,7 @@ class ClassicContext : public ProcessorContext {
...
@@ -36,6 +40,7 @@ class ClassicContext : public ProcessorContext {
public:
public:
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
override
;
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
override
;
void
Wait
()
override
;
void
Wait
()
override
;
static
void
Notify
();
static
void
Notify
();
alignas
(
CACHELINE_SIZE
)
static
std
::
mutex
mtx_wq_
;
alignas
(
CACHELINE_SIZE
)
static
std
::
mutex
mtx_wq_
;
...
@@ -50,4 +55,4 @@ class ClassicContext : public ProcessorContext {
...
@@ -50,4 +55,4 @@ class ClassicContext : public ProcessorContext {
}
// namespace cyber
}
// namespace cyber
}
// namespace apollo
}
// namespace apollo
#endif // CYBER_SCHEDULER_POLICY_CLASSIC_H_
#endif // CYBER_SCHEDULER_POLICY_CLASSIC_
CONTEXT_
H_
cyber/scheduler/policy/scheduler_choreography.cc
浏览文件 @
f0cdf6a8
...
@@ -30,13 +30,14 @@ namespace apollo {
...
@@ -30,13 +30,14 @@ namespace apollo {
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
RoutineState
;
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
SchedulerChoreography
::
SchedulerChoreography
()
{
SchedulerChoreography
::
SchedulerChoreography
()
{
// get sched config
// get sched config
...
...
cyber/scheduler/policy/scheduler_choreography.h
浏览文件 @
f0cdf6a8
...
@@ -22,22 +22,27 @@
...
@@ -22,22 +22,27 @@
#include <unordered_map>
#include <unordered_map>
#include <vector>
#include <vector>
#include "cyber/croutine/croutine.h"
#include "cyber/proto/choreography_conf.pb.h"
#include "cyber/scheduler/scheduler.h"
#include "cyber/scheduler/scheduler.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
CRoutine
;
using
apollo
::
cyber
::
proto
::
ChoreographyTask
;
using
apollo
::
cyber
::
proto
::
ChoreographyTask
;
using
apollo
::
cyber
::
proto
::
InnerThread
;
using
apollo
::
cyber
::
proto
::
InnerThread
;
class
SchedulerChoreography
:
public
Scheduler
{
class
SchedulerChoreography
:
public
Scheduler
{
public:
public:
SchedulerChoreography
();
SchedulerChoreography
();
void
SetInnerThreadAttr
(
const
std
::
thread
*
thr
,
void
SetInnerThreadAttr
(
const
std
::
thread
*
thr
,
const
std
::
string
&
name
)
override
;
const
std
::
string
&
name
)
override
;
bool
RemoveTask
(
const
std
::
string
&
name
)
override
;
bool
RemoveTask
(
const
std
::
string
&
name
)
override
;
private:
private:
void
CreateProcessor
();
void
CreateProcessor
();
bool
DispatchTask
(
const
std
::
shared_ptr
<
CRoutine
>
)
override
;
bool
DispatchTask
(
const
std
::
shared_ptr
<
CRoutine
>
)
override
;
...
@@ -46,14 +51,17 @@ class SchedulerChoreography : public Scheduler {
...
@@ -46,14 +51,17 @@ class SchedulerChoreography : public Scheduler {
std
::
unordered_map
<
std
::
string
,
ChoreographyTask
>
cr_confs_
;
std
::
unordered_map
<
std
::
string
,
ChoreographyTask
>
cr_confs_
;
std
::
unordered_map
<
std
::
string
,
InnerThread
>
inner_thr_confs_
;
std
::
unordered_map
<
std
::
string
,
InnerThread
>
inner_thr_confs_
;
int32_t
choreography_processor_prio_
;
int32_t
pool_processor_prio_
;
std
::
string
choreography_affinity_
;
std
::
string
choreography_affinity_
;
std
::
string
pool_affinity_
;
std
::
string
choreography_processor_policy_
;
std
::
string
choreography_processor_policy_
;
int32_t
choreography_processor_prio_
;
std
::
string
pool_processor_policy_
;
std
::
vector
<
int
>
choreography_cpuset_
;
std
::
vector
<
int
>
choreography_cpuset_
;
std
::
string
pool_affinity_
;
std
::
vector
<
int
>
pool_cpuset_
;
std
::
vector
<
int
>
pool_cpuset_
;
std
::
string
pool_processor_policy_
;
int32_t
pool_processor_prio_
;
};
};
}
// namespace scheduler
}
// namespace scheduler
...
...
cyber/scheduler/policy/scheduler_classic.cc
浏览文件 @
f0cdf6a8
...
@@ -18,25 +18,26 @@
...
@@ -18,25 +18,26 @@
#include <memory>
#include <memory>
#include "cyber/event/perf_event_cache.h"
#include "cyber/common/environment.h"
#include "cyber/common/environment.h"
#include "cyber/common/file.h"
#include "cyber/common/file.h"
#include "cyber/
scheduler/processor
.h"
#include "cyber/
event/perf_event_cache
.h"
#include "cyber/scheduler/policy/classic.h"
#include "cyber/scheduler/policy/classic.h"
#include "cyber/scheduler/processor.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
RoutineState
;
using
apollo
::
cyber
::
base
::
ReadLockGuard
;
using
apollo
::
cyber
::
base
::
ReadLockGuard
;
using
apollo
::
cyber
::
base
::
WriteLockGuard
;
using
apollo
::
cyber
::
base
::
WriteLockGuard
;
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
SchedulerClassic
::
SchedulerClassic
()
{
SchedulerClassic
::
SchedulerClassic
()
{
// get sched config
// get sched config
...
...
cyber/scheduler/policy/scheduler_classic.h
浏览文件 @
f0cdf6a8
...
@@ -22,17 +22,21 @@
...
@@ -22,17 +22,21 @@
#include <vector>
#include <vector>
#include <map>
#include <map>
#include "cyber/croutine/croutine.h"
#include "cyber/proto/classic_conf.pb.h"
#include "cyber/scheduler/scheduler.h"
#include "cyber/scheduler/scheduler.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
croutine
::
CRoutine
;
using
apollo
::
cyber
::
proto
::
ClassicTask
;
using
apollo
::
cyber
::
proto
::
ClassicTask
;
class
SchedulerClassic
:
public
Scheduler
{
class
SchedulerClassic
:
public
Scheduler
{
public:
public:
SchedulerClassic
();
SchedulerClassic
();
bool
RemoveTask
(
const
std
::
string
&
name
)
override
;
bool
RemoveTask
(
const
std
::
string
&
name
)
override
;
void
SetInnerThreadAttr
(
const
std
::
thread
*
thr
,
void
SetInnerThreadAttr
(
const
std
::
thread
*
thr
,
...
@@ -42,6 +46,7 @@ class SchedulerClassic : public Scheduler {
...
@@ -42,6 +46,7 @@ class SchedulerClassic : public Scheduler {
void
CreateProcessor
();
void
CreateProcessor
();
bool
DispatchTask
(
const
std
::
shared_ptr
<
CRoutine
>
)
override
;
bool
DispatchTask
(
const
std
::
shared_ptr
<
CRoutine
>
)
override
;
bool
NotifyProcessor
(
uint64_t
crid
)
override
;
bool
NotifyProcessor
(
uint64_t
crid
)
override
;
std
::
map
<
std
::
string
,
ClassicTask
>
cr_tasks
;
std
::
map
<
std
::
string
,
ClassicTask
>
cr_tasks
;
std
::
string
affinity_
;
std
::
string
affinity_
;
...
...
cyber/scheduler/processor.h
浏览文件 @
f0cdf6a8
...
@@ -47,17 +47,20 @@ class Processor {
...
@@ -47,17 +47,20 @@ class Processor {
void
SetAffinity
(
const
std
::
vector
<
int
>&
,
const
std
::
string
&
,
int
);
void
SetAffinity
(
const
std
::
vector
<
int
>&
,
const
std
::
string
&
,
int
);
void
SetSchedPolicy
(
std
::
string
spolicy
,
int
sched_priority
);
void
SetSchedPolicy
(
std
::
string
spolicy
,
int
sched_priority
);
void
Stop
()
{
running_
.
exchange
(
false
);
}
void
Stop
()
{
running_
.
exchange
(
false
);
}
void
BindContext
(
const
std
::
shared_ptr
<
ProcessorContext
>&
context
)
{
void
BindContext
(
const
std
::
shared_ptr
<
ProcessorContext
>&
context
)
{
context_
=
context
;
context_
=
context
;
}
}
private:
private:
std
::
thread
thread_
;
std
::
shared_ptr
<
ProcessorContext
>
context_
;
std
::
shared_ptr
<
ProcessorContext
>
context_
;
std
::
shared_ptr
<
RoutineContext
>
routine_context_
=
nullptr
;
std
::
shared_ptr
<
RoutineContext
>
routine_context_
=
nullptr
;
std
::
atomic
<
bool
>
running_
{
false
};
std
::
mutex
mtx_ctx_
;
std
::
condition_variable
cv_ctx_
;
std
::
condition_variable
cv_ctx_
;
std
::
mutex
mtx_ctx_
;
std
::
thread
thread_
;
std
::
atomic
<
bool
>
running_
{
false
};
std
::
atomic
<
pid_t
>
tid_
{
-
1
};
std
::
atomic
<
pid_t
>
tid_
{
-
1
};
};
};
...
...
cyber/scheduler/processor_context.cc
浏览文件 @
f0cdf6a8
...
@@ -16,11 +16,6 @@
...
@@ -16,11 +16,6 @@
#include "cyber/scheduler/processor_context.h"
#include "cyber/scheduler/processor_context.h"
#include "cyber/common/log.h"
#include "cyber/common/types.h"
#include "cyber/croutine/croutine.h"
#include "cyber/scheduler/processor.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
...
@@ -29,6 +24,7 @@ void ProcessorContext::ShutDown() {
...
@@ -29,6 +24,7 @@ void ProcessorContext::ShutDown() {
if
(
!
stop_
)
{
if
(
!
stop_
)
{
stop_
=
true
;
stop_
=
true
;
}
}
processor_
->
Stop
();
processor_
->
Stop
();
}
}
...
...
cyber/scheduler/processor_context.h
浏览文件 @
f0cdf6a8
...
@@ -17,47 +17,42 @@
...
@@ -17,47 +17,42 @@
#ifndef CYBER_SCHEDULER_POLICY_PROCESSOR_CONTEXT_H_
#ifndef CYBER_SCHEDULER_POLICY_PROCESSOR_CONTEXT_H_
#define CYBER_SCHEDULER_POLICY_PROCESSOR_CONTEXT_H_
#define CYBER_SCHEDULER_POLICY_PROCESSOR_CONTEXT_H_
#include <future>
#include <limits>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <memory>
#include <mutex>
#include <mutex>
#include <unordered_map>
#include <vector>
#include "cyber/base/atomic_hash_map.h"
#include "cyber/base/atomic_rw_lock.h"
#include "cyber/base/macros.h"
#include "cyber/base/macros.h"
#include "cyber/croutine/croutine.h"
#include "cyber/croutine/croutine.h"
#include "cyber/scheduler/processor.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
base
::
AtomicRWLock
;
using
croutine
::
CRoutine
;
using
croutine
::
CRoutine
;
using
croutine
::
RoutineState
;
class
Processor
;
class
Processor
;
class
ProcessorContext
{
class
ProcessorContext
{
public:
public:
virtual
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
=
0
;
virtual
void
Wait
()
=
0
;
void
ShutDown
();
void
ShutDown
();
void
BindProc
(
const
std
::
shared_ptr
<
Processor
>&
processor
)
{
void
BindProc
(
const
std
::
shared_ptr
<
Processor
>&
processor
)
{
processor_
=
processor
;
processor_
=
processor
;
}
}
virtual
std
::
shared_ptr
<
CRoutine
>
NextRoutine
()
=
0
;
virtual
void
Wait
()
=
0
;
protected:
protected:
bool
stop_
=
false
;
alignas
(
CACHELINE_SIZE
)
std
::
shared_ptr
<
Processor
>
processor_
=
nullptr
;
alignas
(
CACHELINE_SIZE
)
std
::
shared_ptr
<
Processor
>
processor_
=
nullptr
;
alignas
(
CACHELINE_SIZE
)
std
::
atomic_flag
notified_
=
ATOMIC_FLAG_INIT
;
alignas
(
CACHELINE_SIZE
)
std
::
atomic_flag
notified_
=
ATOMIC_FLAG_INIT
;
bool
stop_
=
false
;
};
};
}
// namespace scheduler
}
// namespace scheduler
}
// namespace cyber
}
// namespace cyber
}
// namespace apollo
}
// namespace apollo
#endif // CYBER_SCHEDULER_P
OLICY_P
ROCESSOR_CONTEXT_H_
#endif // CYBER_SCHEDULER_PROCESSOR_CONTEXT_H_
cyber/scheduler/scheduler.cc
浏览文件 @
f0cdf6a8
...
@@ -18,9 +18,11 @@
...
@@ -18,9 +18,11 @@
#include <utility>
#include <utility>
#include "cyber/data/data_visitor.h"
#include "cyber/common/environment.h"
#include "cyber/common/file.h"
#include "cyber/common/global_data.h"
#include "cyber/common/global_data.h"
#include "cyber/common/util.h"
#include "cyber/common/util.h"
#include "cyber/data/data_visitor.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/event/perf_event_cache.h"
#include "cyber/scheduler/policy/choreography.h"
#include "cyber/scheduler/policy/choreography.h"
#include "cyber/scheduler/policy/classic.h"
#include "cyber/scheduler/policy/classic.h"
...
@@ -28,20 +30,19 @@
...
@@ -28,20 +30,19 @@
#include "cyber/scheduler/policy/scheduler_classic.h"
#include "cyber/scheduler/policy/scheduler_classic.h"
#include "cyber/scheduler/processor.h"
#include "cyber/scheduler/processor.h"
#include "cyber/scheduler/processor_context.h"
#include "cyber/scheduler/processor_context.h"
#include "cyber/common/environment.h"
#include "cyber/common/file.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
namespace
scheduler
{
namespace
scheduler
{
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
GetAbsolutePath
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
GetProtoFromFile
;
using
apollo
::
cyber
::
common
::
GlobalData
;
using
apollo
::
cyber
::
common
::
PathExists
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
common
::
WorkRoot
;
using
apollo
::
cyber
::
event
::
PerfEventCache
;
using
apollo
::
cyber
::
event
::
SchedPerf
;
Scheduler
*
Scheduler
::
Instance
()
{
Scheduler
*
Scheduler
::
Instance
()
{
static
Scheduler
*
instance
=
nullptr
;
static
Scheduler
*
instance
=
nullptr
;
...
@@ -58,7 +59,7 @@ Scheduler* Scheduler::Instance() {
...
@@ -58,7 +59,7 @@ Scheduler* Scheduler::Instance() {
if
(
PathExists
(
cfg_file
)
&&
GetProtoFromFile
(
cfg_file
,
&
cfg
))
{
if
(
PathExists
(
cfg_file
)
&&
GetProtoFromFile
(
cfg_file
,
&
cfg
))
{
policy
=
cfg
.
scheduler_conf
().
policy
();
policy
=
cfg
.
scheduler_conf
().
policy
();
}
else
{
}
else
{
A
ERROR
<<
"Pls make sure schedconf exist and which format is correct.
\n
"
;
A
DEBUG
<<
"Pls make sure schedconf exist and which format is correct.
\n
"
;
}
}
if
(
!
policy
.
compare
(
std
::
string
(
"classic"
)))
{
if
(
!
policy
.
compare
(
std
::
string
(
"classic"
)))
{
...
@@ -86,14 +87,15 @@ void Scheduler::ShutDown() {
...
@@ -86,14 +87,15 @@ void Scheduler::ShutDown() {
bool
Scheduler
::
CreateTask
(
const
RoutineFactory
&
factory
,
bool
Scheduler
::
CreateTask
(
const
RoutineFactory
&
factory
,
const
std
::
string
&
name
)
{
const
std
::
string
&
name
)
{
return
CreateTask
(
factory
.
create_routine
(),
name
,
factory
.
GetDataVisitor
());
return
CreateTask
(
factory
.
create_routine
(),
name
,
factory
.
GetDataVisitor
());
}
}
bool
Scheduler
::
CreateTask
(
std
::
function
<
void
()
>&&
func
,
bool
Scheduler
::
CreateTask
(
std
::
function
<
void
()
>&&
func
,
const
std
::
string
&
name
,
const
std
::
string
&
name
,
std
::
shared_ptr
<
DataVisitorBase
>
visitor
)
{
std
::
shared_ptr
<
DataVisitorBase
>
visitor
)
{
if
(
stop_
)
{
if
(
stop_
)
{
A
ERROR
<<
"scheduler is stoped, cannot create task!"
;
A
DEBUG
<<
"scheduler is stoped, cannot create task!"
;
return
false
;
return
false
;
}
}
...
@@ -125,7 +127,8 @@ bool Scheduler::NotifyTask(uint64_t crid) {
...
@@ -125,7 +127,8 @@ bool Scheduler::NotifyTask(uint64_t crid) {
return
NotifyProcessor
(
crid
);
return
NotifyProcessor
(
crid
);
}
}
void
Scheduler
::
ParseCpuset
(
const
std
::
string
&
str
,
std
::
vector
<
int
>
*
cpuset
)
{
void
Scheduler
::
ParseCpuset
(
const
std
::
string
&
str
,
std
::
vector
<
int
>
*
cpuset
)
{
std
::
vector
<
std
::
string
>
lines
;
std
::
vector
<
std
::
string
>
lines
;
std
::
stringstream
ss
(
str
);
std
::
stringstream
ss
(
str
);
std
::
string
l
;
std
::
string
l
;
...
@@ -135,7 +138,7 @@ void Scheduler::ParseCpuset(const std::string &str, std::vector<int> *cpuset) {
...
@@ -135,7 +138,7 @@ void Scheduler::ParseCpuset(const std::string &str, std::vector<int> *cpuset) {
}
}
for
(
std
::
vector
<
std
::
string
>::
const_iterator
it
=
lines
.
begin
(),
for
(
std
::
vector
<
std
::
string
>::
const_iterator
it
=
lines
.
begin
(),
e
=
lines
.
end
();
it
!=
e
;
it
++
)
{
e
=
lines
.
end
();
it
!=
e
;
it
++
)
{
std
::
stringstream
ss
(
*
it
);
std
::
stringstream
ss
(
*
it
);
std
::
vector
<
std
::
string
>
range
;
std
::
vector
<
std
::
string
>
range
;
...
@@ -146,11 +149,12 @@ void Scheduler::ParseCpuset(const std::string &str, std::vector<int> *cpuset) {
...
@@ -146,11 +149,12 @@ void Scheduler::ParseCpuset(const std::string &str, std::vector<int> *cpuset) {
if
(
range
.
size
()
==
1
)
{
if
(
range
.
size
()
==
1
)
{
cpuset
->
push_back
(
std
::
stoi
(
range
[
0
]));
cpuset
->
push_back
(
std
::
stoi
(
range
[
0
]));
}
else
if
(
range
.
size
()
==
2
)
{
}
else
if
(
range
.
size
()
==
2
)
{
for
(
int
i
=
std
::
stoi
(
range
[
0
]),
e
=
std
::
stoi
(
range
[
1
]);
i
<=
e
;
i
++
)
{
for
(
int
i
=
std
::
stoi
(
range
[
0
]),
e
=
std
::
stoi
(
range
[
1
]);
i
<=
e
;
i
++
)
{
cpuset
->
push_back
(
i
);
cpuset
->
push_back
(
i
);
}
}
}
else
{
}
else
{
A
ERROR
<<
"Parsing cpuset format error."
;
A
DEBUG
<<
"Parsing cpuset format error."
;
exit
(
0
);
exit
(
0
);
}
}
}
}
...
...
cyber/scheduler/scheduler.h
浏览文件 @
f0cdf6a8
...
@@ -33,8 +33,6 @@
...
@@ -33,8 +33,6 @@
#include "cyber/common/types.h"
#include "cyber/common/types.h"
#include "cyber/croutine/croutine.h"
#include "cyber/croutine/croutine.h"
#include "cyber/croutine/routine_factory.h"
#include "cyber/croutine/routine_factory.h"
#include "cyber/proto/choreography_conf.pb.h"
#include "cyber/proto/scheduler_conf.pb.h"
namespace
apollo
{
namespace
apollo
{
namespace
cyber
{
namespace
cyber
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录