From owner-svn-src-head@FreeBSD.ORG Wed Oct 17 13:59:10 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 487E8343; Wed, 17 Oct 2012 13:59:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 180118FC14; Wed, 17 Oct 2012 13:59:10 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 501B2B96C; Wed, 17 Oct 2012 09:59:09 -0400 (EDT) From: John Baldwin To: Maksim Yevmenkin Subject: Re: svn commit: r241616 - in head/sys: dev/ixgbe net Date: Wed, 17 Oct 2012 09:51:23 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p20; KDE/4.5.5; amd64; ; ) References: <201210162018.q9GKIG9q013028@svn.freebsd.org> <201210161702.06330.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201210170951.23800.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Wed, 17 Oct 2012 09:59:09 -0400 (EDT) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2012 13:59:10 -0000 On Tuesday, October 16, 2012 5:10:56 pm Maksim Yevmenkin wrote: > On Tue, Oct 16, 2012 at 2:02 PM, John Baldwin wrote: > > On Tuesday, October 16, 2012 4:18:16 pm Maksim Yevmenkin wrote: > >> Author: emax > >> Date: Tue Oct 16 20:18:15 2012 > >> New Revision: 241616 > >> URL: http://svn.freebsd.org/changeset/base/241616 > >> > >> Log: > >> introduce concept of ifi_baudrate power factor. the idea is to work > >> around the problem where high speed interfaces (such as ixgbe(4)) > >> are not able to report real ifi_baudrate. bascially, take a spare > >> byte from struct if_data and use it to store ifi_baudrate power > >> factor. in other words, > >> > >> real ifi_baudrate = ifi_baudrate * 10 ^ ifi_baudrate power factor > >> > >> this should be backwards compatible with old binaries. use ixgbe(4) > >> as an example on how drivers would set ifi_baudrate power factor > >> > >> Discussed with: kib, scottl, glebius > >> MFC after: 1 week > > > > It would be a lot nicer if you could still allow one to use more > > readable things like IF_Gbps(10). Note that we do have a 40G driver > > (mlxen) as well. > > > > Maybe a helper 'if_set_baudrate(ifp, IF_Gbps(10))' that would DTRT. > > (It could be a static inline or some such). I would just like to > > keep the readability. > > well, yes, i thought about it, but decided not to do it right away. we > could provide shortcuts/macros for "popular" baudrates, i.e. 1, 10, 40 > and 100 Gbps. while ixgbe(4) example is not ideal, i thought it still > was pretty readable :) I don't really find it all that readable. IF_Gbps(1) looks like a typo to a casual reader. I really think you should have something like: static __inline void if_initbaudrate(struct ifnet *ifp, uintmax_t baud) { ifp->if_baudrate_pf = 0; while (baud > ULONG_MAX) { baud /= 10; ifp->if_baudrate_pf++; } ifp->if_baudrate = baud; } I tested and with -O the compiler inlines that completely: void foo(void) { if_initbaudrate(&i1g, IF_Gbps(1)); if_initbaudrate(&i10g, IF_Gbps(10)); if_initbaudrate(&i40g, IF_Gbps(40)); } Disassembly (when ULONG_MAX is changed to UINT_MAX to simulate a 32-bit platform): 0000000000000000 : 0: c6 05 00 00 00 00 00 movb $0x0,0(%rip) # 7 7: 48 c7 05 00 00 00 00 movq $0x3b9aca00,0(%rip) # 12 e: 00 ca 9a 3b 12: c6 05 00 00 00 00 01 movb $0x1,0(%rip) # 19 19: 48 c7 05 00 00 00 00 movq $0x3b9aca00,0(%rip) # 24 20: 00 ca 9a 3b 24: c6 05 00 00 00 00 01 movb $0x1,0(%rip) # 2b 2b: c7 05 00 00 00 00 00 movl $0xee6b2800,0(%rip) # 35 32: 28 6b ee 35: c7 05 00 00 00 00 00 movl $0x0,0(%rip) # 3f 3c: 00 00 00 3f: c3 retq One issue though is that currently using 'IF_Gbps(10)' triggers a warning on 32-bit platforms. I'd mitigate that by changing IF_Kbps to cast (x) to a uintmax_t: #define IF_Kbps(x) ((uintmax_t)(x) * 1000) /* kilobits/sec. */ -- John Baldwin