lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 6 Dec 2013 10:56:41 -0000
From:	"David Laight" <David.Laight@...LAB.COM>
To:	"Yang Yingliang" <yangyingliang@...wei.com>, <davem@...emloft.net>,
	<netdev@...r.kernel.org>
Cc:	<eric.dumazet@...il.com>, <brouer@...hat.com>, <jpirko@...hat.com>,
	<jbrouer@...hat.com>
Subject: RE: [PATCH net v6 1/2] net: sched: tbf: fix the calculation of max_size

> From: Yang Yingliang
...
> 
> +/* Time to Length, convert time in ns to length in bytes
> + * to determinate how many bytes can be sent in given time.
> + */
> +static u64 psched_ns_t2l(const struct psched_ratecfg *r,
> +			 u64 time_in_ns)
> +{
> +	/* The formula is :
> +	 * len = (time_in_ns * r->rate_bytes_ps) / NSEC_PER_SEC
> +	 */
> +	u64 len = time_in_ns * r->rate_bytes_ps;
> +
> +	do_div(len, NSEC_PER_SEC);

You are multiplying two values then dividing by 10**9
I'd guess that the intermediate value might exceed 2**64.

> +	if (unlikely(r->linklayer == TC_LINKLAYER_ATM))
> +		len = (len / 53) * 48;

You probably want to do the multiply first.
But why not scale rate_bytes_ps instead.

> +	if (len > r->overhead)
> +		len -= r->overhead;
> +	else
> +		len = 0;
> +
> +	return len;
> +}

Personally I'd work out how much time you have to send each byte.
So if you want a rate of 1MB/sec you have a 'time cost' per byte of 1000ns.
The cost of sending a packet is simply the length multiplied by this cost.
To work out whether a packet can be sent you have a credit variable that
tracks current time.
If 'credit > now' the packet can't be sent, queue and schedule a wakeup.
if 'credit + backlog < now' set credit = now - backlog.
if 'credit <= now' send the packet and add the packet's 'cost' to 'credit'.

In the non-ratelimited case this is almost no work.

You'd probably need to work in 1/1024ns time units and/or blocks of 16 bytes.

	David



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ