app-benchmarks/i7z : Import i7z utility from gentoo

Import i7z-0.27-r1 from gentoo.
Also pull in qt4-r2 eclass from gentoo, which i7z
ebuild inherits.

BUG=chromium-os:19663
TEST=gmerge i7z. Ensure the utility runs
from /usr/sbin/i7z on a Sandy Bridge system.

Change-Id: I51e31e1015790dedb1ad5dbd7ac3734476af05dd
Signed-off-by: Benson Leung <bleung@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/7196
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Benson Leung 2011-09-01 14:46:17 -07:00
parent 95c3c7b783
commit 70a22d535a
4 changed files with 508 additions and 0 deletions

View File

@ -0,0 +1,56 @@
diff --git a/Makefile b/Makefile
index fc4d262..e2347bf 100644
--- a/Makefile
+++ b/Makefile
@@ -17,18 +17,18 @@
#makefile updated from patch by anestling
-CFLAGSANY = -g -O0 -fomit-frame-pointer -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wall
+CFLAGS += -O0 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wall
LBITS := $(shell getconf LONG_BIT)
ifeq ($(LBITS),64)
- CFLAGS = $(CFLAGSANY) -Dx64_BIT
+ CFLAGS += -Dx64_BIT
else
- CFLAGS = $(CFLAGSANY) -Dx86
+ CFLAGS += -Dx86
endif
-CC = gcc
+CC ?= gcc
-LDFLAGS = -lncurses -lpthread -lrt
+LIBS = -lncurses -lpthread -lrt
INCLUDEFLAGS =
OBJS = helper_functions
@@ -36,15 +36,15 @@ OBJS = helper_functions
BIN = i7z
SRC = i7z.c helper_functions.c i7z_Single_Socket.c i7z_Dual_Socket.c
-sbindir = /usr/sbin
+sbindir = $(DESTDIR)/usr/sbin
-all: clean message bin
+all: clean bin
message:
@echo "If the compilation complains about not finding ncurses.h, install ncurses (libncurses5-dev on ubuntu/debian)"
bin:
- $(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDEFLAGS) $(SRC) -o $(BIN)
+ $(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDEFLAGS) $(SRC) -o $(BIN) $(LIBS)
clean:
rm -f *.o $(BIN)
@@ -52,6 +52,6 @@ clean:
distclean: clean
rm -f *~ \#*
-install: all
- install -m 755 $(BIN) $(sbindir)
+install:
+ install -D -m 755 $(BIN) $(sbindir)/$(BIN)

View File

@ -0,0 +1,127 @@
http://code.google.com/p/i7z/issues/detail?id=31
this makes cpuid work on 32bit and 64bit systems, both PIC and non-PIC
the things it fixes:
- no more silent clobbering of ebx/ecx/edx
- works under 32bit pic builds (gcc doesnt like to clobber ebx)
- ebx gets saved/restored via edi register
- get_vendor incorrectly used ebx,ecx,edx when it should be ebx,edx,ecx
- unify all the cpuid implementations to make usage much simpler
I WROTE THIS
--- a/helper_functions.c
+++ b/helper_functions.c
@@ -87,41 +87,40 @@ print_family_info (struct family_info *proc_info)
// printf(" Extended Family %d\n", proc_info->extended_family);
}
+static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx,
+ unsigned int *ecx, unsigned int *edx)
+{
+ unsigned int _eax = info, _ebx, _ecx, _edx;
+ asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC)
+ "cpuid;"
+ "mov %%ebx, %%esi;" // pass to caller
+ "mov %%edi, %%ebx;" // restore ebx
+ :"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx)
+ : /* inputs: eax is handled above */
+ :"edi" /* clobbers: we hit edi directly */);
+ if (eax) *eax = _eax;
+ if (ebx) *ebx = _ebx;
+ if (ecx) *ecx = _ecx;
+ if (edx) *edx = _edx;
+}
-#ifdef x64_BIT
void get_vendor (char *vendor_string)
{
//get vendor name
- unsigned int b, c, d, e;
- // int i;
- asm volatile ("mov %4, %%eax; " // 0 into eax
- "cpuid;" "mov %%eax, %0;" // eeax into b
- "mov %%ebx, %1;" // eebx into c
- "mov %%edx, %2;" // eeax into d
- "mov %%ecx, %3;" // eeax into e
- :"=r" (b), "=r" (c), "=r" (d), "=r" (e) /* output */
- :"r" (0) /* input */
- :"%eax", "%ebx", "%ecx", "%edx" /* clobbered register, will be modifying inside the asm routine so dont use them */
- );
- memcpy (vendor_string, &c, 4);
+ unsigned int a, b, c, d;
+ cpuid (0, &a, &b, &c, &d);
+ memcpy (vendor_string, &b, 4);
memcpy (vendor_string + 4, &d, 4);
- memcpy (vendor_string + 8, &e, 4);
+ memcpy (vendor_string + 8, &c, 4);
vendor_string[12] = '\0';
// printf("Vendor %s\n",vendor_string);
}
-#endif
int turbo_status ()
{
//turbo state flag
unsigned int eax;
- // int i;
- asm volatile ("mov %1, %%eax; " // 0 into eax
- "cpuid;" "mov %%eax, %0;" // eeax into b
- :"=r" (eax) /* output */
- :"r" (6) /* input */
- :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */
- );
+ cpuid (6, &eax, NULL, NULL, NULL);
//printf("eax %d\n",(eax&0x2)>>1);
@@ -132,12 +131,7 @@ void get_familyinformation (struct family_info *proc_info)
{
//get info about CPU
unsigned int b;
- asm volatile ("mov %1, %%eax; " // 0 into eax
- "cpuid;" "mov %%eax, %0;" // eeax into b
- :"=r" (b) /* output */
- :"r" (1) /* input */
- :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */
- );
+ cpuid (1, &b, NULL, NULL, NULL);
// printf ("eax %x\n", b);
proc_info->stepping = b & 0x0000000F; //bits 3:0
proc_info->model = (b & 0x000000F0) >> 4; //bits 7:4
@@ -348,7 +342,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge)
{
struct family_info proc_info;
-#ifdef x64_BIT
char vendor_string[13];
get_vendor (vendor_string);
if (strcmp (vendor_string, "GenuineIntel") == 0)
@@ -359,14 +352,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge)
("this was designed to be a intel proc utility. You can perhaps mod it for your machine?\n");
exit (1);
}
-#endif
-
-#ifndef x64_BIT
- //anecdotal evidence: get_vendor doesnt seem to work on 32-bit
- printf
- ("I dont know the CPUID code to check on 32-bit OS, so i will assume that you have an Intel processor\n");
- printf ("Don't worry if i don't find a nehalem next, i'll quit anyways\n");
-#endif
get_familyinformation (&proc_info);
print_family_info (&proc_info);
--- a/i7z.h
+++ b/i7z.h
@@ -106,9 +106,7 @@ __asm__ __volatile__ ("rdtsc":"=a" (lo), "=d" (hi));
void print_family_info (struct family_info *proc_info);
-#ifdef x64_BIT
void get_vendor (char *vendor_string);
-#endif
int turbo_status ();
double cpufreq_info();

View File

@ -0,0 +1,46 @@
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-benchmarks/i7z/i7z-0.27-r1.ebuild,v 1.1 2011/08/31 14:16:25 vapier Exp $
EAPI="4"
inherit eutils qt4-r2 toolchain-funcs
DESCRIPTION="A better i7 (and now i3, i5) reporting tool for Linux"
HOMEPAGE="http://code.google.com/p/i7z/"
SRC_URI="http://${PN}.googlecode.com/files/${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
IUSE="X"
RDEPEND="
sys-libs/ncurses
X? ( x11-libs/qt-gui:4 )"
DEPEND="${RDEPEND}"
S="${WORKDIR}"/${PN}
src_prepare() {
epatch "${FILESDIR}"/${PV}-gentoo.patch
epatch "${FILESDIR}"/${P}-cpuid.patch
tc-export CC
}
src_compile() {
default
if use X; then
cd GUI
eqmake4 GUI.pro
emake
fi
}
src_install() {
emake DESTDIR="${ED}" install
if use X; then
newsbin GUI/GUI i7z_GUI
fi
dodoc put_cores_o*line.sh MAKEDEV-cpuid-msr
}

View File

@ -0,0 +1,279 @@
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/qt4-r2.eclass,v 1.12 2011/08/22 04:46:32 vapier Exp $
# @ECLASS: qt4-r2.eclass
# @MAINTAINER:
# Ben de Groot <yngwin@gentoo.org>,
# Markos Chandras <hwoarang@gentoo.org>,
# Davide Pesavento <davidepesa@gmail.com>,
# Dominik Kapusta <ayoy@gentoo.org>
# @BLURB: Eclass for Qt4 packages, second edition
# @DESCRIPTION:
# This eclass contains various functions that may be useful when
# dealing with packages using Qt4 libraries. Requires EAPI=2.
case ${EAPI} in
2|3|4) : ;;
*) die "EAPI=${EAPI} is not supported" ;;
esac
inherit base eutils multilib toolchain-funcs
export XDG_CONFIG_HOME="${T}"
# @ECLASS-VARIABLE: LANGS
# @DESCRIPTION:
# In case your Qt4 application provides various translations, use this variable
# to specify them in order to populate "linguas_*" IUSE automatically. Make sure
# that you set this variable BEFORE inheriting qt4-r2 eclass.
# example: LANGS="en el de"
for x in ${LANGS}; do
IUSE="${IUSE} linguas_${x}"
done
# @ECLASS-VARIABLE: LANGSLONG
# @DESCRIPTION:
# Same as above, but this variable is for LINGUAS that must be in long format.
# Remember to set this variable BEFORE inheriting qt4-r2 eclass.
# Look at ${PORTDIR}/profiles/desc/linguas.desc for details.
for x in ${LANGSLONG}; do
IUSE="${IUSE} linguas_${x%_*}"
done
# @FUNCTION: qt4-r2_src_unpack
# @DESCRIPTION:
# Default src_unpack function for packages that depend on qt4. If you have to
# override src_unpack in your ebuild (probably you don't need to), call
# qt4-r2_src_unpack in it.
qt4-r2_src_unpack() {
debug-print-function $FUNCNAME "$@"
base_src_unpack "$@"
# Fallback to ${WORKDIR}/${MY_P} when ${WORKDIR}/${P} doesn't exist.
# Feel free to re-implement this
if [[ "${S}" == "${WORKDIR}/${P}" && ! -d ${S} && -d ${WORKDIR}/${MY_P} ]]; then
ewarn "Falling back to '${WORKDIR}/${MY_P}'"
S="${WORKDIR}/${MY_P}"
fi
}
# @ECLASS-VARIABLE: PATCHES
# @DESCRIPTION:
# In case you have patches to apply, specify them in PATCHES variable. Make sure
# to specify the full path. This variable is used in src_prepare phase.
# example:
# PATCHES=( "${FILESDIR}"/mypatch.patch
# "${FILESDIR}"/mypatch2.patch )
# @FUNCTION: qt4-r2_src_prepare
# @DESCRIPTION:
# Default src_prepare function for packages that depend on qt4. If you have to
# override src_prepare in your ebuild, you should call qt4-r2_src_prepare in it,
# otherwise autopatcher will not work!
qt4-r2_src_prepare() {
debug-print-function $FUNCNAME "$@"
base_src_prepare "$@"
}
# @FUNCTION: qt4-r2_src_configure
# @DESCRIPTION:
# Default src_configure function for packages that depend on qt4. If you have to
# override src_configure in your ebuild, call qt4-r2_src_configure in it.
qt4-r2_src_configure() {
debug-print-function $FUNCNAME "$@"
local project_file="$(_find_project_file)"
if [[ -n ${project_file} ]]; then
eqmake4 ${project_file}
else
base_src_configure "$@"
fi
}
# @FUNCTION: qt4-r2_src_compile
# @DESCRIPTION:
# Default src_compile function for packages that depend on qt4. If you have to
# override src_compile in your ebuild (probably you don't need to), call
# qt4-r2_src_compile in it.
qt4-r2_src_compile() {
debug-print-function $FUNCNAME "$@"
base_src_compile "$@"
}
# @ECLASS-VARIABLE: DOCS
# @DESCRIPTION:
# Use this variable if you want to install any documentation.
# example: DOCS="README AUTHORS"
# @ECLASS-VARIABLE: DOCSDIR
# @DESCRIPTION:
# Directory containing documentation. If not specified, ${S} will be used
# instead.
# @FUNCTION: qt4-r2_src_install
# @DESCRIPTION:
# Default src_install function for qt4-based packages. Installs compiled code,
# documentation (via DOCS variable) and translations (via LANGS and
# LANGSLONG variables).
qt4-r2_src_install() {
debug-print-function $FUNCNAME "$@"
emake INSTALL_ROOT="${D}" DESTDIR="${D}" install || die "emake install failed"
# install documentation
if [[ -n "${DOCS}" ]]; then
local dir=${DOCSDIR:-${S}}
for doc in ${DOCS}; do
dodoc "${dir}/${doc}" || die "dodoc failed"
done
fi
}
# Internal function, used by eqmake4 and qt4-r2_src_configure
# Look for project files:
# 0 *.pro files found - output null string
# 1 *.pro file found - output its name
# 2 or more *.pro files found - if ${PN}.pro or $(basename ${S}).pro
# are there, output any of them
# Outputs a project file argument used by eqmake4. Sets nullglob locally
# to avoid expanding *.pro as "*.pro" when there are no matching files.
_find_project_file() {
shopt -s nullglob
local pro_files=(*.pro)
shopt -u nullglob
local dir_name="$(basename ${S})"
case ${#pro_files[@]} in
1)
echo "${pro_files[0]}"
;;
*)
for pro_file in "${pro_files[@]}"; do
if [[ "${pro_file}" == "${dir_name}" ||
"${pro_file}" == "${PN}.pro" ]]; then
echo "${pro_file}"
break
fi
done
;;
esac
}
# @FUNCTION: eqmake4
# @USAGE: [project file] [parameters to qmake]
# @DESCRIPTION:
# Wrapper for Qt4's qmake. If project file isn't specified eqmake4 will
# look for it in current directory (${S}, non-recursively). If more than
# one project file is found, the ${PN}.pro is processed, provided that it
# exists. Otherwise eqmake4 fails.
# All the arguments are appended unmodified to qmake command line. For
# recursive build systems, i.e. those based on the subdirs template, you
# should run eqmake4 on the top-level project file only, unless you have
# strong reasons to do things differently. During the building, qmake
# will be automatically re-invoked with the right arguments on every
# directory specified inside the top-level project file by the SUBDIRS
# variable.
eqmake4() {
ebegin "Running qmake"
local qmake_args=("$@")
# check if project file was passed as a first argument
# if not, then search for it
local regexp='.*\.pro'
if ! [[ "${1}" =~ ${regexp} ]]; then
local project_file="$(_find_project_file)"
if [[ -z "${project_file}" ]]; then
echo
eerror "No project file found in ${S}!"
eerror "This shouldn't happen - please send a bug report to http://bugs.gentoo.org/"
echo
die "eqmake4 failed"
fi
qmake_args+=("${project_file}")
fi
# make sure CONFIG variable is correctly set for both release and debug builds
local CONFIG_ADD="release"
local CONFIG_REMOVE="debug"
if has debug ${IUSE} && use debug; then
CONFIG_ADD="debug"
CONFIG_REMOVE="release"
fi
local awkscript='BEGIN {
printf "### eqmake4 was here ###\n" > file;
fixed=0;
}
/^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
for (i=1; i <= NF; i++) {
if ($i ~ rem || $i ~ /debug_and_release/)
{ $i=add; fixed=1; }
}
}
/^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
for (i=1; i <= NF; i++) {
if ($i ~ add) { $i=rem; fixed=1; }
}
}
{
print >> file;
}
END {
printf "\nCONFIG -= debug_and_release %s\n", rem >> file;
printf "CONFIG += %s\n", add >> file;
print fixed;
}'
local file=
while read file; do
grep -q '^### eqmake4 was here ###$' "${file}" && continue
local retval=$({
rm -f "${file}" || echo "FAILED"
awk -v file="${file}" -- "${awkscript}" add=${CONFIG_ADD} rem=${CONFIG_REMOVE} || echo "FAILED"
} < "${file}")
if [[ ${retval} == 1 ]]; then
einfo " - fixed CONFIG in ${file}"
elif [[ ${retval} != 0 ]]; then
eerror "An error occurred while processing ${file}"
die "eqmake4 failed to process '${file}'"
fi
done < <(find . -type f -name "*.pr[io]" -printf '%P\n' 2>/dev/null)
[[ ${EAPI} == 2 ]] && use !prefix && EPREFIX=
"${EPREFIX}"/usr/bin/qmake \
-makefile \
-config ${CONFIG_ADD} \
QTDIR="${EPREFIX}"/usr/$(get_libdir) \
QMAKE="${EPREFIX}"/usr/bin/qmake \
QMAKE_CC="$(tc-getCC)" \
QMAKE_CXX="$(tc-getCXX)" \
QMAKE_LINK="$(tc-getCXX)" \
QMAKE_CFLAGS_RELEASE="${CFLAGS}" \
QMAKE_CFLAGS_DEBUG="${CFLAGS}" \
QMAKE_CXXFLAGS_RELEASE="${CXXFLAGS}" \
QMAKE_CXXFLAGS_DEBUG="${CXXFLAGS}" \
QMAKE_LFLAGS_RELEASE="${LDFLAGS}" \
QMAKE_LFLAGS_DEBUG="${LDFLAGS}" \
QMAKE_LIBDIR_QT="${EPREFIX}"/usr/$(get_libdir)/qt4 \
QMAKE_LIBDIR_X11="${EPREFIX}"/usr/$(get_libdir) \
QMAKE_LIBDIR_OPENGL="${EPREFIX}"/usr/$(get_libdir) \
QMAKE_STRIP= \
"${qmake_args[@]}"
# was qmake successful?
if ! eend $? ; then
echo
eerror "Running qmake has failed! (see above for details)"
eerror "This shouldn't happen - please send a bug report to http://bugs.gentoo.org/"
echo
die "eqmake4 failed"
fi
return 0
}
EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install