Page MenuHomePhabricator
Paste P5317

0006-exp-thread-realtime.patch
ActivePublic

Authored by ema on Apr 24 2017, 8:52 AM.
Tags
None
Referenced Files
F7738589: 0006-exp-thread-realtime.patch
Apr 24 2017, 12:26 PM
F7736327: 0006-exp-thread-realtime.patch
Apr 24 2017, 8:52 AM
Subscribers
None
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c03570389..da9ba22aa 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -824,14 +824,15 @@ extern pthread_key_t witness_key;
void Lck__Lock(struct lock *lck, const char *p, int l);
void Lck__Unlock(struct lock *lck, const char *p, int l);
int Lck__Trylock(struct lock *lck, const char *p, int l);
-void Lck__New(struct lock *lck, struct VSC_C_lck *, const char *);
+void Lck__New(struct lock *lck, struct VSC_C_lck *, const char *, int protocol);
void Lck__Assert(const struct lock *lck, int held);
/* public interface: */
void Lck_Delete(struct lock *lck);
int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double);
-#define Lck_New(a, b) Lck__New(a, b, #b)
+#define Lck_New(a, b) Lck__New(a, b, #b, PTHREAD_PRIO_NONE)
+#define Lck_New_Inherit(a, b) Lck__New(a, b, #b, PTHREAD_PRIO_INHERIT)
#define Lck_Lock(a) Lck__Lock(a, __func__, __LINE__)
#define Lck_Unlock(a) Lck__Unlock(a, __func__, __LINE__)
#define Lck_Trylock(a) Lck__Trylock(a, __func__, __LINE__)
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 5c27d0741..2827ae3c5 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -33,6 +33,7 @@
#include "config.h"
#include <stdlib.h>
+#include <stdio.h>
#include "cache.h"
@@ -575,12 +576,23 @@ exp_thread(struct worker *wrk, void *priv)
struct objcore *oc;
double t = 0, tnext = 0;
struct exp_priv *ep;
+ struct sched_param param;
+ int s;
CAST_OBJ_NOTNULL(ep, priv, EXP_PRIV_MAGIC);
ep->wrk = wrk;
VSL_Setup(&ep->vsl, NULL, 0);
ep->heap = binheap_new(NULL, object_cmp, object_update);
AN(ep->heap);
+
+ // Pick a realtime policy scheduling (SCHED_FIFO) and bump prio
+ param.sched_priority = 1;
+ s = pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
+ if (s != 0) {
+ perror("pthread_getschedparam");
+ exit(EXIT_FAILURE);
+ }
+
while (1) {
Lck_Lock(&ep->mtx);
@@ -617,7 +629,8 @@ EXP_Init(void)
ALLOC_OBJ(ep, EXP_PRIV_MAGIC);
AN(ep);
- Lck_New(&ep->mtx, lck_exp);
+ Lck_New_Inherit(&ep->mtx, lck_exp);
+
AZ(pthread_cond_init(&ep->condvar, NULL));
VTAILQ_INIT(&ep->inbox);
AZ(pthread_rwlock_init(&ep->cb_rwl, NULL));
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 90190dcea..8078b3194 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -209,7 +209,7 @@ Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double when)
}
void
-Lck__New(struct lock *lck, struct VSC_C_lck *st, const char *w)
+Lck__New(struct lock *lck, struct VSC_C_lck *st, const char *w, int protocol)
{
struct ilck *ilck;
@@ -221,6 +221,10 @@ Lck__New(struct lock *lck, struct VSC_C_lck *st, const char *w)
ilck->w = w;
ilck->stat = st;
ilck->stat->creat++;
+
+ // PTHREAD_PRIO_NONE | PTHREAD_PRIO_INHERIT | PTHREAD_PRIO_PROTECT
+ pthread_mutexattr_setprotocol(&attr, protocol);
+
AZ(pthread_mutex_init(&ilck->mtx, &attr));
lck->priv = ilck;
}