Commit 08bc1684 authored by Adam Wujek's avatar Adam Wujek

arch-wrs: update files copied from the wr-switch-sw

update:
include/libwr/sfp_lib.h
include/libwr/util.h
shmem.c
util.c
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 531b5134
......@@ -3,9 +3,9 @@
/* note each led contains green and orange part */
#define SFP_LED_WRMODE_SLAVE (1) /* green */
#define SFP_LED_WRMODE_NON_WR (2) /* orange */
#define SFP_LED_WRMODE_OTHER (2) /* orange */
#define SFP_LED_WRMODE_MASTER (3) /* yellow */
#define SFP_LED_WRMODE_OFF (3) /* to off entire WRMODE LED */
#define SFP_LED_WRMODE_OFF (4) /* to off entire WRMODE LED */
#define SFP_LED_WRMODE1 (1 << 0)
#define SFP_LED_WRMODE2 (1 << 1)
#define SFP_LED_SYNCED (1 << 2)
......
......@@ -16,7 +16,7 @@
void shw_udelay_init(void);
void shw_udelay(uint32_t microseconds);
/* get monotonic number of useconds */
uint64_t get_monotonic_tics(void);
uint64_t get_monotonic_us(void);
/* get monotonic number of seconds */
time_t get_monotonic_sec(void);
......
......@@ -80,7 +80,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
if (!(flags & wrs_shm_locked))
return map;
tv1 = get_monotonic_tics();
tv1 = get_monotonic_us();
while (1) {
/* Releasing does not mean initial data is in place! */
/* Read data with wrs_shm_seqbegin and
......@@ -89,7 +89,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
return map;
usleep(10 * 1000);
tv2 = get_monotonic_tics();
tv2 = get_monotonic_us();
if (((tv2 - tv1) / 1000) < SHM_LOCK_TIMEOUT_MS)
continue;
......
......@@ -13,11 +13,36 @@ void shw_udelay_init(void)
volatile int i;
int j, cur, min = 0;
uint64_t tv1, tv2;
/*
* The kernel's scheduler is triggered 1000 times a second, to avoid
* a problem with a context switching, one iteration of loop with "j"
* should be shorter that a half of a scheduler's period.
* Based on the previous calculations that one iteration is about
* 5 CPU instructions (comment at the end of this function, our loop
* shall be shorter than:
* 197000000 / (5 * 1000 * 2) = 19 700
* Before it was 100*1000.
*
* However, at the system call triggered by get_monotonic_us() there
* is a context switch. If there are more processes waiting for the CPU
* (like during the boot, when few daemons are spawned at the same
* time) computations in this function can be underestimated by a
* factor 2-3 (experimental value).
*/
loops_per_msec = 39400;
return;
/*
* If we change the CPU this code can be used to estimate
* loops_per_msec, but should not be run avery time.
*/
for (j = 0; j < 10; j++) {
tv1 = get_monotonic_tics();
tv1 = get_monotonic_us();
for (i = 0; i < 100*1000; i++)
;
tv2 = get_monotonic_tics();
tv2 = get_monotonic_us();
cur = tv2 - tv1;
/* keep minimum time, assuming we were scheduled-off less */
if (!min || cur < min)
......@@ -27,6 +52,7 @@ void shw_udelay_init(void)
if (0)
printf("loops per msec %i\n", loops_per_msec);
/*
* I get 39400 more or less; it makes sense at 197 bogomips.
* The loop is 6 instructions with 3 (cached) memory accesses
......@@ -53,7 +79,7 @@ void shw_udelay(uint32_t microseconds)
}
/* get monotonic number of useconds */
uint64_t get_monotonic_tics(void)
uint64_t get_monotonic_us(void)
{
struct timespec tv;
clock_gettime(CLOCK_MONOTONIC, &tv);
......
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