blob: 3f61f83a7fc181c4a4ded55f0abbf63c2d73c25a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
EAPI="5"
PYTHON_COMPAT=( python2_7 )
inherit eutils multilib toolchain-funcs perl-functions python-any-r1
DESCRIPTION="easy hugepage access"
HOMEPAGE="https://github.com/libhugetlbfs/libhugetlbfs"
SRC_URI="https://github.com/libhugetlbfs/libhugetlbfs/archive/${PV}.tar.gz -> ${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~s390 ~x86"
IUSE="perl static-libs test"
DEPEND="test? ( ${PYTHON_DEPS} )"
RDEPEND="perl? ( dev-lang/perl:= )"
src_prepare() {
perl_set_version
epatch "${FILESDIR}"/${PN}-2.9-build.patch #332517
epatch "${FILESDIR}"/${PN}-2.20-noexec-stack.patch
epatch "${FILESDIR}"/${PN}-2.6-fixup-testsuite.patch
sed -i \
-e '/^PREFIX/s:/local::' \
-e '1iBUILDTYPE = NATIVEONLY' \
-e '1iV = 1' \
-e '/gzip.*MANDIR/d' \
-e "/^LIB\(32\)/s:=.*:= $(get_libdir):" \
-e '/^CC\(32\|64\)/s:=.*:= $(CC):' \
-e "/^PMDIR = .*\/perl5\/TLBC/s::PMDIR = ${VENDOR_LIB}\/TLBC:" \
Makefile || die "sed failed"
if [ "$(get_libdir)" == "lib64" ]; then
sed -i \
-e "/^LIB\(32\)/s:=.*:= lib32:" \
Makefile
fi
# Tarballs from github don't have the version set.
# https://github.com/libhugetlbfs/libhugetlbfs/issues/7
[[ -f version ]] || echo "${PV}" > version
}
src_compile() {
tc-export AR
emake CC="$(tc-getCC)" libs tools
}
src_install() {
default
use static-libs || rm -f "${ED}"/usr/$(get_libdir)/*.a
rm "${ED}"/usr/bin/oprofile* || die
if ! use perl ; then
rm -r \
"${ED}"/usr/bin/cpupcstat \
"${ED}"/usr/share/man/man8/cpupcstat.8 \
"${ED}/${VENDOR_LIB}" \
|| die
fi
}
src_test_alloc_one() {
hugeadm="$1"
sign="$2"
pagesize="$3"
pagecount="$4"
${hugeadm} \
--pool-pages-max ${pagesize}:${sign}${pagecount} \
&& \
${hugeadm} \
--pool-pages-min ${pagesize}:${sign}${pagecount}
return $?
}
# die is NOT allowed in this src_test block after the marked point, so that we
# can clean up memory allocation. You'll leak at LEAST 64MiB per run otherwise.
src_test() {
[[ $UID -eq 0 ]] || die "Need FEATURES=-userpriv to run this testsuite"
einfo "Building testsuite"
emake -j1 tests || die "Failed to build tests"
hugeadm='obj/hugeadm'
allocated=''
rc=0
# the testcases need 64MiB per pagesize.
MIN_HUGEPAGE_RAM=$((64*1024*1024))
einfo "Planning allocation"
PAGESIZES="$(${hugeadm} --page-sizes-all)"
# Need to do this before we can create the mountpoints.
for pagesize in ${PAGESIZES} ; do
# The kernel depends on the location :-(
mkdir -p /var/lib/hugetlbfs/pagesize-${pagesize}
addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
done
addwrite /proc/sys/vm/
addwrite /proc/sys/kernel/shmall
addwrite /proc/sys/kernel/shmmax
addwrite /proc/sys/kernel/shmmni
einfo "Checking HugeTLB mountpoints"
${hugeadm} --create-mounts || die "Failed to set up hugetlb mountpoints."
# -----------------------------------------------------
# --------- die is unsafe after this point. -----------
# -----------------------------------------------------
einfo "Starting allocation"
for pagesize in ${PAGESIZES} ; do
pagecount=$((${MIN_HUGEPAGE_RAM}/${pagesize}))
einfo " ${pagecount} @ ${pagesize}"
addwrite /var/lib/hugetlbfs/pagesize-${pagesize}
src_test_alloc_one "$hugeadm" "+" "${pagesize}" "${pagecount}"
rc=$?
if [[ $rc -eq 0 ]]; then
allocated="${allocated} ${pagesize}:${pagecount}"
else
eerror "Failed to add ${pagecount} pages of size ${pagesize}"
fi
done
einfo "Allocation status"
${hugeadm} --pool-list
if [[ -n "${allocated}" ]]; then
# All our allocations worked, so time to run.
einfo "Starting tests"
cd "${S}"/tests
TESTOPTS="-t func"
case $ARCH in
amd64|ppc64)
TESTOPTS="${TESTOPTS} -b 64"
;;
x86)
TESTOPTS="${TESTOPTS} -b 32"
;;
esac
# This needs a bit of work to give a nice exit code still.
./run_tests.py ${TESTOPTS}
rc=$?
else
eerror "Failed to make HugeTLB allocations."
rc=1
fi
einfo "Cleaning up memory"
cd "${S}"
# Cleanup memory allocation
for alloc in ${allocated} ; do
pagesize="${alloc/:*}"
pagecount="${alloc/*:}"
einfo " ${pagecount} @ ${pagesize}"
src_test_alloc_one "$hugeadm" "-" "${pagesize}" "${pagecount}"
done
# ---------------------------------------------------------
# --------- die is safe again after this point. -----------
# ---------------------------------------------------------
return $rc
}
|