Skip to content

Commit

Permalink
Fixes according review
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMekhanik committed Jul 20, 2024
1 parent d90af0c commit 910f3a1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
17 changes: 8 additions & 9 deletions fw/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ tfw_h2_stream_create(TfwH2Ctx *ctx, unsigned int id)
TfwFramePri *pri = &ctx->priority;
bool excl = pri->exclusive;

T_DBG3("Create new stream (id %u weight %u exclusive %d),"
" which depends from stream with id %u,"
" ctx %px streams_num %lu\n", id, pri->weight,
pri->exclusive, pri->stream_id, ctx, ctx->streams_num);

dep = tfw_h2_find_stream_dep(&ctx->sched, pri->stream_id);
stream = tfw_h2_add_stream(&ctx->sched, id, pri->weight,
ctx->lsettings.wnd_sz,
Expand All @@ -235,24 +240,18 @@ tfw_h2_stream_create(TfwH2Ctx *ctx, unsigned int id)
return NULL;

tfw_h2_add_stream_dep(&ctx->sched, stream, dep, excl);

++ctx->streams_num;

T_DBG3("%s: ctx [%px] (streams_num %lu, dep strm id %u, dep strm [%p],"
"excl %d) added strm [%px] id %u weight %u\n",
__func__, ctx, ctx->streams_num, pri->stream_id, dep,
pri->exclusive, stream, id, stream->weight);

return stream;
}

void
tfw_h2_stream_clean(TfwH2Ctx *ctx, TfwStream *stream)
{
T_DBG3("%s: strm [%px] id %u state %d(%s) weight %u, ctx "
"streams num %lu\n", __func__, stream, stream->id,
T_DBG3("Stop and delete stream (id %u state %d(%s) weight %u),"
" ctx %px streams num %lu\n", stream->id,
tfw_h2_get_stream_state(stream), __h2_strm_st_n(stream),
stream->weight, ctx->streams_num);
stream->weight, ctx, ctx->streams_num);
tfw_h2_stop_stream(&ctx->sched, stream);
tfw_h2_delete_stream(stream);
--ctx->streams_num;
Expand Down
70 changes: 45 additions & 25 deletions fw/http_stream_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#include "http_stream.h"
#include "connection.h"

#define SCHED_PARENT_STREAM(sched, dep) \
(dep != &sched->root ? container_of(dep, TfwStream, sched)->id : 0)

static inline void
tfw_h2_stream_sched_spin_lock_assert(TfwStreamSched *sched)
{
Expand Down Expand Up @@ -325,16 +328,22 @@ tfw_h2_add_stream_dep(TfwStreamSched *sched, TfwStream *stream,

tfw_h2_stream_sched_spin_lock_assert(sched);

T_DBG3("%s: ctx [%px] (stream id %u excl %d)\n",
__func__, ctx, stream->id, excl);

if (!excl) {
deficit = tfw_h2_stream_sched_min_deficit(dep) +
tfw_h2_stream_default_deficit(stream);
T_DBG3("Add new stream dependency: stream (id %u deficit %llu"
" excl %d) depends from stream with id %d, ctx %px\n",
stream->id, deficit, excl,
SCHED_PARENT_STREAM(sched, dep), ctx);
tfw_h2_sched_stream_enqueue(sched, stream, dep, deficit);
return;
}

T_DBG3("Add new stream dependency: stream (id %u deficit %llu"
" excl %d) depends from stream with id %d, ctx %px\n",
stream->id, tfw_h2_stream_default_deficit(stream),
excl, SCHED_PARENT_STREAM(sched, dep), ctx);

/*
* Here we move children of dep scheduler to the current stream
* scheduler. If current stream scheduler has no children we move
Expand All @@ -357,12 +366,13 @@ tfw_h2_add_stream_dep(TfwStreamSched *sched, TfwStream *stream,
struct eb64_node *node = eb64_first(&dep->blocked);
TfwStream *child = eb64_entry(node, TfwStream, sched_node);

T_DBG3("%s: ctx [%px] move blocked child stream with id %u to"
" new parent with id %u\n", __func__, ctx, child->id,
stream->id);

deficit = !stream_has_children ? child->sched_node.key :
min_deficit + tfw_h2_stream_default_deficit(child);
T_DBG3("During adding new stream dependency, move blocked child"
" (id %u new deficit %llu) of stream with id (%u) to the"
" new exclusively added strean with id (%u), ctx %px\n",
child->id, deficit, SCHED_PARENT_STREAM(sched, dep),
stream->id, ctx);
tfw_h2_stream_sched_move_child(sched, child, &stream->sched,
deficit);
}
Expand All @@ -371,12 +381,13 @@ tfw_h2_add_stream_dep(TfwStreamSched *sched, TfwStream *stream,
struct eb64_node *node = eb64_first(&dep->active);
TfwStream *child = eb64_entry(node, TfwStream, sched_node);

T_DBG3("%s: ctx [%px] move active child stream with id %u to"
" new parent with id %u\n", __func__, ctx, child->id,
stream->id);

deficit = !stream_has_children ? child->sched_node.key :
min_deficit + tfw_h2_stream_default_deficit(child);
T_DBG3("During adding new stream dependency, move active child"
" (id %u new deficit %llu) of stream with id (%u) to the"
" new exclusively added strean with id (%u), ctx %px\n",
child->id, deficit, SCHED_PARENT_STREAM(sched, dep),
stream->id, ctx);
tfw_h2_stream_sched_move_child(sched, child, &stream->sched,
deficit);
}
Expand All @@ -401,8 +412,9 @@ tfw_h2_remove_stream_dep(TfwStreamSched *sched, TfwStream *stream)
bool parent_has_children;
u64 deficit;

T_DBG3("%s: ctx [%px] removed stream id %u\n",
__func__, ctx, stream->id);
T_DBG3("Stream (id %u parent id %u removed from dependency tree,"
" ctx %px\n", stream->id, SCHED_PARENT_STREAM(sched, parent),
ctx);

tfw_h2_stream_sched_spin_lock_assert(sched);

Expand Down Expand Up @@ -430,9 +442,6 @@ tfw_h2_remove_stream_dep(TfwStreamSched *sched, TfwStream *stream)
struct eb64_node *node = eb64_first(&stream->sched.blocked);
TfwStream *child = eb64_entry(node, TfwStream, sched_node);

T_DBG3("%s: ctx [%px] move blocked child stream with id %u to"
" new parent\n", __func__, ctx, child->id);

/*
* Remove children of the removed stream, recalculate there
* weights and add them to the scheduler of the parent of
Expand All @@ -443,16 +452,18 @@ tfw_h2_remove_stream_dep(TfwStreamSched *sched, TfwStream *stream)
child->weight = new_weight > 0 ? new_weight : 1;
deficit = !parent_has_children ?
child->sched_node.key : stream->sched_node.key;
T_DBG3("During removing stream with id (%u) from dependency"
" tree, move its blocked child (id %u new deficit %llu)"
" to the new parent stream with id (%u), ctx %px\n",
stream->id, child->id, deficit,
SCHED_PARENT_STREAM(sched, parent), ctx);
tfw_h2_stream_sched_move_child(sched, child, parent, deficit);
}

while (!eb_is_empty(&stream->sched.active)) {
struct eb64_node *node = eb64_first(&stream->sched.active);
TfwStream *child = eb64_entry(node, TfwStream, sched_node);

T_DBG3("%s: ctx [%px] move active child stream with id %u to"
" new parent\n", __func__, ctx, child->id);

/*
* Remove children of the removed stream, recalculate there
* weights and add them to the scheduler of the parent of
Expand All @@ -463,6 +474,11 @@ tfw_h2_remove_stream_dep(TfwStreamSched *sched, TfwStream *stream)
child->weight = new_weight > 0 ? new_weight : 1;
deficit = !parent_has_children ?
child->sched_node.key : stream->sched_node.key;
T_DBG3("During removing stream with id (%u) from dependency"
" tree, move its active child (id %u new deficit %llu)"
" to the new parent stream with id (%u), ctx %px\n",
stream->id, child->id, deficit,
SCHED_PARENT_STREAM(sched, parent), ctx);
tfw_h2_stream_sched_move_child(sched, child, parent, deficit);
}

Expand Down Expand Up @@ -506,9 +522,11 @@ tfw_h2_change_stream_dep(TfwStreamSched *sched, unsigned int stream_id,
old_parent = stream->sched.parent;
BUG_ON(!old_parent);

T_DBG3("%s: ctx [%px] (stream id %u, new dep stream id %u,"
"new weight %u excl %d)\n", __func__, ctx,
stream_id, new_dep, new_weight, excl);
T_DBG3("Change stream dependency: stream with id (%u), which previously"
" depends from stream with id (%u) now depends from stream with"
" id (%u). New weight (%hu) of the stream (id %u) excl %d,"
" ctx %px\n", stream_id, SCHED_PARENT_STREAM(sched, old_parent),
new_dep, new_weight, stream_id, excl, ctx);

new_parent = tfw_h2_find_stream_dep(sched, new_dep);

Expand Down Expand Up @@ -597,9 +615,9 @@ tfw_h2_sched_stream_dequeue(TfwStreamSched *sched, TfwStreamSchedEntry **parent)
if (tfw_h2_stream_is_active(stream)) {
*parent = entry;
tfw_h2_stream_sched_remove(sched, stream);

T_DBG4("%s: ctx [%px] stream with id %u\n",
__func__, ctx, stream->id);
T_DBG4("Stream with id (%u) removed from dependency"
" tree for making frames, ctx %px\n",
stream->id, ctx);
return stream;
} else if (tfw_h2_stream_sched_is_active(&stream->sched)) {
/*
Expand Down Expand Up @@ -651,3 +669,5 @@ tfw_h2_sched_activate_stream(TfwStreamSched *sched, TfwStream *stream)
tfw_h2_stream_sched_insert_active(stream, stream->sched_node.key);
}
}

#undef SCHED_PARENT_STREAM
8 changes: 4 additions & 4 deletions lib/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ enum {
* content, e.g. SKB queues, rbtree, etc.
*/
#define __BNR "[tempesta " BANNER "] "
#define __T_DBG1(...) printk(__BNR " " __VA_ARGS__)
#define __T_DBG2(...) printk(__BNR " " __VA_ARGS__)
#define __T_DBG3(...) printk(__BNR " " __VA_ARGS__)
#define __T_DBG1(...) printk(KERN_DEBUG __BNR " " __VA_ARGS__)
#define __T_DBG2(...) printk(KERN_DEBUG __BNR " " __VA_ARGS__)
#define __T_DBG3(...) printk(KERN_DEBUG __BNR " " __VA_ARGS__)

#if defined(DEBUG) && (DEBUG >= 1)
#define T_DBG(...) __T_DBG1(__VA_ARGS__)
Expand Down Expand Up @@ -170,7 +170,7 @@ do { \
#endif

#if defined(DEBUG) && (DEBUG >= 4)
#define T_DBG4(...) printk(__BNR "# " __VA_ARGS__)
#define T_DBG4(...) printk(KERN_DEBUG __BNR " " __VA_ARGS__)
#else
#define T_DBG4(...)
#endif
Expand Down

0 comments on commit 910f3a1

Please sign in to comment.