Commit 2f70c49e5b9813635ad73666aa30f304c7fdeda9
Committed by
Ben Warren
1 parent
ad2d16393e
Exists in
master
and in
54 other branches
netloop: speed up NetLoop
NetLoop polls every cycle with getenv some environment variables. This is horribly slow, especially when the environment is big. This patch reads only the environment variables in NetLoop, when they were changed. Also moved the init part of the NetLoop function in a seperate function. Signed-off-by: Heiko Schocher <hs@denx.de> Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Showing 4 changed files with 91 additions and 61 deletions Side-by-side Diff
common/cmd_nvedit.c
... | ... | @@ -75,7 +75,12 @@ |
75 | 75 | static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; |
76 | 76 | #define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0])) |
77 | 77 | |
78 | +static int env_id = 1; | |
78 | 79 | |
80 | +int get_env_id (void) | |
81 | +{ | |
82 | + return env_id; | |
83 | +} | |
79 | 84 | /************************************************************************ |
80 | 85 | * Command interface: print one or all environment variables |
81 | 86 | */ |
... | ... | @@ -160,6 +165,7 @@ |
160 | 165 | return 1; |
161 | 166 | } |
162 | 167 | |
168 | + env_id++; | |
163 | 169 | /* |
164 | 170 | * search if variable with this name already exists |
165 | 171 | */ |
include/common.h
net/eth.c
... | ... | @@ -28,6 +28,9 @@ |
28 | 28 | |
29 | 29 | #if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI) |
30 | 30 | |
31 | +static char *act = NULL; | |
32 | +static int env_changed_id = 0; | |
33 | + | |
31 | 34 | /* |
32 | 35 | * CPU and board-specific Ethernet initializations. Aliased function |
33 | 36 | * signals caller to move on |
34 | 37 | |
35 | 38 | |
... | ... | @@ -461,13 +464,17 @@ |
461 | 464 | #ifdef CONFIG_NET_MULTI |
462 | 465 | void eth_set_current(void) |
463 | 466 | { |
464 | - char *act; | |
465 | 467 | struct eth_device* old_current; |
468 | + int env_id; | |
466 | 469 | |
467 | 470 | if (!eth_current) /* XXX no current */ |
468 | 471 | return; |
469 | 472 | |
470 | - act = getenv("ethact"); | |
473 | + env_id = get_env_id(); | |
474 | + if ((act == NULL) || (env_changed_id != env_id)) { | |
475 | + act = getenv("ethact"); | |
476 | + env_changed_id = env_id; | |
477 | + } | |
471 | 478 | if (act != NULL) { |
472 | 479 | old_current = eth_current; |
473 | 480 | do { |
net/net.c
... | ... | @@ -209,6 +209,8 @@ |
209 | 209 | ulong NetArpWaitTimerStart; |
210 | 210 | int NetArpWaitTry; |
211 | 211 | |
212 | +int env_changed_id = 0; | |
213 | + | |
212 | 214 | void ArpRequest (void) |
213 | 215 | { |
214 | 216 | int i; |
... | ... | @@ -276,6 +278,78 @@ |
276 | 278 | } |
277 | 279 | } |
278 | 280 | |
281 | +int | |
282 | +NetInitLoop(proto_t protocol) | |
283 | +{ | |
284 | + bd_t *bd = gd->bd; | |
285 | + int env_id = get_env_id (); | |
286 | + | |
287 | + /* update only when the environment has changed */ | |
288 | + if (env_changed_id == env_id) | |
289 | + return 0; | |
290 | + | |
291 | + switch (protocol) { | |
292 | +#if defined(CONFIG_CMD_NFS) | |
293 | + case NFS: | |
294 | +#endif | |
295 | +#if defined(CONFIG_CMD_PING) | |
296 | + case PING: | |
297 | +#endif | |
298 | +#if defined(CONFIG_CMD_SNTP) | |
299 | + case SNTP: | |
300 | +#endif | |
301 | + case NETCONS: | |
302 | + case TFTP: | |
303 | + NetCopyIP(&NetOurIP, &bd->bi_ip_addr); | |
304 | + NetOurGatewayIP = getenv_IPaddr ("gatewayip"); | |
305 | + NetOurSubnetMask= getenv_IPaddr ("netmask"); | |
306 | + NetOurVLAN = getenv_VLAN("vlan"); | |
307 | + NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
308 | + | |
309 | + switch (protocol) { | |
310 | +#if defined(CONFIG_CMD_NFS) | |
311 | + case NFS: | |
312 | +#endif | |
313 | + case NETCONS: | |
314 | + case TFTP: | |
315 | + NetServerIP = getenv_IPaddr ("serverip"); | |
316 | + break; | |
317 | +#if defined(CONFIG_CMD_PING) | |
318 | + case PING: | |
319 | + /* nothing */ | |
320 | + break; | |
321 | +#endif | |
322 | +#if defined(CONFIG_CMD_SNTP) | |
323 | + case SNTP: | |
324 | + /* nothing */ | |
325 | + break; | |
326 | +#endif | |
327 | + default: | |
328 | + break; | |
329 | + } | |
330 | + | |
331 | + break; | |
332 | + case BOOTP: | |
333 | + case RARP: | |
334 | + /* | |
335 | + * initialize our IP addr to 0 in order to accept ANY | |
336 | + * IP addr assigned to us by the BOOTP / RARP server | |
337 | + */ | |
338 | + NetOurIP = 0; | |
339 | + NetServerIP = getenv_IPaddr ("serverip"); | |
340 | + NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */ | |
341 | + NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
342 | + case CDP: | |
343 | + NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */ | |
344 | + NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
345 | + break; | |
346 | + default: | |
347 | + break; | |
348 | + } | |
349 | + env_changed_id = env_id; | |
350 | + return 0; | |
351 | +} | |
352 | + | |
279 | 353 | /**********************************************************************/ |
280 | 354 | /* |
281 | 355 | * Main network processing loop. |
... | ... | @@ -340,65 +414,7 @@ |
340 | 414 | * here on, this code is a state machine driven by received |
341 | 415 | * packets and timer events. |
342 | 416 | */ |
343 | - | |
344 | - switch (protocol) { | |
345 | -#if defined(CONFIG_CMD_NFS) | |
346 | - case NFS: | |
347 | -#endif | |
348 | -#if defined(CONFIG_CMD_PING) | |
349 | - case PING: | |
350 | -#endif | |
351 | -#if defined(CONFIG_CMD_SNTP) | |
352 | - case SNTP: | |
353 | -#endif | |
354 | - case NETCONS: | |
355 | - case TFTP: | |
356 | - NetCopyIP(&NetOurIP, &bd->bi_ip_addr); | |
357 | - NetOurGatewayIP = getenv_IPaddr ("gatewayip"); | |
358 | - NetOurSubnetMask= getenv_IPaddr ("netmask"); | |
359 | - NetOurVLAN = getenv_VLAN("vlan"); | |
360 | - NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
361 | - | |
362 | - switch (protocol) { | |
363 | -#if defined(CONFIG_CMD_NFS) | |
364 | - case NFS: | |
365 | -#endif | |
366 | - case NETCONS: | |
367 | - case TFTP: | |
368 | - NetServerIP = getenv_IPaddr ("serverip"); | |
369 | - break; | |
370 | -#if defined(CONFIG_CMD_PING) | |
371 | - case PING: | |
372 | - /* nothing */ | |
373 | - break; | |
374 | -#endif | |
375 | -#if defined(CONFIG_CMD_SNTP) | |
376 | - case SNTP: | |
377 | - /* nothing */ | |
378 | - break; | |
379 | -#endif | |
380 | - default: | |
381 | - break; | |
382 | - } | |
383 | - | |
384 | - break; | |
385 | - case BOOTP: | |
386 | - case RARP: | |
387 | - /* | |
388 | - * initialize our IP addr to 0 in order to accept ANY | |
389 | - * IP addr assigned to us by the BOOTP / RARP server | |
390 | - */ | |
391 | - NetOurIP = 0; | |
392 | - NetServerIP = getenv_IPaddr ("serverip"); | |
393 | - NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */ | |
394 | - NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
395 | - case CDP: | |
396 | - NetOurVLAN = getenv_VLAN("vlan"); /* VLANs must be read */ | |
397 | - NetOurNativeVLAN = getenv_VLAN("nvlan"); | |
398 | - break; | |
399 | - default: | |
400 | - break; | |
401 | - } | |
417 | + NetInitLoop(protocol); | |
402 | 418 | |
403 | 419 | switch (net_check_prereq (protocol)) { |
404 | 420 | case 1: |