From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Ananyev, Konstantin" Subject: Re: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd Date: Wed, 30 Dec 2015 11:29:33 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836ADF256@irsmsx105.ger.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> <8F6C2BD409508844A0EFC19955BE09418645CE@SHSMSX103.ccr.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable To: "Wang, Zhihong" , "dev@dpdk.org" Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id D34BE594B for ; Wed, 30 Dec 2015 12:29:36 +0100 (CET) In-Reply-To: <8F6C2BD409508844A0EFC19955BE09418645CE@SHSMSX103.ccr.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" > -----Original Message----- > From: Wang, Zhihong > Sent: Wednesday, December 30, 2015 3:15 AM > To: Ananyev, Konstantin; dev@dpdk.org > Cc: stephen@networkplumber.org; Qiu, Michael > Subject: RE: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in = l3fwd >=20 > > > +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; > > > > Why do you need it at each iteration? >=20 > Only become true when the first enabled port about to started. In case th= ere's no port enabled at all. > In my opinion no need to optimize since it's not performance sensitive an= d the logic is correct :) >=20 >=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; > > > +} >=20 > [...] >=20 > > > +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 { > > > > > > 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= master > > lcore would be in the middle of start_ports()->rte_eth_dev_start(). >=20 > Good point! Then we need rte_atomic16_cmpset() to avoid the race conditio= n. >=20 >=20 > > Probably not a big deal, but why do you need this if (port_started) {.= ..} else {...} > > at all? > > Why not just: >=20 > 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 = down, it'll wait a long time for initialization (memory, etc.) before > the force_quit signal take effect. Do you mean rte_eal_init()? Then why not to install non-default signal handlers after rte_eal_init()? Konstantin >=20 >=20 > > > > signal_handler(int signum) > > { > > signo_quit =3D signum; > > force_quit =3D true; > > } > > ? > > > > Konstantin > > > > > + printf("Ports not started yet...\n"); > > > + printf("Bye...\n"); > > > + /* exit with the expected status */ > > > + signal(signum, SIG_DFL); > > > + kill(getpid(), signum); > > > + } > > > + } > > > +} > > > +