From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Wang, Zhihong" Subject: Re: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable To: "Ananyev, Konstantin" , "dev@dpdk.org" 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) In-Reply-To: <2601191342CEEE43887BDE71AB97725836ADDED8@irsmsx105.ger.corp.intel.com> Content-Language: en-US List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > > +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); > > + } > > + } > > +} > > +