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 5C9F0A04F5 for ; Wed, 11 Dec 2019 22:28:27 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 545621D9E; Wed, 11 Dec 2019 22:28:27 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id A73251D9E for ; Wed, 11 Dec 2019 22:28:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576099705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GfJjeovGzD/yAORf5rwSaieP4gd5EkXTKYpmnQakjD8=; b=GDriSFu8urGPSxJ7FRNhb1ingmEjanpOcCc+oxOwaUTSZbQnrqg2ID675T2N90e8uSw451 VN51UhGSYQHWbkdgrbBK/jOseKE2UIbuDj8+tZcOoNjda/F3rX1bD9oE1Q8D/pdnQg8kak KWjAc/15/mjGrg9QBc4f75zVaH+SB60= 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-218-718QHL-4Owa6tWnNCYiQ2g-1; Wed, 11 Dec 2019 16:28:21 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE966DBFB; Wed, 11 Dec 2019 21:28:20 +0000 (UTC) Received: from rh.redhat.com (ovpn-116-64.ams2.redhat.com [10.36.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3421510013A1; Wed, 11 Dec 2019 21:28:17 +0000 (UTC) From: Kevin Traynor To: Krzysztof Kanas Cc: David Marchand , Kevin Traynor , dpdk stable Date: Wed, 11 Dec 2019 21:26:17 +0000 Message-Id: <20191211212702.27851-25-ktraynor@redhat.com> In-Reply-To: <20191211212702.27851-1-ktraynor@redhat.com> References: <20191211212702.27851-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 718QHL-4Owa6tWnNCYiQ2g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] patch 'test: optimise fd closing in forks' has been queued to LTS release 18.11.6 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.6 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/17/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasi= ng (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/c8d8fad706afba896d= d43f38f41caa1923e7d977 Thanks. Kevin. --- >From c8d8fad706afba896dd43f38f41caa1923e7d977 Mon Sep 17 00:00:00 2001 From: Krzysztof Kanas Date: Tue, 12 Nov 2019 21:31:02 +0100 Subject: [PATCH] test: optimise fd closing in forks [ upstream commit 18562261abadfbdf7e19006c381bcb1d6fd6c2fe ] 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") Signed-off-by: Krzysztof Kanas Signed-off-by: David Marchand Tested-by: Krzysztof Kanas Acked-by: Kevin Traynor --- test/test/process.h | 51 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/test/test/process.h b/test/test/process.h index ba3a18502..f87ff6e72 100644 --- a/test/test/process.h +++ b/test/test/process.h @@ -10,4 +10,5 @@ #include /* NULL */ #include /* readlink */ +#include =20 #ifdef RTE_EXEC_ENV_BSDAPP @@ -30,6 +31,5 @@ process_dup(const char *const argv[], int numargs, const = char *env_value) =09int num; =09char *argv_cpy[numargs + 1]; -=09int i, fd, status; -=09char path[32]; +=09int i, status; =20 =09pid_t pid =3D fork(); @@ -43,11 +43,48 @@ process_dup(const char *const argv[], int numargs, cons= t char *env_value) =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++) --=20 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-= empty: --- --- -=092019-12-11 21:24:14.704348768 +0000 +++ 0025-test-optimise-fd-closing-in-forks.patch=092019-12-11 21:24:12.6276= 52044 +0000 @@ -1 +1 @@ -From 18562261abadfbdf7e19006c381bcb1d6fd6c2fe Mon Sep 17 00:00:00 2001 +From c8d8fad706afba896dd43f38f41caa1923e7d977 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 18562261abadfbdf7e19006c381bcb1d6fd6c2fe ] + @@ -18 +19,0 @@ -Cc: stable@dpdk.org @@ -25,2 +26,2 @@ - app/test/process.h | 50 ++++++++++++++++++++++++++++++++++++++++------ - 1 file changed, 44 insertions(+), 6 deletions(-) + test/test/process.h | 51 ++++++++++++++++++++++++++++++++++++++------- + 1 file changed, 44 insertions(+), 7 deletions(-) @@ -28,6 +29,6 @@ -diff --git a/app/test/process.h b/app/test/process.h -index 128ce4121..191d2796a 100644 ---- a/app/test/process.h -+++ b/app/test/process.h -@@ -12,4 +12,5 @@ - #include /* strerror */ +diff --git a/test/test/process.h b/test/test/process.h +index ba3a18502..f87ff6e72 100644 +--- a/test/test/process.h ++++ b/test/test/process.h +@@ -10,4 +10,5 @@ + #include /* NULL */ @@ -36 +36,0 @@ - #include @@ -38 +38,2 @@ -@@ -41,5 +42,5 @@ process_dup(const char *const argv[], int numargs, const= char *env_value) + #ifdef RTE_EXEC_ENV_BSDAPP +@@ -30,6 +31,5 @@ process_dup(const char *const argv[], int numargs, const= char *env_value) @@ -41,0 +43 @@ +-=09char path[32]; @@ -43,3 +45,3 @@ - =09char path[32]; - #ifdef RTE_LIBRTE_PDUMP -@@ -57,11 +58,48 @@ process_dup(const char *const argv[], int numargs, con= st char *env_value) +=20 + =09pid_t pid =3D fork(); +@@ -43,11 +43,48 @@ process_dup(const char *const argv[], int numargs, con= st char *env_value)