Move thread related members of DCB into a substructure

The `thread` structure of a DCB now contains all the members that relate
to thread ownership of the DCB.
This commit is contained in:
Markus Makela
2016-11-23 09:03:50 +02:00
parent 2efa862944
commit 43f248927e
4 changed files with 33 additions and 30 deletions

View File

@ -225,7 +225,6 @@ typedef struct dcb
DCBEVENTQ evq; /**< The event queue for this DCB */ DCBEVENTQ evq; /**< The event queue for this DCB */
int fd; /**< The descriptor */ int fd; /**< The descriptor */
dcb_state_t state; /**< Current descriptor state */ dcb_state_t state; /**< Current descriptor state */
int owner; /**< Owning thread */
SSL_STATE ssl_state; /**< Current state of SSL if in use */ SSL_STATE ssl_state; /**< Current state of SSL if in use */
int flags; /**< DCB flags */ int flags; /**< DCB flags */
char *remote; /**< Address of remote end */ char *remote; /**< Address of remote end */
@ -276,8 +275,12 @@ typedef struct dcb
bool ssl_write_want_write; /*< Flag */ bool ssl_write_want_write; /*< Flag */
int dcb_port; /**< port of target server */ int dcb_port; /**< port of target server */
bool was_persistent; /**< Whether this DCB was in the persistent pool */ bool was_persistent; /**< Whether this DCB was in the persistent pool */
struct dcb *thr_next; /**< Next DCB in owning thread's list */ struct
struct dcb *thr_tail; /**< Last DCB in owning thread's list */ {
int id; /**< The owning thread's ID */
struct dcb *next; /**< Next DCB in owning thread's list */
struct dcb *tail; /**< Last DCB in owning thread's list */
} thread;
skygw_chk_t dcb_chk_tail; skygw_chk_t dcb_chk_tail;
} DCB; } DCB;
@ -288,7 +291,7 @@ typedef struct dcb
.cb_lock = SPINLOCK_INIT, .pollinlock = SPINLOCK_INIT, \ .cb_lock = SPINLOCK_INIT, .pollinlock = SPINLOCK_INIT, \
.fd = DCBFD_CLOSED, .stats = DCBSTATS_INIT, .ssl_state = SSL_HANDSHAKE_UNKNOWN, \ .fd = DCBFD_CLOSED, .stats = DCBSTATS_INIT, .ssl_state = SSL_HANDSHAKE_UNKNOWN, \
.state = DCB_STATE_ALLOC, .polloutlock = SPINLOCK_INIT, .dcb_chk_tail = CHK_NUM_DCB, \ .state = DCB_STATE_ALLOC, .polloutlock = SPINLOCK_INIT, .dcb_chk_tail = CHK_NUM_DCB, \
.authenticator_data = NULL, .thr_next = NULL, .thr_tail = NULL} .authenticator_data = NULL, .thread = {0}}
/** /**
* The DCB usage filer used for returning DCB's in use for a certain reason * The DCB usage filer used for returning DCB's in use for a certain reason

View File

@ -1660,7 +1660,7 @@ dcb_close(DCB *dcb)
/*< /*<
* Add closing dcb to the top of the list, setting zombie marker * Add closing dcb to the top of the list, setting zombie marker
*/ */
int owner = dcb->owner; int owner = dcb->thread.id;
dcb->dcb_is_zombie = true; dcb->dcb_is_zombie = true;
dcb->memdata.next = zombies[owner]; dcb->memdata.next = zombies[owner];
zombies[owner] = dcb; zombies[owner] = dcb;
@ -3417,20 +3417,20 @@ void dcb_append_readqueue(DCB *dcb, GWBUF *buffer)
void dcb_add_to_list(DCB *dcb) void dcb_add_to_list(DCB *dcb)
{ {
spinlock_acquire(&all_dcbs_lock[dcb->owner]); spinlock_acquire(&all_dcbs_lock[dcb->thread.id]);
if (all_dcbs[dcb->owner] == NULL) if (all_dcbs[dcb->thread.id] == NULL)
{ {
all_dcbs[dcb->owner] = dcb; all_dcbs[dcb->thread.id] = dcb;
all_dcbs[dcb->owner]->thr_tail = dcb; all_dcbs[dcb->thread.id]->thread.tail = dcb;
} }
else else
{ {
all_dcbs[dcb->owner]->thr_tail->thr_next = dcb; all_dcbs[dcb->thread.id]->thread.tail->thread.next = dcb;
all_dcbs[dcb->owner]->thr_tail = dcb; all_dcbs[dcb->thread.id]->thread.tail = dcb;
} }
spinlock_release(&all_dcbs_lock[dcb->owner]); spinlock_release(&all_dcbs_lock[dcb->thread.id]);
} }
/** /**
@ -3440,36 +3440,36 @@ void dcb_add_to_list(DCB *dcb)
*/ */
static void dcb_remove_from_list(DCB *dcb) static void dcb_remove_from_list(DCB *dcb)
{ {
spinlock_acquire(&all_dcbs_lock[dcb->owner]); spinlock_acquire(&all_dcbs_lock[dcb->thread.id]);
if (dcb == all_dcbs[dcb->owner]) if (dcb == all_dcbs[dcb->thread.id])
{ {
DCB *tail = all_dcbs[dcb->owner]->thr_tail; DCB *tail = all_dcbs[dcb->thread.id]->thread.tail;
all_dcbs[dcb->owner] = all_dcbs[dcb->owner]->thr_next; all_dcbs[dcb->thread.id] = all_dcbs[dcb->thread.id]->thread.next;
all_dcbs[dcb->owner]->thr_tail = tail; all_dcbs[dcb->thread.id]->thread.tail = tail;
} }
else else
{ {
DCB *current = all_dcbs[dcb->owner]->thr_next; DCB *current = all_dcbs[dcb->thread.id]->thread.next;
DCB *prev = all_dcbs[dcb->owner]; DCB *prev = all_dcbs[dcb->thread.id];
while (current) while (current)
{ {
if (current == dcb) if (current == dcb)
{ {
if (current == all_dcbs[dcb->owner]->thr_tail) if (current == all_dcbs[dcb->thread.id]->thread.tail)
{ {
all_dcbs[dcb->owner]->thr_tail = prev; all_dcbs[dcb->thread.id]->thread.tail = prev;
} }
prev->thr_next = current->thr_next; prev->thread.next = current->thread.next;
break; break;
} }
prev = current; prev = current;
current = current->thr_next; current = current->thread.next;
} }
} }
spinlock_release(&all_dcbs_lock[dcb->owner]); spinlock_release(&all_dcbs_lock[dcb->thread.id]);
} }
/** /**

View File

@ -375,14 +375,14 @@ poll_add_dcb(DCB *dcb)
if (dcb->dcb_role == DCB_ROLE_BACKEND_HANDLER) if (dcb->dcb_role == DCB_ROLE_BACKEND_HANDLER)
{ {
owner = dcb->session->client_dcb->owner; owner = dcb->session->client_dcb->thread.id;
} }
else else
{ {
owner = (unsigned int)atomic_add(&next_epoll_fd, 1) % n_threads; owner = (unsigned int)atomic_add(&next_epoll_fd, 1) % n_threads;
} }
dcb->owner = owner; dcb->thread.id = owner;
spinlock_release(&dcb->dcb_initlock); spinlock_release(&dcb->dcb_initlock);
dcb_add_to_list(dcb); dcb_add_to_list(dcb);
@ -495,7 +495,7 @@ poll_remove_dcb(DCB *dcb)
} }
else else
{ {
rc = epoll_ctl(epoll_fd[dcb->owner], EPOLL_CTL_DEL, dcbfd, &ev); rc = epoll_ctl(epoll_fd[dcb->thread.id], EPOLL_CTL_DEL, dcbfd, &ev);
} }
/** /**
* The poll_resolve_error function will always * The poll_resolve_error function will always
@ -885,7 +885,7 @@ process_pollq(int thread_id, struct epoll_event *event)
unsigned long qtime; unsigned long qtime;
DCB *dcb = event->data.ptr; DCB *dcb = event->data.ptr;
ss_dassert(dcb->owner == thread_id || dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER); ss_dassert(dcb->thread.id == thread_id || dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER);
#if PROFILE_POLL #if PROFILE_POLL
memlog_log(plog, hkheartbeat - dcb->evq.inserted); memlog_log(plog, hkheartbeat - dcb->evq.inserted);
#endif #endif
@ -1490,7 +1490,7 @@ static void poll_add_event_to_dcb(DCB* dcb,
event->next = NULL; event->next = NULL;
event->tail = event; event->tail = event;
int thr = dcb->owner; int thr = dcb->thread.id;
/** It is possible that a housekeeper or a monitor thread inserts a fake /** It is possible that a housekeeper or a monitor thread inserts a fake
* event into the thread's event queue which is why the operation needs * event into the thread's event queue which is why the operation needs

View File

@ -290,7 +290,7 @@ session_link_dcb(SESSION *session, DCB *dcb)
atomic_add(&session->refcount, 1); atomic_add(&session->refcount, 1);
dcb->session = session; dcb->session = session;
/** Move this DCB under the same thread */ /** Move this DCB under the same thread */
dcb->owner = session->client_dcb->owner; dcb->thread.id = session->client_dcb->thread.id;
spinlock_release(&session->ses_lock); spinlock_release(&session->ses_lock);
return true; return true;
} }