Skip to contentSkip to conversation

Net fix and improvements

PATCH In review Glenn Washburn 2 participants 5 messages Mar 8, 2022 – Mar 17, 2022

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 net: Unset grub_net_poll_cards_idle when net module has been unloaded

In reply to Glenn Washburn
---
 grub-core/net/net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/net/net.c +1 -1
index 4d3eb5c1a5..563dea9ec8 100644
@@ -1948,5 +1948,5 @@ GRUB_MOD_FINI(net)
   grub_net_open = NULL;
   grub_net_fini_hw (0);
   grub_loader_unregister_preboot_hook (fini_hnd);
-  grub_net_poll_cards_idle = grub_net_poll_cards_idle_real;
+  grub_net_poll_cards_idle = NULL;
 }
Signature · 1 line
2.27.0
#0 lore raw

cover Net fix and improvements

The first patch looks like it was a copy/paste error. If the net module is unloaded, grub_net_poll_cards_idle should be NULL so that a function in the net module which now doesn't exist.

The second and third patches are for performance and were helpful when debugging GRUB. When the net module is loaded, even if there are no net cards found, grub_net_poll_cards_idle will call grub_net_tcp_retransmit() unconditionally. But there's no need to go through tcp retransmit logic if there aren't any cards that we could be retransmitting on.

As for the third patch, if the machine has network cards found, but there are no tcp open sockets (because the user doesn't use the network to boot), then grub_net_tcp_retransmit() should be a noop. Thus is doesn't need to call grub_get_time_ms(), which does a call into firmware on powerpc-ieee1275. So only call grub_get_time_ms() if there are tcp sockets.

Calls to grub_net_poll_cards_idle can happen a lot when GRUB is waiting for a keypress (grub_getkey_noblock calls grub_net_poll_cards_idle). I found this annoying when debugging an issue in GRUB with GDB and I found that nearly every time I interrupted GRUB with the GDB I was landing in OpenBIOS's milliseconds call and then I had to step out back into GRUB which could be a hundred or more instructions. This reduces the probability that interrupting GRUB lands in the firmware when GRUB is blocked waiting on a keypress.

Glenn

Glenn Washburn (3):
net: Unset grub_net_poll_cards_idle when net module has been unloaded
net: Avoid unnecessary calls to grub_net_tcp_retransmit net/tcp: Only call grub_get_time_ms when there are sockets to
potentially retransmit for

 grub-core/net/net.c | 5 +++--
 grub-core/net/tcp.c | 9 +++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/3 net: Avoid unnecessary calls to grub_net_tcp_retransmit

In grub_net_poll_cards_idle_real, only call grub_net_tcp_retransmit if there are network cards found. If there are no network card found, there can be no tcp sockets to transmit on.

---
 grub-core/net/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/net/net.c +2 -1
index 563dea9ec8..e208b84019 100644
@@ -1580,7 +1580,8 @@ grub_net_poll_cards_idle_real (void)
 	|| ctime >= card->last_poll + card->idle_poll_delay_ms)
       receive_packets (card, 0);
   }
-  grub_net_tcp_retransmit ();
+  if (grub_net_cards)
+    grub_net_tcp_retransmit ();
 }
 
 /*  Read from the packets list*/
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/3 net/tcp: Only call grub_get_time_ms when there are sockets to potentially retransmit for

In reply to Glenn Washburn

If there are no TCP sockets, this call to grub_get_time_ms is unneeded. This prevents a call into the firmware on some platforms.

---
 grub-core/net/tcp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
grub-core/net/tcp.c +7 -2
index e8ad34b84d..75461eb54e 100644
@@ -362,8 +362,13 @@ void
 grub_net_tcp_retransmit (void)
 {
   grub_net_tcp_socket_t sock;
-  grub_uint64_t ctime = grub_get_time_ms ();
-  grub_uint64_t limit_time = ctime - TCP_RETRANSMISSION_TIMEOUT;
+  grub_uint64_t ctime = 0, limit_time = 0;
+
+  if (tcp_sockets)
+    {
+      ctime = grub_get_time_ms ();
+      limit_time = ctime - TCP_RETRANSMISSION_TIMEOUT;
+    }
 
   FOR_TCP_SOCKETS (sock)
   {
Signature · 1 line
2.27.0
#4 lore raw
In reply to Glenn Washburn

Hey,

Quoted 16 lines · Glenn Washburn

The first patch looks like it was a copy/paste error. If the net module is unloaded, grub_net_poll_cards_idle should be NULL so that a function in the net module which now doesn't exist.

The second and third patches are for performance and were helpful when debugging GRUB. When the net module is loaded, even if there are no net cards found, grub_net_poll_cards_idle will call grub_net_tcp_retransmit() unconditionally. But there's no need to go through tcp retransmit logic if there aren't any cards that we could be retransmitting on.

As for the third patch, if the machine has network cards found, but there are no tcp open sockets (because the user doesn't use the network to boot), then grub_net_tcp_retransmit() should be a noop. Thus is doesn't need to call grub_get_time_ms(), which does a call into firmware on powerpc-ieee1275. So only call grub_get_time_ms() if there are tcp sockets.

Quoted 7 lines

Calls to grub_net_poll_cards_idle can happen a lot when GRUB is waiting for a keypress (grub_getkey_noblock calls grub_net_poll_cards_idle). I found this annoying when debugging an issue in GRUB with GDB and I found that nearly every time I interrupted GRUB with the GDB I was landing in OpenBIOS's milliseconds call and then I had to step out back into GRUB which could be a hundred or more instructions. This reduces the probability that interrupting GRUB lands in the firmware when GRUB is blocked waiting on a keypress.

In general I think this cover letter should be split into three parts and they should go into relevant patches.

Additionally, if you check pointers for NULL please use "== NULL" comparison explicitly instead of shortened version like "if (pointer)".

Otherwise patches LGTM.

Daniel