From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F841A0353; Tue, 12 Nov 2019 21:32:03 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A41E0397D; Tue, 12 Nov 2019 21:32:01 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 18FD32C15 for ; Tue, 12 Nov 2019 21:32:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573590719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDG237trJwoMSZ4sy3ST+pDShtME1ChapwQ/uTTDVpQ=; b=FRRPhkPhBh+IJaZ1lRnmnQrL3oG0fqxKYr7P8oA0S/z/CI0sZ5hpA97wjcI1NKqama3hnk DNzaEXfPf/iQmv78/PpSvOmVbZEyhlhWVt9y4+qPk2phQg3/JnH9rY+fjV20+6greQQV9f rrzyhSdLP4oYlVETekMnGQMI2sQX8n4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-HPt7vpGoOoC-SH8f58BgkQ-1; Tue, 12 Nov 2019 15:31:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D66DADBA6; Tue, 12 Nov 2019 20:31:54 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.205.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 690914D6F1; Tue, 12 Nov 2019 20:31:53 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: kkanas@marvell.com, stable@dpdk.org Date: Tue, 12 Nov 2019 21:31:02 +0100 Message-Id: <1573590662-31370-1-git-send-email-david.marchand@redhat.com> In-Reply-To: <20190902075251.2917-1-kkanas@marvell.com> References: <20190902075251.2917-1-kkanas@marvell.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: HPt7vpGoOoC-SH8f58BgkQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH v4] test: optimise fd closing in forked test process X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Krzysztof Kanas Caught while investigating timeouts on a ARM64 server. Stracing a test process running the eal_flags_autotest, we can see that the fork helper is checking all possible file descriptors from getdtablesize() to 2, and close the existing ones. We can do better by inspecting this forked process /proc/self/fd directory. Besides, checking file descriptors via /proc/self/fd only makes sense for Linux. This code was a noop on FreeBSD. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Krzysztof Kanas Signed-off-by: David Marchand --- Changelog since v3: - rewrote commit log message, - restricted the fix to Linux only, --- app/test/process.h | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 128ce41..191d279 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -11,6 +11,7 @@ #include /* NULL */ #include /* strerror */ #include /* readlink */ +#include #include =20 #include /* strlcpy */ @@ -40,7 +41,7 @@ process_dup(const char *const argv[], int numargs, const = char *env_value) { =09int num; =09char *argv_cpy[numargs + 1]; -=09int i, fd, status; +=09int i, status; =09char path[32]; #ifdef RTE_LIBRTE_PDUMP =09pthread_t thread; @@ -56,13 +57,50 @@ process_dup(const char *const argv[], int numargs, cons= t char *env_value) =09=09argv_cpy[i] =3D NULL; =09=09num =3D numargs; =20 -=09=09/* close all open file descriptors, check /proc/self/fd to only -=09=09 * call close on open fds. Exclude fds 0, 1 and 2*/ -=09=09for (fd =3D getdtablesize(); fd > 2; fd-- ) { -=09=09=09snprintf(path, sizeof(path), "/proc/" exe "/fd/%d", fd); -=09=09=09if (access(path, F_OK) =3D=3D 0) +#ifdef RTE_EXEC_ENV_LINUX +=09=09{ +=09=09=09const char *procdir =3D "/proc/" self "/fd/"; +=09=09=09struct dirent *dirent; +=09=09=09char *endptr; +=09=09=09int fd, fdir; +=09=09=09DIR *dir; + +=09=09=09/* close all open file descriptors, check /proc/self/fd +=09=09=09 * to only call close on open fds. Exclude fds 0, 1 and +=09=09=09 * 2 +=09=09=09 */ +=09=09=09dir =3D opendir(procdir); +=09=09=09if (dir =3D=3D NULL) { +=09=09=09=09rte_panic("Error opening %s: %s\n", procdir, +=09=09=09=09=09=09strerror(errno)); +=09=09=09} + +=09=09=09fdir =3D dirfd(dir); +=09=09=09if (fdir < 0) { +=09=09=09=09status =3D errno; +=09=09=09=09closedir(dir); +=09=09=09=09rte_panic("Error %d obtaining fd for dir %s: %s\n", +=09=09=09=09=09=09fdir, procdir, +=09=09=09=09=09=09strerror(status)); +=09=09=09} + +=09=09=09while ((dirent =3D readdir(dir)) !=3D NULL) { +=09=09=09=09errno =3D 0; +=09=09=09=09fd =3D strtol(dirent->d_name, &endptr, 10); +=09=09=09=09if (errno !=3D 0 || endptr[0] !=3D '\0') { +=09=09=09=09=09printf("Error converting name fd %d %s:\n", +=09=09=09=09=09=09fd, dirent->d_name); +=09=09=09=09=09continue; +=09=09=09=09} + +=09=09=09=09if (fd =3D=3D fdir || fd <=3D 2) +=09=09=09=09=09continue; + =09=09=09=09close(fd); +=09=09=09} +=09=09=09closedir(dir); =09=09} +#endif =09=09printf("Running binary with argv[]:"); =09=09for (i =3D 0; i < num; i++) =09=09=09printf("'%s' ", argv_cpy[i]); --=20 1.8.3.1