Commit 5dfaba0c authored by Alessandro Rubini's avatar Alessandro Rubini

userspace/hal: reorder the main loop, no actual change

Every two months I've been wondering what this 100%-cpu main loop
was, to later acknowledge it was not really 100%.

This commit reorders items and makes it clear where the delay is.
I tried raising it to 100ms from 25ms, but the cpu load of wrsw_hal
didn't change, because most of the time we return to the main
loop before the timeout, due to an RPC call being served.

In my opinion we should add a check in the main loop, to call
port_update_all only 10 times per second, to actually
lower the CPU load of this process.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 5628e3cc
......@@ -242,9 +242,9 @@ int hal_init_wripc(struct hal_port_state *hal_ports)
}
/* wripc update function, must be called in the main program loop */
int hal_update_wripc()
int hal_update_wripc(int ms_timeout)
{
minipc_server_action(hal_ch, 25 /* ms */ );
minipc_server_action(hal_ch, ms_timeout);
return 0;
}
......
......@@ -109,16 +109,6 @@ static int hal_init()
return 0;
}
/* Main loop update - polls for WRIPC requests and rolls the port
* state machines */
static void hal_update()
{
hal_update_wripc();
hal_port_update_all();
shw_update_fans();
// usleep(1000);
}
/* Turns a nice and well-behaving HAL into an evil servant of satan. */
static void hal_deamonize()
{
......@@ -191,7 +181,6 @@ static void hal_parse_cmdline(int argc, char *argv[])
int main(int argc, char *argv[])
{
trace_log_file("/dev/kmsg");
/* Prevent from running HAL twice - it will likely freeze the system */
if (hal_check_running()) {
......@@ -205,8 +194,19 @@ int main(int argc, char *argv[])
if (hal_init())
exit(1);
for (;;)
hal_update();
/*
* Main loop update - polls for WRIPC requests and rolls the port
* state machines. This is not a busy loop, as wripc waits for
* the "max ms delay". Unless an RPC call comes, and then the
* delay is smaller; so this loop really consumes a lot of
* cpu time.
*/
for (;;) {
hal_update_wripc(25 /* max ms delay */);
hal_port_update_all();
shw_update_fans();
}
hal_shutdown();
return 0;
......
......@@ -29,7 +29,7 @@ int hal_port_query_ports(struct hexp_port_list *list,
int hal_init_wripc();
int hal_update_wripc();
int hal_update_wripc(int ms_timeout);
int hal_add_cleanup_callback(hal_cleanup_callback_t cb);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment