libhugetlbfs-2.20.ebuild 4.4 KB

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