Commit 4eb61871 authored by Adam Wujek's avatar Adam Wujek 💬

userspace: fix waiting for lock in shmem

Change waiting for shm lock. Until now, after read attempt there was
usleep/sleep then check if data was read correctly. Now wait in sleep/usleep
only on not consistent data read.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 1d21d757
......@@ -230,7 +230,7 @@ static void wrs_ppsi_get_per_port(void)
/* read data, with the sequential lock to have all data consistent */
struct hal_port_state *port_state;
memset(wrs_p_array, 0, sizeof(wrs_p_array));
do {
while (1) {
ii = wrs_shm_seqbegin(hal_head);
for (i = 0; i < hal_nports_local; ++i) {
/* Assume that number of ports does not change between
......@@ -261,7 +261,10 @@ static void wrs_ppsi_get_per_port(void)
__func__);
retries = 0;
}
} while (wrs_shm_seqretry(hal_head, ii));
if (!wrs_shm_seqretry(hal_head, ii))
break; /* consistent read */
usleep(1000);
}
}
......
......@@ -170,15 +170,17 @@ int read_vlans(void)
if (!vlan_tab_shm)
return -2;
/* read data, with the sequential lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(rtu_port_shmem);
memcpy(&vlan_tab_local, vlan_tab_shm,
NUM_VLANS * sizeof(*vlan_tab_shm));
retries++;
if (retries > 100)
return -1;
if (!wrs_shm_seqretry(rtu_port_shmem, ii))
break; /* consistent read */
usleep(1000);
} while (wrs_shm_seqretry(rtu_port_shmem, ii));
}
return 0;
}
......@@ -198,15 +200,17 @@ int read_htab(int *read_entries)
return -2;
/* Read data, with the sequential lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(rtu_port_shmem);
memcpy(&rtu_htab_local, htab_shm,
RTU_BUCKETS * HTAB_ENTRIES * sizeof(*htab_shm));
retries++;
if (retries > 100)
return -1;
if (!wrs_shm_seqretry(rtu_port_shmem, ii))
break; /* consistent read */
usleep(1000);
} while (wrs_shm_seqretry(rtu_port_shmem, ii));
}
/* Convert hash table to ordered table. Table will be qsorted later,
* no need to qsort entire table */
......
......@@ -32,15 +32,17 @@ int read_ports(void){
unsigned retries = 0;
/* read data, with the sequential lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(hal_head);
memcpy(hal_ports_local_copy, hal_ports,
hal_nports_local*sizeof(struct hal_port_state));
retries++;
if (retries > 100)
return -1;
if (!wrs_shm_seqretry(hal_head, ii))
break; /* consistent read */
usleep(1000);
} while (wrs_shm_seqretry(hal_head, ii));
}
return 0;
}
......
......@@ -433,7 +433,7 @@ static void list_rtu_vlans(void)
static struct rtu_vlan_table_entry vlan_tab_local[NUM_VLANS];
/* read data, with the sequential lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(rtu_port_shmem);
memcpy(&vlan_tab_local, vlan_tab_shm,
NUM_VLANS * sizeof(*vlan_tab_shm));
......@@ -444,8 +444,10 @@ static void list_rtu_vlans(void)
prgname);
break; /* use inconsistent data */
}
if (!wrs_shm_seqretry(rtu_port_shmem, ii))
break; /* consistent read */
usleep(1000);
} while (wrs_shm_seqretry(rtu_port_shmem, ii));
}
printf("# VID FID MASK DROP PRIO PRIO_OVERRIDE\n");
printf("#----------------------------------------------------------\n");
......@@ -608,7 +610,7 @@ static int rtu_find_vlan(struct rtu_vlan_table_entry *rtu_vlan_entry, int vid,
/* copy data no mater if it will be used later, with the sequential
* lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(rtu_port_shmem);
memcpy(rtu_vlan_entry, &vlan_tab_shm[vid],
sizeof(*rtu_vlan_entry));
......@@ -619,8 +621,10 @@ static int rtu_find_vlan(struct rtu_vlan_table_entry *rtu_vlan_entry, int vid,
"Use inconsistent\n", prgname);
break; /* use inconsistent data */
}
if (!wrs_shm_seqretry(rtu_port_shmem, ii))
break; /* consistent read */
usleep(1000);
} while (wrs_shm_seqretry(rtu_port_shmem, ii));
}
/* Ignore entires that are not active */
if ((rtu_vlan_entry->drop != 0)
......
......@@ -67,14 +67,17 @@ int read_ports(void){
unsigned retries = 0;
/* read data, with the sequential lock to have all data consistent */
do {
while (1) {
ii = wrs_shm_seqbegin(hal_head);
memcpy(hal_ports_local_copy, hal_ports,
hal_nports_local*sizeof(struct hal_port_state));
retries++;
if (retries > 100)
return -1;
} while (wrs_shm_seqretry(hal_head, ii));
if (!wrs_shm_seqretry(hal_head, ii))
break; /* consistent read */
usleep(1000);
}
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