Skip to content

Commit

Permalink
daemon/defer: fix other places with recursive time measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Ondráček committed Dec 2, 2024
1 parent 6c9d047 commit 8b4c850
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 36 deletions.
97 changes: 61 additions & 36 deletions daemon/session2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,17 @@ struct qr_task *session2_tasklist_del_msgid(const struct session2 *session, uint

void session2_tasklist_finalize(struct session2 *session, int status)
{
while (session2_tasklist_get_len(session) > 0) {
struct qr_task *t = session2_tasklist_del_first(session, false);
kr_require(worker_task_numrefs(t) > 0);
worker_task_finalize(t, status);
worker_task_unref(t);
if (session2_tasklist_get_len(session) > 0) {
defer_sample_state_t defer_prev_sample_state;
defer_sample_start(&defer_prev_sample_state);
do {
struct qr_task *t = session2_tasklist_del_first(session, false);
kr_require(worker_task_numrefs(t) > 0);
worker_task_finalize(t, status);
worker_task_unref(t);
defer_sample_restart();
} while (session2_tasklist_get_len(session) > 0);
defer_sample_stop(&defer_prev_sample_state, true);
}
}

Expand Down Expand Up @@ -1142,27 +1148,34 @@ int session2_tasklist_finalize_expired(struct session2 *session)
key = (char *)&msg_id;
keylen = sizeof(msg_id);
}
while (queue_len(q) > 0) {
task = queue_head(q);
if (session->outgoing) {
knot_pkt_t *pktbuf = worker_task_get_pktbuf(task);
msg_id = knot_wire_get_id(pktbuf->wire);
}
int res = trie_del(t, key, keylen, NULL);
if (!worker_task_finished(task)) {
/* task->pending_count must be zero,
* but there are can be followers,
* so run worker_task_subreq_finalize() to ensure retrying
* for all the followers. */
worker_task_subreq_finalize(task);
worker_task_finalize(task, KR_STATE_FAIL);
}
if (res == KNOT_EOK) {

if (queue_len(q) > 0) {
defer_sample_state_t defer_prev_sample_state;
defer_sample_start(&defer_prev_sample_state);
do {
task = queue_head(q);
if (session->outgoing) {
knot_pkt_t *pktbuf = worker_task_get_pktbuf(task);
msg_id = knot_wire_get_id(pktbuf->wire);
}
int res = trie_del(t, key, keylen, NULL);
if (!worker_task_finished(task)) {
/* task->pending_count must be zero,
* but there are can be followers,
* so run worker_task_subreq_finalize() to ensure retrying
* for all the followers. */
worker_task_subreq_finalize(task);
worker_task_finalize(task, KR_STATE_FAIL);
}
if (res == KNOT_EOK) {
worker_task_unref(task);
}
queue_pop(q);
worker_task_unref(task);
}
queue_pop(q);
worker_task_unref(task);
++ret;
++ret;
defer_sample_restart();
} while (queue_len(q) > 0);
defer_sample_stop(&defer_prev_sample_state, true);
}

queue_deinit(q);
Expand Down Expand Up @@ -1193,22 +1206,34 @@ struct qr_task *session2_waitinglist_pop(struct session2 *session, bool deref)

void session2_waitinglist_retry(struct session2 *session, bool increase_timeout_cnt)
{
while (!session2_waitinglist_is_empty(session)) {
struct qr_task *task = session2_waitinglist_pop(session, false);
if (increase_timeout_cnt) {
worker_task_timeout_inc(task);
}
worker_task_step(task, session2_get_peer(session), NULL);
worker_task_unref(task);
if (!session2_waitinglist_is_empty(session)) {
defer_sample_state_t defer_prev_sample_state;
defer_sample_start(&defer_prev_sample_state);
do {
struct qr_task *task = session2_waitinglist_pop(session, false);
if (increase_timeout_cnt) {
worker_task_timeout_inc(task);
}
worker_task_step(task, session2_get_peer(session), NULL);
worker_task_unref(task);
defer_sample_restart();
} while (!session2_waitinglist_is_empty(session));
defer_sample_stop(&defer_prev_sample_state, true);
}
}

void session2_waitinglist_finalize(struct session2 *session, int status)
{
while (!session2_waitinglist_is_empty(session)) {
struct qr_task *t = session2_waitinglist_pop(session, false);
worker_task_finalize(t, status);
worker_task_unref(t);
if (!session2_waitinglist_is_empty(session)) {
defer_sample_state_t defer_prev_sample_state;
defer_sample_start(&defer_prev_sample_state);
do {
struct qr_task *t = session2_waitinglist_pop(session, false);
worker_task_finalize(t, status);
worker_task_unref(t);
defer_sample_restart();
} while (!session2_waitinglist_is_empty(session));
defer_sample_stop(&defer_prev_sample_state, true);
}
}

Expand Down
4 changes: 4 additions & 0 deletions daemon/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,10 @@ static int qr_task_finalize(struct qr_task *task, int state)
if (task->finished) {
return kr_ok();
}

if (task->ctx->source.session)
defer_sample_addr(&task->ctx->source.addr, task->ctx->source.session->stream);

struct request_ctx *ctx = task->ctx;
struct session2 *source_session = ctx->source.session;
kr_resolve_finish(&ctx->req, state);
Expand Down

0 comments on commit 8b4c850

Please sign in to comment.