#!/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.
from bb import msg, data, event, mkdirhier, utils
import bb, os, sys
import signal
import stat
import fcntl
class TaskFailure(Exception):
"""Exception raised when a task in a runqueue fails"""
def __init__(self, x):
self.args = x
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
runQueueRunInit = 3
runQueueRunning = 4
runQueueFailed = 6
runQueueCleanUp = 7
runQueueComplete = 8
runQueueChildProcess = 9
class RunQueueScheduler:
"""
Control the order tasks are scheduled in.
"""
def __init__(self, runqueue):
"""
The default scheduler just returns the first buildable task (the
priority map is sorted by task numer)
"""
self.rq = runqueue
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.rq.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.
"""
def __init__(self, runqueue):
"""
The priority map is sorted by task weight.
"""
from copy import deepcopy
self.rq = runqueue
sortweight = deepcopy(self.rq.runq_weight)
sortweight.sort()
copyweight = deepcopy(self.rq.runq_weight)
self.prio_map = []
for weight in sortweight:
idx = copyweight.index(weight)
self.prio_map.append(idx)
copyweight[idx] = -1
self.prio_map.reverse()
class RunQueueSchedulerCompletion(RunQueueSchedulerSpeed):
"""
A scheduler optimised to complete .bb files are quickly as possible. The
priority map is sorted by task weight, but then reordered so once a given
.bb file starts to build, its completed as quickly as possible. This works
well where disk space is at a premium and classes like OE's rm_work are in
force.
"""
def __init__(self, runqueue):
RunQueueSchedulerSpeed.__init__(self, runqueue)
from copy import deepcopy
#FIXME - whilst this groups all fnids together it does not reorder the
#fnid groups optimally.
basemap = deepcopy(self.prio_map)
self.prio_map = []
while (len(basemap) > 0):
entry = basemap.pop(0)
self.prio_map.append(entry)
fnid = self.rq.runq_fnid[entry]
todel = []
for entry in basemap:
entry_fnid = self.rq.runq_fnid[entry]
if entry_fnid == fnid:
todel.append(basemap.index(entry))
self.prio_map.append(entry)
todel.reverse()
for idx in todel:
del basemap[idx]
class RunQueue:
"""
BitBake Run Queue implementation
"""
def __init__(self, cooker, cfgData, dataCache, taskData, targets):
self.reset_runqueue()
self.cooker = cooker
self.dataCache = dataCache
self.taskData = taskData
self.cfgData = cfgData
self.targets = targets
self.number_tasks = int(bb.data.getVar("BB_NUMBER_THREADS", cfgData, 1) or 1)
self.multi_provider_whitelist = (bb.data.getVar("MULTI_PROVIDER_WHITELIST", cfgData, 1) or "").split()
self.scheduler = bb.data.getVar("BB_SCHEDULER", cfgData, 1) or "speed"
self.stamppolicy = bb.data.getVar("BB_STAMP_POLICY", cfgData, 1) or "perfile"
self.stampwhitelist = bb.data.getVar("BB_STAMP_WHITELIST", cfgData, 1) or ""
def reset_runqueue(self):
self.runq_fnid = []
self.runq_task = []
self.runq_depends = []
self.runq_revdeps = []
self.state = runQueuePrepare
def runq_depends_names(self, ids):
import re
ret = []
for id in self.runq_depends[ids]:
nam = os.path.basename(self.get_user_idstring(id))
nam = re.sub("_[^,]*,", ",", nam)
|