repo
stringlengths 1
152
⌀ | file
stringlengths 15
205
| code
stringlengths 0
41.6M
| file_length
int64 0
41.6M
| avg_line_length
float64 0
1.81M
| max_line_length
int64 0
12.7M
| extension_type
stringclasses 90
values |
---|---|---|---|---|---|---|
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/pkg-config.sh | # SPDX-License-Identifier: BSD-3-Clause
# Copyright 2014-2020, Intel Corporation
# Name of package
PACKAGE_NAME="pmdk"
# Name and email of package maintainer
PACKAGE_MAINTAINER="Piotr Balcer <[email protected]>"
# Brief description of the package
PACKAGE_SUMMARY="Persistent Memory Development Kit"
# Full description of the package
PACKAGE_DESCRIPTION="The collection of libraries and utilities for Persistent Memory Programming"
# Website
PACKAGE_URL="https://pmem.io/pmdk"
| 486 | 26.055556 | 97 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/style_check.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# utils/style_check.sh -- common style checking script
#
set -e
ARGS=("$@")
CSTYLE_ARGS=()
CLANG_ARGS=()
FLAKE8_ARGS=()
CHECK_TYPE=$1
[ -z "$clang_format_bin" ] && which clang-format-9 >/dev/null &&
clang_format_bin=clang-format-9
[ -z "$clang_format_bin" ] && which clang-format >/dev/null &&
clang_format_bin=clang-format
[ -z "$clang_format_bin" ] && clang_format_bin=clang-format
#
# print script usage
#
function usage() {
echo "$0 <check|format> [C/C++ files]"
}
#
# require clang-format version 9.0
#
function check_clang_version() {
set +e
which ${clang_format_bin} &> /dev/null && ${clang_format_bin} --version |\
grep "version 9\.0"\
&> /dev/null
if [ $? -ne 0 ]; then
echo "SKIP: requires clang-format version 9.0"
exit 0
fi
set -e
}
#
# run old cstyle check
#
function run_cstyle() {
if [ $# -eq 0 ]; then
return
fi
${cstyle_bin} -pP $@
}
#
# generate diff with clang-format rules
#
function run_clang_check() {
if [ $# -eq 0 ]; then
return
fi
check_clang_version
for file in $@
do
LINES=$(${clang_format_bin} -style=file $file |\
git diff --no-index $file - | wc -l)
if [ $LINES -ne 0 ]; then
${clang_format_bin} -style=file $file | git diff --no-index $file -
fi
done
}
#
# in-place format according to clang-format rules
#
function run_clang_format() {
if [ $# -eq 0 ]; then
return
fi
check_clang_version
${clang_format_bin} -style=file -i $@
}
function run_flake8() {
if [ $# -eq 0 ]; then
return
fi
${flake8_bin} --exclude=testconfig.py,envconfig.py $@
}
for ((i=1; i<$#; i++)) {
IGNORE="$(dirname ${ARGS[$i]})/.cstyleignore"
if [ -e $IGNORE ]; then
if grep -q ${ARGS[$i]} $IGNORE ; then
echo "SKIP ${ARGS[$i]}"
continue
fi
fi
case ${ARGS[$i]} in
*.[ch]pp)
CLANG_ARGS+="${ARGS[$i]} "
;;
*.[ch])
CSTYLE_ARGS+="${ARGS[$i]} "
;;
*.py)
FLAKE8_ARGS+="${ARGS[$i]} "
;;
*)
echo "Unknown argument"
exit 1
;;
esac
}
case $CHECK_TYPE in
check)
run_cstyle ${CSTYLE_ARGS}
run_clang_check ${CLANG_ARGS}
run_flake8 ${FLAKE8_ARGS}
;;
format)
run_clang_format ${CLANG_ARGS}
;;
*)
echo "Invalid parameters"
usage
exit 1
;;
esac
| 2,274 | 15.485507 | 75 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/version.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2020, Intel Corporation
#
# utils/version.sh -- determine project's version
#
set -e
if [ -f "$1/VERSION" ]; then
cat "$1/VERSION"
exit 0
fi
if [ -f $1/GIT_VERSION ]; then
echo -n "\$Format:%h\$" | cmp -s $1/GIT_VERSION - && true
if [ $? -eq 0 ]; then
PARSE_GIT_VERSION=0
else
PARSE_GIT_VERSION=1
fi
else
PARSE_GIT_VERSION=0
fi
LATEST_RELEASE=$(cat $1/ChangeLog | grep "* Version" | cut -d " " -f 3 | sort -rd | head -n1)
if [ $PARSE_GIT_VERSION -eq 1 ]; then
GIT_VERSION_HASH=$(cat $1/GIT_VERSION)
if [ -n "$GIT_VERSION_HASH" ]; then
echo "$LATEST_RELEASE+git.$GIT_VERSION_HASH"
exit 0
fi
fi
cd "$1"
GIT_DESCRIBE=$(git describe 2>/dev/null) && true
if [ -n "$GIT_DESCRIBE" ]; then
# 1.5-19-gb8f78a329 -> 1.5+git19.gb8f78a329
# 1.5-rc1-19-gb8f78a329 -> 1.5-rc1+git19.gb8f78a329
echo "$GIT_DESCRIBE" | sed "s/\([0-9.]*\)-rc\([0-9]*\)-\([0-9]*\)-\([0-9a-g]*\)/\1-rc\2+git\3.\4/" | sed "s/\([0-9.]*\)-\([0-9]*\)-\([0-9a-g]*\)/\1+git\2.\3/"
exit 0
fi
# try commit it, git describe can fail when there are no tags (e.g. with shallow clone, like on Travis)
GIT_COMMIT=$(git log -1 --format=%h) && true
if [ -n "$GIT_COMMIT" ]; then
echo "$LATEST_RELEASE+git.$GIT_COMMIT"
exit 0
fi
cd - >/dev/null
# If nothing works, try to get version from directory name
VER=$(basename `realpath "$1"` | sed 's/pmdk[-]*\([0-9a-z.+-]*\).*/\1/')
if [ -n "$VER" ]; then
echo "$VER"
exit 0
fi
exit 1
| 1,489 | 22.650794 | 159 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/check_license/file-exceptions.sh | #!/bin/sh -e
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
# file-exceptions.sh - filter out files not checked for copyright and license
grep -v -E -e '/queue.h$' -e '/getopt.h$' -e '/getopt.c$' -e 'src/core/valgrind/' -e '/testconfig\...$'
| 278 | 33.875 | 103 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/check_license/check-headers.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
# check-headers.sh - check copyright and license in source files
SELF=$0
function usage() {
echo "Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a]"
echo " -h, --help this help message"
echo " -v, --verbose verbose mode"
echo " -a, --all check all files (only modified files are checked by default)"
}
if [ "$#" -lt 2 ]; then
usage >&2
exit 2
fi
SOURCE_ROOT=$1
shift
LICENSE=$1
shift
PATTERN=`mktemp`
TMP=`mktemp`
TMP2=`mktemp`
TEMPFILE=`mktemp`
rm -f $PATTERN $TMP $TMP2
if [ "$1" == "-h" -o "$1" == "--help" ]; then
usage
exit 0
fi
export GIT="git -C ${SOURCE_ROOT}"
$GIT rev-parse || exit 1
if [ -f $SOURCE_ROOT/.git/shallow ]; then
SHALLOW_CLONE=1
echo
echo "Warning: This is a shallow clone. Checking dates in copyright headers"
echo " will be skipped in case of files that have no history."
echo
else
SHALLOW_CLONE=0
fi
VERBOSE=0
CHECK_ALL=0
while [ "$1" != "" ]; do
case $1 in
-v|--verbose)
VERBOSE=1
;;
-a|--all)
CHECK_ALL=1
;;
esac
shift
done
if [ $CHECK_ALL -eq 0 ]; then
CURRENT_COMMIT=$($GIT log --pretty=%H -1)
MERGE_BASE=$($GIT merge-base HEAD origin/master 2>/dev/null)
[ -z $MERGE_BASE ] && \
MERGE_BASE=$($GIT log --pretty="%cN:%H" | grep GitHub | head -n1 | cut -d: -f2)
[ -z $MERGE_BASE -o "$CURRENT_COMMIT" = "$MERGE_BASE" ] && \
CHECK_ALL=1
fi
if [ $CHECK_ALL -eq 1 ]; then
echo "Checking copyright headers of all files..."
GIT_COMMAND="ls-tree -r --name-only HEAD"
else
if [ $VERBOSE -eq 1 ]; then
echo
echo "Warning: will check copyright headers of modified files only,"
echo " in order to check all files issue the following command:"
echo " $ $SELF <source_root_path> <license_tag> -a"
echo " (e.g.: $ $SELF $SOURCE_ROOT $LICENSE -a)"
echo
fi
echo "Checking copyright headers of modified files only..."
GIT_COMMAND="diff --name-only $MERGE_BASE $CURRENT_COMMIT"
fi
FILES=$($GIT $GIT_COMMAND | ${SOURCE_ROOT}/utils/check_license/file-exceptions.sh | \
grep -E -e '*\.[chs]$' -e '*\.[ch]pp$' -e '*\.sh$' \
-e '*\.py$' -e '*\.link$' -e 'Makefile*' -e 'TEST*' \
-e '/common.inc$' -e '/match$' -e '/check_whitespace$' \
-e 'LICENSE$' -e 'CMakeLists.txt$' -e '*\.cmake$' | \
xargs)
RV=0
for file in $FILES ; do
# The src_path is a path which should be used in every command except git.
# git is called with -C flag so filepaths should be relative to SOURCE_ROOT
src_path="${SOURCE_ROOT}/$file"
[ ! -f $src_path ] && continue
# ensure that file is UTF-8 encoded
ENCODING=`file -b --mime-encoding $src_path`
iconv -f $ENCODING -t "UTF-8" $src_path > $TEMPFILE
if ! grep -q "SPDX-License-Identifier: $LICENSE" $src_path; then
echo >&2 "$src_path:1: no $LICENSE SPDX tag found "
RV=1
fi
if [ $SHALLOW_CLONE -eq 0 ]; then
$GIT log --no-merges --format="%ai %aE" -- $file | sort > $TMP
else
# mark the grafted commits (commits with no parents)
$GIT log --no-merges --format="%ai %aE grafted-%p-commit" -- $file | sort > $TMP
fi
# skip checking dates for non-Intel commits
[[ ! $(tail -n1 $TMP) =~ "@intel.com" ]] && continue
# skip checking dates for new files
[ $(cat $TMP | wc -l) -le 1 ] && continue
# grep out the grafted commits (commits with no parents)
# and skip checking dates for non-Intel commits
grep -v -e "grafted--commit" $TMP | grep -e "@intel.com" > $TMP2
[ $(cat $TMP2 | wc -l) -eq 0 ] && continue
FIRST=`head -n1 $TMP2`
LAST=` tail -n1 $TMP2`
YEARS=`sed '
/Copyright [0-9-]\+.*, Intel Corporation/!d
s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/
s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
if [ -z "$YEARS" ]; then
echo >&2 "$src_path:1: No copyright years found"
RV=1
continue
fi
HEADER_FIRST=`echo $YEARS | cut -d"-" -f1`
HEADER_LAST=` echo $YEARS | cut -d"-" -f2`
COMMIT_FIRST=`echo $FIRST | cut -d"-" -f1`
COMMIT_LAST=` echo $LAST | cut -d"-" -f1`
if [ "$COMMIT_FIRST" != "" -a "$COMMIT_LAST" != "" ]; then
if [ $HEADER_LAST -lt $COMMIT_LAST ]; then
if [ $HEADER_FIRST -lt $COMMIT_FIRST ]; then
COMMIT_FIRST=$HEADER_FIRST
fi
COMMIT_LAST=`date +%G`
if [ $COMMIT_FIRST -eq $COMMIT_LAST ]; then
NEW=$COMMIT_LAST
else
NEW=$COMMIT_FIRST-$COMMIT_LAST
fi
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
RV=1
fi
else
echo "$file:1: unknown commit dates" >&2
RV=1
fi
done
rm -f $TMP $TMP2 $TEMPFILE
$(dirname "$0")/check-ms-license.pl $FILES
# check if error found
if [ $RV -eq 0 ]; then
echo "Copyright headers are OK."
else
echo "Error(s) in copyright headers found!" >&2
fi
exit $RV
| 4,703 | 25.426966 | 87 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/build-local.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2020, Intel Corporation
#
# build-local.sh - runs a Docker container from a Docker image with environment
# prepared for building PMDK project and starts building PMDK
#
# this script is for building PMDK locally (not on Travis)
#
# Notes:
# - run this script from its location or set the variable 'HOST_WORKDIR' to
# where the root of the PMDK project is on the host machine,
# - set variables 'OS' and 'OS_VER' properly to a system you want to build PMDK
# on (for proper values take a look on the list of Dockerfiles at the
# utils/docker/images directory), eg. OS=ubuntu, OS_VER=16.04.
# - set 'KEEP_TEST_CONFIG' variable to 1 if you do not want the tests to be
# reconfigured (your current test configuration will be preserved and used)
# - tests with Device Dax are not supported by pcheck yet, so do not provide
# these devices in your configuration
#
set -e
# Environment variables that can be customized (default values are after dash):
export KEEP_CONTAINER=${KEEP_CONTAINER:-0}
export KEEP_TEST_CONFIG=${KEEP_TEST_CONFIG:-0}
export TEST_BUILD=${TEST_BUILD:-all}
export REMOTE_TESTS=${REMOTE_TESTS:-1}
export MAKE_PKG=${MAKE_PKG:-0}
export EXTRA_CFLAGS=${EXTRA_CFLAGS}
export EXTRA_CXXFLAGS=${EXTRA_CXXFLAGS:-}
export PMDK_CC=${PMDK_CC:-gcc}
export PMDK_CXX=${PMDK_CXX:-g++}
export EXPERIMENTAL=${EXPERIMENTAL:-n}
export VALGRIND=${VALGRIND:-1}
export DOCKERHUB_REPO=${DOCKERHUB_REPO:-pmem/pmdk}
export GITHUB_REPO=${GITHUB_REPO:-pmem/pmdk}
if [[ -z "$OS" || -z "$OS_VER" ]]; then
echo "ERROR: The variables OS and OS_VER have to be set " \
"(eg. OS=ubuntu, OS_VER=16.04)."
exit 1
fi
if [[ -z "$HOST_WORKDIR" ]]; then
HOST_WORKDIR=$(readlink -f ../..)
fi
if [[ "$KEEP_CONTAINER" != "1" ]]; then
RM_SETTING=" --rm"
fi
imageName=${DOCKERHUB_REPO}:1.9-${OS}-${OS_VER}-${CI_CPU_ARCH}
containerName=pmdk-${OS}-${OS_VER}
if [[ $MAKE_PKG -eq 1 ]] ; then
command="./run-build-package.sh"
else
command="./run-build.sh"
fi
if [ -n "$DNS_SERVER" ]; then DNS_SETTING=" --dns=$DNS_SERVER "; fi
if [ -z "$NDCTL_ENABLE" ]; then ndctl_enable=; else ndctl_enable="--env NDCTL_ENABLE=$NDCTL_ENABLE"; fi
WORKDIR=/pmdk
SCRIPTSDIR=$WORKDIR/utils/docker
# Check if we are running on a CI (Travis or GitHub Actions)
[ -n "$GITHUB_ACTIONS" -o -n "$TRAVIS" ] && CI_RUN="YES" || CI_RUN="NO"
echo Building ${OS}-${OS_VER}
# Run a container with
# - environment variables set (--env)
# - host directory containing PMDK source mounted (-v)
# - a tmpfs /tmp with the necessary size and permissions (--tmpfs)*
# - working directory set (-w)
#
# * We need a tmpfs /tmp inside docker but we cannot run it with --privileged
# and do it from inside, so we do using this docker-run option.
# By default --tmpfs add nosuid,nodev,noexec to the mount flags, we don't
# want that and just to make sure we add the usually default rw,relatime just
# in case docker change the defaults.
docker run --name=$containerName -ti \
$RM_SETTING \
$DNS_SETTING \
--env http_proxy=$http_proxy \
--env https_proxy=$https_proxy \
--env CC=$PMDK_CC \
--env CXX=$PMDK_CXX \
--env VALGRIND=$VALGRIND \
--env EXTRA_CFLAGS=$EXTRA_CFLAGS \
--env EXTRA_CXXFLAGS=$EXTRA_CXXFLAGS \
--env EXTRA_LDFLAGS=$EXTRA_LDFLAGS \
--env REMOTE_TESTS=$REMOTE_TESTS \
--env CONFIGURE_TESTS=$CONFIGURE_TESTS \
--env TEST_BUILD=$TEST_BUILD \
--env WORKDIR=$WORKDIR \
--env EXPERIMENTAL=$EXPERIMENTAL \
--env SCRIPTSDIR=$SCRIPTSDIR \
--env KEEP_TEST_CONFIG=$KEEP_TEST_CONFIG \
--env CI_RUN=$CI_RUN \
--env BLACKLIST_FILE=$BLACKLIST_FILE \
$ndctl_enable \
--tmpfs /tmp:rw,relatime,suid,dev,exec,size=6G \
-v $HOST_WORKDIR:$WORKDIR \
-v /etc/localtime:/etc/localtime \
$DAX_SETTING \
-w $SCRIPTSDIR \
$imageName $command
| 3,812 | 33.044643 | 103 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/run-build.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# run-build.sh - is called inside a Docker container; prepares the environment
# and starts a build of PMDK project.
#
set -e
# Prepare build environment
./prepare-for-build.sh
# Build all and run tests
cd $WORKDIR
if [ "$SRC_CHECKERS" != "0" ]; then
make -j$(nproc) check-license
make -j$(nproc) cstyle
fi
make -j$(nproc)
make -j$(nproc) test
# do not change -j2 to -j$(nproc) in case of tests (make check/pycheck)
make -j2 pcheck TEST_BUILD=$TEST_BUILD
# do not change -j2 to -j$(nproc) in case of tests (make check/pycheck)
make -j2 pycheck
make -j$(nproc) DESTDIR=/tmp source
# Create PR with generated docs
if [[ "$AUTO_DOC_UPDATE" == "1" ]]; then
echo "Running auto doc update"
./utils/docker/run-doc-update.sh
fi
| 848 | 23.257143 | 78 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/prepare-for-build.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# prepare-for-build.sh - is called inside a Docker container; prepares
# the environment inside a Docker container for
# running build of PMDK project.
#
set -e
# This should be run only on CIs
if [ "$CI_RUN" == "YES" ]; then
# Make sure $WORKDIR has correct access rights
# - set them to the current UID and GID
echo $USERPASS | sudo -S chown -R $(id -u).$(id -g) $WORKDIR
fi
# Configure tests (e.g. ssh for remote tests) unless the current configuration
# should be preserved
KEEP_TEST_CONFIG=${KEEP_TEST_CONFIG:-0}
if [[ "$KEEP_TEST_CONFIG" == 0 ]]; then
./configure-tests.sh
fi
| 739 | 27.461538 | 78 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/set-ci-vars.sh | #!/usr/bin/env bash
#
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2020, Intel Corporation
#
# set-ci-vars.sh -- set CI variables common for both:
# Travis and GitHub Actions CIs
#
set -e
function get_commit_range_from_last_merge {
# get commit id of the last merge
LAST_MERGE=$(git log --merges --pretty=%H -1)
LAST_COMMIT=$(git log --pretty=%H -1)
if [ "$LAST_MERGE" == "$LAST_COMMIT" ]; then
# GitHub Actions commits its own merge in case of pull requests
# so the first merge commit has to be skipped.
LAST_MERGE=$(git log --merges --pretty=%H -2 | tail -n1)
fi
if [ "$LAST_MERGE" == "" ]; then
# possible in case of shallow clones
# or new repos with no merge commits yet
# - pick up the first commit
LAST_MERGE=$(git log --pretty=%H | tail -n1)
fi
COMMIT_RANGE="$LAST_MERGE..HEAD"
# make sure it works now
if ! git rev-list $COMMIT_RANGE >/dev/null; then
COMMIT_RANGE=""
fi
echo $COMMIT_RANGE
}
COMMIT_RANGE_FROM_LAST_MERGE=$(get_commit_range_from_last_merge)
if [ -n "$TRAVIS" ]; then
CI_COMMIT=$TRAVIS_COMMIT
CI_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../..}"
CI_BRANCH=$TRAVIS_BRANCH
CI_EVENT_TYPE=$TRAVIS_EVENT_TYPE
CI_REPO_SLUG=$TRAVIS_REPO_SLUG
# CI_COMMIT_RANGE is usually invalid for force pushes - fix it when used
# with non-upstream repository
if [ -n "$CI_COMMIT_RANGE" -a "$CI_REPO_SLUG" != "$GITHUB_REPO" ]; then
if ! git rev-list $CI_COMMIT_RANGE; then
CI_COMMIT_RANGE=$COMMIT_RANGE_FROM_LAST_MERGE
fi
fi
case "$TRAVIS_CPU_ARCH" in
"amd64")
CI_CPU_ARCH="x86_64"
;;
*)
CI_CPU_ARCH=$TRAVIS_CPU_ARCH
;;
esac
elif [ -n "$GITHUB_ACTIONS" ]; then
CI_COMMIT=$GITHUB_SHA
CI_COMMIT_RANGE=$COMMIT_RANGE_FROM_LAST_MERGE
CI_BRANCH=$(echo $GITHUB_REF | cut -d'/' -f3)
CI_REPO_SLUG=$GITHUB_REPOSITORY
CI_CPU_ARCH="x86_64" # GitHub Actions supports only x86_64
case "$GITHUB_EVENT_NAME" in
"schedule")
CI_EVENT_TYPE="cron"
;;
*)
CI_EVENT_TYPE=$GITHUB_EVENT_NAME
;;
esac
else
CI_COMMIT=$(git log --pretty=%H -1)
CI_COMMIT_RANGE=$COMMIT_RANGE_FROM_LAST_MERGE
CI_CPU_ARCH="x86_64"
fi
export CI_COMMIT=$CI_COMMIT
export CI_COMMIT_RANGE=$CI_COMMIT_RANGE
export CI_BRANCH=$CI_BRANCH
export CI_EVENT_TYPE=$CI_EVENT_TYPE
export CI_REPO_SLUG=$CI_REPO_SLUG
export CI_CPU_ARCH=$CI_CPU_ARCH
echo CI_COMMIT=$CI_COMMIT
echo CI_COMMIT_RANGE=$CI_COMMIT_RANGE
echo CI_BRANCH=$CI_BRANCH
echo CI_EVENT_TYPE=$CI_EVENT_TYPE
echo CI_REPO_SLUG=$CI_REPO_SLUG
echo CI_CPU_ARCH=$CI_CPU_ARCH
| 2,481 | 24.587629 | 73 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/build-CI.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# build-CI.sh - runs a Docker container from a Docker image with environment
# prepared for building PMDK project and starts building PMDK
#
# this script is used for building PMDK on Travis and GitHub Actions CIs
#
set -e
source $(dirname $0)/set-ci-vars.sh
source $(dirname $0)/set-vars.sh
source $(dirname $0)/valid-branches.sh
if [[ "$CI_EVENT_TYPE" != "cron" && "$CI_BRANCH" != "coverity_scan" \
&& "$COVERITY" -eq 1 ]]; then
echo "INFO: Skip Coverity scan job if build is triggered neither by " \
"'cron' nor by a push to 'coverity_scan' branch"
exit 0
fi
if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\
&& "$COVERITY" -ne 1 ]]; then
echo "INFO: Skip regular jobs if build is triggered either by 'cron'" \
" or by a push to 'coverity_scan' branch"
exit 0
fi
if [[ -z "$OS" || -z "$OS_VER" ]]; then
echo "ERROR: The variables OS and OS_VER have to be set properly " \
"(eg. OS=ubuntu, OS_VER=16.04)."
exit 1
fi
if [[ -z "$HOST_WORKDIR" ]]; then
echo "ERROR: The variable HOST_WORKDIR has to contain a path to " \
"the root of the PMDK project on the host machine"
exit 1
fi
if [[ -z "$TEST_BUILD" ]]; then
TEST_BUILD=all
fi
imageName=${DOCKERHUB_REPO}:1.9-${OS}-${OS_VER}-${CI_CPU_ARCH}
containerName=pmdk-${OS}-${OS_VER}
if [[ $MAKE_PKG -eq 0 ]] ; then command="./run-build.sh"; fi
if [[ $MAKE_PKG -eq 1 ]] ; then command="./run-build-package.sh"; fi
if [[ $COVERAGE -eq 1 ]] ; then command="./run-coverage.sh"; ci_env=`bash <(curl -s https://codecov.io/env)`; fi
if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\
&& "$COVERITY" -eq 1 ]]; then
command="./run-coverity.sh"
fi
if [ -n "$DNS_SERVER" ]; then DNS_SETTING=" --dns=$DNS_SERVER "; fi
if [[ -f $CI_FILE_SKIP_BUILD_PKG_CHECK ]]; then BUILD_PACKAGE_CHECK=n; else BUILD_PACKAGE_CHECK=y; fi
if [ -z "$NDCTL_ENABLE" ]; then ndctl_enable=; else ndctl_enable="--env NDCTL_ENABLE=$NDCTL_ENABLE"; fi
if [[ $UBSAN -eq 1 ]]; then for x in C CPP LD; do declare EXTRA_${x}FLAGS=-fsanitize=undefined; done; fi
# Only run doc update on $GITHUB_REPO master or stable branch
if [[ -z "${CI_BRANCH}" || -z "${TARGET_BRANCHES[${CI_BRANCH}]}" || "$CI_EVENT_TYPE" == "pull_request" || "$CI_REPO_SLUG" != "${GITHUB_REPO}" ]]; then
AUTO_DOC_UPDATE=0
fi
# Check if we are running on a CI (Travis or GitHub Actions)
[ -n "$GITHUB_ACTIONS" -o -n "$TRAVIS" ] && CI_RUN="YES" || CI_RUN="NO"
# We have a blacklist only for ppc64le arch
if [[ "$CI_CPU_ARCH" == ppc64le ]] ; then BLACKLIST_FILE=../../utils/docker/ppc64le.blacklist; fi
# docker on travis + ppc64le runs inside an LXD container and for security
# limits what can be done inside it, and as such, `docker run` fails with
# > the input device is not a TTY
# when using -t because of limited permissions to /dev imposed by LXD.
if [[ -n "$TRAVIS" && "$CI_CPU_ARCH" == ppc64le ]] || [[ -n "$GITHUB_ACTIONS" ]]; then
TTY=''
else
TTY='-t'
fi
WORKDIR=/pmdk
SCRIPTSDIR=$WORKDIR/utils/docker
# Run a container with
# - environment variables set (--env)
# - host directory containing PMDK source mounted (-v)
# - a tmpfs /tmp with the necessary size and permissions (--tmpfs)*
# - working directory set (-w)
#
# * We need a tmpfs /tmp inside docker but we cannot run it with --privileged
# and do it from inside, so we do using this docker-run option.
# By default --tmpfs add nosuid,nodev,noexec to the mount flags, we don't
# want that and just to make sure we add the usually default rw,relatime just
# in case docker change the defaults.
docker run --rm --name=$containerName -i $TTY \
$DNS_SETTING \
$ci_env \
--env http_proxy=$http_proxy \
--env https_proxy=$https_proxy \
--env AUTO_DOC_UPDATE=$AUTO_DOC_UPDATE \
--env CC=$PMDK_CC \
--env CXX=$PMDK_CXX \
--env VALGRIND=$VALGRIND \
--env EXTRA_CFLAGS=$EXTRA_CFLAGS \
--env EXTRA_CXXFLAGS=$EXTRA_CXXFLAGS \
--env EXTRA_LDFLAGS=$EXTRA_LDFLAGS \
--env REMOTE_TESTS=$REMOTE_TESTS \
--env TEST_BUILD=$TEST_BUILD \
--env WORKDIR=$WORKDIR \
--env EXPERIMENTAL=$EXPERIMENTAL \
--env BUILD_PACKAGE_CHECK=$BUILD_PACKAGE_CHECK \
--env SCRIPTSDIR=$SCRIPTSDIR \
--env TRAVIS=$TRAVIS \
--env CI_COMMIT_RANGE=$CI_COMMIT_RANGE \
--env CI_COMMIT=$CI_COMMIT \
--env CI_REPO_SLUG=$CI_REPO_SLUG \
--env CI_BRANCH=$CI_BRANCH \
--env CI_EVENT_TYPE=$CI_EVENT_TYPE \
--env DOC_UPDATE_GITHUB_TOKEN=$DOC_UPDATE_GITHUB_TOKEN \
--env COVERITY_SCAN_TOKEN=$COVERITY_SCAN_TOKEN \
--env COVERITY_SCAN_NOTIFICATION_EMAIL=$COVERITY_SCAN_NOTIFICATION_EMAIL \
--env FAULT_INJECTION=$FAULT_INJECTION \
--env GITHUB_ACTION=$GITHUB_ACTION \
--env GITHUB_HEAD_REF=$GITHUB_HEAD_REF \
--env GITHUB_REPO=$GITHUB_REPO \
--env GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
--env GITHUB_REF=$GITHUB_REF \
--env GITHUB_RUN_ID=$GITHUB_RUN_ID \
--env GITHUB_SHA=$GITHUB_SHA \
--env CI_RUN=$CI_RUN \
--env SRC_CHECKERS=$SRC_CHECKERS \
--env BLACKLIST_FILE=$BLACKLIST_FILE \
$ndctl_enable \
--tmpfs /tmp:rw,relatime,suid,dev,exec,size=6G \
-v $HOST_WORKDIR:$WORKDIR \
-v /etc/localtime:/etc/localtime \
-w $SCRIPTSDIR \
$imageName $command
| 5,193 | 35.069444 | 150 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/run-build-package.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2019, Intel Corporation
#
# run-build-package.sh - is called inside a Docker container; prepares
# the environment and starts a build of PMDK project.
#
set -e
# Prepare build enviromnent
./prepare-for-build.sh
# Create fake tag, so that package has proper 'version' field
git config user.email "[email protected]"
git config user.name "test package"
git tag -a 1.4.99 -m "1.4" HEAD~1 || true
# Build all and run tests
cd $WORKDIR
export PCHECK_OPTS="-j2 BLACKLIST_FILE=${BLACKLIST_FILE}"
make -j$(nproc) $PACKAGE_MANAGER
# Install packages
if [[ "$PACKAGE_MANAGER" == "dpkg" ]]; then
cd $PACKAGE_MANAGER
echo $USERPASS | sudo -S dpkg --install *.deb
else
RPM_ARCH=$(uname -m)
cd $PACKAGE_MANAGER/$RPM_ARCH
echo $USERPASS | sudo -S rpm --install *.rpm
fi
# Compile and run standalone test
cd $WORKDIR/utils/docker/test_package
make -j$(nproc) LIBPMEMOBJ_MIN_VERSION=1.4
./test_package testfile1
# Use pmreorder installed in the system
pmreorder_version="$(pmreorder -v)"
pmreorder_pattern="pmreorder\.py .+$"
(echo "$pmreorder_version" | grep -Ev "$pmreorder_pattern") && echo "pmreorder version failed" && exit 1
touch testfile2
touch logfile1
pmreorder -p testfile2 -l logfile1
| 1,293 | 25.958333 | 104 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/run-doc-update.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019-2020, Intel Corporation
set -e
source `dirname $0`/valid-branches.sh
BOT_NAME="pmem-bot"
USER_NAME="pmem"
REPO_NAME="pmdk"
ORIGIN="https://${DOC_UPDATE_GITHUB_TOKEN}@github.com/${BOT_NAME}/${REPO_NAME}"
UPSTREAM="https://github.com/${USER_NAME}/${REPO_NAME}"
# master or stable-* branch
TARGET_BRANCH=${CI_BRANCH}
VERSION=${TARGET_BRANCHES[$TARGET_BRANCH]}
if [ -z $VERSION ]; then
echo "Target location for branch $TARGET_BRANCH is not defined."
exit 1
fi
# Clone bot repo
git clone ${ORIGIN}
cd ${REPO_NAME}
git remote add upstream ${UPSTREAM}
git config --local user.name ${BOT_NAME}
git config --local user.email "[email protected]"
git remote update
git checkout -B ${TARGET_BRANCH} upstream/${TARGET_BRANCH}
# Copy man & PR web md
cd ./doc
make -j$(nproc) web
cd ..
mv ./doc/web_linux ../
mv ./doc/web_windows ../
mv ./doc/generated/libs_map.yml ../
# Checkout gh-pages and copy docs
GH_PAGES_NAME="gh-pages-for-${TARGET_BRANCH}"
git checkout -B $GH_PAGES_NAME upstream/gh-pages
git clean -dfx
rsync -a ../web_linux/ ./manpages/linux/${VERSION}/
rsync -a ../web_windows/ ./manpages/windows/${VERSION}/ \
--exclude='librpmem' \
--exclude='rpmemd' --exclude='pmreorder' \
--exclude='daxio'
rm -r ../web_linux
rm -r ../web_windows
if [ $TARGET_BRANCH = "master" ]; then
[ ! -d _data ] && mkdir _data
cp ../libs_map.yml _data
fi
# Add and push changes.
# git commit command may fail if there is nothing to commit.
# In that case we want to force push anyway (there might be open pull request
# with changes which were reverted).
git add -A
git commit -m "doc: automatic gh-pages docs update" && true
git push -f ${ORIGIN} $GH_PAGES_NAME
GITHUB_TOKEN=${DOC_UPDATE_GITHUB_TOKEN} hub pull-request -f \
-b ${USER_NAME}:gh-pages \
-h ${BOT_NAME}:${GH_PAGES_NAME} \
-m "doc: automatic gh-pages docs update" && true
exit 0
| 1,924 | 24 | 79 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/pull-or-rebuild-image.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# pull-or-rebuild-image.sh - rebuilds the Docker image used in the
# current Travis build if necessary.
#
# The script rebuilds the Docker image if the Dockerfile for the current
# OS version (Dockerfile.${OS}-${OS_VER}) or any .sh script from the directory
# with Dockerfiles were modified and committed.
#
# If the Travis build is not of the "pull_request" type (i.e. in case of
# merge after pull_request) and it succeed, the Docker image should be pushed
# to the Docker Hub repository. An empty file is created to signal that to
# further scripts.
#
# If the Docker image does not have to be rebuilt, it will be pulled from
# Docker Hub.
#
set -e
source $(dirname $0)/set-ci-vars.sh
source $(dirname $0)/set-vars.sh
if [[ "$CI_EVENT_TYPE" != "cron" && "$CI_BRANCH" != "coverity_scan" \
&& "$COVERITY" -eq 1 ]]; then
echo "INFO: Skip Coverity scan job if build is triggered neither by " \
"'cron' nor by a push to 'coverity_scan' branch"
exit 0
fi
if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\
&& "$COVERITY" -ne 1 ]]; then
echo "INFO: Skip regular jobs if build is triggered either by 'cron'" \
" or by a push to 'coverity_scan' branch"
exit 0
fi
if [[ -z "$OS" || -z "$OS_VER" ]]; then
echo "ERROR: The variables OS and OS_VER have to be set properly " \
"(eg. OS=ubuntu, OS_VER=16.04)."
exit 1
fi
if [[ -z "$HOST_WORKDIR" ]]; then
echo "ERROR: The variable HOST_WORKDIR has to contain a path to " \
"the root of the PMDK project on the host machine"
exit 1
fi
# Find all the commits for the current build
if [ -n "$CI_COMMIT_RANGE" ]; then
commits=$(git rev-list $CI_COMMIT_RANGE)
else
commits=$CI_COMMIT
fi
echo "Commits in the commit range:"
for commit in $commits; do echo $commit; done
# Get the list of files modified by the commits
files=$(for commit in $commits; do git diff-tree --no-commit-id --name-only \
-r $commit; done | sort -u)
echo "Files modified within the commit range:"
for file in $files; do echo $file; done
# Path to directory with Dockerfiles and image building scripts
images_dir_name=images
base_dir=utils/docker/$images_dir_name
# Check if committed file modifications require the Docker image to be rebuilt
for file in $files; do
# Check if modified files are relevant to the current build
if [[ $file =~ ^($base_dir)\/Dockerfile\.($OS)-($OS_VER)$ ]] \
|| [[ $file =~ ^($base_dir)\/.*\.sh$ ]]
then
# Rebuild Docker image for the current OS version
echo "Rebuilding the Docker image for the Dockerfile.$OS-$OS_VER"
pushd $images_dir_name
./build-image.sh ${OS}-${OS_VER} ${CI_CPU_ARCH}
popd
# Check if the image has to be pushed to Docker Hub
# (i.e. the build is triggered by commits to the $GITHUB_REPO
# repository's stable-* or master branch, and the Travis build is not
# of the "pull_request" type). In that case, create the empty
# file.
if [[ "$CI_REPO_SLUG" == "$GITHUB_REPO" \
&& ($CI_BRANCH == stable-* || $CI_BRANCH == devel-* || $CI_BRANCH == master) \
&& $CI_EVENT_TYPE != "pull_request" \
&& $PUSH_IMAGE == "1" ]]
then
echo "The image will be pushed to Docker Hub"
touch $CI_FILE_PUSH_IMAGE_TO_REPO
else
echo "Skip pushing the image to Docker Hub"
fi
if [[ $PUSH_IMAGE == "1" ]]
then
echo "Skip build package check if image has to be pushed"
touch $CI_FILE_SKIP_BUILD_PKG_CHECK
fi
exit 0
fi
done
# Getting here means rebuilding the Docker image is not required.
# Pull the image from Docker Hub.
docker pull ${DOCKERHUB_REPO}:1.9-${OS}-${OS_VER}-${CI_CPU_ARCH}
| 3,681 | 31.584071 | 81 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/valid-branches.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2020, Intel Corporation
declare -A TARGET_BRANCHES=( \
["master"]="master" \
["stable-1.5"]="v1.5" \
["stable-1.6"]="v1.6" \
["stable-1.7"]="v1.7" \
["stable-1.8"]="v1.8" \
["stable-1.9"]="v1.9" \
)
| 291 | 21.461538 | 40 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/configure-tests.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# configure-tests.sh - is called inside a Docker container; configures tests
# and ssh server for use during build of PMDK project.
#
set -e
# Configure tests
cat << EOF > $WORKDIR/src/test/testconfig.sh
LONGDIR=LoremipsumdolorsitametconsecteturadipiscingelitVivamuslacinianibhattortordictumsollicitudinNullamvariusvestibulumligulaetegestaselitsemperidMaurisultriciesligulaeuipsumtinciduntluctusMorbimaximusvariusdolorid
# this path is ~3000 characters long
DIRSUFFIX="$LONGDIR/$LONGDIR/$LONGDIR/$LONGDIR/$LONGDIR"
NON_PMEM_FS_DIR=/tmp
PMEM_FS_DIR=/tmp
PMEM_FS_DIR_FORCE_PMEM=1
TEST_BUILD="debug nondebug"
ENABLE_SUDO_TESTS=y
TM=1
EOF
# Configure remote tests
if [[ $REMOTE_TESTS -eq 1 ]]; then
echo "Configuring remote tests"
cat << EOF >> $WORKDIR/src/test/testconfig.sh
NODE[0]=127.0.0.1
NODE_WORKING_DIR[0]=/tmp/node0
NODE_ADDR[0]=127.0.0.1
NODE_ENV[0]="PMEM_IS_PMEM_FORCE=1"
NODE[1]=127.0.0.1
NODE_WORKING_DIR[1]=/tmp/node1
NODE_ADDR[1]=127.0.0.1
NODE_ENV[1]="PMEM_IS_PMEM_FORCE=1"
NODE[2]=127.0.0.1
NODE_WORKING_DIR[2]=/tmp/node2
NODE_ADDR[2]=127.0.0.1
NODE_ENV[2]="PMEM_IS_PMEM_FORCE=1"
NODE[3]=127.0.0.1
NODE_WORKING_DIR[3]=/tmp/node3
NODE_ADDR[3]=127.0.0.1
NODE_ENV[3]="PMEM_IS_PMEM_FORCE=1"
TEST_BUILD="debug nondebug"
TEST_PROVIDERS=sockets
EOF
mkdir -p ~/.ssh/cm
cat << EOF >> ~/.ssh/config
Host 127.0.0.1
StrictHostKeyChecking no
ControlPath ~/.ssh/cm/%r@%h:%p
ControlMaster auto
ControlPersist 10m
EOF
if [ ! -f /etc/ssh/ssh_host_rsa_key ]
then
(echo $USERPASS | sudo -S ssh-keygen -t rsa -C $USER@$HOSTNAME -P '' -f /etc/ssh/ssh_host_rsa_key)
fi
echo $USERPASS | sudo -S sh -c 'cat /etc/ssh/ssh_host_rsa_key.pub >> /etc/ssh/authorized_keys'
ssh-keygen -t rsa -C $USER@$HOSTNAME -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod -R 700 ~/.ssh
chmod 640 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/config
# Start ssh service
echo $USERPASS | sudo -S $START_SSH_COMMAND
ssh 127.0.0.1 exit 0
else
echo "Skipping remote tests"
echo
echo "Removing all libfabric.pc files in order to simulate that libfabric is not installed:"
find /usr -name "libfabric.pc" 2>/dev/null || true
echo $USERPASS | sudo -S sh -c 'find /usr -name "libfabric.pc" -exec rm -f {} + 2>/dev/null'
fi
# Configure python tests
cat << EOF >> $WORKDIR/src/test/testconfig.py
config = {
'unittest_log_level': 1,
'cacheline_fs_dir': '/tmp',
'force_cacheline': True,
'page_fs_dir': '/tmp',
'force_page': False,
'byte_fs_dir': '/tmp',
'force_byte': True,
'tm': True,
'test_type': 'check',
'granularity': 'all',
'fs_dir_force_pmem': 0,
'keep_going': False,
'timeout': '3m',
'build': ['debug', 'release'],
'force_enable': None,
'device_dax_path': [],
'fail_on_skip': False,
'enable_admin_tests': True
}
EOF
| 2,886 | 26.235849 | 216 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/set-vars.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
# set-vars.sh - set required environment variables
#
set -e
export CI_FILE_PUSH_IMAGE_TO_REPO=/tmp/push_image_to_repo_flag
export CI_FILE_SKIP_BUILD_PKG_CHECK=/tmp/skip_build_package_check
| 290 | 21.384615 | 65 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/run-coverity.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2020, Intel Corporation
#
# run-coverity.sh - runs the Coverity scan build
#
set -e
if [[ "$CI_REPO_SLUG" != "$GITHUB_REPO" \
&& ( "$COVERITY_SCAN_NOTIFICATION_EMAIL" == "" \
|| "$COVERITY_SCAN_TOKEN" == "" ) ]]; then
echo
echo "Skipping Coverity build:"\
"COVERITY_SCAN_TOKEN=\"$COVERITY_SCAN_TOKEN\" or"\
"COVERITY_SCAN_NOTIFICATION_EMAIL="\
"\"$COVERITY_SCAN_NOTIFICATION_EMAIL\" is not set"
exit 0
fi
# Prepare build environment
./prepare-for-build.sh
CERT_FILE=/etc/ssl/certs/ca-certificates.crt
TEMP_CF=$(mktemp)
cp $CERT_FILE $TEMP_CF
# Download Coverity certificate
echo -n | openssl s_client -connect scan.coverity.com:443 | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | \
tee -a $TEMP_CF
echo $USERPASS | sudo -S mv $TEMP_CF $CERT_FILE
export COVERITY_SCAN_PROJECT_NAME="$CI_REPO_SLUG"
[[ "$CI_EVENT_TYPE" == "cron" ]] \
&& export COVERITY_SCAN_BRANCH_PATTERN="master" \
|| export COVERITY_SCAN_BRANCH_PATTERN="coverity_scan"
export COVERITY_SCAN_BUILD_COMMAND="make -j$(nproc) all"
cd $WORKDIR
#
# Run the Coverity scan
#
# The 'travisci_build_coverity_scan.sh' script requires the following
# environment variables to be set:
# - TRAVIS_BRANCH - has to contain the name of the current branch
# - TRAVIS_PULL_REQUEST - has to be set to 'true' in case of pull requests
#
export TRAVIS_BRANCH=${CI_BRANCH}
[ "${CI_EVENT_TYPE}" == "pull_request" ] && export TRAVIS_PULL_REQUEST="true"
# XXX: Patch the Coverity script.
# Recently, this script regularly exits with an error, even though
# the build is successfully submitted. Probably because the status code
# is missing in response, or it's not 201.
# Changes:
# 1) change the expected status code to 200 and
# 2) print the full response string.
#
# This change should be reverted when the Coverity script is fixed.
#
# The previous version was:
# curl -s https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh | bash
wget https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh
patch < utils/docker/0001-travis-fix-travisci_build_coverity_scan.sh.patch
bash ./travisci_build_coverity_scan.sh
| 2,196 | 29.513889 | 82 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/run-coverage.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2019, Intel Corporation
#
# run-coverage.sh - is called inside a Docker container; runs the coverage
# test
#
set -e
# Get and prepare PMDK source
./prepare-for-build.sh
# Hush error messages, mainly from Valgrind
export UT_DUMP_LINES=0
# Skip printing mismatched files for tests with Valgrind
export UT_VALGRIND_SKIP_PRINT_MISMATCHED=1
# Build all and run tests
cd $WORKDIR
make -j$(nproc) COVERAGE=1
make -j$(nproc) test COVERAGE=1
# XXX: unfortunately valgrind raports issues in coverage instrumentation
# which we have to ignore (-k flag), also there is dependency between
# local and remote tests (which cannot be easily removed) we have to
# run local and remote tests separately
cd src/test
# do not change -j2 to -j$(nproc) in case of tests (make check/pycheck)
make -kj2 pcheck-local-quiet TEST_BUILD=debug || true
make check-remote-quiet TEST_BUILD=debug || true
# do not change -j2 to -j$(nproc) in case of tests (make check/pycheck)
make -j2 pycheck TEST_BUILD=debug || true
cd ../..
bash <(curl -s https://codecov.io/bash)
| 1,138 | 28.973684 | 74 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/images/install-valgrind.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# install-valgrind.sh - installs valgrind for persistent memory
#
set -e
OS=$1
install_upstream_from_distro() {
case "$OS" in
fedora) dnf install -y valgrind ;;
ubuntu) apt-get install -y --no-install-recommends valgrind ;;
*) return 1 ;;
esac
}
install_upstream_3_16_1() {
git clone git://sourceware.org/git/valgrind.git
cd valgrind
# valgrind v3.16.1 upstream
git checkout VALGRIND_3_16_BRANCH
./autogen.sh
./configure
make -j$(nproc)
make -j$(nproc) install
cd ..
rm -rf valgrind
}
install_custom-pmem_from_source() {
git clone https://github.com/pmem/valgrind.git
cd valgrind
# valgrind v3.15 with pmemcheck
# 2020.04.01 Merge pull request #78 from marcinslusarz/opt3
git checkout 759686fd66cc0105df8311cfe676b0b2f9e89196
./autogen.sh
./configure
make -j$(nproc)
make -j$(nproc) install
cd ..
rm -rf valgrind
}
ARCH=$(uname -m)
case "$ARCH" in
ppc64le) install_upstream_3_16_1 ;;
*) install_custom-pmem_from_source ;;
esac
| 1,099 | 19.754717 | 66 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/images/build-image.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# build-image.sh <OS-VER> <ARCH> - prepares a Docker image with <OS>-based
# environment intended for the <ARCH> CPU architecture
# designed for building PMDK project, according to
# the Dockerfile.<OS-VER> file located in the same directory.
#
# The script can be run locally.
#
set -e
OS_VER=$1
CPU_ARCH=$2
function usage {
echo "Usage:"
echo " build-image.sh <OS-VER> <ARCH>"
echo "where:"
echo " <OS-VER> - can be for example 'ubuntu-19.10' provided "\
"a Dockerfile named 'Dockerfile.ubuntu-19.10' "\
"exists in the current directory and"
echo " <ARCH> - is a CPU architecture, for example 'x86_64'"
}
# Check if two first arguments are not empty
if [[ -z "$2" ]]; then
usage
exit 1
fi
# Check if the file Dockerfile.OS-VER exists
if [[ ! -f "Dockerfile.$OS_VER" ]]; then
echo "Error: Dockerfile.$OS_VER does not exist."
echo
usage
exit 1
fi
if [[ -z "${DOCKERHUB_REPO}" ]]; then
echo "Error: DOCKERHUB_REPO environment variable is not set"
exit 1
fi
# Build a Docker image tagged with ${DOCKERHUB_REPO}:OS-VER-ARCH
tag=${DOCKERHUB_REPO}:1.9-${OS_VER}-${CPU_ARCH}
docker build -t $tag \
--build-arg http_proxy=$http_proxy \
--build-arg https_proxy=$https_proxy \
-f Dockerfile.$OS_VER .
| 1,373 | 24.444444 | 76 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/images/install-libfabric.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# install-libfabric.sh - installs a customized version of libfabric
#
set -e
OS=$1
# Keep in sync with requirements in src/common.inc.
libfabric_ver=1.4.2
libfabric_url=https://github.com/ofiwg/libfabric/archive
libfabric_dir=libfabric-$libfabric_ver
libfabric_tarball=v${libfabric_ver}.zip
wget "${libfabric_url}/${libfabric_tarball}"
unzip $libfabric_tarball
cd $libfabric_dir
# XXX HACK HACK HACK
# Disable use of spin locks in libfabric.
#
# spinlocks do not play well (IOW at all) with cpu-constrained environments,
# like GitHub Actions, and this leads to timeouts of some PMDK's tests.
# This change speeds up pmempool_sync_remote/TEST28-31 by a factor of 20-30.
#
perl -pi -e 's/have_spinlock=1/have_spinlock=0/' configure.ac
# XXX HACK HACK HACK
./autogen.sh
./configure --prefix=/usr --enable-sockets
make -j$(nproc)
make -j$(nproc) install
cd ..
rm -f ${libfabric_tarball}
rm -rf ${libfabric_dir}
| 1,019 | 23.878049 | 76 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/images/install-libndctl.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2019, Intel Corporation
#
# install-libndctl.sh - installs libndctl
#
set -e
OS=$2
echo "==== clone ndctl repo ===="
git clone https://github.com/pmem/ndctl.git
cd ndctl
git checkout $1
if [ "$OS" = "fedora" ]; then
echo "==== setup rpmbuild tree ===="
rpmdev-setuptree
RPMDIR=$HOME/rpmbuild/
VERSION=$(./git-version)
SPEC=./rhel/ndctl.spec
echo "==== create source tarball ====="
git archive --format=tar --prefix="ndctl-${VERSION}/" HEAD | gzip > "$RPMDIR/SOURCES/ndctl-${VERSION}.tar.gz"
echo "==== build ndctl ===="
./autogen.sh
./configure --disable-docs
make -j$(nproc)
echo "==== build ndctl packages ===="
rpmbuild -ba $SPEC
echo "==== install ndctl packages ===="
RPM_ARCH=$(uname -m)
rpm -i $RPMDIR/RPMS/$RPM_ARCH/*.rpm
echo "==== cleanup ===="
rm -rf $RPMDIR
else
echo "==== build ndctl ===="
./autogen.sh
./configure --disable-docs
make -j$(nproc)
echo "==== install ndctl ===="
make -j$(nproc) install
echo "==== cleanup ===="
fi
cd ..
rm -rf ndctl
| 1,057 | 16.344262 | 109 | sh |
null | NearPMSW-main/nearpm/checkpointing/pmdk-checkpoint1/utils/docker/images/push-image.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
# push-image.sh - pushes the Docker image to the Docker Hub.
#
# The script utilizes $DOCKERHUB_USER and $DOCKERHUB_PASSWORD variables
# to log in to Docker Hub. The variables can be set in the Travis project's
# configuration for automated builds.
#
set -e
source $(dirname $0)/../set-ci-vars.sh
if [[ -z "$OS" ]]; then
echo "OS environment variable is not set"
exit 1
fi
if [[ -z "$OS_VER" ]]; then
echo "OS_VER environment variable is not set"
exit 1
fi
if [[ -z "$CI_CPU_ARCH" ]]; then
echo "CI_CPU_ARCH environment variable is not set"
exit 1
fi
if [[ -z "${DOCKERHUB_REPO}" ]]; then
echo "DOCKERHUB_REPO environment variable is not set"
exit 1
fi
TAG="1.9-${OS}-${OS_VER}-${CI_CPU_ARCH}"
# Check if the image tagged with pmdk/OS-VER exists locally
if [[ ! $(docker images -a | awk -v pattern="^${DOCKERHUB_REPO}:${TAG}\$" \
'$1":"$2 ~ pattern') ]]
then
echo "ERROR: Docker image tagged ${DOCKERHUB_REPO}:${TAG} does not exists locally."
exit 1
fi
# Log in to the Docker Hub
docker login -u="$DOCKERHUB_USER" -p="$DOCKERHUB_PASSWORD"
# Push the image to the repository
docker push ${DOCKERHUB_REPO}:${TAG}
| 1,236 | 22.788462 | 84 | sh |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/tpcc_db.h | /*
Author: Vaibhav Gogte <[email protected]>
Aasheesh Kolli <[email protected]>
This file declares the tpcc database and the accesor transactions.
*/
#include "table_entries.h"
#include <atomic>
#include "simple_queue.h"
#include <pthread.h>
#include <cstdlib>
#include "../include/txopt.h"
typedef simple_queue queue_t;
struct backUpLog{
struct district_entry district_back;
//fill_new_order_entry
struct new_order_entry new_order_entry_back;
//update_order_entry
struct order_entry order_entry_back;
//update_stock_entry
struct stock_entry stock_entry_back[15];
int fill_new_order_entry_indx = 0;
int update_order_entry_indx = 0;
int update_stock_entry_indx[16];
uint64_t district_back_valid;
uint64_t fill_new_order_entry_back_valid;
uint64_t update_order_entry_back_valid;
uint64_t update_stock_entry_num_valid;
//global log valid
uint64_t log_valid;
};
class TPCC_DB {
private:
// Tables with size dependent on num warehouses
short num_warehouses;
short random_3000[3000];
warehouse_entry* warehouse;
district_entry* district;
customer_entry* customer;
stock_entry* stock;
// Tables with slight variation in sizes (due to inserts/deletes etc.)
history_entry* history;
order_entry* order;
new_order_entry* new_order;
order_line_entry* order_line;
// Fixed size table
item_entry* item;
unsigned long* rndm_seeds;
queue_t* perTxLocks; // Array of queues of locks held by active Tx
pthread_mutex_t* locks; // Array of locks held by the TxEngn. RDSs acquire locks through the TxEngn
unsigned g_seed;
public:
struct backUpLog * backUpInst;
TPCC_DB();
~TPCC_DB();
void initialize(int _num_warehouses, int numThreads);
void populate_tables();
void fill_item_entry(int _i_id);
void fill_warehouse_entry(int _w_id);
void fill_stock_entry(int _s_w_id, int s_i_id);
void fill_district_entry(int _d_w_id, int _d_id);
void fill_customer_entry(int _c_w_id, int _c_d_id, int _c_id);
void fill_history_entry(int _h_c_w_id, int _h_c_d_id, int _h_c_id);
void fill_order_entry(int _o_w_id, int _o_d_id, int _o_id);
void fill_order_line_entry(int _ol_w_id, int _ol_d_id, int _ol_o_id, int _o_ol_cnt, long long _o_entry_d);
void fill_new_order_entry(int _no_w_id, int _no_d_id, int _no_o_id, int threadId);
void random_a_string(int min, int max, char* string_ptr);
void random_n_string(int min, int max, char* string_ptr);
void random_a_original_string(int min, int max, int probability, char* string_ptr);
void random_zip(char* string_ptr);
void fill_time(long long &time_slot);
int rand_local(int min, int max);
void new_order_tx(int threadId, int w_id, int d_id, int c_id);
void copy_district_info(district_entry &dest, district_entry &source);
void copy_customer_info(customer_entry &dest, customer_entry &source);
void copy_new_order_info(new_order_entry &dest, new_order_entry &source);
void copy_order_info(order_entry &dest, order_entry &source);
void copy_stock_info(stock_entry &dest, stock_entry &source);
void copy_order_line_info(order_line_entry &dest, order_line_entry &source);
void update_order_entry(int _w_id, short _d_id, int _o_id, int _c_id, int _ol_cnt, int threadId);
void update_stock_entry(int threadId, int _w_id, int _i_id, int _d_id, float &amount, int itr);
unsigned long get_random(int thread_id, int min, int max);
unsigned long get_random(int thread_id);
void printStackPointer(int* sp, int thread_id);
void acquire_locks(int thread_id, queue_t &reqLocks);
void release_locks(int thread_id);
unsigned fastrand();
};
| 3,755 | 30.041322 | 110 | h |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/tpcc_nvm.cc | /*
Author: Vaibhav Gogte <[email protected]>
Aasheesh Kolli <[email protected]>
This file models the TPCC benchmark.
*/
//Korakit
//remove MT stuffs
//#include <pthread.h>
#include <memkind.h>
#include <dlfcn.h>
#include <iostream>
#include <vector>
#include <sys/time.h>
#include <string>
#include <fstream>
#include <cstring>
//#include "txopt.h"
#include <libpmem.h>
#include "tpcc_db.h"
#include "../include/txopt.h"
#define NUM_ORDERS 1000 //10000000
#define NUM_THREADS 1
#define NUM_WAREHOUSES 1
#define NUM_ITEMS 10000//10000
#define NUM_LOCKS NUM_WAREHOUSES*10 + NUM_WAREHOUSES*NUM_ITEMS
TPCC_DB* tpcc_db[NUM_THREADS];
static inline uint64_t getCycle(){
uint32_t cycles_high, cycles_low, pid;
asm volatile ("RDTSCP\n\t" // rdtscp into eax and edx
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t"
"mov %%ecx, %2\n\t"
:"=r" (cycles_high), "=r" (cycles_low), "=r" (pid) //store in vars
:// no input
:"%eax", "%edx", "%ecx" // clobbered by rdtscp
);
return((uint64_t)cycles_high << 32) | cycles_low;
}
void initialize(int tid, void * backUpLog) {
tpcc_db[tid] = (TPCC_DB *)malloc(sizeof(TPCC_DB));
tpcc_db[tid]->backUpInst = (struct backUpLog *)backUpLog;
new(tpcc_db[tid]) TPCC_DB();
tpcc_db[tid]->initialize(NUM_WAREHOUSES, NUM_THREADS);
// fprintf(stderr, "Created tpcc at %p\n", (void *)tpcc_db[tid]);
}
//void new_orders(TxEngine* tx_engine, int tx_engn_type, TPCC_DB* tpcc_db, int thread_id, int num_orders, int num_threads, int num_strands_per_thread, std::atomic<bool>*wait) {
void* new_orders(void* arguments) {
int thread_id = *((int*)arguments);
// fprintf(stdout, "New order, thread: %d\n", thread_id);
for(int i=0; i<NUM_ORDERS/NUM_THREADS; i++) {
int w_id = 1;
//There can only be 10 districts, this controls the number of locks in tpcc_db, which is why NUM_LOCKS = warehouse*10
int d_id = tpcc_db[thread_id]->get_random(thread_id, 1, 10);
int c_id = tpcc_db[thread_id]->get_random(thread_id, 1, 3000);
// fprintf(stdout, "thread: %d, line: %d\n", thread_id, __LINE__);
tpcc_db[thread_id]->new_order_tx(thread_id, w_id, d_id, c_id);
// fprintf(stdout, "thread: %d, #%d\n", thread_id, i);
}
// fprintf(stdout, "thread: %d\n", thread_id);
// return 0;
}
/////////////////Page fault handling/////////////////
#include <bits/types/sig_atomic_t.h>
#include <bits/types/sigset_t.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#define SIGSTKSZ 8192
#define SA_SIGINFO 4
#define SA_ONSTACK 0x08000000 /* Use signal stack by using `sa_restorer'. */
#define SA_RESTART 0x10000000 /* Restart syscall on signal return. */
#define SA_NODEFER 0x40000000 /* Don't automatically block the signal when*/
stack_t _sigstk;
int updated_page_count = 0;
int all_updates = 0;
void * checkpoint_start;
void * page[50];
void * device;
double totTimeShadow = 0;
#define GRANULARITY 2048
void cmd_issue( uint32_t opcode,
uint32_t TXID,
uint32_t TID,
uint32_t OID,
uint64_t data_addr,
uint32_t data_size,
void * ptr){
//command with thread id encoded as first 8 bits of each word
uint32_t issue_cmd[7];
issue_cmd[0] = (TID<<24)|(opcode<<16)|(TXID<<8)|TID;
issue_cmd[1] = (TID<<24)|(OID<<16)|(data_addr>>48);
issue_cmd[2] = (TID<<24)|((data_addr & 0x0000FFFFFFFFFFFF)>>24);
issue_cmd[3] = (TID<<24)|(data_addr & 0x0000000000FFFFFF);
issue_cmd[4] = (TID<<24)|(data_size<<8);
issue_cmd[5] = (TID<<24)|(0X00FFFFFF>>16);
issue_cmd[6] = (TID<<24)|((0X00FFFFFF & 0x0000FFFF)<<8);
for(int i=0;i<7;i++){
// printf("%08x\n",issue_cmd[i]);
*((u_int32_t *) ptr) = issue_cmd[i];
}
}
static void segvHandle(int signum, siginfo_t * siginfo, void * context) {
#define CPTIME
#ifdef CPTIME
uint64_t endCycles, startCycles,totalCycles;
startCycles = getCycle();
#endif
void * addr = siginfo->si_addr; // address of access
uint64_t pageNo = ((uint64_t)addr)/4096;
unsigned long * pageStart = (unsigned long *)(pageNo*4096);
// Check if this was a SEGV that we are supposed to trap.
if (siginfo->si_code == SEGV_ACCERR) {
mprotect(pageStart, 4096, PROT_READ|PROT_WRITE);
if(all_updates >=5 || updated_page_count == 50){
for(int i=0;i<updated_page_count;i++){
//memcpy(checkpoint_start + 4096, pageStart, 4096);
//pmem_persist(checkpoint_start + 4096, 4096);
cmd_issue(2,0,0,0, (uint64_t)pageStart,4096,device);
/* *((uint64_t*)device) = (uint64_t)(checkpoint_start + 4096);
*((uint64_t*)(device)+1) = 00;
*((uint64_t*)(device)+2) = (uint64_t)0.320580;
*((uint64_t*)(device)+3) = ((uint64_t)(((0) << 16)| 6) << 32) | 4096;
*(((uint32_t*)(device))+255) = (uint32_t)(((0) << 16)| 6);
*/
page[updated_page_count] = 0;
}
updated_page_count = 0;
all_updates = 0;
}
all_updates ++;
for(int i=0; i<updated_page_count; i++){
if(page[i] == pageStart){
#ifdef CPTIME
endCycles = getCycle();
totalCycles = endCycles - startCycles;
double totTime = ((double)totalCycles)/2000000000;
printf("cp %f\n", totTime);
#endif
return;}
}
page[updated_page_count] = pageStart;
//printf("test1 %lx %d %d\n",page[updated_page_count],updated_page_count,all_updates);
updated_page_count++;
#ifdef CPTIME
endCycles = getCycle();
totalCycles = endCycles - startCycles;
double totTime = ((double)totalCycles)/2000000000;
printf("cp %f\n", totTime);
#endif
//*((int *)checkpoint_start) = 10;
//test++;
//printf("test1 %lx %d\n",updated_page_count);
} else if (siginfo->si_code == SEGV_MAPERR) {
fprintf (stderr, "%d : map error with addr %p!\n", getpid(), addr);
abort();
} else {
fprintf (stderr, "%d : other access error with addr %p.\n", getpid(), addr);
abort();
}
}
static void installSignalHandler(void) {
// Set up an alternate signal stack.
printf("page fault handler initialized!!\n");
_sigstk.ss_sp = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
_sigstk.ss_size = SIGSTKSZ;
_sigstk.ss_flags = 0;
sigaltstack(&_sigstk, (stack_t *) 0);
// Now set up a signal handler for SIGSEGV events.
struct sigaction siga;
sigemptyset(&siga.sa_mask);
// Set the following signals to a set
sigaddset(&siga.sa_mask, SIGSEGV);
sigaddset(&siga.sa_mask, SIGALRM);
sigprocmask(SIG_BLOCK, &siga.sa_mask, NULL);
// Point to the handler function.
siga.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART | SA_NODEFER;
siga.sa_sigaction = segvHandle;
if (sigaction(SIGSEGV, &siga, NULL) == -1) {
perror("sigaction(SIGSEGV)");
exit(-1);
}
sigprocmask(SIG_UNBLOCK, &siga.sa_mask, NULL);
return;
}
void* open_device(const char* pathname)
{
//int fd = os_open("/sys/devices/pci0000:00/0000:00:00.2/iommu/ivhd0/devices/0000:0a:00.0/resource0",O_RDWR|O_SYNC);
int fd = open(pathname,O_RDWR|O_SYNC);
if(fd == -1)
{
printf("Couldnt opene file!!\n");
exit(0);
}
void * ptr = mmap(0,4096,PROT_READ|PROT_WRITE, MAP_SHARED,fd,0);
if(ptr == (void *)-1)
{
printf("Could not map memory!!\n");
exit(0);
}
printf("opened device without error!!\n");
return ptr;
}
///////////////////////////////////////////////////////////////////
void installSignalHandler (void) __attribute__ ((constructor));
int main(int argc, char* argv[]) {
device = open_device("/sys/devices/pci0000:00/0000:00:00.2/iommu/ivhd0/devices/0000:0a:00.0/resource0");
uint64_t* tmp = (uint64_t*)device;
*tmp = 0xdeadbeefdeadbeef;
pmem_persist(tmp,64);
*tmp = (uint64_t)tmp;
pmem_persist(tmp,64);
uint32_t tid;
tid = 0;//gettid();
tid = tid & 0x3f;
tid = (tid<< 4)| 0;//pop->run_id;
//printf("%d %d\n",tid, pop->run_id);
*tmp = tid;
pmem_persist(tmp,64);
size_t mapped_len;
int is_pmem;
void * backUpLogPtr;
if ((backUpLogPtr = pmem_map_file("/mnt/mem/tpcc_db", sizeof(struct backUpLog)*NUM_THREADS,
PMEM_FILE_CREATE, 0666, &mapped_len, &is_pmem)) == NULL) {
fprintf(stderr, "pmem_map_file failed\n");
exit(0);
}
for(int i=0;i<NUM_THREADS;i++){
initialize(i, (backUpLogPtr + i*sizeof(struct backUpLog)));
}
// exit(0);
//CounterAtomic::initCounterCache();
/*
std::cout<<"num_threads, num_orders = "<< NUM_THREADS <<", "<<NUM_ORDERS <<std::endl;
std::cout<<"done with initialization"<<std::endl;
tpcc_db->populate_tables();
std::cout<<"done with populating tables"<<std::endl;
*/
pthread_t threads[NUM_THREADS];
int id[NUM_THREADS];
//gettimeofday(&tv_start, NULL);
uint64_t endCycles, startCycles,totalCycles;
startCycles = getCycle();
for(int i=0; i<NUM_THREADS; i++) {
id[i] = i;
// fprintf(stderr, "create %d\n", i);
//Korakit
//convert to ST version
//new_orders((void *)(id+i));
new_orders((void *)&id[i]);
}
endCycles = getCycle();
totalCycles = endCycles - startCycles;
double totTime = ((double)totalCycles)/2000000000;
printf("tottime %f\n", totTime);
//Korakit
//remote MT stuffs
// for(int i=0; i<NUM_THREADS; i++) {
// pthread_join(threads[i], NULL);
// }
//Korakit
//Remove all timing stuffs
/*
gettimeofday(&tv_end, NULL);
fprintf(stderr, "time elapsed %ld us\n",
tv_end.tv_usec - tv_start.tv_usec +
(tv_end.tv_sec - tv_start.tv_sec) * 1000000);
fexec << "TPCC" << ", " << std::to_string((tv_end.tv_usec - tv_start.tv_usec) + (tv_end.tv_sec - tv_start.tv_sec) * 1000000) << std::endl;
fexec.close();
*/
//free(tpcc_db);
//std::cout<<"done with threads"<<std::endl;
return 0;
}
| 9,685 | 26.517045 | 176 | cc |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/run.sh | #!/usr/bin/env bash
sudo rm -rf /mnt/mem/*
sudo ./tpcc_nvm > out
tot=$(grep "tottime" out)
grep "cp" out > time
cp=$(awk '{sum+= $2;} END{print sum;}' time)
echo $1$tot
echo $1'cp' $cp
| 187 | 16.090909 | 44 | sh |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/simple_queue.h | /*
Author: Vaibhav Gogte <[email protected]>
Aasheesh Kolli <[email protected]>
*/
//#include <iostream>
#define QUEUE_SIZE 20
class simple_queue {
private:
long entries[QUEUE_SIZE];
long head;
long tail;
public:
simple_queue() {
head = 0;
tail = 0;
}
~simple_queue() {}
bool empty() {
return (head == tail);
}
bool full() {
if(tail == 0)
return (head == QUEUE_SIZE-1);
return (head == tail-1);
}
int size() {
if(head >= tail) {
return head - tail;
}
else {
return (QUEUE_SIZE - tail + head);
}
}
bool push(long entry) {
if(full())
return false;
entries[head] = entry;
if(head == QUEUE_SIZE-1)
head = 0;
else
head++;
return true;
}
long front() {
return entries[tail];
}
bool pop() {
if(empty())
return false;
if(tail == QUEUE_SIZE-1)
tail = 0;
else
tail++;
return true;
}
//void printQueue() {
// std::cout<<"head tail "<<head<<" "<<tail<<std::endl;
// for(int i=0; i<QUEUE_SIZE; i++) {
// std::cout<<i<<" "<<entries[i]<<std::endl;
// }
//}
};
| 1,257 | 16.232877 | 60 | h |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/table_entries.h | /*
Author: Vaibhav Gogte <[email protected]>
Aasheesh Kolli <[email protected]>
This file declares the entry types for each of the tables used in TPCC
*/
struct warehouse_entry {
int w_id;
char w_name[10];
char w_street_1[20];
char w_street_2[20];
char w_city[20];
char w_state[2];
char w_zip[9];
float w_tax;
float w_ytd;
char padding[32];
};
struct district_entry {
short d_id;
int d_w_id;
char d_name[10];
char d_street_1[20];
char d_street_2[20];
char d_city[20];
char d_state[2];
char d_zip[9];
float d_tax;
float d_ytd;
int d_next_o_id;
char padding[24]; //change padding from 4 to 24 to make it fits in 64-byte cacheline size
};
struct customer_entry {
int c_id;
short c_d_id;
int c_w_id;
char c_first[16];
char c_middle[2];
char c_last[16];
char c_street_1[20];
char c_street_2[20];
char c_city[20];
char c_state[2];
char c_zip[9];
char c_phone[16];
long long c_since; // Seconds since 1st Jan 1900, 00:00:00
char c_credit[2];
float c_credit_lim;
float c_discount;
float c_balance;
float c_ytd_payment;
float c_payment_cnt;
float c_delivery_cnt;
char c_data[500];
char padding[32];
};
struct history_entry {
int h_c_id;
short h_c_d_id;
int h_c_w_id;
short h_d_id;
int h_w_id;
long long h_date;
float h_amount;
char h_data[24];
};
struct new_order_entry {
int no_o_id;
short no_d_id;
int no_w_id;
int indx;
char padding[48]; //change padding from 4 to 52 to make it fits in 64-byte cacheline size
};
struct order_entry {
int o_id;
short o_d_id;
int o_w_id;
int o_c_id;
long long o_entry_d;
short o_carrier_id;
float o_ol_cnt;
float o_all_local;
int indx;
char padding[20];
};
struct order_line_entry {
int ol_o_id;
short ol_d_id;
int ol_w_id;
short ol_number;
int ol_i_id;
int ol_supply_w_id;
long long ol_delivery_d;
float ol_quantity;
float ol_amount;
char ol_dist_info[24];
};
struct item_entry {
int i_id;
int i_im_id;
char i_name[24];
float i_price;
char i_data[50];
char padding[40];
};
struct stock_entry {
int s_i_id;
int s_w_id;
float s_quantity;
char s_dist_01[24];
char s_dist_02[24];
char s_dist_03[24];
char s_dist_04[24];
char s_dist_05[24];
char s_dist_06[24];
char s_dist_07[24];
char s_dist_08[24];
char s_dist_09[24];
char s_dist_10[24];
float s_ytd;
float s_order_cnt;
float s_remote_cnt;
char s_data[50];
int indx;
};
| 2,468 | 17.154412 | 91 | h |
null | NearPMSW-main/nearpm/checkpointing/TPCC_CP/tpcc_db.cc | /*
Author: Vaibhav Gogte <[email protected]>
Aasheesh Kolli <[email protected]>
This file defines the various functions of the tpcc database
*/
#include <cstdlib>
#include <iostream>
#include <queue>
#include <cstring> // For memcpy
#include <algorithm> // for sort
#include "tpcc_db.h"
#include <libpmem.h>
#include <sys/mman.h>
//#define NEW_ORDER_LOCK 10;
#define TPCC_DEBUG 0
//#define NUM_ITEMS 1000
#define NUM_ITEMS 10000
#define NUM_RNDM_SEEDS 1280
static void setpage(void * addr){
uint64_t pageNo = ((uint64_t)addr)/4096;
unsigned long * pageStart = (unsigned long *)(pageNo*4096);
mprotect(pageStart, 4096, PROT_READ);
return;
}
extern void * checkpoint_start;
TPCC_DB::TPCC_DB() {
uint64_t district_back_valid = 0UL;
uint64_t fill_new_order_entry_back_valid = 0UL;
uint64_t update_order_entry_back_valid = 0UL;
uint64_t update_stock_entry_num_valid = 0UL;
uint64_t log_valid = 0UL;
g_seed = 1312515;
}
unsigned TPCC_DB::fastrand() {
g_seed = (179423891 * g_seed + 2038073749);
return (g_seed >> 8) & 0x7FFFFFFF;
}
void TPCC_DB::initialize(int _num_warehouses, int numThreads) {
num_warehouses = _num_warehouses;
int num_districts = 10*num_warehouses;
int num_customers = 3000*num_districts;
int num_stocks = NUM_ITEMS*num_warehouses;
for(int i=0; i<3000; i++) {
random_3000[i] = i;
}
for(int i=0; i<3000; i++) {
int rand_loc = fastrand()%3000;
int temp = random_3000[i];
random_3000[i] = random_3000[rand_loc];
random_3000[rand_loc] = temp;
}
/*
perTxLocks = new queue_t[numThreads];
for(int i=0; i<numThreads; i++) {
perTxLocks[i].push(0);
perTxLocks[i].pop();
}
*/
/*
locks = new pthread_mutex_t[numLocks];
for (int i = 0; i < numLocks; i++) {
pthread_mutex_init(&locks[i],NULL);
}
*/
//Korakit
//info removed
// std::cout<<"Allocating tables"<<std::endl;
int num_items = NUM_ITEMS;
int num_histories = num_customers;
int num_orders = 3000*num_districts;
int num_order_lines = 15*num_orders; // Max possible, average is 10*num_orders
int num_new_orders = 900*num_districts;
size_t mapped_len;
int is_pmem;
void * pmemstart;
int totsize = num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_customers*sizeof(customer_entry)
+ num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) + num_histories*sizeof(history_entry) + num_orders*sizeof(order_entry)
+ num_new_orders*sizeof(new_order_entry) + num_order_lines*sizeof(order_line_entry);
if ((pmemstart = pmem_map_file("/mnt/mem/tpcc", totsize,
PMEM_FILE_CREATE, 0666, &mapped_len, &is_pmem)) == NULL) {
fprintf(stderr, "pmem_map_file failed\n");
exit(0);
}
if ((checkpoint_start = pmem_map_file("/mnt/mem/checkpoint", 4096*50,
PMEM_FILE_CREATE, 0666, &mapped_len, &is_pmem)) == NULL) {
fprintf(stderr, "pmem_map_file failed\n");
exit(0);
}
warehouse = (warehouse_entry*) pmemstart;//malloc(num_warehouses*sizeof(warehouse_entry));
district = (district_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry));//malloc(num_districts*sizeof(district_entry));
customer = (customer_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry));//malloc(num_customers*sizeof(customer_entry));
stock = (stock_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry));//malloc(num_stocks*sizeof(stock_entry));
item = (item_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) );//malloc(num_items*sizeof(item_entry));
history = (history_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) + num_histories*sizeof(history_entry));//malloc(num_histories*sizeof(history_entry));
order = (order_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) + num_histories*sizeof(history_entry) + num_orders*sizeof(order_entry));//malloc(num_orders*sizeof(order_entry));
new_order = (new_order_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) + num_histories*sizeof(history_entry) + num_orders*sizeof(order_entry) + num_new_orders*sizeof(new_order_entry));//malloc(num_new_orders*sizeof(new_order_entry));
order_line = (order_line_entry*) (pmemstart + num_warehouses*sizeof(warehouse_entry) + num_districts*sizeof(district_entry) + num_stocks*sizeof(stock_entry) + num_items*sizeof(item_entry) + num_histories*sizeof(history_entry) + num_orders*sizeof(order_entry) + num_new_orders*sizeof(new_order_entry) + num_order_lines*sizeof(order_line_entry));//malloc(num_order_lines*sizeof(order_line_entry));
rndm_seeds = new unsigned long[NUM_RNDM_SEEDS];
for(int i=0; i<NUM_RNDM_SEEDS; i++) {
srand(i);
rndm_seeds[i] = rand_local(1,NUM_RNDM_SEEDS*10);
}
//Korakit
//info removed
/*
std::cout<<"finished allocating tables"<<std::endl;
std::cout<<"warehouse_entry: "<<sizeof(warehouse_entry)<<std::endl;
std::cout<<"district_entry: "<<sizeof(district_entry)<<std::endl;
std::cout<<"customer_entry: "<<sizeof(customer_entry)<<std::endl;
std::cout<<"stock_entry: "<<sizeof(stock_entry)<<std::endl;
std::cout<<"item_entry: "<<sizeof(item_entry)<<std::endl;
std::cout<<"history_entry: "<<sizeof(history_entry)<<std::endl;
std::cout<<"order_entry: "<<sizeof(order_entry)<<std::endl;
std::cout<<"new_order_entry: "<<sizeof(new_order_entry)<<std::endl;
std::cout<<"order_line_entry: "<<sizeof(order_line_entry)<<std::endl;
*/
}
TPCC_DB::~TPCC_DB(){
free(warehouse);
free(district);
free(customer);
free(stock);
free(item);
free(history);
free(order);
free(new_order);
free(order_line);
}
void TPCC_DB::populate_tables() {
//std::cout<<"populating item table"<<std::endl;
for(int i=0; i<NUM_ITEMS; i++) {
fill_item_entry(i+1);
}
//std::cout<<"finished populating item table"<<std::endl;
for(int i=0; i<num_warehouses; i++) {
fill_warehouse_entry(i+1);
for(int j=0; j<NUM_ITEMS; j++) {
fill_stock_entry(i+1, j+1);
}
//std::cout<<"finished populating stock table"<<std::endl;
for(int j=0; j<10; j++) {
fill_district_entry(i+1, j+1);
for(int k=0; k<3000; k++) {
fill_customer_entry(i+1, j+1, k+1);
fill_history_entry(i+1, j+1, k+1);
fill_order_entry(i+1, j+1, k+1);
}
for(int k=2100; k<3000; k++) {
fill_new_order_entry(i+1, j+1, k+1, 0);
}
}
}
}
//Korakit
//remove MT stuff
/*
void TPCC_DB::acquire_locks(int threadId, queue_t &requestedLocks) {
// Acquire locks in order.
int i = -1;
while(!requestedLocks.empty()) {
i = requestedLocks.front();
perTxLocks[threadId].push(i);
requestedLocks.pop();
pthread_mutex_lock(&locks[i]);
}
}
void TPCC_DB::release_locks(int threadId) {
// Release locks in order
int i = -1;
while(!perTxLocks[threadId].empty()) {
i = perTxLocks[threadId].front();
perTxLocks[threadId].pop();
pthread_mutex_unlock(&locks[i]);
}
}
*/
void TPCC_DB::fill_item_entry(int _i_id) {
int indx = (_i_id-1);
item[indx].i_id = _i_id;
item[indx].i_im_id = rand_local(1,NUM_ITEMS);
random_a_string(14,24,item[indx].i_name);
item[indx].i_price = rand_local(1,100)*(1.0);
random_a_original_string(26,50,10,item[indx].i_data);
}
void TPCC_DB::fill_warehouse_entry(int _w_id) {
int indx = (_w_id-1);
warehouse[indx].w_id = _w_id;
random_a_string(6,10,warehouse[indx].w_name);
random_a_string(10,20,warehouse[indx].w_street_1);
random_a_string(10,20,warehouse[indx].w_street_2);
random_a_string(10,20,warehouse[indx].w_city);
random_a_string(2,2,warehouse[indx].w_state);
random_zip(warehouse[indx].w_zip);
warehouse[indx].w_tax = (rand_local(0,20))/100.0;
warehouse[indx].w_ytd = 300000.0;
}
void TPCC_DB::fill_stock_entry(int _s_w_id, int _s_i_id) {
//std::cout<<"entered fill stock entry: "<<_s_w_id<<", "<<_s_i_id<<std::endl;
int indx = (_s_w_id-1)*NUM_ITEMS + (_s_i_id-1);
stock[indx].s_i_id = _s_i_id;
//std::cout<<"1"<<std::endl;
stock[indx].s_w_id = _s_w_id;
//std::cout<<"1"<<std::endl;
stock[indx].s_quantity = rand_local(10,100);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_01);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_02);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_03);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_04);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_05);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_06);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_07);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_08);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_09);
//std::cout<<"1"<<std::endl;
random_a_string(24,24,stock[indx].s_dist_10);
//std::cout<<"1"<<std::endl;
stock[indx].s_ytd = 0.0;
//std::cout<<"1"<<std::endl;
stock[indx].s_order_cnt = 0.0;
//std::cout<<"1"<<std::endl;
stock[indx].s_remote_cnt = 0.0;
//std::cout<<"1"<<std::endl;
random_a_original_string(26,50,10,stock[indx].s_data);
//std::cout<<"exiting fill stock entry: "<<_s_w_id<<", "<<_s_i_id<<std::endl;
}
void TPCC_DB::fill_district_entry(int _d_w_id, int _d_id) {
int indx = (_d_w_id-1)*10 + (_d_id-1);
district[indx].d_id = _d_id;
district[indx].d_w_id = _d_w_id;
random_a_string(6,10,district[indx].d_name);
random_a_string(10,20,district[indx].d_street_1);
random_a_string(10,20,district[indx].d_street_2);
random_a_string(10,20,district[indx].d_city);
random_a_string(2,2,district[indx].d_state);
random_zip(district[indx].d_zip);
district[indx].d_tax = (rand_local(0,20))/100.0;
district[indx].d_ytd = 30000.0;
district[indx].d_next_o_id = 3001;
}
void TPCC_DB::fill_customer_entry(int _c_w_id, int _c_d_id, int _c_id) {
int indx = (_c_w_id-1)*10*3000 + (_c_d_id-1)*3000 + (_c_id-1);
customer[indx].c_id = _c_id;
customer[indx].c_d_id = _c_d_id;
customer[indx].c_w_id = _c_w_id;
random_a_string(16,16,customer[indx].c_last); // FIXME: check tpcc manual for exact setting
customer[indx].c_middle[0] = 'O';
customer[indx].c_middle[1] = 'E';
random_a_string(8,16,customer[indx].c_first);
random_a_string(10,20,customer[indx].c_street_1);
random_a_string(10,20,customer[indx].c_street_2);
random_a_string(10,20,customer[indx].c_city);
random_a_string(2,2,customer[indx].c_state);
random_zip(customer[indx].c_zip);
random_n_string(16,16, customer[indx].c_phone);
fill_time(customer[indx].c_since);
if(fastrand()%10 < 1) {
customer[indx].c_credit[0] = 'G';
customer[indx].c_credit[1] = 'C';
}
else {
customer[indx].c_credit[0] = 'B';
customer[indx].c_credit[1] = 'C';
}
customer[indx].c_credit_lim = 50000.0;
customer[indx].c_discount = (rand_local(0,50))/100.0;
customer[indx].c_balance = -10.0;
customer[indx].c_ytd_payment = 10.0;
customer[indx].c_payment_cnt = 1.0;
customer[indx].c_delivery_cnt = 0.0;
random_a_string(300,500,customer[indx].c_data);
}
void TPCC_DB::fill_history_entry(int _h_c_w_id, int _h_c_d_id, int _h_c_id) {
int indx = (_h_c_w_id-1)*10*3000 + (_h_c_d_id-1)*3000 + (_h_c_id-1);
history[indx].h_c_id = _h_c_id;
history[indx].h_c_d_id = _h_c_d_id;
history[indx].h_c_w_id = _h_c_w_id;
fill_time(history[indx].h_date);
history[indx].h_amount = 10.0;
random_a_string(12,24,history[indx].h_data);
}
void TPCC_DB::fill_order_entry(int _o_w_id, int _o_d_id, int _o_id) {
int indx = (_o_w_id-1)*10*3000 + (_o_d_id-1)*3000 + (_o_id-1);
order[indx].o_id = _o_id;
order[indx].o_c_id = random_3000[_o_id];
order[indx].o_d_id = _o_d_id;
order[indx].o_w_id = _o_w_id;
fill_time(order[indx].o_entry_d);
if(_o_id<2101)
order[indx].o_carrier_id = fastrand()%10 + 1;
else
order[indx].o_carrier_id = 0;
order[indx].o_ol_cnt = rand_local(5,15);
order[indx].o_all_local = 1.0;
for(int i=0; i<order[indx].o_ol_cnt; i++) {
fill_order_line_entry(_o_w_id, _o_d_id, _o_id, i, order[indx].o_entry_d);
}
}
void TPCC_DB::fill_order_line_entry(int _ol_w_id, int _ol_d_id, int _ol_o_id, int _o_ol_cnt, long long _o_entry_d) {
int indx = (_ol_w_id-1)*10*3000*15 + (_ol_d_id-1)*3000*15 + (_ol_o_id-1)*15 + _o_ol_cnt;
order_line[indx].ol_o_id = _ol_o_id;
order_line[indx].ol_d_id = _ol_d_id;
order_line[indx].ol_w_id = _ol_w_id;
order_line[indx].ol_number = _o_ol_cnt;
order_line[indx].ol_i_id = rand_local(1,NUM_ITEMS);
order_line[indx].ol_supply_w_id = _ol_w_id;
if(_ol_o_id < 2101) {
order_line[indx].ol_delivery_d = _o_entry_d;
order_line[indx].ol_amount = 0.0;
}
else {
order_line[indx].ol_delivery_d = 0;
order_line[indx].ol_amount = rand_local(1,999999)/100.0;
}
order_line[indx].ol_quantity = 5.0;
random_a_string(24,24,order_line[indx].ol_dist_info);
}
void TPCC_DB::fill_new_order_entry(int _no_w_id, int _no_d_id, int _no_o_id, int threadId) {
int indx = (_no_w_id-1)*10*900 + (_no_d_id-1)*900 + (_no_o_id-2101) % 900;
// OPT_ADDR((void*)(7), threadId, &new_order[indx], sizeof(new_order_entry));
// if(TPCC_DEBUG)
// std::cout<<"w_id, d_id, o_id, indx: "<<_no_w_id<<", "<<_no_d_id<<", "
// <<_no_o_id<<", "<<indx<<std::endl;
//Korakit
//do backup
//backUpInst->fill_new_order_entry_indx = indx;
//new_order[indx].indx = indx;
//backUpInst->new_order_entry_back = new_order[indx];
//flush_caches((void*)&backUpInst->fill_new_order_entry_indx, (unsigned)sizeof(backUpInst->fill_new_order_entry_indx));
//pmem_persist((void*)&backUpInst->new_order_entry_back, (unsigned)sizeof(backUpInst->new_order_entry_back));
//s_fence();
//backUpInst->fill_new_order_entry_back_valid=1;
//s_fence();
//just flush the cache
new_order[indx].no_o_id = _no_o_id;
new_order[indx].no_d_id = _no_d_id;
setpage(&new_order[indx]);
new_order[indx].no_w_id = _no_w_id;
pmem_persist((void*)&new_order[indx], (unsigned)sizeof(new_order[indx]));
}
int TPCC_DB::rand_local(int min, int max) {
return (min + (fastrand()%(max-min+1)));
}
void TPCC_DB::random_a_string(int min, int max, char* string_ptr) {
//std::cout<<"entered random a string"<<std::endl;
char alphabets[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//std::cout<<"2"<<std::endl;
int string_length = min + (fastrand()%(max-min+1));
//std::cout<<"2"<<std::endl;
for(int i=0; i<string_length; i++) {
string_ptr[max-1-i] = alphabets[fastrand()%26];
//std::cout<<"f3"<<std::endl;
}
//std::cout<<"2"<<std::endl;
for(int i=0; i<max-string_length; i++) {
string_ptr[max-1-i] = ' ';
//std::cout<<"f4"<<std::endl;
}
//std::cout<<"exiting random a string"<<std::endl;
}
void TPCC_DB::random_a_original_string(int min, int max, int probability, char* string_ptr) {
//FIXME: use probability and add ORIGINAL
random_a_string(min, max,string_ptr);
}
void TPCC_DB::random_zip(char* string_ptr) {
random_a_string(4,4,string_ptr);
for(int i=4; i<9; i++) {
string_ptr[i] = '1';
}
}
void TPCC_DB::random_n_string(int min, int max, char* string_ptr) {
char digits[10] = {'0','1','2','3','4','5','6','7','8','9'};
int string_length = min + (fastrand()%(max-min+1));
for(int i=0; i<string_length; i++) {
string_ptr[max-1-i] = digits[fastrand()%10];
}
for(int i=0; i<max-string_length; i++) {
string_ptr[max-1-i] = ' ';
}
}
void TPCC_DB::fill_time(long long &time_slot) {
//FIXME: put correct time
time_slot = 12112342433241;
}
void TPCC_DB::copy_district_info(district_entry &dest, district_entry &source) {
std::memcpy(&dest, &source, sizeof(district_entry));
}
void TPCC_DB::copy_customer_info(customer_entry &dest, customer_entry &source) {
std::memcpy(&dest, &source, sizeof(customer_entry));
}
void TPCC_DB::copy_new_order_info(new_order_entry &dest, new_order_entry &source) {
std::memcpy(&dest, &source, sizeof(new_order_entry));
}
void TPCC_DB::copy_order_info(order_entry &dest, order_entry &source) {
std::memcpy(&dest, &source, sizeof(order_entry));
}
void TPCC_DB::copy_stock_info(stock_entry &dest, stock_entry &source) {
std::memcpy(&dest, &source, sizeof(stock_entry));
}
void TPCC_DB::copy_order_line_info(order_line_entry &dest, order_line_entry &source) {
std::memcpy(&dest, &source, sizeof(order_line_entry));
}
void TPCC_DB::update_order_entry(int _w_id, short _d_id, int _o_id, int _c_id, int _ol_cnt, int threadId) {
int indx = (_w_id-1)*10*3000 + (_d_id-1)*3000 + (_o_id-1)%3000;
// OPT((void*)(8), threadId, &backUpInst->order_entry_back, &order[indx], sizeof(order_entry));
// OPT_ADDR((void*)(9), threadId, &order[indx], sizeof(order_entry));
// Korakit
// create backup
// fprintf(stdout, "thread=%d, line=%d\n", threadId, __LINE__);
//backUpInst->update_order_entry_indx = indx;
//order[indx].indx = indx;
//backUpInst->order_entry_back = order[indx];
//pmem_persist((void*)&backUpInst->update_order_entry_indx, (unsigned)sizeof(backUpInst->update_order_entry_indx));
//pmem_persist((void*)&backUpInst->order_entry_back, (unsigned)sizeof(backUpInst->order_entry_back));
//s_fence();
// fprintf(stdout, "thread=%d, line=%d\n", threadId, __LINE__);
//backUpInst->update_order_entry_back_valid = 1;
//s_fence();
order[indx].o_id = _o_id;
order[indx].o_carrier_id = 0;
order[indx].o_all_local = 1;
order[indx].o_ol_cnt = _ol_cnt;
order[indx].o_c_id = _c_id;
setpage(&order[indx]);
fill_time(order[indx].o_entry_d);
pmem_persist((void*)&order[indx], (unsigned)sizeof(order[indx]));
s_fence();
}
void TPCC_DB::update_stock_entry(int threadId, int _w_id, int _i_id, int _d_id, float &amount, int itr) {
int indx = (_w_id-1)*NUM_ITEMS + _i_id-1;
//int ol_quantity = get_random(threadId, 1, 10);
int ol_quantity = 7;
// OPT_ADDR((void*)(0x20), threadId, &stock[indx], sizeof(stock_entry));
// fprintf(stdout, "thread=%d, line=%d\n", threadId, __LINE__);
//backUpInst->update_stock_entry_indx[itr] = indx;
//stock[indx].indx = indx;
//backUpInst->stock_entry_back[itr] = stock[indx];
//backUpInst->update_stock_entry_num_valid = itr+1;
//pmem_persist((void*)&backUpInst->update_stock_entry_indx[itr], (unsigned)sizeof(backUpInst->update_stock_entry_indx[itr]));
//pmem_persist((void*)&backUpInst->stock_entry_back[itr], (unsigned)sizeof(backUpInst->stock_entry_back[itr]));
//s_fence();
// fprintf(stdout, "%d\n", __LINE__);
if(stock[indx].s_quantity - ol_quantity > 10) {
stock[indx].s_quantity -= ol_quantity;
}
else {
stock[indx].s_quantity -= ol_quantity;
stock[indx].s_quantity += 91;
}
stock[indx].s_ytd += ol_quantity;
setpage(&stock[indx]);
stock[indx].s_order_cnt += 1;
pmem_persist((void*)&stock[indx], (unsigned)sizeof(stock[indx]));
s_fence();
// fprintf(stdout, "%d\n", __LINE__);
//Korakit
//volatile
amount += ol_quantity * item[_i_id-1].i_price;
}
void TPCC_DB::new_order_tx(int threadId, int w_id, int d_id, int c_id) {
// OPT_VAL((void*)(1), threadId, (void*)backUpInst->district_back_valid.getPtr(), 0);
// OPT_VAL((void*)(2), threadId, (void*)backUpInst->fill_new_order_entry_back_valid.getPtr(), 0);
// OPT_VAL((void*)(3), threadId, (void*)backUpInst->update_order_entry_back_valid.getPtr(), 0);
// OPT_VAL((void*)(4), threadId, (void*)backUpInst->update_stock_entry_num_valid.getPtr(), 0);
int w_indx = (w_id-1);
int d_indx = (w_id-1)*10 + (d_id-1);
int c_indx = (w_id-1)*10*3000 + (d_id-1)*3000 + (c_id-1);
// OPT((void*)(5), threadId, &backUpInst->district_back, &district[d_indx], sizeof(backUpInst->district_back));
// OPT_ADDR((void*)(6), threadId, &backUpInst->new_order_entry_back, sizeof(backUpInst->new_order_entry_back));
/*
queue_t reqLocks;
reqLocks.push(d_indx); // Lock for district
*/
/*
if(TPCC_DEBUG)
std::cout<<"**NOTx** district lock id: "<<d_indx<<std::endl;
*/
// fprintf(stdout, "%d\n", __LINE__);
int ol_cnt = get_random(threadId, 5, 15);
int item_ids[ol_cnt];
for(int i=0; i<ol_cnt; i++) {
int new_item_id;
bool match;
do {
match = false;
new_item_id = get_random(threadId, 1, NUM_ITEMS);
for(int j=0; j<i; j++) {
if(new_item_id == item_ids[j]) {
match = true;
break;
}
}
} while (match);
item_ids[i] = new_item_id;
}
// fprintf(stdout, "%d\n", __LINE__);
std::sort(item_ids, item_ids+ol_cnt);
// fprintf(stdout, "%d\n", __LINE__);
/*
if(TPCC_DEBUG)
std::cout<<"**NOTx** ol_cnt: "<<ol_cnt<<std::endl;
*/
for(int i=0; i<ol_cnt; i++) {
int item_lock_id = num_warehouses*10 + (w_id-1)*NUM_ITEMS + item_ids[i] - 1;
/*
reqLocks.push(item_lock_id); // Lock for each item in stock table
*/
/*
if(TPCC_DEBUG)
std::cout<<"**NOTx** item lock id: "<<item_lock_id<<" thread id: "<<threadId<<std::endl;
*/
}
//Korakit
//remove MT stuff
//acquire_locks(threadId, reqLocks);
/*
if(TPCC_DEBUG)
std::cout<<"**NOTx** finished start tx: "<<std::endl;
*/
float w_tax = warehouse[w_indx].w_tax;
float d_tax = district[d_indx].d_tax;
int d_o_id = district[d_indx].d_next_o_id;
int no_indx = (w_id-1)*10*900 + (d_id-1)*900 + (d_o_id-2101) % 900;
int o_indx = (w_id-1)*10*3000 + (d_id-1)*3000 + (d_o_id-1)%3000;
//Korakit
//real stuff here
// okay we gonna try really simple stuff first
// let's force all writes when the transaction completes
// flush_caches(uint64_t addr, unsigned size);
// s_fence();
// fprintf(stdout, "%d\n", __LINE__);
//prepare backup log
//backUpInst->district_back_valid = 0;
//backUpInst->fill_new_order_entry_back_valid = 0;
//backUpInst->update_order_entry_back_valid = 0;
//backUpInst->update_stock_entry_num_valid = 0;
//s_fence();
// OPT_VAL((void*)(0x41), threadId, (void*)backUpInst->district_back_valid.getPtr(), 1);
// OPT_VAL((void*)(0x42), threadId, (void*)backUpInst->fill_new_order_entry_back_valid.getPtr(), 1);
// OPT_VAL((void*)(0x43), threadId, (void*)backUpInst->update_order_entry_back_valid.getPtr(), 1);
//backUpInst->log_valid = 1;
//pmem_persist((void*)&backUpInst->log_valid, (unsigned)sizeof(backUpInst->log_valid));
//s_fence();
for(int i=0; i<ol_cnt; i++) {
// OPT_ADDR((void*)(0x100UL+i), threadId, &backUpInst->stock_entry_back[i], sizeof(stock_entry));
}
//do backup
//fprintf(stdout, "%d\n", __LINE__);
//backUpInst->district_back = district[d_indx];
//pmem_persist(&backUpInst->district_back, sizeof(backUpInst->district_back));
district[d_indx].d_next_o_id++;
//flush district[d_indx].d_next_o_id++;
//pmem_persist((void*)&district[d_indx].d_next_o_id, (unsigned)sizeof(district[d_indx].d_next_o_id));
//s_fence();
// fprintf(stdout, "%d\n", __LINE__);
fill_new_order_entry(w_id,d_id,d_o_id, threadId);
// fprintf(stdout, "%d\n", __LINE__);
update_order_entry(w_id, d_id, d_o_id, c_id, ol_cnt, threadId);
// fprintf(stdout, "%d\n", __LINE__);
float total_amount = 0.0;
for(int i=0; i<ol_cnt; i++) {
update_stock_entry(threadId, w_id, item_ids[i], d_id, total_amount, i);
}
// fprintf(stdout, "%d\n", __LINE__);
//invalidate log entries
//backUpInst->log_valid = 0;
//pmem_persist((void*)&backUpInst->log_valid, (unsigned)sizeof(backUpInst->log_valid));
//s_fence();
// fprintf(stdout, "%d\n", __LINE__);
/////////////////
//Korakit
//debug removed
/*
if(TPCC_DEBUG)
std::cout<<"d_id, d_o_id, ol_cnt, total_amount: "<<d_id<<", "<<d_o_id<<", "<<
ol_cnt<<", "<<total_amount<<std::endl;
*/
//Korakit
//remove MT stuffs
//release_locks(threadId);
return;
}
unsigned long TPCC_DB::get_random(int thread_id) {
unsigned long tmp;
tmp = rndm_seeds[thread_id*10] = (rndm_seeds[thread_id*10] * 16807) % 2147483647;
//return rand()%(2^32-1);
return tmp;
}
unsigned long TPCC_DB::get_random(int thread_id, int min, int max) {
unsigned long tmp;
//return min+(rand()%(max-min+1));
tmp = rndm_seeds[thread_id*10] = (rndm_seeds[thread_id*10] * 16807) % 2147483647;
return min+(tmp%(max-min+1));
//return tmp
}
//Korakit
//debug removed
/*
void TPCC_DB::printStackPointer(int* sp, int thread_id) {
std::cout<<"Stack Heap: "<<sp<<std::endl;
}
*/
| 24,859 | 34.873016 | 397 | cc |
null | NearPMSW-main/nearpm/checkpointing/include/txopt.cc | #include "txopt.h"
#include <string.h>
// source: http://stackoverflow.com/questions/1919183/how-to-allocate-and-free-aligned-memory-in-c
void *
aligned_malloc(int size) {
void *mem = malloc(size+64+sizeof(void*));
void **ptr = (void**)((uintptr_t)((uint64_t)mem+64+uint64_t(sizeof(void*))) & ~(64-1));
ptr[-1] = mem;
return ptr;
}
// source: http://stackoverflow.com/questions/1640258/need-a-fast-random-generator-for-c
static unsigned long x=123456789, y=362436069, z=521288629;
unsigned long xorshf96() { //period 2^96-1
unsigned long t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
//volatile void s_fence();
// Flush the selected addresses
//volatile void metadata_cache_flush(uint64_t addr, unsigned size);
//volatile void cache_flush(uint64_t addr, unsigned size);
//volatile void flush_caches(uint64_t addr, unsigned size);
// Flush the one cacheline
//volatile inline void metadata_flush(uint64_t addr);
//volatile inline void cache_flush(uint64_t addr);
// Flush the whole caches
//volatile inline void metadata_flush();
//volatile inline void cache_flush();
//volatile void TX_OPT(uint64_t addr, unsigned size);
// Deduplication and Compression are transaparent
/*
class Dedup {
public:
};
class Compress {
public:
}
*/
uint64_t CounterAtomic::currAtomicAddr = COUNTER_ATOMIC_VADDR;
//uint64_t CounterAtomic::currCacheFlushAddr = CACHE_FLUSH_VADDR;
//uint64_t CounterAtomic::currCounterCacheFlushAddr = COUNTER_CACHE_FLUSH_VADDR;
void*
CounterAtomic::counter_atomic_malloc(unsigned _size) {
return (void*)getNextAtomicAddr(_size);
}
volatile void
metadata_cache_flush(void* addr, unsigned size) {
int num_cache_line = size / CACHE_LINE_SIZE;
if ((uint64_t)addr % CACHE_LINE_SIZE)
num_cache_line++;
for (int i = 0; i < num_cache_line; ++i)
*((volatile uint64_t*)METADATA_CACHE_FLUSH_VADDR) = (uint64_t)addr + i * CACHE_LINE_SIZE;
}
volatile void
cache_flush(void* addr, unsigned size) {
int num_cache_line = size / CACHE_LINE_SIZE;
if ((uint64_t)addr % CACHE_LINE_SIZE)
num_cache_line++;
for (int i = 0; i < num_cache_line; ++i)
*((volatile uint64_t*)CACHE_FLUSH_VADDR) = (uint64_t)addr + i * CACHE_LINE_SIZE;
}
volatile void
flush_caches(void* addr, unsigned size) {
cache_flush(addr, size);
metadata_cache_flush(addr, size);
}
// OPT with both data and addr ready
volatile void
OPT(void* opt_obj, bool reg, void* pmemaddr, void* data, unsigned size) {
// fprintf(stderr, "size: %u\n", size);
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
//opt_packet.seg_id = i;
//opt_packet.pmemaddr = (void*)((uint64_t)(pmemaddr) + i * CACHE_LINE_SIZE);
opt_packet.pmemaddr = pmemaddr;
//opt_packet.data_ptr = (void*)((uint64_t)(data) + i * CACHE_LINE_SIZE);
//opt_packet.data_val = 0;
opt_packet.size = size;
opt_packet.type = (!reg ? FLAG_OPT : FLAG_OPT_REG);
//opt_packet.type = FLAG_OPT;
*((opt_packet_t*)TXOPT_VADDR) = opt_packet;
//*((opt_packet_t*)TXOPT_VADDR) = (opt_packet_t){opt_obj, pmemaddr, size, FLAG_OPT_DATA};
}
// OPT with both data (int) and addr ready
volatile void
OPT_VAL(void* opt_obj, bool reg, void* pmemaddr, int data_val) {
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
opt_packet.pmemaddr = pmemaddr;
//opt_packet.data_ptr = 0;
//opt_packet.data_val = data_val;
opt_packet.size = sizeof(int);
opt_packet.type = (!reg ? FLAG_OPT_VAL : FLAG_OPT_VAL_REG);
//opt_packet.type = FLAG_OPT;
*((opt_packet_t*)TXOPT_VADDR) = opt_packet;
}
// OPT with only data ready
volatile void
OPT_DATA(void* opt_obj, bool reg, void* data, unsigned size) {
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
opt_packet.pmemaddr = 0;
//opt_packet.data_ptr = (void*)((uint64_t)(data) + i * CACHE_LINE_SIZE);
//opt_packet.data_val = 0;
opt_packet.size = size;
opt_packet.type = (!reg ? FLAG_OPT_DATA : FLAG_OPT_DATA_REG);
//opt_packet.type = FLAG_OPT;
*((opt_packet_t*)TXOPT_VADDR) = opt_packet;
}
// OPT with only addr ready
volatile void
OPT_ADDR(void* opt_obj, bool reg, void* pmemaddr, unsigned size) {
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
opt_packet.pmemaddr = pmemaddr;
//opt_packet.data_ptr = 0;
//opt_packet.data_val = 0;
opt_packet.size = size;
opt_packet.type = (!reg ? FLAG_OPT_ADDR : FLAG_OPT_ADDR_REG);
//opt_packet.type = FLAG_OPT;
*((opt_packet_t*)TXOPT_VADDR) = opt_packet;
}
// OPT with only data (int) ready
volatile void
OPT_DATA_VAL(void* opt_obj, bool reg, int data_val) {
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
opt_packet.pmemaddr = 0;
//opt_packet.data_ptr = 0;
//opt_packet.data_val = data_val;
opt_packet.size = sizeof(int);
opt_packet.type = (!reg ? FLAG_OPT_DATA_VAL : FLAG_OPT_DATA_VAL_REG);
//opt_packet.type = FLAG_OPT;
*((opt_packet_t*)TXOPT_VADDR) = opt_packet;
}
volatile void
OPT_START(void* opt_obj) {
opt_packet_t opt_packet;
opt_packet.opt_obj = opt_obj;
opt_packet.type = FLAG_OPT_START;
}
volatile void
s_fence() {
std::atomic_thread_fence(std::memory_order_acq_rel);
}
CounterAtomic::CounterAtomic() {
val_addr = getNextAtomicAddr(CACHE_LINE_SIZE);
}
CounterAtomic::CounterAtomic(uint64_t _val) {
val_addr = getNextAtomicAddr(CACHE_LINE_SIZE);
*((volatile uint64_t*)val_addr) = _val;
}
CounterAtomic::CounterAtomic(bool _val) {
*((volatile uint64_t*)val_addr) = uint64_t(_val);
val_addr = getNextAtomicAddr(CACHE_LINE_SIZE);
}
uint64_t
CounterAtomic::getValue() {
return *((volatile uint64_t*)val_addr);
}
uint64_t
CounterAtomic::getPtr() {
return val_addr;
}
CounterAtomic&
CounterAtomic::operator=(uint64_t _val) {
*((volatile uint64_t*)val_addr) = _val;
return *this;
}
CounterAtomic&
CounterAtomic::operator+(uint64_t _val) {
*((volatile uint64_t*)val_addr) += _val;
return *this;
}
CounterAtomic&
CounterAtomic::operator++() {
uint64_t val = *((volatile uint64_t*)val_addr);
val++;
*((volatile uint64_t*)val_addr) = val;
return *this;
}
CounterAtomic&
CounterAtomic::operator--() {
uint64_t val = *((volatile uint64_t*)val_addr);
val--;
*((volatile uint64_t*)val_addr) = val;
return *this;
}
CounterAtomic&
CounterAtomic::operator-(uint64_t _val) {
*((volatile uint64_t*)val_addr) -= _val;
return *this;
}
bool
CounterAtomic::operator==(uint64_t _val) {
return *((volatile uint64_t*)val_addr) == _val;
}
bool
CounterAtomic::operator!=(uint64_t _val) {
return *((volatile uint64_t*)val_addr) != _val;
}
uint64_t
CounterAtomic::getNextAtomicAddr(unsigned _size) {
if (currAtomicAddr + _size >= COUNTER_ATOMIC_VADDR + NUM_COUNTER_ATOMIC_PAGE*4*1024) {
printf("@@not enough counter atomic space, current addr=%lu, size=%u\n", currAtomicAddr, _size);
exit(0);
}
currAtomicAddr += _size;
return (currAtomicAddr - _size);
}
volatile void
CounterAtomic::statOutput() {
*((volatile uint64_t*) (STATUS_OUTPUT_VADDR))= 0;
}
volatile void
CounterAtomic::initCounterCache() {
*((volatile uint64_t*) (INIT_METADATA_CACHE_VADDR))= 0;
}
| 6,969 | 24.345455 | 98 | cc |
null | NearPMSW-main/nearpm/checkpointing/include/txopt.h | // The starting address of the selected counter_atomic writes
#ifndef TXOPT_H
#define TXOPT_H
#define COUNTER_ATOMIC_VADDR (4096UL*1024*1024)
#define NUM_COUNTER_ATOMIC_PAGE 262144
// The starting address of the flush cache instruction
#define CACHE_FLUSH_VADDR (4096UL*1024*1024+4*NUM_COUNTER_ATOMIC_PAGE*1024)
// The starting address of the flush metadata cache instruction
#define METADATA_CACHE_FLUSH_VADDR (4096UL*1024*1024+(4*NUM_COUNTER_ATOMIC_PAGE+4)*1024)
#define STATUS_OUTPUT_VADDR (METADATA_CACHE_FLUSH_VADDR + 1024UL)
#define INIT_METADATA_CACHE_VADDR (STATUS_OUTPUT_VADDR + 1024UL)
#define TXOPT_VADDR (INIT_METADATA_CACHE_VADDR+1024UL)
#define CACHE_LINE_SIZE 64UL
#include <vector>
#include <deque>
#include <cstdlib>
#include <cstdint>
#include <atomic>
#include <stdio.h>
#include <cassert>
enum opt_flag {
FLAG_OPT,
FLAG_OPT_VAL,
FLAG_OPT_ADDR,
FLAG_OPT_DATA,
FLAG_OPT_DATA_VAL,
/* register no execute */
FLAG_OPT_REG,
FLAG_OPT_VAL_REG,
FLAG_OPT_ADDR_REG,
FLAG_OPT_DATA_REG,
FLAG_OPT_DATA_VAL_REG,
/* execute registered OPT */
FLAG_OPT_START
};
struct opt_t {
//int pid;
int obj_id;
};
// Fields in the OPT packet
// Used by both SW and HW
struct opt_packet_t {
void* opt_obj;
void* pmemaddr;
//void* data_ptr;
//int seg_id;
//int data_val;
unsigned size;
opt_flag type;
};
// OPT with both data and addr ready
volatile void OPT(void* opt_obj, bool reg, void* pmemaddr, void* data, unsigned size);
//#define OPT(opt_obj, pmemaddr, data, size) \
// *((opt_packet_t*)TXOPT_VADDR) = (opt_packet_t){opt_obj, pmemaddr, size, FLAG_OPT_DATA};
// OPT with both data (int) and addr ready
volatile void OPT_VAL(void* opt_obj, bool reg, void* pmemaddr, int data_val);
// OPT with only data ready
volatile void OPT_DATA(void* opt_obj, bool reg, void* data, unsigned size);
// OPT with only addr ready
volatile void OPT_ADDR(void* opt_obj, bool reg, void* pmemaddr, unsigned size);
// OPT with only data (int) ready
volatile void OPT_DATA_VAL(void* opt_obj, bool reg, int data_val);
// Begin OPT operation
volatile void OPT_START(void* opt_obj);
// store barrier
volatile void s_fence();
// flush both metadata cache and data cache
volatile void flush_caches(void* addr, unsigned size);
// flush data cache only
volatile void cache_flush(void* addr, unsigned size);
// flush metadata cache only
volatile void metadata_cache_flush(void* addr, unsigned size);
// malloc that is cache-line aligned
void *aligned_malloc(int size);
class CounterAtomic {
public:
static void* counter_atomic_malloc(unsigned _size);
// size is num of bytes
static volatile void statOutput();
static volatile void initCounterCache();
uint64_t getValue();
uint64_t getPtr();
CounterAtomic();
CounterAtomic(uint64_t _val);
CounterAtomic(bool _val);
CounterAtomic& operator=(uint64_t _val);
CounterAtomic& operator+(uint64_t _val);
CounterAtomic& operator++();
CounterAtomic& operator--();
CounterAtomic& operator-(uint64_t _val);
bool operator==(uint64_t _val);
bool operator!=(uint64_t _val);
private:
void init();
static uint64_t getNextAtomicAddr(unsigned _size);
static uint64_t getNextCacheFlushAddr(unsigned _size);
//static uint64_t getNextPersistBarrierAddr(unsigned _size);
static uint64_t getNextCounterCacheFlushAddr(unsigned _size);
static uint64_t currAtomicAddr;
static uint64_t currCacheFlushAddr;
//static uint64_t currPersistentBarrierAddr;
static uint64_t currCounterCacheFlushAddr;
/*
static bool hasAllocateCacheFlush;
static bool hasAllocateCounterCacheFlush;
static bool hasAllocatePersistBarrier;
*/
//uint64_t val;
uint64_t val_addr = 0;
};
#endif
| 3,665 | 26.155556 | 90 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/builddatastoreall.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER
make EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER
cat builddatastoreall.sh
| 236 | 46.4 | 99 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/buildclobber.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER EXTRA_CFLAGS+=-DRUN_COUNT=1
make EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER EXTRA_CFLAGS+=-DRUN_COUNT=1
cat buildclobber.sh
| 171 | 33.4 | 70 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/buildredo.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DRUN_COUNT=1
make EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DRUN_COUNT=1
cat buildredo.sh
| 166 | 32.4 | 69 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/builddatastoreclobber.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER
make EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER
cat builddatastoreclobber.sh
| 182 | 35.6 | 70 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/run.sh | make EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DRUN_COUNT=100000
make EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DRUN_COUNT=100000
make EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DGET_NDP_BREAKDOWN
make -j12 EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DGET_NDP_BREAKDOWN
make -j12 EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DRUN_COUNT=10000 EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER
EXTRA_CFLAGS="-Wno-error"
| 481 | 67.857143 | 112 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/build.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DRUN_COUNT=10000
make EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DRUN_COUNT=10000
cat run.sh
| 180 | 35.2 | 79 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/builddatastore.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DRUN_COUNT=1
make EXTRA_CFLAGS+=-DRUN_COUNT=1
cat builddatastore.sh
| 111 | 21.4 | 38 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/builddatastoreredo.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_REDO
make EXTRA_CFLAGS+=-DRUN_COUNT=1 EXTRA_CFLAGS+=-DUSE_NDP_REDO
cat builddatastoreredo.sh
| 173 | 33.8 | 67 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/buildall.sh | make clobber
make -j12 EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER EXTRA_CFLAGS+=-DRUN_COUNT=10000
make EXTRA_CFLAGS+=-DGET_NDP_PERFORMENCE EXTRA_CFLAGS+=-DUSE_NDP_REDO EXTRA_CFLAGS+=-DUSE_NDP_CLOBBER EXTRA_CFLAGS+=-DRUN_COUNT=10000
cat run.sh
| 300 | 59.2 | 139 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_config.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_config.h -- internal definitions for rpmemd config
*/
#include <stdint.h>
#include <stdbool.h>
#ifndef RPMEMD_DEFAULT_LOG_FILE
#define RPMEMD_DEFAULT_LOG_FILE ("/var/log/" DAEMON_NAME ".log")
#endif
#ifndef RPMEMD_GLOBAL_CONFIG_FILE
#define RPMEMD_GLOBAL_CONFIG_FILE ("/etc/" DAEMON_NAME "/" DAEMON_NAME\
".conf")
#endif
#define RPMEMD_USER_CONFIG_FILE ("." DAEMON_NAME ".conf")
#define RPMEM_DEFAULT_MAX_LANES 1024
#define RPMEM_DEFAULT_NTHREADS 0
#define HOME_ENV "HOME"
#define HOME_STR_PLACEHOLDER ("$" HOME_ENV)
struct rpmemd_config {
char *log_file;
char *poolset_dir;
const char *rm_poolset;
bool force;
bool pool_set;
bool persist_apm;
bool persist_general;
bool use_syslog;
uint64_t max_lanes;
enum rpmemd_log_level log_level;
size_t nthreads;
};
int rpmemd_config_read(struct rpmemd_config *config, int argc, char *argv[]);
void rpmemd_config_free(struct rpmemd_config *config);
| 1,012 | 21.021739 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_log.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_log.h -- rpmemd logging functions declarations
*/
#include <string.h>
#include "util.h"
#define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
/*
* The tab character is not allowed in rpmemd log,
* because it is not well handled by syslog.
* Please use RPMEMD_LOG_INDENT instead.
*/
#define RPMEMD_LOG_INDENT " "
#ifdef DEBUG
#define RPMEMD_LOG(level, fmt, arg...) do {\
COMPILE_ERROR_ON(strchr(fmt, '\t') != 0);\
rpmemd_log(RPD_LOG_##level, __FILE__, __LINE__, fmt, ## arg);\
} while (0)
#else
#define RPMEMD_LOG(level, fmt, arg...) do {\
COMPILE_ERROR_ON(strchr(fmt, '\t') != 0);\
rpmemd_log(RPD_LOG_##level, NULL, 0, fmt, ## arg);\
} while (0)
#endif
#ifdef DEBUG
#define RPMEMD_DBG(fmt, arg...) do {\
COMPILE_ERROR_ON(strchr(fmt, '\t') != 0);\
rpmemd_log(_RPD_LOG_DBG, __FILE__, __LINE__, fmt, ## arg);\
} while (0)
#else
#define RPMEMD_DBG(fmt, arg...) do {} while (0)
#endif
#define RPMEMD_ERR(fmt, arg...) do {\
RPMEMD_LOG(ERR, fmt, ## arg);\
} while (0)
#define RPMEMD_FATAL(fmt, arg...) do {\
RPMEMD_LOG(ERR, fmt, ## arg);\
abort();\
} while (0)
#define RPMEMD_ASSERT(cond) do {\
if (!(cond)) {\
rpmemd_log(RPD_LOG_ERR, __FILE__, __LINE__,\
"assertion fault: %s", #cond);\
abort();\
}\
} while (0)
enum rpmemd_log_level {
RPD_LOG_ERR,
RPD_LOG_WARN,
RPD_LOG_NOTICE,
RPD_LOG_INFO,
_RPD_LOG_DBG, /* disallow to use this with LOG macro */
MAX_RPD_LOG,
};
enum rpmemd_log_level rpmemd_log_level_from_str(const char *str);
const char *rpmemd_log_level_to_str(enum rpmemd_log_level level);
extern enum rpmemd_log_level rpmemd_log_level;
int rpmemd_log_init(const char *ident, const char *fname, int use_syslog);
void rpmemd_log_close(void);
int rpmemd_prefix(const char *fmt, ...) FORMAT_PRINTF(1, 2);
void rpmemd_log(enum rpmemd_log_level level, const char *fname,
int lineno, const char *fmt, ...) FORMAT_PRINTF(4, 5);
| 1,991 | 25.210526 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_db.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_db.h -- internal definitions for rpmemd database of pool set files
*/
struct rpmemd_db;
struct rpmem_pool_attr;
/*
* struct rpmemd_db_pool -- remote pool context
*/
struct rpmemd_db_pool {
void *pool_addr;
size_t pool_size;
struct pool_set *set;
};
struct rpmemd_db *rpmemd_db_init(const char *root_dir, mode_t mode);
struct rpmemd_db_pool *rpmemd_db_pool_create(struct rpmemd_db *db,
const char *pool_desc, size_t pool_size,
const struct rpmem_pool_attr *rattr);
struct rpmemd_db_pool *rpmemd_db_pool_open(struct rpmemd_db *db,
const char *pool_desc, size_t pool_size, struct rpmem_pool_attr *rattr);
int rpmemd_db_pool_remove(struct rpmemd_db *db, const char *pool_desc,
int force, int pool_set);
int rpmemd_db_pool_set_attr(struct rpmemd_db_pool *prp,
const struct rpmem_pool_attr *rattr);
void rpmemd_db_pool_close(struct rpmemd_db *db, struct rpmemd_db_pool *prp);
void rpmemd_db_fini(struct rpmemd_db *db);
int rpmemd_db_check_dir(struct rpmemd_db *db);
int rpmemd_db_pool_is_pmem(struct rpmemd_db_pool *pool);
| 1,132 | 32.323529 | 76 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_util.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2018, Intel Corporation */
/*
* rpmemd_util.h -- rpmemd utility functions declarations
*/
int rpmemd_pmem_persist(const void *addr, size_t len);
int rpmemd_flush_fatal(const void *addr, size_t len);
int rpmemd_apply_pm_policy(enum rpmem_persist_method *persist_method,
int (**persist)(const void *addr, size_t len),
void *(**memcpy_persist)(void *pmemdest, const void *src, size_t len),
const int is_pmem);
| 473 | 32.857143 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_fip.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_fip.h -- rpmemd libfabric provider module header file
*/
#include <stddef.h>
struct rpmemd_fip;
struct rpmemd_fip_attr {
void *addr;
size_t size;
unsigned nlanes;
size_t nthreads;
size_t buff_size;
enum rpmem_provider provider;
enum rpmem_persist_method persist_method;
int (*persist)(const void *addr, size_t len);
void *(*memcpy_persist)(void *pmemdest, const void *src, size_t len);
int (*deep_persist)(const void *addr, size_t len, void *ctx);
void *ctx;
};
struct rpmemd_fip *rpmemd_fip_init(const char *node,
const char *service,
struct rpmemd_fip_attr *attr,
struct rpmem_resp_attr *resp,
enum rpmem_err *err);
void rpmemd_fip_fini(struct rpmemd_fip *fip);
int rpmemd_fip_accept(struct rpmemd_fip *fip, int timeout);
int rpmemd_fip_process_start(struct rpmemd_fip *fip);
int rpmemd_fip_process_stop(struct rpmemd_fip *fip);
int rpmemd_fip_wait_close(struct rpmemd_fip *fip, int timeout);
int rpmemd_fip_close(struct rpmemd_fip *fip);
| 1,066 | 27.078947 | 70 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016, Intel Corporation */
/*
* rpmemd.h -- rpmemd main header file
*/
#define DAEMON_NAME "rpmemd"
| 158 | 16.666667 | 40 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/rpmemd/rpmemd_obc.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_obc.h -- rpmemd out-of-band connection declarations
*/
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
struct rpmemd_obc;
struct rpmemd_obc_requests {
int (*create)(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req,
const struct rpmem_pool_attr *pool_attr);
int (*open)(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req);
int (*close)(struct rpmemd_obc *obc, void *arg, int flags);
int (*set_attr)(struct rpmemd_obc *obc, void *arg,
const struct rpmem_pool_attr *pool_attr);
};
struct rpmemd_obc *rpmemd_obc_init(int fd_in, int fd_out);
void rpmemd_obc_fini(struct rpmemd_obc *obc);
int rpmemd_obc_status(struct rpmemd_obc *obc, uint32_t status);
int rpmemd_obc_process(struct rpmemd_obc *obc,
struct rpmemd_obc_requests *req_cb, void *arg);
int rpmemd_obc_create_resp(struct rpmemd_obc *obc,
int status, const struct rpmem_resp_attr *res);
int rpmemd_obc_open_resp(struct rpmemd_obc *obc,
int status, const struct rpmem_resp_attr *res,
const struct rpmem_pool_attr *pool_attr);
int rpmemd_obc_set_attr_resp(struct rpmemd_obc *obc, int status);
int rpmemd_obc_close_resp(struct rpmemd_obc *obc,
int status);
| 1,296 | 31.425 | 65 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/check.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* check.h -- pmempool check command header file
*/
int pmempool_check_func(const char *appname, int argc, char *argv[]);
void pmempool_check_help(const char *appname);
| 261 | 25.2 | 69 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/create.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* create.h -- pmempool create command header file
*/
int pmempool_create_func(const char *appname, int argc, char *argv[]);
void pmempool_create_help(const char *appname);
| 265 | 25.6 | 70 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/dump.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* dump.h -- pmempool dump command header file
*/
int pmempool_dump_func(const char *appname, int argc, char *argv[]);
void pmempool_dump_help(const char *appname);
| 257 | 24.8 | 68 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/rm.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* rm.h -- pmempool rm command header file
*/
void pmempool_rm_help(const char *appname);
int pmempool_rm_func(const char *appname, int argc, char *argv[]);
| 249 | 24 | 66 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/feature.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018, Intel Corporation */
/*
* feature.h -- pmempool feature command header file
*/
int pmempool_feature_func(const char *appname, int argc, char *argv[]);
void pmempool_feature_help(const char *appname);
| 264 | 25.5 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/convert.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* convert.h -- pmempool convert command header file
*/
#include <sys/types.h>
int pmempool_convert_func(const char *appname, int argc, char *argv[]);
void pmempool_convert_help(const char *appname);
| 293 | 23.5 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/synchronize.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* synchronize.h -- pmempool sync command header file
*/
int pmempool_sync_func(const char *appname, int argc, char *argv[]);
void pmempool_sync_help(const char *appname);
| 264 | 25.5 | 68 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* common.h -- declarations of common functions
*/
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdbool.h>
#include "queue.h"
#include "log.h"
#include "blk.h"
#include "libpmemobj.h"
#include "lane.h"
#include "ulog.h"
#include "memops.h"
#include "pmalloc.h"
#include "list.h"
#include "obj.h"
#include "memblock.h"
#include "heap_layout.h"
#include "tx.h"
#include "heap.h"
#include "btt_layout.h"
#include "page_size.h"
/* XXX - modify Linux makefiles to generate srcversion.h and remove #ifdef */
#ifdef _WIN32
#include "srcversion.h"
#endif
#define COUNT_OF(x) (sizeof(x) / sizeof(0[x]))
#define OPT_SHIFT 12
#define OPT_MASK (~((1 << OPT_SHIFT) - 1))
#define OPT_LOG (1 << (PMEM_POOL_TYPE_LOG + OPT_SHIFT))
#define OPT_BLK (1 << (PMEM_POOL_TYPE_BLK + OPT_SHIFT))
#define OPT_OBJ (1 << (PMEM_POOL_TYPE_OBJ + OPT_SHIFT))
#define OPT_BTT (1 << (PMEM_POOL_TYPE_BTT + OPT_SHIFT))
#define OPT_ALL (OPT_LOG | OPT_BLK | OPT_OBJ | OPT_BTT)
#define OPT_REQ_SHIFT 8
#define OPT_REQ_MASK ((1 << OPT_REQ_SHIFT) - 1)
#define _OPT_REQ(c, n) ((c) << (OPT_REQ_SHIFT * (n)))
#define OPT_REQ0(c) _OPT_REQ(c, 0)
#define OPT_REQ1(c) _OPT_REQ(c, 1)
#define OPT_REQ2(c) _OPT_REQ(c, 2)
#define OPT_REQ3(c) _OPT_REQ(c, 3)
#define OPT_REQ4(c) _OPT_REQ(c, 4)
#define OPT_REQ5(c) _OPT_REQ(c, 5)
#define OPT_REQ6(c) _OPT_REQ(c, 6)
#define OPT_REQ7(c) _OPT_REQ(c, 7)
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#define FOREACH_RANGE(range, ranges)\
PMDK_LIST_FOREACH(range, &(ranges)->head, next)
#define PLIST_OFF_TO_PTR(pop, off)\
((off) == 0 ? NULL : (void *)((uintptr_t)(pop) + (off) - OBJ_OOB_SIZE))
#define ENTRY_TO_ALLOC_HDR(entry)\
((void *)((uintptr_t)(entry) - sizeof(struct allocation_header)))
#define OBJH_FROM_PTR(ptr)\
((void *)((uintptr_t)(ptr) - sizeof(struct legacy_object_header)))
#define DEFAULT_HDR_SIZE PMEM_PAGESIZE
#define DEFAULT_DESC_SIZE PMEM_PAGESIZE
#define POOL_HDR_DESC_SIZE (DEFAULT_HDR_SIZE + DEFAULT_DESC_SIZE)
#define PTR_TO_ALLOC_HDR(ptr)\
((void *)((uintptr_t)(ptr) -\
sizeof(struct legacy_object_header)))
#define OBJH_TO_PTR(objh)\
((void *)((uintptr_t)(objh) + sizeof(struct legacy_object_header)))
/* invalid answer for ask_* functions */
#define INV_ANS '\0'
#define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
/*
* pmem_pool_type_t -- pool types
*/
typedef enum {
PMEM_POOL_TYPE_LOG = 0x01,
PMEM_POOL_TYPE_BLK = 0x02,
PMEM_POOL_TYPE_OBJ = 0x04,
PMEM_POOL_TYPE_BTT = 0x08,
PMEM_POOL_TYPE_ALL = 0x0f,
PMEM_POOL_TYPE_UNKNOWN = 0x80,
} pmem_pool_type_t;
struct option_requirement {
int opt;
pmem_pool_type_t type;
uint64_t req;
};
struct options {
const struct option *opts;
size_t noptions;
char *bitmap;
const struct option_requirement *req;
};
struct pmem_pool_params {
pmem_pool_type_t type;
char signature[POOL_HDR_SIG_LEN];
uint64_t size;
mode_t mode;
int is_poolset;
int is_part;
int is_checksum_ok;
union {
struct {
uint64_t bsize;
} blk;
struct {
char layout[PMEMOBJ_MAX_LAYOUT];
} obj;
};
};
struct pool_set_file {
int fd;
char *fname;
void *addr;
size_t size;
struct pool_set *poolset;
size_t replica;
time_t mtime;
mode_t mode;
bool fileio;
};
struct pool_set_file *pool_set_file_open(const char *fname,
int rdonly, int check);
void pool_set_file_close(struct pool_set_file *file);
int pool_set_file_read(struct pool_set_file *file, void *buff,
size_t nbytes, uint64_t off);
int pool_set_file_write(struct pool_set_file *file, void *buff,
size_t nbytes, uint64_t off);
int pool_set_file_set_replica(struct pool_set_file *file, size_t replica);
size_t pool_set_file_nreplicas(struct pool_set_file *file);
void *pool_set_file_map(struct pool_set_file *file, uint64_t offset);
void pool_set_file_persist(struct pool_set_file *file,
const void *addr, size_t len);
struct range {
PMDK_LIST_ENTRY(range) next;
uint64_t first;
uint64_t last;
};
struct ranges {
PMDK_LIST_HEAD(rangeshead, range) head;
};
pmem_pool_type_t pmem_pool_type_parse_hdr(const struct pool_hdr *hdrp);
pmem_pool_type_t pmem_pool_type(const void *base_pool_addr);
int pmem_pool_checksum(const void *base_pool_addr);
pmem_pool_type_t pmem_pool_type_parse_str(const char *str);
uint64_t pmem_pool_get_min_size(pmem_pool_type_t type);
int pmem_pool_parse_params(const char *fname, struct pmem_pool_params *paramsp,
int check);
int util_poolset_map(const char *fname, struct pool_set **poolset, int rdonly);
struct options *util_options_alloc(const struct option *options,
size_t nopts, const struct option_requirement *req);
void util_options_free(struct options *opts);
int util_options_verify(const struct options *opts, pmem_pool_type_t type);
int util_options_getopt(int argc, char *argv[], const char *optstr,
const struct options *opts);
pmem_pool_type_t util_get_pool_type_second_page(const void *pool_base_addr);
int util_parse_mode(const char *str, mode_t *mode);
int util_parse_ranges(const char *str, struct ranges *rangesp,
struct range entire);
int util_ranges_add(struct ranges *rangesp, struct range range);
void util_ranges_clear(struct ranges *rangesp);
int util_ranges_contain(const struct ranges *rangesp, uint64_t n);
int util_ranges_empty(const struct ranges *rangesp);
int util_check_memory(const uint8_t *buff, size_t len, uint8_t val);
int util_parse_chunk_types(const char *str, uint64_t *types);
int util_parse_lane_sections(const char *str, uint64_t *types);
char ask(char op, char *answers, char def_ans, const char *fmt, va_list ap);
char ask_Yn(char op, const char *fmt, ...) FORMAT_PRINTF(2, 3);
char ask_yN(char op, const char *fmt, ...) FORMAT_PRINTF(2, 3);
unsigned util_heap_max_zone(size_t size);
int util_pool_clear_badblocks(const char *path, int create);
static const struct range ENTIRE_UINT64 = {
{ NULL, NULL }, /* range */
0, /* first */
UINT64_MAX /* last */
};
| 5,957 | 28.205882 | 79 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/transform.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* transform.h -- pmempool transform command header file
*/
int pmempool_transform_func(const char *appname, int argc, char *argv[]);
void pmempool_transform_help(const char *appname);
| 277 | 26.8 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/info.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2019, Intel Corporation */
/*
* info.h -- pmempool info command header file
*/
#include "vec.h"
/*
* Verbose levels used in application:
*
* VERBOSE_DEFAULT:
* Default value for application's verbosity level.
* This is also set for data structures which should be
* printed without any command line argument.
*
* VERBOSE_MAX:
* Maximum value for application's verbosity level.
* This value is used when -v command line argument passed.
*
* VERBOSE_SILENT:
* This value is higher than VERBOSE_MAX and it is used only
* for verbosity levels of data structures which should _not_ be
* printed without specified command line arguments.
*/
#define VERBOSE_SILENT 0
#define VERBOSE_DEFAULT 1
#define VERBOSE_MAX 2
/*
* print_bb_e -- printing bad blocks options
*/
enum print_bb_e {
PRINT_BAD_BLOCKS_NOT_SET,
PRINT_BAD_BLOCKS_NO,
PRINT_BAD_BLOCKS_YES,
PRINT_BAD_BLOCKS_MAX
};
/*
* pmempool_info_args -- structure for storing command line arguments
*/
struct pmempool_info_args {
char *file; /* input file */
unsigned col_width; /* column width for printing fields */
bool human; /* sizes in human-readable formats */
bool force; /* force parsing pool */
enum print_bb_e badblocks; /* print bad blocks */
pmem_pool_type_t type; /* forced pool type */
bool use_range; /* use range for blocks */
struct ranges ranges; /* range of block/chunks to dump */
int vlevel; /* verbosity level */
int vdata; /* verbosity level for data dump */
int vhdrdump; /* verbosity level for headers hexdump */
int vstats; /* verbosity level for statistics */
struct {
size_t walk; /* data chunk size */
} log;
struct {
int vmap; /* verbosity level for BTT Map */
int vflog; /* verbosity level for BTT FLOG */
int vbackup; /* verbosity level for BTT Info backup */
bool skip_zeros; /* skip blocks marked with zero flag */
bool skip_error; /* skip blocks marked with error flag */
bool skip_no_flag; /* skip blocks not marked with any flag */
} blk;
struct {
int vlanes; /* verbosity level for lanes */
int vroot;
int vobjects;
int valloc;
int voobhdr;
int vheap;
int vzonehdr;
int vchunkhdr;
int vbitmap;
bool lanes_recovery;
bool ignore_empty_obj;
uint64_t chunk_types;
size_t replica;
struct ranges lane_ranges;
struct ranges type_ranges;
struct ranges zone_ranges;
struct ranges chunk_ranges;
} obj;
};
/*
* pmem_blk_stats -- structure with statistics for pmemblk
*/
struct pmem_blk_stats {
uint32_t total; /* number of processed blocks */
uint32_t zeros; /* number of blocks marked by zero flag */
uint32_t errors; /* number of blocks marked by error flag */
uint32_t noflag; /* number of blocks not marked with any flag */
};
struct pmem_obj_class_stats {
uint64_t n_units;
uint64_t n_used;
uint64_t unit_size;
uint64_t alignment;
uint32_t nallocs;
uint16_t flags;
};
struct pmem_obj_zone_stats {
uint64_t n_chunks;
uint64_t n_chunks_type[MAX_CHUNK_TYPE];
uint64_t size_chunks;
uint64_t size_chunks_type[MAX_CHUNK_TYPE];
VEC(, struct pmem_obj_class_stats) class_stats;
};
struct pmem_obj_type_stats {
PMDK_TAILQ_ENTRY(pmem_obj_type_stats) next;
uint64_t type_num;
uint64_t n_objects;
uint64_t n_bytes;
};
struct pmem_obj_stats {
uint64_t n_total_objects;
uint64_t n_total_bytes;
uint64_t n_zones;
uint64_t n_zones_used;
struct pmem_obj_zone_stats *zone_stats;
PMDK_TAILQ_HEAD(obj_type_stats_head, pmem_obj_type_stats) type_stats;
};
/*
* pmem_info -- context for pmeminfo application
*/
struct pmem_info {
const char *file_name; /* current file name */
struct pool_set_file *pfile;
struct pmempool_info_args args; /* arguments parsed from command line */
struct options *opts;
struct pool_set *poolset;
pmem_pool_type_t type;
struct pmem_pool_params params;
struct {
struct pmem_blk_stats stats;
} blk;
struct {
struct pmemobjpool *pop;
struct palloc_heap *heap;
struct alloc_class_collection *alloc_classes;
size_t size;
struct pmem_obj_stats stats;
uint64_t uuid_lo;
uint64_t objid;
} obj;
};
int pmempool_info_func(const char *appname, int argc, char *argv[]);
void pmempool_info_help(const char *appname);
int pmempool_info_read(struct pmem_info *pip, void *buff,
size_t nbytes, uint64_t off);
int pmempool_info_blk(struct pmem_info *pip);
int pmempool_info_log(struct pmem_info *pip);
int pmempool_info_obj(struct pmem_info *pip);
int pmempool_info_btt(struct pmem_info *pip);
| 4,492 | 25.904192 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/tools/pmempool/output.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2018, Intel Corporation */
/*
* output.h -- declarations of output printing related functions
*/
#include <time.h>
#include <stdint.h>
#include <stdio.h>
void out_set_vlevel(int vlevel);
void out_set_stream(FILE *stream);
void out_set_prefix(const char *prefix);
void out_set_col_width(unsigned col_width);
void outv_err(const char *fmt, ...) FORMAT_PRINTF(1, 2);
void out_err(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void outv_err_vargs(const char *fmt, va_list ap);
void outv_indent(int vlevel, int i);
void outv(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void outv_nl(int vlevel);
int outv_check(int vlevel);
void outv_title(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void outv_field(int vlevel, const char *field, const char *fmt,
...) FORMAT_PRINTF(3, 4);
void outv_hexdump(int vlevel, const void *addr, size_t len, size_t offset,
int sep);
const char *out_get_uuid_str(uuid_t uuid);
const char *out_get_time_str(time_t time);
const char *out_get_size_str(uint64_t size, int human);
const char *out_get_percentage(double percentage);
const char *out_get_checksum(void *addr, size_t len, uint64_t *csump,
uint64_t skip_off);
const char *out_get_btt_map_entry(uint32_t map);
const char *out_get_pool_type_str(pmem_pool_type_t type);
const char *out_get_pool_signature(pmem_pool_type_t type);
const char *out_get_tx_state_str(uint64_t state);
const char *out_get_chunk_type_str(enum chunk_type type);
const char *out_get_chunk_flags(uint16_t flags);
const char *out_get_zone_magic_str(uint32_t magic);
const char *out_get_pmemoid_str(PMEMoid oid, uint64_t uuid_lo);
const char *out_get_arch_machine_class_str(uint8_t machine_class);
const char *out_get_arch_data_str(uint8_t data);
const char *out_get_arch_machine_str(uint16_t machine);
const char *out_get_last_shutdown_str(uint8_t dirty);
const char *out_get_alignment_desc_str(uint64_t ad, uint64_t cur_ad);
const char *out_get_incompat_features_str(uint32_t incompat);
| 2,070 | 41.265306 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmemlog/log.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* log.h -- internal definitions for libpmem log module
*/
#ifndef LOG_H
#define LOG_H 1
#include <stdint.h>
#include <stddef.h>
#include <endian.h>
#include "ctl.h"
#include "util.h"
#include "os_thread.h"
#include "pool_hdr.h"
#include "page_size.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "alloc.h"
#include "fault_injection.h"
#define PMEMLOG_LOG_PREFIX "libpmemlog"
#define PMEMLOG_LOG_LEVEL_VAR "PMEMLOG_LOG_LEVEL"
#define PMEMLOG_LOG_FILE_VAR "PMEMLOG_LOG_FILE"
/* attributes of the log memory pool format for the pool header */
#define LOG_HDR_SIG "PMEMLOG" /* must be 8 bytes including '\0' */
#define LOG_FORMAT_MAJOR 1
#define LOG_FORMAT_FEAT_DEFAULT \
{POOL_FEAT_COMPAT_DEFAULT, POOL_FEAT_INCOMPAT_DEFAULT, 0x0000}
#define LOG_FORMAT_FEAT_CHECK \
{POOL_FEAT_COMPAT_VALID, POOL_FEAT_INCOMPAT_VALID, 0x0000}
static const features_t log_format_feat_default = LOG_FORMAT_FEAT_DEFAULT;
struct pmemlog {
struct pool_hdr hdr; /* memory pool header */
/* root info for on-media format... */
uint64_t start_offset; /* start offset of the usable log space */
uint64_t end_offset; /* maximum offset of the usable log space */
uint64_t write_offset; /* current write point for the log */
/* some run-time state, allocated out of memory pool... */
void *addr; /* mapped region */
size_t size; /* size of mapped region */
int is_pmem; /* true if pool is PMEM */
int rdonly; /* true if pool is opened read-only */
os_rwlock_t *rwlockp; /* pointer to RW lock */
int is_dev_dax; /* true if mapped on device dax */
struct ctl *ctl; /* top level node of the ctl tree structure */
struct pool_set *set; /* pool set info */
};
/* data area starts at this alignment after the struct pmemlog above */
#define LOG_FORMAT_DATA_ALIGN ((uintptr_t)PMEM_PAGESIZE)
/*
* log_convert2h -- convert pmemlog structure to host byte order
*/
static inline void
log_convert2h(struct pmemlog *plp)
{
plp->start_offset = le64toh(plp->start_offset);
plp->end_offset = le64toh(plp->end_offset);
plp->write_offset = le64toh(plp->write_offset);
}
/*
* log_convert2le -- convert pmemlog structure to LE byte order
*/
static inline void
log_convert2le(struct pmemlog *plp)
{
plp->start_offset = htole64(plp->start_offset);
plp->end_offset = htole64(plp->end_offset);
plp->write_offset = htole64(plp->write_offset);
}
#if FAULT_INJECTION
void
pmemlog_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at);
int
pmemlog_fault_injection_enabled(void);
#else
static inline void
pmemlog_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at)
{
abort();
}
static inline int
pmemlog_fault_injection_enabled(void)
{
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
#endif
| 2,832 | 23.422414 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/freebsd/include/endian.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* endian.h -- redirect for FreeBSD <sys/endian.h>
*/
#include <sys/endian.h>
| 165 | 17.444444 | 50 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/freebsd/include/features.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* features.h -- Empty file redirect
*/
| 126 | 17.142857 | 40 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/freebsd/include/sys/sysmacros.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* sys/sysmacros.h -- Empty file redirect
*/
| 131 | 17.857143 | 41 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/freebsd/include/linux/kdev_t.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* linux/kdev_t.h -- Empty file redirect
*/
| 130 | 17.714286 | 40 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/freebsd/include/linux/limits.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* linux/limits.h -- Empty file redirect
*/
| 130 | 17.714286 | 40 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/pmemcore.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* pmemcore.h -- definitions for "core" module
*/
#ifndef PMEMCORE_H
#define PMEMCORE_H 1
#include "util.h"
#include "out.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* core_init -- core module initialization
*/
static inline void
core_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version)
{
util_init();
out_init(log_prefix, log_level_var, log_file_var, major_version,
minor_version);
}
/*
* core_fini -- core module cleanup
*/
static inline void
core_fini(void)
{
out_fini();
}
#ifdef __cplusplus
}
#endif
#endif
| 687 | 14.288889 | 65 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/fault_injection.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
#ifndef CORE_FAULT_INJECTION
#define CORE_FAULT_INJECTION
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
enum pmem_allocation_type { PMEM_MALLOC, PMEM_REALLOC };
#if FAULT_INJECTION
void core_inject_fault_at(enum pmem_allocation_type type,
int nth, const char *at);
int core_fault_injection_enabled(void);
#else
static inline void
core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at)
{
abort();
}
static inline int
core_fault_injection_enabled(void)
{
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
#endif
| 642 | 15.075 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/os.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2020, Intel Corporation */
/*
* os.h -- os abstraction layer
*/
#ifndef PMDK_OS_H
#define PMDK_OS_H 1
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include "errno_freebsd.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32
#define OS_DIR_SEPARATOR '/'
#define OS_DIR_SEP_STR "/"
#else
#define OS_DIR_SEPARATOR '\\'
#define OS_DIR_SEP_STR "\\"
#endif
#ifndef _WIN32
/* madvise() */
#ifdef __FreeBSD__
#define os_madvise minherit
#define MADV_DONTFORK INHERIT_NONE
#else
#define os_madvise madvise
#endif
/* dlopen() */
#ifdef __FreeBSD__
#define RTLD_DEEPBIND 0 /* XXX */
#endif
/* major(), minor() */
#ifdef __FreeBSD__
#define os_major (unsigned)major
#define os_minor (unsigned)minor
#else
#define os_major major
#define os_minor minor
#endif
#endif /* #ifndef _WIN32 */
struct iovec;
/* os_flock */
#define OS_LOCK_SH 1
#define OS_LOCK_EX 2
#define OS_LOCK_NB 4
#define OS_LOCK_UN 8
#ifndef _WIN32
typedef struct stat os_stat_t;
#define os_fstat fstat
#define os_lseek lseek
#else
typedef struct _stat64 os_stat_t;
#define os_fstat _fstat64
#define os_lseek _lseeki64
#endif
#define os_close close
#define os_fclose fclose
#ifndef _WIN32
typedef off_t os_off_t;
#else
/* XXX: os_off_t defined in platform.h */
#endif
int os_open(const char *pathname, int flags, ...);
int os_fsync(int fd);
int os_fsync_dir(const char *dir_name);
int os_stat(const char *pathname, os_stat_t *buf);
int os_unlink(const char *pathname);
int os_access(const char *pathname, int mode);
FILE *os_fopen(const char *pathname, const char *mode);
FILE *os_fdopen(int fd, const char *mode);
int os_chmod(const char *pathname, mode_t mode);
int os_mkstemp(char *temp);
int os_posix_fallocate(int fd, os_off_t offset, os_off_t len);
int os_ftruncate(int fd, os_off_t length);
int os_flock(int fd, int operation);
ssize_t os_writev(int fd, const struct iovec *iov, int iovcnt);
int os_clock_gettime(int id, struct timespec *ts);
unsigned os_rand_r(unsigned *seedp);
int os_unsetenv(const char *name);
int os_setenv(const char *name, const char *value, int overwrite);
char *os_getenv(const char *name);
const char *os_strsignal(int sig);
int os_execv(const char *path, char *const argv[]);
/*
* XXX: missing APis (used in ut_file.c)
*
* rename
* read
* write
*/
#ifdef __cplusplus
}
#endif
#endif /* os.h */
| 2,388 | 19.594828 | 66 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/util.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* Copyright (c) 2016-2020, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util.h -- internal definitions for util module
*/
#ifndef PMDK_UTIL_H
#define PMDK_UTIL_H 1
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#ifdef _MSC_VER
#include <intrin.h> /* popcnt, bitscan */
#endif
#include <sys/param.h>
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned long long Pagesize;
extern unsigned long long Mmap_align;
#if defined(__x86_64) || defined(_M_X64) || defined(__aarch64__)
#define CACHELINE_SIZE 64ULL
#elif defined(__PPC64__)
#define CACHELINE_SIZE 128ULL
#else
#error unable to recognize architecture at compile time
#endif
#define PAGE_ALIGNED_DOWN_SIZE(size) ((size) & ~(Pagesize - 1))
#define PAGE_ALIGNED_UP_SIZE(size)\
PAGE_ALIGNED_DOWN_SIZE((size) + (Pagesize - 1))
#define IS_PAGE_ALIGNED(size) (((size) & (Pagesize - 1)) == 0)
#define IS_MMAP_ALIGNED(size) (((size) & (Mmap_align - 1)) == 0)
#define PAGE_ALIGN_UP(addr) ((void *)PAGE_ALIGNED_UP_SIZE((uintptr_t)(addr)))
#define ALIGN_UP(size, align) (((size) + (align) - 1) & ~((align) - 1))
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
#define ADDR_SUM(vp, lp) ((void *)((char *)(vp) + (lp)))
#define util_alignof(t) offsetof(struct {char _util_c; t _util_m; }, _util_m)
#define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
void util_init(void);
int util_is_zeroed(const void *addr, size_t len);
uint64_t util_checksum_compute(void *addr, size_t len, uint64_t *csump,
size_t skip_off);
int util_checksum(void *addr, size_t len, uint64_t *csump,
int insert, size_t skip_off);
uint64_t util_checksum_seq(const void *addr, size_t len, uint64_t csum);
int util_parse_size(const char *str, size_t *sizep);
char *util_fgets(char *buffer, int max, FILE *stream);
char *util_getexecname(char *path, size_t pathlen);
char *util_part_realpath(const char *path);
int util_compare_file_inodes(const char *path1, const char *path2);
void *util_aligned_malloc(size_t alignment, size_t size);
void util_aligned_free(void *ptr);
struct tm *util_localtime(const time_t *timep);
int util_safe_strcpy(char *dst, const char *src, size_t max_length);
void util_emit_log(const char *lib, const char *func, int order);
char *util_readline(FILE *fh);
int util_snprintf(char *str, size_t size,
const char *format, ...) FORMAT_PRINTF(3, 4);
#ifdef _WIN32
char *util_toUTF8(const wchar_t *wstr);
wchar_t *util_toUTF16(const char *wstr);
void util_free_UTF8(char *str);
void util_free_UTF16(wchar_t *str);
int util_toUTF16_buff(const char *in, wchar_t *out, size_t out_size);
int util_toUTF8_buff(const wchar_t *in, char *out, size_t out_size);
void util_suppress_errmsg(void);
int util_lasterror_to_errno(unsigned long err);
#endif
#define UTIL_MAX_ERR_MSG 128
void util_strerror(int errnum, char *buff, size_t bufflen);
void util_strwinerror(unsigned long err, char *buff, size_t bufflen);
void util_set_alloc_funcs(
void *(*malloc_func)(size_t size),
void (*free_func)(void *ptr),
void *(*realloc_func)(void *ptr, size_t size),
char *(*strdup_func)(const char *s));
/*
* Macro calculates number of elements in given table
*/
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
#ifdef _MSC_VER
#define force_inline inline __forceinline
#define NORETURN __declspec(noreturn)
#define barrier() _ReadWriteBarrier()
#else
#define force_inline __attribute__((always_inline)) inline
#define NORETURN __attribute__((noreturn))
#define barrier() asm volatile("" ::: "memory")
#endif
#ifdef _MSC_VER
typedef UNALIGNED uint64_t ua_uint64_t;
typedef UNALIGNED uint32_t ua_uint32_t;
typedef UNALIGNED uint16_t ua_uint16_t;
#else
typedef uint64_t ua_uint64_t __attribute__((aligned(1)));
typedef uint32_t ua_uint32_t __attribute__((aligned(1)));
typedef uint16_t ua_uint16_t __attribute__((aligned(1)));
#endif
#define util_get_not_masked_bits(x, mask) ((x) & ~(mask))
/*
* util_setbit -- setbit macro substitution which properly deals with types
*/
static inline void
util_setbit(uint8_t *b, uint32_t i)
{
b[i / 8] = (uint8_t)(b[i / 8] | (uint8_t)(1 << (i % 8)));
}
/*
* util_clrbit -- clrbit macro substitution which properly deals with types
*/
static inline void
util_clrbit(uint8_t *b, uint32_t i)
{
b[i / 8] = (uint8_t)(b[i / 8] & (uint8_t)(~(1 << (i % 8))));
}
#define util_isset(a, i) isset(a, i)
#define util_isclr(a, i) isclr(a, i)
#define util_flag_isset(a, f) ((a) & (f))
#define util_flag_isclr(a, f) (((a) & (f)) == 0)
/*
* util_is_pow2 -- returns !0 when there's only 1 bit set in v, 0 otherwise
*/
static force_inline int
util_is_pow2(uint64_t v)
{
return v && !(v & (v - 1));
}
/*
* util_div_ceil -- divides a by b and rounds up the result
*/
static force_inline unsigned
util_div_ceil(unsigned a, unsigned b)
{
return (unsigned)(((unsigned long)a + b - 1) / b);
}
/*
* util_bool_compare_and_swap -- perform an atomic compare and swap
* util_fetch_and_* -- perform an operation atomically, return old value
* util_synchronize -- issue a full memory barrier
* util_popcount -- count number of set bits
* util_lssb_index -- return index of least significant set bit,
* undefined on zero
* util_mssb_index -- return index of most significant set bit
* undefined on zero
*
* XXX assertions needed on (value != 0) in both versions of bitscans
*
*/
#ifndef _MSC_VER
/*
* ISO C11 -- 7.17.1.4
* memory_order - an enumerated type whose enumerators identify memory ordering
* constraints.
*/
typedef enum {
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
memory_order_release = __ATOMIC_RELEASE,
memory_order_acq_rel = __ATOMIC_ACQ_REL,
memory_order_seq_cst = __ATOMIC_SEQ_CST
} memory_order;
/*
* ISO C11 -- 7.17.7.2 The atomic_load generic functions
* Integer width specific versions as supplement for:
*
*
* #include <stdatomic.h>
* C atomic_load(volatile A *object);
* C atomic_load_explicit(volatile A *object, memory_order order);
*
* The atomic_load interface doesn't return the loaded value, but instead
* copies it to a specified address -- see comments at the MSVC version.
*
* Also, instead of generic functions, two versions are available:
* for 32 bit fundamental integers, and for 64 bit ones.
*/
#define util_atomic_load_explicit32 __atomic_load
#define util_atomic_load_explicit64 __atomic_load
/*
* ISO C11 -- 7.17.7.1 The atomic_store generic functions
* Integer width specific versions as supplement for:
*
* #include <stdatomic.h>
* void atomic_store(volatile A *object, C desired);
* void atomic_store_explicit(volatile A *object, C desired,
* memory_order order);
*/
#define util_atomic_store_explicit32 __atomic_store_n
#define util_atomic_store_explicit64 __atomic_store_n
/*
* https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
* https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions
*/
#define util_bool_compare_and_swap32 __sync_bool_compare_and_swap
#define util_bool_compare_and_swap64 __sync_bool_compare_and_swap
#define util_fetch_and_add32 __sync_fetch_and_add
#define util_fetch_and_add64 __sync_fetch_and_add
#define util_fetch_and_sub32 __sync_fetch_and_sub
#define util_fetch_and_sub64 __sync_fetch_and_sub
#define util_fetch_and_and32 __sync_fetch_and_and
#define util_fetch_and_and64 __sync_fetch_and_and
#define util_fetch_and_or32 __sync_fetch_and_or
#define util_fetch_and_or64 __sync_fetch_and_or
#define util_synchronize __sync_synchronize
#define util_popcount(value) ((unsigned char)__builtin_popcount(value))
#define util_popcount64(value) ((unsigned char)__builtin_popcountll(value))
#define util_lssb_index(value) ((unsigned char)__builtin_ctz(value))
#define util_lssb_index64(value) ((unsigned char)__builtin_ctzll(value))
#define util_mssb_index(value) ((unsigned char)(31 - __builtin_clz(value)))
#define util_mssb_index64(value) ((unsigned char)(63 - __builtin_clzll(value)))
#else
/* ISO C11 -- 7.17.1.4 */
typedef enum {
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
} memory_order;
/*
* ISO C11 -- 7.17.7.2 The atomic_load generic functions
* Integer width specific versions as supplement for:
*
*
* #include <stdatomic.h>
* C atomic_load(volatile A *object);
* C atomic_load_explicit(volatile A *object, memory_order order);
*
* The atomic_load interface doesn't return the loaded value, but instead
* copies it to a specified address.
* The MSVC specific implementation needs to trigger a barrier (at least
* compiler barrier) after the load from the volatile value. The actual load
* from the volatile value itself is expected to be atomic.
*
* The actual isnterface here:
* #include "util.h"
* void util_atomic_load32(volatile A *object, A *destination);
* void util_atomic_load64(volatile A *object, A *destination);
* void util_atomic_load_explicit32(volatile A *object, A *destination,
* memory_order order);
* void util_atomic_load_explicit64(volatile A *object, A *destination,
* memory_order order);
*/
#ifndef _M_X64
#error MSVC ports of util_atomic_ only work on X86_64
#endif
#if _MSC_VER >= 2000
#error util_atomic_ utility functions not tested with this version of VC++
#error These utility functions are not future proof, as they are not
#error based on publicly available documentation.
#endif
#define util_atomic_load_explicit(object, dest, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_consume &&\
order != memory_order_acquire &&\
order != memory_order_relaxed);\
*dest = *object;\
if (order == memory_order_seq_cst ||\
order == memory_order_consume ||\
order == memory_order_acquire)\
_ReadWriteBarrier();\
} while (0)
#define util_atomic_load_explicit32 util_atomic_load_explicit
#define util_atomic_load_explicit64 util_atomic_load_explicit
/* ISO C11 -- 7.17.7.1 The atomic_store generic functions */
#define util_atomic_store_explicit64(object, desired, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_release &&\
order != memory_order_relaxed);\
if (order == memory_order_seq_cst) {\
_InterlockedExchange64(\
(volatile long long *)object, desired);\
} else {\
if (order == memory_order_release)\
_ReadWriteBarrier();\
*object = desired;\
}\
} while (0)
#define util_atomic_store_explicit32(object, desired, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_release &&\
order != memory_order_relaxed);\
if (order == memory_order_seq_cst) {\
_InterlockedExchange(\
(volatile long *)object, desired);\
} else {\
if (order == memory_order_release)\
_ReadWriteBarrier();\
*object = desired;\
}\
} while (0)
/*
* https://msdn.microsoft.com/en-us/library/hh977022.aspx
*/
static __inline int
bool_compare_and_swap32_VC(volatile LONG *ptr,
LONG oldval, LONG newval)
{
LONG old = InterlockedCompareExchange(ptr, newval, oldval);
return (old == oldval);
}
static __inline int
bool_compare_and_swap64_VC(volatile LONG64 *ptr,
LONG64 oldval, LONG64 newval)
{
LONG64 old = InterlockedCompareExchange64(ptr, newval, oldval);
return (old == oldval);
}
#define util_bool_compare_and_swap32(p, o, n)\
bool_compare_and_swap32_VC((LONG *)(p), (LONG)(o), (LONG)(n))
#define util_bool_compare_and_swap64(p, o, n)\
bool_compare_and_swap64_VC((LONG64 *)(p), (LONG64)(o), (LONG64)(n))
#define util_fetch_and_add32(ptr, value)\
InterlockedExchangeAdd((LONG *)(ptr), value)
#define util_fetch_and_add64(ptr, value)\
InterlockedExchangeAdd64((LONG64 *)(ptr), value)
#define util_fetch_and_sub32(ptr, value)\
InterlockedExchangeSubtract((LONG *)(ptr), value)
#define util_fetch_and_sub64(ptr, value)\
InterlockedExchangeAdd64((LONG64 *)(ptr), -((LONG64)(value)))
#define util_fetch_and_and32(ptr, value)\
InterlockedAnd((LONG *)(ptr), value)
#define util_fetch_and_and64(ptr, value)\
InterlockedAnd64((LONG64 *)(ptr), value)
#define util_fetch_and_or32(ptr, value)\
InterlockedOr((LONG *)(ptr), value)
#define util_fetch_and_or64(ptr, value)\
InterlockedOr64((LONG64 *)(ptr), value)
static __inline void
util_synchronize(void)
{
MemoryBarrier();
}
#define util_popcount(value) (unsigned char)__popcnt(value)
#define util_popcount64(value) (unsigned char)__popcnt64(value)
static __inline unsigned char
util_lssb_index(int value)
{
unsigned long ret;
_BitScanForward(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_lssb_index64(long long value)
{
unsigned long ret;
_BitScanForward64(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_mssb_index(int value)
{
unsigned long ret;
_BitScanReverse(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_mssb_index64(long long value)
{
unsigned long ret;
_BitScanReverse64(&ret, value);
return (unsigned char)ret;
}
#endif
/* ISO C11 -- 7.17.7 Operations on atomic types */
#define util_atomic_load32(object, dest)\
util_atomic_load_explicit32(object, dest, memory_order_seq_cst)
#define util_atomic_load64(object, dest)\
util_atomic_load_explicit64(object, dest, memory_order_seq_cst)
#define util_atomic_store32(object, desired)\
util_atomic_store_explicit32(object, desired, memory_order_seq_cst)
#define util_atomic_store64(object, desired)\
util_atomic_store_explicit64(object, desired, memory_order_seq_cst)
/*
* util_get_printable_ascii -- convert non-printable ascii to dot '.'
*/
static inline char
util_get_printable_ascii(char c)
{
return isprint((unsigned char)c) ? c : '.';
}
char *util_concat_str(const char *s1, const char *s2);
#if !defined(likely)
#if defined(__GNUC__)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (!!(x))
#define unlikely(x) (!!(x))
#endif
#endif
#if defined(__CHECKER__)
#define COMPILE_ERROR_ON(cond)
#define ASSERT_COMPILE_ERROR_ON(cond)
#elif defined(_MSC_VER)
#define COMPILE_ERROR_ON(cond) C_ASSERT(!(cond))
/* XXX - can't be done with C_ASSERT() unless we have __builtin_constant_p() */
#define ASSERT_COMPILE_ERROR_ON(cond) do {} while (0)
#else
#define COMPILE_ERROR_ON(cond) ((void)sizeof(char[(cond) ? -1 : 1]))
#define ASSERT_COMPILE_ERROR_ON(cond) COMPILE_ERROR_ON(cond)
#endif
#ifndef _MSC_VER
#define ATTR_CONSTRUCTOR __attribute__((constructor)) static
#define ATTR_DESTRUCTOR __attribute__((destructor)) static
#else
#define ATTR_CONSTRUCTOR
#define ATTR_DESTRUCTOR
#endif
#ifndef _MSC_VER
#define CONSTRUCTOR(fun) ATTR_CONSTRUCTOR
#else
#ifdef __cplusplus
#define CONSTRUCTOR(fun) \
void fun(); \
struct _##fun { \
_##fun() { \
fun(); \
} \
}; static _##fun foo; \
static
#else
#define CONSTRUCTOR(fun) \
MSVC_CONSTR(fun) \
static
#endif
#endif
#ifdef __GNUC__
#define CHECK_FUNC_COMPATIBLE(func1, func2)\
COMPILE_ERROR_ON(!__builtin_types_compatible_p(typeof(func1),\
typeof(func2)))
#else
#define CHECK_FUNC_COMPATIBLE(func1, func2) do {} while (0)
#endif /* __GNUC__ */
#ifdef __cplusplus
}
#endif
#endif /* util.h */
| 17,058 | 30.47417 | 79 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind_internal.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* valgrind_internal.h -- internal definitions for valgrind macros
*/
#ifndef PMDK_VALGRIND_INTERNAL_H
#define PMDK_VALGRIND_INTERNAL_H 1
#if !defined(_WIN32) && !defined(__FreeBSD__)
#ifndef VALGRIND_ENABLED
#define VALGRIND_ENABLED 1
#endif
#endif
#if VALGRIND_ENABLED
#define VG_PMEMCHECK_ENABLED 1
#define VG_HELGRIND_ENABLED 1
#define VG_MEMCHECK_ENABLED 1
#define VG_DRD_ENABLED 1
#endif
#if VG_PMEMCHECK_ENABLED || VG_HELGRIND_ENABLED || VG_MEMCHECK_ENABLED || \
VG_DRD_ENABLED
#define ANY_VG_TOOL_ENABLED 1
#else
#define ANY_VG_TOOL_ENABLED 0
#endif
#if ANY_VG_TOOL_ENABLED
extern unsigned _On_valgrind;
#define On_valgrind __builtin_expect(_On_valgrind, 0)
#include "valgrind/valgrind.h"
#else
#define On_valgrind (0)
#endif
#if VG_HELGRIND_ENABLED
extern unsigned _On_helgrind;
#define On_helgrind __builtin_expect(_On_helgrind, 0)
#include "valgrind/helgrind.h"
#else
#define On_helgrind (0)
#endif
#if VG_DRD_ENABLED
extern unsigned _On_drd;
#define On_drd __builtin_expect(_On_drd, 0)
#include "valgrind/drd.h"
#else
#define On_drd (0)
#endif
#if VG_HELGRIND_ENABLED || VG_DRD_ENABLED
extern unsigned _On_drd_or_hg;
#define On_drd_or_hg __builtin_expect(_On_drd_or_hg, 0)
#define VALGRIND_ANNOTATE_HAPPENS_BEFORE(obj) do {\
if (On_drd_or_hg) \
ANNOTATE_HAPPENS_BEFORE((obj));\
} while (0)
#define VALGRIND_ANNOTATE_HAPPENS_AFTER(obj) do {\
if (On_drd_or_hg) \
ANNOTATE_HAPPENS_AFTER((obj));\
} while (0)
#define VALGRIND_ANNOTATE_NEW_MEMORY(addr, size) do {\
if (On_drd_or_hg) \
ANNOTATE_NEW_MEMORY((addr), (size));\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_BEGIN() do {\
if (On_drd_or_hg) \
ANNOTATE_IGNORE_READS_BEGIN();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_END() do {\
if (On_drd_or_hg) \
ANNOTATE_IGNORE_READS_END();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_BEGIN() do {\
if (On_drd_or_hg) \
ANNOTATE_IGNORE_WRITES_BEGIN();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_END() do {\
if (On_drd_or_hg) \
ANNOTATE_IGNORE_WRITES_END();\
} while (0)
/* Supported by both helgrind and drd. */
#define VALGRIND_HG_DRD_DISABLE_CHECKING(addr, size) do {\
if (On_drd_or_hg) \
VALGRIND_HG_DISABLE_CHECKING((addr), (size));\
} while (0)
#else
#define On_drd_or_hg (0)
#define VALGRIND_ANNOTATE_HAPPENS_BEFORE(obj) do { (void)(obj); } while (0)
#define VALGRIND_ANNOTATE_HAPPENS_AFTER(obj) do { (void)(obj); } while (0)
#define VALGRIND_ANNOTATE_NEW_MEMORY(addr, size) do {\
(void) (addr);\
(void) (size);\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_BEGIN() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_END() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_BEGIN() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_END() do {} while (0)
#define VALGRIND_HG_DRD_DISABLE_CHECKING(addr, size) do {\
(void) (addr);\
(void) (size);\
} while (0)
#endif
#if VG_PMEMCHECK_ENABLED
extern unsigned _On_pmemcheck;
#define On_pmemcheck __builtin_expect(_On_pmemcheck, 0)
#include "valgrind/pmemcheck.h"
void pobj_emit_log(const char *func, int order);
void pmem_emit_log(const char *func, int order);
void pmem2_emit_log(const char *func, int order);
extern int _Pmreorder_emit;
#define Pmreorder_emit __builtin_expect(_Pmreorder_emit, 0)
#define VALGRIND_REGISTER_PMEM_MAPPING(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_REGISTER_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_REGISTER_PMEM_FILE(desc, base_addr, size, offset) do {\
if (On_pmemcheck)\
VALGRIND_PMC_REGISTER_PMEM_FILE((desc), (base_addr), (size), \
(offset));\
} while (0)
#define VALGRIND_REMOVE_PMEM_MAPPING(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_REMOVE_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_CHECK_IS_PMEM_MAPPING(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_CHECK_IS_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_PRINT_PMEM_MAPPINGS do {\
if (On_pmemcheck)\
VALGRIND_PMC_PRINT_PMEM_MAPPINGS;\
} while (0)
#define VALGRIND_DO_FLUSH(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_DO_FLUSH((addr), (len));\
} while (0)
#define VALGRIND_DO_FENCE do {\
if (On_pmemcheck)\
VALGRIND_PMC_DO_FENCE;\
} while (0)
#define VALGRIND_DO_PERSIST(addr, len) do {\
if (On_pmemcheck) {\
VALGRIND_PMC_DO_FLUSH((addr), (len));\
VALGRIND_PMC_DO_FENCE;\
}\
} while (0)
#define VALGRIND_SET_CLEAN(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_SET_CLEAN(addr, len);\
} while (0)
#define VALGRIND_WRITE_STATS do {\
if (On_pmemcheck)\
VALGRIND_PMC_WRITE_STATS;\
} while (0)
#define VALGRIND_EMIT_LOG(emit_log) do {\
if (On_pmemcheck)\
VALGRIND_PMC_EMIT_LOG((emit_log));\
} while (0)
#define VALGRIND_START_TX do {\
if (On_pmemcheck)\
VALGRIND_PMC_START_TX;\
} while (0)
#define VALGRIND_START_TX_N(txn) do {\
if (On_pmemcheck)\
VALGRIND_PMC_START_TX_N(txn);\
} while (0)
#define VALGRIND_END_TX do {\
if (On_pmemcheck)\
VALGRIND_PMC_END_TX;\
} while (0)
#define VALGRIND_END_TX_N(txn) do {\
if (On_pmemcheck)\
VALGRIND_PMC_END_TX_N(txn);\
} while (0)
#define VALGRIND_ADD_TO_TX(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_ADD_TO_TX(addr, len);\
} while (0)
#define VALGRIND_ADD_TO_TX_N(txn, addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_ADD_TO_TX_N(txn, addr, len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_REMOVE_FROM_TX(addr, len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX_N(txn, addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_REMOVE_FROM_TX_N(txn, addr, len);\
} while (0)
#define VALGRIND_ADD_TO_GLOBAL_TX_IGNORE(addr, len) do {\
if (On_pmemcheck)\
VALGRIND_PMC_ADD_TO_GLOBAL_TX_IGNORE(addr, len);\
} while (0)
/*
* Logs library and function name with proper suffix
* to pmemcheck store log file.
*/
#define PMEMOBJ_API_START()\
if (Pmreorder_emit)\
pobj_emit_log(__func__, 0);
#define PMEMOBJ_API_END()\
if (Pmreorder_emit)\
pobj_emit_log(__func__, 1);
#define PMEM_API_START()\
if (Pmreorder_emit)\
pmem_emit_log(__func__, 0);
#define PMEM_API_END()\
if (Pmreorder_emit)\
pmem_emit_log(__func__, 1);
#define PMEM2_API_START(func_name)\
if (Pmreorder_emit)\
pmem2_emit_log(func_name, 0);
#define PMEM2_API_END(func_name)\
if (Pmreorder_emit)\
pmem2_emit_log(func_name, 1);
#else
#define On_pmemcheck (0)
#define Pmreorder_emit (0)
#define VALGRIND_REGISTER_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REGISTER_PMEM_FILE(desc, base_addr, size, offset) do {\
(void) (desc);\
(void) (base_addr);\
(void) (size);\
(void) (offset);\
} while (0)
#define VALGRIND_REMOVE_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_CHECK_IS_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_PRINT_PMEM_MAPPINGS do {} while (0)
#define VALGRIND_DO_FLUSH(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_DO_FENCE do {} while (0)
#define VALGRIND_DO_PERSIST(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_SET_CLEAN(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_WRITE_STATS do {} while (0)
#define VALGRIND_EMIT_LOG(emit_log) do {\
(void) (emit_log);\
} while (0)
#define VALGRIND_START_TX do {} while (0)
#define VALGRIND_START_TX_N(txn) do { (void) (txn); } while (0)
#define VALGRIND_END_TX do {} while (0)
#define VALGRIND_END_TX_N(txn) do {\
(void) (txn);\
} while (0)
#define VALGRIND_ADD_TO_TX(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_ADD_TO_TX_N(txn, addr, len) do {\
(void) (txn);\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX_N(txn, addr, len) do {\
(void) (txn);\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_ADD_TO_GLOBAL_TX_IGNORE(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define PMEMOBJ_API_START() do {} while (0)
#define PMEMOBJ_API_END() do {} while (0)
#define PMEM_API_START() do {} while (0)
#define PMEM_API_END() do {} while (0)
#define PMEM2_API_START(func_name) do {\
(void) (func_name);\
} while (0)
#define PMEM2_API_END(func_name) do {\
(void) (func_name);\
} while (0)
#endif
#if VG_MEMCHECK_ENABLED
extern unsigned _On_memcheck;
#define On_memcheck __builtin_expect(_On_memcheck, 0)
#include "valgrind/memcheck.h"
#define VALGRIND_DO_DISABLE_ERROR_REPORTING do {\
if (On_valgrind)\
VALGRIND_DISABLE_ERROR_REPORTING;\
} while (0)
#define VALGRIND_DO_ENABLE_ERROR_REPORTING do {\
if (On_valgrind)\
VALGRIND_ENABLE_ERROR_REPORTING;\
} while (0)
#define VALGRIND_DO_CREATE_MEMPOOL(heap, rzB, is_zeroed) do {\
if (On_memcheck)\
VALGRIND_CREATE_MEMPOOL(heap, rzB, is_zeroed);\
} while (0)
#define VALGRIND_DO_DESTROY_MEMPOOL(heap) do {\
if (On_memcheck)\
VALGRIND_DESTROY_MEMPOOL(heap);\
} while (0)
#define VALGRIND_DO_MEMPOOL_ALLOC(heap, addr, size) do {\
if (On_memcheck)\
VALGRIND_MEMPOOL_ALLOC(heap, addr, size);\
} while (0)
#define VALGRIND_DO_MEMPOOL_FREE(heap, addr) do {\
if (On_memcheck)\
VALGRIND_MEMPOOL_FREE(heap, addr);\
} while (0)
#define VALGRIND_DO_MEMPOOL_CHANGE(heap, addrA, addrB, size) do {\
if (On_memcheck)\
VALGRIND_MEMPOOL_CHANGE(heap, addrA, addrB, size);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_DEFINED(addr, len) do {\
if (On_memcheck)\
VALGRIND_MAKE_MEM_DEFINED(addr, len);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_UNDEFINED(addr, len) do {\
if (On_memcheck)\
VALGRIND_MAKE_MEM_UNDEFINED(addr, len);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_NOACCESS(addr, len) do {\
if (On_memcheck)\
VALGRIND_MAKE_MEM_NOACCESS(addr, len);\
} while (0)
#define VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len) do {\
if (On_memcheck)\
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, len);\
} while (0)
#else
#define On_memcheck (0)
#define VALGRIND_DO_DISABLE_ERROR_REPORTING do {} while (0)
#define VALGRIND_DO_ENABLE_ERROR_REPORTING do {} while (0)
#define VALGRIND_DO_CREATE_MEMPOOL(heap, rzB, is_zeroed)\
do { (void) (heap); (void) (rzB); (void) (is_zeroed); } while (0)
#define VALGRIND_DO_DESTROY_MEMPOOL(heap)\
do { (void) (heap); } while (0)
#define VALGRIND_DO_MEMPOOL_ALLOC(heap, addr, size)\
do { (void) (heap); (void) (addr); (void) (size); } while (0)
#define VALGRIND_DO_MEMPOOL_FREE(heap, addr)\
do { (void) (heap); (void) (addr); } while (0)
#define VALGRIND_DO_MEMPOOL_CHANGE(heap, addrA, addrB, size)\
do {\
(void) (heap); (void) (addrA); (void) (addrB); (void) (size);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_DEFINED(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_MAKE_MEM_UNDEFINED(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_MAKE_MEM_NOACCESS(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#endif
#endif
| 11,169 | 22.319415 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/fs.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2020, Intel Corporation */
/*
* fs.h -- file system traversal abstraction layer
*/
#ifndef PMDK_FS_H
#define PMDK_FS_H 1
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
struct fs;
enum fs_entry_type {
FS_ENTRY_FILE,
FS_ENTRY_DIRECTORY,
FS_ENTRY_SYMLINK,
FS_ENTRY_OTHER,
MAX_FS_ENTRY_TYPES
};
struct fs_entry {
enum fs_entry_type type;
const char *name;
size_t namelen;
const char *path;
size_t pathlen;
/* the depth of the traversal */
/* XXX long on FreeBSD. Linux uses short. No harm in it being bigger */
long level;
};
struct fs *fs_new(const char *path);
void fs_delete(struct fs *f);
/* this call invalidates the previous entry */
struct fs_entry *fs_read(struct fs *f);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_FS_H */
| 827 | 14.923077 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/alloc.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
#ifndef COMMON_ALLOC_H
#define COMMON_ALLOC_H
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void *(*Malloc_func)(size_t size);
typedef void *(*Realloc_func)(void *ptr, size_t size);
extern Malloc_func fn_malloc;
extern Realloc_func fn_realloc;
#if FAULT_INJECTION
void *_flt_Malloc(size_t, const char *);
void *_flt_Realloc(void *, size_t, const char *);
#define Malloc(size) _flt_Malloc(size, __func__)
#define Realloc(ptr, size) _flt_Realloc(ptr, size, __func__)
#else
void *_Malloc(size_t);
void *_Realloc(void *, size_t);
#define Malloc(size) _Malloc(size)
#define Realloc(ptr, size) _Realloc(ptr, size)
#endif
void set_func_malloc(void *(*malloc_func)(size_t size));
void set_func_realloc(void *(*realloc_func)(void *ptr, size_t size));
/*
* overridable names for malloc & friends used by this library
*/
typedef void (*Free_func)(void *ptr);
typedef char *(*Strdup_func)(const char *s);
extern Free_func Free;
extern Strdup_func Strdup;
extern void *Zalloc(size_t sz);
#ifdef __cplusplus
}
#endif
#endif
| 1,131 | 21.64 | 69 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/errno_freebsd.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2020, Intel Corporation */
/*
* errno_freebsd.h -- map Linux errno's to something close on FreeBSD
*/
#ifndef PMDK_ERRNO_FREEBSD_H
#define PMDK_ERRNO_FREEBSD_H 1
#ifdef __FreeBSD__
#define EBADFD EBADF
#define ELIBACC EINVAL
#define EMEDIUMTYPE EOPNOTSUPP
#define ENOMEDIUM ENODEV
#define EREMOTEIO EIO
#endif
#endif /* PMDK_ERRNO_FREEBSD_H */
| 409 | 19.5 | 69 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/os_thread.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_thread.h -- os thread abstraction layer
*/
#ifndef OS_THREAD_H
#define OS_THREAD_H 1
#include <stdint.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef union {
long long align;
char padding[44]; /* linux: 40 windows: 44 */
} os_mutex_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 13 */
} os_rwlock_t;
typedef union {
long long align;
char padding[48]; /* linux: 48 windows: 12 */
} os_cond_t;
typedef union {
long long align;
char padding[32]; /* linux: 8 windows: 32 */
} os_thread_t;
typedef union {
long long align; /* linux: long windows: 8 FreeBSD: 12 */
char padding[16]; /* 16 to be safe */
} os_once_t;
#define OS_ONCE_INIT { .padding = {0} }
typedef unsigned os_tls_key_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 8 */
} os_semaphore_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 8 */
} os_thread_attr_t;
typedef union {
long long align;
char padding[512];
} os_cpu_set_t;
#ifdef __FreeBSD__
#define cpu_set_t cpuset_t
typedef uintptr_t os_spinlock_t;
#else
typedef volatile int os_spinlock_t; /* XXX: not implemented on windows */
#endif
void os_cpu_zero(os_cpu_set_t *set);
void os_cpu_set(size_t cpu, os_cpu_set_t *set);
#ifndef _WIN32
#define _When_(...)
#endif
int os_once(os_once_t *o, void (*func)(void));
int os_tls_key_create(os_tls_key_t *key, void (*destructor)(void *));
int os_tls_key_delete(os_tls_key_t key);
int os_tls_set(os_tls_key_t key, const void *value);
void *os_tls_get(os_tls_key_t key);
int os_mutex_init(os_mutex_t *__restrict mutex);
int os_mutex_destroy(os_mutex_t *__restrict mutex);
_When_(return == 0, _Acquires_lock_(mutex->lock))
int os_mutex_lock(os_mutex_t *__restrict mutex);
_When_(return == 0, _Acquires_lock_(mutex->lock))
int os_mutex_trylock(os_mutex_t *__restrict mutex);
int os_mutex_unlock(os_mutex_t *__restrict mutex);
/* XXX - non POSIX */
int os_mutex_timedlock(os_mutex_t *__restrict mutex,
const struct timespec *abstime);
int os_rwlock_init(os_rwlock_t *__restrict rwlock);
int os_rwlock_destroy(os_rwlock_t *__restrict rwlock);
int os_rwlock_rdlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_wrlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_tryrdlock(os_rwlock_t *__restrict rwlock);
_When_(return == 0, _Acquires_exclusive_lock_(rwlock->lock))
int os_rwlock_trywrlock(os_rwlock_t *__restrict rwlock);
_When_(rwlock->is_write != 0, _Requires_exclusive_lock_held_(rwlock->lock))
_When_(rwlock->is_write == 0, _Requires_shared_lock_held_(rwlock->lock))
int os_rwlock_unlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_timedrdlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime);
int os_rwlock_timedwrlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime);
int os_spin_init(os_spinlock_t *lock, int pshared);
int os_spin_destroy(os_spinlock_t *lock);
int os_spin_lock(os_spinlock_t *lock);
int os_spin_unlock(os_spinlock_t *lock);
int os_spin_trylock(os_spinlock_t *lock);
int os_cond_init(os_cond_t *__restrict cond);
int os_cond_destroy(os_cond_t *__restrict cond);
int os_cond_broadcast(os_cond_t *__restrict cond);
int os_cond_signal(os_cond_t *__restrict cond);
int os_cond_timedwait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex, const struct timespec *abstime);
int os_cond_wait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex);
/* threading */
int os_thread_create(os_thread_t *thread, const os_thread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int os_thread_join(os_thread_t *thread, void **result);
void os_thread_self(os_thread_t *thread);
/* thread affinity */
int os_thread_setaffinity_np(os_thread_t *thread, size_t set_size,
const os_cpu_set_t *set);
int os_thread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void));
int os_semaphore_init(os_semaphore_t *sem, unsigned value);
int os_semaphore_destroy(os_semaphore_t *sem);
int os_semaphore_wait(os_semaphore_t *sem);
int os_semaphore_trywait(os_semaphore_t *sem);
int os_semaphore_post(os_semaphore_t *sem);
#ifdef __cplusplus
}
#endif
#endif /* OS_THREAD_H */
| 5,876 | 31.291209 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/out.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* out.h -- definitions for "out" module
*/
#ifndef PMDK_OUT_H
#define PMDK_OUT_H 1
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include "util.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Suppress errors which are after appropriate ASSERT* macro for nondebug
* builds.
*/
#if !defined(DEBUG) && (defined(__clang_analyzer__) || defined(__COVERITY__) ||\
defined(__KLOCWORK__))
#define OUT_FATAL_DISCARD_NORETURN __attribute__((noreturn))
#else
#define OUT_FATAL_DISCARD_NORETURN
#endif
#ifndef EVALUATE_DBG_EXPRESSIONS
#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\
defined(__KLOCWORK__)
#define EVALUATE_DBG_EXPRESSIONS 1
#else
#define EVALUATE_DBG_EXPRESSIONS 0
#endif
#endif
#ifdef DEBUG
#define OUT_LOG out_log
#define OUT_NONL out_nonl
#define OUT_FATAL out_fatal
#define OUT_FATAL_ABORT out_fatal
#else
static __attribute__((always_inline)) inline void
out_log_discard(const char *file, int line, const char *func, int level,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) level;
(void) fmt;
}
static __attribute__((always_inline)) inline void
out_nonl_discard(int level, const char *fmt, ...)
{
(void) level;
(void) fmt;
}
static __attribute__((always_inline)) OUT_FATAL_DISCARD_NORETURN inline void
out_fatal_discard(const char *file, int line, const char *func,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) fmt;
}
static __attribute__((always_inline)) NORETURN inline void
out_fatal_abort(const char *file, int line, const char *func,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) fmt;
abort();
}
#define OUT_LOG out_log_discard
#define OUT_NONL out_nonl_discard
#define OUT_FATAL out_fatal_discard
#define OUT_FATAL_ABORT out_fatal_abort
#endif
#if defined(__KLOCWORK__)
#define TEST_ALWAYS_TRUE_EXPR(cnd)
#define TEST_ALWAYS_EQ_EXPR(cnd)
#define TEST_ALWAYS_NE_EXPR(cnd)
#else
#define TEST_ALWAYS_TRUE_EXPR(cnd)\
if (__builtin_constant_p(cnd))\
ASSERT_COMPILE_ERROR_ON(cnd);
#define TEST_ALWAYS_EQ_EXPR(lhs, rhs)\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
ASSERT_COMPILE_ERROR_ON((lhs) == (rhs));
#define TEST_ALWAYS_NE_EXPR(lhs, rhs)\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
ASSERT_COMPILE_ERROR_ON((lhs) != (rhs));
#endif
/* produce debug/trace output */
#define LOG(level, ...) do { \
if (!EVALUATE_DBG_EXPRESSIONS) break;\
OUT_LOG(__FILE__, __LINE__, __func__, level, __VA_ARGS__);\
} while (0)
/* produce debug/trace output without prefix and new line */
#define LOG_NONL(level, ...) do { \
if (!EVALUATE_DBG_EXPRESSIONS) break; \
OUT_NONL(level, __VA_ARGS__); \
} while (0)
/* produce output and exit */
#define FATAL(...)\
OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__)
/* assert a condition is true at runtime */
#define ASSERT_rt(cnd) do { \
if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \
OUT_FATAL(__FILE__, __LINE__, __func__, "assertion failure: %s", #cnd);\
} while (0)
/* assertion with extra info printed if assertion fails at runtime */
#define ASSERTinfo_rt(cnd, info) do { \
if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \
OUT_FATAL(__FILE__, __LINE__, __func__, \
"assertion failure: %s (%s = %s)", #cnd, #info, info);\
} while (0)
/* assert two integer values are equal at runtime */
#define ASSERTeq_rt(lhs, rhs) do { \
if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \
OUT_FATAL(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \
} while (0)
/* assert two integer values are not equal at runtime */
#define ASSERTne_rt(lhs, rhs) do { \
if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \
OUT_FATAL(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \
} while (0)
/* assert a condition is true */
#define ASSERT(cnd)\
do {\
/*\
* Detect useless asserts on always true expression. Please use\
* COMPILE_ERROR_ON(!cnd) or ASSERT_rt(cnd) in such cases.\
*/\
TEST_ALWAYS_TRUE_EXPR(cnd);\
ASSERT_rt(cnd);\
} while (0)
/* assertion with extra info printed if assertion fails */
#define ASSERTinfo(cnd, info)\
do {\
/* See comment in ASSERT. */\
TEST_ALWAYS_TRUE_EXPR(cnd);\
ASSERTinfo_rt(cnd, info);\
} while (0)
/* assert two integer values are equal */
#define ASSERTeq(lhs, rhs)\
do {\
/* See comment in ASSERT. */\
TEST_ALWAYS_EQ_EXPR(lhs, rhs);\
ASSERTeq_rt(lhs, rhs);\
} while (0)
/* assert two integer values are not equal */
#define ASSERTne(lhs, rhs)\
do {\
/* See comment in ASSERT. */\
TEST_ALWAYS_NE_EXPR(lhs, rhs);\
ASSERTne_rt(lhs, rhs);\
} while (0)
#define ERR(...)\
out_err(__FILE__, __LINE__, __func__, __VA_ARGS__)
void out_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version);
void out_fini(void);
void out(const char *fmt, ...) FORMAT_PRINTF(1, 2);
void out_nonl(int level, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void out_log(const char *file, int line, const char *func, int level,
const char *fmt, ...) FORMAT_PRINTF(5, 6);
void out_err(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void NORETURN out_fatal(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void out_set_print_func(void (*print_func)(const char *s));
void out_set_vsnprintf_func(int (*vsnprintf_func)(char *str, size_t size,
const char *format, va_list ap));
#ifdef _WIN32
#ifndef PMDK_UTF8_API
#define out_get_errormsg out_get_errormsgW
#else
#define out_get_errormsg out_get_errormsgU
#endif
#endif
#ifndef _WIN32
const char *out_get_errormsg(void);
#else
const char *out_get_errormsgU(void);
const wchar_t *out_get_errormsgW(void);
#endif
#ifdef __cplusplus
}
#endif
#endif
| 6,066 | 25.150862 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind/memcheck.h |
/*
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (memcheck.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of MemCheck, a heavyweight Valgrind tool for
detecting memory errors.
Copyright (C) 2000-2017 Julian Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(memcheck.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
#ifndef __MEMCHECK_H
#define __MEMCHECK_H
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query memory permissions
inside your own programs.
See comment near the top of valgrind.h on how to use them.
*/
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end. */
typedef
enum {
VG_USERREQ__MAKE_MEM_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'),
VG_USERREQ__MAKE_MEM_UNDEFINED,
VG_USERREQ__MAKE_MEM_DEFINED,
VG_USERREQ__DISCARD,
VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE,
VG_USERREQ__CHECK_MEM_IS_DEFINED,
VG_USERREQ__DO_LEAK_CHECK,
VG_USERREQ__COUNT_LEAKS,
VG_USERREQ__GET_VBITS,
VG_USERREQ__SET_VBITS,
VG_USERREQ__CREATE_BLOCK,
VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE,
/* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */
VG_USERREQ__COUNT_LEAK_BLOCKS,
VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE,
VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE,
VG_USERREQ__CHECK_MEM_IS_UNADDRESSABLE,
VG_USERREQ__CHECK_MEM_IS_UNDEFINED,
/* This is just for memcheck's internal use - don't use it */
_VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR
= VG_USERREQ_TOOL_BASE('M','C') + 256
} Vg_MemCheckClientRequest;
/* Client-code macros to manipulate the state of memory. */
/* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_NOACCESS, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similarly, mark memory at _qzz_addr as addressable but undefined
for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_UNDEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similarly, mark memory at _qzz_addr as addressable and defined
for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_DEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similar to VALGRIND_MAKE_MEM_DEFINED except that addressability is
not altered: bytes which are addressable are marked as defined,
but those which are not addressable are left unchanged. */
#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Create a block-description handle. The description is an ascii
string which is included in any messages pertaining to addresses
within the specified memory range. Has no other effect on the
properties of the memory range. */
#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CREATE_BLOCK, \
(_qzz_addr), (_qzz_len), (_qzz_desc), \
0, 0)
/* Discard a block-description-handle. Returns 1 for an
invalid handle, 0 for a valid handle. */
#define VALGRIND_DISCARD(_qzz_blkindex) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__DISCARD, \
0, (_qzz_blkindex), 0, 0, 0)
/* Client-code macros to check the state of memory. */
/* Check that memory at _qzz_addr is addressable for _qzz_len bytes.
If suitable addressability is not established, Valgrind prints an
error message and returns the address of the first offending byte.
Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Check that memory at _qzz_addr is addressable and defined for
_qzz_len bytes. If suitable addressability and definedness are not
established, Valgrind prints an error message and returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_DEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Use this macro to force the definedness and addressability of an
lvalue to be checked. If suitable addressability and definedness
are not established, Valgrind prints an error message and returns
the address of the first offending byte. Otherwise it returns
zero. */
#define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue) \
VALGRIND_CHECK_MEM_IS_DEFINED( \
(volatile unsigned char *)&(__lvalue), \
(unsigned long)(sizeof (__lvalue)))
/* Check that memory at _qzz_addr is unaddressable for _qzz_len bytes.
If any byte in this range is addressable, Valgrind returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_UNADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_UNADDRESSABLE,\
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Check that memory at _qzz_addr is undefined for _qzz_len bytes. If any
byte in this range is defined or unaddressable, Valgrind returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_UNDEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_UNDEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Do a full memory leak check (like --leak-check=full) mid-execution. */
#define VALGRIND_DO_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 0, 0, 0, 0)
/* Same as VALGRIND_DO_LEAK_CHECK but only showing the entries for
which there was an increase in leaked bytes or leaked nr of blocks
since the previous leak search. */
#define VALGRIND_DO_ADDED_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 1, 0, 0, 0)
/* Same as VALGRIND_DO_ADDED_LEAK_CHECK but showing entries with
increased or decreased leaked bytes/blocks since previous leak
search. */
#define VALGRIND_DO_CHANGED_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 2, 0, 0, 0)
/* Do a summary memory leak check (like --leak-check=summary) mid-execution. */
#define VALGRIND_DO_QUICK_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
1, 0, 0, 0, 0)
/* Return number of leaked, dubious, reachable and suppressed bytes found by
all previous leak checks. They must be lvalues. */
#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed) \
/* For safety on 64-bit platforms we assign the results to private
unsigned long variables, then assign these to the lvalues the user
specified, which works no matter what type 'leaked', 'dubious', etc
are. We also initialise '_qzz_leaked', etc because
VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
defined. */ \
{ \
unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \
unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
VG_USERREQ__COUNT_LEAKS, \
&_qzz_leaked, &_qzz_dubious, \
&_qzz_reachable, &_qzz_suppressed, 0); \
leaked = _qzz_leaked; \
dubious = _qzz_dubious; \
reachable = _qzz_reachable; \
suppressed = _qzz_suppressed; \
}
/* Return number of leaked, dubious, reachable and suppressed bytes found by
all previous leak checks. They must be lvalues. */
#define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \
/* For safety on 64-bit platforms we assign the results to private
unsigned long variables, then assign these to the lvalues the user
specified, which works no matter what type 'leaked', 'dubious', etc
are. We also initialise '_qzz_leaked', etc because
VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
defined. */ \
{ \
unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \
unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
VG_USERREQ__COUNT_LEAK_BLOCKS, \
&_qzz_leaked, &_qzz_dubious, \
&_qzz_reachable, &_qzz_suppressed, 0); \
leaked = _qzz_leaked; \
dubious = _qzz_dubious; \
reachable = _qzz_reachable; \
suppressed = _qzz_suppressed; \
}
/* Get the validity data for addresses [zza..zza+zznbytes-1] and copy it
into the provided zzvbits array. Return values:
0 if not running on valgrind
1 success
2 [previously indicated unaligned arrays; these are now allowed]
3 if any parts of zzsrc/zzvbits are not addressable.
The metadata is not copied in cases 0, 2 or 3 so it should be
impossible to segfault your system by using this call.
*/
#define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__GET_VBITS, \
(const char*)(zza), \
(char*)(zzvbits), \
(zznbytes), 0, 0)
/* Set the validity data for addresses [zza..zza+zznbytes-1], copying it
from the provided zzvbits array. Return values:
0 if not running on valgrind
1 success
2 [previously indicated unaligned arrays; these are now allowed]
3 if any parts of zza/zzvbits are not addressable.
The metadata is not copied in cases 0, 2 or 3 so it should be
impossible to segfault your system by using this call.
*/
#define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__SET_VBITS, \
(const char*)(zza), \
(const char*)(zzvbits), \
(zznbytes), 0, 0 )
/* Disable and re-enable reporting of addressing errors in the
specified address range. */
#define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
#define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
#endif
| 15,621 | 47.666667 | 79 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind/helgrind.h | /*
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(helgrind.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
This file is part of Helgrind, a Valgrind tool for detecting errors
in threaded programs.
Copyright (C) 2007-2017 OpenWorks LLP
[email protected]
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(helgrind.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
#ifndef __HELGRIND_H
#define __HELGRIND_H
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end. */
typedef
enum {
VG_USERREQ__HG_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
/* The rest are for Helgrind's internal use. Not for end-user
use. Do not use them unless you are a Valgrind developer. */
/* Notify the tool what this thread's pthread_t is. */
_VG_USERREQ__HG_SET_MY_PTHREAD_T = VG_USERREQ_TOOL_BASE('H','G')
+ 256,
_VG_USERREQ__HG_PTH_API_ERROR, /* char*, int */
_VG_USERREQ__HG_PTHREAD_JOIN_POST, /* pthread_t of quitter */
_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST, /* pth_mx_t*, long mbRec */
_VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE, /* pth_mx_t*, long isInit */
_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE, /* pth_mx_t* */
_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST, /* pth_mx_t* */
_VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_PRE, /* void*, long isTryLock */
_VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_POST, /* void* */
_VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE, /* pth_cond_t* */
_VG_USERREQ__HG_PTHREAD_COND_BROADCAST_PRE, /* pth_cond_t* */
_VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE, /* pth_cond_t*, pth_mx_t* */
_VG_USERREQ__HG_PTHREAD_COND_WAIT_POST, /* pth_cond_t*, pth_mx_t* */
_VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE, /* pth_cond_t*, long isInit */
_VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST, /* pth_rwlk_t* */
_VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE, /* pth_rwlk_t* */
_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE, /* pth_rwlk_t*, long isW */
_VG_USERREQ__HG_PTHREAD_RWLOCK_ACQUIRED, /* void*, long isW */
_VG_USERREQ__HG_PTHREAD_RWLOCK_RELEASED, /* void* */
_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST, /* pth_rwlk_t* */
_VG_USERREQ__HG_POSIX_SEM_INIT_POST, /* sem_t*, ulong value */
_VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, /* sem_t* */
_VG_USERREQ__HG_POSIX_SEM_RELEASED, /* void* */
_VG_USERREQ__HG_POSIX_SEM_ACQUIRED, /* void* */
_VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE, /* pth_bar_t*, ulong, ulong */
_VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE, /* pth_bar_t* */
_VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE, /* pth_bar_t* */
_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE, /* pth_slk_t* */
_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST, /* pth_slk_t* */
_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE, /* pth_slk_t* */
_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST, /* pth_slk_t* */
_VG_USERREQ__HG_PTHREAD_SPIN_DESTROY_PRE, /* pth_slk_t* */
_VG_USERREQ__HG_CLIENTREQ_UNIMP, /* char* */
_VG_USERREQ__HG_USERSO_SEND_PRE, /* arbitrary UWord SO-tag */
_VG_USERREQ__HG_USERSO_RECV_POST, /* arbitrary UWord SO-tag */
_VG_USERREQ__HG_USERSO_FORGET_ALL, /* arbitrary UWord SO-tag */
_VG_USERREQ__HG_RESERVED2, /* Do not use */
_VG_USERREQ__HG_RESERVED3, /* Do not use */
_VG_USERREQ__HG_RESERVED4, /* Do not use */
_VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED, /* Addr a, ulong len */
_VG_USERREQ__HG_ARANGE_MAKE_TRACKED, /* Addr a, ulong len */
_VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE, /* pth_bar_t*, ulong */
_VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK, /* Addr start_of_block */
_VG_USERREQ__HG_PTHREAD_COND_INIT_POST, /* pth_cond_t*, pth_cond_attr_t*/
_VG_USERREQ__HG_GNAT_MASTER_HOOK, /* void*d,void*m,Word ml */
_VG_USERREQ__HG_GNAT_MASTER_COMPLETED_HOOK, /* void*s,Word ml */
_VG_USERREQ__HG_GET_ABITS, /* Addr a,Addr abits, ulong len */
_VG_USERREQ__HG_PTHREAD_CREATE_BEGIN,
_VG_USERREQ__HG_PTHREAD_CREATE_END,
_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE, /* pth_mx_t*,long isTryLock */
_VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST, /* pth_mx_t *,long tookLock */
_VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST, /* pth_rwlk_t*,long isW,long */
_VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE, /* pth_rwlk_t* */
_VG_USERREQ__HG_POSIX_SEM_POST_PRE, /* sem_t* */
_VG_USERREQ__HG_POSIX_SEM_POST_POST, /* sem_t* */
_VG_USERREQ__HG_POSIX_SEM_WAIT_PRE, /* sem_t* */
_VG_USERREQ__HG_POSIX_SEM_WAIT_POST, /* sem_t*, long tookLock */
_VG_USERREQ__HG_PTHREAD_COND_SIGNAL_POST, /* pth_cond_t* */
_VG_USERREQ__HG_PTHREAD_COND_BROADCAST_POST,/* pth_cond_t* */
_VG_USERREQ__HG_RTLD_BIND_GUARD, /* int flags */
_VG_USERREQ__HG_RTLD_BIND_CLEAR, /* int flags */
_VG_USERREQ__HG_GNAT_DEPENDENT_MASTER_JOIN /* void*d, void*m */
} Vg_TCheckClientRequest;
/*----------------------------------------------------------------*/
/*--- ---*/
/*--- Implementation-only facilities. Not for end-user use. ---*/
/*--- For end-user facilities see below (the next section in ---*/
/*--- this file.) ---*/
/*--- ---*/
/*----------------------------------------------------------------*/
/* Do a client request. These are macros rather than a functions so
as to avoid having an extra frame in stack traces.
NB: these duplicate definitions in hg_intercepts.c. But here, we
have to make do with weaker typing (no definition of Word etc) and
no assertions, whereas in helgrind.h we can use those facilities.
Obviously it's important the two sets of definitions are kept in
sync.
The commented-out asserts should actually hold, but unfortunately
they can't be allowed to be visible here, because that would
require the end-user code to #include <assert.h>.
*/
#define DO_CREQ_v_W(_creqF, _ty1F,_arg1F) \
do { \
long int _arg1; \
/* assert(sizeof(_ty1F) == sizeof(long int)); */ \
_arg1 = (long int)(_arg1F); \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
(_creqF), \
_arg1, 0,0,0,0); \
} while (0)
#define DO_CREQ_W_W(_resF, _dfltF, _creqF, _ty1F,_arg1F) \
do { \
long int _arg1; \
/* assert(sizeof(_ty1F) == sizeof(long int)); */ \
_arg1 = (long int)(_arg1F); \
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR( \
(_dfltF), \
(_creqF), \
_arg1, 0,0,0,0); \
_resF = _qzz_res; \
} while (0)
#define DO_CREQ_v_WW(_creqF, _ty1F,_arg1F, _ty2F,_arg2F) \
do { \
long int _arg1, _arg2; \
/* assert(sizeof(_ty1F) == sizeof(long int)); */ \
/* assert(sizeof(_ty2F) == sizeof(long int)); */ \
_arg1 = (long int)(_arg1F); \
_arg2 = (long int)(_arg2F); \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
(_creqF), \
_arg1,_arg2,0,0,0); \
} while (0)
#define DO_CREQ_v_WWW(_creqF, _ty1F,_arg1F, \
_ty2F,_arg2F, _ty3F, _arg3F) \
do { \
long int _arg1, _arg2, _arg3; \
/* assert(sizeof(_ty1F) == sizeof(long int)); */ \
/* assert(sizeof(_ty2F) == sizeof(long int)); */ \
/* assert(sizeof(_ty3F) == sizeof(long int)); */ \
_arg1 = (long int)(_arg1F); \
_arg2 = (long int)(_arg2F); \
_arg3 = (long int)(_arg3F); \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
(_creqF), \
_arg1,_arg2,_arg3,0,0); \
} while (0)
#define DO_CREQ_W_WWW(_resF, _dfltF, _creqF, _ty1F,_arg1F, \
_ty2F,_arg2F, _ty3F, _arg3F) \
do { \
long int _qzz_res; \
long int _arg1, _arg2, _arg3; \
/* assert(sizeof(_ty1F) == sizeof(long int)); */ \
_arg1 = (long int)(_arg1F); \
_arg2 = (long int)(_arg2F); \
_arg3 = (long int)(_arg3F); \
/* \
* XXX: here PMDK's version deviates from upstream;\
* without the fix, this code generates \
* a sign-conversion warning, which PMDK's \
* "awesome" build system promotes to an error \
*/ \
_qzz_res = (long)VALGRIND_DO_CLIENT_REQUEST_EXPR( \
(_dfltF), \
(_creqF), \
_arg1,_arg2,_arg3,0,0); \
_resF = _qzz_res; \
} while (0)
#define _HG_CLIENTREQ_UNIMP(_qzz_str) \
DO_CREQ_v_W(_VG_USERREQ__HG_CLIENTREQ_UNIMP, \
(char*),(_qzz_str))
/*----------------------------------------------------------------*/
/*--- ---*/
/*--- Helgrind-native requests. These allow access to ---*/
/*--- the same set of annotation primitives that are used ---*/
/*--- to build the POSIX pthread wrappers. ---*/
/*--- ---*/
/*----------------------------------------------------------------*/
/* ----------------------------------------------------------
For describing ordinary mutexes (non-rwlocks). For rwlock
descriptions see ANNOTATE_RWLOCK_* below.
---------------------------------------------------------- */
/* Notify here immediately after mutex creation. _mbRec == 0 for a
non-recursive mutex, 1 for a recursive mutex. */
#define VALGRIND_HG_MUTEX_INIT_POST(_mutex, _mbRec) \
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST, \
void*,(_mutex), long,(_mbRec))
/* Notify here immediately before mutex acquisition. _isTryLock == 0
for a normal acquisition, 1 for a "try" style acquisition. */
#define VALGRIND_HG_MUTEX_LOCK_PRE(_mutex, _isTryLock) \
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_PRE, \
void*,(_mutex), long,(_isTryLock))
/* Notify here immediately after a successful mutex acquisition. */
#define VALGRIND_HG_MUTEX_LOCK_POST(_mutex) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_ACQUIRE_POST, \
void*,(_mutex))
/* Notify here immediately before a mutex release. */
#define VALGRIND_HG_MUTEX_UNLOCK_PRE(_mutex) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE, \
void*,(_mutex))
/* Notify here immediately after a mutex release. */
#define VALGRIND_HG_MUTEX_UNLOCK_POST(_mutex) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST, \
void*,(_mutex))
/* Notify here immediately before mutex destruction. */
#define VALGRIND_HG_MUTEX_DESTROY_PRE(_mutex) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE, \
void*,(_mutex))
/* ----------------------------------------------------------
For describing semaphores.
---------------------------------------------------------- */
/* Notify here immediately after semaphore creation. */
#define VALGRIND_HG_SEM_INIT_POST(_sem, _value) \
DO_CREQ_v_WW(_VG_USERREQ__HG_POSIX_SEM_INIT_POST, \
void*, (_sem), unsigned long, (_value))
/* Notify here immediately after a semaphore wait (an acquire-style
operation) */
#define VALGRIND_HG_SEM_WAIT_POST(_sem) \
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_ACQUIRED, \
void*,(_sem))
/* Notify here immediately before semaphore post (a release-style
operation) */
#define VALGRIND_HG_SEM_POST_PRE(_sem) \
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_RELEASED, \
void*,(_sem))
/* Notify here immediately before semaphore destruction. */
#define VALGRIND_HG_SEM_DESTROY_PRE(_sem) \
DO_CREQ_v_W(_VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE, \
void*, (_sem))
/* ----------------------------------------------------------
For describing barriers.
---------------------------------------------------------- */
/* Notify here immediately before barrier creation. _count is the
capacity. _resizable == 0 means the barrier may not be resized, 1
means it may be. */
#define VALGRIND_HG_BARRIER_INIT_PRE(_bar, _count, _resizable) \
DO_CREQ_v_WWW(_VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE, \
void*,(_bar), \
unsigned long,(_count), \
unsigned long,(_resizable))
/* Notify here immediately before arrival at a barrier. */
#define VALGRIND_HG_BARRIER_WAIT_PRE(_bar) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE, \
void*,(_bar))
/* Notify here immediately before a resize (change of barrier
capacity). If _newcount >= the existing capacity, then there is no
change in the state of any threads waiting at the barrier. If
_newcount < the existing capacity, and >= _newcount threads are
currently waiting at the barrier, then this notification is
considered to also have the effect of telling the checker that all
waiting threads have now moved past the barrier. (I can't think of
any other sane semantics.) */
#define VALGRIND_HG_BARRIER_RESIZE_PRE(_bar, _newcount) \
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE, \
void*,(_bar), \
unsigned long,(_newcount))
/* Notify here immediately before barrier destruction. */
#define VALGRIND_HG_BARRIER_DESTROY_PRE(_bar) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE, \
void*,(_bar))
/* ----------------------------------------------------------
For describing memory ownership changes.
---------------------------------------------------------- */
/* Clean memory state. This makes Helgrind forget everything it knew
about the specified memory range. Effectively this announces that
the specified memory range now "belongs" to the calling thread, so
that: (1) the calling thread can access it safely without
synchronisation, and (2) all other threads must sync with this one
to access it safely. This is particularly useful for memory
allocators that wish to recycle memory. */
#define VALGRIND_HG_CLEAN_MEMORY(_qzz_start, _qzz_len) \
DO_CREQ_v_WW(VG_USERREQ__HG_CLEAN_MEMORY, \
void*,(_qzz_start), \
unsigned long,(_qzz_len))
/* The same, but for the heap block starting at _qzz_blockstart. This
allows painting when we only know the address of an object, but not
its size, which is sometimes the case in C++ code involving
inheritance, and in which RTTI is not, for whatever reason,
available. Returns the number of bytes painted, which can be zero
for a zero-sized block. Hence, return values >= 0 indicate success
(the block was found), and the value -1 indicates block not
found, and -2 is returned when not running on Helgrind. */
#define VALGRIND_HG_CLEAN_MEMORY_HEAPBLOCK(_qzz_blockstart) \
(__extension__ \
({long int _npainted; \
DO_CREQ_W_W(_npainted, (-2)/*default*/, \
_VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK, \
void*,(_qzz_blockstart)); \
_npainted; \
}))
/* ----------------------------------------------------------
For error control.
---------------------------------------------------------- */
/* Tell H that an address range is not to be "tracked" until further
notice. This puts it in the NOACCESS state, in which case we
ignore all reads and writes to it. Useful for ignoring ranges of
memory where there might be races we don't want to see. If the
memory is subsequently reallocated via malloc/new/stack allocation,
then it is put back in the trackable state. Hence it is safe in
the situation where checking is disabled, the containing area is
deallocated and later reallocated for some other purpose. */
#define VALGRIND_HG_DISABLE_CHECKING(_qzz_start, _qzz_len) \
DO_CREQ_v_WW(_VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED, \
void*,(_qzz_start), \
unsigned long,(_qzz_len))
/* And put it back into the normal "tracked" state, that is, make it
once again subject to the normal race-checking machinery. This
puts it in the same state as new memory allocated by this thread --
that is, basically owned exclusively by this thread. */
#define VALGRIND_HG_ENABLE_CHECKING(_qzz_start, _qzz_len) \
DO_CREQ_v_WW(_VG_USERREQ__HG_ARANGE_MAKE_TRACKED, \
void*,(_qzz_start), \
unsigned long,(_qzz_len))
/* Checks the accessibility bits for addresses [zza..zza+zznbytes-1].
If zzabits array is provided, copy the accessibility bits in zzabits.
Return values:
-2 if not running on helgrind
-1 if any parts of zzabits is not addressable
>= 0 : success.
When success, it returns the nr of addressable bytes found.
So, to check that a whole range is addressable, check
VALGRIND_HG_GET_ABITS(addr,NULL,len) == len
In addition, if you want to examine the addressability of each
byte of the range, you need to provide a non NULL ptr as
second argument, pointing to an array of unsigned char
of length len.
Addressable bytes are indicated with 0xff.
Non-addressable bytes are indicated with 0x00.
*/
#define VALGRIND_HG_GET_ABITS(zza,zzabits,zznbytes) \
(__extension__ \
({long int _res; \
/* \
* XXX: here PMDK's version deviates from upstream; \
* without the fix, this macro doesn't return \
* the default value correctly \
*/ \
DO_CREQ_W_WWW(_res, (-2LL)/*default*/, \
_VG_USERREQ__HG_GET_ABITS, \
void*,(zza), void*,(zzabits), \
unsigned long,(zznbytes)); \
_res; \
}))
/* End-user request for Ada applications compiled with GNAT.
Helgrind understands the Ada concept of Ada task dependencies and
terminations. See Ada Reference Manual section 9.3 "Task Dependence
- Termination of Tasks".
However, in some cases, the master of (terminated) tasks completes
only when the application exits. An example of this is dynamically
allocated tasks with an access type defined at Library Level.
By default, the state of such tasks in Helgrind will be 'exited but
join not done yet'. Many tasks in such a state are however causing
Helgrind CPU and memory to increase significantly.
VALGRIND_HG_GNAT_DEPENDENT_MASTER_JOIN can be used to indicate
to Helgrind that a not yet completed master has however already
'seen' the termination of a dependent : this is conceptually the
same as a pthread_join and causes the cleanup of the dependent
as done by Helgrind when a master completes.
This allows to avoid the overhead in helgrind caused by such tasks.
A typical usage for a master to indicate it has done conceptually a join
with a dependent task before the master completes is:
while not Dep_Task'Terminated loop
... do whatever to wait for Dep_Task termination.
end loop;
VALGRIND_HG_GNAT_DEPENDENT_MASTER_JOIN
(Dep_Task'Identity,
Ada.Task_Identification.Current_Task);
Note that VALGRIND_HG_GNAT_DEPENDENT_MASTER_JOIN should be a binding
to a C function built with the below macro. */
#define VALGRIND_HG_GNAT_DEPENDENT_MASTER_JOIN(_qzz_dep, _qzz_master) \
DO_CREQ_v_WW(_VG_USERREQ__HG_GNAT_DEPENDENT_MASTER_JOIN, \
void*,(_qzz_dep), \
void*,(_qzz_master))
/*----------------------------------------------------------------*/
/*--- ---*/
/*--- ThreadSanitizer-compatible requests ---*/
/*--- (mostly unimplemented) ---*/
/*--- ---*/
/*----------------------------------------------------------------*/
/* A quite-broad set of annotations, as used in the ThreadSanitizer
project. This implementation aims to be a (source-level)
compatible implementation of the macros defined in:
http://code.google.com/p/data-race-test/source
/browse/trunk/dynamic_annotations/dynamic_annotations.h
(some of the comments below are taken from the above file)
The implementation here is very incomplete, and intended as a
starting point. Many of the macros are unimplemented. Rather than
allowing unimplemented macros to silently do nothing, they cause an
assertion. Intention is to implement them on demand.
The major use of these macros is to make visible to race detectors,
the behaviour (effects) of user-implemented synchronisation
primitives, that the detectors could not otherwise deduce from the
normal observation of pthread etc calls.
Some of the macros are no-ops in Helgrind. That's because Helgrind
is a pure happens-before detector, whereas ThreadSanitizer uses a
hybrid lockset and happens-before scheme, which requires more
accurate annotations for correct operation.
The macros are listed in the same order as in dynamic_annotations.h
(URL just above).
I should point out that I am less than clear about the intended
semantics of quite a number of them. Comments and clarifications
welcomed!
*/
/* ----------------------------------------------------------------
These four allow description of user-level condition variables,
apparently in the style of POSIX's pthread_cond_t. Currently
unimplemented and will assert.
----------------------------------------------------------------
*/
/* Report that wait on the condition variable at address CV has
succeeded and the lock at address LOCK is now held. CV and LOCK
are completely arbitrary memory addresses which presumably mean
something to the application, but are meaningless to Helgrind. */
#define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_LOCK_WAIT")
/* Report that wait on the condition variable at CV has succeeded.
Variant w/o lock. */
#define ANNOTATE_CONDVAR_WAIT(cv) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_WAIT")
/* Report that we are about to signal on the condition variable at
address CV. */
#define ANNOTATE_CONDVAR_SIGNAL(cv) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_SIGNAL")
/* Report that we are about to signal_all on the condition variable at
CV. */
#define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_CONDVAR_SIGNAL_ALL")
/* ----------------------------------------------------------------
Create completely arbitrary happens-before edges between threads.
If threads T1 .. Tn all do ANNOTATE_HAPPENS_BEFORE(obj) and later
(w.r.t. some notional global clock for the computation) thread Tm
does ANNOTATE_HAPPENS_AFTER(obj), then Helgrind will regard all
memory accesses done by T1 .. Tn before the ..BEFORE.. call as
happening-before all memory accesses done by Tm after the
..AFTER.. call. Hence Helgrind won't complain about races if Tm's
accesses afterwards are to the same locations as accesses before by
any of T1 .. Tn.
OBJ is a machine word (unsigned long, or void*), is completely
arbitrary, and denotes the identity of some synchronisation object
you're modelling.
You must do the _BEFORE call just before the real sync event on the
signaller's side, and _AFTER just after the real sync event on the
waiter's side.
If none of the rest of these macros make sense to you, at least
take the time to understand these two. They form the very essence
of describing arbitrary inter-thread synchronisation events to
Helgrind. You can get a long way just with them alone.
See also, extensive discussion on semantics of this in
https://bugs.kde.org/show_bug.cgi?id=243935
ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) is interim until such time
as bug 243935 is fully resolved. It instructs Helgrind to forget
about any ANNOTATE_HAPPENS_BEFORE calls on the specified object, in
effect putting it back in its original state. Once in that state,
a use of ANNOTATE_HAPPENS_AFTER on it has no effect on the calling
thread.
An implementation may optionally release resources it has
associated with 'obj' when ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj)
happens. Users are recommended to use
ANNOTATE_HAPPENS_BEFORE_FORGET_ALL to indicate when a
synchronisation object is no longer needed, so as to avoid
potential indefinite resource leaks.
----------------------------------------------------------------
*/
#define ANNOTATE_HAPPENS_BEFORE(obj) \
DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_SEND_PRE, void*,(obj))
#define ANNOTATE_HAPPENS_AFTER(obj) \
DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_RECV_POST, void*,(obj))
#define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) \
DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_FORGET_ALL, void*,(obj))
/* ----------------------------------------------------------------
Memory publishing. The TSan sources say:
Report that the bytes in the range [pointer, pointer+size) are about
to be published safely. The race checker will create a happens-before
arc from the call ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) to
subsequent accesses to this memory.
I'm not sure I understand what this means exactly, nor whether it
is relevant for a pure h-b detector. Leaving unimplemented for
now.
----------------------------------------------------------------
*/
#define ANNOTATE_PUBLISH_MEMORY_RANGE(pointer, size) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PUBLISH_MEMORY_RANGE")
/* DEPRECATED. Don't use it. */
/* #define ANNOTATE_UNPUBLISH_MEMORY_RANGE(pointer, size) */
/* DEPRECATED. Don't use it. */
/* #define ANNOTATE_SWAP_MEMORY_RANGE(pointer, size) */
/* ----------------------------------------------------------------
TSan sources say:
Instruct the tool to create a happens-before arc between
MU->Unlock() and MU->Lock(). This annotation may slow down the
race detector; normally it is used only when it would be
difficult to annotate each of the mutex's critical sections
individually using the annotations above.
If MU is a posix pthread_mutex_t then Helgrind will do this anyway.
In any case, leave as unimp for now. I'm unsure about the intended
behaviour.
----------------------------------------------------------------
*/
#define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mu) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX")
/* Deprecated. Use ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX. */
/* #define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mu) */
/* ----------------------------------------------------------------
TSan sources say:
Annotations useful when defining memory allocators, or when
memory that was protected in one way starts to be protected in
another.
Report that a new memory at "address" of size "size" has been
allocated. This might be used when the memory has been retrieved
from a free list and is about to be reused, or when a the locking
discipline for a variable changes.
AFAICS this is the same as VALGRIND_HG_CLEAN_MEMORY.
----------------------------------------------------------------
*/
#define ANNOTATE_NEW_MEMORY(address, size) \
VALGRIND_HG_CLEAN_MEMORY((address), (size))
/* ----------------------------------------------------------------
TSan sources say:
Annotations useful when defining FIFO queues that transfer data
between threads.
All unimplemented. Am not claiming to understand this (yet).
----------------------------------------------------------------
*/
/* Report that the producer-consumer queue object at address PCQ has
been created. The ANNOTATE_PCQ_* annotations should be used only
for FIFO queues. For non-FIFO queues use ANNOTATE_HAPPENS_BEFORE
(for put) and ANNOTATE_HAPPENS_AFTER (for get). */
#define ANNOTATE_PCQ_CREATE(pcq) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_CREATE")
/* Report that the queue at address PCQ is about to be destroyed. */
#define ANNOTATE_PCQ_DESTROY(pcq) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_DESTROY")
/* Report that we are about to put an element into a FIFO queue at
address PCQ. */
#define ANNOTATE_PCQ_PUT(pcq) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_PUT")
/* Report that we've just got an element from a FIFO queue at address
PCQ. */
#define ANNOTATE_PCQ_GET(pcq) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_PCQ_GET")
/* ----------------------------------------------------------------
Annotations that suppress errors. It is usually better to express
the program's synchronization using the other annotations, but
these can be used when all else fails.
Currently these are all unimplemented. I can't think of a simple
way to implement them without at least some performance overhead.
----------------------------------------------------------------
*/
/* Report that we may have a benign race at "pointer", with size
"sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the
point where "pointer" has been allocated, preferably close to the point
where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC.
XXX: what's this actually supposed to do? And what's the type of
DESCRIPTION? When does the annotation stop having an effect?
*/
#define ANNOTATE_BENIGN_RACE(pointer, description) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_BENIGN_RACE")
/* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to
the memory range [address, address+size). */
#define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
VALGRIND_HG_DISABLE_CHECKING(address, size)
/* Request the analysis tool to ignore all reads in the current thread
until ANNOTATE_IGNORE_READS_END is called. Useful to ignore
intentional racey reads, while still checking other reads and all
writes. */
#define ANNOTATE_IGNORE_READS_BEGIN() \
_HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_READS_BEGIN")
/* Stop ignoring reads. */
#define ANNOTATE_IGNORE_READS_END() \
_HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_READS_END")
/* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes. */
#define ANNOTATE_IGNORE_WRITES_BEGIN() \
_HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_WRITES_BEGIN")
/* Stop ignoring writes. */
#define ANNOTATE_IGNORE_WRITES_END() \
_HG_CLIENTREQ_UNIMP("ANNOTATE_IGNORE_WRITES_END")
/* Start ignoring all memory accesses (reads and writes). */
#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
do { \
ANNOTATE_IGNORE_READS_BEGIN(); \
ANNOTATE_IGNORE_WRITES_BEGIN(); \
} while (0)
/* Stop ignoring all memory accesses. */
#define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
do { \
ANNOTATE_IGNORE_WRITES_END(); \
ANNOTATE_IGNORE_READS_END(); \
} while (0)
/* ----------------------------------------------------------------
Annotations useful for debugging.
Again, so for unimplemented, partly for performance reasons.
----------------------------------------------------------------
*/
/* Request to trace every access to ADDRESS. */
#define ANNOTATE_TRACE_MEMORY(address) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_TRACE_MEMORY")
/* Report the current thread name to a race detector. */
#define ANNOTATE_THREAD_NAME(name) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_THREAD_NAME")
/* ----------------------------------------------------------------
Annotations for describing behaviour of user-implemented lock
primitives. In all cases, the LOCK argument is a completely
arbitrary machine word (unsigned long, or void*) and can be any
value which gives a unique identity to the lock objects being
modelled.
We just pretend they're ordinary posix rwlocks. That'll probably
give some rather confusing wording in error messages, claiming that
the arbitrary LOCK values are pthread_rwlock_t*'s, when in fact
they are not. Ah well.
----------------------------------------------------------------
*/
/* Report that a lock has just been created at address LOCK. */
#define ANNOTATE_RWLOCK_CREATE(lock) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST, \
void*,(lock))
/* Report that the lock at address LOCK is about to be destroyed. */
#define ANNOTATE_RWLOCK_DESTROY(lock) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE, \
void*,(lock))
/* Report that the lock at address LOCK has just been acquired.
is_w=1 for writer lock, is_w=0 for reader lock. */
#define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_RWLOCK_ACQUIRED, \
void*,(lock), unsigned long,(is_w))
/* Report that the lock at address LOCK is about to be released. */
#define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_RWLOCK_RELEASED, \
void*,(lock)) /* is_w is ignored */
/* -------------------------------------------------------------
Annotations useful when implementing barriers. They are not
normally needed by modules that merely use barriers.
The "barrier" argument is a pointer to the barrier object.
----------------------------------------------------------------
*/
/* Report that the "barrier" has been initialized with initial
"count". If 'reinitialization_allowed' is true, initialization is
allowed to happen multiple times w/o calling barrier_destroy() */
#define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_INIT")
/* Report that we are about to enter barrier_wait("barrier"). */
#define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY")
/* Report that we just exited barrier_wait("barrier"). */
#define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY")
/* Report that the "barrier" has been destroyed. */
#define ANNOTATE_BARRIER_DESTROY(barrier) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_BARRIER_DESTROY")
/* ----------------------------------------------------------------
Annotations useful for testing race detectors.
----------------------------------------------------------------
*/
/* Report that we expect a race on the variable at ADDRESS. Use only
in unit tests for a race detector. */
#define ANNOTATE_EXPECT_RACE(address, description) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_EXPECT_RACE")
/* A no-op. Insert where you like to test the interceptors. */
#define ANNOTATE_NO_OP(arg) \
_HG_CLIENTREQ_UNIMP("ANNOTATE_NO_OP")
/* Force the race detector to flush its state. The actual effect depends on
* the implementation of the detector. */
#define ANNOTATE_FLUSH_STATE() \
_HG_CLIENTREQ_UNIMP("ANNOTATE_FLUSH_STATE")
#endif /* __HELGRIND_H */
| 39,544 | 45.965558 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind/valgrind.h | /* -*- c -*-
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (valgrind.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2000-2017 Julian Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(valgrind.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query Valgrind's
execution inside your own programs.
The resulting executables will still run without Valgrind, just a
little bit more slowly than they otherwise would, but otherwise
unchanged. When not running on valgrind, each client request
consumes very few (eg. 7) instructions, so the resulting performance
loss is negligible unless you plan to execute client requests
millions of times per second. Nevertheless, if that is still a
problem, you can compile with the NVALGRIND symbol defined (gcc
-DNVALGRIND) so that client requests are not even compiled in. */
#ifndef __VALGRIND_H
#define __VALGRIND_H
/* ------------------------------------------------------------------ */
/* VERSION NUMBER OF VALGRIND */
/* ------------------------------------------------------------------ */
/* Specify Valgrind's version number, so that user code can
conditionally compile based on our version number. Note that these
were introduced at version 3.6 and so do not exist in version 3.5
or earlier. The recommended way to use them to check for "version
X.Y or later" is (eg)
#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
&& (__VALGRIND_MAJOR__ > 3 \
|| (__VALGRIND_MAJOR__ == 3 && __VALGRIND_MINOR__ >= 6))
*/
#define __VALGRIND_MAJOR__ 3
#define __VALGRIND_MINOR__ 14
#include <stdarg.h>
/* Nb: this file might be included in a file compiled with -ansi. So
we can't use C++ style "//" comments nor the "asm" keyword (instead
use "__asm__"). */
/* Derive some tags indicating what the target platform is. Note
that in this file we're using the compiler's CPP symbols for
identifying architectures, which are different to the ones we use
within the rest of Valgrind. Note, __powerpc__ is active for both
32 and 64-bit PPC, whereas __powerpc64__ is only active for the
latter (on Linux, that is).
Misc note: how to find out what's predefined in gcc by default:
gcc -Wp,-dM somefile.c
*/
#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_x86_win32
#undef PLAT_amd64_win64
#undef PLAT_x86_linux
#undef PLAT_amd64_linux
#undef PLAT_ppc32_linux
#undef PLAT_ppc64be_linux
#undef PLAT_ppc64le_linux
#undef PLAT_arm_linux
#undef PLAT_arm64_linux
#undef PLAT_s390x_linux
#undef PLAT_mips32_linux
#undef PLAT_mips64_linux
#undef PLAT_x86_solaris
#undef PLAT_amd64_solaris
#if defined(__APPLE__) && defined(__i386__)
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif (defined(__MINGW32__) && !defined(__MINGW64__)) \
|| defined(__CYGWIN32__) \
|| (defined(_WIN32) && defined(_M_IX86))
# define PLAT_x86_win32 1
#elif defined(__MINGW64__) \
|| (defined(_WIN64) && defined(_M_X64))
# define PLAT_amd64_win64 1
#elif defined(__linux__) && defined(__i386__)
# define PLAT_x86_linux 1
#elif defined(__linux__) && defined(__x86_64__) && !defined(__ILP32__)
# define PLAT_amd64_linux 1
#elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
# define PLAT_ppc32_linux 1
#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF != 2
/* Big Endian uses ELF version 1 */
# define PLAT_ppc64be_linux 1
#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF == 2
/* Little Endian uses ELF version 2 */
# define PLAT_ppc64le_linux 1
#elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__)
# define PLAT_arm_linux 1
#elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__)
# define PLAT_arm64_linux 1
#elif defined(__linux__) && defined(__s390__) && defined(__s390x__)
# define PLAT_s390x_linux 1
#elif defined(__linux__) && defined(__mips__) && (__mips==64)
# define PLAT_mips64_linux 1
#elif defined(__linux__) && defined(__mips__) && (__mips!=64)
# define PLAT_mips32_linux 1
#elif defined(__sun) && defined(__i386__)
# define PLAT_x86_solaris 1
#elif defined(__sun) && defined(__x86_64__)
# define PLAT_amd64_solaris 1
#else
/* If we're not compiling for our target platform, don't generate
any inline asms. */
# if !defined(NVALGRIND)
# define NVALGRIND 1
# endif
#endif
/* ------------------------------------------------------------------ */
/* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */
/* in here of use to end-users -- skip to the next section. */
/* ------------------------------------------------------------------ */
/*
* VALGRIND_DO_CLIENT_REQUEST(): a statement that invokes a Valgrind client
* request. Accepts both pointers and integers as arguments.
*
* VALGRIND_DO_CLIENT_REQUEST_STMT(): a statement that invokes a Valgrind
* client request that does not return a value.
* VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind
* client request and whose value equals the client request result. Accepts
* both pointers and integers as arguments. Note that such calls are not
* necessarily pure functions -- they may have side effects.
*/
#define VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, \
_zzq_request, _zzq_arg1, _zzq_arg2, \
_zzq_arg3, _zzq_arg4, _zzq_arg5) \
do { (_zzq_rlval) = VALGRIND_DO_CLIENT_REQUEST_EXPR((_zzq_default), \
(_zzq_request), (_zzq_arg1), (_zzq_arg2), \
(_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
#define VALGRIND_DO_CLIENT_REQUEST_STMT(_zzq_request, _zzq_arg1, \
_zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
(_zzq_request), (_zzq_arg1), (_zzq_arg2), \
(_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
#if defined(NVALGRIND)
/* Define NVALGRIND to completely remove the Valgrind magic sequence
from the compiled code (analogous to NDEBUG's effects on
assert()) */
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
(_zzq_default)
#else /* ! NVALGRIND */
/* The following defines the magic code sequences which the JITter
spots and handles magically. Don't look too closely at them as
they will rot your brain.
The assembly code sequences for all architectures is in this one
file. This is because this file must be stand-alone, and we don't
want to have multiple files.
For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default
value gets put in the return slot, so that everything works when
this is executed not under Valgrind. Args are passed in a memory
block, and so there's no intrinsic limit to the number that could
be passed, but it's currently five.
The macro args are:
_zzq_rlval result lvalue
_zzq_default default value (result returned when running on real CPU)
_zzq_request request code
_zzq_arg1..5 request params
The other two macros are used to support function wrapping, and are
a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the
guest's NRADDR pseudo-register and whatever other information is
needed to safely run the call original from the wrapper: on
ppc64-linux, the R2 value at the divert point is also needed. This
information is abstracted into a user-visible type, OrigFn.
VALGRIND_CALL_NOREDIR_* behaves the same as the following on the
guest, but guarantees that the branch instruction will not be
redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64:
branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a
complete inline asm, since it needs to be combined with more magic
inline asm stuff to be useful.
*/
/* ----------------- x86-{linux,darwin,solaris} ---------------- */
#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
|| (defined(PLAT_x86_win32) && defined(__GNUC__)) \
|| defined(PLAT_x86_solaris)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"roll $3, %%edi ; roll $13, %%edi\n\t" \
"roll $29, %%edi ; roll $19, %%edi\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %EDX = client_request ( %EAX ) */ \
"xchgl %%ebx,%%ebx" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %EAX = guest_NRADDR */ \
"xchgl %%ecx,%%ecx" \
: "=a" (__addr) \
: \
: "cc", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_EAX \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%EAX */ \
"xchgl %%edx,%%edx\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"xchgl %%edi,%%edi\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_x86_linux || PLAT_x86_darwin || (PLAT_x86_win32 && __GNUC__)
|| PLAT_x86_solaris */
/* ------------------------- x86-Win32 ------------------------- */
#if defined(PLAT_x86_win32) && !defined(__GNUC__)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#if defined(_MSC_VER)
#define __SPECIAL_INSTRUCTION_PREAMBLE \
__asm rol edi, 3 __asm rol edi, 13 \
__asm rol edi, 29 __asm rol edi, 19
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \
(uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \
(uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \
(uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5))
static __inline uintptr_t
valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request,
uintptr_t _zzq_arg1, uintptr_t _zzq_arg2,
uintptr_t _zzq_arg3, uintptr_t _zzq_arg4,
uintptr_t _zzq_arg5)
{
volatile uintptr_t _zzq_args[6];
volatile unsigned int _zzq_result;
_zzq_args[0] = (uintptr_t)(_zzq_request);
_zzq_args[1] = (uintptr_t)(_zzq_arg1);
_zzq_args[2] = (uintptr_t)(_zzq_arg2);
_zzq_args[3] = (uintptr_t)(_zzq_arg3);
_zzq_args[4] = (uintptr_t)(_zzq_arg4);
_zzq_args[5] = (uintptr_t)(_zzq_arg5);
__asm { __asm lea eax, _zzq_args __asm mov edx, _zzq_default
__SPECIAL_INSTRUCTION_PREAMBLE
/* %EDX = client_request ( %EAX ) */
__asm xchg ebx,ebx
__asm mov _zzq_result, edx
}
return _zzq_result;
}
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm { __SPECIAL_INSTRUCTION_PREAMBLE \
/* %EAX = guest_NRADDR */ \
__asm xchg ecx,ecx \
__asm mov __addr, eax \
} \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_EAX ERROR
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm { __SPECIAL_INSTRUCTION_PREAMBLE \
__asm xchg edi,edi \
} \
} while (0)
#else
#error Unsupported compiler.
#endif
#endif /* PLAT_x86_win32 */
/* ----------------- amd64-{linux,darwin,solaris} --------------- */
#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
|| defined(PLAT_amd64_solaris) \
|| (defined(PLAT_amd64_win64) && defined(__GNUC__))
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
"rolq $61, %%rdi ; rolq $51, %%rdi\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %RDX = client_request ( %RAX ) */ \
"xchgq %%rbx,%%rbx" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %RAX = guest_NRADDR */ \
"xchgq %%rcx,%%rcx" \
: "=a" (__addr) \
: \
: "cc", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_RAX \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%RAX */ \
"xchgq %%rdx,%%rdx\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"xchgq %%rdi,%%rdi\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
/* ------------------------- amd64-Win64 ------------------------- */
#if defined(PLAT_amd64_win64) && !defined(__GNUC__)
#error Unsupported compiler.
#endif /* PLAT_amd64_win64 */
/* ------------------------ ppc32-linux ------------------------ */
#if defined(PLAT_ppc32_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
"rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned int _zzq_args[6]; \
unsigned int _zzq_result; \
unsigned int* _zzq_ptr; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R11 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc32_linux */
/* ------------------------ ppc64-linux ------------------------ */
#if defined(PLAT_ppc64be_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
unsigned long int r2; /* what tocptr do we need? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
"rotldi 0,0,61 ; rotldi 0,0,51\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned long int _zzq_args[6]; \
unsigned long int _zzq_result; \
unsigned long int* _zzq_ptr; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR_GPR2 */ \
"or 4,4,4\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->r2 = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R11 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc64be_linux */
#if defined(PLAT_ppc64le_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
unsigned long int r2; /* what tocptr do we need? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
"rotldi 0,0,61 ; rotldi 0,0,51\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned long int _zzq_args[6]; \
unsigned long int _zzq_result; \
unsigned long int* _zzq_ptr; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR_GPR2 */ \
"or 4,4,4\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->r2 = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R12 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc64le_linux */
/* ------------------------- arm-linux ------------------------- */
#if defined(PLAT_arm_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
"mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile("mov r3, %1\n\t" /*default*/ \
"mov r4, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* R3 = client_request ( R4 ) */ \
"orr r10, r10, r10\n\t" \
"mov %0, r3" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "cc","memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* R3 = guest_NRADDR */ \
"orr r11, r11, r11\n\t" \
"mov %0, r3" \
: "=r" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R4 */ \
"orr r12, r12, r12\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"orr r9, r9, r9\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_arm_linux */
/* ------------------------ arm64-linux ------------------------- */
#if defined(PLAT_arm64_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"ror x12, x12, #3 ; ror x12, x12, #13 \n\t" \
"ror x12, x12, #51 ; ror x12, x12, #61 \n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile("mov x3, %1\n\t" /*default*/ \
"mov x4, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* X3 = client_request ( X4 ) */ \
"orr x10, x10, x10\n\t" \
"mov %0, x3" /*result*/ \
: "=r" (_zzq_result) \
: "r" ((unsigned long int)(_zzq_default)), \
"r" (&_zzq_args[0]) \
: "cc","memory", "x3", "x4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* X3 = guest_NRADDR */ \
"orr x11, x11, x11\n\t" \
"mov %0, x3" \
: "=r" (__addr) \
: \
: "cc", "memory", "x3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir X8 */ \
"orr x12, x12, x12\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"orr x9, x9, x9\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_arm64_linux */
/* ------------------------ s390x-linux ------------------------ */
#if defined(PLAT_s390x_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
/* __SPECIAL_INSTRUCTION_PREAMBLE will be used to identify Valgrind specific
* code. This detection is implemented in platform specific toIR.c
* (e.g. VEX/priv/guest_s390_decoder.c).
*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"lr 15,15\n\t" \
"lr 1,1\n\t" \
"lr 2,2\n\t" \
"lr 3,3\n\t"
#define __CLIENT_REQUEST_CODE "lr 2,2\n\t"
#define __GET_NR_CONTEXT_CODE "lr 3,3\n\t"
#define __CALL_NO_REDIR_CODE "lr 4,4\n\t"
#define __VEX_INJECT_IR_CODE "lr 5,5\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile(/* r2 = args */ \
"lgr 2,%1\n\t" \
/* r3 = default */ \
"lgr 3,%2\n\t" \
__SPECIAL_INSTRUCTION_PREAMBLE \
__CLIENT_REQUEST_CODE \
/* results = r3 */ \
"lgr %0, 3\n\t" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "2", "3", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
__GET_NR_CONTEXT_CODE \
"lgr %0, 3\n\t" \
: "=a" (__addr) \
: \
: "cc", "3", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_R1 \
__SPECIAL_INSTRUCTION_PREAMBLE \
__CALL_NO_REDIR_CODE
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
__VEX_INJECT_IR_CODE); \
} while (0)
#endif /* PLAT_s390x_linux */
/* ------------------------- mips32-linux ---------------- */
#if defined(PLAT_mips32_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
/* .word 0x342
* .word 0x742
* .word 0xC2
* .word 0x4C2*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"srl $0, $0, 13\n\t" \
"srl $0, $0, 29\n\t" \
"srl $0, $0, 3\n\t" \
"srl $0, $0, 19\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile("move $11, %1\n\t" /*default*/ \
"move $12, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* T3 = client_request ( T4 ) */ \
"or $13, $13, $13\n\t" \
"move %0, $11\n\t" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "$11", "$12", "memory"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %t9 = guest_NRADDR */ \
"or $14, $14, $14\n\t" \
"move %0, $11" /*result*/ \
: "=r" (__addr) \
: \
: "$11" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_T9 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%t9 */ \
"or $15, $15, $15\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or $11, $11, $11\n\t" \
); \
} while (0)
#endif /* PLAT_mips32_linux */
/* ------------------------- mips64-linux ---------------- */
#if defined(PLAT_mips64_linux)
typedef
struct {
unsigned long nraddr; /* where's the code? */
}
OrigFn;
/* dsll $0,$0, 3
* dsll $0,$0, 13
* dsll $0,$0, 29
* dsll $0,$0, 19*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"dsll $0,$0, 3 ; dsll $0,$0,13\n\t" \
"dsll $0,$0,29 ; dsll $0,$0,19\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile("move $11, %1\n\t" /*default*/ \
"move $12, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* $11 = client_request ( $12 ) */ \
"or $13, $13, $13\n\t" \
"move %0, $11\n\t" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "$11", "$12", "memory"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* $11 = guest_NRADDR */ \
"or $14, $14, $14\n\t" \
"move %0, $11" /*result*/ \
: "=r" (__addr) \
: \
: "$11"); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_T9 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir $25 */ \
"or $15, $15, $15\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or $11, $11, $11\n\t" \
); \
} while (0)
#endif /* PLAT_mips64_linux */
/* Insert assembly code for other platforms here... */
#endif /* NVALGRIND */
/* ------------------------------------------------------------------ */
/* PLATFORM SPECIFICS for FUNCTION WRAPPING. This is all very */
/* ugly. It's the least-worst tradeoff I can think of. */
/* ------------------------------------------------------------------ */
/* This section defines magic (a.k.a appalling-hack) macros for doing
guaranteed-no-redirection macros, so as to get from function
wrappers to the functions they are wrapping. The whole point is to
construct standard call sequences, but to do the call itself with a
special no-redirect call pseudo-instruction that the JIT
understands and handles specially. This section is long and
repetitious, and I can't see a way to make it shorter.
The naming scheme is as follows:
CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc}
'W' stands for "word" and 'v' for "void". Hence there are
different macros for calling arity 0, 1, 2, 3, 4, etc, functions,
and for each, the possibility of returning a word-typed result, or
no result.
*/
/* Use these to write the name of your wrapper. NOTE: duplicates
VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. NOTE also: inserts
the default behaviour equivalance class tag "0000" into the name.
See pub_tool_redir.h for details -- normally you don't need to
think about this, though. */
/* Use an extra level of macroisation so as to ensure the soname/fnname
args are fully macro-expanded before pasting them together. */
#define VG_CONCAT4(_aa,_bb,_cc,_dd) _aa##_bb##_cc##_dd
#define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \
VG_CONCAT4(_vgw00000ZU_,soname,_,fnname)
#define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \
VG_CONCAT4(_vgw00000ZZ_,soname,_,fnname)
/* Use this macro from within a wrapper function to collect the
context (address and possibly other info) of the original function.
Once you have that you can then use it in one of the CALL_FN_
macros. The type of the argument _lval is OrigFn. */
#define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval)
/* Also provide end-user facilities for function replacement, rather
than wrapping. A replacement function differs from a wrapper in
that it has no way to get hold of the original function being
called, and hence no way to call onwards to it. In a replacement
function, VALGRIND_GET_ORIG_FN always returns zero. */
#define I_REPLACE_SONAME_FNNAME_ZU(soname,fnname) \
VG_CONCAT4(_vgr00000ZU_,soname,_,fnname)
#define I_REPLACE_SONAME_FNNAME_ZZ(soname,fnname) \
VG_CONCAT4(_vgr00000ZZ_,soname,_,fnname)
/* Derivatives of the main macros below, for calling functions
returning void. */
#define CALL_FN_v_v(fnptr) \
do { volatile unsigned long _junk; \
CALL_FN_W_v(_junk,fnptr); } while (0)
#define CALL_FN_v_W(fnptr, arg1) \
do { volatile unsigned long _junk; \
CALL_FN_W_W(_junk,fnptr,arg1); } while (0)
#define CALL_FN_v_WW(fnptr, arg1,arg2) \
do { volatile unsigned long _junk; \
CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0)
#define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \
do { volatile unsigned long _junk; \
CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0)
#define CALL_FN_v_WWWW(fnptr, arg1,arg2,arg3,arg4) \
do { volatile unsigned long _junk; \
CALL_FN_W_WWWW(_junk,fnptr,arg1,arg2,arg3,arg4); } while (0)
#define CALL_FN_v_5W(fnptr, arg1,arg2,arg3,arg4,arg5) \
do { volatile unsigned long _junk; \
CALL_FN_W_5W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5); } while (0)
#define CALL_FN_v_6W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6) \
do { volatile unsigned long _junk; \
CALL_FN_W_6W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6); } while (0)
#define CALL_FN_v_7W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6,arg7) \
do { volatile unsigned long _junk; \
CALL_FN_W_7W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6,arg7); } while (0)
/* ----------------- x86-{linux,darwin,solaris} ---------------- */
#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
|| defined(PLAT_x86_solaris)
/* These regs are trashed by the hidden call. No need to mention eax
as gcc can already see that, plus causes gcc to bomb. */
#define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"movl %%esp,%%edi\n\t" \
"andl $0xfffffff0,%%esp\n\t"
#define VALGRIND_RESTORE_STACK \
"movl %%edi,%%esp\n\t"
/* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 44(%%eax)\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 48(%%eax)\n\t" \
"pushl 44(%%eax)\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_x86_linux || PLAT_x86_darwin || PLAT_x86_solaris */
/* ---------------- amd64-{linux,darwin,solaris} --------------- */
#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
|| defined(PLAT_amd64_solaris)
/* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \
"rdi", "r8", "r9", "r10", "r11"
/* This is all pretty complex. It's so as to make stack unwinding
work reliably. See bug 243270. The basic problem is the sub and
add of 128 of %rsp in all of the following macros. If gcc believes
the CFA is in %rsp, then unwinding may fail, because what's at the
CFA is not what gcc "expected" when it constructs the CFIs for the
places where the macros are instantiated.
But we can't just add a CFI annotation to increase the CFA offset
by 128, to match the sub of 128 from %rsp, because we don't know
whether gcc has chosen %rsp as the CFA at that point, or whether it
has chosen some other register (eg, %rbp). In the latter case,
adding a CFI annotation to change the CFA offset is simply wrong.
So the solution is to get hold of the CFA using
__builtin_dwarf_cfa(), put it in a known register, and add a
CFI annotation to say what the register is. We choose %rbp for
this (perhaps perversely), because:
(1) %rbp is already subject to unwinding. If a new register was
chosen then the unwinder would have to unwind it in all stack
traces, which is expensive, and
(2) %rbp is already subject to precise exception updates in the
JIT. If a new register was chosen, we'd have to have precise
exceptions for it too, which reduces performance of the
generated code.
However .. one extra complication. We can't just whack the result
of __builtin_dwarf_cfa() into %rbp and then add %rbp to the
list of trashed registers at the end of the inline assembly
fragments; gcc won't allow %rbp to appear in that list. Hence
instead we need to stash %rbp in %r15 for the duration of the asm,
and say that %r15 is trashed instead. gcc seems happy to go with
that.
Oh .. and this all needs to be conditionalised so that it is
unchanged from before this commit, when compiled with older gccs
that don't support __builtin_dwarf_cfa. Furthermore, since
this header file is freestanding, it has to be independent of
config.h, and so the following conditionalisation cannot depend on
configure time checks.
Although it's not clear from
'defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)',
this expression excludes Darwin.
.cfi directives in Darwin assembly appear to be completely
different and I haven't investigated how they work.
For even more entertainment value, note we have to use the
completely undocumented __builtin_dwarf_cfa(), which appears to
really compute the CFA, whereas __builtin_frame_address(0) claims
to but actually doesn't. See
https://bugs.kde.org/show_bug.cgi?id=243270#c47
*/
#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
# define __FRAME_POINTER \
,"r"(__builtin_dwarf_cfa())
# define VALGRIND_CFI_PROLOGUE \
"movq %%rbp, %%r15\n\t" \
"movq %2, %%rbp\n\t" \
".cfi_remember_state\n\t" \
".cfi_def_cfa rbp, 0\n\t"
# define VALGRIND_CFI_EPILOGUE \
"movq %%r15, %%rbp\n\t" \
".cfi_restore_state\n\t"
#else
# define __FRAME_POINTER
# define VALGRIND_CFI_PROLOGUE
# define VALGRIND_CFI_EPILOGUE
#endif
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"movq %%rsp,%%r14\n\t" \
"andq $0xfffffffffffffff0,%%rsp\n\t"
#define VALGRIND_RESTORE_STACK \
"movq %%r14,%%rsp\n\t"
/* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned
long) == 8. */
/* NB 9 Sept 07. There is a nasty kludge here in all these CALL_FN_
macros. In order not to trash the stack redzone, we need to drop
%rsp by 128 before the hidden call, and restore afterwards. The
nastiness is that it is only by luck that the stack still appears
to be unwindable during the hidden call - since then the behaviour
of any routine using this macro does not match what the CFI data
says. Sigh.
Why is this important? Imagine that a wrapper has a stack
allocated local, and passes to the hidden call, a pointer to it.
Because gcc does not know about the hidden call, it may allocate
that local in the redzone. Unfortunately the hidden call may then
trash it before it comes to use it. So we must step clear of the
redzone, for the duration of the hidden call, to make it safe.
Probably the same problem afflicts the other redzone-style ABIs too
(ppc64-linux); but for those, the stack is
self describing (none of this CFI nonsense) so at least messing
with the stack pointer doesn't give a danger of non-unwindable
stack. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 88(%%rax)\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 96(%%rax)\n\t" \
"pushq 88(%%rax)\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
/* ------------------------ ppc32-linux ------------------------ */
#if defined(PLAT_ppc32_linux)
/* This is useful for finding out about the on-stack stuff:
extern int f9 ( int,int,int,int,int,int,int,int,int );
extern int f10 ( int,int,int,int,int,int,int,int,int,int );
extern int f11 ( int,int,int,int,int,int,int,int,int,int,int );
extern int f12 ( int,int,int,int,int,int,int,int,int,int,int,int );
int g9 ( void ) {
return f9(11,22,33,44,55,66,77,88,99);
}
int g10 ( void ) {
return f10(11,22,33,44,55,66,77,88,99,110);
}
int g11 ( void ) {
return f11(11,22,33,44,55,66,77,88,99,110,121);
}
int g12 ( void ) {
return f12(11,22,33,44,55,66,77,88,99,110,121,132);
}
*/
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rlwinm 1,1,0,0,27\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc32-linux,
sizeof(unsigned long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-16\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-16\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-32\n\t" \
/* arg11 */ \
"lwz 3,44(11)\n\t" \
"stw 3,16(1)\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
_argvec[12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-32\n\t" \
/* arg12 */ \
"lwz 3,48(11)\n\t" \
"stw 3,20(1)\n\t" \
/* arg11 */ \
"lwz 3,44(11)\n\t" \
"stw 3,16(1)\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc32_linux */
/* ------------------------ ppc64-linux ------------------------ */
#if defined(PLAT_ppc64be_linux)
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rldicr 1,1,0,59\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+0]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+1]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+2]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+3]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+4]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+5]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+6]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+7]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+8]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+9]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+10]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+11]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg11 */ \
"ld 3,88(11)\n\t" \
"std 3,128(1)\n\t" \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+12]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
_argvec[2+12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg12 */ \
"ld 3,96(11)\n\t" \
"std 3,136(1)\n\t" \
/* arg11 */ \
"ld 3,88(11)\n\t" \
"std 3,128(1)\n\t" \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc64be_linux */
/* ------------------------- ppc64le-linux ----------------------- */
#if defined(PLAT_ppc64le_linux)
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rldicr 1,1,0,59\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+0]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+1]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+2]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+3]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+4]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+5]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+6]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+7]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+8]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+9]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+10]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+11]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg11 */ \
"ld 3,88(12)\n\t" \
"std 3,112(1)\n\t" \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+12]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
_argvec[2+12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg12 */ \
"ld 3,96(12)\n\t" \
"std 3,120(1)\n\t" \
/* arg11 */ \
"ld 3,88(12)\n\t" \
"std 3,112(1)\n\t" \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc64le_linux */
/* ------------------------- arm-linux ------------------------- */
#if defined(PLAT_arm_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "r0", "r1", "r2", "r3","r4", "r12", "r14"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
/* This is a bit tricky. We store the original stack pointer in r10
as it is callee-saves. gcc doesn't allow the use of r11 for some
reason. Also, we can't directly "bic" the stack pointer in thumb
mode since r13 isn't an allowed register number in that context.
So use r4 as a temporary, since that is about to get trashed
anyway, just after each use of this macro. Side effect is we need
to be very careful about any future changes, since
VALGRIND_ALIGN_STACK simply assumes r4 is usable. */
#define VALGRIND_ALIGN_STACK \
"mov r10, sp\n\t" \
"mov r4, sp\n\t" \
"bic r4, r4, #7\n\t" \
"mov sp, r4\n\t"
#define VALGRIND_RESTORE_STACK \
"mov sp, r10\n\t"
/* These CALL_FN_ macros assume that on arm-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"push {r0} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"push {r0, r1} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"push {r0, r1, r2} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"push {r0, r1, r2, r3} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #40] \n\t" \
"push {r0} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #40] \n\t" \
"ldr r1, [%1, #44] \n\t" \
"push {r0, r1} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #40] \n\t" \
"ldr r1, [%1, #44] \n\t" \
"ldr r2, [%1, #48] \n\t" \
"push {r0, r1, r2} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_arm_linux */
/* ------------------------ arm64-linux ------------------------ */
#if defined(PLAT_arm64_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"x0", "x1", "x2", "x3","x4", "x5", "x6", "x7", "x8", "x9", \
"x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", \
"x18", "x19", "x20", "x30", \
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \
"v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", \
"v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", \
"v26", "v27", "v28", "v29", "v30", "v31"
/* x21 is callee-saved, so we can use it to save and restore SP around
the hidden call. */
#define VALGRIND_ALIGN_STACK \
"mov x21, sp\n\t" \
"bic sp, x21, #15\n\t"
#define VALGRIND_RESTORE_STACK \
"mov sp, x21\n\t"
/* These CALL_FN_ macros assume that on arm64-linux,
sizeof(unsigned long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x20 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x20 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x30 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1, #88] \n\t" \
"str x8, [sp, #16] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11, \
arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x30 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1, #88] \n\t" \
"str x8, [sp, #16] \n\t" \
"ldr x8, [%1, #96] \n\t" \
"str x8, [sp, #24] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_arm64_linux */
/* ------------------------- s390x-linux ------------------------- */
#if defined(PLAT_s390x_linux)
/* Similar workaround as amd64 (see above), but we use r11 as frame
pointer and save the old r11 in r7. r11 might be used for
argvec, therefore we copy argvec in r1 since r1 is clobbered
after the call anyway. */
#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
# define __FRAME_POINTER \
,"d"(__builtin_dwarf_cfa())
# define VALGRIND_CFI_PROLOGUE \
".cfi_remember_state\n\t" \
"lgr 1,%1\n\t" /* copy the argvec pointer in r1 */ \
"lgr 7,11\n\t" \
"lgr 11,%2\n\t" \
".cfi_def_cfa r11, 0\n\t"
# define VALGRIND_CFI_EPILOGUE \
"lgr 11, 7\n\t" \
".cfi_restore_state\n\t"
#else
# define __FRAME_POINTER
# define VALGRIND_CFI_PROLOGUE \
"lgr 1,%1\n\t"
# define VALGRIND_CFI_EPILOGUE
#endif
/* Nb: On s390 the stack pointer is properly aligned *at all times*
according to the s390 GCC maintainer. (The ABI specification is not
precise in this regard.) Therefore, VALGRIND_ALIGN_STACK and
VALGRIND_RESTORE_STACK are not defined here. */
/* These regs are trashed by the hidden call. Note that we overwrite
r14 in s390_irgen_noredir (VEX/priv/guest_s390_irgen.c) to give the
function a proper return address. All others are ABI defined call
clobbers. */
#define __CALLER_SAVED_REGS "0","1","2","3","4","5","14", \
"f0","f1","f2","f3","f4","f5","f6","f7"
/* Nb: Although r11 is modified in the asm snippets below (inside
VALGRIND_CFI_PROLOGUE) it is not listed in the clobber section, for
two reasons:
(1) r11 is restored in VALGRIND_CFI_EPILOGUE, so effectively it is not
modified
(2) GCC will complain that r11 cannot appear inside a clobber section,
when compiled with -O -fno-omit-frame-pointer
*/
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 1, 0(1)\n\t" /* target->r1 */ \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "d" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
/* The call abi has the arguments in r2-r6 and stack */
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1, arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1, arg2, arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1, arg2, arg3, arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1, arg2, arg3, arg4, arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-168\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,168\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-176\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,176\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-184\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,184\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-192\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,192\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-200\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,200\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10, arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-208\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"mvc 200(8,15), 88(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,208\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10, arg11, arg12)\
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
_argvec[12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-216\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"mvc 200(8,15), 88(1)\n\t" \
"mvc 208(8,15), 96(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"lgr %0, 2\n\t" \
"aghi 15,216\n\t" \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_s390x_linux */
/* ------------------------- mips32-linux ----------------------- */
#if defined(PLAT_mips32_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
"$25", "$31"
/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16\n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" /* arg1*/ \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 24\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 24 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 32\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"nop\n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 32 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 32\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 32 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 40\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 40 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 40\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 40 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 48\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 48 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 48\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 44(%1) \n\t" \
"sw $4, 40($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 48 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 56\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 44(%1) \n\t" \
"sw $4, 40($29) \n\t" \
"lw $4, 48(%1) \n\t" \
"sw $4, 44($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 56 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_mips32_linux */
/* ------------------------- mips64-linux ------------------------- */
#if defined(PLAT_mips64_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
"$25", "$31"
/* These CALL_FN_ macros assume that on mips64-linux,
sizeof(long long) == 8. */
#define MIPS64_LONG2REG_CAST(x) ((long long)(long)x)
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[1]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
__asm__ volatile( \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[2]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" /* arg1*/ \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[3]; \
volatile unsigned long long _res; \
_argvec[0] = _orig.nraddr; \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[4]; \
volatile unsigned long long _res; \
_argvec[0] = _orig.nraddr; \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[5]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[6]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[7]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[8]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[9]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[10]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
__asm__ volatile( \
"dsubu $29, $29, 8\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 8\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[11]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
__asm__ volatile( \
"dsubu $29, $29, 16\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 16\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[12]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
_argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
__asm__ volatile( \
"dsubu $29, $29, 24\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 88(%1)\n\t" \
"sd $4, 16($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 24\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[13]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
_argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
_argvec[12] = MIPS64_LONG2REG_CAST(arg12); \
__asm__ volatile( \
"dsubu $29, $29, 32\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 88(%1)\n\t" \
"sd $4, 16($29)\n\t" \
"ld $4, 96(%1)\n\t" \
"sd $4, 24($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 32\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#endif /* PLAT_mips64_linux */
/* ------------------------------------------------------------------ */
/* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */
/* */
/* ------------------------------------------------------------------ */
/* Some request codes. There are many more of these, but most are not
exposed to end-user view. These are the public ones, all of the
form 0x1000 + small_number.
Core ones are in the range 0x00000000--0x0000ffff. The non-public
ones start at 0x2000.
*/
/* These macros are used by tools -- they must be public, but don't
embed them into other programs. */
#define VG_USERREQ_TOOL_BASE(a,b) \
((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16))
#define VG_IS_TOOL_USERREQ(a, b, v) \
(VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000))
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE NUMERIC VALUES OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end of the most
relevant group. */
typedef
enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001,
VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
/* These allow any function to be called from the simulated
CPU but run on the real CPU. Nb: the first arg passed to
the function is always the ThreadId of the running
thread! So CLIENT_CALL0 actually requires a 1 arg
function, etc. */
VG_USERREQ__CLIENT_CALL0 = 0x1101,
VG_USERREQ__CLIENT_CALL1 = 0x1102,
VG_USERREQ__CLIENT_CALL2 = 0x1103,
VG_USERREQ__CLIENT_CALL3 = 0x1104,
/* Can be useful in regression testing suites -- eg. can
send Valgrind's output to /dev/null and still count
errors. */
VG_USERREQ__COUNT_ERRORS = 0x1201,
/* Allows the client program and/or gdbserver to execute a monitor
command. */
VG_USERREQ__GDB_MONITOR_COMMAND = 0x1202,
/* These are useful and can be interpreted by any tool that
tracks malloc() et al, by using vg_replace_malloc.c. */
VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
VG_USERREQ__RESIZEINPLACE_BLOCK = 0x130b,
VG_USERREQ__FREELIKE_BLOCK = 0x1302,
/* Memory pool support. */
VG_USERREQ__CREATE_MEMPOOL = 0x1303,
VG_USERREQ__DESTROY_MEMPOOL = 0x1304,
VG_USERREQ__MEMPOOL_ALLOC = 0x1305,
VG_USERREQ__MEMPOOL_FREE = 0x1306,
VG_USERREQ__MEMPOOL_TRIM = 0x1307,
VG_USERREQ__MOVE_MEMPOOL = 0x1308,
VG_USERREQ__MEMPOOL_CHANGE = 0x1309,
VG_USERREQ__MEMPOOL_EXISTS = 0x130a,
/* Allow printfs to valgrind log. */
/* The first two pass the va_list argument by value, which
assumes it is the same size as or smaller than a UWord,
which generally isn't the case. Hence are deprecated.
The second two pass the vargs by reference and so are
immune to this problem. */
/* both :: char* fmt, va_list vargs (DEPRECATED) */
VG_USERREQ__PRINTF = 0x1401,
VG_USERREQ__PRINTF_BACKTRACE = 0x1402,
/* both :: char* fmt, va_list* vargs */
VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404,
/* Stack support. */
VG_USERREQ__STACK_REGISTER = 0x1501,
VG_USERREQ__STACK_DEREGISTER = 0x1502,
VG_USERREQ__STACK_CHANGE = 0x1503,
/* Wine support */
VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
/* Querying of debug info. */
VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701,
/* Disable/enable error reporting level. Takes a single
Word arg which is the delta to this thread's error
disablement indicator. Hence 1 disables or further
disables errors, and -1 moves back towards enablement.
Other values are not allowed. */
VG_USERREQ__CHANGE_ERR_DISABLEMENT = 0x1801,
/* Some requests used for Valgrind internal, such as
self-test or self-hosting. */
/* Initialise IR injection */
VG_USERREQ__VEX_INIT_FOR_IRI = 0x1901,
/* Used by Inner Valgrind to inform Outer Valgrind where to
find the list of inner guest threads */
VG_USERREQ__INNER_THREADS = 0x1902
} Vg_ClientRequest;
#if !defined(__GNUC__)
# define __extension__ /* */
#endif
/* Returns the number of Valgrinds this code is running under. That
is, 0 if running natively, 1 if running under Valgrind, 2 if
running under Valgrind which is running under another Valgrind,
etc. */
#define RUNNING_ON_VALGRIND \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */, \
VG_USERREQ__RUNNING_ON_VALGRIND, \
0, 0, 0, 0, 0) \
/* Discard translation of code in the range [_qzz_addr .. _qzz_addr +
_qzz_len - 1]. Useful if you are debugging a JITter or some such,
since it provides a way to make sure valgrind will retranslate the
invalidated area. Returns no value. */
#define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DISCARD_TRANSLATIONS, \
_qzz_addr, _qzz_len, 0, 0, 0)
#define VALGRIND_INNER_THREADS(_qzz_addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__INNER_THREADS, \
_qzz_addr, 0, 0, 0, 0)
/* These requests are for getting Valgrind itself to print something.
Possibly with a backtrace. This is a really ugly hack. The return value
is the number of characters printed, excluding the "**<pid>** " part at the
start and the backtrace (if present). */
#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
/* Modern GCC will optimize the static routine out if unused,
and unused attribute will shut down warnings about it. */
static int VALGRIND_PRINTF(const char *format, ...)
__attribute__((format(__printf__, 1, 2), __unused__));
#endif
static int
#if defined(_MSC_VER)
__inline
#endif
VALGRIND_PRINTF(const char *format, ...)
{
#if defined(NVALGRIND)
(void)format;
return 0;
#else /* NVALGRIND */
#if defined(_MSC_VER) || defined(__MINGW64__)
uintptr_t _qzz_res;
#else
unsigned long _qzz_res;
#endif
va_list vargs;
va_start(vargs, format);
#if defined(_MSC_VER) || defined(__MINGW64__)
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_VALIST_BY_REF,
(uintptr_t)format,
(uintptr_t)&vargs,
0, 0, 0);
#else
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_VALIST_BY_REF,
(unsigned long)format,
(unsigned long)&vargs,
0, 0, 0);
#endif
va_end(vargs);
return (int)_qzz_res;
#endif /* NVALGRIND */
}
#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
__attribute__((format(__printf__, 1, 2), __unused__));
#endif
static int
#if defined(_MSC_VER)
__inline
#endif
VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
{
#if defined(NVALGRIND)
(void)format;
return 0;
#else /* NVALGRIND */
#if defined(_MSC_VER) || defined(__MINGW64__)
uintptr_t _qzz_res;
#else
unsigned long _qzz_res;
#endif
va_list vargs;
va_start(vargs, format);
#if defined(_MSC_VER) || defined(__MINGW64__)
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
(uintptr_t)format,
(uintptr_t)&vargs,
0, 0, 0);
#else
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
(unsigned long)format,
(unsigned long)&vargs,
0, 0, 0);
#endif
va_end(vargs);
return (int)_qzz_res;
#endif /* NVALGRIND */
}
/* These requests allow control to move from the simulated CPU to the
real CPU, calling an arbitrary function.
Note that the current ThreadId is inserted as the first argument.
So this call:
VALGRIND_NON_SIMD_CALL2(f, arg1, arg2)
requires f to have this signature:
Word f(Word tid, Word arg1, Word arg2)
where "Word" is a word-sized type.
Note that these client requests are not entirely reliable. For example,
if you call a function with them that subsequently calls printf(),
there's a high chance Valgrind will crash. Generally, your prospects of
these working are made higher if the called function does not refer to
any global variables, and does not refer to any libc or other functions
(printf et al). Any kind of entanglement with libc or dynamic linking is
likely to have a bad outcome, for tricky reasons which we've grappled
with a lot in the past.
*/
#define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL0, \
_qyy_fn, \
0, 0, 0, 0)
#define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL1, \
_qyy_fn, \
_qyy_arg1, 0, 0, 0)
#define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL2, \
_qyy_fn, \
_qyy_arg1, _qyy_arg2, 0, 0)
#define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL3, \
_qyy_fn, \
_qyy_arg1, _qyy_arg2, \
_qyy_arg3, 0)
/* Counts the number of errors that have been recorded by a tool. Nb:
the tool must record the errors with VG_(maybe_record_error)() or
VG_(unique_error)() for them to be counted. */
#define VALGRIND_COUNT_ERRORS \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR( \
0 /* default return */, \
VG_USERREQ__COUNT_ERRORS, \
0, 0, 0, 0, 0)
/* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing
when heap blocks are allocated in order to give accurate results. This
happens automatically for the standard allocator functions such as
malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete,
delete[], etc.
But if your program uses a custom allocator, this doesn't automatically
happen, and Valgrind will not do as well. For example, if you allocate
superblocks with mmap() and then allocates chunks of the superblocks, all
Valgrind's observations will be at the mmap() level and it won't know that
the chunks should be considered separate entities. In Memcheck's case,
that means you probably won't get heap block overrun detection (because
there won't be redzones marked as unaddressable) and you definitely won't
get any leak detection.
The following client requests allow a custom allocator to be annotated so
that it can be handled accurately by Valgrind.
VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated
by a malloc()-like function. For Memcheck (an illustrative case), this
does two things:
- It records that the block has been allocated. This means any addresses
within the block mentioned in error messages will be
identified as belonging to the block. It also means that if the block
isn't freed it will be detected by the leak checker.
- It marks the block as being addressable and undefined (if 'is_zeroed' is
not set), or addressable and defined (if 'is_zeroed' is set). This
controls how accesses to the block by the program are handled.
'addr' is the start of the usable block (ie. after any
redzone), 'sizeB' is its size. 'rzB' is the redzone size if the allocator
can apply redzones -- these are blocks of padding at the start and end of
each block. Adding redzones is recommended as it makes it much more likely
Valgrind will spot block overruns. `is_zeroed' indicates if the memory is
zeroed (or filled with another predictable value), as is the case for
calloc().
VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
heap block -- that will be used by the client program -- is allocated.
It's best to put it at the outermost level of the allocator if possible;
for example, if you have a function my_alloc() which calls
internal_alloc(), and the client request is put inside internal_alloc(),
stack traces relating to the heap block will contain entries for both
my_alloc() and internal_alloc(), which is probably not what you want.
For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
custom blocks from within a heap block, B, that has been allocated with
malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
-- the custom blocks will take precedence.
VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For
Memcheck, it does two things:
- It records that the block has been deallocated. This assumes that the
block was annotated as having been allocated via
VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
- It marks the block as being unaddressable.
VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
heap block is deallocated.
VALGRIND_RESIZEINPLACE_BLOCK informs a tool about reallocation. For
Memcheck, it does four things:
- It records that the size of a block has been changed. This assumes that
the block was annotated as having been allocated via
VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
- If the block shrunk, it marks the freed memory as being unaddressable.
- If the block grew, it marks the new area as undefined and defines a red
zone past the end of the new block.
- The V-bits of the overlap between the old and the new block are preserved.
VALGRIND_RESIZEINPLACE_BLOCK should be put after allocation of the new block
and before deallocation of the old block.
In many cases, these three client requests will not be enough to get your
allocator working well with Memcheck. More specifically, if your allocator
writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call
will be necessary to mark the memory as addressable just before the zeroing
occurs, otherwise you'll get a lot of invalid write errors. For example,
you'll need to do this if your allocator recycles freed blocks, but it
zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK).
Alternatively, if your allocator reuses freed blocks for allocator-internal
data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary.
Really, what's happening is a blurring of the lines between the client
program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the
memory should be considered unaddressable to the client program, but the
allocator knows more than the rest of the client program and so may be able
to safely access it. Extra client requests are necessary for Valgrind to
understand the distinction between the allocator and the rest of the
program.
Ignored if addr == 0.
*/
#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK, \
addr, sizeB, rzB, is_zeroed, 0)
/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
Ignored if addr == 0.
*/
#define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__RESIZEINPLACE_BLOCK, \
addr, oldSizeB, newSizeB, rzB, 0)
/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
Ignored if addr == 0.
*/
#define VALGRIND_FREELIKE_BLOCK(addr, rzB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__FREELIKE_BLOCK, \
addr, rzB, 0, 0, 0)
/* Create a memory pool. */
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
pool, rzB, is_zeroed, 0, 0)
/* Create a memory pool with some flags specifying extended behaviour.
When flags is zero, the behaviour is identical to VALGRIND_CREATE_MEMPOOL.
The flag VALGRIND_MEMPOOL_METAPOOL specifies that the pieces of memory
associated with the pool using VALGRIND_MEMPOOL_ALLOC will be used
by the application as superblocks to dole out MALLOC_LIKE blocks using
VALGRIND_MALLOCLIKE_BLOCK. In other words, a meta pool is a "2 levels"
pool : first level is the blocks described by VALGRIND_MEMPOOL_ALLOC.
The second level blocks are described using VALGRIND_MALLOCLIKE_BLOCK.
Note that the association between the pool and the second level blocks
is implicit : second level blocks will be located inside first level
blocks. It is necessary to use the VALGRIND_MEMPOOL_METAPOOL flag
for such 2 levels pools, as otherwise valgrind will detect overlapping
memory blocks, and will abort execution (e.g. during leak search).
Such a meta pool can also be marked as an 'auto free' pool using the flag
VALGRIND_MEMPOOL_AUTO_FREE, which must be OR-ed together with the
VALGRIND_MEMPOOL_METAPOOL. For an 'auto free' pool, VALGRIND_MEMPOOL_FREE
will automatically free the second level blocks that are contained
inside the first level block freed with VALGRIND_MEMPOOL_FREE.
In other words, calling VALGRIND_MEMPOOL_FREE will cause implicit calls
to VALGRIND_FREELIKE_BLOCK for all the second level blocks included
in the first level block.
Note: it is an error to use the VALGRIND_MEMPOOL_AUTO_FREE flag
without the VALGRIND_MEMPOOL_METAPOOL flag.
*/
#define VALGRIND_MEMPOOL_AUTO_FREE 1
#define VALGRIND_MEMPOOL_METAPOOL 2
#define VALGRIND_CREATE_MEMPOOL_EXT(pool, rzB, is_zeroed, flags) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
pool, rzB, is_zeroed, flags, 0)
/* Destroy a memory pool. */
#define VALGRIND_DESTROY_MEMPOOL(pool) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \
pool, 0, 0, 0, 0)
/* Associate a piece of memory with a memory pool. */
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_ALLOC, \
pool, addr, size, 0, 0)
/* Disassociate a piece of memory from a memory pool. */
#define VALGRIND_MEMPOOL_FREE(pool, addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_FREE, \
pool, addr, 0, 0, 0)
/* Disassociate any pieces outside a particular range. */
#define VALGRIND_MEMPOOL_TRIM(pool, addr, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_TRIM, \
pool, addr, size, 0, 0)
/* Resize and/or move a piece associated with a memory pool. */
#define VALGRIND_MOVE_MEMPOOL(poolA, poolB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MOVE_MEMPOOL, \
poolA, poolB, 0, 0, 0)
/* Resize and/or move a piece associated with a memory pool. */
#define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_CHANGE, \
pool, addrA, addrB, size, 0)
/* Return 1 if a mempool exists, else 0. */
#define VALGRIND_MEMPOOL_EXISTS(pool) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__MEMPOOL_EXISTS, \
pool, 0, 0, 0, 0)
/* Mark a piece of memory as being a stack. Returns a stack id.
start is the lowest addressable stack byte, end is the highest
addressable stack byte. */
#define VALGRIND_STACK_REGISTER(start, end) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__STACK_REGISTER, \
start, end, 0, 0, 0)
/* Unmark the piece of memory associated with a stack id as being a
stack. */
#define VALGRIND_STACK_DEREGISTER(id) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_DEREGISTER, \
id, 0, 0, 0, 0)
/* Change the start and end address of the stack id.
start is the new lowest addressable stack byte, end is the new highest
addressable stack byte. */
#define VALGRIND_STACK_CHANGE(id, start, end) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_CHANGE, \
id, start, end, 0, 0)
/* Load PDB debug info for Wine PE image_map. */
#define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LOAD_PDB_DEBUGINFO, \
fd, ptr, total_size, delta, 0)
/* Map a code address to a source file name and line number. buf64
must point to a 64-byte buffer in the caller's address space. The
result will be dumped in there and is guaranteed to be zero
terminated. If no info is found, the first byte is set to zero. */
#define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__MAP_IP_TO_SRCLOC, \
addr, buf64, 0, 0, 0)
/* Disable error reporting for this thread. Behaves in a stack like
way, so you can safely call this multiple times provided that
VALGRIND_ENABLE_ERROR_REPORTING is called the same number of times
to re-enable reporting. The first call of this macro disables
reporting. Subsequent calls have no effect except to increase the
number of VALGRIND_ENABLE_ERROR_REPORTING calls needed to re-enable
reporting. Child threads do not inherit this setting from their
parents -- they are always created with reporting enabled. */
#define VALGRIND_DISABLE_ERROR_REPORTING \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
1, 0, 0, 0, 0)
/* Re-enable error reporting, as per comments on
VALGRIND_DISABLE_ERROR_REPORTING. */
#define VALGRIND_ENABLE_ERROR_REPORTING \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
-1, 0, 0, 0, 0)
/* Execute a monitor command from the client program.
If a connection is opened with GDB, the output will be sent
according to the output mode set for vgdb.
If no connection is opened, output will go to the log output.
Returns 1 if command not recognised, 0 otherwise. */
#define VALGRIND_MONITOR_COMMAND(command) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__GDB_MONITOR_COMMAND, \
command, 0, 0, 0, 0)
#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_x86_win32
#undef PLAT_amd64_win64
#undef PLAT_x86_linux
#undef PLAT_amd64_linux
#undef PLAT_ppc32_linux
#undef PLAT_ppc64be_linux
#undef PLAT_ppc64le_linux
#undef PLAT_arm_linux
#undef PLAT_s390x_linux
#undef PLAT_mips32_linux
#undef PLAT_mips64_linux
#undef PLAT_x86_solaris
#undef PLAT_amd64_solaris
#endif /* __VALGRIND_H */
| 391,825 | 57.938929 | 92 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind/drd.h | /*
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (drd.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of DRD, a Valgrind tool for verification of
multithreaded programs.
Copyright (C) 2006-2017 Bart Van Assche <[email protected]>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(drd.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
#ifndef __VALGRIND_DRD_H
#define __VALGRIND_DRD_H
#include "valgrind.h"
/** Obtain the thread ID assigned by Valgrind's core. */
#define DRD_GET_VALGRIND_THREADID \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID, \
0, 0, 0, 0, 0)
/** Obtain the thread ID assigned by DRD. */
#define DRD_GET_DRD_THREADID \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__DRD_GET_DRD_THREAD_ID, \
0, 0, 0, 0, 0)
/** Tell DRD not to complain about data races for the specified variable. */
#define DRD_IGNORE_VAR(x) ANNOTATE_BENIGN_RACE_SIZED(&(x), sizeof(x), "")
/** Tell DRD to no longer ignore data races for the specified variable. */
#define DRD_STOP_IGNORING_VAR(x) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_FINISH_SUPPRESSION, \
&(x), sizeof(x), 0, 0, 0)
/**
* Tell DRD to trace all memory accesses for the specified variable
* until the memory that was allocated for the variable is freed.
*/
#define DRD_TRACE_VAR(x) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_TRACE_ADDR, \
&(x), sizeof(x), 0, 0, 0)
/**
* Tell DRD to stop tracing memory accesses for the specified variable.
*/
#define DRD_STOP_TRACING_VAR(x) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_STOP_TRACE_ADDR, \
&(x), sizeof(x), 0, 0, 0)
/**
* @defgroup RaceDetectionAnnotations Data race detection annotations.
*
* @see See also the source file <a href="http://code.google.com/p/data-race-test/source/browse/trunk/dynamic_annotations/dynamic_annotations.h</a>
* in the ThreadSanitizer project.
*/
/*@{*/
#ifndef __HELGRIND_H
/**
* Tell DRD to insert a happens-before mark. addr is the address of an object
* that is not a pthread synchronization object.
*/
#define ANNOTATE_HAPPENS_BEFORE(addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE, \
addr, 0, 0, 0, 0)
/**
* Tell DRD that the memory accesses executed after this annotation will
* happen after all memory accesses performed before all preceding
* ANNOTATE_HAPPENS_BEFORE(addr). addr is the address of an object that is not
* a pthread synchronization object. Inserting a happens-after annotation
* before any other thread has passed by a happens-before annotation for the
* same address is an error.
*/
#define ANNOTATE_HAPPENS_AFTER(addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER, \
addr, 0, 0, 0, 0)
#else /* __HELGRIND_H */
#undef ANNOTATE_CONDVAR_LOCK_WAIT
#undef ANNOTATE_CONDVAR_WAIT
#undef ANNOTATE_CONDVAR_SIGNAL
#undef ANNOTATE_CONDVAR_SIGNAL_ALL
#undef ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX
#undef ANNOTATE_PUBLISH_MEMORY_RANGE
#undef ANNOTATE_BARRIER_INIT
#undef ANNOTATE_BARRIER_WAIT_BEFORE
#undef ANNOTATE_BARRIER_WAIT_AFTER
#undef ANNOTATE_BARRIER_DESTROY
#undef ANNOTATE_PCQ_CREATE
#undef ANNOTATE_PCQ_DESTROY
#undef ANNOTATE_PCQ_PUT
#undef ANNOTATE_PCQ_GET
#undef ANNOTATE_BENIGN_RACE
#undef ANNOTATE_BENIGN_RACE_SIZED
#undef ANNOTATE_IGNORE_READS_BEGIN
#undef ANNOTATE_IGNORE_READS_END
#undef ANNOTATE_IGNORE_WRITES_BEGIN
#undef ANNOTATE_IGNORE_WRITES_END
#undef ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN
#undef ANNOTATE_IGNORE_READS_AND_WRITES_END
#undef ANNOTATE_NEW_MEMORY
#undef ANNOTATE_TRACE_MEMORY
#undef ANNOTATE_THREAD_NAME
#endif /* __HELGRIND_H */
/**
* Tell DRD that waiting on the condition variable at address cv has succeeded
* and a lock on the mutex at address mtx is now held. Since DRD always inserts
* a happens before relation between the pthread_cond_signal() or
* pthread_cond_broadcast() call that wakes up a pthread_cond_wait() or
* pthread_cond_timedwait() call and the woken up thread, this macro has been
* defined such that it has no effect.
*/
#define ANNOTATE_CONDVAR_LOCK_WAIT(cv, mtx) do { } while(0)
/**
* Tell DRD that the condition variable at address cv is about to be signaled.
*/
#define ANNOTATE_CONDVAR_SIGNAL(cv) do { } while(0)
/**
* Tell DRD that the condition variable at address cv is about to be signaled.
*/
#define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) do { } while(0)
/**
* Tell DRD that waiting on condition variable at address cv succeeded and that
* the memory operations performed after this annotation should be considered
* to happen after the matching ANNOTATE_CONDVAR_SIGNAL(cv). Since this is the
* default behavior of DRD, this macro and the macro above have been defined
* such that they have no effect.
*/
#define ANNOTATE_CONDVAR_WAIT(cv) do { } while(0)
/**
* Tell DRD to consider the memory operations that happened before a mutex
* unlock event and after the subsequent mutex lock event on the same mutex as
* ordered. This is how DRD always behaves, so this macro has been defined
* such that it has no effect.
*/
#define ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(mtx) do { } while(0)
/** Deprecated -- don't use this annotation. */
#define ANNOTATE_MUTEX_IS_USED_AS_CONDVAR(mtx) do { } while(0)
/**
* Tell DRD to handle the specified memory range like a pure happens-before
* detector would do. Since this is how DRD always behaves, this annotation
* has been defined such that it has no effect.
*/
#define ANNOTATE_PUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
/** Deprecated -- don't use this annotation. */
#define ANNOTATE_UNPUBLISH_MEMORY_RANGE(addr, size) do { } while(0)
/** Deprecated -- don't use this annotation. */
#define ANNOTATE_SWAP_MEMORY_RANGE(addr, size) do { } while(0)
#ifndef __HELGRIND_H
/** Tell DRD that a reader-writer lock object has been initialized. */
#define ANNOTATE_RWLOCK_CREATE(rwlock) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE, \
rwlock, 0, 0, 0, 0);
/** Tell DRD that a reader-writer lock object has been destroyed. */
#define ANNOTATE_RWLOCK_DESTROY(rwlock) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY, \
rwlock, 0, 0, 0, 0);
/**
* Tell DRD that a reader-writer lock has been acquired. is_w == 1 means that
* a write lock has been obtained, is_w == 0 means that a read lock has been
* obtained.
*/
#define ANNOTATE_RWLOCK_ACQUIRED(rwlock, is_w) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED, \
rwlock, is_w, 0, 0, 0)
#endif /* __HELGRIND_H */
/**
* Tell DRD that a reader lock has been acquired on a reader-writer
* synchronization object.
*/
#define ANNOTATE_READERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 0)
/**
* Tell DRD that a writer lock has been acquired on a reader-writer
* synchronization object.
*/
#define ANNOTATE_WRITERLOCK_ACQUIRED(rwlock) ANNOTATE_RWLOCK_ACQUIRED(rwlock, 1)
#ifndef __HELGRIND_H
/**
* Tell DRD that a reader-writer lock is about to be released. is_w == 1 means
* that a write lock is about to be released, is_w == 0 means that a read lock
* is about to be released.
*/
#define ANNOTATE_RWLOCK_RELEASED(rwlock, is_w) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED, \
rwlock, is_w, 0, 0, 0);
#endif /* __HELGRIND_H */
/**
* Tell DRD that a reader lock is about to be released.
*/
#define ANNOTATE_READERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 0)
/**
* Tell DRD that a writer lock is about to be released.
*/
#define ANNOTATE_WRITERLOCK_RELEASED(rwlock) ANNOTATE_RWLOCK_RELEASED(rwlock, 1)
/** Tell DRD that a semaphore object is going to be initialized. */
#define ANNOTATE_SEM_INIT_PRE(sem, value) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE, \
sem, value, 0, 0, 0);
/** Tell DRD that a semaphore object has been destroyed. */
#define ANNOTATE_SEM_DESTROY_POST(sem) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST, \
sem, 0, 0, 0, 0);
/** Tell DRD that a semaphore is going to be acquired. */
#define ANNOTATE_SEM_WAIT_PRE(sem) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE, \
sem, 0, 0, 0, 0)
/** Tell DRD that a semaphore has been acquired. */
#define ANNOTATE_SEM_WAIT_POST(sem) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST, \
sem, 0, 0, 0, 0)
/** Tell DRD that a semaphore is going to be released. */
#define ANNOTATE_SEM_POST_PRE(sem) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE, \
sem, 0, 0, 0, 0)
/*
* Report that a barrier has been initialized with a given barrier count. The
* third argument specifies whether or not reinitialization is allowed, that
* is, whether or not it is allowed to call barrier_init() several times
* without calling barrier_destroy().
*/
#define ANNOTATE_BARRIER_INIT(barrier, count, reinitialization_allowed) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
"ANNOTATE_BARRIER_INIT", barrier, \
count, reinitialization_allowed, 0)
/* Report that a barrier has been destroyed. */
#define ANNOTATE_BARRIER_DESTROY(barrier) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
"ANNOTATE_BARRIER_DESTROY", \
barrier, 0, 0, 0)
/* Report that the calling thread is about to start waiting for a barrier. */
#define ANNOTATE_BARRIER_WAIT_BEFORE(barrier) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
"ANNOTATE_BARRIER_WAIT_BEFORE", \
barrier, 0, 0, 0)
/* Report that the calling thread has just finished waiting for a barrier. */
#define ANNOTATE_BARRIER_WAIT_AFTER(barrier) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_ANNOTATION_UNIMP, \
"ANNOTATE_BARRIER_WAIT_AFTER", \
barrier, 0, 0, 0)
/**
* Tell DRD that a FIFO queue has been created. The abbreviation PCQ stands for
* <em>producer-consumer</em>.
*/
#define ANNOTATE_PCQ_CREATE(pcq) do { } while(0)
/** Tell DRD that a FIFO queue has been destroyed. */
#define ANNOTATE_PCQ_DESTROY(pcq) do { } while(0)
/**
* Tell DRD that an element has been added to the FIFO queue at address pcq.
*/
#define ANNOTATE_PCQ_PUT(pcq) do { } while(0)
/**
* Tell DRD that an element has been removed from the FIFO queue at address pcq,
* and that DRD should insert a happens-before relationship between the memory
* accesses that occurred before the corresponding ANNOTATE_PCQ_PUT(pcq)
* annotation and the memory accesses after this annotation. Correspondence
* between PUT and GET annotations happens in FIFO order. Since locking
* of the queue is needed anyway to add elements to or to remove elements from
* the queue, for DRD all four FIFO annotations are defined as no-ops.
*/
#define ANNOTATE_PCQ_GET(pcq) do { } while(0)
/**
* Tell DRD that data races at the specified address are expected and must not
* be reported.
*/
#define ANNOTATE_BENIGN_RACE(addr, descr) \
ANNOTATE_BENIGN_RACE_SIZED(addr, sizeof(*addr), descr)
/* Same as ANNOTATE_BENIGN_RACE(addr, descr), but applies to
the memory range [addr, addr + size). */
#define ANNOTATE_BENIGN_RACE_SIZED(addr, size, descr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_SUPPRESSION, \
addr, size, 0, 0, 0)
/** Tell DRD to ignore all reads performed by the current thread. */
#define ANNOTATE_IGNORE_READS_BEGIN() \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
0, 0, 0, 0, 0);
/** Tell DRD to no longer ignore the reads performed by the current thread. */
#define ANNOTATE_IGNORE_READS_END() \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_LOADS, \
1, 0, 0, 0, 0);
/** Tell DRD to ignore all writes performed by the current thread. */
#define ANNOTATE_IGNORE_WRITES_BEGIN() \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
0, 0, 0, 0, 0)
/** Tell DRD to no longer ignore the writes performed by the current thread. */
#define ANNOTATE_IGNORE_WRITES_END() \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_RECORD_STORES, \
1, 0, 0, 0, 0)
/** Tell DRD to ignore all memory accesses performed by the current thread. */
#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
do { ANNOTATE_IGNORE_READS_BEGIN(); ANNOTATE_IGNORE_WRITES_BEGIN(); } while(0)
/**
* Tell DRD to no longer ignore the memory accesses performed by the current
* thread.
*/
#define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
do { ANNOTATE_IGNORE_READS_END(); ANNOTATE_IGNORE_WRITES_END(); } while(0)
/**
* Tell DRD that size bytes starting at addr has been allocated by a custom
* memory allocator.
*/
#define ANNOTATE_NEW_MEMORY(addr, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_CLEAN_MEMORY, \
addr, size, 0, 0, 0)
/** Ask DRD to report every access to the specified address. */
#define ANNOTATE_TRACE_MEMORY(addr) DRD_TRACE_VAR(*(char*)(addr))
/**
* Tell DRD to assign the specified name to the current thread. This name will
* be used in error messages printed by DRD.
*/
#define ANNOTATE_THREAD_NAME(name) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_SET_THREAD_NAME, \
name, 0, 0, 0, 0)
/*@}*/
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end.
*/
enum {
/* Ask the DRD tool to discard all information about memory accesses */
/* and client objects for the specified range. This client request is */
/* binary compatible with the similarly named Helgrind client request. */
VG_USERREQ__DRD_CLEAN_MEMORY = VG_USERREQ_TOOL_BASE('H','G'),
/* args: Addr, SizeT. */
/* Ask the DRD tool the thread ID assigned by Valgrind. */
VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID = VG_USERREQ_TOOL_BASE('D','R'),
/* args: none. */
/* Ask the DRD tool the thread ID assigned by DRD. */
VG_USERREQ__DRD_GET_DRD_THREAD_ID,
/* args: none. */
/* To tell the DRD tool to suppress data race detection on the */
/* specified address range. */
VG_USERREQ__DRD_START_SUPPRESSION,
/* args: start address, size in bytes */
/* To tell the DRD tool no longer to suppress data race detection on */
/* the specified address range. */
VG_USERREQ__DRD_FINISH_SUPPRESSION,
/* args: start address, size in bytes */
/* To ask the DRD tool to trace all accesses to the specified range. */
VG_USERREQ__DRD_START_TRACE_ADDR,
/* args: Addr, SizeT. */
/* To ask the DRD tool to stop tracing accesses to the specified range. */
VG_USERREQ__DRD_STOP_TRACE_ADDR,
/* args: Addr, SizeT. */
/* Tell DRD whether or not to record memory loads in the calling thread. */
VG_USERREQ__DRD_RECORD_LOADS,
/* args: Bool. */
/* Tell DRD whether or not to record memory stores in the calling thread. */
VG_USERREQ__DRD_RECORD_STORES,
/* args: Bool. */
/* Set the name of the thread that performs this client request. */
VG_USERREQ__DRD_SET_THREAD_NAME,
/* args: null-terminated character string. */
/* Tell DRD that a DRD annotation has not yet been implemented. */
VG_USERREQ__DRD_ANNOTATION_UNIMP,
/* args: char*. */
/* Tell DRD that a user-defined semaphore synchronization object
* is about to be created. */
VG_USERREQ__DRD_ANNOTATE_SEM_INIT_PRE,
/* args: Addr, UInt value. */
/* Tell DRD that a user-defined semaphore synchronization object
* has been destroyed. */
VG_USERREQ__DRD_ANNOTATE_SEM_DESTROY_POST,
/* args: Addr. */
/* Tell DRD that a user-defined semaphore synchronization
* object is going to be acquired (semaphore wait). */
VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_PRE,
/* args: Addr. */
/* Tell DRD that a user-defined semaphore synchronization
* object has been acquired (semaphore wait). */
VG_USERREQ__DRD_ANNOTATE_SEM_WAIT_POST,
/* args: Addr. */
/* Tell DRD that a user-defined semaphore synchronization
* object is about to be released (semaphore post). */
VG_USERREQ__DRD_ANNOTATE_SEM_POST_PRE,
/* args: Addr. */
/* Tell DRD to ignore the inter-thread ordering introduced by a mutex. */
VG_USERREQ__DRD_IGNORE_MUTEX_ORDERING,
/* args: Addr. */
/* Tell DRD that a user-defined reader-writer synchronization object
* has been created. */
VG_USERREQ__DRD_ANNOTATE_RWLOCK_CREATE
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 14,
/* args: Addr. */
/* Tell DRD that a user-defined reader-writer synchronization object
* is about to be destroyed. */
VG_USERREQ__DRD_ANNOTATE_RWLOCK_DESTROY
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 15,
/* args: Addr. */
/* Tell DRD that a lock on a user-defined reader-writer synchronization
* object has been acquired. */
VG_USERREQ__DRD_ANNOTATE_RWLOCK_ACQUIRED
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 17,
/* args: Addr, Int is_rw. */
/* Tell DRD that a lock on a user-defined reader-writer synchronization
* object is about to be released. */
VG_USERREQ__DRD_ANNOTATE_RWLOCK_RELEASED
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 18,
/* args: Addr, Int is_rw. */
/* Tell DRD that a Helgrind annotation has not yet been implemented. */
VG_USERREQ__HELGRIND_ANNOTATION_UNIMP
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 32,
/* args: char*. */
/* Tell DRD to insert a happens-before annotation. */
VG_USERREQ__DRD_ANNOTATE_HAPPENS_BEFORE
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 33,
/* args: Addr. */
/* Tell DRD to insert a happens-after annotation. */
VG_USERREQ__DRD_ANNOTATE_HAPPENS_AFTER
= VG_USERREQ_TOOL_BASE('H','G') + 256 + 34,
/* args: Addr. */
};
/**
* @addtogroup RaceDetectionAnnotations
*/
/*@{*/
#ifdef __cplusplus
/* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racy reads.
Instead of doing
ANNOTATE_IGNORE_READS_BEGIN();
... = x;
ANNOTATE_IGNORE_READS_END();
one can use
... = ANNOTATE_UNPROTECTED_READ(x); */
template <typename T>
inline T ANNOTATE_UNPROTECTED_READ(const volatile T& x) {
ANNOTATE_IGNORE_READS_BEGIN();
const T result = x;
ANNOTATE_IGNORE_READS_END();
return result;
}
/* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
#define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
namespace { \
static class static_var##_annotator \
{ \
public: \
static_var##_annotator() \
{ \
ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \
#static_var ": " description); \
} \
} the_##static_var##_annotator; \
}
#endif
/*@}*/
#endif /* __VALGRIND_DRD_H */
| 22,982 | 39.18007 | 147 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/core/valgrind/pmemcheck.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2015, Intel Corporation */
#ifndef __PMEMCHECK_H
#define __PMEMCHECK_H
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query memory permissions
inside your own programs.
See comment near the top of valgrind.h on how to use them.
*/
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end. */
typedef
enum {
VG_USERREQ__PMC_REGISTER_PMEM_MAPPING = VG_USERREQ_TOOL_BASE('P','C'),
VG_USERREQ__PMC_REGISTER_PMEM_FILE,
VG_USERREQ__PMC_REMOVE_PMEM_MAPPING,
VG_USERREQ__PMC_CHECK_IS_PMEM_MAPPING,
VG_USERREQ__PMC_PRINT_PMEM_MAPPINGS,
VG_USERREQ__PMC_DO_FLUSH,
VG_USERREQ__PMC_DO_FENCE,
VG_USERREQ__PMC_RESERVED1, /* Do not use. */
VG_USERREQ__PMC_WRITE_STATS,
VG_USERREQ__PMC_RESERVED2, /* Do not use. */
VG_USERREQ__PMC_RESERVED3, /* Do not use. */
VG_USERREQ__PMC_RESERVED4, /* Do not use. */
VG_USERREQ__PMC_RESERVED5, /* Do not use. */
VG_USERREQ__PMC_RESERVED7, /* Do not use. */
VG_USERREQ__PMC_RESERVED8, /* Do not use. */
VG_USERREQ__PMC_RESERVED9, /* Do not use. */
VG_USERREQ__PMC_RESERVED10, /* Do not use. */
VG_USERREQ__PMC_SET_CLEAN,
/* transaction support */
VG_USERREQ__PMC_START_TX,
VG_USERREQ__PMC_START_TX_N,
VG_USERREQ__PMC_END_TX,
VG_USERREQ__PMC_END_TX_N,
VG_USERREQ__PMC_ADD_TO_TX,
VG_USERREQ__PMC_ADD_TO_TX_N,
VG_USERREQ__PMC_REMOVE_FROM_TX,
VG_USERREQ__PMC_REMOVE_FROM_TX_N,
VG_USERREQ__PMC_ADD_THREAD_TO_TX_N,
VG_USERREQ__PMC_REMOVE_THREAD_FROM_TX_N,
VG_USERREQ__PMC_ADD_TO_GLOBAL_TX_IGNORE,
VG_USERREQ__PMC_RESERVED6, /* Do not use. */
VG_USERREQ__PMC_EMIT_LOG,
} Vg_PMemCheckClientRequest;
/* Client-code macros to manipulate pmem mappings */
/** Register a persistent memory mapping region */
#define VALGRIND_PMC_REGISTER_PMEM_MAPPING(_qzz_addr, _qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REGISTER_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register a persistent memory file */
#define VALGRIND_PMC_REGISTER_PMEM_FILE(_qzz_desc, _qzz_addr_base, \
_qzz_size, _qzz_offset) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REGISTER_PMEM_FILE, \
(_qzz_desc), (_qzz_addr_base), (_qzz_size), \
(_qzz_offset), 0)
/** Remove a persistent memory mapping region */
#define VALGRIND_PMC_REMOVE_PMEM_MAPPING(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Check if the given range is a registered persistent memory mapping */
#define VALGRIND_PMC_CHECK_IS_PMEM_MAPPING(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_CHECK_IS_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register an SFENCE */
#define VALGRIND_PMC_PRINT_PMEM_MAPPINGS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_PRINT_PMEM_MAPPINGS, \
0, 0, 0, 0, 0)
/** Register a CLFLUSH-like operation */
#define VALGRIND_PMC_DO_FLUSH(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_DO_FLUSH, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register an SFENCE */
#define VALGRIND_PMC_DO_FENCE \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_DO_FENCE, \
0, 0, 0, 0, 0)
/** Write tool stats */
#define VALGRIND_PMC_WRITE_STATS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_WRITE_STATS, \
0, 0, 0, 0, 0)
/** Emit user log */
#define VALGRIND_PMC_EMIT_LOG(_qzz_emit_log) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_EMIT_LOG, \
(_qzz_emit_log), 0, 0, 0, 0)
/** Set a region of persistent memory as clean */
#define VALGRIND_PMC_SET_CLEAN(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_SET_CLEAN, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Support for transactions */
/** Start an implicit persistent memory transaction */
#define VALGRIND_PMC_START_TX \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_START_TX, \
0, 0, 0, 0, 0)
/** Start an explicit persistent memory transaction */
#define VALGRIND_PMC_START_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_START_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** End an implicit persistent memory transaction */
#define VALGRIND_PMC_END_TX \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_END_TX, \
0, 0, 0, 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_END_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_END_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** Add a persistent memory region to the implicit transaction */
#define VALGRIND_PMC_ADD_TO_TX(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_TO_TX, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Add a persistent memory region to an explicit transaction */
#define VALGRIND_PMC_ADD_TO_TX_N(_qzz_txn,_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_TO_TX_N, \
(_qzz_txn), (_qzz_addr), (_qzz_len), 0, 0)
/** Remove a persistent memory region from the implicit transaction */
#define VALGRIND_PMC_REMOVE_FROM_TX(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_FROM_TX, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Remove a persistent memory region from an explicit transaction */
#define VALGRIND_PMC_REMOVE_FROM_TX_N(_qzz_txn,_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_FROM_TX_N, \
(_qzz_txn), (_qzz_addr), (_qzz_len), 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_ADD_THREAD_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_THREAD_TO_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_REMOVE_THREAD_FROM_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_THREAD_FROM_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** Remove a persistent memory region from the implicit transaction */
#define VALGRIND_PMC_ADD_TO_GLOBAL_TX_IGNORE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_ADD_TO_GLOBAL_TX_IGNORE,\
(_qzz_addr), (_qzz_len), 0, 0, 0)
#endif
| 9,085 | 47.588235 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/clo_vec.hpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* clo_vec.hpp -- command line options vector declarations
*/
#include "queue.h"
#include <cstdlib>
struct clo_vec_args {
PMDK_TAILQ_ENTRY(clo_vec_args) next;
void *args;
};
struct clo_vec_alloc {
PMDK_TAILQ_ENTRY(clo_vec_alloc) next;
void *ptr;
};
struct clo_vec_value {
PMDK_TAILQ_ENTRY(clo_vec_value) next;
void *ptr;
};
struct clo_vec_vlist {
PMDK_TAILQ_HEAD(valueshead, clo_vec_value) head;
size_t nvalues;
};
struct clo_vec {
size_t size;
PMDK_TAILQ_HEAD(argshead, clo_vec_args) args;
size_t nargs;
PMDK_TAILQ_HEAD(allochead, clo_vec_alloc) allocs;
size_t nallocs;
};
struct clo_vec *clo_vec_alloc(size_t size);
void clo_vec_free(struct clo_vec *clovec);
void *clo_vec_get_args(struct clo_vec *clovec, size_t i);
int clo_vec_add_alloc(struct clo_vec *clovec, void *ptr);
int clo_vec_memcpy(struct clo_vec *clovec, size_t off, size_t size, void *ptr);
int clo_vec_memcpy_list(struct clo_vec *clovec, size_t off, size_t size,
struct clo_vec_vlist *list);
struct clo_vec_vlist *clo_vec_vlist_alloc(void);
void clo_vec_vlist_free(struct clo_vec_vlist *list);
void clo_vec_vlist_add(struct clo_vec_vlist *list, void *ptr, size_t size);
| 1,249 | 25.595745 | 79 | hpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmem_flush.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2020, Intel Corporation */
/*
* pmem_flush.cpp -- benchmark implementation for pmem_persist and pmem_msync
*/
#include <cassert>
#include <cerrno>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <libpmem.h>
#include <sys/mman.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "file.h"
#define PAGE_4K ((uintptr_t)1 << 12)
#define PAGE_2M ((uintptr_t)1 << 21)
/*
* align_addr -- round addr down to given boundary
*/
static void *
align_addr(void *addr, uintptr_t align)
{
return (char *)((uintptr_t)addr & ~(align - 1));
}
/*
* align_len -- increase len by the amount we gain when we round addr down
*/
static size_t
align_len(size_t len, void *addr, uintptr_t align)
{
return len + ((uintptr_t)addr & (align - 1));
}
/*
* roundup_len -- increase len by the amount we gain when we round addr down,
* then round up to the nearest multiple of 4K
*/
static size_t
roundup_len(size_t len, void *addr, uintptr_t align)
{
return (align_len(len, addr, align) + align - 1) & ~(align - 1);
}
/*
* pmem_args -- benchmark specific arguments
*/
struct pmem_args {
char *operation; /* msync, dummy_msync, persist, ... */
char *mode; /* stat, seq, rand */
bool no_warmup; /* don't do warmup */
};
/*
* pmem_bench -- benchmark context
*/
struct pmem_bench {
uint64_t *offsets; /* write offsets */
size_t n_offsets; /* number of elements in offsets array */
size_t fsize; /* The size of the allocated PMEM */
struct pmem_args *pargs; /* prog_args structure */
void *pmem_addr; /* PMEM base address */
size_t pmem_len; /* length of PMEM mapping */
void *invalid_addr; /* invalid pages */
void *nondirty_addr; /* non-dirty pages */
void *pmem_addr_aligned; /* PMEM pages - 2M aligned */
void *invalid_addr_aligned; /* invalid pages - 2M aligned */
void *nondirty_addr_aligned; /* non-dirty pages - 2M aligned */
/* the actual benchmark operation */
int (*func_op)(struct pmem_bench *pmb, void *addr, size_t len);
};
/*
* mode_seq -- if copy mode is sequential, returns index of a chunk.
*/
static uint64_t
mode_seq(struct pmem_bench *pmb, uint64_t index)
{
return index;
}
/*
* mode_stat -- if mode is static, the offset is always 0
*/
static uint64_t
mode_stat(struct pmem_bench *pmb, uint64_t index)
{
return 0;
}
/*
* mode_rand -- if mode is random, returns index of a random chunk
*/
static uint64_t
mode_rand(struct pmem_bench *pmb, uint64_t index)
{
return rand() % pmb->n_offsets;
}
/*
* operation_mode -- the mode of the copy process
*
* * static - write always the same chunk,
* * sequential - write chunk by chunk,
* * random - write to chunks selected randomly.
*/
struct op_mode {
const char *mode;
uint64_t (*func_mode)(struct pmem_bench *pmb, uint64_t index);
};
static struct op_mode modes[] = {
{"stat", mode_stat},
{"seq", mode_seq},
{"rand", mode_rand},
};
#define MODES (sizeof(modes) / sizeof(modes[0]))
/*
* parse_op_mode -- parses command line "--mode"
* and returns proper operation mode index.
*/
static int
parse_op_mode(const char *arg)
{
for (unsigned i = 0; i < MODES; i++) {
if (strcmp(arg, modes[i].mode) == 0)
return i;
}
return -1;
}
/*
* flush_noop -- dummy flush, does nothing
*/
static int
flush_noop(struct pmem_bench *pmb, void *addr, size_t len)
{
return 0;
}
/*
* flush_persist -- flush data to persistence using pmem_persist()
*/
static int
flush_persist(struct pmem_bench *pmb, void *addr, size_t len)
{
pmem_persist(addr, len);
return 0;
}
/*
* flush_persist_4K -- always flush entire 4K page(s) using pmem_persist()
*/
static int
flush_persist_4K(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_4K);
len = roundup_len(len, addr, PAGE_4K);
pmem_persist(ptr, len);
return 0;
}
/*
* flush_persist_2M -- always flush entire 2M page(s) using pmem_persist()
*/
static int
flush_persist_2M(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_2M);
len = roundup_len(len, addr, PAGE_2M);
pmem_persist(ptr, len);
return 0;
}
/*
* flush_msync -- flush data to persistence using pmem_msync()
*/
static int
flush_msync(struct pmem_bench *pmb, void *addr, size_t len)
{
pmem_msync(addr, len);
return 0;
}
/*
* flush_msync_async -- emulate dummy msync() using MS_ASYNC flag
*/
static int
flush_msync_async(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_4K);
len = align_len(len, addr, PAGE_4K);
msync(ptr, len, MS_ASYNC);
return 0;
}
/*
* flush_msync_0 -- emulate dummy msync() using zero length
*/
static int
flush_msync_0(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_4K);
(void)len;
msync(ptr, 0, MS_SYNC);
return 0;
}
/*
* flush_persist_4K_msync_0 -- emulate msync() that only flushes CPU cache
*
* Do flushing in user space (4K pages) + dummy syscall.
*/
static int
flush_persist_4K_msync_0(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_4K);
len = roundup_len(len, addr, PAGE_4K);
pmem_persist(ptr, len);
msync(ptr, 0, MS_SYNC);
return 0;
}
/*
* flush_persist_2M_msync_0 -- emulate msync() that only flushes CPU cache
*
* Do flushing in user space (2M pages) + dummy syscall.
*/
static int
flush_persist_2M_msync_0(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_2M);
len = roundup_len(len, addr, PAGE_2M);
pmem_persist(ptr, len);
msync(ptr, 0, MS_SYNC);
return 0;
}
/*
* flush_msync_err -- emulate dummy msync() using invalid flags
*/
static int
flush_msync_err(struct pmem_bench *pmb, void *addr, size_t len)
{
void *ptr = align_addr(addr, PAGE_4K);
len = align_len(len, addr, PAGE_4K);
msync(ptr, len, MS_SYNC | MS_ASYNC);
return 0;
}
/*
* flush_msync_nodirty -- call msync() on non-dirty pages
*/
static int
flush_msync_nodirty(struct pmem_bench *pmb, void *addr, size_t len)
{
uintptr_t uptr = (uintptr_t)addr - (uintptr_t)pmb->pmem_addr_aligned;
uptr += (uintptr_t)pmb->nondirty_addr_aligned;
void *ptr = align_addr((void *)uptr, PAGE_4K);
len = align_len(len, (void *)uptr, PAGE_4K);
pmem_msync(ptr, len);
return 0;
}
/*
* flush_msync_invalid -- emulate dummy msync() using invalid address
*/
static int
flush_msync_invalid(struct pmem_bench *pmb, void *addr, size_t len)
{
uintptr_t uptr = (uintptr_t)addr - (uintptr_t)pmb->pmem_addr_aligned;
uptr += (uintptr_t)pmb->invalid_addr_aligned;
void *ptr = align_addr((void *)uptr, PAGE_4K);
len = align_len(len, (void *)uptr, PAGE_4K);
pmem_msync(ptr, len);
return 0;
}
struct op {
const char *opname;
int (*func_op)(struct pmem_bench *pmb, void *addr, size_t len);
};
static struct op ops[] = {
{"noop", flush_noop},
{"persist", flush_persist},
{"persist_4K", flush_persist_4K},
{"persist_2M", flush_persist_2M},
{"msync", flush_msync},
{"msync_0", flush_msync_0},
{"msync_err", flush_msync_err},
{"persist_4K_msync_0", flush_persist_4K_msync_0},
{"persist_2M_msync_0", flush_persist_2M_msync_0},
{"msync_async", flush_msync_async},
{"msync_nodirty", flush_msync_nodirty},
{"msync_invalid", flush_msync_invalid},
};
#define NOPS (sizeof(ops) / sizeof(ops[0]))
/*
* parse_op_type -- parses command line "--operation" argument
* and returns proper operation type.
*/
static int
parse_op_type(const char *arg)
{
for (unsigned i = 0; i < NOPS; i++) {
if (strcmp(arg, ops[i].opname) == 0)
return i;
}
return -1;
}
/*
* pmem_flush_init -- benchmark initialization
*
* Parses command line arguments, allocates persistent memory, and maps it.
*/
static int
pmem_flush_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
size_t file_size = 0;
int flags = 0;
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
uint64_t (*func_mode)(struct pmem_bench * pmb, uint64_t index);
auto *pmb = (struct pmem_bench *)malloc(sizeof(struct pmem_bench));
assert(pmb != nullptr);
pmb->pargs = (struct pmem_args *)args->opts;
assert(pmb->pargs != nullptr);
int i = parse_op_type(pmb->pargs->operation);
if (i == -1) {
fprintf(stderr, "wrong operation: %s\n", pmb->pargs->operation);
goto err_free_pmb;
}
pmb->func_op = ops[i].func_op;
pmb->n_offsets = args->n_ops_per_thread * args->n_threads;
pmb->fsize = pmb->n_offsets * args->dsize + (2 * PAGE_2M);
/* round up to 2M boundary */
pmb->fsize = (pmb->fsize + PAGE_2M - 1) & ~(PAGE_2M - 1);
i = parse_op_mode(pmb->pargs->mode);
if (i == -1) {
fprintf(stderr, "wrong mode: %s\n", pmb->pargs->mode);
goto err_free_pmb;
}
func_mode = modes[i].func_mode;
/* populate offsets array */
assert(pmb->n_offsets != 0);
pmb->offsets = (size_t *)malloc(pmb->n_offsets * sizeof(*pmb->offsets));
assert(pmb->offsets != nullptr);
for (size_t i = 0; i < pmb->n_offsets; ++i)
pmb->offsets[i] = func_mode(pmb, i);
if (type != TYPE_DEVDAX) {
file_size = pmb->fsize;
flags = PMEM_FILE_CREATE | PMEM_FILE_EXCL;
}
/* create a pmem file and memory map it */
pmb->pmem_addr = pmem_map_file(args->fname, file_size, flags,
args->fmode, &pmb->pmem_len, nullptr);
if (pmb->pmem_addr == nullptr) {
perror("pmem_map_file");
goto err_free_pmb;
}
pmb->nondirty_addr = mmap(nullptr, pmb->fsize, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (pmb->nondirty_addr == MAP_FAILED) {
perror("mmap(1)");
goto err_unmap1;
}
pmb->invalid_addr = mmap(nullptr, pmb->fsize, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (pmb->invalid_addr == MAP_FAILED) {
perror("mmap(2)");
goto err_unmap2;
}
munmap(pmb->invalid_addr, pmb->fsize);
pmb->pmem_addr_aligned =
(void *)(((uintptr_t)pmb->pmem_addr + PAGE_2M - 1) &
~(PAGE_2M - 1));
pmb->nondirty_addr_aligned =
(void *)(((uintptr_t)pmb->nondirty_addr + PAGE_2M - 1) &
~(PAGE_2M - 1));
pmb->invalid_addr_aligned =
(void *)(((uintptr_t)pmb->invalid_addr + PAGE_2M - 1) &
~(PAGE_2M - 1));
pmembench_set_priv(bench, pmb);
if (!pmb->pargs->no_warmup) {
size_t off;
for (off = 0; off < pmb->fsize - PAGE_2M; off += PAGE_4K) {
*(int *)((char *)pmb->pmem_addr_aligned + off) = 0;
*(int *)((char *)pmb->nondirty_addr_aligned + off) = 0;
}
}
return 0;
err_unmap2:
munmap(pmb->nondirty_addr, pmb->fsize);
err_unmap1:
pmem_unmap(pmb->pmem_addr, pmb->pmem_len);
err_free_pmb:
free(pmb);
return -1;
}
/*
* pmem_flush_exit -- benchmark cleanup
*/
static int
pmem_flush_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *pmb = (struct pmem_bench *)pmembench_get_priv(bench);
pmem_unmap(pmb->pmem_addr, pmb->fsize);
munmap(pmb->nondirty_addr, pmb->fsize);
free(pmb);
return 0;
}
/*
* pmem_flush_operation -- actual benchmark operation
*/
static int
pmem_flush_operation(struct benchmark *bench, struct operation_info *info)
{
auto *pmb = (struct pmem_bench *)pmembench_get_priv(bench);
size_t op_idx = info->index;
assert(op_idx < pmb->n_offsets);
uint64_t chunk_idx = pmb->offsets[op_idx];
void *addr =
(char *)pmb->pmem_addr_aligned + chunk_idx * info->args->dsize;
/* store + flush */
*(int *)addr = *(int *)addr + 1;
pmb->func_op(pmb, addr, info->args->dsize);
return 0;
}
/* structure to define command line arguments */
static struct benchmark_clo pmem_flush_clo[3];
/* Stores information about benchmark. */
static struct benchmark_info pmem_flush_bench;
CONSTRUCTOR(pmem_flush_constructor)
void
pmem_flush_constructor(void)
{
pmem_flush_clo[0].opt_short = 'o';
pmem_flush_clo[0].opt_long = "operation";
pmem_flush_clo[0].descr = "Operation type - persist,"
" msync, ...";
pmem_flush_clo[0].type = CLO_TYPE_STR;
pmem_flush_clo[0].off = clo_field_offset(struct pmem_args, operation);
pmem_flush_clo[0].def = "noop";
pmem_flush_clo[1].opt_short = 0;
pmem_flush_clo[1].opt_long = "mode";
pmem_flush_clo[1].descr = "mode - stat, seq or rand";
pmem_flush_clo[1].type = CLO_TYPE_STR;
pmem_flush_clo[1].off = clo_field_offset(struct pmem_args, mode);
pmem_flush_clo[1].def = "stat";
pmem_flush_clo[2].opt_short = 'w';
pmem_flush_clo[2].opt_long = "no-warmup";
pmem_flush_clo[2].descr = "Don't do warmup";
pmem_flush_clo[2].type = CLO_TYPE_FLAG;
pmem_flush_clo[2].off = clo_field_offset(struct pmem_args, no_warmup);
pmem_flush_bench.name = "pmem_flush";
pmem_flush_bench.brief = "Benchmark for pmem_msync() "
"and pmem_persist()";
pmem_flush_bench.init = pmem_flush_init;
pmem_flush_bench.exit = pmem_flush_exit;
pmem_flush_bench.multithread = true;
pmem_flush_bench.multiops = true;
pmem_flush_bench.operation = pmem_flush_operation;
pmem_flush_bench.measure_time = true;
pmem_flush_bench.clos = pmem_flush_clo;
pmem_flush_bench.nclos = ARRAY_SIZE(pmem_flush_clo);
pmem_flush_bench.opts_size = sizeof(struct pmem_args);
pmem_flush_bench.rm_file = true;
pmem_flush_bench.allow_poolset = false;
REGISTER_BENCHMARK(pmem_flush_bench);
}
| 13,147 | 23.303142 | 77 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmembench.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* pmembench.cpp -- main source file for benchmark framework
*/
#include <cassert>
#include <cerrno>
#include <cfloat>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <err.h>
#include <getopt.h>
#include <linux/limits.h>
#include <sched.h>
#include <sys/wait.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "benchmark_worker.hpp"
#include "clo.hpp"
#include "clo_vec.hpp"
#include "config_reader.hpp"
#include "file.h"
#include "libpmempool.h"
#include "mmap.h"
#include "os.h"
#include "os_thread.h"
#include "queue.h"
#include "scenario.hpp"
#include "set.h"
#include "util.h"
#ifndef _WIN32
#include "rpmem_common.h"
#include "rpmem_ssh.h"
#include "rpmem_util.h"
#endif
/* average time required to get a current time from the system */
unsigned long long Get_time_avg;
#define MIN_EXE_TIME_E 0.5
/*
* struct pmembench -- main context
*/
struct pmembench {
int argc;
char **argv;
struct scenario *scenario;
struct clo_vec *clovec;
bool override_clos;
};
/*
* struct benchmark -- benchmark's context
*/
struct benchmark {
PMDK_LIST_ENTRY(benchmark) next;
struct benchmark_info *info;
void *priv;
struct benchmark_clo *clos;
size_t nclos;
size_t args_size;
};
/*
* struct bench_list -- list of available benchmarks
*/
struct bench_list {
PMDK_LIST_HEAD(benchmarks_head, benchmark) head;
bool initialized;
};
/*
* struct benchmark_opts -- arguments for pmembench
*/
struct benchmark_opts {
bool help;
bool version;
const char *file_name;
};
static struct version_s {
unsigned major;
unsigned minor;
} version = {1, 0};
/* benchmarks list initialization */
static struct bench_list benchmarks;
/* common arguments for benchmarks */
static struct benchmark_clo pmembench_clos[13];
/* list of arguments for pmembench */
static struct benchmark_clo pmembench_opts[2];
CONSTRUCTOR(pmembench_constructor)
void
pmembench_constructor(void)
{
pmembench_opts[0].opt_short = 'h';
pmembench_opts[0].opt_long = "help";
pmembench_opts[0].descr = "Print help";
pmembench_opts[0].type = CLO_TYPE_FLAG;
pmembench_opts[0].off = clo_field_offset(struct benchmark_opts, help);
pmembench_opts[0].ignore_in_res = true;
pmembench_opts[1].opt_short = 'v';
pmembench_opts[1].opt_long = "version";
pmembench_opts[1].descr = "Print version";
pmembench_opts[1].type = CLO_TYPE_FLAG;
pmembench_opts[1].off =
clo_field_offset(struct benchmark_opts, version);
pmembench_opts[1].ignore_in_res = true;
pmembench_clos[0].opt_short = 'h';
pmembench_clos[0].opt_long = "help";
pmembench_clos[0].descr = "Print help for single benchmark";
pmembench_clos[0].type = CLO_TYPE_FLAG;
pmembench_clos[0].off = clo_field_offset(struct benchmark_args, help);
pmembench_clos[0].ignore_in_res = true;
pmembench_clos[1].opt_short = 't';
pmembench_clos[1].opt_long = "threads";
pmembench_clos[1].type = CLO_TYPE_UINT;
pmembench_clos[1].descr = "Number of working threads";
pmembench_clos[1].off =
clo_field_offset(struct benchmark_args, n_threads);
pmembench_clos[1].def = "1";
pmembench_clos[1].type_uint.size =
clo_field_size(struct benchmark_args, n_threads);
pmembench_clos[1].type_uint.base = CLO_INT_BASE_DEC;
pmembench_clos[1].type_uint.min = 1;
pmembench_clos[1].type_uint.max = UINT_MAX;
pmembench_clos[2].opt_short = 'n';
pmembench_clos[2].opt_long = "ops-per-thread";
pmembench_clos[2].type = CLO_TYPE_UINT;
pmembench_clos[2].descr = "Number of operations per thread";
pmembench_clos[2].off =
clo_field_offset(struct benchmark_args, n_ops_per_thread);
pmembench_clos[2].def = "1";
pmembench_clos[2].type_uint.size =
clo_field_size(struct benchmark_args, n_ops_per_thread);
pmembench_clos[2].type_uint.base = CLO_INT_BASE_DEC;
pmembench_clos[2].type_uint.min = 1;
pmembench_clos[2].type_uint.max = ULLONG_MAX;
pmembench_clos[3].opt_short = 'd';
pmembench_clos[3].opt_long = "data-size";
pmembench_clos[3].type = CLO_TYPE_UINT;
pmembench_clos[3].descr = "IO data size";
pmembench_clos[3].off = clo_field_offset(struct benchmark_args, dsize);
pmembench_clos[3].def = "1";
pmembench_clos[3].type_uint.size =
clo_field_size(struct benchmark_args, dsize);
pmembench_clos[3].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
pmembench_clos[3].type_uint.min = 1;
pmembench_clos[3].type_uint.max = ULONG_MAX;
pmembench_clos[4].opt_short = 'f';
pmembench_clos[4].opt_long = "file";
pmembench_clos[4].type = CLO_TYPE_STR;
pmembench_clos[4].descr = "File name";
pmembench_clos[4].off = clo_field_offset(struct benchmark_args, fname);
pmembench_clos[4].def = "/mnt/pmem/testfile";
pmembench_clos[4].ignore_in_res = true;
pmembench_clos[5].opt_short = 'm';
pmembench_clos[5].opt_long = "fmode";
pmembench_clos[5].type = CLO_TYPE_UINT;
pmembench_clos[5].descr = "File mode";
pmembench_clos[5].off = clo_field_offset(struct benchmark_args, fmode);
pmembench_clos[5].def = "0666";
pmembench_clos[5].ignore_in_res = true;
pmembench_clos[5].type_uint.size =
clo_field_size(struct benchmark_args, fmode);
pmembench_clos[5].type_uint.base = CLO_INT_BASE_OCT;
pmembench_clos[5].type_uint.min = 0;
pmembench_clos[5].type_uint.max = ULONG_MAX;
pmembench_clos[6].opt_short = 's';
pmembench_clos[6].opt_long = "seed";
pmembench_clos[6].type = CLO_TYPE_UINT;
pmembench_clos[6].descr = "PRNG seed";
pmembench_clos[6].off = clo_field_offset(struct benchmark_args, seed);
pmembench_clos[6].def = "0";
pmembench_clos[6].type_uint.size =
clo_field_size(struct benchmark_args, seed);
pmembench_clos[6].type_uint.base = CLO_INT_BASE_DEC;
pmembench_clos[6].type_uint.min = 0;
pmembench_clos[6].type_uint.max = ~0;
pmembench_clos[7].opt_short = 'r';
pmembench_clos[7].opt_long = "repeats";
pmembench_clos[7].type = CLO_TYPE_UINT;
pmembench_clos[7].descr = "Number of repeats of scenario";
pmembench_clos[7].off =
clo_field_offset(struct benchmark_args, repeats);
pmembench_clos[7].def = "1";
pmembench_clos[7].type_uint.size =
clo_field_size(struct benchmark_args, repeats);
pmembench_clos[7].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
pmembench_clos[7].type_uint.min = 1;
pmembench_clos[7].type_uint.max = ULONG_MAX;
pmembench_clos[8].opt_short = 'F';
pmembench_clos[8].opt_long = "thread-affinity";
pmembench_clos[8].descr = "Set worker threads CPU affinity mask";
pmembench_clos[8].type = CLO_TYPE_FLAG;
pmembench_clos[8].off =
clo_field_offset(struct benchmark_args, thread_affinity);
pmembench_clos[8].def = "false";
/*
* XXX: add link to blog post about optimal affinity
* when it will be done
*/
pmembench_clos[9].opt_short = 'I';
pmembench_clos[9].opt_long = "affinity-list";
pmembench_clos[9].descr =
"Set affinity mask as a list of CPUs separated by semicolon";
pmembench_clos[9].type = CLO_TYPE_STR;
pmembench_clos[9].off =
clo_field_offset(struct benchmark_args, affinity_list);
pmembench_clos[9].def = "";
pmembench_clos[9].ignore_in_res = true;
pmembench_clos[10].opt_long = "main-affinity";
pmembench_clos[10].descr = "Set affinity for main thread";
pmembench_clos[10].type = CLO_TYPE_INT;
pmembench_clos[10].off =
clo_field_offset(struct benchmark_args, main_affinity);
pmembench_clos[10].def = "-1";
pmembench_clos[10].ignore_in_res = false;
pmembench_clos[10].type_int.size =
clo_field_size(struct benchmark_args, main_affinity);
pmembench_clos[10].type_int.base = CLO_INT_BASE_DEC;
pmembench_clos[10].type_int.min = (-1);
pmembench_clos[10].type_int.max = LONG_MAX;
pmembench_clos[11].opt_short = 'e';
pmembench_clos[11].opt_long = "min-exe-time";
pmembench_clos[11].type = CLO_TYPE_UINT;
pmembench_clos[11].descr = "Minimal execution time in seconds";
pmembench_clos[11].off =
clo_field_offset(struct benchmark_args, min_exe_time);
pmembench_clos[11].def = "0";
pmembench_clos[11].type_uint.size =
clo_field_size(struct benchmark_args, min_exe_time);
pmembench_clos[11].type_uint.base = CLO_INT_BASE_DEC;
pmembench_clos[11].type_uint.min = 0;
pmembench_clos[11].type_uint.max = ULONG_MAX;
pmembench_clos[12].opt_short = 'p';
pmembench_clos[12].opt_long = "dynamic-poolset";
pmembench_clos[12].type = CLO_TYPE_FLAG;
pmembench_clos[12].descr =
"Allow benchmark to create poolset and reuse files";
pmembench_clos[12].off =
clo_field_offset(struct benchmark_args, is_dynamic_poolset);
pmembench_clos[12].ignore_in_res = true;
}
/*
* pmembench_get_priv -- return private structure of benchmark
*/
void *
pmembench_get_priv(struct benchmark *bench)
{
return bench->priv;
}
/*
* pmembench_set_priv -- set private structure of benchmark
*/
void
pmembench_set_priv(struct benchmark *bench, void *priv)
{
bench->priv = priv;
}
/*
* pmembench_register -- register benchmark
*/
int
pmembench_register(struct benchmark_info *bench_info)
{
assert(bench_info->name && bench_info->brief);
struct benchmark *bench = (struct benchmark *)calloc(1, sizeof(*bench));
assert(bench != nullptr);
bench->info = bench_info;
if (!benchmarks.initialized) {
PMDK_LIST_INIT(&benchmarks.head);
benchmarks.initialized = true;
}
PMDK_LIST_INSERT_HEAD(&benchmarks.head, bench, next);
return 0;
}
/*
* pmembench_get_info -- return structure with information about benchmark
*/
struct benchmark_info *
pmembench_get_info(struct benchmark *bench)
{
return bench->info;
}
/*
* pmembench_release_clos -- release CLO structure
*/
static void
pmembench_release_clos(struct benchmark *bench)
{
free(bench->clos);
}
/*
* pmembench_merge_clos -- merge benchmark's CLOs with common CLOs
*/
static void
pmembench_merge_clos(struct benchmark *bench)
{
size_t size = sizeof(struct benchmark_args);
size_t pb_nclos = ARRAY_SIZE(pmembench_clos);
size_t nclos = pb_nclos;
size_t i;
if (bench->info->clos) {
size += bench->info->opts_size;
nclos += bench->info->nclos;
}
auto *clos = (struct benchmark_clo *)calloc(
nclos, sizeof(struct benchmark_clo));
assert(clos != nullptr);
memcpy(clos, pmembench_clos, pb_nclos * sizeof(struct benchmark_clo));
if (bench->info->clos) {
memcpy(&clos[pb_nclos], bench->info->clos,
bench->info->nclos * sizeof(struct benchmark_clo));
for (i = 0; i < bench->info->nclos; i++) {
clos[pb_nclos + i].off += sizeof(struct benchmark_args);
}
}
bench->clos = clos;
bench->nclos = nclos;
bench->args_size = size;
}
/*
* pmembench_run_worker -- run worker with benchmark operation
*/
static int
pmembench_run_worker(struct benchmark *bench, struct worker_info *winfo)
{
benchmark_time_get(&winfo->beg);
for (size_t i = 0; i < winfo->nops; i++) {
if (bench->info->operation(bench, &winfo->opinfo[i]))
return -1;
benchmark_time_get(&winfo->opinfo[i].end);
}
benchmark_time_get(&winfo->end);
return 0;
}
/*
* pmembench_print_header -- print header of benchmark's results
*/
static void
pmembench_print_header(struct pmembench *pb, struct benchmark *bench,
struct clo_vec *clovec)
{
if (pb->scenario) {
printf("%s: %s [%" PRIu64 "]%s%s%s\n", pb->scenario->name,
bench->info->name, clovec->nargs,
pb->scenario->group ? " [group: " : "",
pb->scenario->group ? pb->scenario->group : "",
pb->scenario->group ? "]" : "");
} else {
printf("%s [%" PRIu64 "]\n", bench->info->name, clovec->nargs);
}
printf("total-avg[sec];"
"ops-per-second[1/sec];"
"total-max[sec];"
"total-min[sec];"
"total-median[sec];"
"total-std-dev[sec];"
"latency-avg[nsec];"
"latency-min[nsec];"
"latency-max[nsec];"
"latency-std-dev[nsec];"
"latency-pctl-50.0%%[nsec];"
"latency-pctl-99.0%%[nsec];"
"latency-pctl-99.9%%[nsec]");
size_t i;
for (i = 0; i < bench->nclos; i++) {
if (!bench->clos[i].ignore_in_res) {
printf(";%s", bench->clos[i].opt_long);
}
}
if (bench->info->print_bandwidth)
printf(";bandwidth[MiB/s]");
if (bench->info->print_extra_headers)
bench->info->print_extra_headers();
printf("\n");
}
/*
* pmembench_print_results -- print benchmark's results
*/
static void
pmembench_print_results(struct benchmark *bench, struct benchmark_args *args,
struct total_results *res)
{
printf("%f;%f;%f;%f;%f;%f;%" PRIu64 ";%" PRIu64 ";%" PRIu64
";%f;%" PRIu64 ";%" PRIu64 ";%" PRIu64,
res->total.avg, res->nopsps, res->total.max, res->total.min,
res->total.med, res->total.std_dev, res->latency.avg,
res->latency.min, res->latency.max, res->latency.std_dev,
res->latency.pctl50_0p, res->latency.pctl99_0p,
res->latency.pctl99_9p);
size_t i;
for (i = 0; i < bench->nclos; i++) {
if (!bench->clos[i].ignore_in_res)
printf(";%s",
benchmark_clo_str(&bench->clos[i], args,
bench->args_size));
}
if (bench->info->print_bandwidth)
printf(";%f", res->nopsps * args->dsize / 1024 / 1024);
if (bench->info->print_extra_values)
bench->info->print_extra_values(bench, args, res);
printf("\n");
}
/*
* pmembench_parse_clos -- parse command line arguments for benchmark
*/
static int
pmembench_parse_clo(struct pmembench *pb, struct benchmark *bench,
struct clo_vec *clovec)
{
if (!pb->scenario) {
return benchmark_clo_parse(pb->argc, pb->argv, bench->clos,
bench->nclos, clovec);
}
if (pb->override_clos) {
/*
* Use only ARRAY_SIZE(pmembench_clos) clos - these are the
* general clos and are placed at the beginning of the
* clos array.
*/
int ret = benchmark_override_clos_in_scenario(
pb->scenario, pb->argc, pb->argv, bench->clos,
ARRAY_SIZE(pmembench_clos));
/* reset for the next benchmark in the config file */
optind = 1;
if (ret)
return ret;
}
return benchmark_clo_parse_scenario(pb->scenario, bench->clos,
bench->nclos, clovec);
}
/*
* pmembench_parse_affinity -- parse affinity list
*/
static int
pmembench_parse_affinity(const char *list, char **saveptr)
{
char *str = nullptr;
char *end;
int cpu = 0;
if (*saveptr) {
str = strtok(nullptr, ";");
if (str == nullptr) {
/* end of list - we have to start over */
free(*saveptr);
*saveptr = nullptr;
}
}
if (!*saveptr) {
*saveptr = strdup(list);
if (*saveptr == nullptr) {
perror("strdup");
return -1;
}
str = strtok(*saveptr, ";");
if (str == nullptr)
goto err;
}
if ((str == nullptr) || (*str == '\0'))
goto err;
cpu = strtol(str, &end, 10);
if (*end != '\0')
goto err;
return cpu;
err:
errno = EINVAL;
perror("pmembench_parse_affinity");
free(*saveptr);
*saveptr = nullptr;
return -1;
}
/*
* pmembench_init_workers -- init benchmark's workers
*/
static int
pmembench_init_workers(struct benchmark_worker **workers,
struct benchmark *bench, struct benchmark_args *args)
{
unsigned i;
int ncpus = 0;
char *saveptr = nullptr;
int ret = 0;
if (args->thread_affinity) {
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
if (ncpus <= 0)
return -1;
}
for (i = 0; i < args->n_threads; i++) {
workers[i] = benchmark_worker_alloc();
if (args->thread_affinity) {
int cpu;
os_cpu_set_t cpuset;
if (args->affinity_list &&
*args->affinity_list != '\0') {
cpu = pmembench_parse_affinity(
args->affinity_list, &saveptr);
if (cpu == -1) {
ret = -1;
goto end;
}
} else {
cpu = (int)i;
}
assert(ncpus > 0);
cpu %= ncpus;
os_cpu_zero(&cpuset);
os_cpu_set(cpu, &cpuset);
errno = os_thread_setaffinity_np(&workers[i]->thread,
sizeof(os_cpu_set_t),
&cpuset);
if (errno) {
perror("os_thread_setaffinity_np");
ret = -1;
goto end;
}
}
workers[i]->info.index = i;
workers[i]->info.nops = args->n_ops_per_thread;
workers[i]->info.opinfo = (struct operation_info *)calloc(
args->n_ops_per_thread, sizeof(struct operation_info));
size_t j;
for (j = 0; j < args->n_ops_per_thread; j++) {
workers[i]->info.opinfo[j].worker = &workers[i]->info;
workers[i]->info.opinfo[j].args = args;
workers[i]->info.opinfo[j].index = j;
}
workers[i]->bench = bench;
workers[i]->args = args;
workers[i]->func = pmembench_run_worker;
workers[i]->init = bench->info->init_worker;
workers[i]->exit = bench->info->free_worker;
if (benchmark_worker_init(workers[i])) {
fprintf(stderr,
"thread number %u initialization failed\n", i);
ret = -1;
goto end;
}
}
end:
free(saveptr);
return ret;
}
/*
* results_store -- store results of a single repeat
*/
static void
results_store(struct bench_results *res, struct benchmark_worker **workers,
unsigned nthreads, size_t nops)
{
for (unsigned i = 0; i < nthreads; i++) {
res->thres[i]->beg = workers[i]->info.beg;
res->thres[i]->end = workers[i]->info.end;
for (size_t j = 0; j < nops; j++) {
res->thres[i]->end_op[j] =
workers[i]->info.opinfo[j].end;
}
}
}
/*
* compare_time -- compare time values
*/
static int
compare_time(const void *p1, const void *p2)
{
const auto *t1 = (const benchmark_time_t *)p1;
const auto *t2 = (const benchmark_time_t *)p2;
return benchmark_time_compare(t1, t2);
}
/*
* compare_doubles -- comparing function used for sorting
*/
static int
compare_doubles(const void *a1, const void *b1)
{
const auto *a = (const double *)a1;
const auto *b = (const double *)b1;
return (*a > *b) - (*a < *b);
}
/*
* compare_uint64t -- comparing function used for sorting
*/
static int
compare_uint64t(const void *a1, const void *b1)
{
const auto *a = (const uint64_t *)a1;
const auto *b = (const uint64_t *)b1;
return (*a > *b) - (*a < *b);
}
/*
* results_alloc -- prepare structure to store all benchmark results
*/
static struct total_results *
results_alloc(struct benchmark_args *args)
{
struct total_results *total =
(struct total_results *)malloc(sizeof(*total));
assert(total != nullptr);
total->nrepeats = args->repeats;
total->nthreads = args->n_threads;
total->nops = args->n_ops_per_thread;
total->res = (struct bench_results *)malloc(args->repeats *
sizeof(*total->res));
assert(total->res != nullptr);
for (size_t i = 0; i < args->repeats; i++) {
struct bench_results *res = &total->res[i];
assert(args->n_threads != 0);
res->thres = (struct thread_results **)malloc(
args->n_threads * sizeof(*res->thres));
assert(res->thres != nullptr);
for (size_t j = 0; j < args->n_threads; j++) {
res->thres[j] = (struct thread_results *)malloc(
sizeof(*res->thres[j]) +
args->n_ops_per_thread *
sizeof(benchmark_time_t));
assert(res->thres[j] != nullptr);
}
}
return total;
}
/*
* results_free -- release results structure
*/
static void
results_free(struct total_results *total)
{
for (size_t i = 0; i < total->nrepeats; i++) {
for (size_t j = 0; j < total->nthreads; j++)
free(total->res[i].thres[j]);
free(total->res[i].thres);
}
free(total->res);
free(total);
}
/*
* get_total_results -- return results of all repeats of scenario
*/
static void
get_total_results(struct total_results *tres)
{
assert(tres->nrepeats != 0);
assert(tres->nthreads != 0);
assert(tres->nops != 0);
/* reset results */
memset(&tres->total, 0, sizeof(tres->total));
memset(&tres->latency, 0, sizeof(tres->latency));
tres->total.min = DBL_MAX;
tres->total.max = DBL_MIN;
tres->latency.min = UINT64_MAX;
tres->latency.max = 0;
/* allocate helper arrays */
benchmark_time_t *tbeg =
(benchmark_time_t *)malloc(tres->nthreads * sizeof(*tbeg));
assert(tbeg != nullptr);
benchmark_time_t *tend =
(benchmark_time_t *)malloc(tres->nthreads * sizeof(*tend));
assert(tend != nullptr);
auto *totals = (double *)malloc(tres->nrepeats * sizeof(double));
assert(totals != nullptr);
/* estimate total penalty of getting time from the system */
benchmark_time_t Tget;
unsigned long long nsecs = tres->nops * Get_time_avg;
benchmark_time_set(&Tget, nsecs);
for (size_t i = 0; i < tres->nrepeats; i++) {
struct bench_results *res = &tres->res[i];
/* get start and end timestamps of each worker */
for (size_t j = 0; j < tres->nthreads; j++) {
tbeg[j] = res->thres[j]->beg;
tend[j] = res->thres[j]->end;
}
/* sort start and end timestamps */
qsort(tbeg, tres->nthreads, sizeof(benchmark_time_t),
compare_time);
qsort(tend, tres->nthreads, sizeof(benchmark_time_t),
compare_time);
/* calculating time interval between start and end time */
benchmark_time_t Tbeg = tbeg[0];
benchmark_time_t Tend = tend[tres->nthreads - 1];
benchmark_time_t Ttot_ove;
benchmark_time_diff(&Ttot_ove, &Tbeg, &Tend);
/*
* subtract time used for getting the current time from the
* system
*/
benchmark_time_t Ttot;
benchmark_time_diff(&Ttot, &Tget, &Ttot_ove);
double Stot = benchmark_time_get_secs(&Ttot);
if (Stot > tres->total.max)
tres->total.max = Stot;
if (Stot < tres->total.min)
tres->total.min = Stot;
tres->total.avg += Stot;
totals[i] = Stot;
}
/* median */
qsort(totals, tres->nrepeats, sizeof(double), compare_doubles);
if (tres->nrepeats % 2) {
tres->total.med = totals[tres->nrepeats / 2];
} else {
double m1 = totals[tres->nrepeats / 2];
double m2 = totals[tres->nrepeats / 2 - 1];
tres->total.med = (m1 + m2) / 2.0;
}
/* total average time */
tres->total.avg /= (double)tres->nrepeats;
/* number of operations per second */
tres->nopsps =
(double)tres->nops * (double)tres->nthreads / tres->total.avg;
/* std deviation of total time */
for (size_t i = 0; i < tres->nrepeats; i++) {
double dev = (totals[i] - tres->total.avg);
dev *= dev;
tres->total.std_dev += dev;
}
tres->total.std_dev = sqrt(tres->total.std_dev / tres->nrepeats);
/* latency */
for (size_t i = 0; i < tres->nrepeats; i++) {
struct bench_results *res = &tres->res[i];
for (size_t j = 0; j < tres->nthreads; j++) {
struct thread_results *thres = res->thres[j];
benchmark_time_t *beg = &thres->beg;
for (size_t o = 0; o < tres->nops; o++) {
benchmark_time_t lat;
benchmark_time_diff(&lat, beg,
&thres->end_op[o]);
uint64_t nsecs = benchmark_time_get_nsecs(&lat);
/* min, max latency */
if (nsecs > tres->latency.max)
tres->latency.max = nsecs;
if (nsecs < tres->latency.min)
tres->latency.min = nsecs;
tres->latency.avg += nsecs;
beg = &thres->end_op[o];
}
}
}
/* average latency */
size_t count = tres->nrepeats * tres->nthreads * tres->nops;
assert(count > 0);
tres->latency.avg /= count;
auto *ntotals = (uint64_t *)calloc(count, sizeof(uint64_t));
assert(ntotals != nullptr);
count = 0;
/* std deviation of latency and percentiles */
for (size_t i = 0; i < tres->nrepeats; i++) {
struct bench_results *res = &tres->res[i];
for (size_t j = 0; j < tres->nthreads; j++) {
struct thread_results *thres = res->thres[j];
benchmark_time_t *beg = &thres->beg;
for (size_t o = 0; o < tres->nops; o++) {
benchmark_time_t lat;
benchmark_time_diff(&lat, beg,
&thres->end_op[o]);
uint64_t nsecs = benchmark_time_get_nsecs(&lat);
uint64_t dev = (nsecs - tres->latency.avg);
dev *= dev;
tres->latency.std_dev += dev;
beg = &thres->end_op[o];
ntotals[count] = nsecs;
++count;
}
}
}
tres->latency.std_dev = sqrt(tres->latency.std_dev / count);
/* find 50%, 99.0% and 99.9% percentiles */
qsort(ntotals, count, sizeof(uint64_t), compare_uint64t);
uint64_t p50_0 = count * 50 / 100;
uint64_t p99_0 = count * 99 / 100;
uint64_t p99_9 = count * 999 / 1000;
tres->latency.pctl50_0p = ntotals[p50_0];
tres->latency.pctl99_0p = ntotals[p99_0];
tres->latency.pctl99_9p = ntotals[p99_9];
free(ntotals);
free(totals);
free(tend);
free(tbeg);
}
/*
* pmembench_print_args -- print arguments for one benchmark
*/
static void
pmembench_print_args(struct benchmark_clo *clos, size_t nclos)
{
struct benchmark_clo clo;
for (size_t i = 0; i < nclos; i++) {
clo = clos[i];
if (clo.opt_short != 0)
printf("\t-%c,", clo.opt_short);
else
printf("\t");
printf("\t--%-15s\t\t%s", clo.opt_long, clo.descr);
if (clo.type != CLO_TYPE_FLAG)
printf(" [default: %s]", clo.def);
if (clo.type == CLO_TYPE_INT) {
if (clo.type_int.min != LONG_MIN)
printf(" [min: %" PRId64 "]", clo.type_int.min);
if (clo.type_int.max != LONG_MAX)
printf(" [max: %" PRId64 "]", clo.type_int.max);
} else if (clo.type == CLO_TYPE_UINT) {
if (clo.type_uint.min != 0)
printf(" [min: %" PRIu64 "]",
clo.type_uint.min);
if (clo.type_uint.max != ULONG_MAX)
printf(" [max: %" PRIu64 "]",
clo.type_uint.max);
}
printf("\n");
}
}
/*
* pmembench_print_help_single -- prints help for single benchmark
*/
static void
pmembench_print_help_single(struct benchmark *bench)
{
struct benchmark_info *info = bench->info;
printf("%s\n%s\n", info->name, info->brief);
printf("\nArguments:\n");
size_t nclos = sizeof(pmembench_clos) / sizeof(struct benchmark_clo);
pmembench_print_args(pmembench_clos, nclos);
if (info->clos == nullptr)
return;
pmembench_print_args(info->clos, info->nclos);
}
/*
* pmembench_print_usage -- print usage of framework
*/
static void
pmembench_print_usage()
{
printf("Usage: $ pmembench [-h|--help] [-v|--version]"
"\t[<benchmark>[<args>]]\n");
printf("\t\t\t\t\t\t[<config>[<scenario>]]\n");
printf("\t\t\t\t\t\t[<config>[<scenario>[<common_args>]]]\n");
}
/*
* pmembench_print_version -- print version of framework
*/
static void
pmembench_print_version()
{
printf("Benchmark framework - version %u.%u\n", version.major,
version.minor);
}
/*
* pmembench_print_examples() -- print examples of using framework
*/
static void
pmembench_print_examples()
{
printf("\nExamples:\n");
printf("$ pmembench <benchmark_name> <args>\n");
printf(" # runs benchmark of name <benchmark> with arguments <args>\n");
printf("or\n");
printf("$ pmembench <config_file>\n");
printf(" # runs all scenarios from config file\n");
printf("or\n");
printf("$ pmembench [<benchmark_name>] [-h|--help [-v|--version]\n");
printf(" # prints help\n");
printf("or\n");
printf("$ pmembench <config_file> <name_of_scenario>\n");
printf(" # runs the specified scenario from config file\n");
printf("$ pmembench <config_file> <name_of_scenario_1> "
"<name_of_scenario_2> <common_args>\n");
printf(" # runs the specified scenarios from config file and overwrites"
" the given common_args from the config file\n");
}
/*
* pmembench_print_help -- print help for framework
*/
static void
pmembench_print_help()
{
pmembench_print_version();
pmembench_print_usage();
printf("\nCommon arguments:\n");
size_t nclos = sizeof(pmembench_opts) / sizeof(struct benchmark_clo);
pmembench_print_args(pmembench_opts, nclos);
printf("\nAvaliable benchmarks:\n");
struct benchmark *bench = nullptr;
PMDK_LIST_FOREACH(bench, &benchmarks.head, next)
printf("\t%-20s\t\t%s\n", bench->info->name, bench->info->brief);
printf("\n$ pmembench <benchmark> --help to print detailed information"
" about benchmark arguments\n");
pmembench_print_examples();
}
/*
* pmembench_get_bench -- searching benchmarks by name
*/
static struct benchmark *
pmembench_get_bench(const char *name)
{
struct benchmark *bench;
PMDK_LIST_FOREACH(bench, &benchmarks.head, next)
{
if (strcmp(name, bench->info->name) == 0)
return bench;
}
return nullptr;
}
/*
* pmembench_parse_opts -- parse arguments for framework
*/
static int
pmembench_parse_opts(struct pmembench *pb)
{
int ret = 0;
int argc = ++pb->argc;
char **argv = --pb->argv;
struct benchmark_opts *opts = nullptr;
struct clo_vec *clovec;
size_t size, n_clos;
size = sizeof(struct benchmark_opts);
n_clos = ARRAY_SIZE(pmembench_opts);
clovec = clo_vec_alloc(size);
assert(clovec != nullptr);
if (benchmark_clo_parse(argc, argv, pmembench_opts, n_clos, clovec)) {
ret = -1;
goto out;
}
opts = (struct benchmark_opts *)clo_vec_get_args(clovec, 0);
if (opts == nullptr) {
ret = -1;
goto out;
}
if (opts->help)
pmembench_print_help();
if (opts->version)
pmembench_print_version();
out:
clo_vec_free(clovec);
return ret;
}
/*
* pmembench_remove_file -- remove file or directory if exists
*/
static int
pmembench_remove_file(const char *path)
{
int ret = 0;
os_stat_t status;
char *tmp;
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists)
return 0;
if (os_stat(path, &status) != 0)
return 0;
if (!(status.st_mode & S_IFDIR))
return pmempool_rm(path, 0);
struct dir_handle it;
struct file_info info;
if (util_file_dir_open(&it, path)) {
return -1;
}
while (util_file_dir_next(&it, &info) == 0) {
if (strcmp(info.filename, ".") == 0 ||
strcmp(info.filename, "..") == 0)
continue;
tmp = (char *)malloc(strlen(path) + strlen(info.filename) + 2);
if (tmp == nullptr)
return -1;
sprintf(tmp, "%s" OS_DIR_SEP_STR "%s", path, info.filename);
ret = info.is_dir ? pmembench_remove_file(tmp)
: util_unlink(tmp);
free(tmp);
if (ret != 0) {
util_file_dir_close(&it);
return ret;
}
}
util_file_dir_close(&it);
return util_file_dir_remove(path);
}
/*
* pmembench_single_repeat -- runs benchmark ones
*/
static int
pmembench_single_repeat(struct benchmark *bench, struct benchmark_args *args,
struct bench_results *res)
{
int ret = 0;
if (args->main_affinity != -1) {
os_cpu_set_t cpuset;
os_cpu_zero(&cpuset);
os_thread_t self;
os_thread_self(&self);
os_cpu_set(args->main_affinity, &cpuset);
errno = os_thread_setaffinity_np(&self, sizeof(os_cpu_set_t),
&cpuset);
if (errno) {
perror("os_thread_setaffinity_np");
return -1;
}
sched_yield();
}
if (bench->info->rm_file && !args->is_dynamic_poolset) {
ret = pmembench_remove_file(args->fname);
if (ret != 0 && errno != ENOENT) {
perror("removing file failed");
return ret;
}
}
if (bench->info->init) {
if (bench->info->init(bench, args)) {
warn("%s: initialization failed", bench->info->name);
return -1;
}
}
assert(bench->info->operation != nullptr);
assert(args->n_threads != 0);
struct benchmark_worker **workers;
workers = (struct benchmark_worker **)malloc(
args->n_threads * sizeof(struct benchmark_worker *));
assert(workers != nullptr);
if ((ret = pmembench_init_workers(workers, bench, args)) != 0) {
goto out;
}
unsigned j;
for (j = 0; j < args->n_threads; j++) {
benchmark_worker_run(workers[j]);
}
for (j = 0; j < args->n_threads; j++) {
benchmark_worker_join(workers[j]);
if (workers[j]->ret != 0) {
ret = workers[j]->ret;
fprintf(stderr, "thread number %u failed\n", j);
}
}
results_store(res, workers, args->n_threads, args->n_ops_per_thread);
for (j = 0; j < args->n_threads; j++) {
benchmark_worker_exit(workers[j]);
free(workers[j]->info.opinfo);
benchmark_worker_free(workers[j]);
}
out:
free(workers);
if (bench->info->exit)
bench->info->exit(bench, args);
return ret;
}
/*
* scale_up_min_exe_time -- scale up the number of operations to obtain an
* execution time not smaller than the assumed minimal execution time
*/
int
scale_up_min_exe_time(struct benchmark *bench, struct benchmark_args *args,
struct total_results **total_results)
{
const double min_exe_time = args->min_exe_time;
struct total_results *total_res = *total_results;
total_res->nrepeats = 1;
do {
/*
* run single benchmark repeat to probe execution time
*/
int ret = pmembench_single_repeat(bench, args,
&total_res->res[0]);
if (ret != 0)
return 1;
get_total_results(total_res);
if (min_exe_time < total_res->total.min + MIN_EXE_TIME_E)
break;
/*
* scale up number of operations to get assumed minimal
* execution time
*/
args->n_ops_per_thread = (size_t)(
(double)args->n_ops_per_thread *
(min_exe_time + MIN_EXE_TIME_E) / total_res->total.min);
results_free(total_res);
*total_results = results_alloc(args);
assert(*total_results != nullptr);
total_res = *total_results;
total_res->nrepeats = 1;
} while (1);
total_res->nrepeats = args->repeats;
return 0;
}
/*
* is_absolute_path_to_directory -- checks if passed argument is absolute
* path to directory
*/
static bool
is_absolute_path_to_directory(const char *path)
{
os_stat_t sb;
return util_is_absolute_path(path) && os_stat(path, &sb) == 0 &&
S_ISDIR(sb.st_mode);
}
/*
* pmembench_run -- runs one benchmark. Parses arguments and performs
* specific functions.
*/
static int
pmembench_run(struct pmembench *pb, struct benchmark *bench)
{
enum file_type type;
char old_wd[PATH_MAX];
int ret = 0;
struct benchmark_args *args = nullptr;
struct total_results *total_res = nullptr;
struct latency *stats = nullptr;
double *workers_times = nullptr;
struct clo_vec *clovec = nullptr;
assert(bench->info != nullptr);
pmembench_merge_clos(bench);
/*
* Check if PMEMBENCH_DIR env var is set and change
* the working directory accordingly.
*/
char *wd = os_getenv("PMEMBENCH_DIR");
if (wd != nullptr) {
/* get current dir name */
if (getcwd(old_wd, PATH_MAX) == nullptr) {
perror("getcwd");
ret = -1;
goto out_release_clos;
}
os_stat_t stat_buf;
if (os_stat(wd, &stat_buf) != 0) {
perror("os_stat");
ret = -1;
goto out_release_clos;
}
if (!S_ISDIR(stat_buf.st_mode)) {
warn("PMEMBENCH_DIR is not a directory: %s", wd);
ret = -1;
goto out_release_clos;
}
if (chdir(wd)) {
perror("chdir(wd)");
ret = -1;
goto out_release_clos;
}
}
if (bench->info->pre_init) {
if (bench->info->pre_init(bench)) {
warn("%s: pre-init failed", bench->info->name);
ret = -1;
goto out_old_wd;
}
}
clovec = clo_vec_alloc(bench->args_size);
assert(clovec != nullptr);
if (pmembench_parse_clo(pb, bench, clovec)) {
warn("%s: parsing command line arguments failed",
bench->info->name);
ret = -1;
goto out_release_args;
}
args = (struct benchmark_args *)clo_vec_get_args(clovec, 0);
if (args == nullptr) {
warn("%s: parsing command line arguments failed",
bench->info->name);
ret = -1;
goto out_release_args;
}
if (args->help) {
pmembench_print_help_single(bench);
goto out;
}
if (strlen(args->fname) > PATH_MAX) {
warn("Filename too long");
ret = -1;
goto out;
}
type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
pmembench_print_header(pb, bench, clovec);
size_t args_i;
for (args_i = 0; args_i < clovec->nargs; args_i++) {
args = (struct benchmark_args *)clo_vec_get_args(clovec,
args_i);
if (args == nullptr) {
warn("%s: parsing command line arguments failed",
bench->info->name);
ret = -1;
goto out;
}
args->opts = (void *)((uintptr_t)args +
sizeof(struct benchmark_args));
if (args->is_dynamic_poolset) {
if (!bench->info->allow_poolset) {
fprintf(stderr,
"dynamic poolset not supported\n");
goto out;
}
if (!is_absolute_path_to_directory(args->fname)) {
fprintf(stderr,
"path must be absolute and point to a directory\n");
goto out;
}
} else {
args->is_poolset =
util_is_poolset_file(args->fname) == 1;
if (args->is_poolset) {
if (!bench->info->allow_poolset) {
fprintf(stderr,
"poolset files not supported\n");
goto out;
}
args->fsize = util_poolset_size(args->fname);
if (!args->fsize) {
fprintf(stderr,
"invalid size of poolset\n");
goto out;
}
} else if (type == TYPE_DEVDAX) {
args->fsize = util_file_get_size(args->fname);
if (!args->fsize) {
fprintf(stderr,
"invalid size of device dax\n");
goto out;
}
}
}
unsigned n_threads_copy = args->n_threads;
args->n_threads =
!bench->info->multithread ? 1 : args->n_threads;
size_t n_ops_per_thread_copy = args->n_ops_per_thread;
args->n_ops_per_thread =
!bench->info->multiops ? 1 : args->n_ops_per_thread;
stats = (struct latency *)calloc(args->repeats,
sizeof(struct latency));
assert(stats != nullptr);
workers_times = (double *)calloc(
args->n_threads * args->repeats, sizeof(double));
assert(workers_times != nullptr);
total_res = results_alloc(args);
assert(total_res != nullptr);
unsigned i = 0;
if (args->min_exe_time != 0 && bench->info->multiops) {
ret = scale_up_min_exe_time(bench, args, &total_res);
if (ret != 0)
goto out;
i = 1;
}
for (; i < args->repeats; i++) {
ret = pmembench_single_repeat(bench, args,
&total_res->res[i]);
if (ret != 0)
goto out;
}
get_total_results(total_res);
pmembench_print_results(bench, args, total_res);
args->n_ops_per_thread = n_ops_per_thread_copy;
args->n_threads = n_threads_copy;
results_free(total_res);
free(stats);
free(workers_times);
total_res = nullptr;
stats = nullptr;
workers_times = nullptr;
}
out:
if (total_res)
results_free(total_res);
if (stats)
free(stats);
if (workers_times)
free(workers_times);
out_release_args:
clo_vec_free(clovec);
out_old_wd:
/* restore the original working directory */
if (wd != nullptr) { /* Only if PMEMBENCH_DIR env var was defined */
if (chdir(old_wd)) {
perror("chdir(old_wd)");
ret = -1;
}
}
out_release_clos:
pmembench_release_clos(bench);
return ret;
}
/*
* pmembench_free_benchmarks -- release all benchmarks
*/
static void __attribute__((destructor)) pmembench_free_benchmarks(void)
{
while (!PMDK_LIST_EMPTY(&benchmarks.head)) {
struct benchmark *bench = PMDK_LIST_FIRST(&benchmarks.head);
PMDK_LIST_REMOVE(bench, next);
free(bench);
}
}
/*
* pmembench_run_scenario -- run single benchmark's scenario
*/
static int
pmembench_run_scenario(struct pmembench *pb, struct scenario *scenario)
{
struct benchmark *bench = pmembench_get_bench(scenario->benchmark);
if (nullptr == bench) {
fprintf(stderr, "unknown benchmark: %s\n", scenario->benchmark);
return -1;
}
pb->scenario = scenario;
return pmembench_run(pb, bench);
}
/*
* pmembench_run_scenarios -- run all scenarios
*/
static int
pmembench_run_scenarios(struct pmembench *pb, struct scenarios *ss)
{
struct scenario *scenario;
FOREACH_SCENARIO(scenario, ss)
{
if (pmembench_run_scenario(pb, scenario) != 0)
return -1;
}
return 0;
}
/*
* pmembench_run_config -- run one or all scenarios from config file
*/
static int
pmembench_run_config(struct pmembench *pb, const char *config)
{
struct scenarios *ss = nullptr;
struct config_reader *cr = config_reader_alloc();
assert(cr != nullptr);
int ret = 0;
if ((ret = config_reader_read(cr, config)))
goto out;
if ((ret = config_reader_get_scenarios(cr, &ss)))
goto out;
assert(ss != nullptr);
if (pb->argc == 1) {
if ((ret = pmembench_run_scenarios(pb, ss)) != 0)
goto out_scenarios;
} else {
/* Skip the config file name in cmd line params */
int tmp_argc = pb->argc - 1;
char **tmp_argv = pb->argv + 1;
if (!contains_scenarios(tmp_argc, tmp_argv, ss)) {
/* no scenarios in cmd line arguments - parse params */
pb->override_clos = true;
if ((ret = pmembench_run_scenarios(pb, ss)) != 0)
goto out_scenarios;
} else { /* scenarios in cmd line */
struct scenarios *cmd_ss = scenarios_alloc();
assert(cmd_ss != nullptr);
int parsed_scenarios = clo_get_scenarios(
tmp_argc, tmp_argv, ss, cmd_ss);
if (parsed_scenarios < 0)
goto out_cmd;
/*
* If there are any cmd line args left, treat
* them as config file params override.
*/
if (tmp_argc - parsed_scenarios)
pb->override_clos = true;
/*
* Skip the scenarios in the cmd line,
* pmembench_run_scenarios does not expect them and will
* fail otherwise.
*/
pb->argc -= parsed_scenarios;
pb->argv += parsed_scenarios;
ret = pmembench_run_scenarios(pb, cmd_ss);
out_cmd:
scenarios_free(cmd_ss);
}
}
out_scenarios:
scenarios_free(ss);
out:
config_reader_free(cr);
return ret;
}
int
main(int argc, char *argv[])
{
util_init();
util_mmap_init();
/*
* Parse common command line arguments and
* benchmark's specific ones.
*/
if (argc < 2) {
pmembench_print_usage();
exit(EXIT_FAILURE);
}
int ret = 0;
int fexists;
struct benchmark *bench;
struct pmembench *pb = (struct pmembench *)calloc(1, sizeof(*pb));
assert(pb != nullptr);
Get_time_avg = benchmark_get_avg_get_time();
pb->argc = --argc;
pb->argv = ++argv;
char *bench_name = pb->argv[0];
if (nullptr == bench_name) {
ret = -1;
goto out;
}
fexists = os_access(bench_name, R_OK) == 0;
bench = pmembench_get_bench(bench_name);
if (nullptr != bench)
ret = pmembench_run(pb, bench);
else if (fexists)
ret = pmembench_run_config(pb, bench_name);
else if ((ret = pmembench_parse_opts(pb)) != 0) {
pmembench_print_usage();
goto out;
}
out:
free(pb);
util_mmap_fini();
return ret;
}
#ifdef _MSC_VER
extern "C" {
/*
* Since libpmemobj is linked statically,
* we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
}
#endif
| 41,103 | 24.078707 | 77 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmem_memcpy.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* pmem_memcpy.cpp -- benchmark implementation for pmem_memcpy
*/
#include <cassert>
#include <cerrno>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <libpmem.h>
#include <sys/mman.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "file.h"
#define FLUSH_ALIGN 64
#define MAX_OFFSET (FLUSH_ALIGN - 1)
struct pmem_bench;
typedef size_t (*offset_fn)(struct pmem_bench *pmb,
struct operation_info *info);
/*
* pmem_args -- benchmark specific arguments
*/
struct pmem_args {
/*
* Defines the copy operation direction. Whether it is
* writing from RAM to PMEM (for argument value "write")
* or PMEM to RAM (for argument value "read").
*/
char *operation;
/*
* The source address offset used to test pmem_memcpy()
* performance when source address is not aligned.
*/
size_t src_off;
/*
* The destination address offset used to test
* pmem_memcpy() performance when destination address
* is not aligned.
*/
size_t dest_off;
/* The size of data chunk. */
size_t chunk_size;
/*
* Specifies the order in which data chunks are selected
* to be copied. There are three modes supported:
* stat, seq, rand.
*/
char *src_mode;
/*
* Specifies the order in which data chunks are written
* to the destination address. There are three modes
* supported: stat, seq, rand.
*/
char *dest_mode;
/*
* When this flag is set to true, PMEM is not used.
* This option is useful, when comparing performance
* of pmem_memcpy() function to regular memcpy().
*/
bool memcpy;
/*
* When this flag is set to true, pmem_persist()
* function is used, otherwise pmem_flush() is performed.
*/
bool persist;
/* do not do warmup */
bool no_warmup;
};
/*
* pmem_bench -- benchmark context
*/
struct pmem_bench {
/* random offsets */
unsigned *rand_offsets;
/* number of elements in randoms array */
size_t n_rand_offsets;
/* The size of the allocated PMEM */
size_t fsize;
/* The size of the allocated buffer */
size_t bsize;
/* Pointer to the allocated volatile memory */
unsigned char *buf;
/* Pointer to the allocated PMEM */
unsigned char *pmem_addr;
/*
* This field gets 'buf' or 'pmem_addr' fields assigned,
* depending on the prog_args operation direction.
*/
unsigned char *src_addr;
/*
* This field gets 'buf' or 'pmem_addr' fields assigned,
* depending on the prog_args operation direction.
*/
unsigned char *dest_addr;
/* Stores prog_args structure */
struct pmem_args *pargs;
/*
* Function which returns src offset. Matches src_mode.
*/
offset_fn func_src;
/*
* Function which returns dst offset. Matches dst_mode.
*/
offset_fn func_dest;
/*
* The actual operation performed based on benchmark specific
* arguments.
*/
int (*func_op)(void *dest, void *source, size_t len);
};
/*
* operation_type -- type of operation relative to persistent memory
*/
enum operation_type { OP_TYPE_UNKNOWN, OP_TYPE_READ, OP_TYPE_WRITE };
/*
* operation_mode -- the mode of the copy process
*
* * static - read/write always the same chunk,
* * sequential - read/write chunk by chunk,
* * random - read/write to chunks selected randomly.
*
* It is used to determine source mode as well as the destination mode.
*/
enum operation_mode {
OP_MODE_UNKNOWN,
OP_MODE_STAT,
OP_MODE_SEQ,
OP_MODE_RAND
};
/*
* parse_op_type -- parses command line "--operation" argument
* and returns proper operation type.
*/
static enum operation_type
parse_op_type(const char *arg)
{
if (strcmp(arg, "read") == 0)
return OP_TYPE_READ;
else if (strcmp(arg, "write") == 0)
return OP_TYPE_WRITE;
else
return OP_TYPE_UNKNOWN;
}
/*
* parse_op_mode -- parses command line "--src-mode" or "--dest-mode"
* and returns proper operation mode.
*/
static enum operation_mode
parse_op_mode(const char *arg)
{
if (strcmp(arg, "stat") == 0)
return OP_MODE_STAT;
else if (strcmp(arg, "seq") == 0)
return OP_MODE_SEQ;
else if (strcmp(arg, "rand") == 0)
return OP_MODE_RAND;
else
return OP_MODE_UNKNOWN;
}
/*
* mode_seq -- if copy mode is sequential mode_seq() returns
* index of a chunk.
*/
static uint64_t
mode_seq(struct pmem_bench *pmb, struct operation_info *info)
{
return info->args->n_ops_per_thread * info->worker->index + info->index;
}
/*
* mode_stat -- if mode is static, the offset is always 0,
* as only one block is used.
*/
static uint64_t
mode_stat(struct pmem_bench *pmb, struct operation_info *info)
{
return 0;
}
/*
* mode_rand -- if mode is random returns index of a random chunk
*/
static uint64_t
mode_rand(struct pmem_bench *pmb, struct operation_info *info)
{
assert(info->index < pmb->n_rand_offsets);
return info->args->n_ops_per_thread * info->worker->index +
pmb->rand_offsets[info->index];
}
/*
* assign_mode_func -- parses "--src-mode" and "--dest-mode" command line
* arguments and returns one of the above mode functions.
*/
static offset_fn
assign_mode_func(char *option)
{
enum operation_mode op_mode = parse_op_mode(option);
switch (op_mode) {
case OP_MODE_STAT:
return mode_stat;
case OP_MODE_SEQ:
return mode_seq;
case OP_MODE_RAND:
return mode_rand;
default:
return nullptr;
}
}
/*
* libc_memcpy -- copy using libc memcpy() function
* followed by pmem_flush().
*/
static int
libc_memcpy(void *dest, void *source, size_t len)
{
memcpy(dest, source, len);
pmem_flush(dest, len);
return 0;
}
/*
* libc_memcpy_persist -- copy using libc memcpy() function
* followed by pmem_persist().
*/
static int
libc_memcpy_persist(void *dest, void *source, size_t len)
{
memcpy(dest, source, len);
pmem_persist(dest, len);
return 0;
}
/*
* lipmem_memcpy_nodrain -- copy using libpmem pmem_memcpy_no_drain()
* function without pmem_persist().
*/
static int
libpmem_memcpy_nodrain(void *dest, void *source, size_t len)
{
pmem_memcpy_nodrain(dest, source, len);
return 0;
}
/*
* libpmem_memcpy_persist -- copy using libpmem pmem_memcpy_persist() function.
*/
static int
libpmem_memcpy_persist(void *dest, void *source, size_t len)
{
pmem_memcpy_persist(dest, source, len);
return 0;
}
/*
* assign_size -- assigns file and buffer size
* depending on the operation mode and type.
*/
static int
assign_size(struct pmem_bench *pmb, struct benchmark_args *args,
enum operation_type *op_type)
{
*op_type = parse_op_type(pmb->pargs->operation);
if (*op_type == OP_TYPE_UNKNOWN) {
fprintf(stderr, "Invalid operation argument '%s'",
pmb->pargs->operation);
return -1;
}
enum operation_mode op_mode_src = parse_op_mode(pmb->pargs->src_mode);
if (op_mode_src == OP_MODE_UNKNOWN) {
fprintf(stderr, "Invalid source mode argument '%s'",
pmb->pargs->src_mode);
return -1;
}
enum operation_mode op_mode_dest = parse_op_mode(pmb->pargs->dest_mode);
if (op_mode_dest == OP_MODE_UNKNOWN) {
fprintf(stderr, "Invalid destination mode argument '%s'",
pmb->pargs->dest_mode);
return -1;
}
size_t large = args->n_ops_per_thread * pmb->pargs->chunk_size *
args->n_threads;
size_t little = pmb->pargs->chunk_size;
if (*op_type == OP_TYPE_WRITE) {
pmb->bsize = op_mode_src == OP_MODE_STAT ? little : large;
pmb->fsize = op_mode_dest == OP_MODE_STAT ? little : large;
if (pmb->pargs->src_off != 0)
pmb->bsize += MAX_OFFSET;
if (pmb->pargs->dest_off != 0)
pmb->fsize += MAX_OFFSET;
} else {
pmb->fsize = op_mode_src == OP_MODE_STAT ? little : large;
pmb->bsize = op_mode_dest == OP_MODE_STAT ? little : large;
if (pmb->pargs->src_off != 0)
pmb->fsize += MAX_OFFSET;
if (pmb->pargs->dest_off != 0)
pmb->bsize += MAX_OFFSET;
}
return 0;
}
/*
* pmem_memcpy_init -- benchmark initialization
*
* Parses command line arguments, allocates persistent memory, and maps it.
*/
static int
pmem_memcpy_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
int ret = 0;
size_t file_size = 0;
int flags = 0;
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
auto *pmb = (struct pmem_bench *)malloc(sizeof(struct pmem_bench));
assert(pmb != nullptr);
pmb->pargs = (struct pmem_args *)args->opts;
assert(pmb->pargs != nullptr);
pmb->pargs->chunk_size = args->dsize;
enum operation_type op_type;
/*
* Assign file and buffer size depending on the operation type
* (READ from PMEM or WRITE to PMEM)
*/
if (assign_size(pmb, args, &op_type) != 0) {
ret = -1;
goto err_free_pmb;
}
pmb->buf =
(unsigned char *)util_aligned_malloc(FLUSH_ALIGN, pmb->bsize);
if (pmb->buf == nullptr) {
perror("posix_memalign");
ret = -1;
goto err_free_pmb;
}
pmb->n_rand_offsets = args->n_ops_per_thread * args->n_threads;
assert(pmb->n_rand_offsets != 0);
pmb->rand_offsets = (unsigned *)malloc(pmb->n_rand_offsets *
sizeof(*pmb->rand_offsets));
if (pmb->rand_offsets == nullptr) {
perror("malloc");
ret = -1;
goto err_free_pmb_buf;
}
for (size_t i = 0; i < pmb->n_rand_offsets; ++i)
pmb->rand_offsets[i] = rand() % args->n_ops_per_thread;
if (type != TYPE_DEVDAX) {
file_size = pmb->fsize;
flags = PMEM_FILE_CREATE | PMEM_FILE_EXCL;
}
/* create a pmem file and memory map it */
pmb->pmem_addr = (unsigned char *)pmem_map_file(
args->fname, file_size, flags, args->fmode, nullptr, nullptr);
if (pmb->pmem_addr == nullptr) {
perror(args->fname);
ret = -1;
goto err_free_pmb_rand_offsets;
}
if (op_type == OP_TYPE_READ) {
pmb->src_addr = pmb->pmem_addr;
pmb->dest_addr = pmb->buf;
} else {
pmb->src_addr = pmb->buf;
pmb->dest_addr = pmb->pmem_addr;
}
/* set proper func_src() and func_dest() depending on benchmark args */
if ((pmb->func_src = assign_mode_func(pmb->pargs->src_mode)) ==
nullptr) {
fprintf(stderr, "wrong src_mode parameter -- '%s'",
pmb->pargs->src_mode);
ret = -1;
goto err_unmap;
}
if ((pmb->func_dest = assign_mode_func(pmb->pargs->dest_mode)) ==
nullptr) {
fprintf(stderr, "wrong dest_mode parameter -- '%s'",
pmb->pargs->dest_mode);
ret = -1;
goto err_unmap;
}
if (pmb->pargs->memcpy) {
pmb->func_op =
pmb->pargs->persist ? libc_memcpy_persist : libc_memcpy;
} else {
pmb->func_op = pmb->pargs->persist ? libpmem_memcpy_persist
: libpmem_memcpy_nodrain;
}
if (!pmb->pargs->no_warmup) {
memset(pmb->buf, 0, pmb->bsize);
pmem_memset_persist(pmb->pmem_addr, 0, pmb->fsize);
}
pmembench_set_priv(bench, pmb);
return 0;
err_unmap:
pmem_unmap(pmb->pmem_addr, pmb->fsize);
err_free_pmb_rand_offsets:
free(pmb->rand_offsets);
err_free_pmb_buf:
util_aligned_free(pmb->buf);
err_free_pmb:
free(pmb);
return ret;
}
/*
* pmem_memcpy_operation -- actual benchmark operation
*
* Depending on the memcpy flag "-m" tested operation will be memcpy()
* or pmem_memcpy_persist().
*/
static int
pmem_memcpy_operation(struct benchmark *bench, struct operation_info *info)
{
auto *pmb = (struct pmem_bench *)pmembench_get_priv(bench);
size_t src_index = pmb->func_src(pmb, info);
size_t dest_index = pmb->func_dest(pmb, info);
void *source = pmb->src_addr + src_index * pmb->pargs->chunk_size +
pmb->pargs->src_off;
void *dest = pmb->dest_addr + dest_index * pmb->pargs->chunk_size +
pmb->pargs->dest_off;
size_t len = pmb->pargs->chunk_size;
pmb->func_op(dest, source, len);
return 0;
}
/*
* pmem_memcpy_exit -- benchmark cleanup
*/
static int
pmem_memcpy_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *pmb = (struct pmem_bench *)pmembench_get_priv(bench);
pmem_unmap(pmb->pmem_addr, pmb->fsize);
util_aligned_free(pmb->buf);
free(pmb->rand_offsets);
free(pmb);
return 0;
}
/* structure to define command line arguments */
static struct benchmark_clo pmem_memcpy_clo[8];
/* Stores information about benchmark. */
static struct benchmark_info pmem_memcpy_bench;
CONSTRUCTOR(pmem_memcpy_constructor)
void
pmem_memcpy_constructor(void)
{
pmem_memcpy_clo[0].opt_short = 'o';
pmem_memcpy_clo[0].opt_long = "operation";
pmem_memcpy_clo[0].descr = "Operation type - write, read";
pmem_memcpy_clo[0].type = CLO_TYPE_STR;
pmem_memcpy_clo[0].off = clo_field_offset(struct pmem_args, operation);
pmem_memcpy_clo[0].def = "write";
pmem_memcpy_clo[1].opt_short = 'S';
pmem_memcpy_clo[1].opt_long = "src-offset";
pmem_memcpy_clo[1].descr = "Source cache line alignment"
" offset";
pmem_memcpy_clo[1].type = CLO_TYPE_UINT;
pmem_memcpy_clo[1].off = clo_field_offset(struct pmem_args, src_off);
pmem_memcpy_clo[1].def = "0";
pmem_memcpy_clo[1].type_uint.size =
clo_field_size(struct pmem_args, src_off);
pmem_memcpy_clo[1].type_uint.base = CLO_INT_BASE_DEC;
pmem_memcpy_clo[1].type_uint.min = 0;
pmem_memcpy_clo[1].type_uint.max = MAX_OFFSET;
pmem_memcpy_clo[2].opt_short = 'D';
pmem_memcpy_clo[2].opt_long = "dest-offset";
pmem_memcpy_clo[2].descr = "Destination cache line "
"alignment offset";
pmem_memcpy_clo[2].type = CLO_TYPE_UINT;
pmem_memcpy_clo[2].off = clo_field_offset(struct pmem_args, dest_off);
pmem_memcpy_clo[2].def = "0";
pmem_memcpy_clo[2].type_uint.size =
clo_field_size(struct pmem_args, dest_off);
pmem_memcpy_clo[2].type_uint.base = CLO_INT_BASE_DEC;
pmem_memcpy_clo[2].type_uint.min = 0;
pmem_memcpy_clo[2].type_uint.max = MAX_OFFSET;
pmem_memcpy_clo[3].opt_short = 0;
pmem_memcpy_clo[3].opt_long = "src-mode";
pmem_memcpy_clo[3].descr = "Source reading mode";
pmem_memcpy_clo[3].type = CLO_TYPE_STR;
pmem_memcpy_clo[3].off = clo_field_offset(struct pmem_args, src_mode);
pmem_memcpy_clo[3].def = "seq";
pmem_memcpy_clo[4].opt_short = 0;
pmem_memcpy_clo[4].opt_long = "dest-mode";
pmem_memcpy_clo[4].descr = "Destination writing mode";
pmem_memcpy_clo[4].type = CLO_TYPE_STR;
pmem_memcpy_clo[4].off = clo_field_offset(struct pmem_args, dest_mode);
pmem_memcpy_clo[4].def = "seq";
pmem_memcpy_clo[5].opt_short = 'm';
pmem_memcpy_clo[5].opt_long = "libc-memcpy";
pmem_memcpy_clo[5].descr = "Use libc memcpy()";
pmem_memcpy_clo[5].type = CLO_TYPE_FLAG;
pmem_memcpy_clo[5].off = clo_field_offset(struct pmem_args, memcpy);
pmem_memcpy_clo[5].def = "false";
pmem_memcpy_clo[6].opt_short = 'p';
pmem_memcpy_clo[6].opt_long = "persist";
pmem_memcpy_clo[6].descr = "Use pmem_persist()";
pmem_memcpy_clo[6].type = CLO_TYPE_FLAG;
pmem_memcpy_clo[6].off = clo_field_offset(struct pmem_args, persist);
pmem_memcpy_clo[6].def = "true";
pmem_memcpy_clo[7].opt_short = 'w';
pmem_memcpy_clo[7].opt_long = "no-warmup";
pmem_memcpy_clo[7].descr = "Don't do warmup";
pmem_memcpy_clo[7].def = "false";
pmem_memcpy_clo[7].type = CLO_TYPE_FLAG;
pmem_memcpy_clo[7].off = clo_field_offset(struct pmem_args, no_warmup);
pmem_memcpy_bench.name = "pmem_memcpy";
pmem_memcpy_bench.brief = "Benchmark for"
"pmem_memcpy_persist() and "
"pmem_memcpy_nodrain()"
"operations";
pmem_memcpy_bench.init = pmem_memcpy_init;
pmem_memcpy_bench.exit = pmem_memcpy_exit;
pmem_memcpy_bench.multithread = true;
pmem_memcpy_bench.multiops = true;
pmem_memcpy_bench.operation = pmem_memcpy_operation;
pmem_memcpy_bench.measure_time = true;
pmem_memcpy_bench.clos = pmem_memcpy_clo;
pmem_memcpy_bench.nclos = ARRAY_SIZE(pmem_memcpy_clo);
pmem_memcpy_bench.opts_size = sizeof(struct pmem_args);
pmem_memcpy_bench.rm_file = true;
pmem_memcpy_bench.allow_poolset = false;
pmem_memcpy_bench.print_bandwidth = true;
REGISTER_BENCHMARK(pmem_memcpy_bench);
};
| 15,611 | 24.42671 | 79 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmemobj_persist.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2020, Intel Corporation */
/*
* pmemobj_persist.cpp -- pmemobj persist benchmarks definition
*/
#include <cassert>
#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "file.h"
#include "libpmemobj.h"
#include "util.h"
/*
* The factor used for PMEM pool size calculation, accounts for metadata,
* fragmentation and etc.
*/
#define FACTOR 3
/* The minimum allocation size that pmalloc can perform */
#define ALLOC_MIN_SIZE 64
/* OOB and allocation header size */
#define OOB_HEADER_SIZE 64
#define CONST_B 0xFF
/*
* prog_args -- benchmark specific command line options
*/
struct prog_args {
size_t minsize; /* minimum size for random allocation size */
bool use_random_size; /* if set, use random size allocations */
bool no_warmup; /* do not do warmup */
unsigned seed; /* seed for random numbers */
};
/*
* obj_bench -- benchmark context
*/
struct obj_bench {
PMEMobjpool *pop; /* persistent pool handle */
struct prog_args *pa; /* prog_args structure */
PMEMoid *oids; /* vector of allocated objects */
void **ptrs; /* pointers to allocated objects */
uint64_t nobjs; /* number of allocated objects */
size_t obj_size; /* size of each allocated objects */
int const_b; /* memset() value */
};
/*
* init_objects -- allocate persistent objects and obtain direct pointers
*/
static int
init_objects(struct obj_bench *ob)
{
assert(ob->nobjs != 0);
ob->oids = (PMEMoid *)malloc(ob->nobjs * sizeof(*ob->oids));
if (!ob->oids) {
perror("malloc");
return -1;
}
ob->ptrs = (void **)malloc(ob->nobjs * sizeof(*ob->ptrs));
if (!ob->ptrs) {
perror("malloc");
goto err_malloc;
}
for (uint64_t i = 0; i < ob->nobjs; i++) {
PMEMoid oid;
void *ptr;
if (pmemobj_alloc(ob->pop, &oid, ob->obj_size, 0, nullptr,
nullptr)) {
perror("pmemobj_alloc");
goto err_palloc;
}
ptr = pmemobj_direct(oid);
if (!ptr) {
perror("pmemobj_direct");
goto err_palloc;
}
ob->oids[i] = oid;
ob->ptrs[i] = ptr;
}
return 0;
err_palloc:
free(ob->ptrs);
err_malloc:
free(ob->oids);
return -1;
}
/*
* do_warmup -- does the warmup by writing the whole pool area
*/
static void
do_warmup(struct obj_bench *ob)
{
for (uint64_t i = 0; i < ob->nobjs; ++i) {
memset(ob->ptrs[i], 0, ob->obj_size);
pmemobj_persist(ob->pop, ob->ptrs[i], ob->obj_size);
}
}
/*
* obj_persist_op -- actual benchmark operation
*/
static int
obj_persist_op(struct benchmark *bench, struct operation_info *info)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
uint64_t idx = info->worker->index * info->args->n_ops_per_thread +
info->index;
assert(idx < ob->nobjs);
void *ptr = ob->ptrs[idx];
memset(ptr, ob->const_b, ob->obj_size);
pmemobj_persist(ob->pop, ptr, ob->obj_size);
return 0;
}
/*
* obj_persist_init -- initialization function
*/
static int
obj_persist_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
assert(args->opts != nullptr);
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
auto *pa = (struct prog_args *)args->opts;
size_t poolsize;
if (pa->minsize >= args->dsize) {
fprintf(stderr, "Wrong params - allocation size\n");
return -1;
}
auto *ob = (struct obj_bench *)malloc(sizeof(struct obj_bench));
if (ob == nullptr) {
perror("malloc");
return -1;
}
pmembench_set_priv(bench, ob);
ob->pa = pa;
/* initialize memset() value */
ob->const_b = CONST_B;
ob->nobjs = args->n_ops_per_thread * args->n_threads;
/* Create pmemobj pool. */
ob->obj_size = args->dsize;
if (ob->obj_size < ALLOC_MIN_SIZE)
ob->obj_size = ALLOC_MIN_SIZE;
/* For data objects */
poolsize = ob->nobjs * (ob->obj_size + OOB_HEADER_SIZE);
/* multiply by FACTOR for metadata, fragmentation, etc. */
poolsize = poolsize * FACTOR;
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < poolsize) {
fprintf(stderr, "file size too large\n");
goto free_ob;
}
poolsize = 0;
} else if (poolsize < PMEMOBJ_MIN_POOL) {
poolsize = PMEMOBJ_MIN_POOL;
}
poolsize = PAGE_ALIGNED_UP_SIZE(poolsize);
ob->pop = pmemobj_create(args->fname, nullptr, poolsize, args->fmode);
if (ob->pop == nullptr) {
fprintf(stderr, "%s\n", pmemobj_errormsg());
goto free_ob;
}
if (init_objects(ob)) {
goto free_pop;
}
if (!ob->pa->no_warmup) {
do_warmup(ob);
}
return 0;
free_pop:
pmemobj_close(ob->pop);
free_ob:
free(ob);
return -1;
}
/*
* obj_persist_exit -- benchmark cleanup function
*/
static int
obj_persist_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
for (uint64_t i = 0; i < ob->nobjs; ++i) {
pmemobj_free(&ob->oids[i]);
}
pmemobj_close(ob->pop);
free(ob->oids);
free(ob->ptrs);
free(ob);
return 0;
}
static struct benchmark_clo obj_persist_clo[1];
/* Stores information about benchmark. */
static struct benchmark_info obj_persist_info;
CONSTRUCTOR(pmemobj_persist_constructor)
void
pmemobj_persist_constructor(void)
{
obj_persist_clo[0].opt_short = 'w';
obj_persist_clo[0].opt_long = "no-warmup";
obj_persist_clo[0].descr = "Don't do warmup";
obj_persist_clo[0].def = "false";
obj_persist_clo[0].type = CLO_TYPE_FLAG;
obj_persist_clo[0].off = clo_field_offset(struct prog_args, no_warmup);
obj_persist_info.name = "pmemobj_persist";
obj_persist_info.brief = "Benchmark for pmemobj_persist() "
"operation";
obj_persist_info.init = obj_persist_init;
obj_persist_info.exit = obj_persist_exit;
obj_persist_info.multithread = true;
obj_persist_info.multiops = true;
obj_persist_info.operation = obj_persist_op;
obj_persist_info.measure_time = true;
obj_persist_info.clos = obj_persist_clo;
obj_persist_info.nclos = ARRAY_SIZE(obj_persist_clo);
obj_persist_info.opts_size = sizeof(struct prog_args);
obj_persist_info.rm_file = true;
obj_persist_info.allow_poolset = true;
REGISTER_BENCHMARK(obj_persist_info);
};
| 6,293 | 22.139706 | 73 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmemobj_tx.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* pmemobj_tx.cpp -- pmemobj_tx_alloc(), pmemobj_tx_free(),
* pmemobj_tx_realloc(), pmemobj_tx_add_range() benchmarks.
*/
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "file.h"
#include "libpmemobj.h"
#include "poolset_util.hpp"
#define LAYOUT_NAME "benchmark"
#define FACTOR 1.2f
#define ALLOC_OVERHEAD 64
/*
* operations number is limited to prevent stack overflow during
* performing recursive functions.
*/
#define MAX_OPS 10000
TOID_DECLARE(struct item, 0);
struct obj_tx_bench;
struct obj_tx_worker;
int obj_tx_init(struct benchmark *bench, struct benchmark_args *args);
int obj_tx_exit(struct benchmark *bench, struct benchmark_args *args);
/*
* type_num_mode -- type number mode
*/
enum type_num_mode {
NUM_MODE_ONE,
NUM_MODE_PER_THREAD,
NUM_MODE_RAND,
NUM_MODE_UNKNOWN
};
/*
* op_mode -- operation type
*/
enum op_mode {
OP_MODE_COMMIT,
OP_MODE_ABORT,
OP_MODE_ABORT_NESTED,
OP_MODE_ONE_OBJ,
OP_MODE_ONE_OBJ_NESTED,
OP_MODE_ONE_OBJ_RANGE,
OP_MODE_ONE_OBJ_NESTED_RANGE,
OP_MODE_ALL_OBJ,
OP_MODE_ALL_OBJ_NESTED,
OP_MODE_UNKNOWN
};
/*
* lib_mode -- operation type
*/
enum lib_mode {
LIB_MODE_DRAM,
LIB_MODE_OBJ_TX,
LIB_MODE_OBJ_ATOMIC,
LIB_MODE_NONE,
};
/*
* nesting_mode -- nesting type
*/
enum nesting_mode {
NESTING_MODE_SIM,
NESTING_MODE_TX,
NESTING_MODE_UNKNOWN,
};
/*
* add_range_mode -- operation type for obj_add_range benchmark
*/
enum add_range_mode { ADD_RANGE_MODE_ONE_TX, ADD_RANGE_MODE_NESTED_TX };
/*
* parse_mode -- parsing function type
*/
enum parse_mode { PARSE_OP_MODE, PARSE_OP_MODE_ADD_RANGE };
typedef size_t (*fn_type_num_t)(struct obj_tx_bench *obj_bench,
size_t worker_idx, size_t op_idx);
typedef size_t (*fn_num_t)(size_t idx);
typedef int (*fn_op_t)(struct obj_tx_bench *obj_bench,
struct worker_info *worker, size_t idx);
typedef struct offset (*fn_os_off_t)(struct obj_tx_bench *obj_bench,
size_t idx);
typedef enum op_mode (*fn_parse_t)(const char *arg);
/*
* obj_tx_args -- stores command line parsed arguments.
*/
struct obj_tx_args {
/*
* operation which will be performed when flag io set to false.
* modes for obj_tx_alloc, obj_tx_free and obj_tx_realloc:
* - basic - transaction will be committed
* - abort - 'external' transaction will be aborted.
* - abort-nested - all nested transactions will be
* aborted.
*
* modes for obj_tx_add_range benchmark:
* - basic - one object is added to undo log many times in
* one transaction.
* - range - fields of one object are added to undo
* log many times in one transaction.
* - all-obj - all objects are added to undo log in
* one transaction.
* - range-nested - fields of one object are added to undo
* log many times in many nested transactions.
* - one-obj-nested - one object is added to undo log many
* times in many nested transactions.
* - all-obj-nested - all objects are added to undo log in
* many separate, nested transactions.
*/
char *operation;
/*
* type number for each persistent object. There are three modes:
* - one - all of objects have the same type number
* - per-thread - all of object allocated by the same
* thread have the same type number
* - rand - type numbers are assigned randomly for
* each persistent object
*/
char *type_num;
/*
* define s which library will be used in main operations There are
* three modes in which benchmark can be run:
* - tx - uses PMEM transactions
* - pmem - uses PMEM without transactions
* - dram - does not use PMEM
*/
char *lib;
unsigned nested; /* number of nested transactions */
unsigned min_size; /* minimum allocation size */
unsigned min_rsize; /* minimum reallocation size */
unsigned rsize; /* reallocation size */
bool change_type; /* change type number in reallocation */
size_t obj_size; /* size of each allocated object */
size_t n_ops; /* number of operations */
int parse_mode; /* type of parsing function */
};
/*
* obj_tx_bench -- stores variables used in benchmark, passed within functions.
*/
static struct obj_tx_bench {
PMEMobjpool *pop; /* handle to persistent pool */
struct obj_tx_args *obj_args; /* pointer to benchmark arguments */
size_t *random_types; /* array to store random type numbers */
size_t *sizes; /* array to store size of each allocation */
size_t *resizes; /* array to store size of each reallocation */
size_t n_objs; /* number of objects to allocate */
int type_mode; /* type number mode */
int op_mode; /* type of operation */
int lib_mode; /* type of operation used in initialization */
int lib_op; /* type of main operation */
int lib_op_free; /* type of main operation */
int nesting_mode; /* type of nesting in main operation */
fn_num_t n_oid; /* returns object's number in array */
fn_os_off_t fn_off; /* returns offset for proper operation */
/*
* fn_type_num gets proper function assigned, depending on the
* value of the type_mode argument, which returns proper type number for
* each persistent object. Possible functions are:
* - type_mode_one,
* - type_mode_rand.
*/
fn_type_num_t fn_type_num;
/*
* fn_op gets proper array with functions pointer assigned, depending on
* function which is tested by benchmark. Possible arrays are:
* -alloc_op
* -free_op
* -realloc_op
*/
fn_op_t *fn_op;
} obj_bench;
/*
* item -- TOID's structure
*/
struct item;
/*
* obj_tx_worker - stores variables used by one thread.
*/
struct obj_tx_worker {
TOID(struct item) * oids;
char **items;
unsigned tx_level;
unsigned max_level;
};
/*
* offset - stores offset data used in pmemobj_tx_add_range()
*/
struct offset {
uint64_t off;
size_t size;
};
/*
* alloc_dram -- main operations for obj_tx_alloc benchmark in dram mode
*/
static int
alloc_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
obj_worker->items[idx] = (char *)malloc(obj_bench->sizes[idx]);
if (obj_worker->items[idx] == nullptr) {
perror("malloc");
return -1;
}
return 0;
}
/*
* alloc_pmem -- main operations for obj_tx_alloc benchmark in pmem mode
*/
static int
alloc_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
if (pmemobj_alloc(obj_bench->pop, &obj_worker->oids[idx].oid,
obj_bench->sizes[idx], type_num, nullptr,
nullptr) != 0) {
perror("pmemobj_alloc");
return -1;
}
return 0;
}
/*
* alloc_tx -- main operations for obj_tx_alloc benchmark in tx mode
*/
static int
alloc_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
obj_worker->oids[idx].oid = pmemobj_tx_xalloc(
obj_bench->sizes[idx], type_num, POBJ_XALLOC_NO_FLUSH);
if (OID_IS_NULL(obj_worker->oids[idx].oid)) {
perror("pmemobj_tx_alloc");
return -1;
}
return 0;
}
/*
* free_dram -- main operations for obj_tx_free benchmark in dram mode
*/
static int
free_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
free(obj_worker->items[idx]);
return 0;
}
/*
* free_pmem -- main operations for obj_tx_free benchmark in pmem mode
*/
static int
free_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
POBJ_FREE(&obj_worker->oids[idx]);
return 0;
}
/*
* free_tx -- main operations for obj_tx_free benchmark in tx mode
*/
static int
free_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
TX_FREE(obj_worker->oids[idx]);
return 0;
}
/*
* no_free -- exit operation for benchmarks obj_tx_alloc and obj_tx_free
* if there is no need to free memory
*/
static int
no_free(struct obj_tx_bench *obj_bench, struct worker_info *worker, size_t idx)
{
return 0;
}
/*
* realloc_dram -- main operations for obj_tx_realloc benchmark in dram mode
*/
static int
realloc_dram(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
auto *tmp = (char *)realloc(obj_worker->items[idx],
obj_bench->resizes[idx]);
if (tmp == nullptr) {
perror("realloc");
return -1;
}
obj_worker->items[idx] = tmp;
return 0;
}
/*
* realloc_pmem -- main operations for obj_tx_realloc benchmark in pmem mode
*/
static int
realloc_pmem(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
if (obj_bench->obj_args->change_type)
type_num++;
if (pmemobj_realloc(obj_bench->pop, &obj_worker->oids[idx].oid,
obj_bench->resizes[idx], type_num) != 0) {
perror("pmemobj_realloc");
return -1;
}
return 0;
}
/*
* realloc_tx -- main operations for obj_tx_realloc benchmark in tx mode
*/
static int
realloc_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
size_t type_num = obj_bench->fn_type_num(obj_bench, worker->index, idx);
if (obj_bench->obj_args->change_type)
type_num++;
PMEMoid oid = pmemobj_tx_realloc(obj_worker->oids[idx].oid,
obj_bench->sizes[idx], type_num);
if (OID_IS_NULL(oid)) {
perror("pmemobj_tx_realloc");
return -1;
}
/*
* If OP_MODE_ABORT is set, this TX will get aborted, meaning that the
* object allocated as part of the outer transaction will be freed once
* this operation finishes.
* To avoid a potential use-after-free, we either have to snapshot the
* oid pointer or skip this assignment when we know it will abort.
* For performance reason, this code does the latter.
*/
if (obj_bench->op_mode != OP_MODE_ABORT)
obj_worker->oids[idx].oid = oid;
return 0;
}
/*
* add_range_nested_tx -- main operations of the obj_tx_add_range with nesting.
*/
static int
add_range_nested_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
int ret = 0;
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
TX_BEGIN(obj_bench->pop)
{
if (obj_bench->obj_args->n_ops != obj_worker->tx_level) {
size_t n_oid = obj_bench->n_oid(obj_worker->tx_level);
struct offset offset = obj_bench->fn_off(
obj_bench, obj_worker->tx_level);
pmemobj_tx_add_range(obj_worker->oids[n_oid].oid,
offset.off, offset.size);
obj_worker->tx_level++;
ret = add_range_nested_tx(obj_bench, worker, idx);
}
}
TX_ONABORT
{
fprintf(stderr, "transaction failed\n");
ret = -1;
}
TX_END
return ret;
}
/*
* add_range_tx -- main operations of the obj_tx_add_range without nesting.
*/
static int
add_range_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
int ret = 0;
size_t i = 0;
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
TX_BEGIN(obj_bench->pop)
{
for (i = 0; i < obj_bench->obj_args->n_ops; i++) {
size_t n_oid = obj_bench->n_oid(i);
struct offset offset = obj_bench->fn_off(obj_bench, i);
ret = pmemobj_tx_add_range(obj_worker->oids[n_oid].oid,
offset.off, offset.size);
}
}
TX_ONABORT
{
fprintf(stderr, "transaction failed\n");
ret = -1;
}
TX_END
return ret;
}
/*
* obj_op_sim -- main function for benchmarks which simulates nested
* transactions on dram or pmemobj atomic API by calling function recursively.
*/
static int
obj_op_sim(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
int ret = 0;
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
if (obj_worker->max_level == obj_worker->tx_level) {
ret = obj_bench->fn_op[obj_bench->lib_op](obj_bench, worker,
idx);
} else {
obj_worker->tx_level++;
ret = obj_op_sim(obj_bench, worker, idx);
}
return ret;
}
/*
* obj_op_tx -- main recursive function for transactional benchmarks
*/
static int
obj_op_tx(struct obj_tx_bench *obj_bench, struct worker_info *worker,
size_t idx)
{
volatile int ret = 0;
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
TX_BEGIN(obj_bench->pop)
{
if (obj_worker->max_level == obj_worker->tx_level) {
ret = obj_bench->fn_op[obj_bench->lib_op](obj_bench,
worker, idx);
if (obj_bench->op_mode == OP_MODE_ABORT_NESTED)
pmemobj_tx_abort(-1);
} else {
obj_worker->tx_level++;
ret = obj_op_tx(obj_bench, worker, idx);
if (--obj_worker->tx_level == 0 &&
obj_bench->op_mode == OP_MODE_ABORT)
pmemobj_tx_abort(-1);
}
}
TX_ONABORT
{
if (obj_bench->op_mode != OP_MODE_ABORT &&
obj_bench->op_mode != OP_MODE_ABORT_NESTED) {
fprintf(stderr, "transaction failed\n");
ret = -1;
}
}
TX_END
return ret;
}
/*
* type_mode_one -- always returns 0, as in the mode NUM_MODE_ONE
* all of the persistent objects have the same type_number value.
*/
static size_t
type_mode_one(struct obj_tx_bench *obj_bench, size_t worker_idx, size_t op_idx)
{
return 0;
}
/*
* type_mode_per_thread -- always returns worker index to all of the persistent
* object allocated by the same thread have the same type number.
*/
static size_t
type_mode_per_thread(struct obj_tx_bench *obj_bench, size_t worker_idx,
size_t op_idx)
{
return worker_idx;
}
/*
* type_mode_rand -- returns the value from the random_types array assigned
* for the specific operation in a specific thread.
*/
static size_t
type_mode_rand(struct obj_tx_bench *obj_bench, size_t worker_idx, size_t op_idx)
{
return obj_bench->random_types[op_idx];
}
/*
* parse_op_mode_add_range -- parses command line "--operation" argument
* and returns proper op_mode enum value for obj_tx_add_range.
*/
static enum op_mode
parse_op_mode_add_range(const char *arg)
{
if (strcmp(arg, "basic") == 0)
return OP_MODE_ONE_OBJ;
else if (strcmp(arg, "one-obj-nested") == 0)
return OP_MODE_ONE_OBJ_NESTED;
else if (strcmp(arg, "range") == 0)
return OP_MODE_ONE_OBJ_RANGE;
else if (strcmp(arg, "range-nested") == 0)
return OP_MODE_ONE_OBJ_NESTED_RANGE;
else if (strcmp(arg, "all-obj") == 0)
return OP_MODE_ALL_OBJ;
else if (strcmp(arg, "all-obj-nested") == 0)
return OP_MODE_ALL_OBJ_NESTED;
else
return OP_MODE_UNKNOWN;
}
/*
* parse_op_mode -- parses command line "--operation" argument
* and returns proper op_mode enum value.
*/
static enum op_mode
parse_op_mode(const char *arg)
{
if (strcmp(arg, "basic") == 0)
return OP_MODE_COMMIT;
else if (strcmp(arg, "abort") == 0)
return OP_MODE_ABORT;
else if (strcmp(arg, "abort-nested") == 0)
return OP_MODE_ABORT_NESTED;
else
return OP_MODE_UNKNOWN;
}
static fn_op_t alloc_op[] = {alloc_dram, alloc_tx, alloc_pmem};
static fn_op_t free_op[] = {free_dram, free_tx, free_pmem, no_free};
static fn_op_t realloc_op[] = {realloc_dram, realloc_tx, realloc_pmem};
static fn_op_t add_range_op[] = {add_range_tx, add_range_nested_tx};
static fn_parse_t parse_op[] = {parse_op_mode, parse_op_mode_add_range};
static fn_op_t nestings[] = {obj_op_sim, obj_op_tx};
/*
* parse_type_num_mode -- converts string to type_num_mode enum
*/
static enum type_num_mode
parse_type_num_mode(const char *arg)
{
if (strcmp(arg, "one") == 0)
return NUM_MODE_ONE;
else if (strcmp(arg, "per-thread") == 0)
return NUM_MODE_PER_THREAD;
else if (strcmp(arg, "rand") == 0)
return NUM_MODE_RAND;
fprintf(stderr, "unknown type number\n");
return NUM_MODE_UNKNOWN;
}
/*
* parse_lib_mode -- converts string to type_num_mode enum
*/
static enum lib_mode
parse_lib_mode(const char *arg)
{
if (strcmp(arg, "dram") == 0)
return LIB_MODE_DRAM;
else if (strcmp(arg, "pmem") == 0)
return LIB_MODE_OBJ_ATOMIC;
else if (strcmp(arg, "tx") == 0)
return LIB_MODE_OBJ_TX;
fprintf(stderr, "unknown lib mode\n");
return LIB_MODE_NONE;
}
static fn_type_num_t type_num_fn[] = {type_mode_one, type_mode_per_thread,
type_mode_rand, nullptr};
/*
* one_num -- returns always the same number.
*/
static size_t
one_num(size_t idx)
{
return 0;
}
/*
* diff_num -- returns number given as argument.
*/
static size_t
diff_num(size_t idx)
{
return idx;
}
/*
* off_entire -- returns zero offset.
*/
static struct offset
off_entire(struct obj_tx_bench *obj_bench, size_t idx)
{
struct offset offset;
offset.off = 0;
offset.size = obj_bench->sizes[obj_bench->n_oid(idx)];
return offset;
}
/*
* off_range -- returns offset for range in object.
*/
static struct offset
off_range(struct obj_tx_bench *obj_bench, size_t idx)
{
struct offset offset;
offset.size = obj_bench->sizes[0] / obj_bench->obj_args->n_ops;
offset.off = offset.size * idx;
return offset;
}
/*
* rand_values -- allocates array and if range mode calculates random
* values as allocation sizes for each object otherwise populates whole array
* with max value. Used only when range flag set.
*/
static size_t *
rand_values(size_t min, size_t max, size_t n_ops)
{
size_t size = max - min;
auto *sizes = (size_t *)calloc(n_ops, sizeof(size_t));
if (sizes == nullptr) {
perror("calloc");
return nullptr;
}
for (size_t i = 0; i < n_ops; i++)
sizes[i] = max;
if (min) {
if (min > max) {
fprintf(stderr, "Invalid size\n");
free(sizes);
return nullptr;
}
for (size_t i = 0; i < n_ops; i++)
sizes[i] = (rand() % size) + min;
}
return sizes;
}
/*
* obj_tx_add_range_op -- main operations of the obj_tx_add_range benchmark.
*/
static int
obj_tx_add_range_op(struct benchmark *bench, struct operation_info *info)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
auto *obj_worker = (struct obj_tx_worker *)info->worker->priv;
if (add_range_op[obj_bench->lib_op](obj_bench, info->worker,
info->index) != 0)
return -1;
obj_worker->tx_level = 0;
return 0;
}
/*
* obj_tx_op -- main operation for obj_tx_alloc(), obj_tx_free() and
* obj_tx_realloc() benchmarks.
*/
static int
obj_tx_op(struct benchmark *bench, struct operation_info *info)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
auto *obj_worker = (struct obj_tx_worker *)info->worker->priv;
int ret = nestings[obj_bench->nesting_mode](obj_bench, info->worker,
info->index);
obj_worker->tx_level = 0;
return ret;
}
/*
* obj_tx_init_worker -- common part for the worker initialization functions
* for transactional benchmarks.
*/
static int
obj_tx_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
auto *obj_worker =
(struct obj_tx_worker *)calloc(1, sizeof(struct obj_tx_worker));
if (obj_worker == nullptr) {
perror("calloc");
return -1;
}
worker->priv = obj_worker;
obj_worker->tx_level = 0;
obj_worker->max_level = obj_bench->obj_args->nested;
if (obj_bench->lib_mode != LIB_MODE_DRAM)
obj_worker->oids = (TOID(struct item) *)calloc(
obj_bench->n_objs, sizeof(TOID(struct item)));
else
obj_worker->items =
(char **)calloc(obj_bench->n_objs, sizeof(char *));
if (obj_worker->oids == nullptr && obj_worker->items == nullptr) {
free(obj_worker);
perror("calloc");
return -1;
}
return 0;
}
/*
* obj_tx_free_init_worker_alloc_obj -- special part for the worker
* initialization function for benchmarks which needs allocated objects
* before operation.
*/
static int
obj_tx_init_worker_alloc_obj(struct benchmark *bench,
struct benchmark_args *args,
struct worker_info *worker)
{
unsigned i;
if (obj_tx_init_worker(bench, args, worker) != 0)
return -1;
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
for (i = 0; i < obj_bench->n_objs; i++) {
if (alloc_op[obj_bench->lib_mode](obj_bench, worker, i) != 0)
goto out;
}
return 0;
out:
for (; i > 0; i--)
free_op[obj_bench->lib_mode](obj_bench, worker, i - 1);
if (obj_bench->lib_mode == LIB_MODE_DRAM)
free(obj_worker->items);
else
free(obj_worker->oids);
free(obj_worker);
return -1;
}
/*
* obj_tx_exit_worker -- common part for the worker de-initialization.
*/
static void
obj_tx_exit_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
auto *obj_worker = (struct obj_tx_worker *)worker->priv;
for (unsigned i = 0; i < obj_bench->n_objs; i++)
free_op[obj_bench->lib_op_free](obj_bench, worker, i);
if (obj_bench->lib_mode == LIB_MODE_DRAM)
free(obj_worker->items);
else
free(obj_worker->oids);
free(obj_worker);
}
/*
* obj_tx_add_range_init -- specific part of the obj_tx_add_range
* benchmark initialization.
*/
static int
obj_tx_add_range_init(struct benchmark *bench, struct benchmark_args *args)
{
auto *obj_args = (struct obj_tx_args *)args->opts;
obj_args->parse_mode = PARSE_OP_MODE_ADD_RANGE;
if (args->n_ops_per_thread > MAX_OPS)
args->n_ops_per_thread = MAX_OPS;
if (obj_tx_init(bench, args) != 0)
return -1;
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
obj_bench->n_oid = diff_num;
if (obj_bench->op_mode < OP_MODE_ALL_OBJ) {
obj_bench->n_oid = one_num;
obj_bench->n_objs = 1;
}
obj_bench->fn_off = off_entire;
if (obj_bench->op_mode == OP_MODE_ONE_OBJ_RANGE ||
obj_bench->op_mode == OP_MODE_ONE_OBJ_NESTED_RANGE) {
obj_bench->fn_off = off_range;
if (args->n_ops_per_thread > args->dsize)
args->dsize = args->n_ops_per_thread;
obj_bench->sizes[0] = args->dsize;
}
obj_bench->lib_op = (obj_bench->op_mode == OP_MODE_ONE_OBJ ||
obj_bench->op_mode == OP_MODE_ALL_OBJ)
? ADD_RANGE_MODE_ONE_TX
: ADD_RANGE_MODE_NESTED_TX;
return 0;
}
/*
* obj_tx_free_init -- specific part of the obj_tx_free initialization.
*/
static int
obj_tx_free_init(struct benchmark *bench, struct benchmark_args *args)
{
if (obj_tx_init(bench, args) != 0)
return -1;
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
obj_bench->fn_op = free_op;
/*
* Generally all objects which were allocated during worker
* initialization are released in main operation so there is no need to
* free them in exit operation. Only exception is situation where
* transaction (inside which object is releasing) is aborted.
* Then object is not released so there there is necessary to free it
* in exit operation.
*/
if (!(obj_bench->lib_op == LIB_MODE_OBJ_TX &&
obj_bench->op_mode != OP_MODE_COMMIT))
obj_bench->lib_op_free = LIB_MODE_NONE;
return 0;
}
/*
* obj_tx_alloc_init -- specific part of the obj_tx_alloc initialization.
*/
static int
obj_tx_alloc_init(struct benchmark *bench, struct benchmark_args *args)
{
if (obj_tx_init(bench, args) != 0)
return -1;
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
obj_bench->fn_op = alloc_op;
/*
* Generally all objects which will be allocated during main operation
* need to be released. Only exception is situation where transaction
* (inside which object is allocating) is aborted. Then object is not
* allocated so there is no need to free it in exit operation.
*/
if (obj_bench->lib_op == LIB_MODE_OBJ_TX &&
obj_bench->op_mode != OP_MODE_COMMIT)
obj_bench->lib_op_free = LIB_MODE_NONE;
return 0;
}
/*
* obj_tx_realloc_init -- specific part of the obj_tx_realloc initialization.
*/
static int
obj_tx_realloc_init(struct benchmark *bench, struct benchmark_args *args)
{
if (obj_tx_init(bench, args) != 0)
return -1;
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
obj_bench->resizes =
rand_values(obj_bench->obj_args->min_rsize,
obj_bench->obj_args->rsize, args->n_ops_per_thread);
if (obj_bench->resizes == nullptr) {
obj_tx_exit(bench, args);
return -1;
}
obj_bench->fn_op = realloc_op;
return 0;
}
/*
* obj_tx_init -- common part of the benchmark initialization for transactional
* benchmarks in their init functions. Parses command line arguments, set
* variables and creates persistent pool.
*/
int
obj_tx_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
assert(args->opts != nullptr);
char path[PATH_MAX];
if (util_safe_strcpy(path, args->fname, sizeof(path)) != 0)
return -1;
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
pmembench_set_priv(bench, &obj_bench);
obj_bench.obj_args = (struct obj_tx_args *)args->opts;
obj_bench.obj_args->obj_size = args->dsize;
obj_bench.obj_args->n_ops = args->n_ops_per_thread;
obj_bench.n_objs = args->n_ops_per_thread;
obj_bench.lib_op = obj_bench.obj_args->lib != nullptr
? parse_lib_mode(obj_bench.obj_args->lib)
: LIB_MODE_OBJ_ATOMIC;
if (obj_bench.lib_op == LIB_MODE_NONE)
return -1;
obj_bench.lib_mode = obj_bench.lib_op == LIB_MODE_DRAM
? LIB_MODE_DRAM
: LIB_MODE_OBJ_ATOMIC;
obj_bench.lib_op_free = obj_bench.lib_mode;
obj_bench.nesting_mode = obj_bench.lib_op == LIB_MODE_OBJ_TX
? NESTING_MODE_TX
: NESTING_MODE_SIM;
/*
* Multiplication by FACTOR prevents from out of memory error
* as the actual size of the allocated persistent objects
* is always larger than requested.
*/
size_t dsize = obj_bench.obj_args->rsize > args->dsize
? obj_bench.obj_args->rsize
: args->dsize;
size_t psize = args->n_ops_per_thread * (dsize + ALLOC_OVERHEAD) *
args->n_threads;
psize += PMEMOBJ_MIN_POOL;
psize = (size_t)(psize * FACTOR);
/*
* When adding all allocated objects to undo log there is necessary
* to prepare larger pool to prevent out of memory error.
*/
if (obj_bench.op_mode == OP_MODE_ALL_OBJ ||
obj_bench.op_mode == OP_MODE_ALL_OBJ_NESTED)
psize *= 2;
obj_bench.op_mode = parse_op[obj_bench.obj_args->parse_mode](
obj_bench.obj_args->operation);
if (obj_bench.op_mode == OP_MODE_UNKNOWN) {
fprintf(stderr, "operation mode unknown\n");
return -1;
}
obj_bench.type_mode = parse_type_num_mode(obj_bench.obj_args->type_num);
if (obj_bench.type_mode == NUM_MODE_UNKNOWN)
return -1;
obj_bench.fn_type_num = type_num_fn[obj_bench.type_mode];
if (obj_bench.type_mode == NUM_MODE_RAND) {
obj_bench.random_types =
rand_values(1, UINT32_MAX, args->n_ops_per_thread);
if (obj_bench.random_types == nullptr)
return -1;
}
obj_bench.sizes = rand_values(obj_bench.obj_args->min_size,
obj_bench.obj_args->obj_size,
args->n_ops_per_thread);
if (obj_bench.sizes == nullptr)
goto free_random_types;
if (obj_bench.lib_mode == LIB_MODE_DRAM)
return 0;
/* Create pmemobj pool. */
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < psize) {
fprintf(stderr, "file size too large\n");
goto free_all;
}
psize = 0;
} else if (args->is_dynamic_poolset) {
int ret = dynamic_poolset_create(args->fname, psize);
if (ret == -1)
goto free_all;
if (util_safe_strcpy(path, POOLSET_PATH, sizeof(path)) != 0)
goto free_all;
psize = 0;
}
obj_bench.pop = pmemobj_create(path, LAYOUT_NAME, psize, args->fmode);
if (obj_bench.pop == nullptr) {
perror("pmemobj_create");
goto free_all;
}
return 0;
free_all:
free(obj_bench.sizes);
free_random_types:
if (obj_bench.type_mode == NUM_MODE_RAND)
free(obj_bench.random_types);
return -1;
}
/*
* obj_tx_exit -- common part for the exit function of the transactional
* benchmarks in their exit functions.
*/
int
obj_tx_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
if (obj_bench->lib_mode != LIB_MODE_DRAM)
pmemobj_close(obj_bench->pop);
free(obj_bench->sizes);
if (obj_bench->type_mode == NUM_MODE_RAND)
free(obj_bench->random_types);
return 0;
}
/*
* obj_tx_realloc_exit -- common part for the exit function of the transactional
* benchmarks in their exit functions.
*/
static int
obj_tx_realloc_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *obj_bench = (struct obj_tx_bench *)pmembench_get_priv(bench);
free(obj_bench->resizes);
return obj_tx_exit(bench, args);
}
/* Array defining common command line arguments. */
static struct benchmark_clo obj_tx_clo[8];
static struct benchmark_info obj_tx_alloc;
static struct benchmark_info obj_tx_free;
static struct benchmark_info obj_tx_realloc;
static struct benchmark_info obj_tx_add_range;
CONSTRUCTOR(pmemobj_tx_constructor)
void
pmemobj_tx_constructor(void)
{
obj_tx_clo[0].opt_short = 'T';
obj_tx_clo[0].opt_long = "type-number";
obj_tx_clo[0].descr = "Type number - one, rand, per-thread";
obj_tx_clo[0].def = "one";
obj_tx_clo[0].type = CLO_TYPE_STR;
obj_tx_clo[0].off = clo_field_offset(struct obj_tx_args, type_num);
obj_tx_clo[1].opt_short = 'O';
obj_tx_clo[1].opt_long = "operation";
obj_tx_clo[1].descr = "Type of operation";
obj_tx_clo[1].def = "basic";
obj_tx_clo[1].off = clo_field_offset(struct obj_tx_args, operation);
obj_tx_clo[1].type = CLO_TYPE_STR;
obj_tx_clo[2].opt_short = 'm';
obj_tx_clo[2].opt_long = "min-size";
obj_tx_clo[2].type = CLO_TYPE_UINT;
obj_tx_clo[2].descr = "Minimum allocation size";
obj_tx_clo[2].off = clo_field_offset(struct obj_tx_args, min_size);
obj_tx_clo[2].def = "0";
obj_tx_clo[2].type_uint.size =
clo_field_size(struct obj_tx_args, min_size);
obj_tx_clo[2].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
obj_tx_clo[2].type_uint.min = 0;
obj_tx_clo[2].type_uint.max = UINT_MAX;
/*
* nclos field in benchmark_info structures is decremented to make this
* options available only for obj_tx_alloc, obj_tx_free and
* obj_tx_realloc benchmarks.
*/
obj_tx_clo[3].opt_short = 'L';
obj_tx_clo[3].opt_long = "lib";
obj_tx_clo[3].descr = "Type of library";
obj_tx_clo[3].def = "tx";
obj_tx_clo[3].off = clo_field_offset(struct obj_tx_args, lib);
obj_tx_clo[3].type = CLO_TYPE_STR;
obj_tx_clo[4].opt_short = 'N';
obj_tx_clo[4].opt_long = "nestings";
obj_tx_clo[4].type = CLO_TYPE_UINT;
obj_tx_clo[4].descr = "Number of nested transactions";
obj_tx_clo[4].off = clo_field_offset(struct obj_tx_args, nested);
obj_tx_clo[4].def = "0";
obj_tx_clo[4].type_uint.size =
clo_field_size(struct obj_tx_args, nested);
obj_tx_clo[4].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
obj_tx_clo[4].type_uint.min = 0;
obj_tx_clo[4].type_uint.max = MAX_OPS;
obj_tx_clo[5].opt_short = 'r';
obj_tx_clo[5].opt_long = "min-rsize";
obj_tx_clo[5].type = CLO_TYPE_UINT;
obj_tx_clo[5].descr = "Minimum reallocation size";
obj_tx_clo[5].off = clo_field_offset(struct obj_tx_args, min_rsize);
obj_tx_clo[5].def = "0";
obj_tx_clo[5].type_uint.size =
clo_field_size(struct obj_tx_args, min_rsize);
obj_tx_clo[5].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
obj_tx_clo[5].type_uint.min = 0;
obj_tx_clo[5].type_uint.max = UINT_MAX;
obj_tx_clo[6].opt_short = 'R';
obj_tx_clo[6].opt_long = "realloc-size";
obj_tx_clo[6].type = CLO_TYPE_UINT;
obj_tx_clo[6].descr = "Reallocation size";
obj_tx_clo[6].off = clo_field_offset(struct obj_tx_args, rsize);
obj_tx_clo[6].def = "1";
obj_tx_clo[6].type_uint.size =
clo_field_size(struct obj_tx_args, rsize);
obj_tx_clo[6].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
obj_tx_clo[6].type_uint.min = 1;
obj_tx_clo[6].type_uint.max = ULONG_MAX;
obj_tx_clo[7].opt_short = 'c';
obj_tx_clo[7].opt_long = "changed-type";
obj_tx_clo[7].descr = "Use another type number in "
"reallocation than in allocation";
obj_tx_clo[7].type = CLO_TYPE_FLAG;
obj_tx_clo[7].off = clo_field_offset(struct obj_tx_args, change_type);
obj_tx_alloc.name = "obj_tx_alloc";
obj_tx_alloc.brief = "pmemobj_tx_alloc() benchmark";
obj_tx_alloc.init = obj_tx_alloc_init;
obj_tx_alloc.exit = obj_tx_exit;
obj_tx_alloc.multithread = true;
obj_tx_alloc.multiops = true;
obj_tx_alloc.init_worker = obj_tx_init_worker;
obj_tx_alloc.free_worker = obj_tx_exit_worker;
obj_tx_alloc.operation = obj_tx_op;
obj_tx_alloc.measure_time = true;
obj_tx_alloc.clos = obj_tx_clo;
obj_tx_alloc.nclos = ARRAY_SIZE(obj_tx_clo) - 3;
obj_tx_alloc.opts_size = sizeof(struct obj_tx_args);
obj_tx_alloc.rm_file = true;
obj_tx_alloc.allow_poolset = true;
REGISTER_BENCHMARK(obj_tx_alloc);
obj_tx_free.name = "obj_tx_free";
obj_tx_free.brief = "pmemobj_tx_free() benchmark";
obj_tx_free.init = obj_tx_free_init;
obj_tx_free.exit = obj_tx_exit;
obj_tx_free.multithread = true;
obj_tx_free.multiops = true;
obj_tx_free.init_worker = obj_tx_init_worker_alloc_obj;
obj_tx_free.free_worker = obj_tx_exit_worker;
obj_tx_free.operation = obj_tx_op;
obj_tx_free.measure_time = true;
obj_tx_free.clos = obj_tx_clo;
obj_tx_free.nclos = ARRAY_SIZE(obj_tx_clo) - 3;
obj_tx_free.opts_size = sizeof(struct obj_tx_args);
obj_tx_free.rm_file = true;
obj_tx_free.allow_poolset = true;
REGISTER_BENCHMARK(obj_tx_free);
obj_tx_realloc.name = "obj_tx_realloc";
obj_tx_realloc.brief = "pmemobj_tx_realloc() benchmark";
obj_tx_realloc.init = obj_tx_realloc_init;
obj_tx_realloc.exit = obj_tx_realloc_exit;
obj_tx_realloc.multithread = true;
obj_tx_realloc.multiops = true;
obj_tx_realloc.init_worker = obj_tx_init_worker_alloc_obj;
obj_tx_realloc.free_worker = obj_tx_exit_worker;
obj_tx_realloc.operation = obj_tx_op;
obj_tx_realloc.measure_time = true;
obj_tx_realloc.clos = obj_tx_clo;
obj_tx_realloc.nclos = ARRAY_SIZE(obj_tx_clo);
obj_tx_realloc.opts_size = sizeof(struct obj_tx_args);
obj_tx_realloc.rm_file = true;
obj_tx_realloc.allow_poolset = true;
REGISTER_BENCHMARK(obj_tx_realloc);
obj_tx_add_range.name = "obj_tx_add_range";
obj_tx_add_range.brief = "pmemobj_tx_add_range() benchmark";
obj_tx_add_range.init = obj_tx_add_range_init;
obj_tx_add_range.exit = obj_tx_exit;
obj_tx_add_range.multithread = true;
obj_tx_add_range.multiops = false;
obj_tx_add_range.init_worker = obj_tx_init_worker_alloc_obj;
obj_tx_add_range.free_worker = obj_tx_exit_worker;
obj_tx_add_range.operation = obj_tx_add_range_op;
obj_tx_add_range.measure_time = true;
obj_tx_add_range.clos = obj_tx_clo;
obj_tx_add_range.nclos = ARRAY_SIZE(obj_tx_clo) - 5;
obj_tx_add_range.opts_size = sizeof(struct obj_tx_args);
obj_tx_add_range.rm_file = true;
obj_tx_add_range.allow_poolset = true;
REGISTER_BENCHMARK(obj_tx_add_range);
}
| 34,848 | 27.309504 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmemobj_atomic_lists.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* pmemobj_atomic_lists.cpp -- benchmark for pmemobj atomic list API
*/
#include "benchmark.hpp"
#include "file.h"
#include "libpmemobj.h"
#include "queue.h"
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#define FACTOR 8
#define LAYOUT_NAME "benchmark"
struct obj_bench;
struct obj_worker;
struct element;
TOID_DECLARE(struct item, 0);
TOID_DECLARE(struct list, 1);
typedef size_t (*fn_type_num_t)(size_t worker_idx, size_t op_idx);
typedef struct element (*fn_position_t)(struct obj_worker *obj_worker,
size_t op_idx);
typedef int (*fn_init_t)(struct worker_info *worker, size_t n_elm,
size_t list_len);
/*
* args -- stores command line parsed arguments.
*/
struct obj_list_args {
char *type_num; /* type_number mode - one, per-thread, rand */
char *position; /* position - head, tail, middle, rand */
unsigned list_len; /* initial list length */
bool queue; /* use circle queue from <sys/queue.h> */
bool range; /* use random allocation size */
unsigned min_size; /* minimum random allocation size */
unsigned seed; /* seed value */
};
/*
* obj_bench -- stores variables used in benchmark, passed within functions.
*/
static struct obj_bench {
/* handle to persistent pool */
PMEMobjpool *pop;
/* pointer to benchmark specific arguments */
struct obj_list_args *args;
/* array to store random type_number values */
size_t *random_types;
/*
* fn_rpositions array stores random functions returning proper element
* from list, if position where operation is performed is random.
* Possible function which can be in array are:
* - position_head,
* - position_tail,
* - position_middle.
*/
size_t *alloc_sizes; /* array to store random sizes of each object */
size_t max_len; /* maximum list length */
size_t min_len; /* initial list length */
int type_mode; /* type_number mode */
int position_mode; /* list destination mode */
/*
* fn_type_num gets proper function assigned, depending on the
* value of the type_mode argument, which returns proper type number for
* each persistent object. Possible functions are:
* - type_mode_one,
* - type_mode_per_thread,
* - type_mode_rand.
*/
fn_type_num_t fn_type_num;
/*
* fn_position gets proper function assigned, depending on the value
* of the position argument, which returns handle to proper element on
* the list. Possible functions are:
* - position_head,
* - position_tail,
* - position_middle,
* - position_rand.
*/
fn_position_t fn_position;
/*
* fn_init gets proper function assigned, depending on the file_io
* flag, which allocates objects and initializes proper list. Possible
* functions are:
* - obj_init_list,
* - queue_init_list.
*/
fn_init_t fn_init;
} obj_bench;
/*
* item -- structure used to connect elements in lists.
*/
struct item {
POBJ_LIST_ENTRY(struct item) field;
PMDK_CIRCLEQ_ENTRY(item) fieldq;
};
/*
* element -- struct contains one item from list with proper type.
*/
struct element {
struct item *itemq;
TOID(struct item) itemp;
bool before;
};
/*
* obj_worker -- stores variables used by one thread, concerning one list.
*/
struct obj_worker {
/* head of the pmemobj list */
POBJ_LIST_HEAD(plist, struct item) head;
/* head of the circular queue */
PMDK_CIRCLEQ_HEAD(qlist, item) headq;
TOID(struct item) * oids; /* persistent pmemobj list elements */
struct item **items; /* volatile elements */
size_t n_elm; /* number of elements in array */
fn_position_t *fn_positions; /* element access functions */
struct element elm; /* pointer to current element */
/*
* list_move is a pointer to structure storing variables used by
* second list (used only for obj_move benchmark).
*/
struct obj_worker *list_move;
};
/*
* position_mode -- list destination type
*/
enum position_mode {
/* object inserted/removed/moved to/from head of list */
POSITION_MODE_HEAD,
/* object inserted/removed/moved to/from tail of list */
POSITION_MODE_TAIL,
/*
* object inserted/removed/moved to/from second element of the list
* or to/from head if list length equal to one
*/
POSITION_MODE_MIDDLE,
/* object inserted/removed/moved to/from head, tail or middle */
POSITION_MODE_RAND,
POSITION_MODE_UNKNOWN,
};
/*
* type_mode -- type number type
*/
enum type_mode {
TYPE_MODE_ONE, /* one type number for all of objects */
/* one type number for objects allocated by the same thread */
TYPE_MODE_PER_THREAD,
TYPE_MODE_RAND, /* random type number for each object */
TYPE_MODE_UNKNOWN,
};
/*
* position_head -- returns head of the persistent list or volatile queue.
*/
static struct element
position_head(struct obj_worker *obj_worker, size_t op_idx)
{
struct element head = {nullptr, OID_NULL, false};
head.before = true;
if (!obj_bench.args->queue)
head.itemp = POBJ_LIST_FIRST(&obj_worker->head);
else
head.itemq = PMDK_CIRCLEQ_FIRST(&obj_worker->headq);
return head;
}
/*
* position_tail -- returns tail of the persistent list or volatile queue.
*/
static struct element
position_tail(struct obj_worker *obj_worker, size_t op_idx)
{
struct element tail = {nullptr, OID_NULL, false};
tail.before = false;
if (!obj_bench.args->queue)
tail.itemp = POBJ_LIST_LAST(&obj_worker->head, field);
else
tail.itemq = PMDK_CIRCLEQ_LAST(&obj_worker->headq);
return tail;
}
/*
* position_middle -- returns second or first element from the persistent list
* or volatile queue.
*/
static struct element
position_middle(struct obj_worker *obj_worker, size_t op_idx)
{
struct element elm = position_head(obj_worker, op_idx);
elm.before = true;
if (!obj_bench.args->queue)
elm.itemp = POBJ_LIST_NEXT(elm.itemp, field);
else
elm.itemq = PMDK_CIRCLEQ_NEXT(elm.itemq, fieldq);
return elm;
}
/*
* position_rand -- returns first, second or last element from the persistent
* list or volatile queue based on r_positions array.
*/
static struct element
position_rand(struct obj_worker *obj_worker, size_t op_idx)
{
struct element elm;
elm = obj_worker->fn_positions[op_idx](obj_worker, op_idx);
elm.before = true;
return elm;
}
/*
* type_mode_one -- always returns 0, as in the mode TYPE_MODE_ONE
* all of the persistent objects have the same type_number value.
*/
static size_t
type_mode_one(size_t worker_idx, size_t op_idx)
{
return 0;
}
/*
* type_mode_per_thread -- always returns the index of the worker,
* as in the TYPE_MODE_PER_THREAD the value of the persistent object
* type_number is specific to the thread.
*/
static size_t
type_mode_per_thread(size_t worker_idx, size_t op_idx)
{
return worker_idx;
}
/*
* type_mode_rand -- returns the value from the random_types array assigned
* for the specific operation in a specific thread.
*/
static size_t
type_mode_rand(size_t worker_idx, size_t op_idx)
{
return obj_bench.random_types[op_idx];
}
const char *type_num_names[] = {"one", "per-thread", "rand"};
const char *position_names[] = {"head", "tail", "middle", "rand"};
static fn_type_num_t type_num_modes[] = {type_mode_one, type_mode_per_thread,
type_mode_rand};
static fn_position_t positions[] = {position_head, position_tail,
position_middle, position_rand};
/* function pointers randomly picked when using rand mode */
static fn_position_t rand_positions[] = {position_head, position_tail,
position_middle};
/*
* get_item -- common part of initial operation of the all benchmarks.
* It gets pointer to element on the list where object will
* be inserted/removed/moved to/from.
*/
static void
get_item(struct benchmark *bench, struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
obj_worker->elm = obj_bench.fn_position(obj_worker, info->index);
}
/*
* get_move_item -- special part of initial operation of the obj_move
* benchmarks. It gets pointer to element on the list where object will be
* inserted/removed/moved to/from.
*/
static void
get_move_item(struct benchmark *bench, struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
obj_worker->list_move->elm =
obj_bench.fn_position(obj_worker->list_move, info->index);
get_item(bench, info);
}
/*
* parse_args -- parse command line string argument
*/
static int
parse_args(char *arg, int max, const char **names)
{
int i = 0;
for (; i < max && strcmp(names[i], arg) != 0; i++)
;
if (i == max)
fprintf(stderr, "Invalid argument\n");
return i;
}
/*
* obj_init_list -- special part of worker initialization, performed only if
* queue flag set false. Allocates proper number of items, and inserts proper
* part of them to the pmemobj list.
*/
static int
obj_init_list(struct worker_info *worker, size_t n_oids, size_t list_len)
{
size_t i;
auto *obj_worker = (struct obj_worker *)worker->priv;
obj_worker->oids =
(TOID(struct item) *)calloc(n_oids, sizeof(TOID(struct item)));
if (obj_worker->oids == nullptr) {
perror("calloc");
return -1;
}
for (i = 0; i < n_oids; i++) {
size_t type_num = obj_bench.fn_type_num(worker->index, i);
size_t size = obj_bench.alloc_sizes[i];
auto *tmp = (PMEMoid *)&obj_worker->oids[i];
if (pmemobj_alloc(obj_bench.pop, tmp, size, type_num, nullptr,
nullptr) != 0)
goto err_oids;
}
for (i = 0; i < list_len; i++)
POBJ_LIST_INSERT_TAIL(obj_bench.pop, &obj_worker->head,
obj_worker->oids[i], field);
return 0;
err_oids:
for (; i > 0; i--)
POBJ_FREE(&obj_worker->oids[i - 1]);
free(obj_worker->oids);
return -1;
}
/*
* queue_init_list -- special part of worker initialization, performed only if
* queue flag set. Initiates circle queue, allocates proper number of items and
* inserts proper part of them to the queue.
*/
static int
queue_init_list(struct worker_info *worker, size_t n_items, size_t list_len)
{
size_t i;
auto *obj_worker = (struct obj_worker *)worker->priv;
PMDK_CIRCLEQ_INIT(&obj_worker->headq);
obj_worker->items =
(struct item **)malloc(n_items * sizeof(struct item *));
if (obj_worker->items == nullptr) {
perror("malloc");
return -1;
}
for (i = 0; i < n_items; i++) {
size_t size = obj_bench.alloc_sizes[i];
obj_worker->items[i] = (struct item *)calloc(1, size);
if (obj_worker->items[i] == nullptr) {
perror("calloc");
goto err;
}
}
for (i = 0; i < list_len; i++)
PMDK_CIRCLEQ_INSERT_TAIL(&obj_worker->headq,
obj_worker->items[i], fieldq);
return 0;
err:
for (; i > 0; i--)
free(obj_worker->items[i - 1]);
free(obj_worker->items);
return -1;
}
/*
* queue_free_worker_list -- special part for the worker de-initialization when
* queue flag is true. Releases items directly from atomic list.
*/
static void
queue_free_worker_list(struct obj_worker *obj_worker)
{
while (!PMDK_CIRCLEQ_EMPTY(&obj_worker->headq)) {
struct item *tmp = PMDK_CIRCLEQ_LAST(&obj_worker->headq);
PMDK_CIRCLEQ_REMOVE(&obj_worker->headq, tmp, fieldq);
free(tmp);
}
free(obj_worker->items);
}
/*
* obj_free_worker_list -- special part for the worker de-initialization when
* queue flag is false. Releases items directly from atomic list.
*/
static void
obj_free_worker_list(struct obj_worker *obj_worker)
{
while (!POBJ_LIST_EMPTY(&obj_worker->head)) {
TOID(struct item) tmp = POBJ_LIST_FIRST(&obj_worker->head);
POBJ_LIST_REMOVE_FREE(obj_bench.pop, &obj_worker->head, tmp,
field);
}
free(obj_worker->oids);
}
/*
* obj_free_worker_items -- special part for the worker de-initialization when
* queue flag is false. Releases items used for create pmemobj list.
*/
static void
obj_free_worker_items(struct obj_worker *obj_worker)
{
for (size_t i = 0; i < obj_worker->n_elm; i++)
POBJ_FREE(&obj_worker->oids[i]);
free(obj_worker->oids);
}
/*
* queue_free_worker_items -- special part for the worker de-initialization
* when queue flag set. Releases used for create circle queue.
*/
static void
queue_free_worker_items(struct obj_worker *obj_worker)
{
for (size_t i = 0; i < obj_worker->n_elm; i++)
free(obj_worker->items[i]);
free(obj_worker->items);
}
/*
* random_positions -- allocates array and calculates random values for
* defining positions where each operation will be performed. Used only
* in POSITION_MODE_RAND
*/
static fn_position_t *
random_positions(void)
{
auto *positions = (fn_position_t *)calloc(obj_bench.max_len,
sizeof(fn_position_t));
if (positions == nullptr) {
perror("calloc");
return nullptr;
}
if (obj_bench.args->seed != 0)
srand(obj_bench.args->seed);
size_t rmax = ARRAY_SIZE(rand_positions);
for (size_t i = 0; i < obj_bench.max_len; i++) {
size_t id = RRAND(rmax, 0);
positions[i] = rand_positions[id];
}
return positions;
}
/*
* rand_values -- allocates array and if range mode calculates random
* values as allocation sizes for each object otherwise populates whole array
* with max value. Used only when range flag set.
*/
static size_t *
random_values(size_t min, size_t max, size_t n_ops, size_t min_range)
{
auto *randoms = (size_t *)calloc(n_ops, sizeof(size_t));
if (randoms == nullptr) {
perror("calloc");
return nullptr;
}
for (size_t i = 0; i < n_ops; i++)
randoms[i] = max;
if (min > min_range) {
if (min > max) {
fprintf(stderr, "Invalid size\n");
free(randoms);
return nullptr;
}
for (size_t i = 0; i < n_ops; i++)
randoms[i] = RRAND(max, min);
}
return randoms;
}
/*
* queue_insert_op -- main operations of the obj_insert benchmark when queue
* flag set to true.
*/
static int
queue_insert_op(struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
PMDK_CIRCLEQ_INSERT_AFTER(
&obj_worker->headq, obj_worker->elm.itemq,
obj_worker->items[info->index + obj_bench.min_len], fieldq);
return 0;
}
/*
* obj_insert_op -- main operations of the obj_insert benchmark when queue flag
* set to false.
*/
static int
obj_insert_op(struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
POBJ_LIST_INSERT_AFTER(
obj_bench.pop, &obj_worker->head, obj_worker->elm.itemp,
obj_worker->oids[info->index + obj_bench.min_len], field);
return 0;
}
/*
* queue_remove_op -- main operations of the obj_remove benchmark when queue
* flag set to true.
*/
static int
queue_remove_op(struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
PMDK_CIRCLEQ_REMOVE(&obj_worker->headq, obj_worker->elm.itemq, fieldq);
return 0;
}
/*
* obj_remove_op -- main operations of the obj_remove benchmark when queue flag
* set to false.
*/
static int
obj_remove_op(struct operation_info *info)
{
auto *obj_worker = (struct obj_worker *)info->worker->priv;
POBJ_LIST_REMOVE(obj_bench.pop, &obj_worker->head,
obj_worker->elm.itemp, field);
return 0;
}
/*
* insert_op -- main operations of the obj_insert benchmark.
*/
static int
insert_op(struct benchmark *bench, struct operation_info *info)
{
get_item(bench, info);
return obj_bench.args->queue ? queue_insert_op(info)
: obj_insert_op(info);
}
/*
* obj_insert_new_op -- main operations of the obj_insert_new benchmark.
*/
static int
obj_insert_new_op(struct benchmark *bench, struct operation_info *info)
{
get_item(bench, info);
auto *obj_worker = (struct obj_worker *)info->worker->priv;
PMEMoid tmp;
size_t size = obj_bench.alloc_sizes[info->index];
size_t type_num =
obj_bench.fn_type_num(info->worker->index, info->index);
tmp = pmemobj_list_insert_new(
obj_bench.pop, offsetof(struct item, field), &obj_worker->head,
obj_worker->elm.itemp.oid, obj_worker->elm.before, size,
type_num, nullptr, nullptr);
if (OID_IS_NULL(tmp)) {
perror("pmemobj_list_insert_new");
return -1;
}
return 0;
}
/*
* remove_op -- main operations of the obj_remove benchmark.
*/
static int
remove_op(struct benchmark *bench, struct operation_info *info)
{
get_item(bench, info);
return obj_bench.args->queue ? queue_remove_op(info)
: obj_remove_op(info);
}
/*
* obj_remove_free_op -- main operation of the obj_remove_free benchmark.
*/
static int
obj_remove_free_op(struct benchmark *bench, struct operation_info *info)
{
get_item(bench, info);
auto *obj_worker = (struct obj_worker *)info->worker->priv;
POBJ_LIST_REMOVE_FREE(obj_bench.pop, &obj_worker->head,
obj_worker->elm.itemp, field);
return 0;
}
/*
* obj_move_op -- main operation of the obj_move benchmark.
*/
static int
obj_move_op(struct benchmark *bench, struct operation_info *info)
{
get_move_item(bench, info);
auto *obj_worker = (struct obj_worker *)info->worker->priv;
POBJ_LIST_MOVE_ELEMENT_BEFORE(obj_bench.pop, &obj_worker->head,
&obj_worker->list_move->head,
obj_worker->list_move->elm.itemp,
obj_worker->elm.itemp, field, field);
return 0;
}
/*
* free_worker -- free common worker state
*/
static void
free_worker(struct obj_worker *obj_worker)
{
if (obj_bench.position_mode == POSITION_MODE_RAND)
free(obj_worker->fn_positions);
free(obj_worker);
}
/*
* free_worker_list -- worker de-initialization function for: obj_insert_new,
* obj_remove_free, obj_move. Requires releasing objects directly from list.
*/
static void
free_worker_list(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *obj_worker = (struct obj_worker *)worker->priv;
obj_bench.args->queue ? queue_free_worker_list(obj_worker)
: obj_free_worker_list(obj_worker);
free_worker(obj_worker);
}
/*
* obj_free_worker_items -- worker de-initialization function of obj_insert and
* obj_remove benchmarks, where deallocation can't be performed directly on the
* list and where is possibility of using queue flag.
*/
static void
free_worker_items(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *obj_worker = (struct obj_worker *)worker->priv;
auto *obj_args = (struct obj_list_args *)args->opts;
obj_args->queue ? queue_free_worker_items(obj_worker)
: obj_free_worker_items(obj_worker);
free_worker(obj_worker);
}
/*
* obj_move_free_worker -- special part for the worker de-initialization
* function of obj_move benchmarks.
*/
static void
obj_move_free_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *obj_worker = (struct obj_worker *)worker->priv;
while (!POBJ_LIST_EMPTY(&obj_worker->list_move->head))
POBJ_LIST_REMOVE_FREE(
obj_bench.pop, &obj_worker->list_move->head,
POBJ_LIST_LAST(&obj_worker->list_move->head, field),
field);
if (obj_bench.position_mode == POSITION_MODE_RAND)
free(obj_worker->list_move->fn_positions);
free(obj_worker->list_move);
free_worker_list(bench, args, worker);
}
/*
* obj_init_worker -- common part for the worker initialization for:
* obj_insert, obj_insert_new, obj_remove obj_remove_free and obj_move.
*/
static int
obj_init_worker(struct worker_info *worker, size_t n_elm, size_t list_len)
{
auto *obj_worker =
(struct obj_worker *)calloc(1, sizeof(struct obj_worker));
if (obj_worker == nullptr) {
perror("calloc");
return -1;
}
worker->priv = obj_worker;
obj_worker->n_elm = obj_bench.max_len;
obj_worker->list_move = nullptr;
if (obj_bench.position_mode == POSITION_MODE_RAND) {
obj_worker->fn_positions = random_positions();
if (obj_worker->fn_positions == nullptr)
goto err;
}
if (obj_bench.fn_init(worker, n_elm, list_len) != 0)
goto err_positions;
return 0;
err_positions:
free(obj_worker->fn_positions);
err:
free(obj_worker);
return -1;
}
/*
* obj_insert_init_worker -- worker initialization functions of the obj_insert
* benchmark.
*/
static int
obj_insert_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
return obj_init_worker(worker, obj_bench.max_len, obj_bench.min_len);
}
/*
* obj_insert_new_init_worker -- worker initialization functions of the
* obj_insert_new benchmark.
*/
static int
obj_insert_new_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
return obj_init_worker(worker, obj_bench.min_len, obj_bench.min_len);
}
/*
* obj_remove_init_worker -- worker initialization functions of the obj_remove
* and obj_remove_free benchmarks.
*/
static int
obj_remove_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
return obj_init_worker(worker, obj_bench.max_len, obj_bench.max_len);
}
/*
* obj_move_init_worker -- worker initialization functions of the obj_move
* benchmark.
*/
static int
obj_move_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
if (obj_init_worker(worker, obj_bench.max_len, obj_bench.max_len) != 0)
return -1;
auto *obj_worker = (struct obj_worker *)worker->priv;
obj_worker->list_move =
(struct obj_worker *)calloc(1, sizeof(struct obj_worker));
if (obj_worker->list_move == nullptr) {
perror("calloc");
goto free;
}
size_t i;
if (obj_bench.position_mode == POSITION_MODE_RAND) {
obj_worker->list_move->fn_positions = random_positions();
if (obj_worker->list_move->fn_positions == nullptr)
goto free_list_move;
}
for (i = 0; i < obj_bench.min_len; i++) {
size_t size = obj_bench.alloc_sizes[i];
POBJ_LIST_INSERT_NEW_TAIL(obj_bench.pop,
&obj_worker->list_move->head, field,
size, nullptr, nullptr);
if (TOID_IS_NULL(POBJ_LIST_LAST(&obj_worker->list_move->head,
field))) {
perror("pmemobj_list_insert_new");
goto free_all;
}
}
return 0;
free_all:
for (; i > 0; i--) {
POBJ_LIST_REMOVE_FREE(
obj_bench.pop, &obj_worker->list_move->head,
POBJ_LIST_LAST(&obj_worker->list_move->head, field),
field);
}
free(obj_worker->list_move->fn_positions);
free_list_move:
free(obj_worker->list_move);
free:
free_worker_list(bench, args, worker);
return -1;
}
/*
* obj_init - common part of the benchmark initialization for: obj_insert,
* obj_insert_new, obj_remove, obj_remove_free and obj_move used in their init
* functions. Parses command line arguments, sets variables and
* creates persistent pool.
*/
static int
obj_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
assert(args->opts != nullptr);
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
obj_bench.args = (struct obj_list_args *)args->opts;
obj_bench.min_len = obj_bench.args->list_len + 1;
obj_bench.max_len = args->n_ops_per_thread + obj_bench.min_len;
obj_bench.fn_init =
obj_bench.args->queue ? queue_init_list : obj_init_list;
/* Decide if use random or state allocation sizes */
size_t obj_size = args->dsize < sizeof(struct item)
? sizeof(struct item)
: args->dsize;
size_t min_size = obj_bench.args->min_size < sizeof(struct item)
? sizeof(struct item)
: obj_bench.args->min_size;
obj_bench.alloc_sizes = random_values(
min_size, obj_size, obj_bench.max_len, sizeof(struct item));
if (obj_bench.alloc_sizes == nullptr)
goto free_random_types;
/* Decide where operations will be performed */
obj_bench.position_mode =
parse_args(obj_bench.args->position, POSITION_MODE_UNKNOWN,
position_names);
if (obj_bench.position_mode == POSITION_MODE_UNKNOWN)
goto free_all;
obj_bench.fn_position = positions[obj_bench.position_mode];
if (!obj_bench.args->queue) {
/* Decide what type number will be used */
obj_bench.type_mode =
parse_args(obj_bench.args->type_num, TYPE_MODE_UNKNOWN,
type_num_names);
if (obj_bench.type_mode == TYPE_MODE_UNKNOWN)
return -1;
obj_bench.fn_type_num = type_num_modes[obj_bench.type_mode];
if (obj_bench.type_mode == TYPE_MODE_RAND) {
obj_bench.random_types = random_values(
1, UINT32_MAX, obj_bench.max_len, 0);
if (obj_bench.random_types == nullptr)
return -1;
}
/*
* Multiplication by FACTOR prevents from out of memory error
* as the actual size of the allocated persistent objects
* is always larger than requested.
*/
size_t psize =
(args->n_ops_per_thread + obj_bench.min_len + 1) *
obj_size * args->n_threads * FACTOR;
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < psize) {
fprintf(stderr, "file size too large\n");
goto free_all;
}
psize = 0;
} else if (psize < PMEMOBJ_MIN_POOL) {
psize = PMEMOBJ_MIN_POOL;
}
/* Create pmemobj pool. */
if ((obj_bench.pop = pmemobj_create(args->fname, LAYOUT_NAME,
psize, args->fmode)) ==
nullptr) {
perror(pmemobj_errormsg());
goto free_all;
}
}
return 0;
free_all:
free(obj_bench.alloc_sizes);
free_random_types:
if (obj_bench.type_mode == TYPE_MODE_RAND)
free(obj_bench.random_types);
return -1;
}
/*
* obj_exit -- common part for the exit function for: obj_insert,
* obj_insert_new, obj_remove, obj_remove_free and obj_move used in their exit
* functions.
*/
static int
obj_exit(struct benchmark *bench, struct benchmark_args *args)
{
if (!obj_bench.args->queue) {
pmemobj_close(obj_bench.pop);
if (obj_bench.type_mode == TYPE_MODE_RAND)
free(obj_bench.random_types);
}
free(obj_bench.alloc_sizes);
return 0;
}
/* obj_list_clo -- array defining common command line arguments. */
static struct benchmark_clo obj_list_clo[6];
static struct benchmark_info obj_insert;
static struct benchmark_info obj_remove;
static struct benchmark_info obj_insert_new;
static struct benchmark_info obj_remove_free;
static struct benchmark_info obj_move;
CONSTRUCTOR(pmem_atomic_list_constructor)
void
pmem_atomic_list_constructor(void)
{
obj_list_clo[0].opt_short = 'T';
obj_list_clo[0].opt_long = "type-number";
obj_list_clo[0].descr = "Type number mode - one, per-thread, "
"rand";
obj_list_clo[0].def = "one";
obj_list_clo[0].off = clo_field_offset(struct obj_list_args, type_num);
obj_list_clo[0].type = CLO_TYPE_STR;
obj_list_clo[1].opt_short = 'P';
obj_list_clo[1].opt_long = "position";
obj_list_clo[1].descr = "Place where operation will be "
"performed - head, tail, rand, middle";
obj_list_clo[1].def = "middle";
obj_list_clo[1].off = clo_field_offset(struct obj_list_args, position);
obj_list_clo[1].type = CLO_TYPE_STR;
obj_list_clo[2].opt_short = 'l';
obj_list_clo[2].opt_long = "list-len";
obj_list_clo[2].type = CLO_TYPE_UINT;
obj_list_clo[2].descr = "Initial list len";
obj_list_clo[2].off = clo_field_offset(struct obj_list_args, list_len);
obj_list_clo[2].def = "1";
obj_list_clo[2].type_uint.size =
clo_field_size(struct obj_list_args, list_len);
obj_list_clo[2].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
obj_list_clo[2].type_uint.min = 1;
obj_list_clo[2].type_uint.max = ULONG_MAX;
obj_list_clo[3].opt_short = 'm';
obj_list_clo[3].opt_long = "min-size";
obj_list_clo[3].type = CLO_TYPE_UINT;
obj_list_clo[3].descr = "Min allocation size";
obj_list_clo[3].off = clo_field_offset(struct obj_list_args, min_size);
obj_list_clo[3].def = "0";
obj_list_clo[3].type_uint.size =
clo_field_size(struct obj_list_args, min_size);
obj_list_clo[3].type_uint.base = CLO_INT_BASE_DEC;
obj_list_clo[3].type_uint.min = 0;
obj_list_clo[3].type_uint.max = UINT_MAX;
obj_list_clo[4].opt_short = 's';
obj_list_clo[4].type_uint.max = INT_MAX;
obj_list_clo[4].opt_long = "seed";
obj_list_clo[4].type = CLO_TYPE_UINT;
obj_list_clo[4].descr = "Seed value";
obj_list_clo[4].off = clo_field_offset(struct obj_list_args, seed);
obj_list_clo[4].def = "0";
obj_list_clo[4].type_uint.size =
clo_field_size(struct obj_list_args, seed);
obj_list_clo[4].type_uint.base = CLO_INT_BASE_DEC;
obj_list_clo[4].type_uint.min = 0;
/*
* nclos field in benchmark_info structures is decremented to make
* queue option available only for obj_isert, obj_remove
*/
obj_list_clo[5].opt_short = 'q';
obj_list_clo[5].opt_long = "queue";
obj_list_clo[5].descr = "Use circleq from queue.h instead "
"pmemobj";
obj_list_clo[5].type = CLO_TYPE_FLAG;
obj_list_clo[5].off = clo_field_offset(struct obj_list_args, queue);
obj_insert.name = "obj_insert";
obj_insert.brief = "pmemobj_list_insert() benchmark";
obj_insert.init = obj_init;
obj_insert.exit = obj_exit;
obj_insert.multithread = true;
obj_insert.multiops = true;
obj_insert.init_worker = obj_insert_init_worker;
obj_insert.free_worker = free_worker_items;
obj_insert.operation = insert_op;
obj_insert.measure_time = true;
obj_insert.clos = obj_list_clo;
obj_insert.nclos = ARRAY_SIZE(obj_list_clo);
obj_insert.opts_size = sizeof(struct obj_list_args);
obj_insert.rm_file = true;
obj_insert.allow_poolset = true;
REGISTER_BENCHMARK(obj_insert);
obj_remove.name = "obj_remove";
obj_remove.brief = "pmemobj_list_remove() benchmark "
"without freeing element";
obj_remove.init = obj_init;
obj_remove.exit = obj_exit;
obj_remove.multithread = true;
obj_remove.multiops = true;
obj_remove.init_worker = obj_remove_init_worker;
obj_remove.free_worker = free_worker_items;
obj_remove.operation = remove_op;
obj_remove.measure_time = true;
obj_remove.clos = obj_list_clo;
obj_remove.nclos = ARRAY_SIZE(obj_list_clo);
obj_remove.opts_size = sizeof(struct obj_list_args);
obj_remove.rm_file = true;
obj_remove.allow_poolset = true;
REGISTER_BENCHMARK(obj_remove);
obj_insert_new.name = "obj_insert_new";
obj_insert_new.brief = "pmemobj_list_insert_new() benchmark";
obj_insert_new.init = obj_init;
obj_insert_new.exit = obj_exit;
obj_insert_new.multithread = true;
obj_insert_new.multiops = true;
obj_insert_new.init_worker = obj_insert_new_init_worker;
obj_insert_new.free_worker = free_worker_list;
obj_insert_new.operation = obj_insert_new_op;
obj_insert_new.measure_time = true;
obj_insert_new.clos = obj_list_clo;
obj_insert_new.nclos = ARRAY_SIZE(obj_list_clo) - 1;
obj_insert_new.opts_size = sizeof(struct obj_list_args);
obj_insert_new.rm_file = true;
obj_insert_new.allow_poolset = true;
REGISTER_BENCHMARK(obj_insert_new);
obj_remove_free.name = "obj_remove_free";
obj_remove_free.brief = "pmemobj_list_remove() benchmark "
"with freeing element";
obj_remove_free.init = obj_init;
obj_remove_free.exit = obj_exit;
obj_remove_free.multithread = true;
obj_remove_free.multiops = true;
obj_remove_free.init_worker = obj_remove_init_worker;
obj_remove_free.free_worker = free_worker_list;
obj_remove_free.operation = obj_remove_free_op;
obj_remove_free.measure_time = true;
obj_remove_free.clos = obj_list_clo;
obj_remove_free.nclos = ARRAY_SIZE(obj_list_clo) - 1;
obj_remove_free.opts_size = sizeof(struct obj_list_args);
obj_remove_free.rm_file = true;
obj_remove_free.allow_poolset = true;
REGISTER_BENCHMARK(obj_remove_free);
obj_move.name = "obj_move";
obj_move.brief = "pmemobj_list_move() benchmark";
obj_move.init = obj_init;
obj_move.exit = obj_exit;
obj_move.multithread = true;
obj_move.multiops = true;
obj_move.init_worker = obj_move_init_worker;
obj_move.free_worker = obj_move_free_worker;
obj_move.operation = obj_move_op;
obj_move.measure_time = true;
obj_move.clos = obj_list_clo;
obj_move.nclos = ARRAY_SIZE(obj_list_clo) - 1;
obj_move.opts_size = sizeof(struct obj_list_args);
obj_move.rm_file = true;
obj_move.allow_poolset = true;
REGISTER_BENCHMARK(obj_move);
}
| 31,463 | 27.734247 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/config_reader.hpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2017, Intel Corporation */
/*
* config_reader.hpp -- config reader module declarations
*/
struct config_reader;
struct config_reader *config_reader_alloc(void);
int config_reader_read(struct config_reader *cr, const char *fname);
void config_reader_free(struct config_reader *cr);
int config_reader_get_scenarios(struct config_reader *cr,
struct scenarios **scenarios);
| 436 | 32.615385 | 68 | hpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/benchmark_worker.hpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2017, Intel Corporation */
/*
* benchmark_worker.hpp -- benchmark_worker module declarations
*/
#include "benchmark.hpp"
#include "os_thread.h"
/*
*
* The following table shows valid state transitions upon specified
* API calls and operations performed by the worker thread:
*
* +========================+==========================+=============+
* | Application | State | Worker |
* +========================+==========================+=============+
* | benchmark_worker_alloc | WORKER_STATE_IDLE | wait |
* +------------------------+--------------------------+-------------+
* | benchmark_worker_init | WORKER_STATE_INIT | invoke init |
* +------------------------+--------------------------+-------------+
* | wait | WORKER_STATE_INITIALIZED | end of init |
* +------------------------+--------------------------+-------------+
* | benchmark_worker_run | WORKER_STATE_RUN | invoke func |
* +------------------------+--------------------------+-------------+
* | benchmark_worker_join | WORKER_STATE_END | end of func |
* +------------------------+--------------------------+-------------+
* | benchmark_worker_exit | WORKER_STATE_EXIT | invoke exit |
* +------------------------+--------------------------+-------------+
* | wait | WORKER_STATE_DONE | end of exit |
* +------------------------+--------------------------+-------------+
*/
enum benchmark_worker_state {
WORKER_STATE_IDLE,
WORKER_STATE_INIT,
WORKER_STATE_INITIALIZED,
WORKER_STATE_RUN,
WORKER_STATE_END,
WORKER_STATE_EXIT,
WORKER_STATE_DONE,
MAX_WORKER_STATE,
};
struct benchmark_worker {
os_thread_t thread;
struct benchmark *bench;
struct benchmark_args *args;
struct worker_info info;
int ret;
int ret_init;
int (*func)(struct benchmark *bench, struct worker_info *info);
int (*init)(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *info);
void (*exit)(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *info);
os_cond_t cond;
os_mutex_t lock;
enum benchmark_worker_state state;
};
struct benchmark_worker *benchmark_worker_alloc(void);
void benchmark_worker_free(struct benchmark_worker *);
int benchmark_worker_init(struct benchmark_worker *);
void benchmark_worker_exit(struct benchmark_worker *);
int benchmark_worker_run(struct benchmark_worker *);
int benchmark_worker_join(struct benchmark_worker *);
| 2,576 | 36.897059 | 70 | hpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/clo_vec.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* clo_vec.cpp -- command line options vector definitions
*/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include "clo_vec.hpp"
/*
* clo_vec_alloc -- allocate new CLO vector
*/
struct clo_vec *
clo_vec_alloc(size_t size)
{
struct clo_vec *clovec = (struct clo_vec *)malloc(sizeof(*clovec));
assert(clovec != nullptr);
/* init list of arguments and allocations */
PMDK_TAILQ_INIT(&clovec->allocs);
PMDK_TAILQ_INIT(&clovec->args);
clovec->nallocs = 0;
/* size of each struct */
clovec->size = size;
/* add first struct to list */
struct clo_vec_args *args =
(struct clo_vec_args *)malloc(sizeof(*args));
assert(args != nullptr);
args->args = calloc(1, size);
assert(args->args != nullptr);
PMDK_TAILQ_INSERT_TAIL(&clovec->args, args, next);
clovec->nargs = 1;
return clovec;
}
/*
* clo_vec_free -- free CLO vector and all allocations
*/
void
clo_vec_free(struct clo_vec *clovec)
{
assert(clovec != nullptr);
/* free all allocations */
while (!PMDK_TAILQ_EMPTY(&clovec->allocs)) {
struct clo_vec_alloc *alloc = PMDK_TAILQ_FIRST(&clovec->allocs);
PMDK_TAILQ_REMOVE(&clovec->allocs, alloc, next);
free(alloc->ptr);
free(alloc);
}
/* free all arguments */
while (!PMDK_TAILQ_EMPTY(&clovec->args)) {
struct clo_vec_args *args = PMDK_TAILQ_FIRST(&clovec->args);
PMDK_TAILQ_REMOVE(&clovec->args, args, next);
free(args->args);
free(args);
}
free(clovec);
}
/*
* clo_vec_get_args -- return pointer to CLO arguments at specified index
*/
void *
clo_vec_get_args(struct clo_vec *clovec, size_t i)
{
if (i >= clovec->nargs)
return nullptr;
size_t c = 0;
struct clo_vec_args *args;
PMDK_TAILQ_FOREACH(args, &clovec->args, next)
{
if (c == i)
return args->args;
c++;
}
return nullptr;
}
/*
* clo_vec_add_alloc -- add allocation to CLO vector
*/
int
clo_vec_add_alloc(struct clo_vec *clovec, void *ptr)
{
struct clo_vec_alloc *alloc =
(struct clo_vec_alloc *)malloc(sizeof(*alloc));
assert(alloc != nullptr);
alloc->ptr = ptr;
PMDK_TAILQ_INSERT_TAIL(&clovec->allocs, alloc, next);
clovec->nallocs++;
return 0;
}
/*
* clo_vec_grow -- (internal) grow in size the CLO vector
*/
static void
clo_vec_grow(struct clo_vec *clovec, size_t new_len)
{
size_t nargs = new_len - clovec->nargs;
size_t i;
for (i = 0; i < nargs; i++) {
struct clo_vec_args *args =
(struct clo_vec_args *)calloc(1, sizeof(*args));
assert(args != nullptr);
PMDK_TAILQ_INSERT_TAIL(&clovec->args, args, next);
args->args = malloc(clovec->size);
assert(args->args != nullptr);
void *argscpy = clo_vec_get_args(clovec, i % clovec->nargs);
assert(argscpy != nullptr);
memcpy(args->args, argscpy, clovec->size);
}
clovec->nargs = new_len;
}
/*
* clo_vec_vlist_alloc -- allocate list of values
*/
struct clo_vec_vlist *
clo_vec_vlist_alloc(void)
{
struct clo_vec_vlist *list =
(struct clo_vec_vlist *)malloc(sizeof(*list));
assert(list != nullptr);
list->nvalues = 0;
PMDK_TAILQ_INIT(&list->head);
return list;
}
/*
* clo_vec_vlist_free -- release list of values
*/
void
clo_vec_vlist_free(struct clo_vec_vlist *list)
{
assert(list != nullptr);
while (!PMDK_TAILQ_EMPTY(&list->head)) {
struct clo_vec_value *val = PMDK_TAILQ_FIRST(&list->head);
PMDK_TAILQ_REMOVE(&list->head, val, next);
free(val->ptr);
free(val);
}
free(list);
}
/*
* clo_vec_vlist_add -- add value to list
*/
void
clo_vec_vlist_add(struct clo_vec_vlist *list, void *ptr, size_t size)
{
struct clo_vec_value *val =
(struct clo_vec_value *)malloc(sizeof(*val));
assert(val != nullptr);
val->ptr = malloc(size);
assert(val->ptr != nullptr);
memcpy(val->ptr, ptr, size);
PMDK_TAILQ_INSERT_TAIL(&list->head, val, next);
list->nvalues++;
}
/*
* clo_vec_memcpy -- copy value to CLO vector
*
* - clovec - CLO vector
* - off - offset to value in structure
* - size - size of value field
* - ptr - pointer to value
*/
int
clo_vec_memcpy(struct clo_vec *clovec, size_t off, size_t size, void *ptr)
{
if (off + size > clovec->size)
return -1;
size_t i;
for (i = 0; i < clovec->nargs; i++) {
auto *args = (char *)clo_vec_get_args(clovec, i);
char *dptr = args + off;
memcpy(dptr, ptr, size);
}
return 0;
}
/*
* clo_vec_memcpy_list -- copy values from list to CLO vector
*
* - clovec - CLO vector
* - off - offset to value in structure
* - size - size of value field
* - list - list of values
*/
int
clo_vec_memcpy_list(struct clo_vec *clovec, size_t off, size_t size,
struct clo_vec_vlist *list)
{
if (off + size > clovec->size)
return -1;
size_t len = clovec->nargs;
if (list->nvalues > 1)
clo_vec_grow(clovec, clovec->nargs * list->nvalues);
struct clo_vec_value *value;
size_t value_i = 0;
size_t i;
PMDK_TAILQ_FOREACH(value, &list->head, next)
{
for (i = value_i * len; i < (value_i + 1) * len; i++) {
auto *args = (char *)clo_vec_get_args(clovec, i);
char *dptr = args + off;
memcpy(dptr, value->ptr, size);
}
value_i++;
}
return 0;
}
| 5,100 | 19.322709 | 74 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/poolset_util.hpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018, Intel Corporation */
/*
* poolset_util.hpp -- this file provides interface for creating
* poolsets of specified size
*/
#ifndef POOLSET_UTIL_HPP
#define POOLSET_UTIL_HPP
#include <stddef.h>
#define POOLSET_PATH "pool.set"
int dynamic_poolset_create(const char *path, size_t size);
#endif
| 356 | 18.833333 | 64 | hpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/scenario.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* scenario.cpp -- scenario module definitions
*/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include "queue.h"
#include "scenario.hpp"
/*
* kv_alloc -- allocate key/value structure
*/
struct kv *
kv_alloc(const char *key, const char *value)
{
struct kv *kv = (struct kv *)malloc(sizeof(*kv));
assert(kv != nullptr);
kv->key = strdup(key);
assert(kv->key != nullptr);
kv->value = strdup(value);
assert(kv->value != nullptr);
return kv;
}
/*
* kv_free -- free the key/value structure
*/
void
kv_free(struct kv *kv)
{
assert(kv != nullptr);
free(kv->key);
free(kv->value);
free(kv);
}
/*
* scenario_alloc -- allocate scenario structure
*/
struct scenario *
scenario_alloc(const char *name, const char *bench)
{
struct scenario *s = (struct scenario *)malloc(sizeof(*s));
assert(s != nullptr);
PMDK_TAILQ_INIT(&s->head);
s->name = strdup(name);
assert(s->name != nullptr);
s->benchmark = strdup(bench);
assert(s->benchmark != nullptr);
s->group = nullptr;
return s;
}
/*
* scenario_free -- free the scenario structure and all its content
*/
void
scenario_free(struct scenario *s)
{
assert(s != nullptr);
while (!PMDK_TAILQ_EMPTY(&s->head)) {
struct kv *kv = PMDK_TAILQ_FIRST(&s->head);
PMDK_TAILQ_REMOVE(&s->head, kv, next);
kv_free(kv);
}
free(s->group);
free(s->name);
free(s->benchmark);
free(s);
}
/*
* scenario_set_group -- set group of scenario
*/
void
scenario_set_group(struct scenario *s, const char *group)
{
assert(s != nullptr);
s->group = strdup(group);
}
/*
* scenarios_alloc -- allocate scenarios structure
*/
struct scenarios *
scenarios_alloc(void)
{
struct scenarios *scenarios =
(struct scenarios *)malloc(sizeof(*scenarios));
assert(nullptr != scenarios);
PMDK_TAILQ_INIT(&scenarios->head);
return scenarios;
}
/*
* scenarios_free -- free scenarios structure and all its content
*/
void
scenarios_free(struct scenarios *scenarios)
{
assert(scenarios != nullptr);
while (!PMDK_TAILQ_EMPTY(&scenarios->head)) {
struct scenario *sce = PMDK_TAILQ_FIRST(&scenarios->head);
PMDK_TAILQ_REMOVE(&scenarios->head, sce, next);
scenario_free(sce);
}
free(scenarios);
}
/*
* scenarios_get_scenario -- get scenario of given name
*/
struct scenario *
scenarios_get_scenario(struct scenarios *ss, const char *name)
{
struct scenario *scenario;
FOREACH_SCENARIO(scenario, ss)
{
if (strcmp(scenario->name, name) == 0)
return scenario;
}
return nullptr;
}
/*
* contains_scenarios -- check if cmd line args contain any scenarios from ss
*/
bool
contains_scenarios(int argc, char **argv, struct scenarios *ss)
{
assert(argv != nullptr);
assert(argc > 0);
assert(ss != nullptr);
for (int i = 0; i < argc; i++) {
if (scenarios_get_scenario(ss, argv[i]))
return true;
}
return false;
}
/*
* clone_scenario -- alloc a new scenario and copy all data from src scenario
*/
struct scenario *
clone_scenario(struct scenario *src_scenario)
{
assert(src_scenario != nullptr);
struct scenario *new_scenario =
scenario_alloc(src_scenario->name, src_scenario->benchmark);
assert(new_scenario != nullptr);
struct kv *src_kv;
FOREACH_KV(src_kv, src_scenario)
{
struct kv *new_kv = kv_alloc(src_kv->key, src_kv->value);
assert(new_kv != nullptr);
PMDK_TAILQ_INSERT_TAIL(&new_scenario->head, new_kv, next);
}
return new_scenario;
}
/*
* find_kv_in_scenario - find a kv in the given scenario with the given key
* value. Function returns the pointer to the kv structure containing the key or
* nullptr if it is not found
*/
struct kv *
find_kv_in_scenario(const char *key, const struct scenario *scenario)
{
struct kv *kv;
FOREACH_KV(kv, scenario)
{
if (strcmp(kv->key, key) == 0)
return kv;
}
return nullptr;
}
| 3,844 | 18.419192 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/config_reader.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* config_reader.cpp -- config reader module definitions
*/
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <glib.h>
#include <sys/queue.h>
#include "config_reader.hpp"
#include "scenario.hpp"
#define SECTION_GLOBAL "global"
#define KEY_BENCHMARK "bench"
#define KEY_GROUP "group"
/*
* config_reader -- handle structure
*/
struct config_reader {
GKeyFile *key_file;
};
/*
* config_reader_alloc -- allocate config reader
*/
struct config_reader *
config_reader_alloc(void)
{
struct config_reader *cr = (struct config_reader *)malloc(sizeof(*cr));
assert(cr != nullptr);
cr->key_file = g_key_file_new();
if (!cr->key_file)
goto err;
return cr;
err:
free(cr);
return nullptr;
}
/*
* config_reader_read -- read config file
*/
int
config_reader_read(struct config_reader *cr, const char *fname)
{
if (g_key_file_load_from_file(cr->key_file, fname, G_KEY_FILE_NONE,
nullptr) != TRUE)
return -1;
return 0;
}
/*
* config_reader_free -- free config reader
*/
void
config_reader_free(struct config_reader *cr)
{
g_key_file_free(cr->key_file);
free(cr);
}
/*
* is_scenario -- (internal) return true if _name_ is scenario name
*
* This filters out the _global_ and _config_ sections.
*/
static int
is_scenario(const char *name)
{
return strcmp(name, SECTION_GLOBAL);
}
/*
* is_argument -- (internal) return true if _name_ is argument name
*
* This filters out the _benchmark_ key.
*/
static int
is_argument(const char *name)
{
return strcmp(name, KEY_BENCHMARK) != 0 && strcmp(name, KEY_GROUP) != 0;
}
/*
* config_reader_get_scenarios -- return scenarios from config file
*
* This function reads the config file and returns a list of scenarios.
* Each scenario contains a list of key/value arguments.
* The scenario's arguments are merged with arguments from global section.
*/
int
config_reader_get_scenarios(struct config_reader *cr,
struct scenarios **scenarios)
{
/*
* Read all groups.
* The config file must have at least one group, otherwise
* it is considered as invalid.
*/
gsize ngroups;
gsize g;
gchar **groups = g_key_file_get_groups(cr->key_file, &ngroups);
assert(nullptr != groups);
if (!groups)
return -1;
/*
* Check if global section is present and read keys from it.
*/
int ret = 0;
int has_global =
g_key_file_has_group(cr->key_file, SECTION_GLOBAL) == TRUE;
gsize ngkeys;
gchar **gkeys = nullptr;
struct scenarios *s;
if (has_global) {
gkeys = g_key_file_get_keys(cr->key_file, SECTION_GLOBAL,
&ngkeys, nullptr);
assert(nullptr != gkeys);
if (!gkeys) {
ret = -1;
goto err_groups;
}
}
s = scenarios_alloc();
assert(nullptr != s);
if (!s) {
ret = -1;
goto err_gkeys;
}
for (g = 0; g < ngroups; g++) {
/*
* Check whether a group is a scenario
* or global section.
*/
if (!is_scenario(groups[g]))
continue;
/*
* Check for KEY_BENCHMARK which contains benchmark name.
* If not present the benchmark name is the same as the
* name of the section.
*/
struct scenario *scenario = nullptr;
if (g_key_file_has_key(cr->key_file, groups[g], KEY_BENCHMARK,
nullptr) == FALSE) {
scenario = scenario_alloc(groups[g], groups[g]);
assert(scenario != nullptr);
} else {
gchar *benchmark =
g_key_file_get_value(cr->key_file, groups[g],
KEY_BENCHMARK, nullptr);
assert(benchmark != nullptr);
if (!benchmark) {
ret = -1;
goto err_scenarios;
}
scenario = scenario_alloc(groups[g], benchmark);
assert(scenario != nullptr);
free(benchmark);
}
gsize k;
if (has_global) {
/*
* Merge key/values from global section.
*/
for (k = 0; k < ngkeys; k++) {
if (g_key_file_has_key(cr->key_file, groups[g],
gkeys[k],
nullptr) == TRUE)
continue;
if (!is_argument(gkeys[k]))
continue;
char *value = g_key_file_get_value(
cr->key_file, SECTION_GLOBAL, gkeys[k],
nullptr);
assert(nullptr != value);
if (!value) {
ret = -1;
goto err_scenarios;
}
struct kv *kv = kv_alloc(gkeys[k], value);
assert(nullptr != kv);
free(value);
if (!kv) {
ret = -1;
goto err_scenarios;
}
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv,
next);
}
}
/* check for group name */
if (g_key_file_has_key(cr->key_file, groups[g], KEY_GROUP,
nullptr) != FALSE) {
gchar *group = g_key_file_get_value(
cr->key_file, groups[g], KEY_GROUP, nullptr);
assert(group != nullptr);
scenario_set_group(scenario, group);
} else if (g_key_file_has_key(cr->key_file, SECTION_GLOBAL,
KEY_GROUP, nullptr) != FALSE) {
gchar *group = g_key_file_get_value(cr->key_file,
SECTION_GLOBAL,
KEY_GROUP, nullptr);
scenario_set_group(scenario, group);
}
gsize nkeys;
gchar **keys = g_key_file_get_keys(cr->key_file, groups[g],
&nkeys, nullptr);
assert(nullptr != keys);
if (!keys) {
ret = -1;
goto err_scenarios;
}
/*
* Read key/values from the scenario's section.
*/
for (k = 0; k < nkeys; k++) {
if (!is_argument(keys[k]))
continue;
char *value = g_key_file_get_value(
cr->key_file, groups[g], keys[k], nullptr);
assert(nullptr != value);
if (!value) {
ret = -1;
g_strfreev(keys);
goto err_scenarios;
}
struct kv *kv = kv_alloc(keys[k], value);
assert(nullptr != kv);
free(value);
if (!kv) {
g_strfreev(keys);
ret = -1;
goto err_scenarios;
}
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv, next);
}
g_strfreev(keys);
PMDK_TAILQ_INSERT_TAIL(&s->head, scenario, next);
}
g_strfreev(gkeys);
g_strfreev(groups);
*scenarios = s;
return 0;
err_scenarios:
scenarios_free(s);
err_gkeys:
g_strfreev(gkeys);
err_groups:
g_strfreev(groups);
return ret;
}
| 5,961 | 20.292857 | 74 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/pmemobj_gen.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* pmemobj_gen.cpp -- benchmark for pmemobj_direct()
* and pmemobj_open() functions.
*/
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <file.h>
#include <sys/stat.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "libpmemobj.h"
#define LAYOUT_NAME "benchmark"
#define FACTOR 4
#define DIR_MODE 0700
#define FILE_MODE 0666
#define PART_NAME "/part"
#define MAX_DIGITS 2
struct pobj_bench;
struct pobj_worker;
typedef size_t (*fn_type_num_t)(struct pobj_bench *ob, size_t worker_idx,
size_t op_idx);
typedef size_t (*fn_size_t)(struct pobj_bench *ob, size_t idx);
typedef size_t (*fn_num_t)(size_t idx);
/*
* Enumeration used to determine the mode of the assigning type_number
* value to the persistent objects.
*/
enum type_mode {
TYPE_MODE_ONE,
TYPE_MODE_PER_THREAD,
TYPE_MODE_RAND,
MAX_TYPE_MODE,
};
/*
* pobj_args - Stores command line parsed arguments.
*
* rand_type : Use random type number for every new allocated object.
* Default, there is one type number for all objects.
*
* range : Use random allocation size.
*
* min_size : Minimum allocation size.
*
* n_objs : Number of objects allocated per thread
*
* one_pool : Use one common pool for all thread
*
* one_obj : Create and use one object per thread
*
* obj_size : Size of each allocated object
*
* n_ops : Number of operations
*/
struct pobj_args {
char *type_num;
bool range;
unsigned min_size;
size_t n_objs;
bool one_pool;
bool one_obj;
size_t obj_size;
size_t n_ops;
};
/*
* pobj_bench - Stores variables used in benchmark, passed within functions.
*
* pop : Pointer to the persistent pool.
*
* pa : Stores pobj_args structure.
*
* sets : Stores files names using to create pool per thread
*
* random_types : Random type numbers for persistent objects.
*
* rand_sizes : random values with allocation sizes.
*
* n_pools : Number of created pools.
*
* n_objs : Number of object created per thread.
*
* type_mode : Type_mode enum value
*
* fn_type_num : Function returning proper type number for each object.
*
* fn_size : Function returning proper size of allocation.
*
* pool : Functions returning number of thread if
* one pool per thread created or index 0 if not.
*
* obj : Function returning number of operation if flag set
* to false or index 0 if set to true.
*/
struct pobj_bench {
PMEMobjpool **pop;
struct pobj_args *args_priv;
const char **sets;
size_t *random_types;
size_t *rand_sizes;
size_t n_pools;
int type_mode;
fn_type_num_t fn_type_num;
fn_size_t fn_size;
fn_num_t pool;
fn_num_t obj;
};
/*
* pobj_worker - Stores variables used by one thread.
*/
struct pobj_worker {
PMEMoid *oids;
};
/*
* type_mode_one -- always returns 0, as in the mode TYPE_MODE_ONE
* all of the persistent objects have the same type_number value.
*/
static size_t
type_mode_one(struct pobj_bench *bench_priv, size_t worker_idx, size_t op_idx)
{
return 0;
}
/*
* type_mode_per_thread -- always returns worker index, as in the mode
* TYPE_MODE_PER_THREAD all persistent object allocated by the same thread
* have the same type_number value.
*/
static size_t
type_mode_per_thread(struct pobj_bench *bench_priv, size_t worker_idx,
size_t op_idx)
{
return worker_idx;
}
/*
* type_mode_rand -- returns the value from the random_types array assigned
* for the specific operation in a specific thread.
*/
static size_t
type_mode_rand(struct pobj_bench *bench_priv, size_t worker_idx, size_t op_idx)
{
return bench_priv->random_types[op_idx];
}
/*
* range_size -- returns size of object allocation from rand_sizes array.
*/
static size_t
range_size(struct pobj_bench *bench_priv, size_t idx)
{
return bench_priv->rand_sizes[idx];
}
/*
* static_size -- returns always the same size of object allocation.
*/
static size_t
static_size(struct pobj_bench *bench_priv, size_t idx)
{
return bench_priv->args_priv->obj_size;
}
/*
* diff_num -- returns given index
*/
static size_t
diff_num(size_t idx)
{
return idx;
}
/*
* one_num -- returns always the same index.
*/
static size_t
one_num(size_t idx)
{
return 0;
}
static fn_type_num_t type_mode_func[MAX_TYPE_MODE] = {
type_mode_one, type_mode_per_thread, type_mode_rand};
const char *type_mode_names[MAX_TYPE_MODE] = {"one", "per-thread", "rand"};
/*
* parse_type_mode -- parses command line "--type-number" argument
* and returns proper type_mode enum value.
*/
static enum type_mode
parse_type_mode(const char *arg)
{
enum type_mode i = TYPE_MODE_ONE;
for (; i < MAX_TYPE_MODE && strcmp(arg, type_mode_names[i]) != 0;
i = (enum type_mode)(i + 1))
;
return i;
}
/*
* rand_sizes -- allocates array and calculates random values as allocation
* sizes for each object. Used only when range flag set.
*/
static size_t *
rand_sizes(size_t min, size_t max, size_t n_ops)
{
assert(n_ops != 0);
auto *rand_sizes = (size_t *)malloc(n_ops * sizeof(size_t));
if (rand_sizes == nullptr) {
perror("malloc");
return nullptr;
}
for (size_t i = 0; i < n_ops; i++) {
rand_sizes[i] = RRAND(max, min);
}
return rand_sizes;
}
/*
* random_types -- allocates array and calculates random values to assign
* type_number for each object.
*/
static int
random_types(struct pobj_bench *bench_priv, struct benchmark_args *args)
{
assert(bench_priv->args_priv->n_objs != 0);
bench_priv->random_types = (size_t *)malloc(
bench_priv->args_priv->n_objs * sizeof(size_t));
if (bench_priv->random_types == nullptr) {
perror("malloc");
return -1;
}
for (size_t i = 0; i < bench_priv->args_priv->n_objs; i++)
bench_priv->random_types[i] = rand() % UINT32_MAX;
return 0;
}
/*
* pobj_init - common part of the benchmark initialization functions.
* Parses command line arguments, set variables and creates persistent pools.
*/
static int
pobj_init(struct benchmark *bench, struct benchmark_args *args)
{
unsigned i = 0;
size_t psize;
size_t n_objs;
assert(bench != nullptr);
assert(args != nullptr);
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
auto *bench_priv =
(struct pobj_bench *)malloc(sizeof(struct pobj_bench));
if (bench_priv == nullptr) {
perror("malloc");
return -1;
}
assert(args->opts != nullptr);
bench_priv->args_priv = (struct pobj_args *)args->opts;
bench_priv->args_priv->obj_size = args->dsize;
bench_priv->args_priv->range =
bench_priv->args_priv->min_size > 0 ? true : false;
bench_priv->n_pools =
!bench_priv->args_priv->one_pool ? args->n_threads : 1;
bench_priv->pool = bench_priv->n_pools > 1 ? diff_num : one_num;
bench_priv->obj = !bench_priv->args_priv->one_obj ? diff_num : one_num;
if ((args->is_poolset || type == TYPE_DEVDAX) &&
bench_priv->n_pools > 1) {
fprintf(stderr,
"cannot use poolset nor device dax for multiple pools,"
" please use -P|--one-pool option instead");
goto free_bench_priv;
}
/*
* Multiplication by FACTOR prevents from out of memory error
* as the actual size of the allocated persistent objects
* is always larger than requested.
*/
n_objs = bench_priv->args_priv->n_objs;
if (bench_priv->n_pools == 1)
n_objs *= args->n_threads;
psize = PMEMOBJ_MIN_POOL +
n_objs * args->dsize * args->n_threads * FACTOR;
/* assign type_number determining function */
bench_priv->type_mode =
parse_type_mode(bench_priv->args_priv->type_num);
switch (bench_priv->type_mode) {
case MAX_TYPE_MODE:
fprintf(stderr, "unknown type mode");
goto free_bench_priv;
case TYPE_MODE_RAND:
if (random_types(bench_priv, args))
goto free_bench_priv;
break;
default:
bench_priv->random_types = nullptr;
}
bench_priv->fn_type_num = type_mode_func[bench_priv->type_mode];
/* assign size determining function */
bench_priv->fn_size =
bench_priv->args_priv->range ? range_size : static_size;
bench_priv->rand_sizes = nullptr;
if (bench_priv->args_priv->range) {
if (bench_priv->args_priv->min_size > args->dsize) {
fprintf(stderr, "Invalid allocation size");
goto free_random_types;
}
bench_priv->rand_sizes =
rand_sizes(bench_priv->args_priv->min_size,
bench_priv->args_priv->obj_size,
bench_priv->args_priv->n_objs);
if (bench_priv->rand_sizes == nullptr)
goto free_random_types;
}
assert(bench_priv->n_pools > 0);
bench_priv->pop = (PMEMobjpool **)calloc(bench_priv->n_pools,
sizeof(PMEMobjpool *));
if (bench_priv->pop == nullptr) {
perror("calloc");
goto free_random_sizes;
}
bench_priv->sets = (const char **)calloc(bench_priv->n_pools,
sizeof(const char *));
if (bench_priv->sets == nullptr) {
perror("calloc");
goto free_pop;
}
if (bench_priv->n_pools > 1) {
assert(!args->is_poolset);
if (util_file_mkdir(args->fname, DIR_MODE) != 0) {
fprintf(stderr, "cannot create directory\n");
goto free_sets;
}
size_t path_len = (strlen(PART_NAME) + strlen(args->fname)) +
MAX_DIGITS + 1;
for (i = 0; i < bench_priv->n_pools; i++) {
bench_priv->sets[i] =
(char *)malloc(path_len * sizeof(char));
if (bench_priv->sets[i] == nullptr) {
perror("malloc");
goto free_sets;
}
int ret = util_snprintf((char *)bench_priv->sets[i],
path_len, "%s%s%02x",
args->fname, PART_NAME, i);
if (ret < 0) {
perror("snprintf");
goto free_sets;
}
bench_priv->pop[i] =
pmemobj_create(bench_priv->sets[i], LAYOUT_NAME,
psize, FILE_MODE);
if (bench_priv->pop[i] == nullptr) {
perror(pmemobj_errormsg());
goto free_sets;
}
}
} else {
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < psize) {
fprintf(stderr, "file size too large\n");
goto free_pools;
}
psize = 0;
}
bench_priv->sets[0] = args->fname;
bench_priv->pop[0] = pmemobj_create(
bench_priv->sets[0], LAYOUT_NAME, psize, FILE_MODE);
if (bench_priv->pop[0] == nullptr) {
perror(pmemobj_errormsg());
goto free_pools;
}
}
pmembench_set_priv(bench, bench_priv);
return 0;
free_sets:
for (; i > 0; i--) {
pmemobj_close(bench_priv->pop[i - 1]);
free((char *)bench_priv->sets[i - 1]);
}
free_pools:
free(bench_priv->sets);
free_pop:
free(bench_priv->pop);
free_random_sizes:
free(bench_priv->rand_sizes);
free_random_types:
free(bench_priv->random_types);
free_bench_priv:
free(bench_priv);
return -1;
}
/*
* pobj_direct_init -- special part of pobj_direct benchmark initialization.
*/
static int
pobj_direct_init(struct benchmark *bench, struct benchmark_args *args)
{
auto *pa = (struct pobj_args *)args->opts;
pa->n_objs = pa->one_obj ? 1 : args->n_ops_per_thread;
if (pobj_init(bench, args) != 0)
return -1;
return 0;
}
/*
* pobj_exit -- common part for the benchmarks exit functions
*/
static int
pobj_exit(struct benchmark *bench, struct benchmark_args *args)
{
size_t i;
auto *bench_priv = (struct pobj_bench *)pmembench_get_priv(bench);
if (bench_priv->n_pools > 1) {
for (i = 0; i < bench_priv->n_pools; i++) {
pmemobj_close(bench_priv->pop[i]);
free((char *)bench_priv->sets[i]);
}
} else {
pmemobj_close(bench_priv->pop[0]);
}
free(bench_priv->sets);
free(bench_priv->pop);
free(bench_priv->rand_sizes);
free(bench_priv->random_types);
free(bench_priv);
return 0;
}
/*
* pobj_init_worker -- worker initialization
*/
static int
pobj_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
size_t i, idx = worker->index;
auto *bench_priv = (struct pobj_bench *)pmembench_get_priv(bench);
auto *pw = (struct pobj_worker *)calloc(1, sizeof(struct pobj_worker));
if (pw == nullptr) {
perror("calloc");
return -1;
}
worker->priv = pw;
pw->oids = (PMEMoid *)calloc(bench_priv->args_priv->n_objs,
sizeof(PMEMoid));
if (pw->oids == nullptr) {
free(pw);
perror("calloc");
return -1;
}
PMEMobjpool *pop = bench_priv->pop[bench_priv->pool(idx)];
for (i = 0; i < bench_priv->args_priv->n_objs; i++) {
size_t size = bench_priv->fn_size(bench_priv, i);
size_t type = bench_priv->fn_type_num(bench_priv, idx, i);
if (pmemobj_alloc(pop, &pw->oids[i], size, type, nullptr,
nullptr) != 0) {
perror("pmemobj_alloc");
goto out;
}
}
return 0;
out:
for (; i > 0; i--)
pmemobj_free(&pw->oids[i - 1]);
free(pw->oids);
free(pw);
return -1;
}
/*
* pobj_direct_op -- main operations of the obj_direct benchmark.
*/
static int
pobj_direct_op(struct benchmark *bench, struct operation_info *info)
{
auto *bench_priv = (struct pobj_bench *)pmembench_get_priv(bench);
auto *pw = (struct pobj_worker *)info->worker->priv;
size_t idx = bench_priv->obj(info->index);
/* Query an invalid uuid:off pair to invalidate the cache. */
PMEMoid bad = {1, 1};
#define OBJ_DIRECT_NITER 1024
/*
* As we measure a very fast operation, we need a loop inside the
* test harness.
*/
for (int i = 0; i < OBJ_DIRECT_NITER; i++) {
if (pmemobj_direct(pw->oids[idx]) == nullptr)
return -1;
if (pmemobj_direct(bad) != nullptr)
return -1;
}
return 0;
#undef OBJ_DIRECT_NITER
}
/*
* pobj_open_op -- main operations of the obj_open benchmark.
*/
static int
pobj_open_op(struct benchmark *bench, struct operation_info *info)
{
auto *bench_priv = (struct pobj_bench *)pmembench_get_priv(bench);
size_t idx = bench_priv->pool(info->worker->index);
pmemobj_close(bench_priv->pop[idx]);
bench_priv->pop[idx] = pmemobj_open(bench_priv->sets[idx], LAYOUT_NAME);
if (bench_priv->pop[idx] == nullptr)
return -1;
return 0;
}
/*
* pobj_free_worker -- worker exit function
*/
static void
pobj_free_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *pw = (struct pobj_worker *)worker->priv;
auto *bench_priv = (struct pobj_bench *)pmembench_get_priv(bench);
for (size_t i = 0; i < bench_priv->args_priv->n_objs; i++)
pmemobj_free(&pw->oids[i]);
free(pw->oids);
free(pw);
}
static struct benchmark_info obj_open;
static struct benchmark_info obj_direct;
/* Array defining common command line arguments. */
static struct benchmark_clo pobj_direct_clo[4];
static struct benchmark_clo pobj_open_clo[3];
CONSTRUCTOR(pmemobj_gen_constructor)
void
pmemobj_gen_constructor(void)
{
pobj_direct_clo[0].opt_short = 'T';
pobj_direct_clo[0].opt_long = "type-number";
pobj_direct_clo[0].descr = "Type number mode - one, per-thread, "
"rand";
pobj_direct_clo[0].def = "one";
pobj_direct_clo[0].off = clo_field_offset(struct pobj_args, type_num);
pobj_direct_clo[0].type = CLO_TYPE_STR;
pobj_direct_clo[1].opt_short = 'm';
pobj_direct_clo[1].opt_long = "min-size";
pobj_direct_clo[1].type = CLO_TYPE_UINT;
pobj_direct_clo[1].descr = "Minimum allocation size";
pobj_direct_clo[1].off = clo_field_offset(struct pobj_args, min_size);
pobj_direct_clo[1].def = "0";
pobj_direct_clo[1].type_uint.size =
clo_field_size(struct pobj_args, min_size);
pobj_direct_clo[1].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
pobj_direct_clo[1].type_uint.min = 0;
pobj_direct_clo[1].type_uint.max = UINT_MAX;
pobj_direct_clo[2].opt_short = 'P';
pobj_direct_clo[2].opt_long = "one-pool";
pobj_direct_clo[2].descr = "Create one pool for all threads";
pobj_direct_clo[2].type = CLO_TYPE_FLAG;
pobj_direct_clo[2].off = clo_field_offset(struct pobj_args, one_pool);
pobj_direct_clo[3].opt_short = 'O';
pobj_direct_clo[3].opt_long = "one-object";
pobj_direct_clo[3].descr = "Use only one object per thread";
pobj_direct_clo[3].type = CLO_TYPE_FLAG;
pobj_direct_clo[3].off = clo_field_offset(struct pobj_args, one_obj);
pobj_open_clo[0].opt_short = 'T',
pobj_open_clo[0].opt_long = "type-number",
pobj_open_clo[0].descr = "Type number mode - one, "
"per-thread, rand",
pobj_open_clo[0].def = "one",
pobj_open_clo[0].off = clo_field_offset(struct pobj_args, type_num),
pobj_open_clo[0].type = CLO_TYPE_STR,
pobj_open_clo[1].opt_short = 'm',
pobj_open_clo[1].opt_long = "min-size",
pobj_open_clo[1].type = CLO_TYPE_UINT,
pobj_open_clo[1].descr = "Minimum allocation size",
pobj_open_clo[1].off = clo_field_offset(struct pobj_args, min_size),
pobj_open_clo[1].def = "0",
pobj_open_clo[1].type_uint.size =
clo_field_size(struct pobj_args, min_size),
pobj_open_clo[1].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX,
pobj_open_clo[1].type_uint.min = 0,
pobj_open_clo[1].type_uint.max = UINT_MAX,
pobj_open_clo[2].opt_short = 'o';
pobj_open_clo[2].opt_long = "objects";
pobj_open_clo[2].type = CLO_TYPE_UINT;
pobj_open_clo[2].descr = "Number of objects in each pool";
pobj_open_clo[2].off = clo_field_offset(struct pobj_args, n_objs);
pobj_open_clo[2].def = "1";
pobj_open_clo[2].type_uint.size =
clo_field_size(struct pobj_args, n_objs);
pobj_open_clo[2].type_uint.base = CLO_INT_BASE_DEC | CLO_INT_BASE_HEX;
pobj_open_clo[2].type_uint.min = 1;
pobj_open_clo[2].type_uint.max = UINT_MAX;
obj_open.name = "obj_open";
obj_open.brief = "pmemobj_open() benchmark";
obj_open.init = pobj_init;
obj_open.exit = pobj_exit;
obj_open.multithread = true;
obj_open.multiops = true;
obj_open.init_worker = pobj_init_worker;
obj_open.free_worker = pobj_free_worker;
obj_open.operation = pobj_open_op;
obj_open.measure_time = true;
obj_open.clos = pobj_open_clo;
obj_open.nclos = ARRAY_SIZE(pobj_open_clo);
obj_open.opts_size = sizeof(struct pobj_args);
obj_open.rm_file = true;
obj_open.allow_poolset = true;
REGISTER_BENCHMARK(obj_open);
obj_direct.name = "obj_direct";
obj_direct.brief = "pmemobj_direct() benchmark";
obj_direct.init = pobj_direct_init;
obj_direct.exit = pobj_exit;
obj_direct.multithread = true;
obj_direct.multiops = true;
obj_direct.init_worker = pobj_init_worker;
obj_direct.free_worker = pobj_free_worker;
obj_direct.operation = pobj_direct_op;
obj_direct.measure_time = true;
obj_direct.clos = pobj_direct_clo;
obj_direct.nclos = ARRAY_SIZE(pobj_direct_clo);
obj_direct.opts_size = sizeof(struct pobj_args);
obj_direct.rm_file = true;
obj_direct.allow_poolset = true;
REGISTER_BENCHMARK(obj_direct);
};
| 18,229 | 26.127976 | 79 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/rpmem.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2020, Intel Corporation */
/*
* rpmem.cpp -- rpmem benchmarks definition
*/
#include <cassert>
#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "libpmem.h"
#include "librpmem.h"
#include "os.h"
#include "set.h"
#include "util.h"
#define CL_ALIGNMENT 64
#define MAX_OFFSET (CL_ALIGNMENT - 1)
#define ALIGN_CL(x) (((x) + CL_ALIGNMENT - 1) & ~(CL_ALIGNMENT - 1))
#define BENCH_RPMEM_FLUSH_NAME "rpmem_flush_drain"
#define BENCH_RPMEM_PERSIST_NAME "rpmem_persist"
#define BENCH_RPMEM_MIXED_NAME "rpmem_mixed"
/*
* rpmem_args -- benchmark specific command line options
*/
struct rpmem_args {
char *mode; /* operation mode: stat, seq, rand */
bool no_warmup; /* do not do warmup */
bool no_memset; /* do not call memset before each persist */
size_t chunk_size; /* elementary chunk size */
size_t dest_off; /* destination address offset */
bool relaxed; /* use RPMEM_PERSIST_RELAXED / RPMEM_FLUSH_RELAXED flag */
char *workload; /* workload */
int flushes_per_drain; /* # of flushes between drains */
};
/*
* rpmem_bench -- benchmark context
*/
struct rpmem_bench {
struct rpmem_args *pargs; /* benchmark specific arguments */
size_t *offsets; /* random/sequential address offsets */
size_t n_offsets; /* number of random elements */
size_t *offsets_pos; /* position within offsets */
int const_b; /* memset() value */
size_t min_size; /* minimum file size */
void *addrp; /* mapped file address */
void *pool; /* memory pool address */
size_t pool_size; /* size of memory pool */
size_t mapped_len; /* mapped length */
RPMEMpool **rpp; /* rpmem pool pointers */
unsigned *nlanes; /* number of lanes for each remote replica */
unsigned nreplicas; /* number of remote replicas */
size_t csize_align; /* aligned elementary chunk size */
unsigned *flags; /* flags for ops */
size_t workload_len; /* length of the workload */
unsigned n_flushing_ops_per_thread; /* # of operation which require
offsets per thread */
};
/*
* operation_mode -- mode of operation
*/
enum operation_mode {
OP_MODE_UNKNOWN,
OP_MODE_STAT, /* always use the same chunk */
OP_MODE_SEQ, /* use consecutive chunks */
OP_MODE_RAND, /* use random chunks */
OP_MODE_SEQ_WRAP, /* use consecutive chunks, but use file size */
OP_MODE_RAND_WRAP, /* use random chunks, but use file size */
};
/*
* parse_op_mode -- parse operation mode from string
*/
static enum operation_mode
parse_op_mode(const char *arg)
{
if (strcmp(arg, "stat") == 0)
return OP_MODE_STAT;
else if (strcmp(arg, "seq") == 0)
return OP_MODE_SEQ;
else if (strcmp(arg, "rand") == 0)
return OP_MODE_RAND;
else if (strcmp(arg, "seq-wrap") == 0)
return OP_MODE_SEQ_WRAP;
else if (strcmp(arg, "rand-wrap") == 0)
return OP_MODE_RAND_WRAP;
else
return OP_MODE_UNKNOWN;
}
/*
* get_flushing_op_num -- return # of operations in the workload which require
* offsets
*/
static unsigned
get_flushing_op_num(struct benchmark *bench, struct rpmem_bench *mb)
{
assert(bench);
struct benchmark_info *info = pmembench_get_info(bench);
assert(info);
/*
* The rpmem_persist benchmark does one rpmem_persist() per worker op.
* The rpmem_flush_drain benchmark does one rpmem_flush() or
* rpmem_flush() + rpmem_drain() per worker op. Either way, it
* requires one offset per worker op.
*/
if (strcmp(info->name, BENCH_RPMEM_PERSIST_NAME) == 0 ||
strcmp(info->name, BENCH_RPMEM_FLUSH_NAME) == 0)
return 1;
assert(strcmp(info->name, BENCH_RPMEM_MIXED_NAME) == 0);
assert(mb);
assert(mb->pargs);
assert(mb->pargs->workload);
assert(mb->workload_len > 0);
unsigned num = 0;
/*
* The rpmem_mixed benchmark performs multiple API calls per worker
* op some of them flushes ergo requires its own offset.
*/
for (size_t i = 0; i < mb->workload_len; ++i) {
switch (mb->pargs->workload[i]) {
case 'f': /* rpmem_flush */
case 'g': /* rpmem_flush + RPMEM_FLUSH_RELAXED */
case 'p': /* rpmem_persist */
case 'r': /* rpmem_persist + RPMEM_PERSIST_RELAXED */
++num;
break;
}
}
/*
* To simplify checks it is assumed each worker op requires at least one
* flushing operation even though it doesn't have to use it.
*/
if (num < 1)
num = 1;
return num;
}
/*
* init_offsets -- initialize offsets[] array depending on the selected mode
*/
static int
init_offsets(struct benchmark_args *args, struct rpmem_bench *mb,
enum operation_mode op_mode)
{
size_t n_ops_by_size = (mb->pool_size - POOL_HDR_SIZE) /
(args->n_threads * mb->csize_align);
mb->n_offsets = mb->n_flushing_ops_per_thread * args->n_threads;
mb->offsets = (size_t *)malloc(mb->n_offsets * sizeof(*mb->offsets));
if (!mb->offsets) {
perror("malloc");
return -1;
}
mb->offsets_pos = (size_t *)calloc(args->n_threads, sizeof(size_t));
if (!mb->offsets_pos) {
perror("calloc");
free(mb->offsets);
return -1;
}
rng_t rng;
randomize_r(&rng, args->seed);
for (size_t i = 0; i < args->n_threads; i++) {
for (size_t j = 0; j < mb->n_flushing_ops_per_thread; j++) {
size_t off_idx = i * mb->n_flushing_ops_per_thread + j;
size_t chunk_idx;
switch (op_mode) {
case OP_MODE_STAT:
chunk_idx = i;
break;
case OP_MODE_SEQ:
chunk_idx =
i * mb->n_flushing_ops_per_thread +
j;
break;
case OP_MODE_RAND:
chunk_idx =
i * mb->n_flushing_ops_per_thread +
rnd64_r(&rng) %
mb->n_flushing_ops_per_thread;
break;
case OP_MODE_SEQ_WRAP:
chunk_idx = i * n_ops_by_size +
j % n_ops_by_size;
break;
case OP_MODE_RAND_WRAP:
chunk_idx = i * n_ops_by_size +
rnd64_r(&rng) % n_ops_by_size;
break;
default:
assert(0);
return -1;
}
mb->offsets[off_idx] = POOL_HDR_SIZE +
chunk_idx * mb->csize_align +
mb->pargs->dest_off;
}
}
return 0;
}
/*
* do_warmup -- does the warmup by writing the whole pool area
*/
static int
do_warmup(struct rpmem_bench *mb)
{
/* clear the entire pool */
memset((char *)mb->pool + POOL_HDR_SIZE, 0,
mb->pool_size - POOL_HDR_SIZE);
for (unsigned r = 0; r < mb->nreplicas; ++r) {
int ret = rpmem_persist(mb->rpp[r], POOL_HDR_SIZE,
mb->pool_size - POOL_HDR_SIZE, 0,
RPMEM_PERSIST_RELAXED);
if (ret)
return ret;
}
/* if no memset for each operation, do one big memset */
if (mb->pargs->no_memset) {
memset((char *)mb->pool + POOL_HDR_SIZE, 0xFF,
mb->pool_size - POOL_HDR_SIZE);
}
return 0;
}
/*
* rpmem_mixed_op_flush -- perform rpmem_flush
*/
static inline int
rpmem_mixed_op_flush(struct rpmem_bench *mb, struct operation_info *info)
{
size_t *pos = &mb->offsets_pos[info->worker->index];
uint64_t idx =
info->worker->index * mb->n_flushing_ops_per_thread + *pos;
assert(idx < mb->n_offsets);
size_t offset = mb->offsets[idx];
size_t len = mb->pargs->chunk_size;
if (!mb->pargs->no_memset) {
void *dest = (char *)mb->pool + offset;
/* thread id on MS 4 bits and operation id on LS 4 bits */
int c = ((info->worker->index & 0xf) << 4) +
((0xf & info->index));
memset(dest, c, len);
}
int ret = 0;
for (unsigned r = 0; r < mb->nreplicas; ++r) {
assert(info->worker->index < mb->nlanes[r]);
ret = rpmem_flush(mb->rpp[r], offset, len, info->worker->index,
mb->flags[info->worker->index]);
if (ret) {
fprintf(stderr, "rpmem_flush replica #%u: %s\n", r,
rpmem_errormsg());
return ret;
}
}
++*pos;
return 0;
}
/*
* rpmem_mixed_op_drain -- perform rpmem_drain
*/
static inline int
rpmem_mixed_op_drain(struct rpmem_bench *mb, struct operation_info *info)
{
int ret = 0;
for (unsigned r = 0; r < mb->nreplicas; ++r) {
ret = rpmem_drain(mb->rpp[r], info->worker->index, 0);
if (unlikely(ret)) {
fprintf(stderr, "rpmem_drain replica #%u: %s\n", r,
rpmem_errormsg());
return ret;
}
}
return 0;
}
/*
* rpmem_flush_drain_op -- actual benchmark operation for the rpmem_flush_drain
* benchmark
*/
static int
rpmem_flush_drain_op(struct benchmark *bench, struct operation_info *info)
{
auto *mb = (struct rpmem_bench *)pmembench_get_priv(bench);
int ret = 0;
if (mb->pargs->flushes_per_drain != 0) {
ret |= rpmem_mixed_op_flush(mb, info);
/* no rpmem_drain() required */
if (mb->pargs->flushes_per_drain < 0)
return ret;
/* more rpmem_flush() required before rpmem_drain() */
if ((info->index + 1) % mb->pargs->flushes_per_drain != 0)
return ret;
/* rpmem_drain() required */
}
ret |= rpmem_mixed_op_drain(mb, info);
return ret;
}
/*
* rpmem_persist_op -- actual benchmark operation for the rpmem_persist
* benchmark
*/
static int
rpmem_persist_op(struct benchmark *bench, struct operation_info *info)
{
auto *mb = (struct rpmem_bench *)pmembench_get_priv(bench);
size_t *pos = &mb->offsets_pos[info->worker->index];
uint64_t idx =
info->worker->index * mb->n_flushing_ops_per_thread + *pos;
assert(idx < mb->n_offsets);
size_t offset = mb->offsets[idx];
size_t len = mb->pargs->chunk_size;
if (!mb->pargs->no_memset) {
void *dest = (char *)mb->pool + offset;
/* thread id on MS 4 bits and operation id on LS 4 bits */
int c = ((info->worker->index & 0xf) << 4) +
((0xf & info->index));
memset(dest, c, len);
}
int ret = 0;
for (unsigned r = 0; r < mb->nreplicas; ++r) {
assert(info->worker->index < mb->nlanes[r]);
ret = rpmem_persist(mb->rpp[r], offset, len,
info->worker->index,
mb->flags[info->worker->index]);
if (ret) {
fprintf(stderr, "rpmem_persist replica #%u: %s\n", r,
rpmem_errormsg());
return ret;
}
}
++*pos;
return 0;
}
/*
* rpmem_mixed_op -- actual benchmark operation for the rpmem_mixed
* benchmark
*/
static int
rpmem_mixed_op(struct benchmark *bench, struct operation_info *info)
{
auto *mb = (struct rpmem_bench *)pmembench_get_priv(bench);
assert(mb->workload_len != 0);
int ret = 0;
for (size_t i = 0; i < mb->workload_len; ++i) {
char op = mb->pargs->workload[i];
mb->flags[info->worker->index] = 0;
switch (op) {
case 'g':
mb->flags[info->worker->index] =
RPMEM_FLUSH_RELAXED;
/* FALLTHROUGH */
case 'f':
ret |= rpmem_mixed_op_flush(mb, info);
break;
case 'd':
ret |= rpmem_mixed_op_drain(mb, info);
break;
case 'r':
mb->flags[info->worker->index] =
RPMEM_PERSIST_RELAXED;
/* FALLTHROUGH */
case 'p':
ret |= rpmem_persist_op(bench, info);
break;
default:
fprintf(stderr, "unknown operation: %c", op);
return 1;
}
}
return ret;
}
/*
* rpmem_map_file -- map local file
*/
static int
rpmem_map_file(const char *path, struct rpmem_bench *mb, size_t size)
{
int mode;
#ifndef _WIN32
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#else
mode = S_IWRITE | S_IREAD;
#endif
mb->addrp = pmem_map_file(path, size, PMEM_FILE_CREATE, mode,
&mb->mapped_len, nullptr);
if (!mb->addrp)
return -1;
return 0;
}
/*
* rpmem_unmap_file -- unmap local file
*/
static int
rpmem_unmap_file(struct rpmem_bench *mb)
{
return pmem_unmap(mb->addrp, mb->mapped_len);
}
/*
* rpmem_poolset_init -- read poolset file and initialize benchmark accordingly
*/
static int
rpmem_poolset_init(const char *path, struct rpmem_bench *mb,
struct benchmark_args *args)
{
struct pool_set *set;
struct pool_replica *rep;
struct remote_replica *remote;
struct pool_set_part *part;
struct rpmem_pool_attr attr;
memset(&attr, 0, sizeof(attr));
memcpy(attr.signature, "PMEMBNCH", sizeof(attr.signature));
/* read and validate poolset */
if (util_poolset_read(&set, path)) {
fprintf(stderr, "Invalid poolset file '%s'\n", path);
return -1;
}
assert(set);
if (set->nreplicas < 2) {
fprintf(stderr, "No replicas defined\n");
goto err_poolset_free;
}
if (set->remote == 0) {
fprintf(stderr, "No remote replicas defined\n");
goto err_poolset_free;
}
for (unsigned i = 1; i < set->nreplicas; ++i) {
if (!set->replica[i]->remote) {
fprintf(stderr, "Local replicas are not supported\n");
goto err_poolset_free;
}
}
/* read and validate master replica */
rep = set->replica[0];
assert(rep);
assert(rep->remote == nullptr);
if (rep->nparts != 1) {
fprintf(stderr,
"Multipart master replicas are not supported\n");
goto err_poolset_free;
}
if (rep->repsize < mb->min_size) {
fprintf(stderr, "A master replica is too small (%zu < %zu)\n",
rep->repsize, mb->min_size);
goto err_poolset_free;
}
part = (struct pool_set_part *)&rep->part[0];
if (rpmem_map_file(part->path, mb, rep->repsize)) {
perror(part->path);
goto err_poolset_free;
}
mb->pool_size = mb->mapped_len;
mb->pool = (void *)((uintptr_t)mb->addrp);
/* prepare remote replicas */
mb->nreplicas = set->nreplicas - 1;
mb->nlanes = (unsigned *)malloc(mb->nreplicas * sizeof(unsigned));
if (mb->nlanes == nullptr) {
perror("malloc");
goto err_unmap_file;
}
mb->rpp = (RPMEMpool **)malloc(mb->nreplicas * sizeof(RPMEMpool *));
if (mb->rpp == nullptr) {
perror("malloc");
goto err_free_lanes;
}
unsigned r;
for (r = 0; r < mb->nreplicas; ++r) {
remote = set->replica[r + 1]->remote;
assert(remote);
mb->nlanes[r] = args->n_threads;
/* Temporary WA for librpmem issue */
++mb->nlanes[r];
mb->rpp[r] = rpmem_create(remote->node_addr, remote->pool_desc,
mb->addrp, mb->pool_size,
&mb->nlanes[r], &attr);
if (!mb->rpp[r]) {
perror("rpmem_create");
goto err_rpmem_close;
}
if (mb->nlanes[r] < args->n_threads) {
fprintf(stderr,
"Number of threads too large for replica #%u (max: %u)\n",
r, mb->nlanes[r]);
r++; /* close current replica */
goto err_rpmem_close;
}
}
util_poolset_free(set);
return 0;
err_rpmem_close:
for (unsigned i = 0; i < r; i++)
rpmem_close(mb->rpp[i]);
free(mb->rpp);
err_free_lanes:
free(mb->nlanes);
err_unmap_file:
rpmem_unmap_file(mb);
err_poolset_free:
util_poolset_free(set);
return -1;
}
/*
* rpmem_poolset_fini -- close opened local and remote replicas
*/
static void
rpmem_poolset_fini(struct rpmem_bench *mb)
{
for (unsigned r = 0; r < mb->nreplicas; ++r) {
rpmem_close(mb->rpp[r]);
}
free(mb->rpp);
rpmem_unmap_file(mb);
}
/*
* rpmem_set_min_size -- compute minimal file size based on benchmark arguments
*/
static void
rpmem_set_min_size(struct rpmem_bench *mb, enum operation_mode op_mode,
struct benchmark_args *args)
{
mb->csize_align = ALIGN_CL(mb->pargs->chunk_size);
switch (op_mode) {
case OP_MODE_STAT:
mb->min_size = mb->csize_align * args->n_threads;
break;
case OP_MODE_SEQ:
case OP_MODE_RAND:
mb->min_size = mb->csize_align *
args->n_ops_per_thread * args->n_threads;
break;
case OP_MODE_SEQ_WRAP:
case OP_MODE_RAND_WRAP:
/*
* at least one chunk per thread to avoid false sharing
*/
mb->min_size = mb->csize_align * args->n_threads;
break;
default:
assert(0);
}
mb->min_size += POOL_HDR_SIZE;
}
/*
* rpmem_flags_init -- initialize flags[] array depending on the selected mode
*/
static int
rpmem_flags_init(struct benchmark *bench, struct benchmark_args *args,
struct rpmem_bench *mb)
{
assert(bench);
struct benchmark_info *info = pmembench_get_info(bench);
assert(info);
mb->flags = (unsigned *)calloc(args->n_threads, sizeof(unsigned));
if (!mb->flags) {
perror("calloc");
return -1;
}
unsigned relaxed_flag = 0;
if (strcmp(info->name, BENCH_RPMEM_PERSIST_NAME) == 0)
relaxed_flag = RPMEM_PERSIST_RELAXED;
else if (strcmp(info->name, BENCH_RPMEM_FLUSH_NAME) == 0)
relaxed_flag = RPMEM_FLUSH_RELAXED;
/* for rpmem_mixed benchmark flags are set during the benchmark */
/* for rpmem_persist and rpmem_flush_drain benchmark all ops have the
* same flags */
if (mb->pargs->relaxed) {
for (unsigned i = 0; i < args->n_threads; ++i)
mb->flags[i] = relaxed_flag;
}
return 0;
}
/*
* rpmem_init -- initialization function
*/
static int
rpmem_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench != nullptr);
assert(args != nullptr);
assert(args->opts != nullptr);
auto *mb = (struct rpmem_bench *)malloc(sizeof(struct rpmem_bench));
if (!mb) {
perror("malloc");
return -1;
}
mb->pargs = (struct rpmem_args *)args->opts;
mb->pargs->chunk_size = args->dsize;
enum operation_mode op_mode = parse_op_mode(mb->pargs->mode);
if (op_mode == OP_MODE_UNKNOWN) {
fprintf(stderr, "Invalid operation mode argument '%s'\n",
mb->pargs->mode);
goto err_parse_mode;
}
if (rpmem_flags_init(bench, args, mb))
goto err_flags_init;
mb->workload_len = 0;
if (mb->pargs->workload) {
mb->workload_len = strlen(mb->pargs->workload);
assert(mb->workload_len > 0);
}
rpmem_set_min_size(mb, op_mode, args);
if (rpmem_poolset_init(args->fname, mb, args)) {
goto err_poolset_init;
}
/* initialize offsets[] array depending on benchmark args */
mb->n_flushing_ops_per_thread =
get_flushing_op_num(bench, mb) * args->n_ops_per_thread;
if (init_offsets(args, mb, op_mode) < 0) {
goto err_init_offsets;
}
if (!mb->pargs->no_warmup) {
if (do_warmup(mb) != 0) {
fprintf(stderr, "do_warmup() function failed.\n");
goto err_warmup;
}
}
pmembench_set_priv(bench, mb);
return 0;
err_warmup:
free(mb->offsets_pos);
free(mb->offsets);
err_init_offsets:
rpmem_poolset_fini(mb);
err_poolset_init:
free(mb->flags);
err_flags_init:
err_parse_mode:
free(mb);
return -1;
}
/*
* rpmem_exit -- benchmark cleanup function
*/
static int
rpmem_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *mb = (struct rpmem_bench *)pmembench_get_priv(bench);
rpmem_poolset_fini(mb);
free(mb->offsets_pos);
free(mb->offsets);
free(mb->flags);
free(mb);
return 0;
}
static struct benchmark_clo rpmem_flush_clo[6];
static struct benchmark_clo rpmem_persist_clo[5];
static struct benchmark_clo rpmem_mixed_clo[5];
/* Stores information about benchmark. */
static struct benchmark_info rpmem_flush_info;
static struct benchmark_info rpmem_persist_info;
static struct benchmark_info rpmem_mixed_info;
CONSTRUCTOR(rpmem_constructor)
void
rpmem_constructor(void)
{
static struct benchmark_clo common_clo[4];
static struct benchmark_info common_info;
memset(&common_info, 0, sizeof(common_info));
/* common benchmarks definitions */
common_clo[0].opt_short = 'M';
common_clo[0].opt_long = "mem-mode";
common_clo[0].descr = "Memory writing mode :"
" stat, seq[-wrap], rand[-wrap]";
common_clo[0].def = "seq";
common_clo[0].off = clo_field_offset(struct rpmem_args, mode);
common_clo[0].type = CLO_TYPE_STR;
common_clo[1].opt_short = 'D';
common_clo[1].opt_long = "dest-offset";
common_clo[1].descr = "Destination cache line "
"alignment offset";
common_clo[1].def = "0";
common_clo[1].off = clo_field_offset(struct rpmem_args, dest_off);
common_clo[1].type = CLO_TYPE_UINT;
common_clo[1].type_uint.size =
clo_field_size(struct rpmem_args, dest_off);
common_clo[1].type_uint.base = CLO_INT_BASE_DEC;
common_clo[1].type_uint.min = 0;
common_clo[1].type_uint.max = MAX_OFFSET;
common_clo[2].opt_short = 'w';
common_clo[2].opt_long = "no-warmup";
common_clo[2].descr = "Don't do warmup";
common_clo[2].def = "false";
common_clo[2].type = CLO_TYPE_FLAG;
common_clo[2].off = clo_field_offset(struct rpmem_args, no_warmup);
common_clo[3].opt_short = 'T';
common_clo[3].opt_long = "no-memset";
common_clo[3].descr = "Don't call memset for all rpmem_persist";
common_clo[3].def = "false";
common_clo[3].off = clo_field_offset(struct rpmem_args, no_memset);
common_clo[3].type = CLO_TYPE_FLAG;
common_info.init = rpmem_init;
common_info.exit = rpmem_exit;
common_info.multithread = true;
common_info.multiops = true;
common_info.measure_time = true;
common_info.opts_size = sizeof(struct rpmem_args);
common_info.rm_file = true;
common_info.allow_poolset = true;
common_info.print_bandwidth = true;
/* rpmem_flush_drain benchmark definitions */
assert(sizeof(rpmem_flush_clo) >= sizeof(common_clo));
memcpy(rpmem_flush_clo, common_clo, sizeof(common_clo));
rpmem_flush_clo[4].opt_short = 0;
rpmem_flush_clo[4].opt_long = "flushes-per-drain";
rpmem_flush_clo[4].descr =
"Number of flushes between drains (-1 means flushes only)";
rpmem_flush_clo[4].def = "-1";
rpmem_flush_clo[4].off =
clo_field_offset(struct rpmem_args, flushes_per_drain);
rpmem_flush_clo[4].type = CLO_TYPE_INT;
rpmem_flush_clo[4].type_int.size =
clo_field_size(struct rpmem_args, flushes_per_drain);
rpmem_flush_clo[4].type_int.base = CLO_INT_BASE_DEC;
rpmem_flush_clo[4].type_int.min = -1;
rpmem_flush_clo[4].type_int.max = INT_MAX;
rpmem_flush_clo[5].opt_short = 0;
rpmem_flush_clo[5].opt_long = "flush-relaxed";
rpmem_flush_clo[5].descr = "Use RPMEM_FLUSH_RELAXED flag";
rpmem_flush_clo[5].def = "false";
rpmem_flush_clo[5].off = clo_field_offset(struct rpmem_args, relaxed);
rpmem_flush_clo[5].type = CLO_TYPE_FLAG;
memcpy(&rpmem_flush_info, &common_info, sizeof(common_info));
rpmem_flush_info.name = BENCH_RPMEM_FLUSH_NAME;
rpmem_flush_info.brief =
"Benchmark for rpmem_flush() and rpmem_drain() operations";
rpmem_flush_info.operation = rpmem_flush_drain_op;
rpmem_flush_info.clos = rpmem_flush_clo;
rpmem_flush_info.nclos = ARRAY_SIZE(rpmem_flush_clo);
REGISTER_BENCHMARK(rpmem_flush_info);
/* rpmem_persist benchmark definitions */
assert(sizeof(rpmem_persist_clo) >= sizeof(common_clo));
memcpy(rpmem_persist_clo, common_clo, sizeof(common_clo));
rpmem_persist_clo[4].opt_short = 0;
rpmem_persist_clo[4].opt_long = "persist-relaxed";
rpmem_persist_clo[4].descr = "Use RPMEM_PERSIST_RELAXED flag";
rpmem_persist_clo[4].def = "false";
rpmem_persist_clo[4].off = clo_field_offset(struct rpmem_args, relaxed);
rpmem_persist_clo[4].type = CLO_TYPE_FLAG;
memcpy(&rpmem_persist_info, &common_info, sizeof(common_info));
rpmem_persist_info.name = BENCH_RPMEM_PERSIST_NAME;
rpmem_persist_info.brief = "Benchmark for rpmem_persist() operation";
rpmem_persist_info.operation = rpmem_persist_op;
rpmem_persist_info.clos = rpmem_persist_clo;
rpmem_persist_info.nclos = ARRAY_SIZE(rpmem_persist_clo);
REGISTER_BENCHMARK(rpmem_persist_info);
/* rpmem_mixed benchmark definitions */
assert(sizeof(rpmem_mixed_clo) >= sizeof(common_clo));
memcpy(rpmem_mixed_clo, common_clo, sizeof(common_clo));
rpmem_mixed_clo[4].opt_short = 0;
rpmem_mixed_clo[4].opt_long = "workload";
rpmem_mixed_clo[4].descr = "Workload e.g.: 'prfgd' means "
"rpmem_persist(), "
"rpmem_persist() + RPMEM_PERSIST_RELAXED, "
"rpmem_flush(),"
"rpmem_flush() + RPMEM_FLUSH_RELAXED "
"and rpmem_drain()";
rpmem_mixed_clo[4].def = "fd";
rpmem_mixed_clo[4].off = clo_field_offset(struct rpmem_args, workload);
rpmem_mixed_clo[4].type = CLO_TYPE_STR;
memcpy(&rpmem_mixed_info, &common_info, sizeof(common_info));
rpmem_mixed_info.name = BENCH_RPMEM_MIXED_NAME;
rpmem_mixed_info.brief = "Benchmark for mixed rpmem workloads";
rpmem_mixed_info.operation = rpmem_mixed_op;
rpmem_mixed_info.clos = rpmem_mixed_clo;
rpmem_mixed_info.nclos = ARRAY_SIZE(rpmem_mixed_clo);
REGISTER_BENCHMARK(rpmem_mixed_info);
};
| 23,301 | 25.50967 | 79 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/config_reader_win.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2019, Intel Corporation */
/*
* config_reader_win.cpp -- config reader module definitions
*/
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tchar.h>
#include "config_reader.hpp"
#include "queue.h"
#include "scenario.hpp"
#define SECTION_GLOBAL TEXT("global")
#define KEY_BENCHMARK TEXT("bench")
#define KEY_GROUP TEXT("group")
/*
* Maximum section size according to MSDN documentation
*/
#define SIZEOF_SECTION 32767
#define NULL_LIST_EMPTY(x) (_tcslen(x) == 0)
#define NULL_LIST_NEXT(x) ((x) += (_tcslen(x) + 1))
#define KV_LIST_EMPTY(x) (_tcslen(x) == 0)
#define KV_FIRST(x)
#define KV_LIST_NEXT(x) \
((x) += (_tcslen(x) + 1), (x) += (_tcslen(x) + 1), \
(x) = kv_list_skip_comment(x))
#define KV_LIST_KEY(x) (x)
#define KV_LIST_VALUE(x) ((x) + _tcslen(x) + 1)
#define KV_LIST_INIT(x) kv_list_init(x)
#define LIST LPTSTR
#define KV_LIST LPTSTR
/*
* kv_list_skip_comment -- skip comment lines in ini file
*/
static KV_LIST
kv_list_skip_comment(KV_LIST list)
{
while (list[0] == TEXT('#'))
list += (_tcslen(list) + 1);
return list;
}
/*
* kv_list_init -- init KV list
*/
static KV_LIST
kv_list_init(LPTSTR list)
{
list = kv_list_skip_comment(list);
for (KV_LIST it = list; !KV_LIST_EMPTY(it); KV_LIST_NEXT(it)) {
LPTSTR c = _tcsstr(it, TEXT("="));
if (c == NULL)
return NULL;
*c = TEXT('\0');
}
return list;
}
/*
* config_reader -- handle structure
*/
struct config_reader {
LPTSTR lpFileName;
};
/*
* config_reader_alloc -- allocate config reader
*/
struct config_reader *
config_reader_alloc(void)
{
struct config_reader *cr = (struct config_reader *)malloc(sizeof(*cr));
if (cr == NULL)
return NULL;
return cr;
}
/*
* config_reader_read -- read config file
*/
int
config_reader_read(struct config_reader *cr, const char *fname)
{
DWORD len = 0;
LPTSTR buf = TEXT(" ");
/* get the length of the full pathname incl. terminating null char */
len = GetFullPathName((LPTSTR)fname, 0, buf, NULL);
if (len == 0) {
/* the function failed */
return -1;
} else {
/* allocate a buffer large enough to store the pathname */
LPTSTR buffer = (LPTSTR)malloc(len * sizeof(TCHAR));
DWORD ret = GetFullPathName((LPTSTR)fname, len, buffer, NULL);
if (_taccess(buffer, 0) != 0) {
printf("%s", strerror(errno));
return -1;
}
cr->lpFileName = (LPTSTR)buffer;
}
return 0;
}
/*
* config_reader_free -- free config reader
*/
void
config_reader_free(struct config_reader *cr)
{
free(cr);
}
/*
* is_scenario -- (internal) return true if _name_ is scenario name
*
* This filters out the _global_ and _config_ sections.
*/
static int
is_scenario(LPTSTR name)
{
return _tcscmp(name, SECTION_GLOBAL);
}
/*
* is_argument -- (internal) return true if _name_ is argument name
*
* This filters out the _benchmark_ key.
*/
static int
is_argument(LPTSTR name)
{
return _tcscmp(name, KEY_BENCHMARK) != 0 &&
_tcscmp(name, KEY_GROUP) != 0;
}
/*
* config_reader_get_scenarios -- return scenarios from config file
*
* This function reads the config file and returns a list of scenarios.
* Each scenario contains a list of key/value arguments.
* The scenario's arguments are merged with arguments from global section.
*/
int
config_reader_get_scenarios(struct config_reader *cr,
struct scenarios **scenarios)
{
/*
* Read all groups.
* The config file must have at least one group, otherwise
* it is considered as invalid.
*/
int ret = 0;
TCHAR *sections = (TCHAR *)malloc(sizeof(TCHAR) * SIZEOF_SECTION);
if (!sections)
return -1;
GetPrivateProfileSectionNames(sections, SIZEOF_SECTION, cr->lpFileName);
if (NULL_LIST_EMPTY(sections)) {
ret = -1;
goto err_sections;
}
/*
* Check if global section is present and read it.
*/
TCHAR *global = (TCHAR *)malloc(sizeof(TCHAR) * SIZEOF_SECTION);
if (!global)
return -1;
GetPrivateProfileSection(SECTION_GLOBAL, global, SIZEOF_SECTION,
cr->lpFileName);
KV_LIST global_kv = KV_LIST_INIT(global);
int has_global = !KV_LIST_EMPTY(global_kv);
struct scenarios *s = scenarios_alloc();
assert(NULL != s);
if (!s) {
ret = -1;
goto err_gkeys;
}
LPTSTR global_group = NULL;
for (KV_LIST it = global_kv; !KV_LIST_EMPTY(it); KV_LIST_NEXT(it)) {
if (_tcscmp(KV_LIST_KEY(it), KEY_GROUP) == 0) {
global_group = KV_LIST_VALUE(it);
break;
}
}
TCHAR *section;
for (LPTSTR group_name = sections; !NULL_LIST_EMPTY(group_name);
group_name = NULL_LIST_NEXT(group_name)) {
/*
* Check whether a group is a scenario
* or global section.
*/
if (!is_scenario(group_name))
continue;
/*
* Check for KEY_BENCHMARK which contains benchmark name.
* If not present the benchmark name is the same as the
* name of the section.
*/
section = (TCHAR *)malloc(sizeof(TCHAR) * SIZEOF_SECTION);
if (!section)
ret = -1;
GetPrivateProfileSection(group_name, section, SIZEOF_SECTION,
cr->lpFileName);
KV_LIST section_kv = KV_LIST_INIT(section);
struct scenario *scenario = NULL;
LPTSTR name = NULL;
LPTSTR group = NULL;
for (KV_LIST it = section_kv; !KV_LIST_EMPTY(it);
KV_LIST_NEXT(it)) {
if (_tcscmp(KV_LIST_KEY(it), KEY_BENCHMARK) == 0) {
name = KV_LIST_VALUE(it);
}
if (_tcscmp(KV_LIST_KEY(it), KEY_GROUP) == 0) {
group = KV_LIST_VALUE(it);
}
}
if (name == NULL) {
scenario = scenario_alloc((const char *)group_name,
(const char *)group_name);
} else {
scenario = scenario_alloc((const char *)group_name,
(const char *)name);
}
assert(scenario != NULL);
if (has_global) {
/*
* Merge key/values from global section.
*/
for (KV_LIST it = global_kv; !KV_LIST_EMPTY(it);
KV_LIST_NEXT(it)) {
LPTSTR key = KV_LIST_KEY(it);
if (!is_argument(key))
continue;
LPTSTR value = KV_LIST_VALUE(it);
assert(NULL != value);
if (!value) {
ret = -1;
goto err_scenarios;
}
struct kv *kv = kv_alloc((const char *)key,
(const char *)value);
assert(NULL != kv);
if (!kv) {
ret = -1;
goto err_scenarios;
}
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv,
next);
}
}
/* check for group name */
if (group) {
scenario_set_group(scenario, (const char *)group);
} else if (global_group) {
scenario_set_group(scenario,
(const char *)global_group);
}
for (KV_LIST it = section_kv; !KV_LIST_EMPTY(it);
KV_LIST_NEXT(it)) {
LPTSTR key = KV_LIST_KEY(it);
if (!is_argument(key))
continue;
LPTSTR value = KV_LIST_VALUE(it);
assert(NULL != value);
if (!value) {
ret = -1;
goto err_scenarios;
}
struct kv *kv = kv_alloc((const char *)key,
(const char *)value);
assert(NULL != kv);
if (!kv) {
ret = -1;
goto err_scenarios;
}
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv, next);
}
PMDK_TAILQ_INSERT_TAIL(&s->head, scenario, next);
free(section);
}
*scenarios = s;
free(global);
free(sections);
return 0;
err_scenarios:
free(section);
scenarios_free(s);
err_gkeys:
free(global);
err_sections:
free(sections);
return ret;
}
| 7,258 | 20.99697 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/obj_pmalloc.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* obj_pmalloc.cpp -- pmalloc benchmarks definition
*/
#include <cassert>
#include <cerrno>
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include "benchmark.hpp"
#include "file.h"
#include "libpmemobj.h"
#include "memops.h"
#include "os.h"
#include "pmalloc.h"
#include "poolset_util.hpp"
#include "valgrind_internal.h"
/*
* The factor used for PMEM pool size calculation, accounts for metadata,
* fragmentation and etc.
*/
#define FACTOR 1.2f
/* The minimum allocation size that pmalloc can perform */
#define ALLOC_MIN_SIZE 64
/* OOB and allocation header size */
#define OOB_HEADER_SIZE 64
/*
* prog_args - command line parsed arguments
*/
struct prog_args {
size_t minsize; /* minimum size for random allocation size */
bool use_random_size; /* if set, use random size allocations */
unsigned seed; /* PRNG seed */
};
POBJ_LAYOUT_BEGIN(pmalloc_layout);
POBJ_LAYOUT_ROOT(pmalloc_layout, struct my_root);
POBJ_LAYOUT_TOID(pmalloc_layout, uint64_t);
POBJ_LAYOUT_END(pmalloc_layout);
/*
* my_root - root object
*/
struct my_root {
TOID(uint64_t) offs; /* vector of the allocated object offsets */
};
/*
* obj_bench - variables used in benchmark, passed within functions
*/
struct obj_bench {
PMEMobjpool *pop; /* persistent pool handle */
struct prog_args *pa; /* prog_args structure */
size_t *sizes; /* sizes for allocations */
TOID(struct my_root) root; /* root object's OID */
uint64_t *offs; /* pointer to the vector of offsets */
};
/*
* obj_init -- common part of the benchmark initialization for pmalloc and
* pfree. It allocates the PMEM memory pool and the necessary offset vector.
*/
static int
obj_init(struct benchmark *bench, struct benchmark_args *args)
{
struct my_root *root = nullptr;
assert(bench != nullptr);
assert(args != nullptr);
assert(args->opts != nullptr);
char path[PATH_MAX];
if (util_safe_strcpy(path, args->fname, sizeof(path)) != 0)
return -1;
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
if (((struct prog_args *)(args->opts))->minsize >= args->dsize) {
fprintf(stderr, "Wrong params - allocation size\n");
return -1;
}
auto *ob = (struct obj_bench *)malloc(sizeof(struct obj_bench));
if (ob == nullptr) {
perror("malloc");
return -1;
}
pmembench_set_priv(bench, ob);
ob->pa = (struct prog_args *)args->opts;
size_t n_ops_total = args->n_ops_per_thread * args->n_threads;
assert(n_ops_total != 0);
/* Create pmemobj pool. */
size_t alloc_size = args->dsize;
if (alloc_size < ALLOC_MIN_SIZE)
alloc_size = ALLOC_MIN_SIZE;
/* For data objects */
size_t poolsize = PMEMOBJ_MIN_POOL +
(n_ops_total * (alloc_size + OOB_HEADER_SIZE))
/* for offsets */
+ n_ops_total * sizeof(uint64_t);
/* multiply by FACTOR for metadata, fragmentation, etc. */
poolsize = (size_t)(poolsize * FACTOR);
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < poolsize) {
fprintf(stderr, "file size too large\n");
goto free_ob;
}
poolsize = 0;
} else if (poolsize < PMEMOBJ_MIN_POOL) {
poolsize = PMEMOBJ_MIN_POOL;
}
if (args->is_dynamic_poolset) {
int ret = dynamic_poolset_create(args->fname, poolsize);
if (ret == -1)
goto free_ob;
if (util_safe_strcpy(path, POOLSET_PATH, sizeof(path)) != 0)
goto free_ob;
poolsize = 0;
}
ob->pop = pmemobj_create(path, POBJ_LAYOUT_NAME(pmalloc_layout),
poolsize, args->fmode);
if (ob->pop == nullptr) {
fprintf(stderr, "%s\n", pmemobj_errormsg());
goto free_ob;
}
ob->root = POBJ_ROOT(ob->pop, struct my_root);
if (TOID_IS_NULL(ob->root)) {
fprintf(stderr, "POBJ_ROOT: %s\n", pmemobj_errormsg());
goto free_pop;
}
root = D_RW(ob->root);
assert(root != nullptr);
POBJ_ZALLOC(ob->pop, &root->offs, uint64_t,
n_ops_total * sizeof(PMEMoid));
if (TOID_IS_NULL(root->offs)) {
fprintf(stderr, "POBJ_ZALLOC off_vect: %s\n",
pmemobj_errormsg());
goto free_pop;
}
ob->offs = D_RW(root->offs);
ob->sizes = (size_t *)malloc(n_ops_total * sizeof(size_t));
if (ob->sizes == nullptr) {
fprintf(stderr, "malloc rand size vect err\n");
goto free_pop;
}
if (ob->pa->use_random_size) {
size_t width = args->dsize - ob->pa->minsize;
for (size_t i = 0; i < n_ops_total; i++) {
auto hr = (uint32_t)os_rand_r(&ob->pa->seed);
auto lr = (uint32_t)os_rand_r(&ob->pa->seed);
uint64_t r64 = (uint64_t)hr << 32 | lr;
ob->sizes[i] = r64 % width + ob->pa->minsize;
}
} else {
for (size_t i = 0; i < n_ops_total; i++)
ob->sizes[i] = args->dsize;
}
return 0;
free_pop:
pmemobj_close(ob->pop);
free_ob:
free(ob);
return -1;
}
/*
* obj_exit -- common part for the exit function for pmalloc and pfree
* benchmarks. It frees the allocated offset vector and the memory pool.
*/
static int
obj_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
free(ob->sizes);
POBJ_FREE(&D_RW(ob->root)->offs);
pmemobj_close(ob->pop);
return 0;
}
/*
* pmalloc_init -- initialization for the pmalloc benchmark. Performs only the
* common initialization.
*/
static int
pmalloc_init(struct benchmark *bench, struct benchmark_args *args)
{
return obj_init(bench, args);
}
/*
* pmalloc_op -- actual benchmark operation. Performs the pmalloc allocations.
*/
static int
pmalloc_op(struct benchmark *bench, struct operation_info *info)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
uint64_t i = info->index +
info->worker->index * info->args->n_ops_per_thread;
int ret = pmalloc(ob->pop, &ob->offs[i], ob->sizes[i], 0, 0);
if (ret) {
fprintf(stderr, "pmalloc ret: %d\n", ret);
return ret;
}
return 0;
}
struct pmix_worker {
size_t nobjects;
size_t shuffle_start;
rng_t rng;
};
/*
* pmix_worker_init -- initialization of the worker structure
*/
static int
pmix_worker_init(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
struct pmix_worker *w = (struct pmix_worker *)calloc(1, sizeof(*w));
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
if (w == nullptr)
return -1;
randomize_r(&w->rng, ob->pa->seed);
worker->priv = w;
return 0;
}
/*
* pmix_worker_fini -- destruction of the worker structure
*/
static void
pmix_worker_fini(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *w = (struct pmix_worker *)worker->priv;
free(w);
}
/*
* shuffle_objects -- randomly shuffle elements on a list
*
* Ideally, we wouldn't count the time this function takes, but for all
* practical purposes this is fast enough and isn't visible on the results.
* Just make sure the amount of objects to shuffle is not large.
*/
static void
shuffle_objects(uint64_t *objects, size_t start, size_t nobjects, rng_t *rng)
{
uint64_t tmp;
size_t dest;
for (size_t n = start; n < nobjects; ++n) {
dest = RRAND_R(rng, nobjects - 1, 0);
tmp = objects[n];
objects[n] = objects[dest];
objects[dest] = tmp;
}
}
#define FREE_PCT 10
#define FREE_OPS 10
/*
* pmix_op -- mixed workload benchmark
*/
static int
pmix_op(struct benchmark *bench, struct operation_info *info)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
auto *w = (struct pmix_worker *)info->worker->priv;
uint64_t idx = info->worker->index * info->args->n_ops_per_thread;
uint64_t *objects = &ob->offs[idx];
if (w->nobjects > FREE_OPS && FREE_PCT > RRAND_R(&w->rng, 100, 0)) {
shuffle_objects(objects, w->shuffle_start, w->nobjects,
&w->rng);
for (int i = 0; i < FREE_OPS; ++i) {
uint64_t off = objects[--w->nobjects];
pfree(ob->pop, &off);
}
w->shuffle_start = w->nobjects;
} else {
int ret = pmalloc(ob->pop, &objects[w->nobjects++],
ob->sizes[idx + info->index], 0, 0);
if (ret) {
fprintf(stderr, "pmalloc ret: %d\n", ret);
return ret;
}
}
return 0;
}
/*
* pmalloc_exit -- the end of the pmalloc benchmark. Frees the memory allocated
* during pmalloc_op and performs the common exit operations.
*/
static int
pmalloc_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
for (size_t i = 0; i < args->n_ops_per_thread * args->n_threads; i++) {
if (ob->offs[i])
pfree(ob->pop, &ob->offs[i]);
}
return obj_exit(bench, args);
}
/*
* pfree_init -- initialization for the pfree benchmark. Performs the common
* initialization and allocates the memory to be freed during pfree_op.
*/
static int
pfree_init(struct benchmark *bench, struct benchmark_args *args)
{
int ret = obj_init(bench, args);
if (ret)
return ret;
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
for (size_t i = 0; i < args->n_ops_per_thread * args->n_threads; i++) {
ret = pmalloc(ob->pop, &ob->offs[i], ob->sizes[i], 0, 0);
if (ret) {
fprintf(stderr, "pmalloc at idx %" PRIu64 " ret: %s\n",
i, pmemobj_errormsg());
/* free the allocated memory */
while (i != 0) {
pfree(ob->pop, &ob->offs[i - 1]);
i--;
}
obj_exit(bench, args);
return ret;
}
}
return 0;
}
/*
* pmalloc_op -- actual benchmark operation. Performs the pfree operation.
*/
static int
pfree_op(struct benchmark *bench, struct operation_info *info)
{
auto *ob = (struct obj_bench *)pmembench_get_priv(bench);
uint64_t i = info->index +
info->worker->index * info->args->n_ops_per_thread;
pfree(ob->pop, &ob->offs[i]);
return 0;
}
/* command line options definition */
static struct benchmark_clo pmalloc_clo[3];
/*
* Stores information about pmalloc benchmark.
*/
static struct benchmark_info pmalloc_info;
/*
* Stores information about pfree benchmark.
*/
static struct benchmark_info pfree_info;
/*
* Stores information about pmix benchmark.
*/
static struct benchmark_info pmix_info;
CONSTRUCTOR(obj_pmalloc_constructor)
void
obj_pmalloc_constructor(void)
{
pmalloc_clo[0].opt_short = 'r';
pmalloc_clo[0].opt_long = "random";
pmalloc_clo[0].descr = "Use random size allocations - "
"from min-size to data-size";
pmalloc_clo[0].off =
clo_field_offset(struct prog_args, use_random_size);
pmalloc_clo[0].type = CLO_TYPE_FLAG;
pmalloc_clo[1].opt_short = 'm';
pmalloc_clo[1].opt_long = "min-size";
pmalloc_clo[1].descr = "Minimum size of allocation for "
"random mode";
pmalloc_clo[1].type = CLO_TYPE_UINT;
pmalloc_clo[1].off = clo_field_offset(struct prog_args, minsize);
pmalloc_clo[1].def = "1";
pmalloc_clo[1].type_uint.size =
clo_field_size(struct prog_args, minsize);
pmalloc_clo[1].type_uint.base = CLO_INT_BASE_DEC;
pmalloc_clo[1].type_uint.min = 1;
pmalloc_clo[1].type_uint.max = UINT64_MAX;
pmalloc_clo[2].opt_short = 'S';
pmalloc_clo[2].opt_long = "seed";
pmalloc_clo[2].descr = "Random mode seed value";
pmalloc_clo[2].off = clo_field_offset(struct prog_args, seed);
pmalloc_clo[2].def = "1";
pmalloc_clo[2].type = CLO_TYPE_UINT;
pmalloc_clo[2].type_uint.size = clo_field_size(struct prog_args, seed);
pmalloc_clo[2].type_uint.base = CLO_INT_BASE_DEC;
pmalloc_clo[2].type_uint.min = 1;
pmalloc_clo[2].type_uint.max = UINT_MAX;
pmalloc_info.name = "pmalloc",
pmalloc_info.brief = "Benchmark for internal pmalloc() "
"operation";
pmalloc_info.init = pmalloc_init;
pmalloc_info.exit = pmalloc_exit;
pmalloc_info.multithread = true;
pmalloc_info.multiops = true;
pmalloc_info.operation = pmalloc_op;
pmalloc_info.measure_time = true;
pmalloc_info.clos = pmalloc_clo;
pmalloc_info.nclos = ARRAY_SIZE(pmalloc_clo);
pmalloc_info.opts_size = sizeof(struct prog_args);
pmalloc_info.rm_file = true;
pmalloc_info.allow_poolset = true;
REGISTER_BENCHMARK(pmalloc_info);
pfree_info.name = "pfree";
pfree_info.brief = "Benchmark for internal pfree() "
"operation";
pfree_info.init = pfree_init;
pfree_info.exit = pmalloc_exit; /* same as for pmalloc */
pfree_info.multithread = true;
pfree_info.multiops = true;
pfree_info.operation = pfree_op;
pfree_info.measure_time = true;
pfree_info.clos = pmalloc_clo;
pfree_info.nclos = ARRAY_SIZE(pmalloc_clo);
pfree_info.opts_size = sizeof(struct prog_args);
pfree_info.rm_file = true;
pfree_info.allow_poolset = true;
REGISTER_BENCHMARK(pfree_info);
pmix_info.name = "pmix";
pmix_info.brief = "Benchmark for mixed alloc/free workload";
pmix_info.init = pmalloc_init;
pmix_info.exit = pmalloc_exit; /* same as for pmalloc */
pmix_info.multithread = true;
pmix_info.multiops = true;
pmix_info.operation = pmix_op;
pmix_info.init_worker = pmix_worker_init;
pmix_info.free_worker = pmix_worker_fini;
pmix_info.measure_time = true;
pmix_info.clos = pmalloc_clo;
pmix_info.nclos = ARRAY_SIZE(pmalloc_clo);
pmix_info.opts_size = sizeof(struct prog_args);
pmix_info.rm_file = true;
pmix_info.allow_poolset = true;
REGISTER_BENCHMARK(pmix_info);
};
| 13,031 | 24.805941 | 79 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/map_bench.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2018, Intel Corporation */
/*
* map_bench.cpp -- benchmarks for: ctree, btree, rtree, rbtree, hashmap_atomic
* and hashmap_tx from examples.
*/
#include <cassert>
#include "benchmark.hpp"
#include "file.h"
#include "os.h"
#include "os_thread.h"
#include "poolset_util.hpp"
#include "map.h"
#include "map_btree.h"
#include "map_ctree.h"
#include "map_hashmap_atomic.h"
#include "map_hashmap_rp.h"
#include "map_hashmap_tx.h"
#include "map_rbtree.h"
#include "map_rtree.h"
/* Values less than 3 is not suitable for current rtree implementation */
#define FACTOR 3
#define ALLOC_OVERHEAD 64
TOID_DECLARE_ROOT(struct root);
struct root {
TOID(struct map) map;
};
#define OBJ_TYPE_NUM 1
#define swap(a, b) \
do { \
__typeof__(a) _tmp = (a); \
(a) = (b); \
(b) = _tmp; \
} while (0)
/* Values less than 2048 is not suitable for current rtree implementation */
#define SIZE_PER_KEY 2048
static const struct {
const char *str;
const struct map_ops *ops;
} map_types[] = {
{"ctree", MAP_CTREE}, {"btree", MAP_BTREE},
{"rtree", MAP_RTREE}, {"rbtree", MAP_RBTREE},
{"hashmap_tx", MAP_HASHMAP_TX}, {"hashmap_atomic", MAP_HASHMAP_ATOMIC},
{"hashmap_rp", MAP_HASHMAP_RP}};
#define MAP_TYPES_NUM (sizeof(map_types) / sizeof(map_types[0]))
struct map_bench_args {
unsigned seed;
uint64_t max_key;
char *type;
bool ext_tx;
bool alloc;
};
struct map_bench_worker {
uint64_t *keys;
size_t nkeys;
};
struct map_bench {
struct map_ctx *mapc;
os_mutex_t lock;
PMEMobjpool *pop;
size_t pool_size;
size_t nkeys;
size_t init_nkeys;
uint64_t *keys;
struct benchmark_args *args;
struct map_bench_args *margs;
TOID(struct root) root;
PMEMoid root_oid;
TOID(struct map) map;
int (*insert)(struct map_bench *, uint64_t);
int (*remove)(struct map_bench *, uint64_t);
int (*get)(struct map_bench *, uint64_t);
};
/*
* mutex_lock_nofail -- locks mutex and aborts if locking failed
*/
static void
mutex_lock_nofail(os_mutex_t *lock)
{
errno = os_mutex_lock(lock);
if (errno) {
perror("os_mutex_lock");
abort();
}
}
/*
* mutex_unlock_nofail -- unlocks mutex and aborts if unlocking failed
*/
static void
mutex_unlock_nofail(os_mutex_t *lock)
{
errno = os_mutex_unlock(lock);
if (errno) {
perror("os_mutex_unlock");
abort();
}
}
/*
* get_key -- return 64-bit random key
*/
static uint64_t
get_key(unsigned *seed, uint64_t max_key)
{
unsigned key_lo = os_rand_r(seed);
unsigned key_hi = os_rand_r(seed);
uint64_t key = (((uint64_t)key_hi) << 32) | ((uint64_t)key_lo);
if (max_key)
key = key % max_key;
return key;
}
/*
* parse_map_type -- parse type of map
*/
static const struct map_ops *
parse_map_type(const char *str)
{
for (unsigned i = 0; i < MAP_TYPES_NUM; i++) {
if (strcmp(str, map_types[i].str) == 0)
return map_types[i].ops;
}
return nullptr;
}
/*
* map_remove_free_op -- remove and free object from map
*/
static int
map_remove_free_op(struct map_bench *map_bench, uint64_t key)
{
volatile int ret = 0;
TX_BEGIN(map_bench->pop)
{
PMEMoid val = map_remove(map_bench->mapc, map_bench->map, key);
if (OID_IS_NULL(val))
ret = -1;
else
pmemobj_tx_free(val);
}
TX_ONABORT
{
ret = -1;
}
TX_END
return ret;
}
/*
* map_remove_root_op -- remove root object from map
*/
static int
map_remove_root_op(struct map_bench *map_bench, uint64_t key)
{
PMEMoid val = map_remove(map_bench->mapc, map_bench->map, key);
return !OID_EQUALS(val, map_bench->root_oid);
}
/*
* map_remove_op -- main operation for map_remove benchmark
*/
static int
map_remove_op(struct benchmark *bench, struct operation_info *info)
{
auto *map_bench = (struct map_bench *)pmembench_get_priv(bench);
auto *tworker = (struct map_bench_worker *)info->worker->priv;
uint64_t key = tworker->keys[info->index];
mutex_lock_nofail(&map_bench->lock);
int ret = map_bench->remove(map_bench, key);
mutex_unlock_nofail(&map_bench->lock);
return ret;
}
/*
* map_insert_alloc_op -- allocate an object and insert to map
*/
static int
map_insert_alloc_op(struct map_bench *map_bench, uint64_t key)
{
int ret = 0;
TX_BEGIN(map_bench->pop)
{
PMEMoid oid =
pmemobj_tx_alloc(map_bench->args->dsize, OBJ_TYPE_NUM);
ret = map_insert(map_bench->mapc, map_bench->map, key, oid);
}
TX_ONABORT
{
ret = -1;
}
TX_END
return ret;
}
/*
* map_insert_root_op -- insert root object to map
*/
static int
map_insert_root_op(struct map_bench *map_bench, uint64_t key)
{
return map_insert(map_bench->mapc, map_bench->map, key,
map_bench->root_oid);
}
/*
* map_insert_op -- main operation for map_insert benchmark
*/
static int
map_insert_op(struct benchmark *bench, struct operation_info *info)
{
auto *map_bench = (struct map_bench *)pmembench_get_priv(bench);
auto *tworker = (struct map_bench_worker *)info->worker->priv;
uint64_t key = tworker->keys[info->index];
mutex_lock_nofail(&map_bench->lock);
int ret = map_bench->insert(map_bench, key);
mutex_unlock_nofail(&map_bench->lock);
return ret;
}
/*
* map_get_obj_op -- get object from map at specified key
*/
static int
map_get_obj_op(struct map_bench *map_bench, uint64_t key)
{
PMEMoid val = map_get(map_bench->mapc, map_bench->map, key);
return OID_IS_NULL(val);
}
/*
* map_get_root_op -- get root object from map at specified key
*/
static int
map_get_root_op(struct map_bench *map_bench, uint64_t key)
{
PMEMoid val = map_get(map_bench->mapc, map_bench->map, key);
return !OID_EQUALS(val, map_bench->root_oid);
}
/*
* map_get_op -- main operation for map_get benchmark
*/
static int
map_get_op(struct benchmark *bench, struct operation_info *info)
{
auto *map_bench = (struct map_bench *)pmembench_get_priv(bench);
auto *tworker = (struct map_bench_worker *)info->worker->priv;
uint64_t key = tworker->keys[info->index];
mutex_lock_nofail(&map_bench->lock);
int ret = map_bench->get(map_bench, key);
mutex_unlock_nofail(&map_bench->lock);
return ret;
}
/*
* map_common_init_worker -- common init worker function for map_* benchmarks
*/
static int
map_common_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
struct map_bench_worker *tworker =
(struct map_bench_worker *)calloc(1, sizeof(*tworker));
struct map_bench *tree;
struct map_bench_args *targs;
if (!tworker) {
perror("calloc");
return -1;
}
tworker->nkeys = args->n_ops_per_thread;
tworker->keys =
(uint64_t *)malloc(tworker->nkeys * sizeof(*tworker->keys));
if (!tworker->keys) {
perror("malloc");
goto err_free_worker;
}
tree = (struct map_bench *)pmembench_get_priv(bench);
targs = (struct map_bench_args *)args->opts;
if (targs->ext_tx) {
int ret = pmemobj_tx_begin(tree->pop, nullptr);
if (ret) {
(void)pmemobj_tx_end();
goto err_free_keys;
}
}
worker->priv = tworker;
return 0;
err_free_keys:
free(tworker->keys);
err_free_worker:
free(tworker);
return -1;
}
/*
* map_common_free_worker -- common cleanup worker function for map_*
* benchmarks
*/
static void
map_common_free_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *tworker = (struct map_bench_worker *)worker->priv;
auto *targs = (struct map_bench_args *)args->opts;
if (targs->ext_tx) {
pmemobj_tx_commit();
(void)pmemobj_tx_end();
}
free(tworker->keys);
free(tworker);
}
/*
* map_insert_init_worker -- init worker function for map_insert benchmark
*/
static int
map_insert_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
int ret = map_common_init_worker(bench, args, worker);
if (ret)
return ret;
auto *targs = (struct map_bench_args *)args->opts;
assert(targs);
auto *tworker = (struct map_bench_worker *)worker->priv;
assert(tworker);
for (size_t i = 0; i < tworker->nkeys; i++)
tworker->keys[i] = get_key(&targs->seed, targs->max_key);
return 0;
}
/*
* map_global_rand_keys_init -- assign random keys from global keys array
*/
static int
map_global_rand_keys_init(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
auto *tree = (struct map_bench *)pmembench_get_priv(bench);
assert(tree);
auto *targs = (struct map_bench_args *)args->opts;
assert(targs);
auto *tworker = (struct map_bench_worker *)worker->priv;
assert(tworker);
assert(tree->init_nkeys);
/*
* Assign random keys from global tree->keys array without repetitions.
*/
for (size_t i = 0; i < tworker->nkeys; i++) {
uint64_t index = get_key(&targs->seed, tree->init_nkeys);
tworker->keys[i] = tree->keys[index];
swap(tree->keys[index], tree->keys[tree->init_nkeys - 1]);
tree->init_nkeys--;
}
return 0;
}
/*
* map_remove_init_worker -- init worker function for map_remove benchmark
*/
static int
map_remove_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
int ret = map_common_init_worker(bench, args, worker);
if (ret)
return ret;
ret = map_global_rand_keys_init(bench, args, worker);
if (ret)
goto err_common_free_worker;
return 0;
err_common_free_worker:
map_common_free_worker(bench, args, worker);
return -1;
}
/*
* map_bench_get_init_worker -- init worker function for map_get benchmark
*/
static int
map_bench_get_init_worker(struct benchmark *bench, struct benchmark_args *args,
struct worker_info *worker)
{
int ret = map_common_init_worker(bench, args, worker);
if (ret)
return ret;
ret = map_global_rand_keys_init(bench, args, worker);
if (ret)
goto err_common_free_worker;
return 0;
err_common_free_worker:
map_common_free_worker(bench, args, worker);
return -1;
}
/*
* map_common_init -- common init function for map_* benchmarks
*/
static int
map_common_init(struct benchmark *bench, struct benchmark_args *args)
{
assert(bench);
assert(args);
assert(args->opts);
char path[PATH_MAX];
if (util_safe_strcpy(path, args->fname, sizeof(path)) != 0)
return -1;
enum file_type type = util_file_get_type(args->fname);
if (type == OTHER_ERROR) {
fprintf(stderr, "could not check type of file %s\n",
args->fname);
return -1;
}
size_t size_per_key;
struct map_bench *map_bench =
(struct map_bench *)calloc(1, sizeof(*map_bench));
if (!map_bench) {
perror("calloc");
return -1;
}
map_bench->args = args;
map_bench->margs = (struct map_bench_args *)args->opts;
const struct map_ops *ops = parse_map_type(map_bench->margs->type);
if (!ops) {
fprintf(stderr, "invalid map type value specified -- '%s'\n",
map_bench->margs->type);
goto err_free_bench;
}
if (map_bench->margs->ext_tx && args->n_threads > 1) {
fprintf(stderr,
"external transaction requires single thread\n");
goto err_free_bench;
}
if (map_bench->margs->alloc) {
map_bench->insert = map_insert_alloc_op;
map_bench->remove = map_remove_free_op;
map_bench->get = map_get_obj_op;
} else {
map_bench->insert = map_insert_root_op;
map_bench->remove = map_remove_root_op;
map_bench->get = map_get_root_op;
}
map_bench->nkeys = args->n_threads * args->n_ops_per_thread;
map_bench->init_nkeys = map_bench->nkeys;
size_per_key = map_bench->margs->alloc
? SIZE_PER_KEY + map_bench->args->dsize + ALLOC_OVERHEAD
: SIZE_PER_KEY;
map_bench->pool_size = map_bench->nkeys * size_per_key * FACTOR;
if (args->is_poolset || type == TYPE_DEVDAX) {
if (args->fsize < map_bench->pool_size) {
fprintf(stderr, "file size too large\n");
goto err_free_bench;
}
map_bench->pool_size = 0;
} else if (map_bench->pool_size < 2 * PMEMOBJ_MIN_POOL) {
map_bench->pool_size = 2 * PMEMOBJ_MIN_POOL;
}
if (args->is_dynamic_poolset) {
int ret = dynamic_poolset_create(args->fname,
map_bench->pool_size);
if (ret == -1)
goto err_free_bench;
if (util_safe_strcpy(path, POOLSET_PATH, sizeof(path)) != 0)
goto err_free_bench;
map_bench->pool_size = 0;
}
map_bench->pop = pmemobj_create(path, "map_bench", map_bench->pool_size,
args->fmode);
if (!map_bench->pop) {
fprintf(stderr, "pmemobj_create: %s\n", pmemobj_errormsg());
goto err_free_bench;
}
errno = os_mutex_init(&map_bench->lock);
if (errno) {
perror("os_mutex_init");
goto err_close;
}
map_bench->mapc = map_ctx_init(ops, map_bench->pop);
if (!map_bench->mapc) {
perror("map_ctx_init");
goto err_destroy_lock;
}
map_bench->root = POBJ_ROOT(map_bench->pop, struct root);
if (TOID_IS_NULL(map_bench->root)) {
fprintf(stderr, "pmemobj_root: %s\n", pmemobj_errormsg());
goto err_free_map;
}
map_bench->root_oid = map_bench->root.oid;
if (map_create(map_bench->mapc, &D_RW(map_bench->root)->map, nullptr)) {
perror("map_new");
goto err_free_map;
}
map_bench->map = D_RO(map_bench->root)->map;
pmembench_set_priv(bench, map_bench);
return 0;
err_free_map:
map_ctx_free(map_bench->mapc);
err_destroy_lock:
os_mutex_destroy(&map_bench->lock);
err_close:
pmemobj_close(map_bench->pop);
err_free_bench:
free(map_bench);
return -1;
}
/*
* map_common_exit -- common cleanup function for map_* benchmarks
*/
static int
map_common_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *tree = (struct map_bench *)pmembench_get_priv(bench);
os_mutex_destroy(&tree->lock);
map_ctx_free(tree->mapc);
pmemobj_close(tree->pop);
free(tree);
return 0;
}
/*
* map_keys_init -- initialize array with keys
*/
static int
map_keys_init(struct benchmark *bench, struct benchmark_args *args)
{
auto *map_bench = (struct map_bench *)pmembench_get_priv(bench);
assert(map_bench);
auto *targs = (struct map_bench_args *)args->opts;
assert(targs);
assert(map_bench->nkeys != 0);
map_bench->keys =
(uint64_t *)malloc(map_bench->nkeys * sizeof(*map_bench->keys));
if (!map_bench->keys) {
perror("malloc");
return -1;
}
int ret = 0;
mutex_lock_nofail(&map_bench->lock);
TX_BEGIN(map_bench->pop)
{
for (size_t i = 0; i < map_bench->nkeys; i++) {
uint64_t key;
PMEMoid oid;
do {
key = get_key(&targs->seed, targs->max_key);
oid = map_get(map_bench->mapc, map_bench->map,
key);
} while (!OID_IS_NULL(oid));
if (targs->alloc)
oid = pmemobj_tx_alloc(args->dsize,
OBJ_TYPE_NUM);
else
oid = map_bench->root_oid;
ret = map_insert(map_bench->mapc, map_bench->map, key,
oid);
if (ret)
break;
map_bench->keys[i] = key;
}
}
TX_ONABORT
{
ret = -1;
}
TX_END
mutex_unlock_nofail(&map_bench->lock);
if (!ret)
return 0;
free(map_bench->keys);
return ret;
}
/*
* map_keys_exit -- cleanup of keys array
*/
static int
map_keys_exit(struct benchmark *bench, struct benchmark_args *args)
{
auto *tree = (struct map_bench *)pmembench_get_priv(bench);
free(tree->keys);
return 0;
}
/*
* map_remove_init -- init function for map_remove benchmark
*/
static int
map_remove_init(struct benchmark *bench, struct benchmark_args *args)
{
int ret = map_common_init(bench, args);
if (ret)
return ret;
ret = map_keys_init(bench, args);
if (ret)
goto err_exit_common;
return 0;
err_exit_common:
map_common_exit(bench, args);
return -1;
}
/*
* map_remove_exit -- cleanup function for map_remove benchmark
*/
static int
map_remove_exit(struct benchmark *bench, struct benchmark_args *args)
{
map_keys_exit(bench, args);
return map_common_exit(bench, args);
}
/*
* map_bench_get_init -- init function for map_get benchmark
*/
static int
map_bench_get_init(struct benchmark *bench, struct benchmark_args *args)
{
int ret = map_common_init(bench, args);
if (ret)
return ret;
ret = map_keys_init(bench, args);
if (ret)
goto err_exit_common;
return 0;
err_exit_common:
map_common_exit(bench, args);
return -1;
}
/*
* map_get_exit -- exit function for map_get benchmark
*/
static int
map_get_exit(struct benchmark *bench, struct benchmark_args *args)
{
map_keys_exit(bench, args);
return map_common_exit(bench, args);
}
static struct benchmark_clo map_bench_clos[5];
static struct benchmark_info map_insert_info;
static struct benchmark_info map_remove_info;
static struct benchmark_info map_get_info;
CONSTRUCTOR(map_bench_constructor)
void
map_bench_constructor(void)
{
map_bench_clos[0].opt_short = 'T';
map_bench_clos[0].opt_long = "type";
map_bench_clos[0].descr =
"Type of container "
"[ctree|btree|rtree|rbtree|hashmap_tx|hashmap_atomic]";
map_bench_clos[0].off = clo_field_offset(struct map_bench_args, type);
map_bench_clos[0].type = CLO_TYPE_STR;
map_bench_clos[0].def = "ctree";
map_bench_clos[1].opt_short = 's';
map_bench_clos[1].opt_long = "seed";
map_bench_clos[1].descr = "PRNG seed";
map_bench_clos[1].off = clo_field_offset(struct map_bench_args, seed);
map_bench_clos[1].type = CLO_TYPE_UINT;
map_bench_clos[1].def = "1";
map_bench_clos[1].type_uint.size =
clo_field_size(struct map_bench_args, seed);
map_bench_clos[1].type_uint.base = CLO_INT_BASE_DEC;
map_bench_clos[1].type_uint.min = 1;
map_bench_clos[1].type_uint.max = UINT_MAX;
map_bench_clos[2].opt_short = 'M';
map_bench_clos[2].opt_long = "max-key";
map_bench_clos[2].descr = "maximum key (0 means no limit)";
map_bench_clos[2].off =
clo_field_offset(struct map_bench_args, max_key);
map_bench_clos[2].type = CLO_TYPE_UINT;
map_bench_clos[2].def = "0";
map_bench_clos[2].type_uint.size =
clo_field_size(struct map_bench_args, seed);
map_bench_clos[2].type_uint.base = CLO_INT_BASE_DEC;
map_bench_clos[2].type_uint.min = 0;
map_bench_clos[2].type_uint.max = UINT64_MAX;
map_bench_clos[3].opt_short = 'x';
map_bench_clos[3].opt_long = "external-tx";
map_bench_clos[3].descr = "Use external transaction for all "
"operations (works with single "
"thread only)";
map_bench_clos[3].off = clo_field_offset(struct map_bench_args, ext_tx);
map_bench_clos[3].type = CLO_TYPE_FLAG;
map_bench_clos[4].opt_short = 'A';
map_bench_clos[4].opt_long = "alloc";
map_bench_clos[4].descr = "Allocate object of specified size "
"when inserting";
map_bench_clos[4].off = clo_field_offset(struct map_bench_args, alloc);
map_bench_clos[4].type = CLO_TYPE_FLAG;
map_insert_info.name = "map_insert";
map_insert_info.brief = "Inserting to tree map";
map_insert_info.init = map_common_init;
map_insert_info.exit = map_common_exit;
map_insert_info.multithread = true;
map_insert_info.multiops = true;
map_insert_info.init_worker = map_insert_init_worker;
map_insert_info.free_worker = map_common_free_worker;
map_insert_info.operation = map_insert_op;
map_insert_info.measure_time = true;
map_insert_info.clos = map_bench_clos;
map_insert_info.nclos = ARRAY_SIZE(map_bench_clos);
map_insert_info.opts_size = sizeof(struct map_bench_args);
map_insert_info.rm_file = true;
map_insert_info.allow_poolset = true;
REGISTER_BENCHMARK(map_insert_info);
map_remove_info.name = "map_remove";
map_remove_info.brief = "Removing from tree map";
map_remove_info.init = map_remove_init;
map_remove_info.exit = map_remove_exit;
map_remove_info.multithread = true;
map_remove_info.multiops = true;
map_remove_info.init_worker = map_remove_init_worker;
map_remove_info.free_worker = map_common_free_worker;
map_remove_info.operation = map_remove_op;
map_remove_info.measure_time = true;
map_remove_info.clos = map_bench_clos;
map_remove_info.nclos = ARRAY_SIZE(map_bench_clos);
map_remove_info.opts_size = sizeof(struct map_bench_args);
map_remove_info.rm_file = true;
map_remove_info.allow_poolset = true;
REGISTER_BENCHMARK(map_remove_info);
map_get_info.name = "map_get";
map_get_info.brief = "Tree lookup";
map_get_info.init = map_bench_get_init;
map_get_info.exit = map_get_exit;
map_get_info.multithread = true;
map_get_info.multiops = true;
map_get_info.init_worker = map_bench_get_init_worker;
map_get_info.free_worker = map_common_free_worker;
map_get_info.operation = map_get_op;
map_get_info.measure_time = true;
map_get_info.clos = map_bench_clos;
map_get_info.nclos = ARRAY_SIZE(map_bench_clos);
map_get_info.opts_size = sizeof(struct map_bench_args);
map_get_info.rm_file = true;
map_get_info.allow_poolset = true;
REGISTER_BENCHMARK(map_get_info);
}
| 20,418 | 23.107438 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/clo.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* clo.cpp -- command line options module definitions
*/
#include <cassert>
#include <cerrno>
#include <cinttypes>
#include <cstring>
#include <err.h>
#include <getopt.h>
#include "benchmark.hpp"
#include "clo.hpp"
#include "clo_vec.hpp"
#include "queue.h"
#include "scenario.hpp"
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
typedef int (*clo_parse_fn)(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec);
typedef int (*clo_parse_single_fn)(struct benchmark_clo *clo, const char *arg,
void *ptr);
typedef int (*clo_eval_range_fn)(struct benchmark_clo *clo, void *first,
void *step, void *last, char type,
struct clo_vec_vlist *vlist);
typedef const char *(*clo_str_fn)(struct benchmark_clo *clo, void *addr,
size_t size);
#define STR_BUFF_SIZE 1024
static char str_buff[STR_BUFF_SIZE];
/*
* clo_parse_flag -- (internal) parse flag
*/
static int
clo_parse_flag(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec)
{
bool flag = true;
if (arg != nullptr) {
if (strcmp(arg, "true") == 0)
flag = true;
else if (strcmp(arg, "false") == 0)
flag = false;
else
return -1;
}
return clo_vec_memcpy(clovec, clo->off, sizeof(flag), &flag);
}
/*
* clo_parse_str -- (internal) parse string value
*/
static int
clo_parse_str(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec)
{
struct clo_vec_vlist *vlist = clo_vec_vlist_alloc();
assert(vlist != nullptr);
char *str = strdup(arg);
assert(str != nullptr);
clo_vec_add_alloc(clovec, str);
char *next = strtok(str, ",");
while (next) {
clo_vec_vlist_add(vlist, &next, sizeof(next));
next = strtok(nullptr, ",");
}
int ret = clo_vec_memcpy_list(clovec, clo->off, sizeof(str), vlist);
clo_vec_vlist_free(vlist);
return ret;
}
/*
* is_oct -- check if string may be octal number
*/
static int
is_oct(const char *arg, size_t len)
{
return (arg[0] == '0' || (len > 1 && arg[0] == '-' && arg[1] == '0'));
}
/*
* is_hex -- check if string may be hexadecimal number
*/
static int
is_hex(const char *arg, size_t len)
{
if (arg[0] == '-') {
arg++;
len--;
}
return (len > 2 && arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'));
}
/*
* parse_number_base -- parse string as integer of given sign and base
*/
static int
parse_number_base(const char *arg, void *value, int s, int base)
{
char *end;
errno = 0;
if (s) {
auto *v = (int64_t *)value;
*v = strtoll(arg, &end, base);
} else {
auto *v = (uint64_t *)value;
*v = strtoull(arg, &end, base);
}
if (errno || *end != '\0')
return -1;
return 0;
}
/*
* parse_number -- parse string as integer of given sign and allowed bases
*/
static int
parse_number(const char *arg, size_t len, void *value, int s, int base)
{
if ((base & CLO_INT_BASE_HEX) && is_hex(arg, len)) {
if (!parse_number_base(arg, value, s, 16))
return 0;
}
if ((base & CLO_INT_BASE_OCT) && is_oct(arg, len)) {
if (!parse_number_base(arg, value, s, 8))
return 0;
}
if (base & CLO_INT_BASE_DEC) {
if (!parse_number_base(arg, value, s, 10))
return 0;
}
return -1;
}
/*
* clo_parse_single_int -- (internal) parse single int value
*/
static int
clo_parse_single_int(struct benchmark_clo *clo, const char *arg, void *ptr)
{
int64_t value = 0;
size_t len = strlen(arg);
if (parse_number(arg, len, &value, 1, clo->type_int.base)) {
errno = EINVAL;
return -1;
}
int64_t tmax = ((int64_t)1 << (8 * clo->type_int.size - 1)) - 1;
int64_t tmin = -((int64_t)1 << (8 * clo->type_int.size - 1));
tmax = min(tmax, clo->type_int.max);
tmin = max(tmin, clo->type_int.min);
if (value > tmax || value < tmin) {
errno = ERANGE;
return -1;
}
memcpy(ptr, &value, clo->type_int.size);
return 0;
}
/*
* clo_parse_single_uint -- (internal) parse single uint value
*/
static int
clo_parse_single_uint(struct benchmark_clo *clo, const char *arg, void *ptr)
{
if (arg[0] == '-') {
errno = EINVAL;
return -1;
}
uint64_t value = 0;
size_t len = strlen(arg);
if (parse_number(arg, len, &value, 0, clo->type_uint.base)) {
errno = EINVAL;
return -1;
}
uint64_t tmax = ~0 >> (64 - 8 * clo->type_uint.size);
uint64_t tmin = 0;
tmax = min(tmax, clo->type_uint.max);
tmin = max(tmin, clo->type_uint.min);
if (value > tmax || value < tmin) {
errno = ERANGE;
return -1;
}
memcpy(ptr, &value, clo->type_uint.size);
return 0;
}
/*
* clo_eval_range_uint -- (internal) evaluate range for uint values
*/
static int
clo_eval_range_uint(struct benchmark_clo *clo, void *first, void *step,
void *last, char type, struct clo_vec_vlist *vlist)
{
uint64_t curr = *(uint64_t *)first;
uint64_t l = *(uint64_t *)last;
int64_t s = *(int64_t *)step;
while (1) {
clo_vec_vlist_add(vlist, &curr, clo->type_uint.size);
switch (type) {
case '+':
curr += s;
if (curr > l)
return 0;
break;
case '-':
if (curr < (uint64_t)s)
return 0;
curr -= s;
if (curr < l)
return 0;
break;
case '*':
curr *= s;
if (curr > l)
return 0;
break;
case '/':
curr /= s;
if (curr < l)
return 0;
break;
default:
return -1;
}
}
return -1;
}
/*
* clo_eval_range_int -- (internal) evaluate range for int values
*/
static int
clo_eval_range_int(struct benchmark_clo *clo, void *first, void *step,
void *last, char type, struct clo_vec_vlist *vlist)
{
int64_t curr = *(int64_t *)first;
int64_t l = *(int64_t *)last;
uint64_t s = *(uint64_t *)step;
while (1) {
clo_vec_vlist_add(vlist, &curr, clo->type_int.size);
switch (type) {
case '+':
curr += s;
if (curr > l)
return 0;
break;
case '-':
curr -= s;
if (curr < l)
return 0;
break;
case '*':
curr *= s;
if (curr > l)
return 0;
break;
case '/':
curr /= s;
if (curr < l)
return 0;
break;
default:
return -1;
}
}
return -1;
}
/*
* clo_check_range_params -- (internal) validate step and step type
*/
static int
clo_check_range_params(uint64_t step, char step_type)
{
switch (step_type) {
/*
* Cannot construct range with step equal to 0
* for '+' or '-' range.
*/
case '+':
case '-':
if (step == 0)
return -1;
break;
/*
* Cannot construct range with step equal to 0 or 1
* for '*' or '/' range.
*/
case '*':
case '/':
if (step == 0 || step == 1)
return -1;
break;
default:
return -1;
}
return 0;
}
/*
* clo_parse_range -- (internal) parse range or value
*
* The range may be in the following format:
* <first>:<step type><step>:<last>
*
* Step type must be one of the following: +, -, *, /.
*/
static int
clo_parse_range(struct benchmark_clo *clo, const char *arg,
clo_parse_single_fn parse_single, clo_eval_range_fn eval_range,
struct clo_vec_vlist *vlist)
{
auto *str_first = (char *)malloc(strlen(arg) + 1);
assert(str_first != nullptr);
auto *str_step = (char *)malloc(strlen(arg) + 1);
assert(str_step != nullptr);
char step_type = '\0';
auto *str_last = (char *)malloc(strlen(arg) + 1);
assert(str_last != nullptr);
int ret = sscanf(arg, "%[^:]:%c%[^:]:%[^:]", str_first, &step_type,
str_step, str_last);
if (ret == 1) {
/* single value */
uint64_t value;
if (parse_single(clo, arg, &value)) {
ret = -1;
} else {
if (clo->type == CLO_TYPE_UINT)
clo_vec_vlist_add(vlist, &value,
clo->type_uint.size);
else
clo_vec_vlist_add(vlist, &value,
clo->type_int.size);
ret = 0;
}
} else if (ret == 4) {
/* range */
uint64_t first = 0;
uint64_t last = 0;
uint64_t step = 0;
if (parse_single(clo, str_first, &first)) {
ret = -1;
goto out;
}
char *end;
errno = 0;
step = strtoull(str_step, &end, 10);
if (errno || !end || *end != '\0') {
ret = -1;
goto out;
}
if (parse_single(clo, str_last, &last)) {
ret = -1;
goto out;
}
if (clo_check_range_params(step, step_type)) {
ret = -1;
goto out;
}
/* evaluate the range */
if (eval_range(clo, &first, &step, &last, step_type, vlist)) {
ret = -1;
goto out;
}
ret = 0;
} else {
ret = -1;
}
out:
free(str_first);
free(str_step);
free(str_last);
return ret;
}
/*
* clo_parse_ranges -- (internal) parse ranges/values separated by commas
*/
static int
clo_parse_ranges(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec, clo_parse_single_fn parse_single,
clo_eval_range_fn eval_range)
{
struct clo_vec_vlist *vlist = clo_vec_vlist_alloc();
assert(vlist != nullptr);
int ret = 0;
char *args = strdup(arg);
assert(args != nullptr);
char *curr = args;
char *next;
/* iterate through all values separated by comma */
while ((next = strchr(curr, ',')) != nullptr) {
*next = '\0';
next++;
/* parse each comma separated value as range or single value */
if ((ret = clo_parse_range(clo, curr, parse_single, eval_range,
vlist)))
goto out;
curr = next;
}
/* parse each comma separated value as range or single value */
if ((ret = clo_parse_range(clo, curr, parse_single, eval_range, vlist)))
goto out;
/* add list of values to CLO vector */
if (clo->type == CLO_TYPE_UINT)
ret = clo_vec_memcpy_list(clovec, clo->off, clo->type_uint.size,
vlist);
else
ret = clo_vec_memcpy_list(clovec, clo->off, clo->type_int.size,
vlist);
out:
free(args);
clo_vec_vlist_free(vlist);
return ret;
}
/*
* clo_parse_int -- (internal) parse int value
*/
static int
clo_parse_int(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec)
{
return clo_parse_ranges(clo, arg, clovec, clo_parse_single_int,
clo_eval_range_int);
}
/*
* clo_parse_uint -- (internal) parse uint value
*/
static int
clo_parse_uint(struct benchmark_clo *clo, const char *arg,
struct clo_vec *clovec)
{
return clo_parse_ranges(clo, arg, clovec, clo_parse_single_uint,
clo_eval_range_uint);
}
/*
* clo_str_flag -- (internal) convert flag value to string
*/
static const char *
clo_str_flag(struct benchmark_clo *clo, void *addr, size_t size)
{
if (clo->off + sizeof(bool) > size)
return nullptr;
bool flag = *(bool *)((char *)addr + clo->off);
return flag ? "true" : "false";
}
/*
* clo_str_str -- (internal) convert str value to string
*/
static const char *
clo_str_str(struct benchmark_clo *clo, void *addr, size_t size)
{
if (clo->off + sizeof(char *) > size)
return nullptr;
return *(char **)((char *)addr + clo->off);
}
/*
* clo_str_int -- (internal) convert int value to string
*/
static const char *
clo_str_int(struct benchmark_clo *clo, void *addr, size_t size)
{
if (clo->off + clo->type_int.size > size)
return nullptr;
void *val = (char *)addr + clo->off;
int ret = 0;
switch (clo->type_int.size) {
case 1:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRId8,
*(int8_t *)val);
break;
case 2:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRId16,
*(int16_t *)val);
break;
case 4:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRId32,
*(int32_t *)val);
break;
case 8:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRId64,
*(int64_t *)val);
break;
default:
return nullptr;
}
if (ret < 0)
return nullptr;
return str_buff;
}
/*
* clo_str_uint -- (internal) convert uint value to string
*/
static const char *
clo_str_uint(struct benchmark_clo *clo, void *addr, size_t size)
{
if (clo->off + clo->type_uint.size > size)
return nullptr;
void *val = (char *)addr + clo->off;
int ret = 0;
switch (clo->type_uint.size) {
case 1:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRIu8,
*(uint8_t *)val);
break;
case 2:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRIu16,
*(uint16_t *)val);
break;
case 4:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRIu32,
*(uint32_t *)val);
break;
case 8:
ret = util_snprintf(str_buff, STR_BUFF_SIZE, "%" PRIu64,
*(uint64_t *)val);
break;
default:
return nullptr;
}
if (ret < 0)
return nullptr;
return str_buff;
}
/*
* clo_parse -- (internal) array with functions for parsing CLOs
*/
static clo_parse_fn clo_parse[CLO_TYPE_MAX] = {
/* [CLO_TYPE_FLAG] = */ clo_parse_flag,
/* [CLO_TYPE_STR] = */ clo_parse_str,
/* [CLO_TYPE_INT] = */ clo_parse_int,
/* [CLO_TYPE_UINT] = */ clo_parse_uint,
};
/*
* clo_str -- (internal) array with functions for converting to string
*/
static clo_str_fn clo_str[CLO_TYPE_MAX] = {
/* [CLO_TYPE_FLAG] = */ clo_str_flag,
/* [CLO_TYPE_STR] = */ clo_str_str,
/* [CLO_TYPE_INT] = */ clo_str_int,
/* [CLO_TYPE_UINT] = */ clo_str_uint,
};
/*
* clo_get_by_short -- (internal) return CLO with specified short opt
*/
static struct benchmark_clo *
clo_get_by_short(struct benchmark_clo *clos, size_t nclo, char opt_short)
{
size_t i;
for (i = 0; i < nclo; i++) {
if (clos[i].opt_short == opt_short)
return &clos[i];
}
return nullptr;
}
/*
* clo_get_by_long -- (internal) return CLO with specified long opt
*/
static struct benchmark_clo *
clo_get_by_long(struct benchmark_clo *clos, size_t nclo, const char *opt_long)
{
size_t i;
for (i = 0; i < nclo; i++) {
if (strcmp(clos[i].opt_long, opt_long) == 0)
return &clos[i];
}
return nullptr;
}
/*
* clo_get_optstr -- (internal) returns option string from CLOs
*
* This function returns option string which contains all short
* options from CLO structure.
* The returned value must be freed by caller.
*/
static char *
clo_get_optstr(struct benchmark_clo *clos, size_t nclo)
{
size_t i;
char *optstr;
char *ptr;
/*
* In worst case every option requires an argument
* so we need space for ':' character + terminating
* NULL.
*/
size_t optstrlen = nclo * 2 + 1;
optstr = (char *)calloc(1, optstrlen);
assert(optstr != nullptr);
ptr = optstr;
for (i = 0; i < nclo; i++) {
if (clos[i].opt_short) {
*(ptr++) = clos[i].opt_short;
if (clos[i].type != CLO_TYPE_FLAG)
*(ptr++) = ':';
}
}
return optstr;
}
/*
* clo_get_long_options -- (internal) allocate long options structure
*
* This function allocates structure for long options and fills all
* entries according to values from becnhmark_clo. This is essentially
* conversion from struct benchmark_clo to struct option.
* The returned value must be freed by caller.
*/
static struct option *
clo_get_long_options(struct benchmark_clo *clos, size_t nclo)
{
size_t i;
struct option *options;
options = (struct option *)calloc(nclo + 1, sizeof(struct option));
assert(options != nullptr);
for (i = 0; i < nclo; i++) {
options[i].name = clos[i].opt_long;
options[i].val = clos[i].opt_short;
/* no optional arguments */
if (clos[i].type == CLO_TYPE_FLAG) {
options[i].has_arg = no_argument;
} else {
options[i].has_arg = required_argument;
}
}
return options;
}
/*
* clo_set_defaults -- (internal) set default values
*
* Default values are stored as strings in CLO
* structure so this function parses default values in
* the same manner as values passed by user. Returns -1
* if argument was not passed by user and default value
* is missing.
*/
static int
clo_set_defaults(struct benchmark_clo *clos, size_t nclo,
struct clo_vec *clovec)
{
size_t i;
for (i = 0; i < nclo; i++) {
if (clos[i].used)
continue;
/*
* If option was not used and default value
* is not specified, return error. Otherwise
* parse the default value in the same way as
* values passed by user. Except for the flag.
* If the flag default value was not specified
* assign "false" value to it.
*/
if (clos[i].def) {
if (clo_parse[clos[i].type](&clos[i], clos[i].def,
clovec))
return -1;
} else if (clos[i].type == CLO_TYPE_FLAG) {
if (clo_parse[clos[i].type](&clos[i], "false", clovec))
return -1;
} else {
printf("'%s' is required option\n", clos[i].opt_long);
return -1;
}
}
return 0;
}
/*
* benchmark_clo_parse -- parse CLOs and store values in desired structure
*
* This function parses command line arguments according to information
* from CLOs structure. The parsed values are stored in CLO vector
* pointed by clovec. If any of command line options are not passed by user,
* the default value is stored if exists. Otherwise it means the argument is
* required and error is returned.
*
* - argc - number of command line options passed by user
* - argv - command line options passed by user
* - clos - description of available command line options
* - nclos - number of available command line options
* - clovec - vector of arguments
*/
int
benchmark_clo_parse(int argc, char *argv[], struct benchmark_clo *clos,
ssize_t nclos, struct clo_vec *clovec)
{
char *optstr;
struct option *options;
int ret = 0;
int opt;
int optindex;
/* convert CLOs to option string and long options structure */
optstr = clo_get_optstr(clos, nclos);
options = clo_get_long_options(clos, nclos);
/* parse CLOs as long and/or short options */
while ((opt = getopt_long(argc, argv, optstr, options, &optindex)) !=
-1) {
struct benchmark_clo *clo = nullptr;
if (opt) {
clo = clo_get_by_short(clos, nclos, opt);
} else {
assert(optindex < nclos);
clo = &clos[optindex];
}
if (!clo) {
ret = -1;
goto out;
}
/* invoke parser according to type of CLO */
assert(clo->type < CLO_TYPE_MAX);
ret = clo_parse[clo->type](clo, optarg, clovec);
if (ret)
goto out;
/* mark CLO as used */
clo->used = optarg != nullptr || clo->type == CLO_TYPE_FLAG;
}
if (optind < argc) {
fprintf(stderr, "Unknown option: %s\n", argv[optind]);
ret = -1;
goto out;
}
/* parse unused CLOs with default values */
ret = clo_set_defaults(clos, nclos, clovec);
out:
free(options);
free(optstr);
if (ret)
errno = EINVAL;
return ret;
}
/*
* benchmark_clo_parse_scenario -- parse CLOs from scenario
*
* This function parses command line arguments according to information
* from CLOs structure. The parsed values are stored in CLO vector
* pointed by clovec. If any of command line options are not passed by user,
* the default value is stored if exists. Otherwise it means the argument is
* required and error is returned.
*
* - scenario - scenario with key value arguments
* - clos - description of available command line options
* - nclos - number of available command line options
* - clovec - vector of arguments
*/
int
benchmark_clo_parse_scenario(struct scenario *scenario,
struct benchmark_clo *clos, size_t nclos,
struct clo_vec *clovec)
{
struct kv *kv;
FOREACH_KV(kv, scenario)
{
struct benchmark_clo *clo =
clo_get_by_long(clos, nclos, kv->key);
if (!clo) {
fprintf(stderr, "unrecognized option -- '%s'\n",
kv->key);
return -1;
}
assert(clo->type < CLO_TYPE_MAX);
if (clo_parse[clo->type](clo, kv->value, clovec)) {
fprintf(stderr, "parsing option -- '%s' failed\n",
kv->value);
return -1;
}
/* mark CLO as used */
clo->used = 1;
}
return clo_set_defaults(clos, nclos, clovec);
}
/*
* benchmark_override_clos_in_scenario - parse the command line arguments and
* override/add the parameters in/to the scenario by replacing/adding the kv
* struct in/to the scenario.
*
* - scenario - scenario with key value arguments
* - argc - command line arguments number
* - argv - command line arguments vector
* - clos - description of available command line options
* - nclos - number of available command line options
*/
int
benchmark_override_clos_in_scenario(struct scenario *scenario, int argc,
char *argv[], struct benchmark_clo *clos,
int nclos)
{
char *optstr;
struct option *options;
int ret = 0;
int opt;
int optindex;
const char *true_str = "true";
/* convert CLOs to option string and long options structure */
optstr = clo_get_optstr(clos, nclos);
options = clo_get_long_options(clos, nclos);
/* parse CLOs as long and/or short options */
while ((opt = getopt_long(argc, argv, optstr, options, &optindex)) !=
-1) {
struct benchmark_clo *clo = nullptr;
if (opt) {
clo = clo_get_by_short(clos, nclos, opt);
} else {
assert(optindex < nclos);
clo = &clos[optindex];
}
if (!clo) {
ret = -1;
goto out;
}
/* Check if the given clo is defined in the scenario */
struct kv *kv = find_kv_in_scenario(clo->opt_long, scenario);
if (kv) { /* replace the value in the scenario */
if (optarg != nullptr && clo->type != CLO_TYPE_FLAG) {
free(kv->value);
kv->value = strdup(optarg);
} else if (optarg == nullptr &&
clo->type == CLO_TYPE_FLAG) {
free(kv->value);
kv->value = strdup(true_str);
} else {
ret = -1;
goto out;
}
} else { /* add a new param to the scenario */
if (optarg != nullptr && clo->type != CLO_TYPE_FLAG) {
kv = kv_alloc(clo->opt_long, optarg);
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv,
next);
} else if (optarg == nullptr &&
clo->type == CLO_TYPE_FLAG) {
kv = kv_alloc(clo->opt_long, true_str);
PMDK_TAILQ_INSERT_TAIL(&scenario->head, kv,
next);
} else {
ret = -1;
goto out;
}
}
}
if (optind < argc) {
fprintf(stderr, "Unknown option: %s\n", argv[optind]);
ret = -1;
goto out;
}
out:
free(options);
free(optstr);
if (ret)
errno = EINVAL;
return ret;
}
/*
* benchmark_clo_str -- converts command line option to string
*
* According to command line option type and parameters, converts
* the value from structure pointed by args of size size.
*/
const char *
benchmark_clo_str(struct benchmark_clo *clo, void *args, size_t size)
{
assert(clo->type < CLO_TYPE_MAX);
return clo_str[clo->type](clo, args, size);
}
/*
* clo_get_scenarios - search the command line arguments for scenarios listed in
* available_scenarios and put them in found_scenarios. Returns the number of
* found scenarios in the cmd line or -1 on error. The passed cmd line
* args should contain the scenario name(s) as the first argument(s) - starting
* from index 0
*/
int
clo_get_scenarios(int argc, char *argv[], struct scenarios *available_scenarios,
struct scenarios *found_scenarios)
{
assert(argv != nullptr);
assert(available_scenarios != nullptr);
assert(found_scenarios != nullptr);
if (argc <= 0) {
fprintf(stderr, "clo get scenarios, argc invalid value: %d\n",
argc);
return -1;
}
int tmp_argc = argc;
char **tmp_argv = argv;
do {
struct scenario *scenario =
scenarios_get_scenario(available_scenarios, *tmp_argv);
if (!scenario) {
fprintf(stderr, "unknown scenario: %s\n", *tmp_argv);
return -1;
}
struct scenario *new_scenario = clone_scenario(scenario);
assert(new_scenario != nullptr);
PMDK_TAILQ_INSERT_TAIL(&found_scenarios->head, new_scenario,
next);
tmp_argc--;
tmp_argv++;
} while (tmp_argc &&
contains_scenarios(tmp_argc, tmp_argv, available_scenarios));
return argc - tmp_argc;
}
| 23,174 | 21.609756 | 80 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/poolset_util.cpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018, Intel Corporation */
#include <cassert>
#include <fcntl.h>
#include <file.h>
#include "os.h"
#include "poolset_util.hpp"
#include "set.h"
#define PART_TEMPLATE "part."
#define POOL_PART_SIZE (1UL << 30)
/*
* dynamic_poolset_clear -- clears header in first part if it exists
*/
static int
dynamic_poolset_clear(const char *dir)
{
char path[PATH_MAX];
int count = snprintf(path, sizeof(path),
"%s" OS_DIR_SEP_STR PART_TEMPLATE "0", dir);
assert(count > 0);
if ((size_t)count >= sizeof(path)) {
fprintf(stderr, "path to a poolset part too long\n");
return -1;
}
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists)
return 0;
return util_file_zero(path, 0, POOL_HDR_SIZE);
}
/*
* dynamic_poolset_create -- clear pool's header and create new poolset
*/
int
dynamic_poolset_create(const char *path, size_t size)
{
/* buffer for part's path and size */
char buff[PATH_MAX + 20];
int ret;
int fd;
int count;
int curr_part = 0;
ret = dynamic_poolset_clear(path);
if (ret == -1)
return -1;
fd = os_open(POOLSET_PATH, O_RDWR | O_CREAT, 0644);
if (fd == -1) {
perror("open");
return -1;
}
char header[] = "PMEMPOOLSET\nOPTION SINGLEHDR\n";
ret = util_write_all(fd, header, sizeof(header) - 1);
if (ret == -1)
goto err;
while (curr_part * POOL_PART_SIZE < size + POOL_HDR_SIZE) {
count = snprintf(buff, sizeof(buff),
"%lu %s" OS_DIR_SEP_STR PART_TEMPLATE "%d\n",
POOL_PART_SIZE, path, curr_part);
assert(count > 0);
if ((size_t)count >= sizeof(buff)) {
fprintf(stderr, "path to a poolset part too long\n");
goto err;
}
ret = util_write_all(fd, buff, count);
if (ret == -1)
goto err;
curr_part++;
}
close(fd);
return 0;
err:
close(fd);
return -1;
}
| 1,827 | 18.446809 | 71 | cpp |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/benchmarks/benchmark_time.hpp | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2017, Intel Corporation */
/*
* benchmark_time.hpp -- declarations of benchmark_time module
*/
#include <ctime>
typedef struct timespec benchmark_time_t;
void benchmark_time_get(benchmark_time_t *time);
void benchmark_time_diff(benchmark_time_t *d, benchmark_time_t *t1,
benchmark_time_t *t2);
double benchmark_time_get_secs(benchmark_time_t *t);
unsigned long long benchmark_time_get_nsecs(benchmark_time_t *t);
int benchmark_time_compare(const benchmark_time_t *t1,
const benchmark_time_t *t2);
void benchmark_time_set(benchmark_time_t *time, unsigned long long nsecs);
unsigned long long benchmark_get_avg_get_time(void);
| 698 | 35.789474 | 74 | hpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.