Skip to contentSkip to conversation

common, env: optimize boottime

PATCH In review Heiko Schocher 2 participants 2 messages Dec 19, 2013 – Jan 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common, env: optimize boottime

when creating the hashtable, for each environmentvariable getenv(ENV_CALLBACK_VAR) and getenv(ENV_FLAGS_VAR) is called, which costs at this point a lot of time. So call this two getenv() calls only once.

Boottime on the ids8313 board without this patch:

2013-12-19 13:38:22,894:  NAND:  128 MiB
2013-12-19 13:38:27,659:  In:    serial

(~4.8 sec)

Bootime with this patch on the ids8313 board:

2013-12-19 13:40:25,332:  NAND:  128 MiB
2013-12-19 13:40:25,546:  In:    serial

(~0.2 sec)

Cc Tom Rini <[email protected]>
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 common/env_callback.c | 9 ++++++++-
 common/env_flags.c    | 8 +++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
common/env_callback.c +8 -1
index 34bb58e..d03fa03 100644
@@ -35,6 +35,9 @@ static struct env_clbk_tbl *find_env_callback(const char *name)
 	return NULL;
 }
 
+static int first_call = 1;
+static const char *callback_list;
+
 /*
  * Look for a possible callback for a newly added variable
  * This is called specifically when the variable did not exist in the hash
@@ -43,11 +46,15 @@ static struct env_clbk_tbl *find_env_callback(const char *name)
 void env_callback_init(ENTRY *var_entry)
 {
 	const char *var_name = var_entry->key;
-	const char *callback_list = getenv(ENV_CALLBACK_VAR);
 	char callback_name[256] = "";
 	struct env_clbk_tbl *clbkp;
 	int ret = 1;
 
+	if (first_call) {
+		callback_list = getenv(ENV_CALLBACK_VAR);
+		first_call = 0;
+	}
+
 	/* look in the ".callbacks" var for a reference to this variable */
 	if (callback_list != NULL)
 		ret = env_attr_lookup(callback_list, var_name, callback_name);
common/env_flags.c +7 -1
index e9b72e6..985f92e 100644
@@ -395,6 +395,9 @@ static int env_parse_flags_to_bin(const char *flags)
 	return binflags;
 }
 
+static int first_call = 1;
+static const char *flags_list;
+
 /*
  * Look for possible flags for a newly added variable
  * This is called specifically when the variable did not exist in the hash
@@ -403,10 +406,13 @@ static int env_parse_flags_to_bin(const char *flags)
 void env_flags_init(ENTRY *var_entry)
 {
 	const char *var_name = var_entry->key;
-	const char *flags_list = getenv(ENV_FLAGS_VAR);
 	char flags[ENV_FLAGS_ATTR_MAX_LEN + 1] = "";
 	int ret = 1;
 
+	if (first_call) {
+		flags_list = getenv(ENV_FLAGS_VAR);
+		first_call = 0;
+	}
 	/* look in the ".flags" and static for a reference to this variable */
 	ret = env_flags_lookup(flags_list, var_name, flags);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 13 lines · Heiko Schocher

when creating the hashtable, for each environmentvariable getenv(ENV_CALLBACK_VAR) and getenv(ENV_FLAGS_VAR) is called, which costs at this point a lot of time. So call this two getenv() calls only once.

Boottime on the ids8313 board without this patch:

2013-12-19 13:38:22,894:  NAND:  128 MiB
2013-12-19 13:38:27,659:  In:    serial

(~4.8 sec)

Bootime with this patch on the ids8313 board:

Quoted 8 lines
2013-12-19 13:40:25,332:  NAND:  128 MiB
2013-12-19 13:40:25,546:  In:    serial

(~0.2 sec)

Cc Tom Rini <[email protected]>
Cc Joe Hershberger <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140114/8ae788a2/attachment.pgp>