summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2023-07-10 14:13:50 +0300
committerGitHub <noreply@github.com>2023-07-10 14:13:50 +0300
commitb12edb1208554cdbb93fa3d4e9570bf4a9879e0f (patch)
tree3c257a4a7077a24e7c99478c3a7158540f4465c2 /health
parenteb6f1de7c6f7b626cb2ec333697b63034115914b (diff)
Use spinlock in host and chart (#15328)
* Switch alarm log lock to spinlock * Switch the alerts lock in the chart structure to spinlock * Proper lock usage
Diffstat (limited to 'health')
-rw-r--r--health/health.c14
-rw-r--r--health/health_log.c12
2 files changed, 13 insertions, 13 deletions
diff --git a/health/health.c b/health/health.c
index 3a206afcc9..72f2660712 100644
--- a/health/health.c
+++ b/health/health.c
@@ -346,13 +346,13 @@ static void health_reload_host(RRDHOST *host) {
rrdcalctemplate_delete_all(host);
// invalidate all previous entries in the alarm log
- netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_lock(&host->health_log.spinlock);
ALARM_ENTRY *t;
for(t = host->health_log.alarms ; t ; t = t->next) {
if(t->new_status != RRDCALC_STATUS_REMOVED)
t->flags |= HEALTH_ENTRY_FLAG_UPDATED;
}
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_unlock(&host->health_log.spinlock);
// reset all thresholds to all charts
RRDSET *st;
@@ -632,7 +632,7 @@ static inline void health_alarm_log_process(RRDHOST *host) {
uint32_t first_waiting = (host->health_log.alarms)?host->health_log.alarms->unique_id:0;
time_t now = now_realtime_sec();
- netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_lock(&host->health_log.spinlock);
ALARM_ENTRY *ae;
for(ae = host->health_log.alarms; ae && ae->unique_id >= host->health_last_processed_id; ae = ae->next) {
@@ -648,13 +648,13 @@ static inline void health_alarm_log_process(RRDHOST *host) {
}
}
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_unlock(&host->health_log.spinlock);
// remember this for the next iteration
host->health_last_processed_id = first_waiting;
//delete those that are updated, no in progress execution, and is not repeating
- netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_lock(&host->health_log.spinlock);
ALARM_ENTRY *prev = NULL, *next = NULL;
for(ae = host->health_log.alarms; ae ; ae = next) {
@@ -686,7 +686,7 @@ static inline void health_alarm_log_process(RRDHOST *host) {
prev = ae;
}
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_unlock(&host->health_log.spinlock);
}
static inline int rrdcalc_isrunnable(RRDCALC *rc, time_t now, time_t *next_run) {
@@ -815,7 +815,7 @@ static void initialize_health(RRDHOST *host)
conf_enabled_alarms = simple_pattern_create(config_get(CONFIG_SECTION_HEALTH, "enabled alarms", "*"), NULL,
SIMPLE_PATTERN_EXACT, true);
- netdata_rwlock_init(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_init(&host->health_log.spinlock);
char filename[FILENAME_MAX + 1];
diff --git a/health/health_log.c b/health/health_log.c
index fcc224349c..069f571dda 100644
--- a/health/health_log.c
+++ b/health/health_log.c
@@ -94,14 +94,14 @@ inline void health_alarm_log_add_entry(
__atomic_add_fetch(&host->health_transitions, 1, __ATOMIC_RELAXED);
// link it
- netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_lock(&host->health_log.spinlock);
ae->next = host->health_log.alarms;
host->health_log.alarms = ae;
host->health_log.count++;
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_unlock(&host->health_log.spinlock);
// match previous alarms
- netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_lock(&host->health_log.spinlock);
ALARM_ENTRY *t;
for(t = host->health_log.alarms ; t ; t = t->next) {
if(t != ae && t->alarm_id == ae->alarm_id) {
@@ -121,7 +121,7 @@ inline void health_alarm_log_add_entry(
break;
}
}
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_read_unlock(&host->health_log.spinlock);
health_alarm_log_save(host, ae);
}
@@ -145,7 +145,7 @@ inline void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae) {
}
inline void health_alarm_log_free(RRDHOST *host) {
- netdata_rwlock_wrlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_lock(&host->health_log.spinlock);
ALARM_ENTRY *ae;
while((ae = host->health_log.alarms)) {
@@ -153,5 +153,5 @@ inline void health_alarm_log_free(RRDHOST *host) {
health_alarm_log_free_one_nochecks_nounlink(ae);
}
- netdata_rwlock_unlock(&host->health_log.alarm_log_rwlock);
+ rw_spinlock_write_unlock(&host->health_log.spinlock);
}