Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1210364imm; Fri, 27 Jul 2018 13:05:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcHErH5BfwjHLUqyXrLepbqVKiZX8G/SQW8klHb/rEHOge7HQUh6pD5LekB83gahNSlovsY X-Received: by 2002:a17:902:3a2:: with SMTP id d31-v6mr7423971pld.287.1532721942944; Fri, 27 Jul 2018 13:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532721942; cv=none; d=google.com; s=arc-20160816; b=QhToSYGSY+3YQTvNdP4oTw4Dr8f6Ie0v9cPZSJbMOy+6roO0fE0rduqV0AlRYKBNap sSofaoCX8Ec2560wYxT8x0XKfJ2MyRq854ON4ypU1djXcX9ZWe3PIOqvvd0P9SY9nnMx n1G4VckrjtsDibfSEZkbUkLwPh/IbspIehfEZdvPe+U+cVc8BVxVAqJKJ15KWz7Eb+XW 7h43AJYxLz2WwrLoJnv5eINg7JUgNIQm3pZwpGZieFQGS/SckqgUvLI7KxjKYOuaanri lcw6vmbFKTC36285fDbCXMvKiU6IJsenc10YxtNDQs+gkr9155LEaYsyVYBNPWVT+vwb 0pGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=sCZu3HJPWgU7dkJBx0nJ7DCiRuar8NwbSuuu7D6jZpk=; b=Mx8A/ortosAbFDkgO2gdsN2atFJeKMkdBBW67aAU8J9wIlu7uHn+GWObday2gbHs34 zyYTsq48rqSY7UgK07mv288MW+ouG9vqHowLQbTHidoVfYhqmiKRnb2pi0I0JUXg9+cY xkpMTwt33BoM2RT6ftQ/OsJycVLWWgyYtesyxY4cnXF9n88DVYR4ABDtK9c4pTnkDyXE Ft/6wbx/JkgMTOqv9EjNbqHp67bFfhn9OsbGUeeix+OqkaYjpiZ0aIHQfRsRn9XAhHdf mdbdtRMU7tAKLCLzOEmJ3lVJqLy/6QfPRTXXc4zGcnIIeaZTkx1vlV8ues8nydkoouTR o5qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7-v6si4093113pgk.595.2018.07.27.13.05.28; Fri, 27 Jul 2018 13:05:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389541AbeG0V1v (ORCPT + 99 others); Fri, 27 Jul 2018 17:27:51 -0400 Received: from smtprelay0003.hostedemail.com ([216.40.44.3]:34542 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389337AbeG0V1v (ORCPT ); Fri, 27 Jul 2018 17:27:51 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay08.hostedemail.com (Postfix) with ESMTP id 28163182CF69F; Fri, 27 Jul 2018 20:04:25 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:2:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:2194:2197:2199:2200:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3622:3653:3865:3866:3867:3868:3872:4117:4250:4321:4605:5007:6119:7903:8603:9121:10004:10848:11026:11232:11233:11473:11657:11658:11914:12043:12295:12296:12438:12555:12679:12740:12760:12895:12986:13255:13439:13870:14096:14097:14659:21080:21221:21433:21451:21611:21627:30012:30046:30054:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: pigs55_7db3e850f6508 X-Filterd-Recvd-Size: 6309 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA; Fri, 27 Jul 2018 20:04:23 +0000 (UTC) Message-ID: Subject: Re: [PATCH net-next] net: ethernet: ti: cpsw: replace unnecessarily macroses on functions From: Joe Perches To: Ivan Khoronzhuk Cc: grygorii.strashko@ti.com, davem@davemloft.net, linux-omap@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 27 Jul 2018 13:04:22 -0700 In-Reply-To: <20180727193641.GA2619@khorivan> References: <20180727191318.18698-1-ivan.khoronzhuk@linaro.org> <98a6d1cd4d313512d66ced3fc25f438449b3c310.camel@perches.com> <20180727193641.GA2619@khorivan> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-07-27 at 22:36 +0300, Ivan Khoronzhuk wrote: > On Fri, Jul 27, 2018 at 12:21:07PM -0700, Joe Perches wrote: > > On Fri, 2018-07-27 at 22:13 +0300, Ivan Khoronzhuk wrote: > > > Replace ugly macroses on functions. > > > > Careful, see below. > > > > > diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c > > > > [] > > > @@ -565,40 +565,40 @@ static const struct cpsw_stats cpsw_gstrings_ch_stats[] = { > > > (func)(slave++, ##arg); \ > > > } while (0) > > > > > > -#define cpsw_dual_emac_src_port_detect(cpsw, status, ndev, skb) \ > > > - do { \ > > > - if (!cpsw->data.dual_emac) \ > > > - break; \ > > > - if (CPDMA_RX_SOURCE_PORT(status) == 1) { \ > > > - ndev = cpsw->slaves[0].ndev; \ > > > - skb->dev = ndev; \ > > > - } else if (CPDMA_RX_SOURCE_PORT(status) == 2) { \ > > > - ndev = cpsw->slaves[1].ndev; \ > > > - skb->dev = ndev; \ > > > - } \ > > > - } while (0) > > > -#define cpsw_add_mcast(cpsw, priv, addr) \ > > > - do { \ > > > - if (cpsw->data.dual_emac) { \ > > > - struct cpsw_slave *slave = cpsw->slaves + \ > > > - priv->emac_port; \ > > > - int slave_port = cpsw_get_slave_port( \ > > > - slave->slave_num); \ > > > - cpsw_ale_add_mcast(cpsw->ale, addr, \ > > > - 1 << slave_port | ALE_PORT_HOST, \ > > > - ALE_VLAN, slave->port_vlan, 0); \ > > > - } else { \ > > > - cpsw_ale_add_mcast(cpsw->ale, addr, \ > > > - ALE_ALL_PORTS, \ > > > - 0, 0, 0); \ > > > - } \ > > > - } while (0) > > > - > > > static inline int cpsw_get_slave_port(u32 slave_num) > > > { > > > return slave_num + 1; > > > } > > > > > > +static inline void cpsw_src_port_detect(struct cpsw_common *cpsw, int status, > > > + struct sk_buff *skb) > > > +{ > > > + if (!cpsw->data.dual_emac) > > > + return; > > > + > > > + if (CPDMA_RX_SOURCE_PORT(status) == 1) > > > + skb->dev = cpsw->slaves[0].ndev; > > > + else if (CPDMA_RX_SOURCE_PORT(status) == 2) > > > + skb->dev = cpsw->slaves[1].ndev; > > > +} > > > > perhaps better as a switch/case > > not better, it's shorter. True for the source code but it compiles to more object code. $ cat foo.c struct cpsw_common { struct { int dual_emac; } data; struct { int ndev; } slaves[2]; }; struct sk_buff { int dev; }; #define CPDMA_RX_SOURCE_PORT(__status__) ((__status__ >> 16) & 0x7) #if defined SWITCH void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb) { if (!cpsw->data.dual_emac) return; switch (CPDMA_RX_SOURCE_PORT(status)) { case 1: skb->dev = cpsw->slaves[0].ndev; break; case 2: skb->dev = cpsw->slaves[1].ndev; break; } } #else void foo(struct cpsw_common *cpsw, int status, struct sk_buff *skb) { if (!cpsw->data.dual_emac) return; if (CPDMA_RX_SOURCE_PORT(status) == 1) skb->dev = cpsw->slaves[0].ndev; else if (CPDMA_RX_SOURCE_PORT(status) == 2) skb->dev = cpsw->slaves[1].ndev; } #endif $ gcc -c -O2 -DSWITCH foo.c $ size foo.o text data bss dec hex filename 94 0 0 94 5e foo.o $ objdump -d foo.o foo.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 : 0: 8b 07 mov (%rdi),%eax 2: 85 c0 test %eax,%eax 4: 74 15 je 1b 6: c1 fe 10 sar $0x10,%esi 9: 83 e6 07 and $0x7,%esi c: 83 fe 01 cmp $0x1,%esi f: 74 17 je 28 11: 83 fe 02 cmp $0x2,%esi 14: 75 0a jne 20 16: 8b 47 08 mov 0x8(%rdi),%eax 19: 89 02 mov %eax,(%rdx) 1b: f3 c3 repz retq 1d: 0f 1f 00 nopl (%rax) 20: f3 c3 repz retq 22: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) 28: 8b 47 04 mov 0x4(%rdi),%eax 2b: 89 02 mov %eax,(%rdx) 2d: c3 retq $ gcc -c -O2 foo.c $ size foo.o text data bss dec hex filename 102 0 0 102 66 foo.o $ objdump -d foo.o foo.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 : 0: 8b 07 mov (%rdi),%eax 2: 85 c0 test %eax,%eax 4: 74 10 je 16 6: c1 fe 10 sar $0x10,%esi 9: 83 e6 07 and $0x7,%esi c: 83 fe 01 cmp $0x1,%esi f: 74 0f je 20 11: 83 fe 02 cmp $0x2,%esi 14: 74 1a je 30 16: f3 c3 repz retq 18: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) 1f: 00 20: 8b 47 04 mov 0x4(%rdi),%eax 23: 89 02 mov %eax,(%rdx) 25: c3 retq 26: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 2d: 00 00 00 30: 8b 47 08 mov 0x8(%rdi),%eax 33: 89 02 mov %eax,(%rdx) 35: c3 retq