Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa2c7fe216 | ||
|
|
3ab9a4f6bd | ||
|
|
7de2f1d148 | ||
|
|
7b8ae0d09e | ||
|
|
56fc4397e0 | ||
|
|
1177316eed | ||
|
|
5bd1d29359 | ||
|
|
b241e3b2fc | ||
|
|
d151d09660 | ||
|
|
7e2b3d93f7 |
+2
-2
@@ -773,7 +773,7 @@ create_managers(void) {
|
||||
INSIST(named_g_cpus_detected > 0);
|
||||
|
||||
if (named_g_cpus == 0)
|
||||
named_g_cpus = named_g_cpus_detected;
|
||||
named_g_cpus = named_g_cpus_detected * 1.5;
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"found %u CPU%s, using %u worker thread%s",
|
||||
@@ -787,7 +787,7 @@ create_managers(void) {
|
||||
if (named_g_cpus_detected == 1)
|
||||
named_g_udpdisp = 1;
|
||||
else
|
||||
named_g_udpdisp = named_g_cpus_detected - 1;
|
||||
named_g_udpdisp = named_g_cpus_detected;
|
||||
}
|
||||
if (named_g_udpdisp > named_g_cpus)
|
||||
named_g_udpdisp = named_g_cpus;
|
||||
|
||||
+4
-2
@@ -2873,7 +2873,7 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
|
||||
dns_dispatch_t *disp;
|
||||
isc_socket_t *sock = NULL;
|
||||
int i = 0;
|
||||
|
||||
dup_socket = NULL;
|
||||
/*
|
||||
* dispatch_allocate() checks mgr for us.
|
||||
*/
|
||||
@@ -2950,7 +2950,9 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
|
||||
}
|
||||
goto kill_socket;
|
||||
}
|
||||
isc_task_setname(disp->task[i], "udpdispatch", disp);
|
||||
char n[32];
|
||||
sprintf(n, "UDPD-%d", i);
|
||||
isc_task_setname(disp->task[i], n, disp);
|
||||
}
|
||||
|
||||
disp->ctlevent = isc_event_allocate(mgr->mctx, disp,
|
||||
|
||||
@@ -208,6 +208,8 @@ isc_task_detach(isc_task_t **taskp);
|
||||
|
||||
void
|
||||
isc_task_send(isc_task_t *task, isc_event_t **eventp);
|
||||
void
|
||||
isc_task_sendto(isc_task_t *task, isc_event_t **eventp, int id);
|
||||
/*%<
|
||||
* Send '*event' to 'task'.
|
||||
*
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@
|
||||
*/
|
||||
#include "xoshiro128starstar.c"
|
||||
|
||||
static isc_once_t isc_random_once = ISC_ONCE_INIT;
|
||||
static thread_local isc_once_t isc_random_once = ISC_ONCE_INIT;
|
||||
|
||||
static void
|
||||
isc_random_initialize(void) {
|
||||
|
||||
+133
-79
@@ -19,7 +19,9 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <isc/atomic.h>
|
||||
#include <isc/app.h>
|
||||
#include <isc/condition.h>
|
||||
#include <isc/event.h>
|
||||
@@ -53,6 +55,7 @@
|
||||
* is expected to have a separate manager; no "worker threads" are shared by
|
||||
* the application threads.
|
||||
*/
|
||||
// #define ISC_TASK_TRACE
|
||||
#ifdef ISC_TASK_TRACE
|
||||
#define XTRACE(m) fprintf(stderr, "task %p thread %lu: %s\n", \
|
||||
task, isc_thread_self(), (m))
|
||||
@@ -104,6 +107,7 @@ struct isc__task {
|
||||
isc_time_t tnow;
|
||||
char name[16];
|
||||
void * tag;
|
||||
int c;
|
||||
/* Locked by task manager lock. */
|
||||
LINK(isc__task_t) link;
|
||||
LINK(isc__task_t) ready_link;
|
||||
@@ -126,19 +130,20 @@ struct isc__taskmgr {
|
||||
isc_taskmgr_t common;
|
||||
isc_mem_t * mctx;
|
||||
isc_mutex_t lock;
|
||||
isc_mutex_t *locks;
|
||||
unsigned int workers;
|
||||
isc_thread_t * threads;
|
||||
/* Locked by task manager lock. */
|
||||
unsigned int default_quantum;
|
||||
LIST(isc__task_t) tasks;
|
||||
isc__tasklist_t ready_tasks;
|
||||
isc__tasklist_t ready_priority_tasks;
|
||||
isc__tasklist_t *ready_tasks;
|
||||
isc__tasklist_t *ready_priority_tasks;
|
||||
isc_taskmgrmode_t mode;
|
||||
isc_condition_t work_available;
|
||||
isc_condition_t *work_available;
|
||||
isc_condition_t exclusive_granted;
|
||||
isc_condition_t paused;
|
||||
unsigned int tasks_running;
|
||||
unsigned int tasks_ready;
|
||||
int32_t tasks_running;
|
||||
int32_t tasks_ready;
|
||||
bool pause_requested;
|
||||
bool exclusive_requested;
|
||||
bool exiting;
|
||||
@@ -175,13 +180,13 @@ isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0);
|
||||
isc_result_t
|
||||
isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp);
|
||||
static inline bool
|
||||
empty_readyq(isc__taskmgr_t *manager);
|
||||
empty_readyq(isc__taskmgr_t *manager, int c);
|
||||
|
||||
static inline isc__task_t *
|
||||
pop_readyq(isc__taskmgr_t *manager);
|
||||
pop_readyq(isc__taskmgr_t *manager, int c);
|
||||
|
||||
static inline void
|
||||
push_readyq(isc__taskmgr_t *manager, isc__task_t *task);
|
||||
push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c);
|
||||
|
||||
/***
|
||||
*** Tasks.
|
||||
@@ -190,7 +195,6 @@ push_readyq(isc__taskmgr_t *manager, isc__task_t *task);
|
||||
static void
|
||||
task_finished(isc__task_t *task) {
|
||||
isc__taskmgr_t *manager = task->manager;
|
||||
|
||||
REQUIRE(EMPTY(task->events));
|
||||
REQUIRE(task->nevents == 0);
|
||||
REQUIRE(EMPTY(task->on_shutdown));
|
||||
@@ -201,6 +205,7 @@ task_finished(isc__task_t *task) {
|
||||
|
||||
LOCK(&manager->lock);
|
||||
UNLINK(manager->tasks, task, link);
|
||||
UNLOCK(&manager->lock);
|
||||
if (FINISHED(manager)) {
|
||||
/*
|
||||
* All tasks have completed and the
|
||||
@@ -208,10 +213,12 @@ task_finished(isc__task_t *task) {
|
||||
* any idle worker threads so they
|
||||
* can exit.
|
||||
*/
|
||||
BROADCAST(&manager->work_available);
|
||||
for (unsigned i=0; i<manager->workers; i++) {
|
||||
LOCK(&manager->locks[i]);
|
||||
BROADCAST(&manager->work_available[i]);
|
||||
UNLOCK(&manager->locks[i]);
|
||||
}
|
||||
}
|
||||
UNLOCK(&manager->lock);
|
||||
|
||||
DESTROYLOCK(&task->lock);
|
||||
task->common.impmagic = 0;
|
||||
task->common.magic = 0;
|
||||
@@ -235,6 +242,7 @@ isc_task_create(isc_taskmgr_t *manager0, unsigned int quantum,
|
||||
return (ISC_R_NOMEMORY);
|
||||
XTRACE("isc_task_create");
|
||||
task->manager = manager;
|
||||
task->c = -1;
|
||||
result = isc_mutex_init(&task->lock);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_mem_put(manager->mctx, task, sizeof(*task));
|
||||
@@ -351,12 +359,15 @@ task_ready(isc__task_t *task) {
|
||||
REQUIRE(task->state == task_state_ready);
|
||||
|
||||
XTRACE("task_ready");
|
||||
|
||||
LOCK(&manager->lock);
|
||||
push_readyq(manager, task);
|
||||
if (manager->mode == isc_taskmgrmode_normal || has_privilege)
|
||||
SIGNAL(&manager->work_available);
|
||||
UNLOCK(&manager->lock);
|
||||
task->c = sched_getcpu() % task->manager->workers;
|
||||
// printf("Pushing onto %d\n", task->c);
|
||||
LOCK(&manager->locks[task->c]);
|
||||
push_readyq(manager, task, task->c);
|
||||
if (manager->mode == isc_taskmgrmode_normal || has_privilege) {
|
||||
// printf("Broadcasting %d\n", task->c);
|
||||
BROADCAST(&manager->work_available[task->c]);
|
||||
}
|
||||
UNLOCK(&manager->locks[task->c]);
|
||||
}
|
||||
|
||||
static inline bool
|
||||
@@ -434,6 +445,7 @@ task_send(isc__task_t *task, isc_event_t **eventp) {
|
||||
if (task->state == task_state_idle) {
|
||||
was_idle = true;
|
||||
INSIST(EMPTY(task->events));
|
||||
task->c = sched_getcpu() % task->manager->workers;
|
||||
task->state = task_state_ready;
|
||||
}
|
||||
INSIST(task->state == task_state_ready ||
|
||||
@@ -485,6 +497,7 @@ isc_task_send(isc_task_t *task0, isc_event_t **eventp) {
|
||||
*/
|
||||
task_ready(task);
|
||||
}
|
||||
pthread_yield();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -507,7 +520,7 @@ isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) {
|
||||
idle1 = task_send(task, eventp);
|
||||
idle2 = task_detach(task);
|
||||
UNLOCK(&task->lock);
|
||||
|
||||
|
||||
/*
|
||||
* If idle1, then idle2 shouldn't be true as well since we're holding
|
||||
* the task lock, and thus the task cannot switch from ready back to
|
||||
@@ -517,7 +530,7 @@ isc_task_sendanddetach(isc_task_t **taskp, isc_event_t **eventp) {
|
||||
|
||||
if (idle1 || idle2)
|
||||
task_ready(task);
|
||||
|
||||
pthread_yield();
|
||||
*taskp = NULL;
|
||||
}
|
||||
|
||||
@@ -829,13 +842,13 @@ isc_task_getcurrenttimex(isc_task_t *task0, isc_time_t *t) {
|
||||
* Caller must hold the task manager lock.
|
||||
*/
|
||||
static inline bool
|
||||
empty_readyq(isc__taskmgr_t *manager) {
|
||||
empty_readyq(isc__taskmgr_t *manager, int c) {
|
||||
isc__tasklist_t queue;
|
||||
|
||||
if (manager->mode == isc_taskmgrmode_normal)
|
||||
queue = manager->ready_tasks;
|
||||
queue = manager->ready_tasks[c];
|
||||
else
|
||||
queue = manager->ready_priority_tasks;
|
||||
queue = manager->ready_priority_tasks[c];
|
||||
|
||||
return (EMPTY(queue));
|
||||
}
|
||||
@@ -849,18 +862,18 @@ empty_readyq(isc__taskmgr_t *manager) {
|
||||
* Caller must hold the task manager lock.
|
||||
*/
|
||||
static inline isc__task_t *
|
||||
pop_readyq(isc__taskmgr_t *manager) {
|
||||
pop_readyq(isc__taskmgr_t *manager, int c) {
|
||||
isc__task_t *task;
|
||||
|
||||
if (manager->mode == isc_taskmgrmode_normal)
|
||||
task = HEAD(manager->ready_tasks);
|
||||
task = HEAD(manager->ready_tasks[c]);
|
||||
else
|
||||
task = HEAD(manager->ready_priority_tasks);
|
||||
task = HEAD(manager->ready_priority_tasks[c]);
|
||||
|
||||
if (task != NULL) {
|
||||
DEQUEUE(manager->ready_tasks, task, ready_link);
|
||||
DEQUEUE(manager->ready_tasks[c], task, ready_link);
|
||||
if (ISC_LINK_LINKED(task, ready_priority_link))
|
||||
DEQUEUE(manager->ready_priority_tasks, task,
|
||||
DEQUEUE(manager->ready_priority_tasks[c], task,
|
||||
ready_priority_link);
|
||||
}
|
||||
|
||||
@@ -874,16 +887,16 @@ pop_readyq(isc__taskmgr_t *manager) {
|
||||
* Caller must hold the task manager lock.
|
||||
*/
|
||||
static inline void
|
||||
push_readyq(isc__taskmgr_t *manager, isc__task_t *task) {
|
||||
ENQUEUE(manager->ready_tasks, task, ready_link);
|
||||
push_readyq(isc__taskmgr_t *manager, isc__task_t *task, int c) {
|
||||
ENQUEUE(manager->ready_tasks[c], task, ready_link);
|
||||
if ((task->flags & TASK_F_PRIVILEGED) != 0)
|
||||
ENQUEUE(manager->ready_priority_tasks, task,
|
||||
ENQUEUE(manager->ready_priority_tasks[c], task,
|
||||
ready_priority_link);
|
||||
manager->tasks_ready++;
|
||||
isc_atomic_xadd(&manager->tasks_ready, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
dispatch(isc__taskmgr_t *manager) {
|
||||
dispatch(isc__taskmgr_t *manager, int c) {
|
||||
isc__task_t *task;
|
||||
|
||||
REQUIRE(VALID_MANAGER(manager));
|
||||
@@ -937,9 +950,7 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
* For N iterations of the loop, this code does N+1 locks and N+1
|
||||
* unlocks. The while expression is always protected by the lock.
|
||||
*/
|
||||
|
||||
LOCK(&manager->lock);
|
||||
|
||||
|
||||
while (!FINISHED(manager)) {
|
||||
/*
|
||||
* For reasons similar to those given in the comment in
|
||||
@@ -951,13 +962,16 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
* If a pause has been requested, don't do any work
|
||||
* until it's been released.
|
||||
*/
|
||||
while ((empty_readyq(manager) || manager->pause_requested ||
|
||||
LOCK(&manager->locks[c]);
|
||||
while ((empty_readyq(manager, c) || manager->pause_requested ||
|
||||
manager->exclusive_requested) && !FINISHED(manager))
|
||||
{
|
||||
XTHREADTRACE(isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_WAIT, "wait"));
|
||||
WAIT(&manager->work_available, &manager->lock);
|
||||
// printf("WAITING %d %d %d %d\n", c, empty_readyq(manager, c), manager->pause_requested, manager->exclusive_requested);
|
||||
WAIT(&manager->work_available[c], &manager->locks[c]);
|
||||
// printf("DONEWAITING %d %d %d %d\n", c, empty_readyq(manager, c), manager->pause_requested, manager->exclusive_requested);
|
||||
XTHREADTRACE(isc_msgcat_get(isc_msgcat,
|
||||
ISC_MSGSET_TASK,
|
||||
ISC_MSG_AWAKE, "awake"));
|
||||
@@ -965,7 +979,7 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
XTHREADTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TASK,
|
||||
ISC_MSG_WORKING, "working"));
|
||||
|
||||
task = pop_readyq(manager);
|
||||
task = pop_readyq(manager, c);
|
||||
if (task != NULL) {
|
||||
unsigned int dispatch_count = 0;
|
||||
bool done = false;
|
||||
@@ -980,15 +994,21 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
* have a task to do. We must reacquire the manager
|
||||
* lock before exiting the 'if (task != NULL)' block.
|
||||
*/
|
||||
UNLOCK(&manager->locks[c]);
|
||||
LOCK(&manager->lock);
|
||||
manager->tasks_ready--;
|
||||
manager->tasks_running++;
|
||||
UNLOCK(&manager->lock);
|
||||
// isc_atomic_xadd(&manager->tasks_ready, -1);
|
||||
// isc_atomic_xadd(&manager->tasks_running, 1);
|
||||
|
||||
LOCK(&task->lock);
|
||||
INSIST(task->state == task_state_ready);
|
||||
task->state = task_state_running;
|
||||
task->c = c;
|
||||
XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_RUNNING, "running"));
|
||||
XTRACE(task->name);
|
||||
TIME_NOW(&task->tnow);
|
||||
task->now = isc_time_seconds(&task->tnow);
|
||||
do {
|
||||
@@ -1004,6 +1024,7 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
ISC_MSGSET_TASK,
|
||||
ISC_MSG_EXECUTE,
|
||||
"execute action"));
|
||||
XTRACE(task->name);
|
||||
if (event->ev_action != NULL) {
|
||||
UNLOCK(&task->lock);
|
||||
(event->ev_action)(
|
||||
@@ -1093,7 +1114,6 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
|
||||
if (finished)
|
||||
task_finished(task);
|
||||
|
||||
LOCK(&manager->lock);
|
||||
manager->tasks_running--;
|
||||
if (manager->exclusive_requested &&
|
||||
@@ -1103,6 +1123,7 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
manager->tasks_running == 0) {
|
||||
SIGNAL(&manager->paused);
|
||||
}
|
||||
UNLOCK(&manager->lock);
|
||||
if (requeue) {
|
||||
/*
|
||||
* We know we're awake, so we don't have
|
||||
@@ -1123,7 +1144,9 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
* were usually nonempty, the 'optimization'
|
||||
* might even hurt rather than help.
|
||||
*/
|
||||
push_readyq(manager, task);
|
||||
LOCK(&manager->locks[c]);
|
||||
push_readyq(manager, task, c);
|
||||
UNLOCK(&manager->locks[c]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1133,27 +1156,40 @@ dispatch(isc__taskmgr_t *manager) {
|
||||
* we're stuck. Automatically drop privileges at that
|
||||
* point and continue with the regular ready queue.
|
||||
*/
|
||||
if (manager->tasks_running == 0 && empty_readyq(manager)) {
|
||||
manager->mode = isc_taskmgrmode_normal;
|
||||
if (!empty_readyq(manager))
|
||||
BROADCAST(&manager->work_available);
|
||||
if (manager->tasks_running == 0 && empty_readyq(manager, c)) {
|
||||
if (manager->mode != isc_taskmgrmode_normal) {
|
||||
manager->mode = isc_taskmgrmode_normal;
|
||||
for (unsigned i=0; i<manager->workers; i++) {
|
||||
if (i != (unsigned)c)
|
||||
LOCK(&manager->locks[i]);
|
||||
BROADCAST(&manager->work_available[i]);
|
||||
if (i != (unsigned)c)
|
||||
UNLOCK(&manager->locks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UNLOCK(&manager->lock);
|
||||
}
|
||||
|
||||
typedef struct st {
|
||||
isc__taskmgr_t *manager;
|
||||
int c;
|
||||
} stt;
|
||||
|
||||
static isc_threadresult_t
|
||||
#ifdef _WIN32
|
||||
WINAPI
|
||||
#endif
|
||||
run(void *uap) {
|
||||
isc__taskmgr_t *manager = uap;
|
||||
stt *st = uap;
|
||||
isc__taskmgr_t *manager = st->manager;
|
||||
int c = st->c;
|
||||
free(st);
|
||||
|
||||
XTHREADTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_STARTING, "starting"));
|
||||
|
||||
dispatch(manager);
|
||||
dispatch(manager, c);
|
||||
|
||||
XTHREADTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_EXITING, "exiting"));
|
||||
@@ -1170,7 +1206,7 @@ manager_free(isc__taskmgr_t *manager) {
|
||||
isc_mem_t *mctx;
|
||||
|
||||
(void)isc_condition_destroy(&manager->exclusive_granted);
|
||||
(void)isc_condition_destroy(&manager->work_available);
|
||||
(void)isc_condition_destroy(&manager->work_available[0]);
|
||||
(void)isc_condition_destroy(&manager->paused);
|
||||
isc_mem_free(manager->mctx, manager->threads);
|
||||
DESTROYLOCK(&manager->lock);
|
||||
@@ -1220,14 +1256,6 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
|
||||
result = ISC_R_NOMEMORY;
|
||||
goto cleanup_lock;
|
||||
}
|
||||
if (isc_condition_init(&manager->work_available) != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_condition_init() %s",
|
||||
isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_FAILED, "failed"));
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup_threads;
|
||||
}
|
||||
if (isc_condition_init(&manager->exclusive_granted) != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_condition_init() %s",
|
||||
@@ -1248,8 +1276,10 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
|
||||
default_quantum = DEFAULT_DEFAULT_QUANTUM;
|
||||
manager->default_quantum = default_quantum;
|
||||
INIT_LIST(manager->tasks);
|
||||
INIT_LIST(manager->ready_tasks);
|
||||
INIT_LIST(manager->ready_priority_tasks);
|
||||
manager->ready_tasks = malloc(workers * sizeof(isc__tasklist_t));
|
||||
manager->locks = malloc(workers * sizeof(isc_mutex_t));
|
||||
manager->work_available = malloc(workers * sizeof(isc_condition_t));
|
||||
manager->ready_priority_tasks = malloc(workers * sizeof(isc__tasklist_t));
|
||||
manager->tasks_running = 0;
|
||||
manager->tasks_ready = 0;
|
||||
manager->exclusive_requested = false;
|
||||
@@ -1264,16 +1294,34 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
|
||||
* Start workers.
|
||||
*/
|
||||
for (i = 0; i < workers; i++) {
|
||||
if (isc_thread_create(run, manager,
|
||||
&manager->threads[manager->workers]) ==
|
||||
ISC_R_SUCCESS) {
|
||||
char name[16]; /* thread name limit on Linux */
|
||||
snprintf(name, sizeof(name), "isc-worker%04u", i);
|
||||
isc_thread_setname(manager->threads[manager->workers],
|
||||
name);
|
||||
manager->workers++;
|
||||
started++;
|
||||
INIT_LIST(manager->ready_tasks[i]);
|
||||
INIT_LIST(manager->ready_priority_tasks[i]);
|
||||
isc_mutex_init(&manager->locks[i]);
|
||||
if (isc_condition_init(&manager->work_available[i]) != ISC_R_SUCCESS) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_condition_init() %s",
|
||||
isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
|
||||
ISC_MSG_FAILED, "failed"));
|
||||
result = ISC_R_UNEXPECTED;
|
||||
goto cleanup_threads;
|
||||
}
|
||||
stt *st = malloc(sizeof(stt));
|
||||
st->manager = manager;
|
||||
st->c = i;
|
||||
if (isc_thread_create(run, st,
|
||||
&manager->threads[i]) != ISC_R_SUCCESS) {
|
||||
goto cleanup_threads;
|
||||
}
|
||||
char name[16]; /* thread name limit on Linux */
|
||||
snprintf(name, sizeof(name), "isc-worker%04u", i);
|
||||
isc_thread_setname(manager->threads[manager->workers],
|
||||
name);
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(i, &cpuset);
|
||||
pthread_setaffinity_np(manager->threads[i], sizeof(cpu_set_t), &cpuset);
|
||||
manager->workers++;
|
||||
started++;
|
||||
}
|
||||
UNLOCK(&manager->lock);
|
||||
|
||||
@@ -1290,7 +1338,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int workers,
|
||||
cleanup_exclusivegranted:
|
||||
(void)isc_condition_destroy(&manager->exclusive_granted);
|
||||
cleanup_workavailable:
|
||||
(void)isc_condition_destroy(&manager->work_available);
|
||||
(void)isc_condition_destroy(&manager->work_available[0]);
|
||||
cleanup_threads:
|
||||
isc_mem_free(mctx, manager->threads);
|
||||
cleanup_lock:
|
||||
@@ -1362,7 +1410,7 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
|
||||
task = NEXT(task, link)) {
|
||||
LOCK(&task->lock);
|
||||
if (task_shutdown(task))
|
||||
push_readyq(manager, task);
|
||||
push_readyq(manager, task, 0);
|
||||
UNLOCK(&task->lock);
|
||||
}
|
||||
/*
|
||||
@@ -1370,7 +1418,7 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) {
|
||||
* there's work left to do, and if there are already no tasks left
|
||||
* it will cause the workers to see manager->exiting.
|
||||
*/
|
||||
BROADCAST(&manager->work_available);
|
||||
BROADCAST(&manager->work_available[0]);
|
||||
UNLOCK(&manager->lock);
|
||||
|
||||
/*
|
||||
@@ -1421,7 +1469,7 @@ isc__taskmgr_resume(isc_taskmgr_t *manager0) {
|
||||
LOCK(&manager->lock);
|
||||
if (manager->pause_requested) {
|
||||
manager->pause_requested = false;
|
||||
BROADCAST(&manager->work_available);
|
||||
BROADCAST(&manager->work_available[0]); // TODO
|
||||
}
|
||||
UNLOCK(&manager->lock);
|
||||
}
|
||||
@@ -1493,8 +1541,12 @@ isc_task_endexclusive(isc_task_t *task0) {
|
||||
LOCK(&manager->lock);
|
||||
REQUIRE(manager->exclusive_requested);
|
||||
manager->exclusive_requested = false;
|
||||
BROADCAST(&manager->work_available);
|
||||
UNLOCK(&manager->lock);
|
||||
for (unsigned i=0; i < manager->workers; i++) {
|
||||
LOCK(&manager->locks[i]);
|
||||
BROADCAST(&manager->work_available[i]);
|
||||
UNLOCK(&manager->locks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1514,15 +1566,17 @@ isc_task_setprivilege(isc_task_t *task0, bool priv) {
|
||||
|
||||
if (priv == oldpriv)
|
||||
return;
|
||||
|
||||
LOCK(&manager->lock);
|
||||
if (task->c == -1) {
|
||||
task->c = sched_getcpu() % task->manager->workers;
|
||||
}
|
||||
LOCK(&manager->locks[task->c]);
|
||||
if (priv && ISC_LINK_LINKED(task, ready_link))
|
||||
ENQUEUE(manager->ready_priority_tasks, task,
|
||||
ENQUEUE(manager->ready_priority_tasks[task->c], task,
|
||||
ready_priority_link);
|
||||
else if (!priv && ISC_LINK_LINKED(task, ready_priority_link))
|
||||
DEQUEUE(manager->ready_priority_tasks, task,
|
||||
DEQUEUE(manager->ready_priority_tasks[task->c], task,
|
||||
ready_priority_link);
|
||||
UNLOCK(&manager->lock);
|
||||
UNLOCK(&manager->locks[task->c]);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
+314
-412
File diff suppressed because it is too large
Load Diff
@@ -60,7 +60,7 @@ static volatile HANDLE _mutex = NULL;
|
||||
#else /* defined(_WIN32) || defined(_WIN64) */
|
||||
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
//static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define _LOCK() pthread_mutex_lock(&_mutex)
|
||||
#define _UNLOCK() pthread_mutex_unlock(&_mutex)
|
||||
#endif /* defined(_WIN32) || defined(_WIN64) */
|
||||
@@ -69,13 +69,13 @@ static inline uint32_t rotl(const uint32_t x, int k) {
|
||||
return (x << k) | (x >> (32 - k));
|
||||
}
|
||||
|
||||
static uint32_t seed[4];
|
||||
static thread_local uint32_t seed[4];
|
||||
|
||||
static inline uint32_t
|
||||
next(void) {
|
||||
uint32_t result_starstar, t;
|
||||
|
||||
_LOCK();
|
||||
// _LOCK();
|
||||
|
||||
result_starstar = rotl(seed[0] * 5, 7) * 9;
|
||||
t = seed[1] << 9;
|
||||
@@ -89,7 +89,7 @@ next(void) {
|
||||
|
||||
seed[3] = rotl(seed[3], 11);
|
||||
|
||||
_UNLOCK();
|
||||
// _UNLOCK();
|
||||
|
||||
return (result_starstar);
|
||||
}
|
||||
|
||||
+49
-2
@@ -1048,6 +1048,51 @@ ns_client_sendraw(ns_client_t *client, dns_message_t *message) {
|
||||
ns_client_next(client, result);
|
||||
}
|
||||
|
||||
#ifdef PSEUDOSEND
|
||||
static void
|
||||
client_pseudosend(ns_client_t *client, uint16_t id) {
|
||||
isc_result_t result;
|
||||
unsigned char *data;
|
||||
isc_buffer_t buffer;
|
||||
isc_buffer_t tcpbuffer;
|
||||
isc_region_t r;
|
||||
unsigned char sendbuf[SEND_BUFFER_SIZE];
|
||||
result = client_allocsendbuf(client, &buffer, &tcpbuffer, 0,
|
||||
sendbuf, &data);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
isc_buffer_putuint16(&buffer, id);
|
||||
isc_buffer_putuint8(&buffer, 0x81);
|
||||
isc_buffer_putuint8(&buffer, 0x80);
|
||||
isc_buffer_putuint16(&buffer, 0);
|
||||
isc_buffer_putuint16(&buffer, 0);
|
||||
isc_buffer_putuint16(&buffer, 0);
|
||||
isc_buffer_putuint16(&buffer, 0);
|
||||
if (client->sendcb != NULL) {
|
||||
client->sendcb(&buffer);
|
||||
} else if (TCP_CLIENT(client)) {
|
||||
isc_buffer_usedregion(&buffer, &r);
|
||||
isc_buffer_putuint16(&tcpbuffer, (uint16_t) r.length);
|
||||
isc_buffer_add(&tcpbuffer, r.length);
|
||||
result = client_sendpkg(client, &tcpbuffer);
|
||||
} else {
|
||||
result = client_sendpkg(client, &buffer);
|
||||
}
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
done:
|
||||
if (client->tcpbuf != NULL) {
|
||||
isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
|
||||
client->tcpbuf = NULL;
|
||||
}
|
||||
ns_client_next(client, result);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
client_send(ns_client_t *client) {
|
||||
isc_result_t result;
|
||||
@@ -2346,7 +2391,6 @@ ns__client_request(isc_task_t *task, isc_event_t *event) {
|
||||
}
|
||||
|
||||
isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
|
||||
|
||||
#if NS_CLIENT_DROPPORT
|
||||
if (ns_client_dropport(isc_sockaddr_getport(&client->peeraddr)) ==
|
||||
DROPPORT_REQUEST) {
|
||||
@@ -2403,7 +2447,10 @@ ns__client_request(isc_task_t *task, isc_event_t *event) {
|
||||
ns_client_next(client, result);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef PSEUDOSEND
|
||||
client_pseudosend(client, id);
|
||||
return;
|
||||
#endif
|
||||
/*
|
||||
* The client object handles requests, not responses.
|
||||
* If this is a UDP response, forward it to the dispatcher.
|
||||
|
||||
Reference in New Issue
Block a user