From 3d4a7579175877ec8c838233fd1f507282a67556 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 8 Apr 2013 11:28:26 +0200 Subject: [PATCH] ionice --- doc/config | 2 ++ doc/example.cfg | 1 + lib/config/getConfigGeneral | 43 +++++++++++++++++++++++++++++++++++ lib/config/print | 3 ++- lib/decode/decodeMpcdec | 3 ++- lib/decode/decodeOpusdec | 3 ++- lib/decode/decodeSox | 2 +- lib/encode/encodeFile::mp3 | 3 ++- lib/encode/encodeFile::opus | 2 +- lib/encode/encodeFile::vorbis | 2 +- 10 files changed, 57 insertions(+), 7 deletions(-) diff --git a/doc/config b/doc/config index a32eead..4aa2f32 100644 --- a/doc/config +++ b/doc/config @@ -26,6 +26,8 @@ Sections: too quickly. Set this too high, and AtOM will not adapt quickly enough to load increase. In both cases, your hard drive will suffer. In my experience, 30 seconds is a good value. + * ionice [niceness]: IO-hungry processes will be run with ionice class + and niceness [niceness] (if applicable). See man ionice for details. * temporary-directory : String. Name speaks for itself: this is where FIFOs (for communicating with sqlite) and temporary WAVE files will be created. Note that debug logs (if enabled) will go there too. diff --git a/doc/example.cfg b/doc/example.cfg index 1ffdb39..19b2b14 100644 --- a/doc/example.cfg +++ b/doc/example.cfg @@ -1,4 +1,5 @@ [general] +ionice 3 max-load 6 load-interval 30 temporary-directory %HOME%/.atom/tmp diff --git a/lib/config/getConfigGeneral b/lib/config/getConfigGeneral index 9de2888..ec183ab 100644 --- a/lib/config/getConfigGeneral +++ b/lib/config/getConfigGeneral @@ -23,6 +23,49 @@ getConfigGeneral() { fi unset expr ;; + 'ionice') + read class niceness <<<"$value" + case $class in + 1) + # real-time class, only root can do that + if (( UID )) + then + echo "IO class 'realtime' is"\ + "not available to unprivileged"\ + "users" >&2 + exit $EIONICE + fi + if [ -n "$niceness" ] \ + && (( niceness >= 0 && niceness <= 7 )) + then + ionice="ionice -c1 -n$niceness " + else + echo "Invalid IO priority"\ + "'$niceness'" >&2 + exit $EIONICE + fi + ;; + 2) + if [ -n "$niceness" ] \ + && (( niceness >= 0 && niceness <= 7 )) + then + ionice="ionice -c2 -n$niceness " + else + echo "Invalid IO priority"\ + "'$niceness'" >&2 + exit $EIONICE + fi + ;; + 3) + ionice="ionice -c3 " + ;; + *) + echo "Invalid ionice parameters $value"\ + >&2 + exit $EIONICE + ;; + esac + ;; 'temporary-directory') tempdir="$value" ;; diff --git a/lib/config/print b/lib/config/print index bc189a0..0a4fea4 100644 --- a/lib/config/print +++ b/lib/config/print @@ -1,8 +1,9 @@ #!/bin/bash printConfig() { { + echo "General|Config file|$cffile" + [ -n "$ionice" ] && echo "|IO Nice|$ionice" cat <<-EOF - General|Config file|$cffile |Load|$maxload |Load Interval|$loadinterval |Temp Dir|$tempdir diff --git a/lib/decode/decodeMpcdec b/lib/decode/decodeMpcdec index fd92a4f..3bbd71c 100644 --- a/lib/decode/decodeMpcdec +++ b/lib/decode/decodeMpcdec @@ -1,5 +1,6 @@ #!/bin/bash decodeMpcdec() { tmpfile="${fileid}mpcdec" - commandline=(mpcdec "$sourcepath/$filename" "$tempdir/$tmpfile.wav") + commandline=(${ionice}mpcdec) + commandline+=("$sourcepath/$filename" "$tempdir/$tmpfile.wav") } diff --git a/lib/decode/decodeOpusdec b/lib/decode/decodeOpusdec index 9f9d0ef..46f08bd 100644 --- a/lib/decode/decodeOpusdec +++ b/lib/decode/decodeOpusdec @@ -1,5 +1,6 @@ #!/bin/bash decodeOpusdec() { tmpfile="${fileid}opusdec" - commandline=(opusdec "$sourcepath/$filename" "$tempdir/$tmpfile.wav") + commandline=(${ionice}opusdec) + commandline+=("$sourcepath/$filename" "$tempdir/$tmpfile.wav") } diff --git a/lib/decode/decodeSox b/lib/decode/decodeSox index 69f8053..5d7e6df 100644 --- a/lib/decode/decodeSox +++ b/lib/decode/decodeSox @@ -1,6 +1,6 @@ #!/bin/bash decodeSox() { - commandline=(sox --single-threaded --temp "$tempdir") + commandline=(${ionice}sox --single-threaded --temp "$tempdir") soxoptions_in='' soxoptions_out='' if (( ${destinationnormalize["$destination"]} )) diff --git a/lib/encode/encodeFile::mp3 b/lib/encode/encodeFile::mp3 index 34aa133..c958f2a 100644 --- a/lib/encode/encodeFile::mp3 +++ b/lib/encode/encodeFile::mp3 @@ -1,6 +1,7 @@ #!/bin/bash encodeFile::mp3() { - lameopts=(lame --quiet -v --abr ${destinationquality[$destination]}) + lameopts=(${ionice}lame --quiet) + lameopts+=(-v --abr ${destinationquality[$destination]}) [ -n "$album" ] && lameopts+=(--tl "$album" ) [ -n "$artist" ] && lameopts+=(--ta "$artist") [ -n "$genre" ] && lameopts+=(--tg "$genre") diff --git a/lib/encode/encodeFile::opus b/lib/encode/encodeFile::opus index bc7d9f3..2794a05 100644 --- a/lib/encode/encodeFile::opus +++ b/lib/encode/encodeFile::opus @@ -1,6 +1,6 @@ #!/bin/bash encodeFile::opus() { - opusencopts=(opusenc --music --quiet) + opusencopts=(${ionice}opusenc --music --quiet) opusencopts+=(--bitrate ${destinationquality[$destination]}) [ -n "${destinationloss["$destination"]}" ] \ && opusencopts+=(--expect-loss "${destinationloss["$destination"]}") diff --git a/lib/encode/encodeFile::vorbis b/lib/encode/encodeFile::vorbis index e3d87d4..c3a72e3 100644 --- a/lib/encode/encodeFile::vorbis +++ b/lib/encode/encodeFile::vorbis @@ -1,6 +1,6 @@ #!/bin/bash encodeFile::vorbis() { - oggencopts=(oggenc -Q -q ${destinationquality[$destination]}) + oggencopts=(${ionice}oggenc -Q -q ${destinationquality[$destination]}) [ -n "$albumartist" ] && oggencopts+=(-c "ALBUMARTIST=$albumartist") [ -n "$album" ] && oggencopts+=(-l "$album") [ -n "$artist" ] && oggencopts+=(-a "$artist")