Introduce squashfs compression threshold

If we can't beat that compression ratio for a single block then we leave
it uncompressed. The choice of the threshold depends on the cost of I/O
in a specific device which is determined from block I/O speed and CPU
speed.

BUG: 29058965
Change-Id: I8d17a4551c7d00ddb85687381b7cb0d6c60babf6
Signed-off-by: Mohamad Ayyash <mkayyash@google.com>
diff --git a/squashfs_utils/mksquashfsimage.sh b/squashfs_utils/mksquashfsimage.sh
index 0079f6e..9dae51b 100755
--- a/squashfs_utils/mksquashfsimage.sh
+++ b/squashfs_utils/mksquashfsimage.sh
@@ -5,7 +5,7 @@
 function usage() {
 cat<<EOT
 Usage:
-${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-C FS_CONFIG ] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT]
+${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-C FS_CONFIG ] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT] [-t COMPRESS_THRESHOLD]
 EOT
 }
 
@@ -73,6 +73,13 @@
     shift; shift
 fi
 
+COMPRESS_THRESHOLD=0
+if [[ "$1" == "-t" ]]; then
+    COMPRESS_THRESHOLD=$2
+    shift; shift
+fi
+
+
 OPT=""
 if [ -n "$MOUNT_POINT" ]; then
   OPT="$OPT -mount-point $MOUNT_POINT"
@@ -89,6 +96,9 @@
 if [ -n "$BLOCK_SIZE" ]; then
   OPT="$OPT -b $BLOCK_SIZE"
 fi
+if [ -n "$COMPRESS_THRESHOLD" ]; then
+  OPT="$OPT -t $COMPRESS_THRESHOLD"
+fi
 
 MAKE_SQUASHFS_CMD="mksquashfs $SRC_DIR/ $OUTPUT_FILE -no-progress -comp $COMPRESSOR $COMPRESSOR_OPT -no-exports -noappend -no-recovery -android-fs-config -no-fragments $OPT"
 echo $MAKE_SQUASHFS_CMD