From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 126EA8D93 for ; Wed, 30 Dec 2015 04:15:26 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 29 Dec 2015 19:15:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,498,1444719600"; d="scan'208";a="883230441" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga002.fm.intel.com with ESMTP; 29 Dec 2015 19:15:25 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 29 Dec 2015 19:15:25 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 29 Dec 2015 19:15:25 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.57]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.111]) with mapi id 14.03.0248.002; Wed, 30 Dec 2015 11:15:23 +0800 From: "Wang, Zhihong" To: "Ananyev, Konstantin" , "dev@dpdk.org" Thread-Topic: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd Thread-Index: AQHRQhJKGTHc2nOSeUqpBhdTMcsbSZ7hcPyAgAFfcZA= Date: Wed, 30 Dec 2015 03:15:22 +0000 Message-ID: <8F6C2BD409508844A0EFC19955BE09418645CE@SHSMSX103.ccr.corp.intel.com> References: <1451011032-83106-1-git-send-email-zhihong.wang@intel.com> <1451352032-105576-1-git-send-email-zhihong.wang@intel.com> <1451352032-105576-4-git-send-email-zhihong.wang@intel.com> <2601191342CEEE43887BDE71AB97725836ADDED8@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB97725836ADDED8@irsmsx105.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZWZkMjhkY2ItNGRlNy00YmE2LWIwYzAtMjRlYTdmMjBkYWRjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjQuMTAuMTkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibEg0UCtqYVRpK2FsZlFkTHVQZkFjTkErXC84Y2NjZXoxUzlhTnd4bHgwTGc9In0= x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2015 03:15:27 -0000 > > +static uint8_t > > +start_ports(void) > > +{ > > + unsigned portid, nb_ports, avail_ports; > > + int ret; > > + > > + nb_ports =3D rte_eth_dev_count(); > > + avail_ports =3D 0; > > + for (portid =3D 0; portid < nb_ports; portid++) { > > + if ((enabled_port_mask & (1 << portid)) =3D=3D 0) > > + continue; > > + avail_ports++; > > + port_started =3D true; >=20 > Why do you need it at each iteration? Only become true when the first enabled port about to started. In case ther= e's no port enabled at all. In my opinion no need to optimize since it's not performance sensitive and = the logic is correct :) >=20 > > + printf("Starting port %d...", portid); > > + ret =3D rte_eth_dev_start(portid); > > + if (ret < 0) > > + rte_exit(EXIT_FAILURE, > > + "rte_eth_dev_start: err=3D%d, port=3D%d\n", > > + ret, portid); > > + /* > > + * If enabled, put device in promiscuous mode. > > + * This allows IO forwarding mode to forward packets > > + * to itself through 2 cross-connected ports of the > > + * target machine. > > + */ > > + if (promiscuous_on) > > + rte_eth_promiscuous_enable(portid); > > + printf(" Done\n"); > > + } > > + > > + return avail_ports; > > +} [...] > > +static void > > +signal_handler(int signum) > > +{ > > + if (signum =3D=3D SIGINT || signum =3D=3D SIGTERM) { > > + printf("\nSignal %d received, preparing to exit...\n", > > + signum); > > + if (port_started) { > > + printf("Ports started already...\n"); > > + signo_quit =3D signum; > > + force_quit =3D true; > > + } else { >=20 >=20 > Hmm, and what if signal_handler() would be executed not in the context of > master lcore? > Then there could be a raise condition, and you could end up here, while m= aster > lcore would be in the middle of start_ports()->rte_eth_dev_start(). Good point! Then we need rte_atomic16_cmpset() to avoid the race condition. > Probably not a big deal, but why do you need this if (port_started) {...= } else {...} > at all? > Why not just: If no port has been started, then just kill itself. This is for cases like when you just started it and then want to shut it do= wn, it'll wait a long time for initialization (memory, etc.) before the for= ce_quit signal take effect. >=20 > signal_handler(int signum) > { > signo_quit =3D signum; > force_quit =3D true; > } > ? >=20 > Konstantin >=20 > > + printf("Ports not started yet...\n"); > > + printf("Bye...\n"); > > + /* exit with the expected status */ > > + signal(signum, SIG_DFL); > > + kill(getpid(), signum); > > + } > > + } > > +} > > +