Commit 405dea1d authored by David Howells's avatar David Howells

rxrpc: Fix the call timer handling

The call timer's concept of a call timeout (of which there are three) that
is inactive is that it is the timeout has the same expiration time as the
call expiration timeout (the expiration timer is never inactive).  However,
I'm not resetting the timeouts when they expire, leading to repeated
processing of expired timeouts when other timeout events occur.

Fix this by:

 (1) Move the timer expiry detection into rxrpc_set_timer() inside the
     locked section.  This means that if a timeout is set that will expire
     immediately, we deal with it immediately.

 (2) If a timeout is at or before now then it has expired.  When an expiry
     is detected, an event is raised, the timeout is automatically
     inactivated and the event processor is queued.

 (3) If a timeout is at or after the expiry timeout then it is inactive.
     Inactive timeouts do not contribute to the timer setting.

 (4) The call timer callback can now just call rxrpc_set_timer() to handle
     things.

 (5) The call processor work function now checks the event flags rather
     than checking the timeouts directly.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent df0adc78
...@@ -29,6 +29,7 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why, ...@@ -29,6 +29,7 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why,
{ {
unsigned long t_j, now_j = jiffies; unsigned long t_j, now_j = jiffies;
ktime_t t; ktime_t t;
bool queue = false;
read_lock_bh(&call->state_lock); read_lock_bh(&call->state_lock);
...@@ -37,13 +38,21 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why, ...@@ -37,13 +38,21 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why,
if (!ktime_after(t, now)) if (!ktime_after(t, now))
goto out; goto out;
if (ktime_after(call->resend_at, now) && if (!ktime_after(call->resend_at, now)) {
ktime_before(call->resend_at, t)) call->resend_at = call->expire_at;
if (!test_and_set_bit(RXRPC_CALL_EV_RESEND, &call->events))
queue = true;
} else if (ktime_before(call->resend_at, t)) {
t = call->resend_at; t = call->resend_at;
}
if (ktime_after(call->ack_at, now) && if (!ktime_after(call->ack_at, now)) {
ktime_before(call->ack_at, t)) call->ack_at = call->expire_at;
if (!test_and_set_bit(RXRPC_CALL_EV_ACK, &call->events))
queue = true;
} else if (ktime_before(call->ack_at, t)) {
t = call->ack_at; t = call->ack_at;
}
t_j = nsecs_to_jiffies(ktime_to_ns(ktime_sub(t, now))); t_j = nsecs_to_jiffies(ktime_to_ns(ktime_sub(t, now)));
t_j += jiffies; t_j += jiffies;
...@@ -59,6 +68,9 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why, ...@@ -59,6 +68,9 @@ void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why,
mod_timer(&call->timer, t_j); mod_timer(&call->timer, t_j);
trace_rxrpc_timer(call, why, now, now_j); trace_rxrpc_timer(call, why, now, now_j);
} }
if (queue)
rxrpc_queue_call(call);
} }
out: out:
...@@ -332,8 +344,7 @@ void rxrpc_process_call(struct work_struct *work) ...@@ -332,8 +344,7 @@ void rxrpc_process_call(struct work_struct *work)
goto recheck_state; goto recheck_state;
} }
if (test_and_clear_bit(RXRPC_CALL_EV_ACK, &call->events) || if (test_and_clear_bit(RXRPC_CALL_EV_ACK, &call->events)) {
ktime_before(call->ack_at, now)) {
call->ack_at = call->expire_at; call->ack_at = call->expire_at;
if (call->ackr_reason) { if (call->ackr_reason) {
rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK); rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK);
...@@ -341,8 +352,7 @@ void rxrpc_process_call(struct work_struct *work) ...@@ -341,8 +352,7 @@ void rxrpc_process_call(struct work_struct *work)
} }
} }
if (test_and_clear_bit(RXRPC_CALL_EV_RESEND, &call->events) || if (test_and_clear_bit(RXRPC_CALL_EV_RESEND, &call->events)) {
ktime_before(call->resend_at, now)) {
rxrpc_resend(call, now); rxrpc_resend(call, now);
goto recheck_state; goto recheck_state;
} }
......
...@@ -71,11 +71,8 @@ static void rxrpc_call_timer_expired(unsigned long _call) ...@@ -71,11 +71,8 @@ static void rxrpc_call_timer_expired(unsigned long _call)
_enter("%d", call->debug_id); _enter("%d", call->debug_id);
if (call->state < RXRPC_CALL_COMPLETE) { if (call->state < RXRPC_CALL_COMPLETE)
trace_rxrpc_timer(call, rxrpc_timer_expired, rxrpc_set_timer(call, rxrpc_timer_expired, ktime_get_real());
ktime_get_real(), jiffies);
rxrpc_queue_call(call);
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment