WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.2% of users enabled 2FA.

Commit b08ead5f authored by John Zhang's avatar John Zhang
Browse files

refactor: add cbconf.py to setup configuration for callbacks

parent ff79fd19
#!/usr/bin/env python3
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Functions to configure callback settings
from pathlib import Path
from mubench import CALLBACKS_DIR
from mubench.util import expandenv
def configure_cb_perfevent(cb_d, env):
assert 'libpfm4_dir' in cb_d, "libpfm4 install directory not specified"
libpfm4 = Path(expandenv(cb_d['libpfm4_dir'], env))
if not libpfm4.is_absolute():
libpfm4 = CALLBACKS_DIR / libpfm4 # default relative to CALLBACKS_DIR
cb_d['include_dirs'].extend([
str(libpfm4 / 'include'),
str(libpfm4 / 'util')
])
cb_d['library_dirs'].append(str(libpfm4 / 'lib'))
cb_d['libraries'].append('pfm')
cb_d['extra_srcs'].append(str(libpfm4 / 'util' / 'perf_util.c'))
cb_d['flags'].append('-pthread')
def configure_cb_clock(cb_d, env):
pass
def configure_cb_print(cb_d, env):
pass
\ No newline at end of file
......@@ -29,6 +29,7 @@ from mubench.util import expandenv, dictify, run_in_subproc, ExecutionFailure
from mubench.util import add_path_to_ld_library_path
from mubench.lang import get_lang, Language
from mubench.models.result import Result
from mubench.models import cbconf
logger = logging.getLogger(__name__)
......@@ -62,22 +63,27 @@ class TaskSet:
ts_env[v] = expandenv(ts_env[v], self.env)
self.env.update(ts_env)
# expand environs in benchmark args and callback param
benchmark['args'] = list(
map(lambda a: expandenv(str(a), self.env), benchmark['args']))
# configure callback
conf_func = getattr(cbconf, 'configure_cb_%(name)s' % callback)
conf_func(callback, self.env)
# expand environs in benchmark args and callback param and paths
def get_expanded_list(l):
return list(map(lambda a: expandenv(str(a), self.env), l))
benchmark['args'] = get_expanded_list(benchmark['args'])
callback['param'] = expandenv(callback['param'], self.env)
callback['include_dirs'] = get_expanded_list(callback['include_dirs'])
callback['library_dirs'] = get_expanded_list(callback['library_dirs'])
callback['extra_srcs'] = get_expanded_list(callback['extra_srcs'])
# compiled callback shared library
libext = '.dylib' if sys.platform == 'darwin' else '.so'
add_path_to_ld_library_path(str(self.output_dir), self.env)
self.callback['dylib'] = self.output_dir / ('libcb_%(name)s' % self.callback + libext)
# TODO: refactor this!
for d in self.callback['library_dirs']:
p = Path(expandenv(d, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
add_path_to_ld_library_path(str(p), self.env)
add_path_to_ld_library_path(d, self.env)
@staticmethod
def from_config_dict(name, conf_d, conf_dir=None):
......@@ -113,6 +119,10 @@ class TaskSet:
d['library_dirs'] = [] # default to []
if 'libraries' not in d or d['libraries'] is None:
d['libraries'] = [] # default to []
if 'extra_srcs' not in d or d['extra_srcs'] is None:
d['extra_srcs'] = [] # default to []
if 'flags' not in d or d['flags'] is None:
d['flags'] = [] # default to []
conf_d['callback'] = d
# add comparison
......@@ -220,36 +230,23 @@ class TaskSet:
cmd.extend(['-shared', '-fPIC'])
# include_dirs
for d in self.callback['include_dirs']:
p = Path(expandenv(d, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append('-I%s' % p)
cmd.extend(map(lambda s: '-I' + s, self.callback['include_dirs']))
# library_dirs
for d in self.callback['library_dirs']:
p = Path(expandenv(d, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append('-L%s' % p)
cmd.extend(map(lambda s: '-L' + s, self.callback['library_dirs']))
# libraries
for lib in self.callback['libraries']:
cmd.append('-l%s' % lib)
cmd.extend(map(lambda s: '-l' + s, self.callback['libraries']))
# flags
cmd.extend(self.callback.get('flags', []))
cmd.extend(self.callback['flags'])
# output
cmd.extend(['-o', self.callback['dylib']])
# source
cmd.append(CALLBACKS_DIR / ('cb_%(name)s.c' % self.callback))
for src in self.callback.get('extra_srcs', []):
p = Path(expandenv(src, self.env))
if not p.is_absolute():
p = CALLBACKS_DIR / p # default relative to CALLBACKS_DIR
cmd.append(p)
cmd.extend(self.callback['extra_srcs'])
run_in_subproc(cmd, self.env)
......
......@@ -15,7 +15,8 @@ tar xf libpfm-4.8.0.tar.gz
cd libpfm-4.8.0
sudo make PREFIX=$DEST_DIR install
sudo chown -R $USER:$USER $DEST_DIR
cp -r perf_examples $DEST_DIR
mkdir $DEST_DIR/util
cp perf_examples/perf_util.h perf_examples/perf_util.c $DEST_DIR/util
cd ..
rm libpfm-4.8.0.tar.gz
# rm -rf libpfm-4.8.0
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment