OpenSDN source code
|
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is added to the run queue or the pending queue depending as to whether there is a runable or pending task ahead of it that violates the mutual exclusion policies. When tasks exit the scheduler re-examines the tasks on the pending queue which may now be runnable. It is important that this process is efficient such that exit events do not scan tasks that are not waiting on a particular task id or task instance to have a 0 count. More...
#include <task.h>
Public Types | |
enum | CancelReturnCode { CANCELLED, FAILED, QUEUED } |
typedef boost::function< void(const char *file_name, uint32_t line_no, const Task *task, const char *description, uint64_t delay)> | LogFn |
Public Member Functions | |
TaskScheduler (int thread_count=0) | |
TaskScheduler constructor. TBB assumes it can use the "thread" invoking tbb::scheduler can be used for task scheduling. But, in our case we dont want "main" thread to be part of tbb. So, initialize TBB with one thread more than its default. More... | |
~TaskScheduler () | |
Frees up the task_entry_db_ allocated for scheduler. More... | |
void | Enqueue (Task *task) |
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq. Enqueueing may may result in the task being immedietly added to the run queue or to a pending queue. Tasks may not be added to the run queue in violation of their exclusion policy. More... | |
void | EnqueueUnLocked (Task *task) |
CancelReturnCode | Cancel (Task *task) |
Cancels a Task that can be in RUN/WAIT state. The caller needs to ensure that the task exists when Cancel() is invoked. More... | |
void | SetPolicy (int task_id, TaskPolicy &policy) |
Sets the task exclusion policy. Adds policy entries for the task Examples: More... | |
bool | GetRunStatus () |
int | GetTaskId (const std::string &name) |
std::string | GetTaskName (int task_id) const |
TaskStats * | GetTaskGroupStats (int task_id) |
TaskStats * | GetTaskStats (int task_id) |
TaskStats * | GetTaskStats (int task_id, int instance_id) |
void | ClearTaskGroupStats (int task_id) |
void | ClearTaskStats (int task_id) |
void | ClearTaskStats (int task_id, int instance_id) |
TaskGroup * | GetTaskGroup (int task_id) |
Get TaskGroup for a task_id. Grows task_entry_db_ if necessary. More... | |
TaskGroup * | QueryTaskGroup (int task_id) |
Query TaskGroup for a task_id.Assumes valid entry is present for task_id. More... | |
bool | IsTaskGroupEmpty (int task_id) const |
Check if there are any Tasks in the given TaskGroup. Assumes that all task ids are mutually exclusive with bgp::Config. More... | |
TaskEntry * | GetTaskEntry (int task_id, int instance_id) |
Get TaskGroup for a task_id. Grows task_entry_db_ if necessary. More... | |
TaskEntry * | QueryTaskEntry (int task_id, int instance_id) |
Query TaskEntry for a task-id and task-instance. More... | |
void | OnTaskExit (Task *task) |
Method invoked on exit of a Task. Exit of a task can potentially start tasks in pendingq. More... | |
void | Stop () |
Stops scheduling of all tasks. More... | |
void | Start () |
Starts scheduling of all tasks. More... | |
void | Print () |
Debug print routine. More... | |
bool | IsEmpty (bool running_only=false) |
Returns true if there are no tasks running and/or enqueued If running_only is true, enqueued tasks are ignored i.e. return true if there are no running tasks. Ignore TaskGroup or TaskEntry if it is disabled. More... | |
void | Terminate () |
int | HardwareThreadCount () |
uint64_t | enqueue_count () const |
uint64_t | done_count () const |
uint64_t | cancel_count () const |
void | SetMaxThreadCount (int n) |
Force number of threads. More... | |
void | GetSandeshData (SandeshTaskScheduler *resp, bool summary) |
void | Log (const char *file_name, uint32_t line_no, const Task *task, const char *description, uint64_t delay) |
void | RegisterLog (LogFn fn) |
void | SetTrackRunTime (bool value) |
bool | track_run_time () const |
void | EnableLatencyThresholds (uint32_t execute, uint32_t schedule) |
Enable logging of tasks exceeding configured latency. More... | |
uint32_t | schedule_delay () const |
uint32_t | execute_delay () const |
bool | measure_delay () const |
void | SetLatencyThreshold (const std::string &name, uint32_t execute, uint32_t schedule) |
uint32_t | schedule_delay (Task *task) const |
uint32_t | execute_delay (Task *task) const |
void | set_event_manager (EventManager *evm) |
void | DisableTaskGroup (int task_id) |
void | EnableTaskGroup (int task_id) |
void | DisableTaskEntry (int task_id, int instance_id) |
void | EnableTaskEntry (int task_id, int instance_id) |
void | ModifyTbbKeepAwakeTimeout (uint32_t timeout) |
void | EnableMonitor (EventManager *evm, uint64_t tbb_keepawake_time_msec, uint64_t inactivity_time_msec, uint64_t poll_interval_msec) |
Enable Task monitoring. More... | |
const TaskMonitor * | task_monitor () const |
const TaskTbbKeepAwake * | tbb_awake_task () const |
bool | use_spawn () const |
Static Public Member Functions | |
static void | Initialize (uint32_t thread_count=0, EventManager *evm=NULL) |
static TaskScheduler * | GetInstance () |
static int | GetThreadCount (int thread_count=0) |
Get number of tbb worker threads. For testing purposes only. Limit the number of tbb worker threads. More... | |
static bool | ShouldUseSpawn () |
static int | GetDefaultThreadCount () |
static void | SetThreadAmpFactor (int n) |
following function allows one to increase max num of threads used by TBB More... | |
Private Types | |
typedef std::vector< TaskGroup * > | TaskGroupDb |
typedef std::map< std::string, int > | TaskIdMap |
Private Member Functions | |
void | SetRunningTask (Task *) |
This function should not be called in production code. It is only for unit testing to control current running task This function modifies the running task as specified by the input. More... | |
void | ClearRunningTask () |
void | WaitForTerminateCompletion () |
int | CountThreadsPerPid (pid_t pid) |
Platfrom-dependent subroutine in Linux and FreeBSD implementations, used only in TaskScheduler::WaitForTerminateCompletion(). In Linux, make sure that all the [tbb] threads launched have completely exited. We do so by looking for the Threads count of this process in /proc/<pid>/status. More... | |
DISALLOW_COPY_AND_ASSIGN (TaskScheduler) | |
Private Attributes | |
bool | use_spawn_ |
Use spawn() to run a tbb::task instead of enqueue() More... | |
TaskEntry * | stop_entry_ |
tbb::task_scheduler_init | task_scheduler_ |
tbb::mutex | mutex_ |
bool | running_ |
uint64_t | seqno_ |
TaskGroupDb | task_group_db_ |
tbb::reader_writer_lock | id_map_mutex_ |
TaskIdMap | id_map_ |
int | id_max_ |
LogFn | log_fn_ |
int | hw_thread_count_ |
bool | track_run_time_ |
bool | measure_delay_ |
uint32_t | schedule_delay_ |
Log if time between enqueue and task-execute exceeds the delay. More... | |
uint32_t | execute_delay_ |
Log if time taken to execute exceeds the delay. More... | |
uint64_t | enqueue_count_ |
uint64_t | done_count_ |
uint64_t | cancel_count_ |
EventManager * | evm_ |
TaskTbbKeepAwake * | tbb_awake_task_ |
TaskMonitor * | task_monitor_ |
Static Private Attributes | |
static const int | kVectorGrowSize = 16 |
static boost::scoped_ptr < TaskScheduler > | singleton_ |
static int | ThreadAmpFactor_ = 1 |
following variable allows one to increase max num of threads used by TBB More... | |
Friends | |
class | ConcurrencyScope |
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is added to the run queue or the pending queue depending as to whether there is a runable or pending task ahead of it that violates the mutual exclusion policies. When tasks exit the scheduler re-examines the tasks on the pending queue which may now be runnable. It is important that this process is efficient such that exit events do not scan tasks that are not waiting on a particular task id or task instance to have a 0 count.
typedef boost::function<void(const char *file_name, uint32_t line_no, const Task *task, const char *description, uint64_t delay)> TaskScheduler::LogFn |
|
private |
|
private |
TaskScheduler::TaskScheduler | ( | int | thread_count = 0 | ) |
TaskScheduler constructor. TBB assumes it can use the "thread" invoking tbb::scheduler can be used for task scheduling. But, in our case we dont want "main" thread to be part of tbb. So, initialize TBB with one thread more than its default.
Definition at line 444 of file task.cc.
TaskScheduler::~TaskScheduler | ( | ) |
TaskScheduler::CancelReturnCode TaskScheduler::Cancel | ( | Task * | task | ) |
void TaskScheduler::ClearTaskGroupStats | ( | int | task_id | ) |
void TaskScheduler::ClearTaskStats | ( | int | task_id | ) |
void TaskScheduler::ClearTaskStats | ( | int | task_id, |
int | instance_id | ||
) |
|
private |
Platfrom-dependent subroutine in Linux and FreeBSD implementations, used only in TaskScheduler::WaitForTerminateCompletion(). In Linux, make sure that all the [tbb] threads launched have completely exited. We do so by looking for the Threads count of this process in /proc/<pid>/status.
In FreeBSD use libprocstat to check how many threads is running in specific process.
void TaskScheduler::DisableTaskEntry | ( | int | task_id, |
int | instance_id | ||
) |
void TaskScheduler::DisableTaskGroup | ( | int | task_id | ) |
|
private |
void TaskScheduler::EnableLatencyThresholds | ( | uint32_t | execute, |
uint32_t | schedule | ||
) |
void TaskScheduler::EnableMonitor | ( | EventManager * | evm, |
uint64_t | tbb_keepawake_time_msec, | ||
uint64_t | inactivity_time_msec, | ||
uint64_t | poll_interval_msec | ||
) |
void TaskScheduler::EnableTaskEntry | ( | int | task_id, |
int | instance_id | ||
) |
void TaskScheduler::EnableTaskGroup | ( | int | task_id | ) |
void TaskScheduler::Enqueue | ( | Task * | task | ) |
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq. Enqueueing may may result in the task being immedietly added to the run queue or to a pending queue. Tasks may not be added to the run queue in violation of their exclusion policy.
Definition at line 636 of file task.cc.
void TaskScheduler::EnqueueUnLocked | ( | Task * | task | ) |
uint32_t TaskScheduler::execute_delay | ( | Task * | task | ) | const |
|
static |
void TaskScheduler::GetSandeshData | ( | SandeshTaskScheduler * | resp, |
bool | summary | ||
) |
TaskEntry * TaskScheduler::GetTaskEntry | ( | int | task_id, |
int | instance_id | ||
) |
TaskGroup * TaskScheduler::GetTaskGroup | ( | int | task_id | ) |
TaskStats * TaskScheduler::GetTaskGroupStats | ( | int | task_id | ) |
TaskStats * TaskScheduler::GetTaskStats | ( | int | task_id | ) |
TaskStats * TaskScheduler::GetTaskStats | ( | int | task_id, |
int | instance_id | ||
) |
|
static |
|
static |
bool TaskScheduler::IsEmpty | ( | bool | running_only = false | ) |
bool TaskScheduler::IsTaskGroupEmpty | ( | int | task_id | ) | const |
void TaskScheduler::Log | ( | const char * | file_name, |
uint32_t | line_no, | ||
const Task * | task, | ||
const char * | description, | ||
uint64_t | delay | ||
) |
void TaskScheduler::ModifyTbbKeepAwakeTimeout | ( | uint32_t | timeout | ) |
void TaskScheduler::OnTaskExit | ( | Task * | task | ) |
void TaskScheduler::Print | ( | ) |
TaskEntry * TaskScheduler::QueryTaskEntry | ( | int | task_id, |
int | instance_id | ||
) |
TaskGroup * TaskScheduler::QueryTaskGroup | ( | int | task_id | ) |
uint32_t TaskScheduler::schedule_delay | ( | Task * | task | ) | const |
void TaskScheduler::set_event_manager | ( | EventManager * | evm | ) |
void TaskScheduler::SetLatencyThreshold | ( | const std::string & | name, |
uint32_t | execute, | ||
uint32_t | schedule | ||
) |
void TaskScheduler::SetMaxThreadCount | ( | int | n | ) |
Force number of threads.
void TaskScheduler::SetPolicy | ( | int | task_id, |
TaskPolicy & | policy | ||
) |
Sets the task exclusion policy. Adds policy entries for the task Examples:
Definition at line 610 of file task.cc.
|
private |
|
static |
void TaskScheduler::Start | ( | ) |
|
inline |
|
inline |
void TaskScheduler::Terminate | ( | ) |
|
private |
|
friend |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |