#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
"""
BitBake 'RunQueue' implementation
Handles preparation and execution of a queue of tasks
"""
# Copyright (C) 2006-2007 Richard Purdie
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import bb, os, sys
from bb import msg, data, event
import signal
import stat
import fcntl
import copy
class RunQueueStats:
"""
Holds statistics on the tasks handled by the associated runQueue
"""
def __init__(self, total):
self.completed = 0
self.skipped = 0
self.failed = 0
self.active = 0
self.total = total
def taskFailed(self):
self.active = self.active - 1
self.failed = self.failed + 1
def taskCompleted(self, number = 1):
self.active = self.active - number
self.completed = self.completed + number
def taskSkipped(self, number = 1):
self.active = self.active + number
self.skipped = self.skipped + number
def taskActive(self):
self.active = self.active + 1
# These values indicate the next step due to be run in the
# runQueue state machine
runQueuePrepare = 2
runQueueSceneInit = 3
runQueueSceneRun = 4
runQueueRunInit = 5
runQueueRunning = 6
runQueueFailed = 7
runQueueCleanUp = 8
runQueueComplete = 9
runQueueChildProcess = 10
class RunQueueScheduler(object):
"""
Control the order tasks are scheduled in.
"""
name = "basic"
def __init__(self, runqueue, rqdata):
"""
The default scheduler just returns the first buildable task (the
priority map is sorted by task numer)
"""
self.rq = runqueue
self.rqdata = rqdata
numTasks = len(self.rq.runq_fnid)
self.prio_map = []
self.prio_map.extend(range(numTasks))
def next(self):
"""
Return the id of the first task we find that is buildable
"""
for task1 in range(len(self.rqdata.runq_fnid)):
task = self.prio_map[task1]
if self.rq.runq_running[task] == 1:
continue
if self.rq.runq_buildable[task] == 1:
return task
class RunQueueSchedulerSpeed(RunQueueScheduler):
"""
A scheduler optimised for speed. The priority map is sorted by task weight,
heavier weighted tasks (tasks needed by the most other tasks) are run first.
"""
name = "speed"
def __init__(self, runqueue, rqdata):
"""
The priority map is sorted by task weight.
"""
from copy import deepcopy
self.rq = runqueue
self.rqdata =
|