aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArunaMaurya221B <aruna.maurya12@gmail.com>2017-12-08 16:48:27 +0530
committerMatt Traudt <sirmatt@ksu.edu>2017-12-11 08:46:43 -0500
commitad5cfa30396fcbf8e60806594a1a59fd411bc325 (patch)
tree27dcc5a11c8b613c646530ef0f65572545c9d99f
parentd77cacb7ab97e876900063f4d7c852a458bdab93 (diff)
downloadtor-ad5cfa30396fcbf8e60806594a1a59fd411bc325.tar.gz
tor-ad5cfa30396fcbf8e60806594a1a59fd411bc325.zip
Bug:24531 Function to change channel scheduler state for easy debugging added.
-rw-r--r--src/or/scheduler.c41
-rw-r--r--src/or/scheduler.h2
2 files changed, 22 insertions, 21 deletions
diff --git a/src/or/scheduler.c b/src/or/scheduler.c
index 38b2ee5ef8..36aa6ba921 100644
--- a/src/or/scheduler.c
+++ b/src/or/scheduler.c
@@ -363,8 +363,8 @@ set_scheduler(void)
*****************************************************************************/
/* Function to log and change all the old and new states*/
-void scheduler_set_channel(chan,new_state){
- log_debug(LD_SCHED, "chan %d changed from scheduler state %d to %d",chan->global_id, chan->scheduler_state, new_state);
+void scheduler_set_channel_state(channel_t *chan,int new_state){
+ log_debug(LD_SCHED, "chan %s changed from scheduler state %d to %d",chan->global_identifier, chan->scheduler_state, new_state);
chan->scheduler_state = new_state;
}
/** Return the pending channel list. */
@@ -494,7 +494,7 @@ scheduler_channel_doesnt_want_writes,(channel_t *chan))
}
/* If it's already in pending, we can put it in waiting_to_write */
- if (chan->scheduler_state == SCHED_CHAN_PENDING) {
+ if (chan->scheduler_state == SCHED_CHAN_PENDING){
/*
* It's in channels_pending, so it shouldn't be in any of
* the other lists. It can't write any more, so it goes to
@@ -504,7 +504,7 @@ scheduler_channel_doesnt_want_writes,(channel_t *chan))
scheduler_compare_channels,
offsetof(channel_t, sched_heap_idx),
chan);
- chan->scheduler_state = SCHED_CHAN_WAITING_TO_WRITE;
+ scheduler_set_channel_state(chan,SCHED_CHAN_WAITING_TO_WRITE);
log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p went from pending "
"to waiting_to_write",
@@ -515,8 +515,8 @@ scheduler_channel_doesnt_want_writes,(channel_t *chan))
* either not in any of the lists (nothing to do) or it's already in
* waiting_for_cells (remove it, can't write any more).
*/
- if (scheduler_set_channel(chan,new_state) == SCHED_CHAN_WAITING_FOR_CELLS) {
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_IDLE;
+ if (chan->scheduler_state == SCHED_CHAN_WAITING_FOR_CELLS){
+ scheduler_set_channel_state(chan,SCHED_CHAN_IDLE);
log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p left waiting_for_cells",
U64_PRINTF_ARG(chan->global_identifier), chan);
@@ -536,13 +536,13 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
}
/* First, check if it's also writeable */
- if (scheduler_set_channel(chan,new_state) == SCHED_CHAN_WAITING_FOR_CELLS) {
+ if (chan->scheduler_state == SCHED_CHAN_WAITING_FOR_CELLS){
/*
* It's in channels_waiting_for_cells, so it shouldn't be in any of
* the other lists. It has waiting cells now, so it goes to
* channels_pending.
*/
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_PENDING;
+ scheduler_set_channel_state(chan,SCHED_CHAN_PENDING);
smartlist_pqueue_add(channels_pending,
scheduler_compare_channels,
offsetof(channel_t, sched_heap_idx),
@@ -560,9 +560,9 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
* either not in any of the lists (we add it to waiting_to_write)
* or it's already in waiting_to_write or pending (we do nothing)
*/
- if (!(scheduler_set_channel(chan,new_state) == SCHED_CHAN_WAITING_TO_WRITE ||
- scheduler_set_channel(chan,new_state) == SCHED_CHAN_PENDING)) {
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_WAITING_TO_WRITE;
+ if (!(chan->scheduler_state == SCHED_CHAN_WAITING_TO_WRITE ||
+ chan->scheduler_state== SCHED_CHAN_PENDING)) {
+ scheduler_set_channel_state(chan, SCHED_CHAN_WAITING_TO_WRITE);
log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p entered waiting_to_write",
U64_PRINTF_ARG(chan->global_identifier), chan);
@@ -632,7 +632,7 @@ scheduler_release_channel,(channel_t *chan))
return;
}
- if (scheduler_set_channel(chan,new_state) == SCHED_CHAN_PENDING) {
+ if (chan->scheduler_state == SCHED_CHAN_PENDING) {
if (SCHED_BUG(smartlist_pos(channels_pending, chan) == -1, chan)) {
log_warn(LD_SCHED, "Scheduler asked to release channel %" PRIu64 " "
"but it wasn't in channels_pending",
@@ -648,7 +648,7 @@ scheduler_release_channel,(channel_t *chan))
if (the_scheduler->on_channel_free) {
the_scheduler->on_channel_free(chan);
}
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_IDLE;
+ scheduler_set_channel_state(chan,SCHED_CHAN_IDLE);
}
/** Mark a channel as ready to accept writes */
@@ -664,7 +664,7 @@ scheduler_channel_wants_writes(channel_t *chan)
}
/* If it's already in waiting_to_write, we can put it in pending */
- if (scheduler_set_channel(chan,new_state) == SCHED_CHAN_WAITING_TO_WRITE) {
+ if (chan->scheduler_state == SCHED_CHAN_WAITING_TO_WRITE) {
/*
* It can write now, so it goes to channels_pending.
*/
@@ -674,7 +674,7 @@ scheduler_channel_wants_writes(channel_t *chan)
scheduler_compare_channels,
offsetof(channel_t, sched_heap_idx),
chan);
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_PENDING;
+ scheduler_set_channel_state(chan,SCHED_CHAN_PENDING);
log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p went from waiting_to_write "
"to pending",
@@ -686,9 +686,9 @@ scheduler_channel_wants_writes(channel_t *chan)
* It's not in SCHED_CHAN_WAITING_TO_WRITE, so it can't become pending;
* it's either idle and goes to WAITING_FOR_CELLS, or it's a no-op.
*/
- if (!(scheduler_set_channel(chan,new_state) == SCHED_CHAN_WAITING_FOR_CELLS ||
- scheduler_set_channel(chan,new_state) == SCHED_CHAN_PENDING)) {
- scheduler_set_channel(chan,new_state) = SCHED_CHAN_WAITING_FOR_CELLS;
+ if (!(chan->scheduler_state == SCHED_CHAN_WAITING_FOR_CELLS ||
+ chan->scheduler_state == SCHED_CHAN_PENDING)) {
+ scheduler_set_channel_state(chan, SCHED_CHAN_WAITING_FOR_CELLS);
log_debug(LD_SCHED,
"Channel " U64_FORMAT " at %p entered waiting_for_cells",
U64_PRINTF_ARG(chan->global_identifier), chan);
@@ -705,6 +705,7 @@ scheduler_bug_occurred(const channel_t *chan)
char buf[128];
if (chan != NULL) {
+ int new_state=0;
const size_t outbuf_len =
buf_datalen(TO_CONN(BASE_CHAN_TO_TLS((channel_t *) chan)->conn)->outbuf);
tor_snprintf(buf, sizeof(buf),
@@ -712,7 +713,7 @@ scheduler_bug_occurred(const channel_t *chan)
" Num cells on cmux: %d. Connection outbuf len: %lu.",
chan->global_identifier,
channel_state_to_string(chan->state),
- scheduler_set_channel(chan,new_state), circuitmux_num_cells(chan->cmux),
+ chan->scheduler_state, circuitmux_num_cells(chan->cmux),
(unsigned long)outbuf_len);
}
@@ -745,7 +746,7 @@ scheduler_touch_channel(channel_t *chan)
return;
}
- if (scheduler_set_channel(chan,new_state) == SCHED_CHAN_PENDING) {
+ if (chan->scheduler_state == SCHED_CHAN_PENDING) {
/* Remove and re-add it */
smartlist_pqueue_remove(channels_pending,
scheduler_compare_channels,
diff --git a/src/or/scheduler.h b/src/or/scheduler.h
index b2d05166a4..2c2559f2c9 100644
--- a/src/or/scheduler.h
+++ b/src/or/scheduler.h
@@ -145,7 +145,7 @@ MOCK_DECL(void, scheduler_channel_has_waiting_cells, (channel_t *chan));
*********************************/
/* Function to log and change all the old and new states*/
-void scheduler_set_channel(chan,new_state);
+void scheduler_set_channel_state(channel_t *chan,int new_state);
/* Triggers a BUG() and extra information with chan if available. */
#define SCHED_BUG(cond, chan) \