code:
[mirrors]
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/xresprobe-0.4.24ubuntu9.tar.bz2

[vars]
filesize=139204
sha512=07f9f6e2f405c019f345cecf693a3203558e074b95568eb1d57b5fc9f25b70ccbf541f7607c9748c68f765386d65a83ae3d20f0a1d445ac97d7cd52f6791b22e
desc="Contains the 'ddcprobe' utility, which performs a DDC probe to the monitor. Only works on x86 and powerpc"

[deps]

[build]

case $A in
 i386)
  cd ddcprobe
  gcc -W -Wall  -g -O2    -c -o vesamode.o vesamode.c
  gcc -W -Wall  -g -O2    -c -o common.o common.c
  gcc -W -Wall  -g -O2    -c -o x86-common.o x86-common.c
  gcc -W -Wall  -g -O2    -c -o lrmi.o lrmi.c
  gcc -W -Wall  -g -O2    -c -o vbe.o vbe.c
  gcc -W -Wall  -g -O2    -c -o ddcprobe.o ddcprobe.c
  gcc -W -Wall  -g -O2  -o ddcprobe vesamode.o common.o x86-common.o lrmi.o vbe.o ddcprobe.o
  strip ddcprobe
  cd ..
 ;;
 x86_64)
  cd ddcprobe
  gcc -W -Wall  -g -O2    -c -o vesamode.o vesamode.c
  gcc -W -Wall  -g -O2    -c -o common.o common.c
  gcc -W -Wall  -g -O2    -c -o x86-common.o x86-common.c
  gcc -W -Wall  -g -O2    -c -o vbe.o vbe.c
  gcc -W -Wall  -g -O2    -c -o thunk.o thunk.c
  cd x86emu
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include debug.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include decode.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include fpu.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include ops.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include ops2.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include prim_ops.c
  gcc -g -O -Wall -c -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG -DDEBUG -I. -Ix86emu -I../../include -I../x86emu_include sys.c
  ar rv libx86emu.a debug.o decode.o fpu.o ops.o ops2.o prim_ops.o sys.o
  cd ..
  gcc -W -Wall  -g -O2    -c -o ddcprobe.o ddcprobe.c
  gcc -W -Wall  -g -O2  -o ddcprobe vesamode.o common.o x86-common.o vbe.o thunk.o x86emu/libx86emu.a ddcprobe.o
  gcc -W -Wall  -g -O2    -c -o ddcxinfo.o ddcxinfo.c
  gcc -W -Wall  -g -O2  -o ddcxinfo vesamode.o common.o x86-common.o vbe.o thunk.o x86emu/libx86emu.a ddcxinfo.o
  strip ddcprobe
  cd ..
 ;;
 *)
  cd ddcprobe
  echo '#!/bin/sh
echo "oem: armsystem"' > ddcprobe
  cd ..
 ;;
esac

dest="$butch_install_dir""$butch_prefix"
mkdir -p "$dest"/bin
install -m755 ddcprobe/ddcprobe "$dest"/bin

path: pkg/xresprobe


code:
[mirrors]
http://www.vergenet.net/~conrad/software/xsel/download/xsel-1.2.0.tar.gz

[vars]
filesize=169155
sha512=e28623e6cc180f2e2210c20697d21d336633f0a5272ca9b62150a1c535e8de89731acc07230a9977e391e37d3943a9d687f1f967765a15bca5092a6c6d8c4d8f

[deps]
libx11

[build]
#patch -p1 < "$K"/some.patch

[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"

CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C --prefix="$butch_prefix" --disable-nls $xconfflags

#[ -n "$CROSS_COMPILE" ] && "$K"/libtool.cross.gen --sysroot="$butch_root_dir"

make V=1 -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

repo_name: aarf/bkauler

path: pkg/xsel

license: unknown


code:
[mirrors]
http://xorg.freedesktop.org/releases/individual/app/xset-1.2.3.tar.bz2

[vars]
filesize=142286
sha512=7b2cf4b06b93aec9f6f868be3f0932a5d6e62968485f7eb742a9b775059aa2a49c9170404e0597fd41a5730c0bf321e371ee6b23bbcde3be054f768ab8d3d92a

[deps]
libx11

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"
CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make V=1 -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/xset


code:
[mirrors]
http://xorg.freedesktop.org/releases/individual/app/xsetroot-1.1.1.tar.bz2

[vars]
filesize=119977
sha512=04834a8ca658a4aabe03e62588353102e8019d424e25fab450d48e6fc4ac358df5bb98a850c82c61e2495faabfe54f3d92d9563e77c83ace7fd69c278edbbd64

[deps]
libx11
libxau
xbitmaps

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"

CPPFLAGS=-D_GNU_SOURCE \
CFLAGS="$optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C --prefix="$butch_prefix" $xconfflags

make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/xsetroot


code:
[mirrors]
ftp://invisible-island.net/xterm/xterm-324.tgz

[vars]
filesize=1235312
sha512=f6f2518a11eec6e41afb10ca4ec298c566b1fc5c3b3c4c4d533311b3f64ec04c2bc692798e75bbd34382cb64eca9b21ee4b05438c4d18486046d3c710c586626

[deps]
libx11
libxaw
libxft
curses

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/')"
# Gleiches mit gleichem vergelten.
CFLAGS="-include termcap.h -g -D__GNU__ -D__GLIBC__=2 -D__GLIBC_MINOR__=10 -D_POSIX_SOURCE -D_GNU_SOURCE $optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C \
  --prefix="$butch_prefix" \
  --mandir=/share/man \
  --enable-256-color \
  --enable-wide-chars \
  --disable-tek4014 \
  --disable-active-icon \
  --disable-builtin-xpms \
  --without-xpm \
  ac_cv_header_lastlog_h=no cf_cv_path_lastlog=no $xconfflags
cat <<EOF >>ptyx.h
#ifndef HACKY_HACKY_GETPT
#define HACKY_HACKY_GETPT
static inline int getpt() { return open("/dev/ptmx",O_RDWR|O_NOCTTY); }
#endif
EOF
touch curses.h
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install
dest="$butch_install_dir""$butch_prefix"
mkdir -p "$dest"/share/applications/
cp -f xterm.desktop "$dest"/share/applications/
# replace the ugly 70ies xterm icon with a nice one
sed -i 's@xterm-color_48x48@terminal@' "$dest"/share/applications/xterm.desktop

path: pkg/xterm


code:
[mirrors]
http://xorg.freedesktop.org/releases/individual/lib/xtrans-1.3.3.tar.bz2

[vars]
filesize=177244
sha512=9db9464f8e9f1b48e5b8953e764fce7dc0e454c50c794c7871023380f6881b7e9d2e754831c906000c18467a7946d67c86eb4574f11175f8dc27b53599af01b5

[build]
[ -n "$CROSS_COMPILE" ] && xconfflags="--host=$($CC -dumpmachine)"
CFLAGS="$optcflags" LDFLAGS="$optldflags" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make DESTDIR="$butch_install_dir" install
dest="$butch_install_dir""$butch_prefix"
mkdir -p "$dest"/lib/pkgconfig
mv "$dest"/share/pkgconfig/* "$dest"/lib/pkgconfig/
rm -rf "$dest"/share/pkgconfig

path: pkg/xtrans


code:
[mirrors]
http://distro.ibiblio.org/quirky/quirky6/sources/t2/april/xvidcore-1.3.3.tar.bz2

[vars]
filesize=695279
sha512=e2178ee946fa057cf465da855b702e74fbab04347020ab7900850c07dfcd5202003fcd579fc404e0a567807285607ed4bcd14dc4c074ea19123143f03af80f09
desc="A high performance and high quality MPEG-4 video de-/encoding library."
tardir=xvidcore

[deps]
coreutils

[build]
#alt d/l: http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.gz

cd build/generic

#ref: http://www.linuxfromscratch.org/blfs/view/svn/multimedia/xvid.html
sed -i 's/^LN_S=@LN_S@/& -f -v/' platform.inc.in

CFLAGS="$optcflags" \
  LDFLAGS="$optldflags" \
    ./configure --prefix="$butch_prefix" $xconfflags \
      --disable-assembly
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/xvid


code:
[mirrors]
http://xorg.freedesktop.org/releases/individual/app/xwininfo-1.1.3.tar.bz2

[vars]
filesize=157512
sha512=b4c3c72de157d33e309694be96dcafabb3240c1883fb3caf44843cba8b90fe09496eb4ab061eba9107115d76ca59a8ec660e11ff968e422ab35cd5e1749ca466

[deps]
libx11

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"
CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/xwininfo


code:
[mirrors]
http://tukaani.org/xz/xz-5.2.2.tar.xz

[vars]
filesize=1016404
sha512=949ef90669a31b9855c5328d7f9d7e2e537c8072b700b1d2f5d69c307eb7f7635a2a4b1b5bb1bb300fba9429355a6d8935b803c505be5c0104bda9e81d0cf477

[deps.host]
dynamic-toolchain

[build]
printf "all:\n\ttrue\n\ninstall:\n\ttrue\n\n" > tests/Makefile.in
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine)"
# the stage0 arm toolchain has a slightly broken libgcc (with external deps to libc)
# this package is the only one that fails to build.
# so let it depend on the stage1 toolchain. another fix could be to add -lc at the
# end of the gcc invocation in musl-gcc.
CFLAGS="$optcflags" LDFLAGS="$optldflags" \
  ./configure -C --prefix="$butch_prefix" \
    --disable-nls --with-pic --enable-shared \
    --enable-static $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/xz


code:
[mirrors]
http://yaml-cpp.googlecode.com/files/yaml-cpp-0.5.1.tar.gz

[vars]
filesize=118244
sha512=3c6928684d603815c016d663af36be94507f2cccf167d6d8d7cd7dea3ea5f73ec88d62952a2b5d11796e40132857afcbbacd9eafd688f2dc11d0c339caf2e013

[deps]
boost

[deps.host]
cmake

[build]
CFLAGS="-D_GNU_SOURCE $optcflags" LDFLAGS="$optldflags" \
  cmake -DCMAKE_INSTALL_PREFIX="$butch_prefix" .
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/yaml-cpp


code:
[vars]
filesize=1436502
sha512=e80ace766e145f6486e76da1a5a9819221b7f406745a02529b4ad220ef7f51ddd67f23d0d8b187bffc9725d9f9742ae5f3a0bb23ee5b2a61153332fb3e286b77
desc='x86 and x86_64 assembler'

[mirrors]
http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz

[deps]

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"
CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/yasm


code:
[mirrors]
http://repo.hu/projects/yget/releases/yget-2.8.0.tar.gz

[vars]
filesize=8745
sha512=9740617f315f7dcb60d3e649b5d056d25c918409dbbe2780cb3688632e46acebd4f0843c0e3c2f0708651de7859dfabf8815e4fdcb88a9a49b0552f9f3e04375
desc='download or view youtube videos'

[deps]

[build]
sed -i 's/mplayer/mpv/' yplay
make prefix="$butch_prefix" install_root="$butch_install_dir" install

path: pkg/yget


code:
[mirrors]
http://youtube-dl.org/downloads/2016.04.24/youtube-dl-2016.04.24.tar.gz

[vars]
filesize=2084276
sha512=b30b01eb9100a30ce792283e1598f5f2058a56a90d1a1f0359efb79ca2d360dff4f525a3b906d777d4e09e046e3e21ed0342b29bf90c42be6321fc77a303ee42
tardir=youtube-dl
uchkurl=http://youtube-dl.org/downloads/

[deps]
python
python-setuptools

[build]
python setup.py install --prefix="$butch_prefix" --root="$butch_install_dir" --optimize=1

path: pkg/youtube-dl


code:
[mirrors]
https://github.com/Z3Prover/z3/archive/z3-4.4.0.tar.gz

[vars]
filesize=3060731
sha512=4e02e7a2ebc4208eb1233242612501707ec2356b6b72192d73a1803030ca95b49d6a8c3de04a40782677a25ff62cf8c2108e09f3bd87510ce6ad6c5df468535a
tardir=z3-z3-4.4.0

[deps]
python

[build]
python scripts/mk_make.py --prefix="$butch_install_dir$butch_prefix"
cd build
make
make install


code:
[mirrors]
http://downloads.sourceforge.net/infozip/zip30.tar.gz

[vars]
filesize=1118845
sha512=c1c3d62bf1426476c0f9919b568013d6d7b03514912035f09ee283226d94c978791ad2af5310021e96c4c2bf320bfc9d0b8f4045c48e4667e034d98197e1a9b3

[deps]

[build]
make -f unix/Makefile generic_gcc -j$MAKE_THREADS \
CFLAGS="-D_GNU_SOURCE $optcflags" LDFLAGS="$optldflags"

make prefix="$butch_install_dir""$butch_prefix" -f unix/Makefile install

path: pkg/zip


code:
[deps]

[mirrors]
http://download.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.xz
[vars]
filesize=450776
sha512=405fbb4fc9ca8a59f34488205f403e77d4f184b08d344efbec6a8f558cac0512ee6cda1dc01b7913d61d9bed04cc710e61db1081bb8782c139fcb727f586fa54

[build]
CC="$CC" CFLAGS="$optcflags -D_GNU_SOURCE -fPIC" LDFLAGS="$optldflags" \
  ./configure --prefix="$butch_prefix"
#busybox mktemp -u is broken and returns empty string
#sed -i 's,mktemp -u,mktemp,g' Makefile
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

# make install is broken
ranlib libz.a
dest="$butch_install_dir""$butch_prefix"
mkdir -p "$dest"/lib
install -m644 libz.a "$dest"/lib/
mkdir -p "$dest"/include
install -m644 zlib.h zconf.h "$dest"/include/

path: pkg/zlib-orig


code:
[vars]
filesize=1239648
sha512=0c33b05e8232084999812cbaa467dc7d37b80cafc1001b82e89c702b4303d8db9a27b948fe653e7090404eb1c66f5492f02f3524bc39efabade4be8bdb476671
desc='IRC bouncer'

[mirrors]
http://znc.in/releases/archive/znc-1.4.tar.gz

[deps]
libressl

[build]
patch -p1 < "$K"/znc.patch
patch -p1 < "$K"/znc-comp.patch
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"
CPPFLAGS="-D_GNU_SOURCE" \
CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/znc


code:
[mirrors]
http://downloads.sourceforge.net/project/zsh/zsh/5.0.5/zsh-5.0.5.tar.bz2

[vars]
filesize=3104375
sha512=34d69bed190cbc476bcdaa4b703fee1caaeae7e011fe7ea595b29bbd31df57bbe4d19b5940618e0c89a0a4b6c476f9ef03ce9829b4fb3735c1aedf309b0225a5

[deps]

[build]
cp -f "$K"/config.sub .
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine) \
  --with-sysroot=$butch_root_dir"

CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure --enable-libc-musl -C --prefix="$butch_prefix" $xconfflags

make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/zsh


code:
[mirrors]
http://heanet.dl.sourceforge.net/project/zziplib/zziplib13/0.13.62/zziplib-0.13.62.tar.bz2

[vars]
filesize=685770
sha512=fd3b9e9015ba7603bdebd8f6a2ac6d11003705bfab22f3a0025f75455042664aea69440845b59e6f389417dff5ac777f49541d8cbacb2a220e67d20bb6973e25

[deps]

[build]
[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/') \
  --with-sysroot=$butch_root_dir"
CPPFLAGS="-D_GNU_SOURCE" CFLAGS="$optcflags" CXXFLAGS="$optcflags" \
LDFLAGS="$optldflags" \
  ./configure -C --prefix="$butch_prefix" $xconfflags
make -j$MAKE_THREADS
make DESTDIR="$butch_install_dir" install

path: pkg/zziplib


code:
#!/bin/sh
# use: utils/build-kernel.sh [no args]
# build a grsecurity-patched kernel (https://grsecurity.net/) and
# a vanilla kernel, adding both to boot menu.

if ENABLE_GRSEC=1 butch rebuild kernel ; then
mv /boot/vmlinuz /boot/vmlinuz-grsec
mv /boot/System.map /boot/System.map-grsec
cat << EOF > /boot/extlinux.conf
PROMPT 1
TIMEOUT 100
DEFAULT sabotage

LABEL sabotage
        KERNEL vmlinuz
        APPEND root=/dev/sda1 rw vga=ask

LABEL sabotage-grsec
        KERNEL vmlinuz-grsec
        APPEND root=/dev/sda1 rw vga=ask

LABEL rescue
        KERNEL vmlinuz
        APPEND root=/dev/sda1 rw

EOF
butch rebuild kernel
fi


code:
#!/bin/sh
# Tobias Klein, 02/2009
# http://www.trapkit.de
# simplified and made static link aware: rofl0r, 08/2013

# help
if [ "$#" = "0" ]; then
  echo "usage: checkrelro OPTIONS"
  echo -e "\t--file <binary name>"
  echo -e "\t--dir <directory name>"
  echo -e "\t--proc <process name>"
  echo -e "\t--proc-all"
  echo
  exit 1
fi

is_dynamic_bin() {
	readelf -l $1 2>/dev/null | grep -q 'INTERP'
}

has_bind_now() {
	readelf -d $1 2>/dev/null | grep -q 'BIND_NOW'
}

has_relro() {
	readelf -l $1 2>/dev/null | grep -q 'GNU_RELRO'
}

full() {
	echo -n -e '\033[32mfull RELRO\033[m'
}

partial() {
	echo -n -e '\033[33mpartial RELRO\033[m'
}

none() {
	echo -n -e '\033[31mno RELRO\033[m'
}

# check if a file supports RELRO
bincheckrelro() {
  if has_relro $1 ; then
    if ! is_dynamic_bin $1 || has_bind_now $1 ; then
      full
    else
      partial
    fi
  else
    none
  fi
}

# check if a process supports RELRO
proccheckrelro() {
  if readelf -l $1/exe 2>/dev/null | grep -q 'Program Headers' ; then
    bincheckrelro $1/exe
  else
    echo -n -e '\033[31mPermission denied\033[m'
  fi
}

if [ "$1" = "--dir" ]; then
  cd /$2
  for I in [a-z]*; do
    if [ "$I" != "[a-z]*" ]; then
      echo -n -e $I
      echo -n -e ' - '
      bincheckrelro $I
      echo
    fi
  done
  exit 0
fi

if [ "$1" = "--file" ]; then
  echo -n -e $2
  echo -n -e ' - '
  bincheckrelro $2
  echo
  exit 0
fi

if [ "$1" = "--proc-all" ]; then
  cd /proc
  for I in [1-9]*; do
    if [ $I != $$ ] && readlink -q $I/exe > /dev/null; then
      echo -n -e `head -1 $I/status | cut -b 7-`
      echo -n -e ' ('
      echo -n -e $I
      echo -n -e ') - '
      proccheckrelro $I
      echo
    fi
  done
  exit 0
fi

if [ "$1" = "--proc" ]; then
  cd /proc
  for I in `pidof $2`; do
    if [ -d $I ]; then
      echo -n -e $2
      echo -n -e ' ('
      echo -n -e $I
      echo -n -e ') - '
      proccheckrelro $I
      echo
    fi
  done
fi


code:
#!/usr/bin/env perl
use strict; use warnings;
use File::Slurp;

sub check {
	chomp;
	if(/^#/ || $_ eq "") {
	} elsif(/^([\w_]+)=.*?\'(.*?)\'/) {
		my $a = $1;
		my $b = $2;
		return ($a, $b);
	} elsif(/^([\w_]+)=(.*?)/) {
		my $a = $1;
		my $b = $2;
		return ($a, $b);
	} else {
		print STDERR "no match ! $_\n";
		#exit(1);
	}
	return (undef, undef);
}

my (%h, %l);

while(<>) {
	my ($a, $b) = check($_);
	if(defined($a)) {
		$h{$a} = defined($h{$a}) ? $h{$a} + 1 : 1;
		$l{$a} = $b if (defined($b));
	}
}

my @sorted = sort { $h{$a} <=> $h{$b} } keys %h;
for (@sorted) {
	print "$_ : $h{$_}\n";
}

my %h2;
my @templ = read_file("/lib/config.cache") or die("couldnt find config.cache");
for(@templ) {
	my ($a, $b) = check($_);
	if(defined($a)) {
		$h2{$a} = 1;
	}
}

for(@sorted) {
	print "missing: $_". "=" . (defined($l{$_}) ? $l{$_} : "") . " <- last value : count $h{$_}\n", if(!defined($h2{$_}));
}


code:
#!/usr/bin/env perl
use strict;
use warnings;
use File::Slurp;

my $n = 0;
my $state = 0;
my @arr;
my $test = "";

while(<>) {
	if($state < 2 && /^configure:(\d+): checking (.+)$/) {
		$n = $1;
		$test = $2;
		$state = 1;
		@arr = ();
		push @arr, "//$_";
	}
	elsif($state == 1) {
		push @arr, "//$_";
		$state = 2, print "test failed: $test" if(/^configure: failed program was:/);
	}
	elsif($state == 2) {
		if(! /^\|/) {
			my $outfile = sprintf("configure_fail%06d.c", $n);
			write_file $outfile, @arr;
			print " -> $outfile\n";
			@arr = ();
			$state = 0;
		} else {
			push @arr, substr( $_ , 1);
		}
	}

}

__END__


code:
#!/usr/bin/env perl

# to be used in combination with the output of config_log_extractor.pl

use strict;
use warnings;

my $file = $ARGV[0] or die "need filename";
my @fc = `cat $file`;

my $cc = "";
my @oc;
my $cstart = 0;
for(@fc) {
	if(!$cstart) {
		if(/^\/\//) {
			if(/gcc (.*)?>/) {
				$cc = "gcc " . $1 ;
			}
			next;
		} else {
			$cstart = 1;
			goto add;
		}
	}
	add:
	push @oc, $_;
}

die "no compiler commandline found" if $cc eq "";
print "$cc\n";
open(my $fh, ">", "conftest.c") or die "cannot open output file";
for (@oc) {
	print { $fh } $_;
}

close($fh);
system("$cc") ;
my $ret = system("./conftest");
print "ret: " . ($ret >> 8) . ", $?\n";


code:
#!/bin/sh
lib=$1
tmpc=/tmp/rpath-check.c
tmpb=/tmp/rpath-check
tmpchk=/tmp/test.c

if [ -z "$lib" ] ; then
	echo run "$0 check" to start a check
	echo run "$0 clear" to clean up temp files
elif [ "$lib" = "clear" ] ; then
	rm -f $tmpc
	rm -f $tmpb
	rm -f $tmpchk
elif [ "$lib" = "check" ] ; then
	cat << EOF > $tmpc
	#include <stdio.h>
	#include <string.h>

	int main(int argc, char** argv) {
		if(argc > 1) {
			char* dir = strrchr(argv[1], '/');
			*dir = 0;
			char *ext;
			do {
				ext = strrchr(dir + 1, '.');
				*ext = 0;
			} while (strcmp(ext+1, "so"));
			if(!memcmp(dir + 1, "lib", 3))
				printf("-L%s -l%s\n", argv[1], dir + 4);
		}
		return 0;
	}
EOF
	gcc -g -O0 $tmpc -o $tmpb || exit 1
	touch $tmpchk

	find /lib -name '*.so*' -exec $0 "{}" \;

else
	flags=`$tmpb $lib`
	if [ ! -z "$flags" ] ; then
		gcc $tmpchk $flags 2>&1 | grep "needed by"
	fi
fi


code:
#!/bin/sh
is_dynamic_bin() {
        readelf -l $1 2>/dev/null | grep -q 'INTERP'
}

for i in $(find /bin -type f -or -type l) ; do
	is_dynamic_bin "$i" && printf "%s\n" "$i"
done


code:
#!/bin/sh
is_dynamic_bin() {
        readelf -l $1 2>/dev/null | grep -q 'INTERP'
}

for i in $(find /bin -type f -or -type l) ; do
	is_dynamic_bin "$i" || printf "%s\n" "$i"
done


code:
#!/bin/sh
# use: hunt-library-tree.sh <search term> <elf file>
# searches "elf file" and its shared libraries for instances of "search term"

if [ -z "$1" -o -z "$2" ] ; then
        echo "Usage: hunt-library-tree <search term> <elf file>"
fi
if [ ! -z "$LD_LIBRARY_PATH" ] ; then
        libpath="$LD_LIBRARY_PATH":/lib
else
        libpath=/lib
fi

for i in $(readelf -a "$2" |grep NEEDED |sed -e 's/.*\[//g' |sed -e 's/\]//g') ; do
        for p in $(echo "$libpath" |sed s/:/\\n/g) ; do
		[ -f "$p"/"$i" ] && readelf -a "$p"/"$i" |grep "$1" |sed -e "s@^@$p/$i: @"
        done
done

readelf -a "$2" |grep "$1" |sed -e "s@^@$2: @"
readelf -a "$2" |grep NEEDED |sed -e 's@.*\[@@g' |sed -e 's@\]@@g'

exit 0


code:
#!/bin/sh
# use: cp `./utils/print-builddir.sh`/src/some.patch .
# used as a subsitute to the chroot root path.

. "$PWD"/config
echo "$R"


code:
#!/bin/sh
# use: root-perms.sh <directory>
# set up default permissions on a directory intended to be used for a rootfs

if [ -z "$1" ] ; then
	echo "error: expecting directory name to apply root perms"
	exit 1
fi

if [ ! -e "$1"/src/config ] ; then
	echo "error: $1 doesn't look like a sabotage rootfs"
	exit 1
fi

for dir in / etc bin boot home include lib libexec mnt root sbin share src srv sys tmp usr var ; do
        chown -R root:root "$1"/$dir
done
chmod 0755 "$1"/var/empty


code:
#!/bin/sh
# use: run-emulator.sh [--console --ro]
# runs the rootfs under QEMU using 9P mount
# --console puts QEMU in terminal-only mode (no SDL window)
# --ro mounts the file system read-only
# uses $H/config to detect rootfs location

export H="$PWD"
. ./config

console=
rw=rw
for i ; do
	[ "$i" = --console ] && console="console=ttyS0"
	[ "$i" = --ro ] && rw=ro
done
nographic=
[ -z "$console" ] || nographic="-nographic"
[ -z "$console" ] && console="vga=ask"
[ -z "$INIT" ] && INIT=/bin/init
[ -z "$KERNEL" ] && KERNEL=$R/boot/vmlinuz
[ -z "$ram" ] && ram=140

qemu-system-$A $nographic -m $ram -no-reboot -kernel $KERNEL -append \
  "root=root $rw rootflags=$rw,trans=virtio,version=9p2000.L rootfstype=9p init=$INIT panic=1 HOST=$A $console" \
  -fsdev local,id=root,path=$R,security_model=none -device virtio-9p-pci,fsdev=root,mount_tag=root


code:
#!/bin/sh
# use: setup-rootfs.sh [no args, uses $H/config]
# used for cross-compilation
# this prepares a chroot-like directory containing the root file system

export H="$PWD"
[ -z "$CONFIG" ] && CONFIG=./config
. "$CONFIG"

if [ -z "$R" ]; then
    printf -- "ERROR: invalid or no config file\n"
    exit 1
fi

# enable verbose printing, abort on error
set -e

mkdir -p "$K" "$C" "$S" "$R" "$LOGPATH"

cd "$R"
mkdir -p boot bin dev etc home lib mnt proc root share srv src sys tmp var
mkdir -p src/logs src/build var/log/sshd var/log/crond var/log/dmesg
mkdir -p var/empty var/service var/lib var/spool/cron/crontabs

# usr and sbin are a mistake
ln -sfn . usr
ln -sfn bin sbin

ln -sfn ../tmp var/tmp

chmod 775 src/build
chmod 1777 tmp
chmod 700 root

cp -r "$K"/etc/* "$R"/etc/
cp -r "$K"/boot/* "$R"/boot/
chmod 0600 "$R"/etc/shadow

echo nameserver 8.8.8.8 > "$R"/etc/resolv.conf


code:
#!/bin/sh
# use: update-chroot.sh [no args, uses $H/config]
# updates the chroot /src with the contents of the current sabotage checkout

MYDIR=$(dirname "$(readlink -f "$0")")
export H="$MYDIR/.."
. "$H"/config

if [ -z "$R" ] ; then
	echo "error sourcing config" >&2
	exit 1
fi

cp "$H"/COOKBOOK.md "$H"/LICENSE "$H"/README.md "$R"/src/
cp "$H"/build-stage0 "$H"/enter-chroot "$R"/src/
cp -r "$H"/KEEP "$H"/pkg "$H"/utils "$R"/src/


code:
#!/bin/sh
# use: write-hd-image.sh <img file> <root directory or tarball> <size> [--clear-builds] [--copy-tarballs]
# "--clear-builds" clears /src/build
# "`--copy-tarballs" will copy tarballs from $C
# "size" will be passed to dd, so you can use whatever value dd supports. (i.e. 8G)
# the resulting raw image may be written to media via dd or converted to various VM drive formats

MYDIR=$(dirname "$(readlink -f "$0")")

echo_bold() {
	tput bold
	echo $@
	tput sgr0
}

usage() {
	echo_bold "Usage: $0 <img file> <directory or tarball of content> <img size> [options]"
	echo "options: --clear-builds --copy-tarballs"
	echo
	echo "--clear-builds will remove stuff in /src/build (butch 0.0.8+ build directory)"
	echo '--copy-tarballs will copy tarballs from directory pointed to by "C" env var'
	echo
	echo "<img size> will be passed directly to dd, so you can use whatever value dd supports, i.e. 8G"
	exit 1
}

die() {
	echo "$1"
	[ -d "$mountdir" ] && rmdir "$mountdir"
	exit 1
}

die_unloop() {
	sync
	losetup -d "$loopdev"
	die "$1"
}

die_unmount() {
	umount "$mountdir" || die_unloop 'Failed to unmount /boot'
	die_unloop "$1"
}

check_opts() {
	while [ ! -z "$1" ] ; do
		case $1 in
			--clear-builds)
				echo "clear_builds selected"
				clear_builds=1;;
			--copy-tarballs)
				echo "copy_tarballs selected"
				copy_tarballs=1;;
		esac
		shift
	done
}

quote () {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
$1
EOF
printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
}

quote_args() {
local cmdline=
for i ; do cmdline="$cmdline $(quote $i)" ; done
printf "%s" "$cmdline"
}

run_echo() {
	local cmdline="$(quote_args $@)"
	printf "%s\n" "$cmdline"
	"$@"
}

isemptydir() {
	if [ $(ls "$1" | wc -l) = "0" ] ; then true ; else false ; fi
}

mountdir=

losetup --help 2>&1 | grep [-]-sizelimit > /dev/null \
  || die "losetup does not support --sizelimit. maybe try building util-linux"

which extlinux 2>&1 > /dev/null || die 'extlinux must be in PATH (try installing syslinux)'
[ -z "$UID" ] && UID=`id -u`
[ "$UID" = "0" ] || die "must be root"

imagefile="$1"
[ -z "$imagefile" ] && usage

contents="$2"
[ -z "$contents" ] && usage
[ ! -f "$contents" ] && [ ! -d "$contents" ] && die "failed to access $contents"
[ -d "$contents" ] && [ ! -d "$contents"/src ] && die "$contents does not contain a valid directory layout"
if ! isemptydir "$contents/proc" || ! isemptydir "$contents/sys" || ! isemptydir "$contents/dev" ; then
	die "$contents was not properly unmounted! (check sys/ dev/ proc/)"
fi
[ ! -f "$contents"/boot/vmlinuz ] && die "$contents does not have a kernel image"

imagesize="$3"
[ -z "$imagesize" ] && usage

check_opts $@
[ "$copy_tarballs" = "1" ] && [ -z "$C" ] && die "--copy_tarballs needs C to be set. consider running 'source config'"

for mbr_bin in mbr.bin /usr/lib/syslinux/mbr.bin /usr/share/syslinux/mbr.bin
	do [ -f "$mbr_bin" ] && break ; done

[ -z "$mbr_bin" ] && die 'Could not find mbr.bin'

echo_bold "0) rm the image file"
[ -f "$imagefile" ] && rm -f "$imagefile"

echo_bold "1) make the image file"
dd if=/dev/zero of="$imagefile" bs=1 count=0 seek="$imagesize" || die "Failed to create $imagefile"

echo_bold "2) fdisk"

bytes_per_sector=512
sectors_per_track=63
heads=255
#tracks/cylinder

# first partition (/boot), starts on sector 2048 and is 100 MB
part1_start_sector=2048
part1_size_mb=100

# second partition starts at $part1_start_sector + ($part1_size_mb * 1024 * (1024/512))
part2_start_sector=$(($part1_start_sector + ($part1_size_mb * 1024 * 1024 / $bytes_per_sector)))

# ancient fdisk 2.17 (as used by debian 6) does not calculate cylinders automatically...
imagesize_in_bytes=`wc -c $imagefile |  cut -d ' ' -f 1`

cylinders=$(($imagesize_in_bytes / ($heads * $sectors_per_track * $bytes_per_sector)))

# n - new partition
# p - primary partition
# part. number
# 2048 : first sector (this is required for images > a couple GB)
# +100M: size of first partition
# n - new partition
# part. number
# RETURN : use default sector
# RETURN : use default size
# a - toggle bootable flag
# part. number
# w - write

# byte positions
part1_start=$(($bytes_per_sector * $part1_start_sector))
part1_size=$(($part1_size_mb * 1024 * 1024))

# test if we're using the ancient version, it can't deal with -u=sectors flag
# additionally, sending "u" to it as a keystroke will turn into sectors mode, while
# the newer versions will turn into deprecated cylinder mode.
# even worse, the old version will allocate one sector too much.
echo q | fdisk -u=sectors "$imagefile" 2>/dev/null || olde_shit=1
need_u_flag=
if [ "$olde_shit" = "1" ] ; then
	echo "ancient fdisk version detected, passing -u"
	need_u_flag="-u"
	part2_start_sector=$(($part2_start_sector + 2))
	part1_size=$(($part1_size + (2 * $bytes_per_sector)))
fi

# byte pos
part2_start=$(($part1_start + $part1_size))

echo fdisk -C "$cylinders" -H "$heads" -S "$sectors_per_track" -b "$bytes_per_sector" $need_u_flag "$imagefile"
fdisk -C "$cylinders" -H "$heads" -S "$sectors_per_track" -b "$bytes_per_sector" $need_u_flag "$imagefile" << EOF
n
p
1
$part1_start_sector
+${part1_size_mb}M
n
p
2
$part2_start_sector

a
1
w
EOF

echo_bold '3) copy mbr'
dd conv=notrunc if="$mbr_bin" of="$imagefile" || die 'Failed to set up MBR'

echo_bold '4) /boot'
loopdev=`losetup -f`
mountdir="/tmp/mnt.$$"

echo_bold "info: mounting $imagefile as $loopdev on $mountdir"

run_echo losetup -o $part1_start --sizelimit $part1_size "$loopdev" "$imagefile" || die 'Failed to losetup for /boot'

mkdir -p "$mountdir" || die_unloop 'Failed to create '"$mountdir"
mkfs.ext3 "$loopdev" || die_unloop 'Failed to mkfs.ext3 loop for /boot'
mount "$loopdev" "$mountdir" || die_unloop 'Failed to mount loop for /boot'

if [ -d "$contents" ] ; then
	cp -a "$contents"/boot/* "$mountdir"/ || die_unmount 'Failed to copy boot'
else
	tar -C "$mountdir" -xf "$contents" boot || die_unmount 'Failed to extract boot'
	mv "$mountdir"/boot/* "$mountdir"/ || die_unmount 'Failed to move /boot content to root of boot partition'
	rmdir "$mountdir"/boot
fi
sed -i 's/sda1/sda2/g' "$mountdir"/extlinux.conf || die_unmount 'Failed to reconfigure extlinux.conf'
extlinux -i "$mountdir"/ || die_unmount 'Failed to install extlinux'
umount "$mountdir" || die_unloop 'Failed to unmount /boot'
sync
losetup -d "$loopdev"

echo_bold ' 5) /'
loopdev=`losetup -f`
run_echo losetup -o $part2_start "$loopdev" "$imagefile" || die 'Failed to losetup for /'
mkfs.ext4 "$loopdev" || die_unloop 'Failed to mkfs.ext4 loop for /'
mount "$loopdev" "$mountdir" || die_unloop 'Failed to mount loop for /'

echo_bold "copying contents, this will take a while"
if [ -d "$contents" ]
then
	if [ "$clear_builds" = "1" ] ; then
		echo -ne "clearing builds..."
		[ -d "$contents/src/build" ] && rm -rf "$contents/src/build"/*
		echo "done"
	fi
	if [ "$copy_tarballs" = "1" ] ; then
		echo -ne "copying tarballs..."
		mkdir -p "$mountdir/src/tarballs/"
		cp -f "$C/"* "$mountdir/src/tarballs/"
		echo "done"
	fi

	time cp -a "$contents"/* "$mountdir"/ || die_unmount 'Failed to copy /'
	ls_contents=`ls "$mountdir/"`
	printf "%s\n" "$ls_contents"
else
	time tar -C "$mountdir" -zxf "$contents" || die_unmount 'Failed to extract /'
fi
rm -f "$mountdir"/boot/*
echo '/dev/sda1 /boot ext3 defaults 0 0' >> "$mountdir"/etc/fstab || die_unmount 'Failed to extend fstab'

echo_bold ' 6) applying root perms'
$MYDIR/root-perms.sh "$mountdir"

echo_bold ' 7) cleaning up'

umount "$mountdir" || die_unloop 'Failed to unmount /'
sync
losetup -d "$loopdev"

# cleanup
rmdir "$mountdir" || die "Failed to remove $mountdir"

echo_bold 'Done.'


code:
Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/
*.o
*.zip
amdmsrt
*.sw?
amdmsrt4myZ575
core

repo_name: ActualizeInMaterial/amdmsrtweaker

path: .gitignore

license: mit


code:
amdmsrtweaker-lnx
=======

amdmsrt (amdmsrtweaker-lnx) is a Linux port of the AmdMsrTweaker tool written by Martin Kinkelin and extended by Marcus Pollice.

The current version that you're looking at is modified by Emanuel Czirai and is meant to run only on my own laptop! Resides at: https://github.com/zazdxscf/amdmsrtweaker-lnx
Please do not use this one but instead, look at the original repo. which is meant to work generally: https://github.com/johkra/amdmsrtweaker-lnx

Changes to frequency will not be reflected by /proc/cpuinfo, but a quick benchmark such as "openssl speed sha1" should show a speed difference.

Compilation
-----------

Clone the repo and make sure you have gcc and make installed. Then execute "make" in the cloned directory. Optionally copy the file "amdmsrt" to a directory in $PATH such as /usr/bin or /usr/local/bin.

Usage
-----

Make sure you have the `msr` module loaded (cpuid not required). ("modprobe msr" as root) The program will otherwise exit with a corresponding error message.

See the file "readme.txt" for usage examples. The program has to executed as root and the executable is called "amdmsrt".


code:
Legend:
* todo
- done
\ extra comments
\// obsolete comments that do not apply

TODO:

*// embed in kernel
 \ see /home/emacs/build/kernel/linuxgit/makepkg/linux-git/src/linux-git/tools/power/cpupower/utils/helpers/cpuid.c
 \ /proc may not be mounted for /proc/cpuinfo
 \ modules may not be available(on the storage: initramfs?) depending on at which point in kernel I wanna load them with init_module
 \// can have both /proc and modules  for fallback if one's not available
 \ must not keep modules loaded
 \ modules must not be built into kernel because this allows other msr activities after boot UNLESS grcsecurity can have that option which denies all such access to msr and stuff.

- reduce code to handle only my specific Z575 laptop CPU (family 0x12 == 18)
  - tested to work
  - remove all commented code
  - remove boost code, it would work but why keep it since we don't intend on using it(ever); esp. since it gets rid of read/write to pci

* then embed in kernel
  \ see /arch/x86/kernel/msr.c
    \ http://lxr.free-electrons.com/source/arch/x86/include/asm/msr.h#L233
    \ vim /home/emacs/build/1packages/kernel/linuxgit/makepkg/linux-git/src/linux-git/arch/x86/kernel/msr.c
  \ also see arch/x86/kernel/cpuid.c  for making sure the cpu is my AMD cpu before applying msr values on it.
    \ vim /home/emacs/build/1packages/kernel/linuxgit/makepkg/linux-git/src/linux-git/arch/x86/kernel/cpuid.c

path: TODO


code:
#!/bin/bash

destdir="`dirname $CSCOPE_DB`"
if test -z "$destdir"; then
  destdir=/tmp/cscope/
  echo "no \$CSCOPE_DB env var, fallback to: '$destdir'. Don't forget to \":cscope add $destdir\"  within vim"
fi

mkdir -p "$(realpath "$destdir")"

if test ! -d "$destdir"; then
  echo "!! failed to make destdir: '$destdir'"
  exit 1
fi

oldpwd="`pwd`"

cd "$destdir"
find "$oldpwd" -iname '*.h' -or -iname '*.c' -or -iname '*.cpp' | cscope -b -q -i- -R -k


code:
#!/bin/bash

sudo=''
if [ `id -u` != 0 ] ; then
  echo "!! You're not root, using sudo..."
#    echo "you are not root! press a key, not shift/ctrl/alt"
#    read -n 1 -s
#    exit 1
  sudo='sudo -- '
fi

cmd='CPUunderclocking'
#cmd='nounderclocking'
##cmd='file'
#if grep --color=always -i "$cmd" /proc/cmdline; then
#  echo "!! CPU underclocking disabled due to kernel cmdline '$cmd'"
#  exit 0
#fi
if ! grep --color=always -i "$cmd" /proc/cmdline; then
  echo "!! CPU underclocking is not enabled (lacks kernel cmdline '$cmd')"
  exit 0
fi
scriptdir="$(dirname "$0")"

#on manjaro/arch
#all 4 cores affected
$sudo cpupower frequency-set -g conservative
#cpupower frequency-set -g ondemand
#this was on linux mint
#cpufreq-set -g conservative -c 0
#cpufreq-set -g conservative -c 1
#cpufreq-set -g conservative -c 2
#cpufreq-set -g conservative -c 3

$sudo modprobe msr
#$sudo modprobe cpuid
#echo before was:
#"${scriptdir}/amdmsrt"
#echo setting anew:
#this is for
#vendor_id  : AuthenticAMD
#cpu family  : 18
#model   : 1
#model name  : AMD A6-3400M APU with Radeon(tm) HD Graphics
#stepping  : 0
#on my Lenovo Z575
#don't use this anywhere else, or it will corrupt your system, obviously!
#"${scriptdir}/amdmsrt" P0=22@1.0875 P1=20@1.0250 P2=18@0.9625 P3=17@0.9375 P4=16@0.9 P5=14@0.8625 P6=12@0.8125 P7=8@0.7125
$sudo "${scriptdir}/amdmsrt4myZ575" 'I wanna brick my system!'
#"${scriptdir}/amdmsrt"
#echo now is:
#"${scriptdir}/amdmsrt"
$sudo rmmod msr
#$sudo rmmod cpuid

#put network card in auto power mode (cable must be plugged in after boot, else it will fail to wake up, tested this to be true with 3.16-rc7 )
#FIXME: this changes to 02:00.0 when DIScrete gfx card is not disabled in BIOS
#echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control'
#this is only needed when network card was blacklisted in /etc/default/tlp and that is only needed when using NetworkManager (which is default in Manajaro) but currnetly removed and using manual script to up the network

#keep radeon card in thermal power mode (power state 6  as seen in dmesg)
#only has effect when not using fglrx, otherwise harmless
#actually, /etc/tmpfiles.d/*  is doing this for us:
#[ -f "/sys/class/drm/card0/device/power_dpm_state" ] && echo 'thermal' > /sys/class/drm/card0/device/power_dpm_state
#see with: watch -n1 cat $(find /sys/kernel/debug/dri/ -iname \*pm\*)

#traffic shapeing to increase responsiveness during upload, works so far
#needs (at least) the following kernel modules:
#cls_u32 sch_ingress sch_sfq sch_cbq act_police
#FIXME: wow this is seriously broken! the download rate is limited to like 30-40 KB/s
#sudo wondershaper -a enp1s0 -d 10000 -u 500
#sudo wondershaper -s -a enp1s0
#clear all limits:
#sudo wondershaper -c -a enp1s0

#sudo /home/emacs/bin/utc
$sudo cat /proc/cpuinfo |grep cores

path: go


code:
#!/bin/bash

sudo=''

if [ `id -u` != 0 ] ; then
  echo "!! You're not root, using sudo..."
#    echo "you are not root! press a key, not shift/ctrl/alt"
#    read -n 1 -s
#    exit 1
  sudo='sudo -- '
fi

#on manjaro/arch
#all 4 cores affected
$sudo cpupower frequency-set -g ondemand

path: higher


code:
/*
 * Copyright (c) Martin Kinkelin
 *
 * See the "License.txt" file in the root directory for infos
 * about permitted and prohibited uses of this code.
 */

#include <cstdio> //for stdout
#include <iostream> //for cout
#include "mumu.h"

#include <unistd.h> //for pread, pwrite, close
#include <stdlib.h> //for exit

#include <string.h> //strncmp

#include <assert.h> //assert

#include <fcntl.h> //for O_RDONLY

using std::cout;
using std::endl;

void showAndCheckCurrentPStateInfo();//forward declaration
void PrintParams();
void applyUnderclocking();

/*const int count=1+8;
  const char* params[count]={
  "self"
  ,"P0=22@1.0875"
  ,"P1=20@1.0250"
  ,"P2=18@0.9625"
  ,"P3=17@0.9375"
  ,"P4=16@0.9"
  ,"P5=14@0.8625"
  ,"P6=12@0.8125"
  ,"P7=8@0.7125"
  };*/

/// <summary>Entry point for the program.</summary>
int main(int argc, const char* argv[]) {
  cout << endl;
  cout << "AmdMsrTweaker v1.1 modified for my own Lenovo Z575 ONLY!!! (voltages are fixed, params ignored!)" << endl;
  cout << "argv[0] is: " << argv[0] << endl;
  try {
    if ((argc > 1)and(0 == strncmp("I wanna brick my system!", argv[1],25))) {//we make sure, because we're about to apply preset voltages!(hardcoded in source code)
      PrintParams();

      fprintf(stdout,"Before:\n");
      showAndCheckCurrentPStateInfo();

      applyUnderclocking();

      fprintf(stdout,"After:\n");
      showAndCheckCurrentPStateInfo();
    } else {
      showAndCheckCurrentPStateInfo();
    }
  } catch (const std::exception& e) {
    std::cerr << "ERROR: " << e.what() << endl;
    return 10;
  }

  return 0;
}

uint64_t Rdmsr(const uint32_t regIndex) {
    uint64_t result[4]={0,0,0,0};
    char path[255]= "\0";

    for (int i = 0; i < NUMCPUCORES; i++) {
      int ret=sprintf(path, "/dev/cpu/%d/msr", i);
      if (ret<0) {
        pERR("snprintf failed");
        fprintf(stderr,"!! snprintf ret=%d\n",ret);
        exit(-1);
      }

      fprintf(stdout, startYELLOWcolortext "  !! Rdmsr: %s idx:%x ... %lu bytes ... ", path, regIndex, sizeof(result[i]));
      int msrdev = open(path, O_RDONLY);
      if (msrdev == -1) {
        pERR("Failed to open msr device for reading. You need: # modprobe msr");
        exit(-1);
      }
      if (sizeof(result[i]) != pread(msrdev, &(result[i]), sizeof(result[i]), regIndex)) {//read 8 bytes
        pERR("Failed to read from msr device");
      }
      close(msrdev);
      fprintf(stdout," done. (result==%"PRIu64" hex:%08x%08x)" endcolor "\n", result[i], (unsigned int)(result[i] >> 32), (unsigned int)(result[i] & 0xFFFFFFFF));//just in case unsigned int gets more than 32 bits for wtw reason in the future! leave the & there.
      if (i>0) {
        if (result[i-1] != result[i]) {
          pERR("Rdmsr: different results for cores(this is expected to be so depending on load)");
          fprintf(stderr,"!! core[%d]==%"PRIu64" != core[%d]==%"PRIu64"\n", i-1, result[i-1], i, result[i]);
        }
      }
    }

    return result[0];//return only the core0 result
}

void Wrmsr(const uint32_t regIndex, const uint64_t& value) {
    char path[255]= "\0";
    const uint32_t *tmp1=(const uint32_t *)&value;
//    const uint32_t *tmp2=tmp1+2;
    uint32_t data1[2];
    memcpy(&data1, tmp1, 8);
//    data1=tmp1;
//    uint32_t data2[2];
//    memcpy(data2, tmp2, 8);
    fprintf(stdout, startPURPLEcolortext "  !! Wrmsr: %s idx:%x val:%"PRIu64" valx:%08x%08x... %x %x sizeof=%lu %lu\n" endcolor,
        path, regIndex, value, (unsigned int)(value >> 32), (unsigned int)(value & 0xFFFFFFFF),
        data1[0],
        data1[1],
//        data2[0],
//        data2[1],
        sizeof(value),
        sizeof(data1[0])
        );
    fflush(stdout);
    exit(1);

    for (int i = 0; i < NUMCPUCORES; i++) {
        int ret=sprintf(path, "/dev/cpu/%d/msr", i);
        if (ret<0) {
          pERR("snprintf failed");
          exit(-1);
        }
        //fprintf(stdout,"!! Wrmsr: %s idx:%"PRIu32" val:%"PRIu64"\n", path, index, value);
        fprintf(stdout, startPURPLEcolortext "  !! Wrmsr: %s idx:%x val:%"PRIu64" valx:%08x%08x... ", path, regIndex, value, (unsigned int)(value >> 32), (unsigned int)(value & 0xFFFFFFFF));
        int msrdev = open(path, O_WRONLY);
        if (msrdev == -1) {
            pERR("Failed to open msr device for writing");
            exit(-1);
        }
        if(pwrite(msrdev, &value, sizeof(value), regIndex) != sizeof(value)) {
            pERR("Failed to write to msr device");
        }
        close(msrdev);
        fprintf(stdout," done." endcolor "\n");
    }
}

void FindFraction(double value, const double* divisors,
    int& numerator, int& divisorIndex,
    const int minNumerator, const int maxNumerator) {
  // limitations: non-negative value and divisors

  // count the null-terminated and ascendingly ordered divisors
  int numDivisors = 0;
  for (; divisors[numDivisors] > 0; numDivisors++) { }

  // make sure the value is in a valid range
  value = std::max(minNumerator / divisors[numDivisors-1], std::min(maxNumerator / divisors[0], value));

  // search the best-matching combo
  double bestValue = -1.0; // numerator / divisors[divisorIndex]
  for (int i = 0; i < numDivisors; i++) {
    const double d = divisors[i];
    const int n = std::max(minNumerator, std::min(maxNumerator, (int)(value * d)));
    const double myValue = n / d;

    if (myValue <= value && myValue > bestValue) {
      numerator = n;
      divisorIndex = i;
      bestValue = myValue;

      if (bestValue == value)
        break;
    }
  }
}

inline double multifromfidndid(const int fid, const int did) {
  double multi= (fid + 16) / DIVISORS_12[did];
  if ((multi < CPUMINMULTI) || (multi > CPUMAXMULTI)) {
    std::cerr << startREDcolortext << "!! unexpected multiplier, you're probably running inside virtualbox fid:" << fid << " did:" << did << " multi:" << multi << endcolor << endl;
  }
  assert(multi>=CPUMINMULTI);
  assert(multi<=CPUMAXMULTI);
  return multi;
}

inline void multi2fidndid(const double multi, int& fid, int& did) {
  assert(multi>=CPUMINMULTI);
  assert(multi<CPUMAXMULTI);

  const int minNumerator = 16; // numerator: 0x10 = 16 as fixed offset
  const int maxNumerator = 31 + minNumerator; // 5 bits => max 2^5-1 = 31

  int numerator, divisorIndex;
  FindFraction(multi, DIVISORS_12, numerator, divisorIndex, minNumerator, maxNumerator);

  fid = numerator - minNumerator;
  did = divisorIndex;
}

PStateInfo ReadPState(const uint32_t numpstate) {
  assert(numpstate >=0);
  assert(numpstate < NUMPSTATES);
  const uint64_t msr = Rdmsr(0xc0010064 + numpstate);

  PStateInfo result;

  int fid, did;
  fid = GetBits(msr, 4, 5);
  did = GetBits(msr, 0, 4);

  result.multi = multifromfidndid(fid, did);

  result.VID = GetBits(msr, 9, 7);

  fprintf(stdout,"!! ReadPState P%d fid:%d did:%d multi:%02.2f vid:%d\n",
      numpstate, fid, did, result.multi, result.VID);
  return result;
}

bool WritePState(const uint32_t numpstate, const PStateInfo& info) {
  assert(numpstate >=0);
  assert(numpstate < NUMPSTATES);
  const uint32_t regIndex = 0xc0010064 + numpstate;
  uint64_t msr = Rdmsr(regIndex);

  const int fidbefore = GetBits(msr, 4, 5);
  const int didbefore = GetBits(msr, 0, 4);
  const double Multi = multifromfidndid(fidbefore, didbefore);
  const int VID = GetBits(msr, 9, 7);
  fprintf(stdout,"!! Write PState(1of3) read : fid:%d did:%d vid:%d Multi:%f\n", fidbefore, didbefore, VID, Multi);

  assert(info.multi >= CPUMINMULTIunderclocked);
  assert(info.multi <= CPUMAXMULTIunderclocked);

  int fid, did;
  multi2fidndid(info.multi, fid, did);
  if ((fid != fidbefore) || (did != didbefore) || true) {
    SetBits(msr, fid, 4, 5);
    SetBits(msr, did, 0, 4);

    assert(info.VID >= CPUMAXVIDunderclocked);
    assert(info.VID <= CPUMINVIDunderclocked);
    SetBits(msr, info.VID, 9, 7);

    fprintf(stdout,"!! Write PState(2of3) write:%d did:%d vid:%d (multi:%02.2f) ...\n", fid, did, info.VID, info.multi);
    Wrmsr(regIndex, msr);
    fprintf(stdout,"!! Write PState(3of3) write: done.\n");
    return true;
  } else {
    fprintf(stdout,"!! Write PState(2of3 3of3) no write needed: same values. Done.\n");
    return false;
  }
}

int GetCurrentPState() {
  const uint64_t msr = Rdmsr(0xc0010071);
  const int i = GetBits(msr, 16, 3);//0..7
  return i;
}

void SetCurrentPState(int numpstate) {
  if (numpstate < 0 || numpstate >= NUMPSTATES)
    throw ExceptionWithMessage("P-state index out of range");

  // //so excluding the turbo state, however! isn't P0 the turbo state? unless this means that pstates here start from 0 to 7  and represent P7 to P0 in this order! (need to FIXME: verify this!) nope, P0 is turbo state here too, confirmed by http://review.coreboot.org/gitweb?p=coreboot.git;a=commitdiff;h=363010694dba5b5c9132e78be357a1098bdc0aba which says "/* All cores: set pstate 0 (1600 MHz) early to save a few ms of boot time */"
  //ok so I got it: https://github.com/johkra/amdmsrtweaker-lnx/commit/11a4fe2f486a6686bd5e64bc0e6859145a890ef2#commitcomment-13245640
  //decrease the turbo state(s) because index=0 is P1 ... and there is no way to select turbo state! (I may still be wrong, but this explaination makes sense why this was originally coded this way)
  numpstate -= 1;//NumBoostStates;//XXX: no idea why decrease by 1 here then.
  if (numpstate < 0)
    numpstate = 0;

  uint32_t regIndex = 0xc0010062;
  uint64_t msr = Rdmsr(regIndex);
  SetBits(msr, numpstate, 0, 3);
  Wrmsr(regIndex, msr);

  //Next, wait for the new pstate to be set, code from: https://chromium.googlesource.com/chromiumos/third_party/coreboot/+/c02b4fc9db3c3c1e263027382697b566127f66bb/src/cpu/amd/model_10xxx/fidvid.c line 367
  regIndex=0xC0010063;
  int i=-1;
  int j=-1;
  do {
    msr = Rdmsr(regIndex);
    i = GetBits(msr, 0, 16);
    j = GetBits(msr, 0, 64);
    cout << "i=" << i << " j=" << j << " wanted:" << numpstate << endl;//only printed once, because it's already set apparently.
  } while (i != numpstate);
}

inline double vid2voltage(const int vid) {
  return V155 - vid * CPUVIDSTEP;
}

inline int voltage2vid(double voltage) {
  assert(CPUVIDSTEP > 0);
  assert(voltage > 0.0);
  assert(voltage < V155);//XXX: actual max for my CPU is probably 1.40V though!(need to verify this).
  //^ wanna catch the mistake rather than just round to the limits

  //XXX: here, just making sure input voltage doesn't exceed 1.325V ! (my CPU)
  voltage = std::max(0.0, std::min(V1325, voltage));//done: use a less than 1.55 max voltage there, depending on reported one which is 1.325V for my cpu eg. 1.45 shouldn't be allowed!; OK, maybe that 1.55 is something else... in which case ignore all this.

  assert(voltage<=V1325);
  assert(voltage >= CPUMINVOLTAGEunderclocked); //that's the lowest (pstate7) stable voltage for my CPU, multi:8x
  //    assert(vid<=1.0875); //that's highest (pstate0) stable voltage for my CPU, multi:22x; but initially it's 1.325V at 22x pstate0, before the downclocking!
  assert(voltage <= CPUMAXVOLTAGE);//when not underclocked, this is tops
  // round to nearest step
  int r = (int)(voltage / CPUVIDSTEP + 0.5);

  //1.55 / VIDStep = highest VID (124)
  int vid= (int)(V155 / CPUVIDSTEP) - r;//VIDStep is 0.0125; so, 124 - 87(for 1.0875 aka 22x multi) = 37
  assert(vid >= CPUMAXVID);//multi 23x, fid 30, did 2, vid 18, pstate0 (highest) normal clocked
  assert(vid <= CPUMINVIDunderclocked);//multi 8x, fid 0, did 2 vid 67, pstate7(lowest) underclocked
  return vid;
}

void PrintParams() {
  assert(V1325 == bootdefaults_psi[0].strvid);//ensuring; but not using V1325 because of genericity of that def. (could be changed but this use here should not!)

  fprintf(stdout,"Hardcoded values to apply:\n");
  for (int i = 0; i < NUMPSTATES; i++) {
    assert( allpsi[i].VID/*eg. 37*/ == voltage2vid(allpsi[i].strvid /*eg. 1.0875*/));
    fprintf(stdout,"pstate:%d multi:%02.2f vid:%d\n",// voltage:%d\n",
        i,
        allpsi[i].multi,
        allpsi[i].VID
        );
  }
}

void applyUnderclocking() {
  //pstates stuff:
  bool modded=false;
  for (size_t i = 0; i < NUMPSTATES; i++) {
    modded=WritePState(i, allpsi[i]) | modded;
  }

  if (modded) {
    fprintf(stdout, "Switching to another p-state temporarily so to ensure current one uses newly applied values\n");

    const int currentPState = GetCurrentPState();

    //we switch to another pstate temporarily, then back again so that it takes effect (apparently that's why, unsure, it's not my coding)
    const int lastpstate= NUMPSTATES - 1;//aka the lowest speed one
    const int tempPState = (currentPState == lastpstate ? 0 : lastpstate);
//    const int tempPState = ((currentPState + 1) % NUMPSTATES);//some cores may already be at current+1 pstate; so don't use this variant
    fprintf(stdout,"!! currentpstate:%d temppstate:%d\n", currentPState, tempPState);
    SetCurrentPState(tempPState);
    fprintf(stdout,"!! currentpstate:%d\n", GetCurrentPState());
    SetCurrentPState(currentPState);
    fprintf(stdout,"!! currentpstate:%d\n", GetCurrentPState());
  }
}

void showAndCheckCurrentPStateInfo() {
  bool unexpected=false;
  for (int i = 0; i < NUMPSTATES; i++) {
    const PStateInfo pi = ReadPState(i);
    const double voltage=vid2voltage(pi.VID);

    cout << "  P" << i << ": " << pi.multi << "x at " << voltage << "V vid:"<< pi.VID << endl;

    if ((pi.multi != bootdefaults_psi[i].multi) && (pi.multi != allpsi[i].multi)) {
      unexpected=true;
      std::cerr << startREDcolortext << "Unexpected PState multi " << "P"<<i<<": "<<pi.multi<<"x (expected "<< allpsi[i].multi<<"x or "<<bootdefaults_psi[i].multi<<"x)" << endcolor << endl;
    }

    if ((voltage != bootdefaults_psi[i].strvid) && (voltage != allpsi[i].strvid)) {
      std::cerr << startREDcolortext << "Unexpected PState voltage " << "P"<<i<<": "<<voltage<<"V (expected "<< allpsi[i].strvid<<"V or "<<bootdefaults_psi[i].strvid<<"V)" << endcolor << endl;
    }

    if ((pi.VID != bootdefaults_psi[i].VID) && (pi.VID != allpsi[i].VID)) {
      std::cerr << startREDcolortext << "Unexpected PState vid " << "P"<<i<<": "<<pi.VID<<" (expected "<< allpsi[i].VID<<" or "<<bootdefaults_psi[i].VID<<")" << endcolor << endl;
    }
  }

  if (unexpected) {
    throw ExceptionWithMessage("P-state values unexpected(if inside virtualbox avoid running this program!)");
  }
}


code:
CXX = g++
CXXFLAGS=-O2 -Wall -pedantic -ggdb -DDEBUG -pipe -fvar-tracking-assignments -fno-omit-frame-pointer -ftrack-macro-expansion=2 -fstack-protector-all -fPIC
exe = amdmsrt4myZ575

all: zmain.o
	${CXX} zmain.o ${CXXFLAGS} -o ${exe}

zmain.o: main.cpp mumu.h
	${CXX} -c main.cpp ${CXXFLAGS} -o zmain.o

clean:
	rm -f *.o ${exe}

path: makefile


code:
#pragma once

#include <inttypes.h> //for uint32_t uint64_t

struct PStateInfo {
    double multi; //multiplier ( multiply with the reference clock of 100Mhz eg. multi*REFERENCECLOCK)
    double strvid; //real life voltage eg. 1.325V as a double
    int VID; //vid, eg. 18 (for 1.325V) or 67 (for 1.0875V)
};

// special divisors for family 0x12 (aka 18 in decimal)
static const double DIVISORS_12[] = { 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 12.0, 16.0, 0.0 };

//top voltage, fixed value used for calculating VIDs and stuff, do not change!!!
#define V155 1.55
#define V1325 1.325 //my original turbo state voltage!

#define DEFAULTREFERENCECLOCK 100 //MHz
#define REFERENCECLOCK DEFAULTREFERENCECLOCK //for my CPU, is the same 100MHz (unused)

#define NUMPSTATES 8
#define NUMCPUCORES 4 //4 cores, for my CPU
#define CPUFAMILY 0x12
#define CPUMODEL 0x1
#define CPUMINMULTI 1.0
#define CPUMAXMULTI 40.0 //24+16
#define CPUVIDSTEP 0.0125 //fixed; default step for pre SVI2 platforms

#define CPUMINVID 88 //1.55 - 88*0.0125 = 0.450
#define CPUMINVOLTAGE 0.4500

#define CPUMAXVID 18 //1.55 - 18*0.0125 = 1.325; multi 23x, fid 30, did 2, vid 18, pstate0 (highest) normal clocked
#define CPUMAXVOLTAGE 1.3250 //multi 23x, fid 30, did 2, vid 18, pstate0 (highest) normal clocked

#define CPUMAXVIDunderclocked 37 //1.0875V fid:6 did:0 multi:22.00 vid:37
#define CPUMAXVOLTAGEunderclocked 1.0875 //1.55 - 37*0.0125 = 1.0875; fid:6 did:0 multi:22.00 vid:37

#define CPUMINMULTIunderclocked 8 //multi 8x, fid 0, did 2 vid 67, pstate7(lowest) underclocked
#define CPUMAXMULTIunderclocked 22 //1.0875V fid:6 did:0 multi:22.00 vid:37

#define CPUMINVIDunderclocked 67 //multi 8x, fid 0, did 2 vid 67, pstate7(lowest) underclocked
#define CPUMINVOLTAGEunderclocked 0.7125 //1.55 - 67*0.0125 = .7125

const PStateInfo  __attribute__((unused)) bootdefaults_psi[NUMPSTATES]={//XXX: fyi only, do not use this!
  {23.0, 1.325, 18}, //P0, boost
  {14.0, 1.0625, 39}, //P1, normal
  {13.0, 1.025, 42},
  {12.0, 0.9875, 45},
  {11.0, 0.975, 46},
  {10.0, 0.9625, 47},
  {9.0, 0.95, 48},
  {8.0, 0.925, 50} //P7, normal
};
//bootdefaults_psi;//prevent -Wunused-variable warning; nvm, got statement has no effect  warning. What I actually need is:  __attribute__((unused))  src: https://stackoverflow.com/questions/15053776/how-do-you-disable-the-unused-variable-warnings-coming-out-of-gcc
const PStateInfo allpsi[NUMPSTATES]={//stable underclocking for my CPU:
  {22.0, 1.0875, 37}, //P0, boost
  {20.0, 1.0250, 42}, //P1, normal
  {18.0, 0.9625, 47},
  {17.0, 0.9375, 49},
  {16.0, 0.9, 52},
  {14.0, 0.8625, 55},
  {12.0, 0.8125, 59},
  {8.0, 0.7125, 67} //P7, normal
};

template <typename T> uint32_t GetBits(T value, unsigned char offset, unsigned char numBits) {
    const T mask = (((T)1 << numBits) - (T)1); // 2^numBits - 1; after right-shift
    return (uint32_t)((value >> offset) & mask);
}

template <typename T> void SetBits(T& value, uint32_t bits, unsigned char offset, unsigned char numBits) {
    const T mask = (((T)1 << numBits) - (T)1) << offset; // 2^numBits - 1, shifted by offset to the left
    value = (value & ~mask) | (((T)bits << offset) & mask);
}

class ExceptionWithMessage: public std::exception {
    const char* what;

public:

    ExceptionWithMessage(std::string msg) {
        this->what = msg.c_str();
    }
};

//thanks to: https://stackoverflow.com/questions/5459868/c-preprocessor-concatenate-int-to-string?answertab=active#tab-top
#define STR_HELPER(x) #x

#define termESC "\033"
#define termESC_openparen termESC "["
#define termCOLOR(type, color) \
  termESC_openparen STR_HELPER(type) ";5;" STR_HELPER(color) "m"
#define fgCOLOR 38
#define bgCOLOR 48

#define termCOLORfg(color) \
  termCOLOR(fgCOLOR, color)

#define termCOLORbg(color) \
  termCOLOR(bgCOLOR, color)

#define termCOLORreset \
  termESC_openparen "m" termESC "(B"

#define startREDcolortext \
    termCOLORfg(1)

#define startPURPLEcolortext \
    termCOLORfg(5)

#define endcolor \
    termCOLORreset

#define startYELLOWcolortext \
    termCOLORfg(3)

#define ERRORtext(txt) \
    startREDcolortext txt endcolor

#define pERR(txt) \
  perror(ERRORtext(txt))


code:
AMDMsrTweaker

Description
-----------

AmdMsrTweaker is a command line tool for Windows which allows to reprogram the
P-States used by various CPUs and APUs of AMD for their Cool&Quiet power
saving technology.

The following CPU lines are supported:
- K10 / K10.5 CPUs (various Athlon/Phenom models): CPU P-States, NB P-States on supported models
- Llano (Family 12h):  CPU P-States
- Ontario / Zacate (Family 14h):  CPU P-States
- Bulldozer, Piledriver, Trinity, Richland, Kaveri (Family 15h): CPU P-States, NB P-States

Usage
-----

The following quick guide was taken from the original thread.

Quick guide: I'm too lazy to write a complete guide just now, so please take a look at the following examples:
AmdMsrTweaker
=> no parameters: info
AmdMsrTweaker P0=12.5@1.4 P2=8 P3=@0.85
=> modifies P0 (multi=12.5, VID=1.4V), P2 (multi=8) and P3 (VID=0.85V)
AmdMsrTweaker P2
=> switches to P2 (note: if C&Q is enabled, the cores are likely to switch very soon to another P-state, so this makes only sense if C&Q is disabled or if the high-performance power-profile is active)
AmdMsrTweaker Turbo=0
=> disables the turbo (use 1 to enable it)
AmdMsrTweaker APM=0
=> disables Application Power Management (TDP limiting) for Bulldozer (use 1 to enable it)
AmdMsrTweaker NB_P0=8@1.3 NB_P1=@1.1 NB_low=3
=> modifies the NorthBridge P0 state (multi=8 (multis only supported by Bulldozer), VID=1.3V), its P1 state (VID=1.1V) and uses NB_P0 for all P-states < 3 and NB_P1 for all P-states >= 3
You can combine all parameters above

Do note that from version 1.1 onwards, different voltage steps are supported.
The voltage step supported on your platform is indicated on the info output.

Version History
---------------

v1.1	2013-04-09
- Trinity and Richland support
- preliminary Kaveri support

v1.0	2011-12-18
- initial release


code:
#!/bin/bash

sudo=''

if [ `id -u` != 0 ] ; then
  echo "!! You're not root, using sudo..."
#    echo "you are not root! press a key, not shift/ctrl/alt"
#    read -n 1 -s
#    exit 1
  sudo='sudo -- '
fi

$sudo modprobe msr
#$sudo modprobe cpuid
$sudo ./amdmsrt4myZ575
$sudo rmmod msr
#$sudo rmmod cpuid

path: show


code:
*.[oa]
*.cache
*.gmo
*.info
*.lo
*.log
*.trs
.deps
/Pod-Simple-Texinfo/pod2texi
/aclocal.m4
/config.h
/config.in
/config.status
/doc/texinfo.info
/doc/texinfo.info-*
/doc/tp_api/api_includes/
/doc/tp_api/tp_api.texi
/doc/version-stnd.texi
/doc/version.texi
/info/doc.c
/info/funs.h
/info/ginfo
/info/makedoc
/info/pseudotty
/info/t/search-after-tag.sh.out
/install-info/ginstall-info
/install-info/tests/defs
/mimetype
/po/POTFILES
/po/remove-potcdate.sed
/po/texinfo.pot
/po_document/POTFILES
/po_document/remove-potcdate.sed
/po_document/texinfo_document.pot
/stamp-h1
/texindex/texindex
/texindex/texindex.awk
/tp/LocaleData/
/tp/Makefile.docstr
/tp/Makefile.tres
/tp/Texinfo/Convert/XSParagraph/TestXS.c
/tp/Texinfo/Convert/XSParagraph/compile
/tp/Texinfo/Convert/XSParagraph/config.guess
/tp/Texinfo/Convert/XSParagraph/config.h
/tp/Texinfo/Convert/XSParagraph/config.status
/tp/Texinfo/Convert/XSParagraph/config.sub
/tp/Texinfo/Convert/XSParagraph/depcomp
/tp/Texinfo/Convert/XSParagraph/install-sh
/tp/Texinfo/Convert/XSParagraph/libtool
/tp/Texinfo/Convert/XSParagraph/ltmain.sh
/tp/Texinfo/Convert/XSParagraph/m4/libtool.m4
/tp/Texinfo/Convert/XSParagraph/m4/ltoptions.m4
/tp/Texinfo/Convert/XSParagraph/m4/ltsugar.m4
/tp/Texinfo/Convert/XSParagraph/m4/ltversion.m4
/tp/Texinfo/Convert/XSParagraph/m4/lt~obsolete.m4
/tp/Texinfo/Convert/XSParagraph/missing
/tp/Texinfo/Convert/XSParagraph/stamp-h1
/tp/Texinfo/MiscXS/compile
/tp/Texinfo/MiscXS/config.guess
/tp/Texinfo/MiscXS/config.in
/tp/Texinfo/MiscXS/config.sub
/tp/Texinfo/MiscXS/depcomp
/tp/Texinfo/MiscXS/install-sh
/tp/Texinfo/MiscXS/ltmain.sh
/tp/Texinfo/MiscXS/missing
/tp/Texinfo/ModulePath.pm
/tp/defs
/tp/maintain/catalog.xml
/tp/makeinfo
/tp/t/include_dir/
/tp/tests/Makefile.onetst
/tp/tests/coverage_macro-cr.texi
/tp/tests/equivalent_nodes-noderename.cnf
/tp/tests/formatting/
/tp/tests/htmlxref-only_mono/Makefile.onetst
/tp/tests/htmlxref-only_mono/htmlxref.cnf
/tp/tests/htmlxref-only_mono/test_scripts/
/tp/tests/htmlxref-only_split/Makefile.onetst
/tp/tests/htmlxref-only_split/htmlxref.cnf
/tp/tests/htmlxref-only_split/test_scripts/
/tp/tests/htmlxref/Makefile.onetst
/tp/tests/htmlxref/htmlxref.cnf
/tp/tests/htmlxref/test_scripts/
/tp/tests/many_input_files/diffs/
/tp/tests/many_input_files/index_split/
/tp/tests/many_input_files/indices.out
/tp/tests/many_input_files/indices/
/tp/tests/sectioning/equivalent_nodes-noderename.cnf
/tp/tests/unknown_nodes_renamed-noderename.cnf
/tp/texi2any
/util/txixml2texi
Makefile
Makefile.in
aclocal.m4
configure
gnulib/*
man/*.1
stamp-1
stamp-po
stamp-vti
node_modules/
/js/build/
/js/examples/kawa/kawa-ebook.js

repo_name: mthl/texinfo