Commit 1b6788cb authored by Adam Wujek's avatar Adam Wujek 💬

userspace/wrsw_hal: add locking shmem on write

Lock HAL's shmem on write to let a reader know about potential inconsistent
data

List below indicates which functions requires a lock (marked as "UPDATE").
minipc:
--halexp_lock_cmd:
  --hal_port_enable_tracking - not
  --hal_port_start_lock - UPDATE
  --hal_port_check_lock - not
--halexp_pps_cmd
  --rts_adjust_phase - not
  --shw_pps_gen_adjust - not
  --shw_pps_gen_busy - not
  --hal_port_pshifter_busy - not
  --shw_pps_gen_enable_output - not

hal_port_update_all:
--poll_rts_state - not
--hal_port_poll_sfp:
  --shw_sfp_module_scan - not
  --hal_port_insert_sfp - UPDATE
  --hal_port_remove_sfp - UPDATE
--hal_port_fsm - UPDATE
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent d8a817b8
......@@ -16,6 +16,7 @@
#include <libwr/shw_io.h>
#include <libwr/sfp_lib.h>
#include <libwr/config.h>
#include <libwr/shmem.h>
#include <libwr/hal_shmem.h>
#include <libwr/util.h>
......@@ -31,6 +32,7 @@ static char *logfilename;
static char *dotconfigname = "/wr/etc/dot-config";
struct hal_shmem_header *hal_shmem;
struct wrs_shm_head *hal_shmem_hdr;
/* Adds a function to be called during the HAL shutdown. */
int hal_add_cleanup_callback(hal_cleanup_callback_t cb)
......@@ -222,7 +224,7 @@ static void hal_parse_cmdline(int argc, char *argv[])
int main(int argc, char *argv[])
{
uint64_t t1, t2;
struct hal_temp_sensors temp_sensors; /* local copy of temperatures */
wrs_msg_init(argc, argv);
/* Print HAL's version */
......@@ -264,8 +266,13 @@ int main(int argc, char *argv[])
continue;
hal_port_update_all();
/* update fans and temperatures in shmem */
shw_update_fans(&hal_shmem->temp);
/* Update fans and get temperatures values. Don't write
* temperatures directly to the shmem to reduce the critical
* section of shmem */
shw_update_fans(&temp_sensors);
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_BEGIN);
memcpy(&hal_shmem->temp, &temp_sensors, sizeof(temp_sensors));
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
t1 = t2;
}
......
......@@ -34,6 +34,7 @@
#define SFP_POLL_INTERVAL 1000 /* ms */
extern struct hal_shmem_header *hal_shmem;
extern struct wrs_shm_head *hal_shmem_hdr;
/* Port table: the only item which is not "hal_port_*", as it's much used */
static struct hal_port_state *ports;
......@@ -210,8 +211,6 @@ static int hal_port_init(int index)
int hal_port_init_shmem(char *logfilename)
{
int index;
struct wrs_shm_head *hal_shmem_hdr;
pr_info("Initializing switch ports...\n");
/* default timeouts */
......@@ -608,12 +607,18 @@ void hal_port_update_all()
{
int i;
/* poll_rts_state does not write to shmem */
poll_rts_state();
/* lock shmem */
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_BEGIN);
hal_port_poll_sfp();
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use)
hal_port_fsm(&ports[i]);
/* unlock shmem */
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
}
int hal_port_enable_tracking(const char *port_name)
......@@ -641,8 +646,11 @@ int hal_port_start_lock(const char *port_name, int priority)
if (p->state != HAL_PORT_STATE_UP)
return -1;
/* lock shmem */
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_BEGIN);
/* fixme: check the main FSM state before */
p->state = HAL_PORT_STATE_LOCKING;
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
pr_info("Locking to port: %s\n", port_name);
......
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