]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
- isc_task_create_bound - create a task bound to specific task queue
authorWitold Kręcicki <wpk@isc.org>
Wed, 21 Nov 2018 09:50:50 +0000 (09:50 +0000)
committerWitold Kręcicki <wpk@isc.org>
Wed, 21 Nov 2018 16:24:46 +0000 (16:24 +0000)
- bind resolver tasks to queues, hashed by bucket

lib/dns/resolver.c
lib/isc/include/isc/task.h
lib/isc/task.c

index d50148abb49dd3426b0c81f532509f77f13e36ee..de2e33de4e2ab82a94d1d1eb6d9d5f21f18d40bd 100644 (file)
@@ -4382,8 +4382,8 @@ fctx_shutdown(fetchctx_t *fctx) {
         */
        if (fctx->state != fetchstate_init) {
                cevent = &fctx->control_event;
-               isc_task_send(fctx->res->buckets[fctx->bucketnum].task,
-                             &cevent);
+               isc_task_sendto(fctx->res->buckets[fctx->bucketnum].task,
+                               &cevent, fctx->bucketnum);
        }
 }
 
@@ -9925,7 +9925,7 @@ dns_resolver_create(dns_view_t *view,
                if (result != ISC_R_SUCCESS)
                        goto cleanup_buckets;
                res->buckets[i].task = NULL;
-               result = isc_task_create(taskmgr, 0, &res->buckets[i].task);
+               result = isc_task_create_bound(taskmgr, 0, &res->buckets[i].task, i);
                if (result != ISC_R_SUCCESS) {
                        DESTROYLOCK(&res->buckets[i].lock);
                        goto cleanup_buckets;
index 4ee783aedc0718c49340017ff99b89af3e01aee6..b2d9c4838460b256481932db37056ac598bdd6d0 100644 (file)
@@ -136,6 +136,10 @@ struct isc_task {
 isc_result_t
 isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
                isc_task_t **taskp);
+
+isc_result_t
+isc_task_create_bound(isc_taskmgr_t *manager, unsigned int quantum,
+                     isc_task_t **taskp, int threadid);
 /*%<
  * Create a task.
  *
index c2d00feffd929cc96b6fa137d1997a5d989030ba..685b787c05b8738a423a62685a6442fec5aaf182 100644 (file)
@@ -104,6 +104,7 @@ struct isc__task {
        char                            name[16];
        void *                          tag;
        unsigned int                    threadid;
+       bool                            bound;
        /* Locked by task manager lock. */
        LINK(isc__task_t)               link;
        LINK(isc__task_t)               ready_link;
@@ -243,7 +244,14 @@ task_finished(isc__task_t *task) {
 
 isc_result_t
 isc_task_create(isc_taskmgr_t *manager0, unsigned int quantum,
-                isc_task_t **taskp)
+               isc_task_t **taskp)
+{
+       return (isc_task_create_bound(manager0, quantum, taskp, -1));
+}
+
+isc_result_t
+isc_task_create_bound(isc_taskmgr_t *manager0, unsigned int quantum,
+                     isc_task_t **taskp, int threadid)
 {
        isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
        isc__task_t *task;
@@ -258,9 +266,15 @@ isc_task_create(isc_taskmgr_t *manager0, unsigned int quantum,
                return (ISC_R_NOMEMORY);
        XTRACE("isc_task_create");
        task->manager = manager;
-       task->threadid = atomic_fetch_add_explicit(&manager->curq, 1,
-                                                  memory_order_relaxed)
-                                                  % manager->workers;
+       if (threadid == -1) {
+               task->bound = false;
+               task->threadid = atomic_fetch_add_explicit(&manager->curq, 1,
+                                                          memory_order_relaxed)
+                                                          % manager->workers;
+       } else {
+               task->bound = true;
+               task->threadid = threadid % manager->workers;
+       }
        result = isc_mutex_init(&task->lock);
        if (result != ISC_R_SUCCESS) {
                isc_mem_put(manager->mctx, task, sizeof(*task));
@@ -494,7 +508,9 @@ isc_task_sendto(isc_task_t *task0, isc_event_t **eventp, int c) {
        REQUIRE(VALID_TASK(task));
        XTRACE("isc_task_send");
 
-       if (c < 0) {
+       if (task->bound) {
+               c = task->threadid;
+       } else if (c < 0) {
                c = atomic_fetch_add_explicit(&task->manager->curq, 1,
                                              memory_order_relaxed);
        }
@@ -544,7 +560,9 @@ isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) {
        REQUIRE(VALID_TASK(task));
        XTRACE("isc_task_sendanddetach");
 
-       if (c < 0) {
+       if (task->bound) {
+               c = task->threadid;
+       } else if (c < 0) {
                c = atomic_fetch_add_explicit(&task->manager->curq, 1,
                                              memory_order_relaxed);
        }