netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rick Jones <rick.jones2@hp.com>
To: netdev@vger.kernel.org
Subject: [PATCH] [RFC] allow admin/users to specify rto_min in milliseconds rather than jiffies
Date: Tue, 4 Sep 2007 13:20:47 -0700 (PDT)	[thread overview]
Message-ID: <200709042020.NAA29612@tardy.cup.hp.com> (raw)

Build upon David Miller's initial patches to set the per-route rto_min
so users can specify the rto_min in the same units (milliseconds) in
which they are displayed.  This is desirable because asking users to
convert to and from jiffies themselves, when there can be different
values of HZ from system to system would be error prone.

Signed-off-by: Rick Jones <rick.jones2@hp.com>
---

*** ./lib/utils.c.orig	2007-09-04 13:11:01.000000000 -0700
--- ./lib/utils.c	2007-09-04 13:06:11.000000000 -0700
***************
*** 61,66 ****
--- 61,141 ----
  	return 0;
  }
  
+ /* liberally lifted from kernel/time.c. raj */
+ unsigned int jiffies_to_msecs(const unsigned long j)
+ {
+ 	if (__iproute2_hz_internal == 0)
+ 		__iproute2_hz_internal = __get_hz();
+  
+ 	if ((__iproute2_hz_internal <= 1000) && 
+ 		!(1000 % __iproute2_hz_internal))
+ 		return (1000 / __iproute2_hz_internal) * j;
+ 	else if (__iproute2_hz_internal > 1000 && 
+ 		!(__iproute2_hz_internal % 1000))
+ 		return (j + (__iproute2_hz_internal / 1000) - 1) /
+ 			(__iproute2_hz_internal / 1000);
+ 	else
+         	return (j * 1000) / __iproute2_hz_internal;
+ }
+ 
+ /* liberally lifted from kernel/time.c  raj */
+ unsigned long msecs_to_jiffies(const unsigned int m)
+ {
+ 
+ 	if (__iproute2_hz_internal == 0)
+ 		__iproute2_hz_internal = __get_hz();
+ 
+ 	if (__iproute2_hz_internal <= 1000 && 
+ 		!(1000 % __iproute2_hz_internal))
+         	/*
+          	 * HZ is equal to or smaller than 1000, and 1000 is a nice
+          	 * round multiple of HZ, divide with the factor between them,
+          	 * but round upwards:
+          	 */
+ 		return (m + (1000 / __iproute2_hz_internal) - 1) / 
+ 			(1000 / __iproute2_hz_internal);
+ 	else if (__iproute2_hz_internal > 1000 && 
+ 		!(__iproute2_hz_internal % 1000)) {
+         	/*
+           	 * HZ is larger than 1000, and HZ is a nice round multiple of
+          	 * 1000 - simply multiply with the factor between them.
+          	 *
+          	 * But first make sure the multiplication result cannot
+          	 * overflow:
+          	 */
+         	if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
+                 	return MAX_JIFFY_OFFSET;
+ 
+ 		return m * (__iproute2_hz_internal / 1000);
+ 	}
+ 	else {
+         	/*
+          	 * Generic case - multiply, round and divide. But first
+          	 * check that if we are doing a net multiplication, that
+          	 * we wouldnt overflow:
+          	 */
+         	if (__iproute2_hz_internal > 1000 && 
+ 			m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
+                 	return MAX_JIFFY_OFFSET;
+ 
+ 		return (m * __iproute2_hz_internal + 1000 - 1) / 1000;
+ 	}
+ }
+ 
+ int get_unsigned_ms_to_jiffies(unsigned *val, const char *arg, int base)
+ {
+ 	int ret;
+ 	unsigned myval = *val;
+ 
+ 	if (__iproute2_hz_internal == 0)
+ 		__iproute2_hz_internal = __get_hz();
+ 	ret = get_unsigned(&myval,arg,base);
+ 	if (ret == -1 || myval > (UINT_MAX / __iproute2_hz_internal))
+ 		return -1;
+ 	*val = msecs_to_jiffies(myval);
+ 	return 0;
+ }	
+ 
  int get_u64(__u64 *val, const char *arg, int base)
  {
  	unsigned long long res;
*** ./include/utils.h.orig	2007-09-04 12:56:09.000000000 -0700
--- ./include/utils.h	2007-09-04 12:55:56.000000000 -0700
***************
*** 69,74 ****
--- 69,78 ----
  	u_int8_t  ipx_node[IPX_NODE_LEN];
  };
  
+ #ifndef MAX_JIFFY_OFFSET
+ #define MAX_JIFFY_OFFSET ((LONG_MAX >> 1)-1)
+ #endif
+ 
  extern __u32 get_addr32(const char *name);
  extern int get_addr_1(inet_prefix *dst, const char *arg, int family);
  extern int get_prefix_1(inet_prefix *dst, char *arg, int family);
***************
*** 77,82 ****
--- 81,87 ----
  
  extern int get_integer(int *val, const char *arg, int base);
  extern int get_unsigned(unsigned *val, const char *arg, int base);
+ extern int get_unsigned_ms_to_jiffies(unsigned *val, const char *arg, int base);
  #define get_byte get_u8
  #define get_ushort get_u16
  #define get_short get_s16
*** ./include/linux/rtnetlink.h.orig	2007-03-13 14:50:56.000000000 -0700
--- ./include/linux/rtnetlink.h	2007-08-31 13:27:36.000000000 -0700
***************
*** 352,357 ****
--- 352,359 ----
  #define RTAX_INITCWND RTAX_INITCWND
  	RTAX_FEATURES,
  #define RTAX_FEATURES RTAX_FEATURES
+ 	RTAX_RTO_MIN,
+ #define RTAX_RTO_MIN RTAX_RTO_MIN
  	__RTAX_MAX
  };
  
*** ./ip/iproute.c.orig	2007-08-31 13:15:45.000000000 -0700
--- ./ip/iproute.c	2007-09-04 13:02:42.000000000 -0700
***************
*** 51,56 ****
--- 51,57 ----
  	[RTAX_HOPLIMIT] = "hoplimit",
  	[RTAX_INITCWND] = "initcwnd",
  	[RTAX_FEATURES] = "features",
+ 	[RTAX_RTO_MIN]	= "rto_min",
  };
  static void usage(void) __attribute__((noreturn));
  
***************
*** 74,79 ****
--- 75,81 ----
  	fprintf(stderr, "           [ rtt NUMBER ] [ rttvar NUMBER ]\n");
  	fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
  	fprintf(stderr, "           [ ssthresh NUMBER ] [ realms REALM ]\n");
+ 	fprintf(stderr, "           [ rto_min NUMBER ]\n");
  	fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
  	fprintf(stderr, "          unreachable | prohibit | blackhole | nat ]\n");
  	fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
***************
*** 516,522 ****
  			if (mxlock & (1<<i))
  				fprintf(fp, " lock");
  
! 			if (i != RTAX_RTT && i != RTAX_RTTVAR)
  				fprintf(fp, " %u", *(unsigned*)RTA_DATA(mxrta[i]));
  			else {
  				unsigned val = *(unsigned*)RTA_DATA(mxrta[i]);
--- 518,525 ----
  			if (mxlock & (1<<i))
  				fprintf(fp, " lock");
  
! 			if (i != RTAX_RTT && i != RTAX_RTTVAR &&
! 			    i != RTAX_RTO_MIN)
  				fprintf(fp, " %u", *(unsigned*)RTA_DATA(mxrta[i]));
  			else {
  				unsigned val = *(unsigned*)RTA_DATA(mxrta[i]);
***************
*** 524,530 ****
  				val *= 1000;
  				if (i == RTAX_RTT)
  					val /= 8;
! 				else
  					val /= 4;
  				if (val >= hz)
  					fprintf(fp, " %ums", val/hz);
--- 527,533 ----
  				val *= 1000;
  				if (i == RTAX_RTT)
  					val /= 8;
! 				else if (i == RTAX_RTTVAR)
  					val /= 4;
  				if (val >= hz)
  					fprintf(fp, " %ums", val/hz);
***************
*** 823,828 ****
--- 826,840 ----
  			if (get_unsigned(&rtt, *argv, 0))
  				invarg("\"rtt\" value is invalid\n", *argv);
  			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT, rtt);
+ 		} else if (strcmp(*argv, "rto_min") == 0) {
+ 			unsigned rto_min;
+ 			NEXT_ARG();
+ 			mxlock |= (1<<RTAX_RTO_MIN);
+ 			if (get_unsigned_ms_to_jiffies(&rto_min, *argv, 0))
+ 				invarg("\"rto_min\" value is invalid\n",
+ 				       *argv);
+ 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
+ 				      rto_min);
  		} else if (matches(*argv, "window") == 0) {
  			unsigned win;
  			NEXT_ARG();

             reply	other threads:[~2007-09-04 20:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-04 20:20 Rick Jones [this message]
2007-09-05  6:38 ` [PATCH] [RFC] allow admin/users to specify rto_min in milliseconds rather than jiffies Stephen Hemminger
2007-09-05 17:11   ` Rick Jones
2007-09-06 21:17   ` Rick Jones
2007-09-12 20:28     ` Rick Jones
2007-09-13  8:39       ` Stephen Hemminger
2007-09-13 16:56         ` Rick Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200709042020.NAA29612@tardy.cup.hp.com \
    --to=rick.jones2@hp.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).