I'm trying to learn, want to ask few questions
I suspect that this approach to a rwlock is faster when lots of threads > try to take the read lock at once, because it should avoid cross-core > contention on cache lines. For avoiding the contention, is that only because each thread will have its own lock or more precisely "fat_rwlock_perthread" which is aligned to cache line? +void > +fat_rwlock_destroy(struct fat_rwlock *rwlock) > +{ > + struct fat_rwlock_perthread *perthread, *next; > + > + ovs_mutex_lock(&mutex); > + LIST_FOR_EACH_SAFE (perthread, next, list_node, &rwlock->threads) { > + list_remove(&perthread->list_node); > + hmap_remove(&perthread->table->perthreads, &perthread->hmap_node); > + ovs_mutex_destroy(&perthread->mutex); > + free(perthread->base); > + } > + ovs_mutex_unlock(&mutex); > +} > + > +static struct fat_rwlock_perthread * > +fat_rwlock_get_perthread__(struct fat_rwlock *rwlock) > + OVS_NO_THREAD_SAFETY_ANALYSIS > +{ > + struct fat_rwlock_perthread_table *table; > + struct fat_rwlock_perthread *perthread; > + void *base; > + > + table = pthread_getspecific(perthread_table_key); > + if (!table) { > + table = xmalloc(sizeof *table); > + hmap_init(&table->perthreads); > + xpthread_setspecific(perthread_table_key, table); > + } > + > + HMAP_FOR_EACH_WITH_HASH (perthread, hmap_node, rwlock->id, > + &table->perthreads) { > + return perthread; > + } > + > + ovs_mutex_lock(&mutex); > + fat_rwlock_lockall__(rwlock); > + > + base = xmalloc(sizeof *perthread + CACHE_LINE_SIZE - 1); > + perthread = (void *) ROUND_UP((uintptr_t) base, CACHE_LINE_SIZE); > + > > * + perthread = xmalloc(sizeof *perthread);* + perthread->base = > base; > + perthread->rwlock = rwlock; > + list_push_back(&rwlock->threads, &perthread->list_node); > + perthread->table = table; > + hmap_insert(&table->perthreads, &perthread->hmap_node, rwlock->id); > + ovs_mutex_init(&perthread->mutex); > + ovs_mutex_lock(&perthread->mutex); > + perthread->depth = 0; > Here, you want to align the perthread to cache line size, right? What is the meaning of this second "perthread = xmalloc(sizeof *perthread);" ?
_______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev