From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <lei.a.yao@intel.com>
Received: from mga04.intel.com (mga04.intel.com [192.55.52.120])
 by dpdk.org (Postfix) with ESMTP id EE2CB23C
 for <dev@dpdk.org>; Wed, 18 Jul 2018 17:58:41 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga003.jf.intel.com ([10.7.209.27])
 by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 18 Jul 2018 08:58:40 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.51,370,1526367600"; d="scan'208";a="67941823"
Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202])
 by orsmga003.jf.intel.com with ESMTP; 18 Jul 2018 08:58:33 -0700
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.319.2; Wed, 18 Jul 2018 08:58:32 -0700
Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by
 fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS)
 id 14.3.319.2; Wed, 18 Jul 2018 08:58:32 -0700
Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by
 SHSMSX103.ccr.corp.intel.com ([169.254.4.100]) with mapi id 14.03.0319.002;
 Wed, 18 Jul 2018 23:58:30 +0800
From: "Yao, Lei A" <lei.a.yao@intel.com>
To: "Burakov, Anatoly" <anatoly.burakov@intel.com>, "dev@dpdk.org"
 <dev@dpdk.org>
CC: "Richardson, Bruce" <bruce.richardson@intel.com>, "Xu, Qian Q"
 <qian.q.xu@intel.com>, "Lu, PeipeiX" <peipeix.lu@intel.com>
Thread-Topic: [PATCH] eal: fix circular dependency in EAL proc type detection
Thread-Index: AQHUHoW4vS7FQI7pnEyKnhhMOlx3z6SVIreA
Date: Wed, 18 Jul 2018 15:58:29 +0000
Message-ID: <2DBBFF226F7CF64BAFCA79B681719D953A4F9683@shsmsx102.ccr.corp.intel.com>
References: <be78bcd8da77c58dc43764e562295485f987ea71.1531911034.git.anatoly.burakov@intel.com>
In-Reply-To: <be78bcd8da77c58dc43764e562295485f987ea71.1531911034.git.anatoly.burakov@intel.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZTFlZWU1OTMtZDQyNC00MDJkLWJmZjMtZjZhZjgxOTk2Yzg5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibGpTVW5hOHdrNVBoUk9rZmJUNGhheDUxb3NtUU92NzdzSm42MHFzdUgxaEZhajZSaENEQnZWejdYOGZudndKVCJ9
x-ctpclassification: CTP_NT
dlp-product: dlpe-windows
dlp-version: 11.0.200.100
dlp-reaction: no-action
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] eal: fix circular dependency in EAL proc
	type detection
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 18 Jul 2018 15:58:42 -0000



> -----Original Message-----
> From: Burakov, Anatoly
> Sent: Wednesday, July 18, 2018 11:54 AM
> To: dev@dpdk.org
> Cc: Richardson, Bruce <bruce.richardson@intel.com>; Xu, Qian Q
> <qian.q.xu@intel.com>; Yao, Lei A <lei.a.yao@intel.com>; Lu, PeipeiX
> <peipeix.lu@intel.com>
> Subject: [PATCH] eal: fix circular dependency in EAL proc type detection
>=20
> Currently, we need runtime dir to put all of our runtime info in,
> including the DPDK shared config. However, we use the shared
> config to determine our proc type, and this happens earlier than
> we actually create the config dir and thus can know where to
> place the config file.
>=20
> Fix this by moving runtime dir creation right after the EAL
> arguments parsing, but before proc type autodetection. Also,
> previously we were creating the config file unconditionally,
> even if we specified no_shconf - fix it by only creating
> the config file if no_shconf is not set.
>=20
> Fixes: adf1d867361c ("eal: move runtime config file to new location")
>=20
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Tested-by: Yao Lei<lei.a.yao@intel.com>
This patch pass the test with simple_mp sample. The secondary process
can recognize itself as "secondary process" even use  "--proc-type=3Dauto"
parameter.=20
> ---
>  lib/librte_eal/bsdapp/eal/eal.c   | 33 ++++++++++++++++++-------------
>  lib/librte_eal/linuxapp/eal/eal.c | 33 ++++++++++++++++++-------------
>  2 files changed, 38 insertions(+), 28 deletions(-)
>=20
> diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/=
eal.c
> index 73cdf07b8..7b399bc9d 100644
> --- a/lib/librte_eal/bsdapp/eal/eal.c
> +++ b/lib/librte_eal/bsdapp/eal/eal.c
> @@ -286,12 +286,17 @@ eal_proc_type_detect(void)
>  	enum rte_proc_type_t ptype =3D RTE_PROC_PRIMARY;
>  	const char *pathname =3D eal_runtime_config_path();
>=20
> -	/* if we can open the file but not get a write-lock we are a secondary
> -	 * process. NOTE: if we get a file handle back, we keep that open
> -	 * and don't close it to prevent a race condition between multiple
> opens */
> -	if (((mem_cfg_fd =3D open(pathname, O_RDWR)) >=3D 0) &&
> -			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> -		ptype =3D RTE_PROC_SECONDARY;
> +	/* if there no shared config, there can be no secondary processes */
> +	if (!internal_config.no_shconf) {
> +		/* if we can open the file but not get a write-lock we are a
> +		 * secondary process. NOTE: if we get a file handle back, we
> +		 * keep that open and don't close it to prevent a race
> condition
> +		 * between multiple opens.
> +		 */
> +		if (((mem_cfg_fd =3D open(pathname, O_RDWR)) >=3D 0) &&
> +				(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> +			ptype =3D RTE_PROC_SECONDARY;
> +	}
>=20
>  	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
>  			ptype =3D=3D RTE_PROC_PRIMARY ? "PRIMARY" :
> "SECONDARY");
> @@ -468,6 +473,14 @@ eal_parse_args(int argc, char **argv)
>  		}
>  	}
>=20
> +	/* create runtime data directory */
> +	if (internal_config.no_shconf =3D=3D 0 &&
> +			eal_create_runtime_dir() < 0) {
> +		RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
> +		ret =3D -1;
> +		goto out;
> +	}
> +
>  	if (eal_adjust_config(&internal_config) !=3D 0) {
>  		ret =3D -1;
>  		goto out;
> @@ -600,14 +613,6 @@ rte_eal_init(int argc, char **argv)
>  		return -1;
>  	}
>=20
> -	/* create runtime data directory */
> -	if (internal_config.no_shconf =3D=3D 0 &&
> -			eal_create_runtime_dir() < 0) {
> -		rte_eal_init_alert("Cannot create runtime directory\n");
> -		rte_errno =3D EACCES;
> -		return -1;
> -	}
> -
>  	/* FreeBSD always uses legacy memory model */
>  	internal_config.legacy_mem =3D true;
>=20
> diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/=
eal/eal.c
> index d75ae9dae..d2d5aae80 100644
> --- a/lib/librte_eal/linuxapp/eal/eal.c
> +++ b/lib/librte_eal/linuxapp/eal/eal.c
> @@ -344,12 +344,17 @@ eal_proc_type_detect(void)
>  	enum rte_proc_type_t ptype =3D RTE_PROC_PRIMARY;
>  	const char *pathname =3D eal_runtime_config_path();
>=20
> -	/* if we can open the file but not get a write-lock we are a secondary
> -	 * process. NOTE: if we get a file handle back, we keep that open
> -	 * and don't close it to prevent a race condition between multiple
> opens */
> -	if (((mem_cfg_fd =3D open(pathname, O_RDWR)) >=3D 0) &&
> -			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> -		ptype =3D RTE_PROC_SECONDARY;
> +	/* if there no shared config, there can be no secondary processes */
> +	if (!internal_config.no_shconf) {
> +		/* if we can open the file but not get a write-lock we are a
> +		 * secondary process. NOTE: if we get a file handle back, we
> +		 * keep that open and don't close it to prevent a race
> condition
> +		 * between multiple opens.
> +		 */
> +		if (((mem_cfg_fd =3D open(pathname, O_RDWR)) >=3D 0) &&
> +				(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> +			ptype =3D RTE_PROC_SECONDARY;
> +	}
>=20
>  	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
>  			ptype =3D=3D RTE_PROC_PRIMARY ? "PRIMARY" :
> "SECONDARY");
> @@ -692,6 +697,14 @@ eal_parse_args(int argc, char **argv)
>  		}
>  	}
>=20
> +	/* create runtime data directory */
> +	if (internal_config.no_shconf =3D=3D 0 &&
> +			eal_create_runtime_dir() < 0) {
> +		RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
> +		ret =3D -1;
> +		goto out;
> +	}
> +
>  	if (eal_adjust_config(&internal_config) !=3D 0) {
>  		ret =3D -1;
>  		goto out;
> @@ -831,14 +844,6 @@ rte_eal_init(int argc, char **argv)
>  		return -1;
>  	}
>=20
> -	/* create runtime data directory */
> -	if (internal_config.no_shconf =3D=3D 0 &&
> -			eal_create_runtime_dir() < 0) {
> -		rte_eal_init_alert("Cannot create runtime directory\n");
> -		rte_errno =3D EACCES;
> -		return -1;
> -	}
> -
>  	if (eal_plugins_init() < 0) {
>  		rte_eal_init_alert("Cannot init plugins\n");
>  		rte_errno =3D EINVAL;
> --
> 2.17.1