2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

1527. [cleanup] Reduce the number of gettimeofday() calls without

losing necessary timer granularity.

(reviewed by marka and Kurt)
This commit is contained in:
Tatuya JINMEI 神明達哉
2003-10-25 00:09:14 +00:00
parent 8cb1558ff8
commit 6da7c87a77
5 changed files with 62 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
1528. [placeholder] 1528. [placeholder]
1527. [placeholder] 1527. [cleanup] Reduce the number of gettimeofday() calls without
losing necessary timer granularity.
1526. [placeholder] 1526. [placeholder]

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: client.c,v 1.216 2003/07/04 04:38:54 marka Exp $ */ /* $Id: client.c,v 1.217 2003/10/25 00:09:13 jinmei Exp $ */
#include <config.h> #include <config.h>
@@ -1129,8 +1129,6 @@ client_request(isc_task_t *task, isc_event_t *event) {
REQUIRE(NS_CLIENT_VALID(client)); REQUIRE(NS_CLIENT_VALID(client));
REQUIRE(task == client->task); REQUIRE(task == client->task);
UNUSED(task);
INSIST(client->recursionquota == NULL); INSIST(client->recursionquota == NULL);
INSIST(client->state == INSIST(client->state ==
@@ -1174,7 +1172,7 @@ client_request(isc_task_t *task, isc_event_t *event) {
goto cleanup; goto cleanup;
client->state = client->newstate = NS_CLIENTSTATE_WORKING; client->state = client->newstate = NS_CLIENTSTATE_WORKING;
isc_stdtime_get(&client->requesttime); isc_task_getcurrenttime(task, &client->requesttime);
client->now = client->requesttime; client->now = client->requesttime;
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: task.h,v 1.49 2001/02/13 04:11:44 gson Exp $ */ /* $Id: task.h,v 1.50 2003/10/25 00:09:14 jinmei Exp $ */
#ifndef ISC_TASK_H #ifndef ISC_TASK_H
#define ISC_TASK_H 1 #define ISC_TASK_H 1
@@ -58,9 +58,10 @@
*** Imports. *** Imports.
***/ ***/
#include <isc/lang.h>
#include <isc/types.h>
#include <isc/eventclass.h> #include <isc/eventclass.h>
#include <isc/lang.h>
#include <isc/stdtime.h>
#include <isc/types.h>
#define ISC_TASKEVENT_FIRSTEVENT (ISC_EVENTCLASS_TASK + 0) #define ISC_TASKEVENT_FIRSTEVENT (ISC_EVENTCLASS_TASK + 0)
#define ISC_TASKEVENT_SHUTDOWN (ISC_EVENTCLASS_TASK + 1) #define ISC_TASKEVENT_SHUTDOWN (ISC_EVENTCLASS_TASK + 1)
@@ -518,6 +519,19 @@ isc_task_endexclusive(isc_task_t *task);
* exclusive access by calling isc_task_spl(). * exclusive access by calling isc_task_spl().
*/ */
void
isc_task_getcurrenttime(isc_task_t *task, isc_stdtime_t *t);
/*
* Provide the most recent timestamp on the task. The timestamp is considered
* as the "current time" in the second-order granularity.
*
* Requires:
* 'task' is a valid task.
* 't' is a valid non NULL pointer.
*
* Ensures:
* '*t' has the "current time".
*/
/***** /*****
***** Task Manager. ***** Task Manager.

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: task.c,v 1.88 2002/07/19 03:39:43 marka Exp $ */ /* $Id: task.c,v 1.89 2003/10/25 00:09:13 jinmei Exp $ */
/* /*
* Principal Author: Bob Halley * Principal Author: Bob Halley
@@ -82,6 +82,7 @@ struct isc_task {
isc_eventlist_t on_shutdown; isc_eventlist_t on_shutdown;
unsigned int quantum; unsigned int quantum;
unsigned int flags; unsigned int flags;
isc_stdtime_t now;
#ifdef ISC_TASK_NAMES #ifdef ISC_TASK_NAMES
char name[16]; char name[16];
void * tag; void * tag;
@@ -196,6 +197,7 @@ isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
INIT_LIST(task->on_shutdown); INIT_LIST(task->on_shutdown);
task->quantum = quantum; task->quantum = quantum;
task->flags = 0; task->flags = 0;
task->now = 0;
#ifdef ISC_TASK_NAMES #ifdef ISC_TASK_NAMES
memset(task->name, 0, sizeof(task->name)); memset(task->name, 0, sizeof(task->name));
task->tag = NULL; task->tag = NULL;
@@ -717,6 +719,17 @@ isc_task_gettag(isc_task_t *task) {
return (task->tag); return (task->tag);
} }
void
isc_task_getcurrenttime(isc_task_t *task, isc_stdtime_t *t) {
REQUIRE(VALID_TASK(task));
REQUIRE(t != NULL);
LOCK(&task->lock);
*t = task->now;
UNLOCK(&task->lock);
}
/*** /***
*** Task Manager. *** Task Manager.
@@ -838,6 +851,7 @@ dispatch(isc_taskmgr_t *manager) {
task->state = task_state_running; task->state = task_state_running;
XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL, XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
ISC_MSG_RUNNING, "running")); ISC_MSG_RUNNING, "running"));
isc_stdtime_get(&task->now);
do { do {
if (!EMPTY(task->events)) { if (!EMPTY(task->events)) {
event = HEAD(task->events); event = HEAD(task->events);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: app.c,v 1.48 2002/05/10 06:41:54 marka Exp $ */ /* $Id: app.c,v 1.49 2003/10/25 00:09:14 jinmei Exp $ */
#include <config.h> #include <config.h>
@@ -304,12 +304,14 @@ evloop() {
fd_set readfds, writefds; fd_set readfds, writefds;
int maxfd; int maxfd;
isc_boolean_t readytasks; isc_boolean_t readytasks;
isc_boolean_t call_timer_dispatch = ISC_FALSE;
readytasks = isc__taskmgr_ready(); readytasks = isc__taskmgr_ready();
if (readytasks) { if (readytasks) {
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
tvp = &tv; tvp = &tv;
call_timer_dispatch = ISC_TRUE;
} else { } else {
result = isc__timermgr_nextevent(&when); result = isc__timermgr_nextevent(&when);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
@@ -319,6 +321,8 @@ evloop() {
TIME_NOW(&now); TIME_NOW(&now);
us = isc_time_microdiff(&when, &now); us = isc_time_microdiff(&when, &now);
if (us == 0)
call_timer_dispatch = ISC_TRUE;
tv.tv_sec = us / 1000000; tv.tv_sec = us / 1000000;
tv.tv_usec = us % 1000000; tv.tv_usec = us % 1000000;
tvp = &tv; tvp = &tv;
@@ -328,7 +332,23 @@ evloop() {
isc__socketmgr_getfdsets(&readfds, &writefds, &maxfd); isc__socketmgr_getfdsets(&readfds, &writefds, &maxfd);
n = select(maxfd, &readfds, &writefds, NULL, tvp); n = select(maxfd, &readfds, &writefds, NULL, tvp);
isc__timermgr_dispatch(); if (n == 0 || call_timer_dispatch) {
/*
* We call isc__timermgr_dispatch() only when
* necessary, in order to reduce overhead. If the
* select() call indicates a timeout, we need the
* dispatch. Even if not, if we set the 0-timeout
* for the select() call, we need to check the timer
* events. In the 'readytasks' case, there may be no
* timeout event actually, but there is no other way
* to reduce the overhead.
* Note that we do not have to worry about the case
* where a new timer is inserted during the select()
* call, since this loop only runs in the non-thread
* mode.
*/
isc__timermgr_dispatch();
}
if (n > 0) if (n > 0)
(void)isc__socketmgr_dispatch(&readfds, &writefds, (void)isc__socketmgr_dispatch(&readfds, &writefds,
maxfd); maxfd);
@@ -367,16 +387,16 @@ static isc_boolean_t signalled = ISC_FALSE;
isc_result_t isc_result_t
isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) { isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) {
isc_result_t result; isc_result_t result;
UNUSED(cp); UNUSED(cp);
UNUSED(mp); UNUSED(mp);
INSIST(!in_recursive_evloop); INSIST(!in_recursive_evloop);
in_recursive_evloop = ISC_TRUE; in_recursive_evloop = ISC_TRUE;
INSIST(*mp == 1); /* Mutex must be locked on entry. */ INSIST(*mp == 1); /* Mutex must be locked on entry. */
--*mp; --*mp;
result = evloop(); result = evloop();
if (result == ISC_R_RELOAD) if (result == ISC_R_RELOAD)
want_reload = ISC_TRUE; want_reload = ISC_TRUE;
@@ -394,7 +414,7 @@ isc_result_t
isc__nothread_signal_hack(isc_condition_t *cp) { isc__nothread_signal_hack(isc_condition_t *cp) {
UNUSED(cp); UNUSED(cp);
INSIST(in_recursive_evloop); INSIST(in_recursive_evloop);
want_shutdown = ISC_TRUE; want_shutdown = ISC_TRUE;