libhugetlbfs-2.19-r1.ebuild 4.3 KB

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