Commit 710be885 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: define cache timeouts and improve caching timeout

Try to solve problem when cascade of caches has to be called.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 176f16a7
......@@ -9,9 +9,18 @@ static struct pickinfo wrsOSStatus_pickinfo[] = {
struct wrsOSStatus_s wrsOSStatus_s;
int wrsOSStatus_data_fill(void)
time_t wrsOSStatus_data_fill(void)
{
wrsTemperature_data_fill();
static time_t time_update; /* time of last update */
time_t time_temp; /* time when temperature data was updated */
time_temp = wrsTemperature_data_fill();
if (time_temp <= time_update) {
/* cache not updated, return last update time */
return time_update;
}
time_update = time(NULL);
memset(&wrsOSStatus_s, 0, sizeof(wrsOSStatus_s));
/* wrsTemperatureWarning */
......@@ -35,8 +44,8 @@ int wrsOSStatus_data_fill(void)
|| (wrsTemperature_s.temp_psr > wrsTemperature_s.temp_psr_thold));
}
/* there was an update, return 0 */
return 0;
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRS_OID, 6, 3
......
......@@ -11,7 +11,7 @@ struct wrsOSStatus_s {
};
extern struct wrsOSStatus_s wrsOSStatus_s;
int wrsOSStatus_data_fill(void);
time_t wrsOSStatus_data_fill(void);
void init_wrsOSStatus(void);
#endif /* WRS_WRS_OSSTATUS_H */
......@@ -21,6 +21,8 @@
extern struct wrs_shm_head *ppsi_head;
extern struct wr_servo_state_t *ppsi_servo;
#define WRSPTPDATA_CACHE_TIMEOUT 5
/* Our data: globals */
static struct wrsPtpData_s {
ClockIdentity gm_id; /* FIXME: not implemented */
......@@ -74,18 +76,20 @@ static int32_t int_saturate(int64_t value)
return value;
}
int wrsPtpData_data_fill(void)
time_t wrsPtpData_data_fill(void)
{
unsigned ii;
unsigned retries = 0;
static time_t t0, t1;
static time_t time_update;
time_t time_cur;
t1 = time(NULL);
if (t0 && t1 - t0 < 5) {/* TODO: timeout constatnt */
/* cache not updated */
return 1;
time_cur = time(NULL);
if (time_update
&& time_cur - time_update < WRSPTPDATA_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
return time_update;
}
t0 = t1;
time_update = time_cur;
memset(&wrsPtpData_s, 0, sizeof(wrsPtpData_s));
while (1) {
......@@ -127,8 +131,8 @@ int wrsPtpData_data_fill(void)
break; /* consistent read */
usleep(1000);
}
/* there was an update, return 0 */
return 0;
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRS_OID, 6, 1
......
......@@ -14,18 +14,20 @@ static struct pickinfo wrsTemperature_pickinfo[] = {
struct wrsTemperature_s wrsTemperature_s;
int wrsTemperature_data_fill(void)
time_t wrsTemperature_data_fill(void)
{
unsigned ii;
unsigned retries = 0;
static time_t t0, t1;
static time_t time_update;
time_t time_cur;
t1 = time(NULL);
if (t0 && t1 - t0 < 5) {/* TODO: timeout constatnt */
/* cache not updated */
return 1;
time_cur = time(NULL);
if (time_update
&& time_cur - time_update < WRSTEMPERATURE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
return time_update;
}
t0 = t1;
time_update = time_cur;
memset(&wrsTemperature_s, 0, sizeof(wrsTemperature_s));
while (1) {
......@@ -50,8 +52,8 @@ int wrsTemperature_data_fill(void)
break; /* consistent read */
usleep(1000);
}
/* there was an update, return 0 */
return 0;
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRS_OID, 6, 2
......
#ifndef WRS_WRS_TEMPERATURE_H
#define WRS_WRS_TEMPERATURE_H
#define WRSTEMPERATURE_CACHE_TIMEOUT 5
struct wrsTemperature_s {
int temp_fpga; /* FPGA temperature */
int temp_pll; /* PLL temperature */
......@@ -13,7 +15,7 @@ struct wrsTemperature_s {
};
extern struct wrsTemperature_s wrsTemperature_s;
int wrsTemperature_data_fill(void);
time_t wrsTemperature_data_fill(void);
void init_wrsTemperature(void);
#endif /* WRS_WRS_TEMPERATURE_H */
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