Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177552848
D60957.1794699534.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D60957.1794699534.diff
View Options
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -516,6 +516,10 @@
/* Number rwlocks rdlocks held. */
int rdlock_count;
+ void *pshared_key;
+ void *pshared_val;
+ unsigned long pshared_gen;
+
/*
* Current locks bitmap for rtld. */
int rtld_bits;
diff --git a/lib/libthr/thread/thr_pshared.c b/lib/libthr/thread/thr_pshared.c
--- a/lib/libthr/thread/thr_pshared.c
+++ b/lib/libthr/thread/thr_pshared.c
@@ -47,9 +47,14 @@
static struct pshared_hash_head pshared_hash[HASH_SIZE];
#define PSHARED_KEY_HASH(key) (((unsigned long)(key) >> 8) % HASH_SIZE)
/* XXXKIB: lock could be split to per-hash chain, if appears contested */
-static struct urwlock pshared_lock = DEFAULT_URWLOCK;
+static struct urwlock pshared_lock __aligned(CACHE_LINE_SIZE) = DEFAULT_URWLOCK;
static int page_size;
+static struct {
+ unsigned long val;
+ char pad[CACHE_LINE_SIZE - sizeof(unsigned long)];
+} pshared_gen __aligned(CACHE_LINE_SIZE);
+
#define GC_INTERVAL_USEC 25000
static struct timeval pshared_gc_time = {0, 0};
bool __thr_pshared_destroy_imm_gc = false;
@@ -93,6 +98,30 @@
_thr_ast(curthread);
}
+static void
+pshared_gen_bump(void)
+{
+ atomic_add_long(&pshared_gen.val, 1);
+}
+
+static void *
+pshared_cache_lookup(struct pthread *curthread, void *key)
+{
+ if (curthread->pshared_key == key &&
+ curthread->pshared_gen == atomic_load_long(&pshared_gen.val))
+ return (curthread->pshared_val);
+ return (NULL);
+}
+
+static void
+pshared_cache_insert(struct pthread *curthread, void *key, void *val,
+ unsigned long gen)
+{
+ curthread->pshared_key = key;
+ curthread->pshared_val = val;
+ curthread->pshared_gen = gen;
+}
+
/*
* Among all processes sharing a lock only one executes
* pthread_lock_destroy(). Other processes still have the hash and
@@ -128,6 +157,7 @@
if (error == 0)
continue;
LIST_REMOVE(h, link);
+ pshared_gen_bump();
munmap(h->val, page_size);
free(h);
}
@@ -212,6 +242,7 @@
LIST_FOREACH(h, hd, link) {
if (h->key == key) {
LIST_REMOVE(h, link);
+ pshared_gen_bump();
val = h->val;
free(h);
return (val);
@@ -245,6 +276,7 @@
{
struct pthread *curthread;
void *res;
+ unsigned long gen;
int fd, ins_done;
curthread = _get_curthread();
@@ -252,11 +284,17 @@
pshared_destroy(curthread, key);
res = NULL;
} else {
+ res = pshared_cache_lookup(curthread, key);
+ if (res != NULL)
+ return (res);
pshared_rlock(curthread);
+ gen = pshared_gen.val;
res = pshared_lookup(key);
pshared_unlock(curthread);
- if (res != NULL)
+ if (res != NULL) {
+ pshared_cache_insert(curthread, key, res, gen);
return (res);
+ }
}
fd = _umtx_op(NULL, UMTX_OP_SHM, doalloc ? UMTX_SHM_CREAT :
UMTX_SHM_LOOKUP, key, NULL);
@@ -267,11 +305,14 @@
if (res == MAP_FAILED)
return (NULL);
pshared_wlock(curthread);
+ gen = pshared_gen.val;
ins_done = pshared_insert(key, &res);
pshared_unlock(curthread);
if (!ins_done) {
pshared_clean(key, res);
res = NULL;
+ } else {
+ pshared_cache_insert(curthread, key, res, gen);
}
return (res);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 14, 11:38 PM (3 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41734109
Default Alt Text
D60957.1794699534.diff (3 KB)
Attached To
Mode
D60957: libthr: Cache recent pshared_key
Attached
Detach File
Event Timeline