aboutsummaryrefslogtreecommitdiffstats
path: root/nandroid.c
diff options
context:
space:
mode:
authorAndrew Dodd <atd7@cornell.edu>2012-05-04 21:38:24 -0400
committerAndrew Dodd <atd7@cornell.edu>2012-06-13 21:58:17 -0400
commit04076f0722381ca68420c3b9172dac78d3b91017 (patch)
treee79ba602c706c41039559566f396befcec0053d6 /nandroid.c
parent8ba9a6335becb20598187a3523dc94aab0456284 (diff)
downloadbootable_recovery-04076f0722381ca68420c3b9172dac78d3b91017.zip
bootable_recovery-04076f0722381ca68420c3b9172dac78d3b91017.tar.gz
bootable_recovery-04076f0722381ca68420c3b9172dac78d3b91017.tar.bz2
Only update UI at 1 Hz during nandroid backup/restore
On high-resolution devices such as the Galaxy Note, UI updates consume more CPU than all other operations. For example, a nandroid restore on Note pegs an entire core at 1.4 GHz for the recovery process while tar is using only 14% of the other core, and iowait times are low indicating the CPU is not simply waiting for IO. Nandroid backup/restore should be I/O bound, not CPU bound. This changes the update interval to 1 Hz during nandroid backup and restore. Change-Id: Ic021cd6dc453b92468396cab1a31bd693efb43e0
Diffstat (limited to 'nandroid.c')
-rw-r--r--nandroid.c50
1 files changed, 42 insertions, 8 deletions
diff --git a/nandroid.c b/nandroid.c
index fc39359..d986457 100644
--- a/nandroid.c
+++ b/nandroid.c
@@ -42,6 +42,7 @@
#include "flashutils/flashutils.h"
#include <libgen.h>
+
void nandroid_generate_timestamp_path(const char* backup_path)
{
time_t t = time(NULL);
@@ -63,6 +64,19 @@ static int print_and_error(const char* message) {
return 1;
}
+static long delta_milliseconds(struct timeval from, struct timeval to) {
+ long delta_sec = (to.tv_sec - from.tv_sec)*1000;
+ long delta_usec = (to.tv_usec - from.tv_usec)/1000;
+ return (delta_sec + delta_usec);
+}
+
+/*
+ * How often nandroid updates text in ms
+ */
+
+#define NANDROID_UPDATE_INTERVAL 1000
+
+static struct timeval lastupdate = (struct timeval) {0};
static int yaffs_files_total = 0;
static int yaffs_files_count = 0;
static void yaffs_callback(const char* filename)
@@ -71,15 +85,29 @@ static void yaffs_callback(const char* filename)
return;
const char* justfile = basename(filename);
char tmp[PATH_MAX];
- strcpy(tmp, justfile);
- if (tmp[strlen(tmp) - 1] == '\n')
- tmp[strlen(tmp) - 1] = NULL;
- if (strlen(tmp) < 30)
- ui_print("%s", tmp);
+ struct timeval curtime;
+ gettimeofday(&curtime,NULL);
+ /*
+ * Only update once every NANDROID_UPDATE_INTERVAL
+ * milli seconds. We don't need frequent progress
+ * updates and updating every file uses WAY
+ * too much CPU time.
+ */
yaffs_files_count++;
- if (yaffs_files_total != 0)
- ui_set_progress((float)yaffs_files_count / (float)yaffs_files_total);
- ui_reset_text_col();
+ if(delta_milliseconds(lastupdate,curtime) > NANDROID_UPDATE_INTERVAL)
+ {
+ strcpy(tmp, justfile);
+ if (tmp[strlen(tmp) - 1] == '\n')
+ tmp[strlen(tmp) - 1] = NULL;
+ if (strlen(tmp) < 30) {
+ lastupdate = curtime;
+ ui_print("%s", tmp);
+ }
+
+ if (yaffs_files_total != 0)
+ ui_set_progress((float)yaffs_files_count / (float)yaffs_files_total);
+ ui_reset_text_col();
+ }
}
static void compute_directory_stats(const char* directory)
@@ -103,6 +131,7 @@ typedef int (*nandroid_backup_handler)(const char* backup_path, const char* back
static int mkyaffs2image_wrapper(const char* backup_path, const char* backup_file_image, int callback) {
char backup_file_image_with_extension[PATH_MAX];
sprintf(backup_file_image_with_extension, "%s.img", backup_file_image);
+ gettimeofday(&lastupdate,NULL);
return mkyaffs2image(backup_path, backup_file_image_with_extension, 0, callback ? yaffs_callback : NULL);
}
@@ -119,6 +148,8 @@ static int tar_compress_wrapper(const char* backup_path, const char* backup_file
return -1;
}
+ gettimeofday(&lastupdate,NULL);
+
while (fgets(tmp, PATH_MAX, fp) != NULL) {
tmp[PATH_MAX - 1] = NULL;
if (callback)
@@ -337,6 +368,7 @@ static void ensure_directory(const char* dir) {
typedef int (*nandroid_restore_handler)(const char* backup_file_image, const char* backup_path, int callback);
static int unyaffs_wrapper(const char* backup_file_image, const char* backup_path, int callback) {
+ gettimeofday(&lastupdate,NULL);
return unyaffs(backup_file_image, backup_path, callback ? yaffs_callback : NULL);
}
@@ -351,6 +383,8 @@ static int tar_extract_wrapper(const char* backup_file_image, const char* backup
return -1;
}
+ gettimeofday(&lastupdate,NULL);
+
while (fgets(path, PATH_MAX, fp) != NULL) {
if (callback)
yaffs_callback(path);