From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91C9AC43331 for ; Tue, 12 Nov 2019 20:32:03 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 01111206A3 for ; Tue, 12 Nov 2019 20:32:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FRRPhkPh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01111206A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org 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