Commit c6d037fb authored by Adam Wujek's avatar Adam Wujek 💬

userspace/wrsw_hal: improve timeouts

In hal_main.c, use timeout functions from libwr. Use two different timeouts for
temperature/fan updates and for port information.

In hal_ports.c use different timeouts for sync LEDs, link LEDs and SFPs' DOMs
updates.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 980b0e17
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
#include <libwr/shmem.h> #include <libwr/shmem.h>
#include <libwr/hal_shmem.h> #include <libwr/hal_shmem.h>
#include <libwr/util.h> #include <libwr/util.h>
#include <libwr/timeout.h>
#include "wrsw_hal.h" #include "wrsw_hal.h"
#include <rt_ipc.h> #include <rt_ipc.h>
#define MAX_CLEANUP_CALLBACKS 16 #define MAX_CLEANUP_CALLBACKS 16
#define PORT_FAN_MS_PERIOD 250 #define UPDATE_FAN_PERIOD 500
#define UPDATE_ALL_PERIOD 100
static int daemon_mode = 0; static int daemon_mode = 0;
static hal_cleanup_callback_t cleanup_cb[MAX_CLEANUP_CALLBACKS]; static hal_cleanup_callback_t cleanup_cb[MAX_CLEANUP_CALLBACKS];
...@@ -223,8 +225,10 @@ static void hal_parse_cmdline(int argc, char *argv[]) ...@@ -223,8 +225,10 @@ static void hal_parse_cmdline(int argc, char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint64_t t1, t2;
struct hal_temp_sensors temp_sensors; /* local copy of temperatures */ struct hal_temp_sensors temp_sensors; /* local copy of temperatures */
static timeout_t update_fan_tmo;
static timeout_t update_all_tmo;
wrs_msg_init(argc, argv); wrs_msg_init(argc, argv);
/* Print HAL's version */ /* Print HAL's version */
...@@ -242,6 +246,9 @@ int main(int argc, char *argv[]) ...@@ -242,6 +246,9 @@ int main(int argc, char *argv[])
if (hal_init()) if (hal_init())
exit(1); exit(1);
libwr_tmo_init(&update_fan_tmo, UPDATE_FAN_PERIOD, 1);
libwr_tmo_init(&update_all_tmo, UPDATE_ALL_PERIOD, 1);
/* /*
* Main loop update - polls for WRIPC requests and rolls the port * Main loop update - polls for WRIPC requests and rolls the port
* state machines. This is not a busy loop, as wripc waits for * state machines. This is not a busy loop, as wripc waits for
...@@ -249,31 +256,26 @@ int main(int argc, char *argv[]) ...@@ -249,31 +256,26 @@ int main(int argc, char *argv[])
* case it returns earlier. * case it returns earlier.
* *
* We thus check the actual time, and only proceed with * We thus check the actual time, and only proceed with
* port and fan update every PORT_FAN_MS_PERIOD. There still * port and fan update every UPDATE_FAN_PERIOD. There still
* is some jitter from hal_update_wripc() timing. * is some jitter from hal_update_wripc() timing.
* includes some jitter.
*/ */
t1 = get_monotonic_us();
for (;;) { for (;;) {
int delay_ms;
hal_update_wripc(25 /* max ms delay */); hal_update_wripc(25 /* max ms delay */);
t2 = get_monotonic_us(); if (libwr_tmo_expired(&update_all_tmo))
delay_ms = (t2 - t1) / 1000; hal_port_update_all();
if (delay_ms < PORT_FAN_MS_PERIOD)
continue; if (libwr_tmo_expired(&update_fan_tmo)) {
/* Update fans and get temperatures values. Don't write
hal_port_update_all(); * temperatures directly to the shmem to reduce the
/* Update fans and get temperatures values. Don't write * critical section of shmem */
* temperatures directly to the shmem to reduce the critical shw_update_fans(&temp_sensors);
* section of shmem */ wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_BEGIN);
shw_update_fans(&temp_sensors); memcpy(&hal_shmem->temp, &temp_sensors,
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_BEGIN); sizeof(temp_sensors));
memcpy(&hal_shmem->temp, &temp_sensors, sizeof(temp_sensors)); wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END); }
t1 = t2;
} }
hal_shutdown(); hal_shutdown();
......
...@@ -31,8 +31,11 @@ ...@@ -31,8 +31,11 @@
#include <libwr/hal_shmem.h> #include <libwr/hal_shmem.h>
#include "driver_stuff.h" #include "driver_stuff.h"
#define RTS_POLL_INTERVAL 200 /* ms */ #define UPDATE_RTS_PERIOD 250 /* ms */
#define SFP_POLL_INTERVAL 1000 /* ms */ #define UPDATE_SFP_PERIOD 1000 /* ms */
#define UPDATE_SYNC_LEDS_PERIOD 500 /* ms */
#define UPDATE_LINK_LEDS_PERIOD 500 /* ms */
#define UPDATE_SFP_DOM_PERIOD 1000 /* ms */
extern struct hal_shmem_header *hal_shmem; extern struct hal_shmem_header *hal_shmem;
extern struct wrs_shm_head *hal_shmem_hdr; extern struct wrs_shm_head *hal_shmem_hdr;
...@@ -49,6 +52,8 @@ static int hal_port_rts_state_valid = 0; ...@@ -49,6 +52,8 @@ static int hal_port_rts_state_valid = 0;
/* Polling timeouts (RT Subsystem & SFP detection) */ /* Polling timeouts (RT Subsystem & SFP detection) */
static timeout_t hal_port_tmo_rts, hal_port_tmo_sfp; static timeout_t hal_port_tmo_rts, hal_port_tmo_sfp;
static timeout_t update_sync_leds_tmo, update_link_leds_tmo;
static timeout_t update_sfp_dom_tmo;
static int hal_port_nports; static int hal_port_nports;
static struct wr_servo_state *ppsi_servo; static struct wr_servo_state *ppsi_servo;
...@@ -230,8 +235,11 @@ int hal_port_init_shmem(char *logfilename) ...@@ -230,8 +235,11 @@ int hal_port_init_shmem(char *logfilename)
pr_info("Initializing switch ports...\n"); pr_info("Initializing switch ports...\n");
/* default timeouts */ /* default timeouts */
libwr_tmo_init(&hal_port_tmo_sfp, SFP_POLL_INTERVAL, 1); libwr_tmo_init(&hal_port_tmo_sfp, UPDATE_SFP_PERIOD, 1);
libwr_tmo_init(&hal_port_tmo_rts, RTS_POLL_INTERVAL, 1); libwr_tmo_init(&hal_port_tmo_rts, UPDATE_RTS_PERIOD, 1);
libwr_tmo_init(&update_sync_leds_tmo, UPDATE_SYNC_LEDS_PERIOD, 1);
libwr_tmo_init(&update_link_leds_tmo, UPDATE_LINK_LEDS_PERIOD, 1);
libwr_tmo_init(&update_sfp_dom_tmo, UPDATE_SFP_DOM_PERIOD, 1);
/* Open a single raw socket for accessing the MAC addresses, etc. */ /* Open a single raw socket for accessing the MAC addresses, etc. */
hal_port_fd = socket(AF_PACKET, SOCK_DGRAM, 0); hal_port_fd = socket(AF_PACKET, SOCK_DGRAM, 0);
...@@ -658,17 +666,23 @@ void hal_port_update_all() ...@@ -658,17 +666,23 @@ void hal_port_update_all()
hal_port_poll_sfp(); hal_port_poll_sfp();
for (i = 0; i < HAL_MAX_PORTS; i++) for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use) { if (ports[i].in_use)
hal_port_fsm(&ports[i]); hal_port_fsm(&ports[i]);
if (hal_shmem->read_sfp_diag == READ_SFP_DIAG_ENABLE
&& libwr_tmo_expired(&update_sfp_dom_tmo)) {
for (i = 0; i < HAL_MAX_PORTS; i++) {
/* update DOM only for plugged ports with DOM /* update DOM only for plugged ports with DOM
* capabilities */ * capabilities */
if (ports[i].state != HAL_PORT_STATE_DISABLED if (ports[i].in_use
&& hal_shmem->read_sfp_diag == READ_SFP_DIAG_ENABLE && ports[i].state != HAL_PORT_STATE_DISABLED
&& (ports[i].has_sfp_diag)) { && (ports[i].has_sfp_diag)) {
shw_sfp_update_dom(ports[i].hw_index, shw_sfp_update_dom(ports[i].hw_index,
&ports[i].calib.sfp_dom_raw); &ports[i].calib.sfp_dom_raw);
} }
} }
}
/* unlock shmem */ /* unlock shmem */
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END); wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
...@@ -676,11 +690,15 @@ void hal_port_update_all() ...@@ -676,11 +690,15 @@ void hal_port_update_all()
if (!try_open_ppsi_shmem()) if (!try_open_ppsi_shmem())
return; return;
/* update color of the link LEDs */ if (libwr_tmo_expired(&update_link_leds_tmo)) {
update_link_leds(); /* update color of the link LEDs */
update_link_leds();
}
/* update LEDs of synced ports */ if (libwr_tmo_expired(&update_sync_leds_tmo)) {
update_sync_leds(); /* update LEDs of synced ports */
update_sync_leds();
}
} }
int hal_port_enable_tracking(const char *port_name) int hal_port_enable_tracking(const char *port_name)
...@@ -889,7 +907,7 @@ static void update_sync_leds(void) ...@@ -889,7 +907,7 @@ static void update_sync_leds(void)
&& state_up(ports[i].state) && state_up(ports[i].state)
&& !strcmp(ppsi_servo_local.if_name, ports[i].name)) { && !strcmp(ppsi_servo_local.if_name, ports[i].name)) {
if (update_count == ppsi_servo_local.update_count) { if (update_count == ppsi_servo_local.update_count) {
if (since_last_servo_update < 10) if (since_last_servo_update < 7)
since_last_servo_update++; since_last_servo_update++;
} else { } else {
since_last_servo_update = 0; since_last_servo_update = 0;
...@@ -902,7 +920,7 @@ static void update_sync_leds(void) ...@@ -902,7 +920,7 @@ static void update_sync_leds(void)
*/ */
if (ports[i].mode == HEXP_PORT_MODE_WR_SLAVE if (ports[i].mode == HEXP_PORT_MODE_WR_SLAVE
&& ppsi_servo_local.state == WR_TRACK_PHASE && ppsi_servo_local.state == WR_TRACK_PHASE
&& since_last_servo_update < 10 && since_last_servo_update < 7
) { ) {
set_led_synced(i, 1); set_led_synced(i, 1);
} else { } else {
......
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