bitkeeper revision 1.810 (4059c6e8EQAxVfRpkNjdygO1O6otTQ)

schedule.c, sched_bvt.c, main.py, Makefile, setup.py, Xc.c:
  Python tool fixes.
tempfile.py:
  new file
This commit is contained in:
kaf24@scramble.cl.cam.ac.uk committed 2004-03-18 15:57:28 +00:00
1 parent fcaa8335c3
commit bc906fc66a
11 files changed
+512 -42

No files matched your search

+1
View File
@@ -93,6 +93,7 @@
4055ee41IfFazrwadCH2J72nz-A9YA tools/xenctl/Makefile
4055ee4b_4Rvns_KzE12csI14EKK6Q tools/xenctl/lib/__init__.py
4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/xenctl/lib/console_client.py
4059c6a0pnxhG8hwSOivXybbGOwuXw tools/xenctl/lib/tempfile.py
3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xenctl/lib/utils.py
4055ee44Bu6oP7U0WxxXypbUt4dNPQ tools/xenctl/setup.py
40431ac64Hj4ixUnKmlugZKhXPFE_Q tools/xend/Makefile
+2 -2
View File
@@ -19,8 +19,8 @@ install: all
$(MAKE) -C tools install
dist: all
$(MAKE) prefix=`pwd`/../install -C xen install
$(MAKE) prefix=`pwd`/../install -C tools install
$(MAKE) prefix=`pwd`/../install dist=yes -C xen install
$(MAKE) prefix=`pwd`/../install dist=yes -C tools install
clean:
$(MAKE) -C xen clean
+7 -2
View File
@@ -3,8 +3,13 @@ all:
python setup.py build
install: all
if [ "$(prefix)" = "" ]; then python setup.py install; \
else python setup.py install --root="$(prefix)"; fi
if [ "$(prefix)" = "" ]; then \
python setup.py install; \
elif [ "$(dist)" = "yes" ]; then \
python setup.py install --home="$(prefix)"; \
else \
python setup.py install --root="$(prefix)"; \
fi
clean:
rm -rf build *.pyc *.pyo *.o *.a *~
-2
View File
@@ -867,7 +867,6 @@ static PyObject *pyxc_atropos_domain_set(PyObject *self,
PyObject *kwds)
{
XcObject *xc = (XcObject *)self;
PyObject *ret_obj;
int xtratime;
u64 domid;
@@ -889,7 +888,6 @@ static PyObject *pyxc_rrobin_global_set(PyObject *self,
PyObject *kwds)
{
XcObject *xc = (XcObject *)self;
PyObject *ret_obj;
u64 slice;
static char *kwd_list[] = { "slice", NULL };
+7 -2
View File
@@ -3,8 +3,13 @@ all:
python setup.py build
install: all
if [ "$(prefix)" = "" ]; then python setup.py install; \
else python setup.py install --root="$(prefix)"; fi
if [ "$(prefix)" = "" ]; then \
python setup.py install; \
elif [ "$(dist)" = "yes" ]; then \
python setup.py install --home="$(prefix)"; \
else \
python setup.py install --root="$(prefix)"; \
fi
clean:
rm -rf build *.pyc *.pyo *.o *.a *~
+451
View File
@@ -0,0 +1,451 @@
"""Temporary files.
This module provides generic, low- and high-level interfaces for
creating temporary files and directories. The interfaces listed
as "safe" just below can be used without fear of race conditions.
Those listed as "unsafe" cannot, and are provided for backward
compatibility only.
This module also provides some data items to the user:
TMP_MAX - maximum number of names that will be tried before
giving up.
template - the default prefix for all temporary names.
You may change this to control the default prefix.
tempdir - If this is set to a string before the first use of
any routine from this module, it will be considered as
another candidate location to store temporary files.
"""
__all__ = [
"NamedTemporaryFile", "TemporaryFile", # high level safe interfaces
"mkstemp", "mkdtemp", # low level safe interfaces
"mktemp", # deprecated unsafe interface
"TMP_MAX", "gettempprefix", # constants
"tempdir", "gettempdir"
]
# Imports.
import os as _os
import errno as _errno
from random import Random as _Random
if _os.name == 'mac':
import Carbon.Folder as _Folder
import Carbon.Folders as _Folders
try:
import fcntl as _fcntl
# If PYTHONCASEOK is set on Windows, stinking FCNTL.py gets
# imported, and we don't get an ImportError then. Provoke
# an AttributeError instead in that case.
_fcntl.fcntl
except (ImportError, AttributeError):
def _set_cloexec(fd):
pass
else:
def _set_cloexec(fd):
flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
if flags >= 0:
# flags read successfully, modify
flags |= _fcntl.FD_CLOEXEC
_fcntl.fcntl(fd, _fcntl.F_SETFD, flags)
try:
import thread as _thread
except ImportError:
import dummy_thread as _thread
_allocate_lock = _thread.allocate_lock
_text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL
if hasattr(_os, 'O_NOINHERIT'):
_text_openflags |= _os.O_NOINHERIT
if hasattr(_os, 'O_NOFOLLOW'):
_text_openflags |= _os.O_NOFOLLOW
_bin_openflags = _text_openflags
if hasattr(_os, 'O_BINARY'):
_bin_openflags |= _os.O_BINARY
if hasattr(_os, 'TMP_MAX'):
TMP_MAX = _os.TMP_MAX
else:
TMP_MAX = 10000
template = "tmp"
tempdir = None
# Internal routines.
_once_lock = _allocate_lock()
class _RandomNameSequence:
"""An instance of _RandomNameSequence generates an endless
sequence of unpredictable strings which can safely be incorporated
into file names. Each string is six characters long. Multiple
threads can safely use the same instance at the same time.
_RandomNameSequence is an iterator."""
characters = ("abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"0123456789-_")
def __init__(self):
self.mutex = _allocate_lock()
self.rng = _Random()
self.normcase = _os.path.normcase
def __iter__(self):
return self
def next(self):
m = self.mutex
c = self.characters
choose = self.rng.choice
m.acquire()
try:
letters = [choose(c) for dummy in "123456"]
finally:
m.release()
return self.normcase(''.join(letters))
def _candidate_tempdir_list():
"""Generate a list of candidate temporary directories which
_get_default_tempdir will try."""
dirlist = []
# First, try the environment.
for envname in 'TMPDIR', 'TEMP', 'TMP':
dirname = _os.getenv(envname)
if dirname: dirlist.append(dirname)
# Failing that, try OS-specific locations.
if _os.name == 'mac':
try:
fsr = _Folder.FSFindFolder(_Folders.kOnSystemDisk,
_Folders.kTemporaryFolderType, 1)
dirname = fsr.as_pathname()
dirlist.append(dirname)
except _Folder.error:
pass
elif _os.name == 'riscos':
dirname = _os.getenv('Wimp$ScrapDir')
if dirname: dirlist.append(dirname)
elif _os.name == 'nt':
dirlist.extend([ r'c:\temp', r'c:\tmp', r'\temp', r'\tmp' ])
else:
dirlist.extend([ '/tmp', '/var/tmp', '/usr/tmp' ])
# As a last resort, the current directory.
try:
dirlist.append(_os.getcwd())
except (AttributeError, _os.error):
dirlist.append(_os.curdir)
return dirlist
def _get_default_tempdir():
"""Calculate the default directory to use for temporary files.
This routine should be called exactly once.
We determine whether or not a candidate temp dir is usable by
trying to create and write to a file in that directory. If this
is successful, the test file is deleted. To prevent denial of
service, the name of the test file must be randomized."""
namer = _RandomNameSequence()
dirlist = _candidate_tempdir_list()
flags = _text_openflags
for dir in dirlist:
if dir != _os.curdir:
dir = _os.path.normcase(_os.path.abspath(dir))
# Try only a few names per directory.
for seq in xrange(100):
name = namer.next()
filename = _os.path.join(dir, name)
try:
fd = _os.open(filename, flags, 0600)
fp = _os.fdopen(fd, 'w')
fp.write('blat')
fp.close()
_os.unlink(filename)
del fp, fd
return dir
except (OSError, IOError), e:
if e[0] != _errno.EEXIST:
break # no point trying more names in this directory
pass
raise IOError, (_errno.ENOENT,
("No usable temporary directory found in %s" % dirlist))
_name_sequence = None
def _get_candidate_names():
"""Common setup sequence for all user-callable interfaces."""
global _name_sequence
if _name_sequence is None:
_once_lock.acquire()
try:
if _name_sequence is None:
_name_sequence = _RandomNameSequence()
finally:
_once_lock.release()
return _name_sequence
def _mkstemp_inner(dir, pre, suf, flags):
"""Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""
names = _get_candidate_names()
for seq in xrange(TMP_MAX):
name = names.next()
file = _os.path.join(dir, pre + name + suf)
try:
fd = _os.open(file, flags, 0600)
_set_cloexec(fd)
return (fd, file)
except OSError, e:
if e.errno == _errno.EEXIST:
continue # try again
raise
raise IOError, (_errno.EEXIST, "No usable temporary file name found")
# User visible interfaces.
def gettempprefix():
"""Accessor for tempdir.template."""
return template
tempdir = None
def gettempdir():
"""Accessor for tempdir.tempdir."""
global tempdir
if tempdir is None:
_once_lock.acquire()
try:
if tempdir is None:
tempdir = _get_default_tempdir()
finally:
_once_lock.release()
return tempdir
def mkstemp(suffix="", prefix=template, dir=None, text=False):
"""mkstemp([suffix, [prefix, [dir, [text]]]])
User-callable function to create and return a unique temporary
file. The return value is a pair (fd, name) where fd is the
file descriptor returned by os.open, and name is the filename.
If 'suffix' is specified, the file name will end with that suffix,
otherwise there will be no suffix.
If 'prefix' is specified, the file name will begin with that prefix,
otherwise a default prefix is used.
If 'dir' is specified, the file will be created in that directory,
otherwise a default directory is used.
If 'text' is specified and true, the file is opened in text
mode. Else (the default) the file is opened in binary mode. On
some operating systems, this makes no difference.
The file is readable and writable only by the creating user ID.
If the operating system uses permission bits to indicate whether a
file is executable, the file is executable by no one. The file
descriptor is not inherited by children of this process.
Caller is responsible for deleting the file when done with it.
"""
if dir is None:
dir = gettempdir()
if text:
flags = _text_openflags
else:
flags = _bin_openflags
return _mkstemp_inner(dir, prefix, suffix, flags)
def mkdtemp(suffix="", prefix=template, dir=None):
"""mkdtemp([suffix, [prefix, [dir]]])
User-callable function to create and return a unique temporary
directory. The return value is the pathname of the directory.
Arguments are as for mkstemp, except that the 'text' argument is
not accepted.
The directory is readable, writable, and searchable only by the
creating user.
Caller is responsible for deleting the directory when done with it.
"""
if dir is None:
dir = gettempdir()
names = _get_candidate_names()
for seq in xrange(TMP_MAX):
name = names.next()
file = _os.path.join(dir, prefix + name + suffix)
try:
_os.mkdir(file, 0700)
return file
except OSError, e:
if e.errno == _errno.EEXIST:
continue # try again
raise
raise IOError, (_errno.EEXIST, "No usable temporary directory name found")
def mktemp(suffix="", prefix=template, dir=None):
"""mktemp([suffix, [prefix, [dir]]])
User-callable function to return a unique temporary file name. The
file is not created.
Arguments are as for mkstemp, except that the 'text' argument is
not accepted.
This function is unsafe and should not be used. The file name
refers to a file that did not exist at some point, but by the time
you get around to creating it, someone else may have beaten you to
the punch.
"""
## from warnings import warn as _warn
## _warn("mktemp is a potential security risk to your program",
## RuntimeWarning, stacklevel=2)
if dir is None:
dir = gettempdir()
names = _get_candidate_names()
for seq in xrange(TMP_MAX):
name = names.next()
file = _os.path.join(dir, prefix + name + suffix)
if not _os.path.exists(file):
return file
raise IOError, (_errno.EEXIST, "No usable temporary filename found")
class _TemporaryFileWrapper:
"""Temporary file wrapper
This class provides a wrapper around files opened for
temporary use. In particular, it seeks to automatically
remove the file when it is no longer needed.
"""
def __init__(self, file, name):
self.file = file
self.name = name
self.close_called = False
def __getattr__(self, name):
file = self.__dict__['file']
a = getattr(file, name)
if type(a) != type(0):
setattr(self, name, a)
return a
# NT provides delete-on-close as a primitive, so we don't need
# the wrapper to do anything special. We still use it so that
# file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile.
if _os.name != 'nt':
# Cache the unlinker so we don't get spurious errors at
# shutdown when the module-level "os" is None'd out. Note
# that this must be referenced as self.unlink, because the
# name TemporaryFileWrapper may also get None'd out before
# __del__ is called.
unlink = _os.unlink
def close(self):
if not self.close_called:
self.close_called = True
self.file.close()
self.unlink(self.name)
def __del__(self):
self.close()
def NamedTemporaryFile(mode='w+b', bufsize=-1, suffix="",
prefix=template, dir=None):
"""Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'dir' -- as for mkstemp.
'mode' -- the mode argument to os.fdopen (default "w+b").
'bufsize' -- the buffer size argument to os.fdopen (default -1).
The file is created as mkstemp() would do it.
Returns a file object; the name of the file is accessible as
file.name. The file will be automatically deleted when it is
closed.
"""
if dir is None:
dir = gettempdir()
if 'b' in mode:
flags = _bin_openflags
else:
flags = _text_openflags
# Setting O_TEMPORARY in the flags causes the OS to delete
# the file when it is closed. This is only supported by Windows.
if _os.name == 'nt':
flags |= _os.O_TEMPORARY
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
file = _os.fdopen(fd, mode, bufsize)
return _TemporaryFileWrapper(file, name)
if _os.name != 'posix' or _os.sys.platform == 'cygwin':
# On non-POSIX and Cygwin systems, assume that we cannot unlink a file
# while it is open.
TemporaryFile = NamedTemporaryFile
else:
def TemporaryFile(mode='w+b', bufsize=-1, suffix="",
prefix=template, dir=None):
"""Create and return a temporary file.
Arguments:
'prefix', 'suffix', 'directory' -- as for mkstemp.
'mode' -- the mode argument to os.fdopen (default "w+b").
'bufsize' -- the buffer size argument to os.fdopen (default -1).
The file is created as mkstemp() would do it.
Returns a file object. The file has no name, and will cease to
exist when it is closed.
"""
if dir is None:
dir = gettempdir()
if 'b' in mode:
flags = _bin_openflags
else:
flags = _text_openflags
(fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
try:
_os.unlink(name)
return _os.fdopen(fd, mode, bufsize)
except:
_os.close(fd)
raise
+15 -4
View File
@@ -1,8 +1,19 @@
from distutils.core import setup, Extension
import sys
setup(name = "xenctl",
version = "1.0",
packages = ["xenctl"],
package_dir = { "xenctl" : "lib" },
modules = [ 'xenctl.console_client', 'xenctl.utils' ]
# We need the 'tempfile' module from Python 2.3. We install this ourselves
# if the installed Python is older than 2.3.
major = sys.version_info[0]
minor = sys.version_info[1]
if major == 2 and minor < 3:
modules.append('xenctl.tempfile')
setup(name = 'xenctl',
version = '1.0',
py_modules = modules,
package_dir = { 'xenctl' : 'lib' },
)
+7 -2
View File
@@ -3,8 +3,13 @@ all:
python setup.py build
install: all
if [ "$(prefix)" = "" ]; then python setup.py install; \
else python setup.py install --root="$(prefix)"; fi
if [ "$(prefix)" = "" ]; then \
python setup.py install; \
elif [ "$(dist)" = "yes" ]; then \
python setup.py install --home="$(prefix)"; \
else \
python setup.py install --root="$(prefix)"; \
fi
mkdir -p $(prefix)/usr/sbin
install -m0755 xend $(prefix)/usr/sbin
+1 -1
View File
@@ -4,7 +4,7 @@
## Copyright (c) 2004, K A Fraser (University of Cambridge)
###########################################################
import errno, re, os, pwd, select, signal, socket, struct, sys, tempfile, time
import errno, re, os, pwd, select, signal, socket, struct, sys, time
import xend.console, xend.manager, xend.utils, Xc
+16 -20
View File
@@ -48,9 +48,9 @@ struct bvt_cpu_info
};
#define DOM_INF(p) ((struct bvt_dom_info *)(p)->sched_priv)
#define CPU_INF(cpu) ((struct bvt_cpu_info *)(schedule_data[cpu]).sched_priv)
#define CPU_SVT(cpu) (CPU_INF(cpu)->svt)
#define BVT_INFO(p) ((struct bvt_dom_info *)(p)->sched_priv)
#define CPU_INFO(cpu) ((struct bvt_cpu_info *)(schedule_data[cpu]).sched_priv)
#define CPU_SVT(cpu) (CPU_INFO(cpu)->svt)
#define MCU (s32)MICROSECS(100) /* Minimum unit */
#define MCU_ADVANCE 10 /* default weight */
@@ -98,10 +98,7 @@ static void __calc_evt(struct bvt_dom_info *inf)
*/
int bvt_alloc_task(struct task_struct *p)
{
DOM_INF(p)
= (struct bvt_dom_info *)kmem_cache_alloc(dom_info_cache,GFP_KERNEL);
if ( DOM_INF(p) == NULL )
if ( (BVT_INFO(p) = kmem_cache_alloc(dom_info_cache,GFP_KERNEL)) == NULL )
return -1;
return 0;
@@ -112,7 +109,7 @@ int bvt_alloc_task(struct task_struct *p)
*/
void bvt_add_task(struct task_struct *p)
{
struct bvt_dom_info *inf = DOM_INF(p);
struct bvt_dom_info *inf = BVT_INFO(p);
ASSERT(inf != NULL);
ASSERT(p != NULL);
@@ -151,10 +148,9 @@ void bvt_free_task(struct task_struct *p)
void bvt_wake_up(struct task_struct *p)
{
struct bvt_dom_info *inf = DOM_INF(p);
struct bvt_dom_info *inf = BVT_INFO(p);
ASSERT(inf != NULL);
/* set the BVT parameters */
if (inf->avt < CPU_SVT(p->processor))
@@ -172,7 +168,7 @@ void bvt_wake_up(struct task_struct *p)
*/
static long bvt_do_block(struct task_struct *p)
{
DOM_INF(p)->warpback = 0;
BVT_INFO(p)->warpback = 0;
return 0;
}
@@ -196,7 +192,7 @@ int bvt_adjdom(struct task_struct *p,
warpl = params->warpl,
warpu = params->warpu;
struct bvt_dom_info *inf = DOM_INF(p);
struct bvt_dom_info *inf = BVT_INFO(p);
/* Sanity -- this can avoid divide-by-zero. */
if ( mcu_adv == 0 )
@@ -229,7 +225,7 @@ static task_slice_t bvt_do_schedule(s_time_t now)
s32 ranfor; /* assume we never run longer than 2.1s! */
s32 mcus;
u32 next_evt, next_prime_evt, min_avt;
struct bvt_dom_info *prev_inf = DOM_INF(prev),
struct bvt_dom_info *prev_inf = BVT_INFO(prev),
*p_inf = NULL,
*next_inf = NULL,
*next_prime_inf = NULL;
@@ -271,7 +267,7 @@ static task_slice_t bvt_do_schedule(s_time_t now)
list_for_each ( tmp, &schedule_data[cpu].runqueue )
{
p = list_entry(tmp, struct task_struct, run_list);
p_inf = DOM_INF(p);
p_inf = BVT_INFO(p);
if ( p_inf->evt < next_evt )
{
@@ -331,8 +327,8 @@ static task_slice_t bvt_do_schedule(s_time_t now)
goto sched_done;
}
next_prime_inf = DOM_INF(next_prime);
next_inf = DOM_INF(next);
next_prime_inf = BVT_INFO(next_prime);
next_inf = BVT_INFO(next);
/*
* If we are here then we have two runnable tasks.
@@ -357,7 +353,7 @@ static task_slice_t bvt_do_schedule(s_time_t now)
static void bvt_dump_runq_el(struct task_struct *p)
{
struct bvt_dom_info *inf = DOM_INF(p);
struct bvt_dom_info *inf = BVT_INFO(p);
printk("mcua=0x%04lX ev=0x%08X av=0x%08X ",
inf->mcu_advance, inf->evt, inf->avt);
@@ -381,11 +377,11 @@ int bvt_init_scheduler()
for ( i = 0; i < NR_CPUS; i++ )
{
CPU_INF(i) = kmalloc(sizeof(struct bvt_cpu_info), GFP_KERNEL);
CPU_INFO(i) = kmalloc(sizeof(struct bvt_cpu_info), GFP_KERNEL);
if ( CPU_INF(i) == NULL )
if ( CPU_INFO(i) == NULL )
{
printk("Failed to allocate BVT scheduler private per-CPU memory!\n");
printk("Failed to allocate BVT scheduler per-CPU memory!\n");
return -1;
}
+5 -7
View File
@@ -112,9 +112,7 @@ struct task_struct *alloc_task_struct(void)
{
struct task_struct *p;
p=((struct task_struct *)kmem_cache_alloc(task_struct_cachep,GFP_KERNEL));
if ( p == NULL )
if ( (p = kmem_cache_alloc(task_struct_cachep,GFP_KERNEL)) == NULL )
return NULL;
memset(p, 0, sizeof(*p));
@@ -135,7 +133,7 @@ void sched_add_domain(struct task_struct *p)
{
p->state = TASK_STOPPED;
if( p->domain != IDLE_DOMAIN_ID )
if ( p->domain != IDLE_DOMAIN_ID )
{
/* Initialise the per-domain timer. */
init_ac_timer(&p->timer);
@@ -175,8 +173,8 @@ void init_idle_task(void)
unsigned long flags;
struct task_struct *p = current;
if ( SCHED_FN (alloc_task, p) < 0)
panic("Failed to allocate scheduler private data for idle task");
if ( SCHED_FN(alloc_task, p) < 0 )
panic("Failed to allocate scheduler private data for idle task");
SCHED_FN(add_task, p);
spin_lock_irqsave(&schedule_lock[p->processor], flags);
@@ -671,7 +669,7 @@ void dump_runq(u_char key, void *dev_id, struct pt_regs *regs)
s_time_t now = NOW();
int i;
printk("Scheduler: %s (%s)\n", ops.name, ops.opt_name);
printk("Scheduler: %s (%s)\n", ops.name, ops.opt_name);
SCHED_FN(dump_settings);
printk("NOW=0x%08X%08X\n", (u32)(now>>32), (u32)now);
for (i = 0; i < smp_num_cpus; i++) {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.