From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id B92CF68A5 for ; Thu, 31 Dec 2015 03:14:30 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 30 Dec 2015 18:14:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,503,1444719600"; d="scan'208";a="872148601" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga001.fm.intel.com with ESMTP; 30 Dec 2015 18:14:29 -0800 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 30 Dec 2015 18:14:29 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 30 Dec 2015 18:14:29 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.57]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.183]) with mapi id 14.03.0248.002; Thu, 31 Dec 2015 10:14:27 +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: AQHRQhJKGTHc2nOSeUqpBhdTMcsbSZ7hcPyAgAFfcZCAABAHgIABfORg Date: Thu, 31 Dec 2015 02:14:26 +0000 Message-ID: <8F6C2BD409508844A0EFC19955BE0941864793@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> <8F6C2BD409508844A0EFC19955BE09418645CE@SHSMSX103.ccr.corp.intel.com> <2601191342CEEE43887BDE71AB97725836ADF256@irsmsx105.ger.corp.intel.com> In-Reply-To: <2601191342CEEE43887BDE71AB97725836ADF256@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: Thu, 31 Dec 2015 02:14:31 -0000 > -----Original Message----- > From: Ananyev, Konstantin > Sent: Wednesday, December 30, 2015 7:30 PM > To: Wang, Zhihong ; dev@dpdk.org > Cc: stephen@networkplumber.org; Qiu, Michael > Subject: RE: [PATCH v3 3/3] examples/l3fwd: Handle SIGINT and SIGTERM in > l3fwd >=20 >=20 >=20 > > -----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 > > > > > > +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? > > > > Only become true when the first enabled port about to started. In case = there's > no port enabled at all. > > In my opinion no need to optimize since it's not performance sensitive > > and the logic is correct :) > > > > > > > > > > > + 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 { > > > > > > > > > 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(). > > > > Good point! Then we need rte_atomic16_cmpset() to avoid the race condit= ion. > > > > > > > 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 down, it'll wait a long time for initialization (memory, etc.) befor= e the > force_quit signal take effect. >=20 > Do you mean rte_eal_init()? > Then why not to install non-default signal handlers after rte_eal_init()? > Konstantin Yes that does sounds better :) >=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); > > > > + } > > > > + } > > > > +} > > > > +