Commit 14583c20 authored by Adam Wujek's avatar Adam Wujek 💬

arch-wrs: add locking on writes to ppsi shemem

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent d39a15b9
...@@ -58,7 +58,7 @@ struct minipc_ch *hal_ch; ...@@ -58,7 +58,7 @@ struct minipc_ch *hal_ch;
struct minipc_ch *ppsi_ch; struct minipc_ch *ppsi_ch;
struct hal_port_state *hal_ports; struct hal_port_state *hal_ports;
int hal_nports; int hal_nports;
struct wrs_shm_head *ppsi_head;
/* /*
* we need to call calloc, to reset all stuff that used to be static, * we need to call calloc, to reset all stuff that used to be static,
* but we'd better have a simple prototype, compatilble with wrs_shm_alloc() * but we'd better have a simple prototype, compatilble with wrs_shm_alloc()
...@@ -80,7 +80,7 @@ int main(int argc, char **argv) ...@@ -80,7 +80,7 @@ int main(int argc, char **argv)
unsigned long seed; unsigned long seed;
struct timex t; struct timex t;
int i, hal_retries; int i, hal_retries;
struct wrs_shm_head *hal_head, *ppsi_head; struct wrs_shm_head *hal_head;
struct hal_shmem_header *h; struct hal_shmem_header *h;
void *(*alloc_fn)(void *headptr, size_t size) = local_malloc; void *(*alloc_fn)(void *headptr, size_t size) = local_malloc;
...@@ -139,7 +139,8 @@ int main(int argc, char **argv) ...@@ -139,7 +139,8 @@ int main(int argc, char **argv)
} }
wrs_init_ipcserver(ppsi_ch); wrs_init_ipcserver(ppsi_ch);
ppsi_head = wrs_shm_get(wrs_shm_ptp, "ppsi", WRS_SHM_WRITE); ppsi_head = wrs_shm_get(wrs_shm_ptp, "ppsi",
WRS_SHM_WRITE | WRS_SHM_LOCKED);
if (!ppsi_head) { if (!ppsi_head) {
fprintf(stderr, "Fatal: could not create shmem: %s\n", fprintf(stderr, "Fatal: could not create shmem: %s\n",
strerror(errno)); strerror(errno));
...@@ -241,6 +242,10 @@ int main(int argc, char **argv) ...@@ -241,6 +242,10 @@ int main(int argc, char **argv)
seed = atoi(getenv("PPSI_DROP_SEED")); seed = atoi(getenv("PPSI_DROP_SEED"));
ppsi_drop_init(ppg, seed); ppsi_drop_init(ppg, seed);
/* release lock from wrs_shm_get */
if (BUILT_WITH_WHITERABBIT)
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END);
wrs_main_loop(ppg); wrs_main_loop(ppg);
return 0; /* never reached */ return 0; /* never reached */
} }
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "wr-api.h" #include "wr-api.h"
#include <libwr/shmem.h>
#define WR_SERVO_NONE 0 #define WR_SERVO_NONE 0
#define WR_SYNC_NSEC 1 #define WR_SYNC_NSEC 1
...@@ -26,6 +27,7 @@ static const char *servo_name[] = { ...@@ -26,6 +27,7 @@ static const char *servo_name[] = {
ptpdexp_sync_state_t cur_servo_state; /* Exported with mini-rpc */ ptpdexp_sync_state_t cur_servo_state; /* Exported with mini-rpc */
static int tracking_enabled = 1; /* FIXME: why? */ static int tracking_enabled = 1; /* FIXME: why? */
extern struct wrs_shm_head *ppsi_head;
void wr_servo_enable_tracking(int enable) void wr_servo_enable_tracking(int enable)
{ {
...@@ -149,7 +151,8 @@ int wr_servo_init(struct pp_instance *ppi) ...@@ -149,7 +151,8 @@ int wr_servo_init(struct pp_instance *ppi)
struct wr_dsport *wrp = WR_DSPOR(ppi); struct wr_dsport *wrp = WR_DSPOR(ppi);
struct wr_servo_state_t *s = struct wr_servo_state_t *s =
&((struct wr_data_t *)ppi->ext_data)->servo_state; &((struct wr_data_t *)ppi->ext_data)->servo_state;
/* shmem lock */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
/* Determine the alpha coefficient */ /* Determine the alpha coefficient */
if (wrp->ops->read_calib_data(ppi, 0, 0, if (wrp->ops->read_calib_data(ppi, 0, 0,
&s->fiber_fix_alpha, &s->clock_period_ps) != WR_HW_CALIB_OK) &s->fiber_fix_alpha, &s->clock_period_ps) != WR_HW_CALIB_OK)
...@@ -190,6 +193,9 @@ int wr_servo_init(struct pp_instance *ppi) ...@@ -190,6 +193,9 @@ int wr_servo_init(struct pp_instance *ppi)
s->update_count = 0; s->update_count = 0;
got_sync = 0; got_sync = 0;
/* shmem unlock */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END);
return 0; return 0;
} }
...@@ -257,6 +263,10 @@ int wr_servo_update(struct pp_instance *ppi) ...@@ -257,6 +263,10 @@ int wr_servo_update(struct pp_instance *ppi)
s->t3.correct, s->t4.correct); s->t3.correct, s->t4.correct);
return 0; return 0;
} }
/* shmem lock */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_BEGIN);
errcount = 0; errcount = 0;
cur_servo_state.update_count++; cur_servo_state.update_count++;
...@@ -411,5 +421,7 @@ int wr_servo_update(struct pp_instance *ppi) ...@@ -411,5 +421,7 @@ int wr_servo_update(struct pp_instance *ppi)
break; break;
} }
/* shmem unlock */
wrs_shm_write(ppsi_head, WRS_SHM_WRITE_END);
return 0; return 0;
} }
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