From mboxrd@z Thu Jan 1 00:00:00 1970 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) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 30 Dec 2015 03:29:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,500,1444719600"; d="scan'208";a="717450787" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by orsmga003.jf.intel.com with ESMTP; 30 Dec 2015 03:29:34 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.104]) by IRSMSX101.ger.corp.intel.com ([169.254.1.134]) with mapi id 14.03.0248.002; Wed, 30 Dec 2015 11:29:34 +0000 From: "Ananyev, Konstantin" To: "Wang, Zhihong" , "dev@dpdk.org" Thread-Topic: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in l3fwd Thread-Index: AQHRQhJJmo/zzLdiZkephgyQllCcq57h8K/AgADrzwCAAImzMA== 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> In-Reply-To: <8F6C2BD409508844A0EFC19955BE09418645CE@SHSMSX103.ccr.corp.intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZWZkMjhkY2ItNGRlNy00YmE2LWIwYzAtMjRlYTdmMjBkYWRjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjQuMTAuMTkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibEg0UCtqYVRpK2FsZlFkTHVQZkFjTkErXC84Y2NjZXoxUzlhTnd4bHgwTGc9In0= x-ctpclassification: CTP_IC x-originating-ip: [163.33.239.182] 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 11:29:37 -0000 > -----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); > > > + } > > > + } > > > +} > > > +