Skip to content

Commit

Permalink
[DCCP] Introduce dccp_timestamp
Browse files Browse the repository at this point in the history
To start the timestamps with 0.0ms, easing the integer maths in the CCIDs, this
probably will be reworked to use the to be introduced struct timeval_offset
infrastructure out of skb_get_timestamp, etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Sep 9, 2005
1 parent 954ee31 commit b0e5678
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 39 deletions.
1 change: 1 addition & 0 deletions include/linux/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ struct dccp_sock {
struct ccid *dccps_hc_rx_ccid;
struct ccid *dccps_hc_tx_ccid;
struct dccp_options_received dccps_options_received;
struct timeval dccps_epoch;
enum dccp_role dccps_role:2;
__u8 dccps_hc_rx_insert_options:1;
__u8 dccps_hc_tx_insert_options:1;
Expand Down
27 changes: 14 additions & 13 deletions net/dccp/ccids/ccid3.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
} else {
struct timeval now;

do_gettimeofday(&now);
dccp_timestamp(sk, &now);
if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >=
hctx->ccid3hctx_rtt) {
hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv,
Expand Down Expand Up @@ -317,7 +317,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet);
}

do_gettimeofday(&now);
dccp_timestamp(sk, &now);

switch (hctx->ccid3hctx_state) {
case TFRC_SSTATE_NO_SENT:
Expand Down Expand Up @@ -382,7 +382,7 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
return;
}

do_gettimeofday(&now);
dccp_timestamp(sk, &now);

/* check if we have sent a data packet */
if (len > 0) {
Expand Down Expand Up @@ -461,6 +461,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
struct ccid3_options_received *opt_recv;
struct dccp_tx_hist_entry *packet;
struct timeval now;
unsigned long next_tmout;
u32 t_elapsed;
u32 pinv;
Expand Down Expand Up @@ -508,7 +509,8 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
}

/* Update RTT */
r_sample = timeval_now_delta(&packet->dccphtx_tstamp);
dccp_timestamp(sk, &now);
r_sample = timeval_delta(&now, &packet->dccphtx_tstamp);
if (unlikely(r_sample <= t_elapsed))
LIMIT_NETDEBUG(KERN_WARNING
"%s: r_sample=%uus, t_elapsed=%uus\n",
Expand Down Expand Up @@ -774,7 +776,7 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)

ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);

do_gettimeofday(&now);
dccp_timestamp(sk, &now);

switch (hcrx->ccid3hcrx_state) {
case TFRC_RSTATE_NO_DATA:
Expand Down Expand Up @@ -903,10 +905,9 @@ static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
if (rtt == 0)
rtt = 1;

delta = timeval_now_delta(&hcrx->ccid3hcrx_tstamp_last_feedback);
x_recv = hcrx->ccid3hcrx_bytes_recv * USEC_PER_SEC;
if (likely(delta > 1))
x_recv /= delta;
dccp_timestamp(sk, &tstamp);
delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback);
x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta);

tmp1 = (u64)x_recv * (u64)rtt;
do_div(tmp1,10000000);
Expand Down Expand Up @@ -981,7 +982,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
if (opt_recv->dccpor_timestamp_echo == 0)
break;
p_prev = hcrx->ccid3hcrx_rtt;
do_gettimeofday(&now);
dccp_timestamp(sk, &now);
timeval_sub_usecs(&now, opt_recv->dccpor_timestamp_echo * 10);
r_sample = timeval_usecs(&now);
t_elapsed = opt_recv->dccpor_elapsed_time * 10;
Expand Down Expand Up @@ -1013,7 +1014,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
return;
}

packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp,
packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
skb, SLAB_ATOMIC);
if (packet == NULL) {
ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet "
Expand Down Expand Up @@ -1045,7 +1046,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
if (ins != 0)
break;

do_gettimeofday(&now);
dccp_timestamp(sk, &now);
if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >=
hcrx->ccid3hcrx_rtt) {
hcrx->ccid3hcrx_tstamp_last_ack = now;
Expand Down Expand Up @@ -1100,7 +1101,7 @@ static int ccid3_hc_rx_init(struct sock *sk)
hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist);
do_gettimeofday(&hcrx->ccid3hcrx_tstamp_last_ack);
dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */
return 0;
Expand Down
2 changes: 1 addition & 1 deletion net/dccp/ccids/ccid3.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct ccid3_hc_rx_sock {
u64 ccid3hcrx_seqno_last_counter:48,
ccid3hcrx_state:8,
ccid3hcrx_last_counter:4;
unsigned long ccid3hcrx_rtt;
u32 ccid3hcrx_rtt;
u32 ccid3hcrx_p;
u32 ccid3hcrx_bytes_recv;
struct timeval ccid3hcrx_tstamp_last_feedback;
Expand Down
3 changes: 2 additions & 1 deletion net/dccp/ccids/lib/packet_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ static inline struct dccp_tx_hist_entry *

static inline struct dccp_rx_hist_entry *
dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
const struct sock *sk,
const u32 ndp,
const struct sk_buff *skb,
const unsigned int __nocast prio)
Expand All @@ -148,7 +149,7 @@ static inline struct dccp_rx_hist_entry *
entry->dccphrx_ccval = dh->dccph_ccval;
entry->dccphrx_type = dh->dccph_type;
entry->dccphrx_ndp = ndp;
do_gettimeofday(&(entry->dccphrx_tstamp));
dccp_timestamp(sk, &entry->dccphrx_tstamp);
}

return entry;
Expand Down
16 changes: 4 additions & 12 deletions net/dccp/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,13 @@ extern struct dccp_ackpkts *
dccp_ackpkts_alloc(unsigned int len,
const unsigned int __nocast priority);
extern void dccp_ackpkts_free(struct dccp_ackpkts *ap);
extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state);
extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
u64 ackno, u8 state);
extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap,
struct sock *sk, u64 ackno);

extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);

static inline suseconds_t timeval_usecs(const struct timeval *tv)
{
return tv->tv_sec * USEC_PER_SEC + tv->tv_usec;
Expand Down Expand Up @@ -468,17 +471,6 @@ static inline void timeval_sub_usecs(struct timeval *tv,
}
}

/*
* Returns the difference in usecs between timeval
* passed in and current time
*/
static inline suseconds_t timeval_now_delta(const struct timeval *tv)
{
struct timeval now;
do_gettimeofday(&now);
return timeval_delta(&now, tv);
}

#ifdef CONFIG_IP_DCCP_DEBUG
extern void dccp_ackvector_print(const u64 ackno,
const unsigned char *vector, int len);
Expand Down
4 changes: 2 additions & 2 deletions net/dccp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
if (dp->dccps_options.dccpo_send_ack_vector) {
struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;

if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts,
if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
DCCP_SKB_CB(skb)->dccpd_seq,
DCCP_ACKPKTS_STATE_RECEIVED)) {
LIMIT_NETDEBUG(KERN_WARNING "DCCP: acknowledgeable "
Expand Down Expand Up @@ -498,7 +498,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
* DCCP_ACKPKTS_STATE_ECN_MARKED
*/
if (dp->dccps_options.dccpo_send_ack_vector) {
if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts,
if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
DCCP_SKB_CB(skb)->dccpd_seq,
DCCP_ACKPKTS_STATE_RECEIVED))
goto discard;
Expand Down
1 change: 1 addition & 0 deletions net/dccp/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ static int dccp_v4_init_sock(struct sock *sk)
static int dccp_ctl_socket_init = 1;

dccp_options_init(&dp->dccps_options);
do_gettimeofday(&dp->dccps_epoch);

if (dp->dccps_options.dccpo_send_ack_vector) {
dp->dccps_hc_rx_ackpkts =
Expand Down
1 change: 1 addition & 0 deletions net/dccp/minisocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
newdp->dccps_hc_rx_ackpkts = NULL;
newdp->dccps_role = DCCP_ROLE_SERVER;
newicsk->icsk_rto = DCCP_TIMEOUT_INIT;
do_gettimeofday(&newdp->dccps_epoch);

if (newdp->dccps_options.dccpo_send_ack_vector) {
newdp->dccps_hc_rx_ackpkts =
Expand Down
45 changes: 35 additions & 10 deletions net/dccp/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
opt_recv->dccpor_timestamp = ntohl(*(u32 *)value);

dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp;
do_gettimeofday(&dp->dccps_timestamp_time);
dccp_timestamp(sk, &dp->dccps_timestamp_time);

dccp_pr_debug("%sTIMESTAMP=%u, ackno=%llu\n",
debug_prefix, opt_recv->dccpor_timestamp,
Expand Down Expand Up @@ -361,9 +361,13 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
#endif
struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
int len = ap->dccpap_buf_vector_len + 2;
const u32 elapsed_time = timeval_now_delta(&ap->dccpap_time) / 10;
struct timeval now;
u32 elapsed_time;
unsigned char *to, *from;

dccp_timestamp(sk, &now);
elapsed_time = timeval_delta(&now, &ap->dccpap_time) / 10;

if (elapsed_time != 0)
dccp_insert_option_elapsed_time(sk, skb, elapsed_time);

Expand Down Expand Up @@ -428,13 +432,29 @@ static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
(unsigned long long) ap->dccpap_ack_ackno);
}

void dccp_timestamp(const struct sock *sk, struct timeval *tv)
{
const struct dccp_sock *dp = dccp_sk(sk);

do_gettimeofday(tv);
tv->tv_sec -= dp->dccps_epoch.tv_sec;
tv->tv_usec -= dp->dccps_epoch.tv_usec;

while (tv->tv_usec < 0) {
tv->tv_sec--;
tv->tv_usec += USEC_PER_SEC;
}
}

EXPORT_SYMBOL_GPL(dccp_timestamp);

void dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb)
{
struct timeval tv;
u32 now;

do_gettimeofday(&tv);
now = (tv.tv_sec * USEC_PER_SEC + tv.tv_usec) / 10;
dccp_timestamp(sk, &tv);
now = timeval_usecs(&tv) / 10;
/* yes this will overflow but that is the point as we want a
* 10 usec 32 bit timer which mean it wraps every 11.9 hours */

Expand All @@ -452,13 +472,17 @@ static void dccp_insert_option_timestamp_echo(struct sock *sk,
const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
"CLIENT TX opt: " : "server TX opt: ";
#endif
struct timeval now;
u32 tstamp_echo;
const u32 elapsed_time =
timeval_now_delta(&dp->dccps_timestamp_time) / 10;
const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
const int len = 6 + elapsed_time_len;
u32 elapsed_time;
int len, elapsed_time_len;
unsigned char *to;

dccp_timestamp(sk, &now);
elapsed_time = timeval_delta(&now, &dp->dccps_timestamp_time) / 10;
elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
len = 6 + elapsed_time_len;

if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) {
LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to insert "
"timestamp echo!\n");
Expand Down Expand Up @@ -623,7 +647,8 @@ static inline int dccp_ackpkts_set_buf_head_state(struct dccp_ackpkts *ap,
/*
* Implements the draft-ietf-dccp-spec-11.txt Appendix A
*/
int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state)
int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
u64 ackno, u8 state)
{
/*
* Check at the right places if the buffer is full, if it is, tell the
Expand Down Expand Up @@ -704,7 +729,7 @@ int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state)
}

ap->dccpap_buf_ackno = ackno;
do_gettimeofday(&ap->dccpap_time);
dccp_timestamp(sk, &ap->dccpap_time);
out:
dccp_pr_debug("");
dccp_ackpkts_print(ap);
Expand Down

0 comments on commit b0e5678

Please sign in to comment.