aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/dccp.h
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@mandriva.com>2005-08-27 17:18:18 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 19:11:56 -0400
commitb6ee3d4ada4e85d9b9b9164c1327ef0850c79d5e (patch)
tree26dfc68ab042ebb8186fe3a93a34723cb1faaae1 /net/dccp/dccp.h
parent1f2333aea3269e196c44ae9a220e714cc1427792 (diff)
[CCID3]: Reorganise timeval handling
Introducing functions to add to or subtract from a timeval variable and renaming now_delta to timeval_new_delta that calls do_gettimeofday and then timeval_delta, that should be used when there are several deltas made relative to the current time or setting variables to it, so as to avoid calling do_gettimeofday excessively. I'm leaving these "timeval_" prefixed funcions internal to DCCP for a while till we're sure there are no subtle bugs in it. It also is more correct as it checks if the number of usecs added to or subtracted from a tv_usec field is more than 2 seconds. Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/dccp.h')
-rw-r--r--net/dccp/dccp.h44
1 files changed, 40 insertions, 4 deletions
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 6ba21509e797..5cd9e794bbe2 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -429,17 +429,53 @@ extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state);
429extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap, 429extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap,
430 struct sock *sk, u64 ackno); 430 struct sock *sk, u64 ackno);
431 431
432static inline suseconds_t timeval_usecs(const struct timeval *tv)
433{
434 return tv->tv_sec * USEC_PER_SEC + tv->tv_usec;
435}
436
437static inline suseconds_t timeval_delta(const struct timeval *large,
438 const struct timeval *small)
439{
440 time_t secs = large->tv_sec - small->tv_sec;
441 suseconds_t usecs = large->tv_usec - small->tv_usec;
442
443 if (usecs < 0) {
444 secs--;
445 usecs += USEC_PER_SEC;
446 }
447 return secs * USEC_PER_SEC + usecs;
448}
449
450static inline void timeval_add_usecs(struct timeval *tv,
451 const suseconds_t usecs)
452{
453 tv->tv_usec += usecs;
454 while (tv->tv_usec >= USEC_PER_SEC) {
455 tv->tv_sec++;
456 tv->tv_usec -= USEC_PER_SEC;
457 }
458}
459
460static inline void timeval_sub_usecs(struct timeval *tv,
461 const suseconds_t usecs)
462{
463 tv->tv_usec -= usecs;
464 while (tv->tv_usec < 0) {
465 tv->tv_sec--;
466 tv->tv_usec += USEC_PER_SEC;
467 }
468}
469
432/* 470/*
433 * Returns the difference in usecs between timeval 471 * Returns the difference in usecs between timeval
434 * passed in and current time 472 * passed in and current time
435 */ 473 */
436static inline u32 now_delta(struct timeval tv) 474static inline suseconds_t timeval_now_delta(const struct timeval *tv)
437{ 475{
438 struct timeval now; 476 struct timeval now;
439
440 do_gettimeofday(&now); 477 do_gettimeofday(&now);
441 return (now.tv_sec - tv.tv_sec) * USEC_PER_SEC + 478 return timeval_delta(&now, tv);
442 (now.tv_usec - tv.tv_usec);
443} 479}
444 480
445#ifdef CONFIG_IP_DCCP_DEBUG 481#ifdef CONFIG_IP_DCCP_DEBUG