From patchwork Fri Nov 8 10:21:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kanas X-Patchwork-Id: 62757 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6DBE7A04B3; Fri, 8 Nov 2019 11:23:36 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 136281C0C0; Fri, 8 Nov 2019 11:21:55 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 4DF711C123 for ; Fri, 8 Nov 2019 11:21:51 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xA8AGXia007337; Fri, 8 Nov 2019 02:21:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=N04pQ0v9N8tf0SYeg7UREAOSX7H3DOmkRnfFqgnIFB8=; b=nWbi8YPaBdOHXFX1KzmnUjTfSRcZCIe5QZMUIW390z6vSU3rzUuq8dVzG8X3pR8p02iX Z1LfVLrwiwuqOQSIThzmGFahBSf8GvgCIRAI2aaDaDqeSWw6R0e3fhAjYHtmEUcG6j2e A0A/YWRLJgQbPm0OI+w4vEUs7g/S5Ec7OK+e0BQmV+/YDOF1rh7GVsyiZ5kc92W3J4KE OWi91zdYrOqNT9lNGIx8lpU73izZpxUYw/T/Mq4yK3IVxbiDEVElkJ+4AqxjLsy7YRY8 FZ55Bz3ETmemLIVHDzNm8O+c+NS/+j2Cly6xhtZRnxAtXK6lMFzXHtEcCTEt60fzrkvb mg== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2w4fq6whw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 08 Nov 2019 02:21:50 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 02:21:48 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 8 Nov 2019 02:21:48 -0800 Received: from kk-box-0.marvell.com (unknown [10.95.130.41]) by maili.marvell.com (Postfix) with ESMTP id A51293F703F; Fri, 8 Nov 2019 02:21:47 -0800 (PST) From: To: , , CC: Krzysztof Kanas Date: Fri, 8 Nov 2019 11:21:33 +0100 Message-ID: <20191108102135.7249-2-kkanas@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191108102135.7249-1-kkanas@marvell.com> References: <20191108102135.7249-1-kkanas@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-08_02:2019-11-07,2019-11-08 signatures=0 Subject: [dpdk-dev] [PATCH v3 1/3] test: fix timeout in flags autotest 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 Test eal_flags_autotest times out on 64 ARM due to excessive calls to 'access' system call. While at it fix process_dup logic so it tests correct file path for opened fd's. Fixes: af75078fece3 ("first public release") Cc: intel.com Signed-off-by: Krzysztof Kanas --- app/test/process.h | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 128ce41219a1..298ba288087a 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -11,6 +11,7 @@ #include /* NULL */ #include /* strerror */ #include /* readlink */ +#include #include #include /* strlcpy */ @@ -40,8 +41,12 @@ process_dup(const char *const argv[], int numargs, const char *env_value) { int num; char *argv_cpy[numargs + 1]; - int i, fd, status; + int i, fd, fdir, status; + struct dirent *dirent; + const char *procdir = "/proc/self/fd/"; char path[32]; + char *endptr; + DIR *dir; #ifdef RTE_LIBRTE_PDUMP pthread_t thread; #endif @@ -58,11 +63,39 @@ process_dup(const char *const argv[], int numargs, const char *env_value) /* close all open file descriptors, check /proc/self/fd to only * call close on open fds. Exclude fds 0, 1 and 2*/ - for (fd = getdtablesize(); fd > 2; fd-- ) { - snprintf(path, sizeof(path), "/proc/" exe "/fd/%d", fd); - if (access(path, F_OK) == 0) - close(fd); + dir = opendir(procdir); + if (dir == NULL) { + rte_panic("Error opening %s: %s\n", procdir, + strerror(errno)); } + + fdir = dirfd(dir); + if (fdir < 0) { + status = errno; + closedir(dir); + rte_panic("Error %d obtaining fd for dir %s: %s\n", + fdir, procdir, strerror(status)); + } + + while ((dirent = readdir(dir)) != NULL) { + if (!strcmp(".", dirent->d_name) || + !strcmp("..", dirent->d_name)) + continue; + + errno = 0; + fd = strtol(dirent->d_name, &endptr, 10); + if (errno != 0 || endptr[0] != '\0') { + printf("Error converint name fd %d %s:\n", + fd, dirent->d_name); + continue; + } + if (fd == fdir || fd <= 2) + continue; + + close(fd); + } + closedir(dir); + printf("Running binary with argv[]:"); for (i = 0; i < num; i++) printf("'%s' ", argv_cpy[i]); From patchwork Fri Nov 8 10:21:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kanas X-Patchwork-Id: 62759 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 905CFA04B3; Fri, 8 Nov 2019 11:23:51 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6FA621C18E; Fri, 8 Nov 2019 11:21:58 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id B486A1C036 for ; Fri, 8 Nov 2019 11:21:52 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xA8ALG65000689; Fri, 8 Nov 2019 02:21:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=/mgMmurjUoCM0T8alMNKUeuswL70Izc1VMe24W/aGdc=; b=pr7/V3oYFNNKXDZanberiAdCIUxVuL0VUDr0TX1yZzX2LMU1TnTUUZTAZRSTD/l5XYPp kW9V1xrJdt6q/1+8Th8ttk5AE3H5VhIIKLL0Mnkt3+ZwYTXgV+oPxCdnP15WK1WSXe0T UauDdXjs6QzCwShvKGVotEMNf+cWdozRsQIvDb5uAN43o3qznBwseVBv8zA6DBKyCPRg Y//E+4hwfbB46Rgk+ii5Zb1EAslEjeXvLmLlEf1KQBGAdUyPGiyfPK8m9P/hVZTa+NCR zw2slXJwsnZw9VIVqAd/E9jzcsdmqN4epKOMiCvZ7OsNF2n00J5tRoX1VfQgIFOJVQqU 2w== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2w511615dw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 08 Nov 2019 02:21:51 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 02:21:50 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 8 Nov 2019 02:21:50 -0800 Received: from kk-box-0.marvell.com (unknown [10.95.130.41]) by maili.marvell.com (Postfix) with ESMTP id 4B1723F7040; Fri, 8 Nov 2019 02:21:49 -0800 (PST) From: To: , , CC: Krzysztof Kanas Date: Fri, 8 Nov 2019 11:21:34 +0100 Message-ID: <20191108102135.7249-3-kkanas@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191108102135.7249-1-kkanas@marvell.com> References: <20191108102135.7249-1-kkanas@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-08_02:2019-11-07,2019-11-08 signatures=0 Subject: [dpdk-dev] [PATCH v3 2/3] test: move close files to separate function 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 As iterating over opened files is different on Linux and FreeBSD move to separate function. Signed-off-by: Krzysztof Kanas --- app/test/process.h | 89 ++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/app/test/process.h b/app/test/process.h index 298ba288087a..34afac5a1f39 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -30,6 +30,54 @@ extern void *send_pkts(void *empty); extern uint16_t flag_for_send_pkts; #endif + +/* close all open file descriptors, check /proc/self/fd to only + * call close on open fds. Exclude fds 0, 1 and 2 + */ +#ifdef RTE_EXEC_ENV_LINUX +static inline void +close_files(void) +{ + const char *procdir = "/proc/self/fd/"; + struct dirent *dirent; + int fd, fdir, status; + char *endptr; + DIR *dir; + + dir = opendir(procdir); + if (dir == NULL) { + rte_panic("Error opening %s: %s\n", procdir, + strerror(errno)); + } + + fdir = dirfd(dir); + if (fdir < 0) { + status = errno; + closedir(dir); + rte_panic("Error %d obtaining fd for dir %s: %s\n", + fdir, procdir, strerror(status)); + } + + while ((dirent = readdir(dir)) != NULL) { + if (!strcmp(".", dirent->d_name) || + !strcmp("..", dirent->d_name)) + continue; + + errno = 0; + fd = strtol(dirent->d_name, &endptr, 10); + if (errno != 0 || endptr[0] != '\0') { + printf("Error converint name fd %d %s:\n", + fd, dirent->d_name); + continue; + } + if (fd == fdir || fd <= 2) + continue; + + close(fd); + } + closedir(dir); +} +#endif /* * launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the @@ -41,12 +89,8 @@ process_dup(const char *const argv[], int numargs, const char *env_value) { int num; char *argv_cpy[numargs + 1]; - int i, fd, fdir, status; - struct dirent *dirent; - const char *procdir = "/proc/self/fd/"; + int i, status; char path[32]; - char *endptr; - DIR *dir; #ifdef RTE_LIBRTE_PDUMP pthread_t thread; #endif @@ -61,40 +105,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value) argv_cpy[i] = NULL; num = numargs; - /* close all open file descriptors, check /proc/self/fd to only - * call close on open fds. Exclude fds 0, 1 and 2*/ - dir = opendir(procdir); - if (dir == NULL) { - rte_panic("Error opening %s: %s\n", procdir, - strerror(errno)); - } - - fdir = dirfd(dir); - if (fdir < 0) { - status = errno; - closedir(dir); - rte_panic("Error %d obtaining fd for dir %s: %s\n", - fdir, procdir, strerror(status)); - } - - while ((dirent = readdir(dir)) != NULL) { - if (!strcmp(".", dirent->d_name) || - !strcmp("..", dirent->d_name)) - continue; - - errno = 0; - fd = strtol(dirent->d_name, &endptr, 10); - if (errno != 0 || endptr[0] != '\0') { - printf("Error converint name fd %d %s:\n", - fd, dirent->d_name); - continue; - } - if (fd == fdir || fd <= 2) - continue; - - close(fd); - } - closedir(dir); + close_files(); printf("Running binary with argv[]:"); for (i = 0; i < num; i++) From patchwork Fri Nov 8 10:21:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kanas X-Patchwork-Id: 62761 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BAED9A04B3; Fri, 8 Nov 2019 11:24:06 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E878F1C19C; Fri, 8 Nov 2019 11:22:01 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 535581C12B for ; Fri, 8 Nov 2019 11:21:54 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xA8AFsTk006980; Fri, 8 Nov 2019 02:21:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=C+L7Qmkj7Fln0xikmUICqREKSDSrfrf7J7a5HQFDFjY=; b=ENlz8/PcKNFM8nu4o+Q9G7QBCaSVcn3kZ6u2E8Q585kUK2/25ZF3WlzZE79vioJS6LaW Q5cBbGg51dUBJuSt+n8NDYqRs5v/KtPCVsx2XcGf/B2frsZoooRSfAKrwOQ+qkfuyJzC gL4JGWMY7LKUkQ3Gt/REAwfInPdVsYR0IXEslV654XzASlVUIiEWiAj9hM7fylxeLjFm ATb22fV6yGCNlumWyXa35oxUfCD1m74vMg1/Yk62K80Rz8YQd14Wi1VNoA+g7INwMKlb ZLM4fxCa4L6cnY2M+0qFuBcaG6w4io876CtY0UsuIHWZeMCbBhW5FfOJAYIO/fvr06R7 ag== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2w4fq6whw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 08 Nov 2019 02:21:53 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 8 Nov 2019 02:21:52 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 8 Nov 2019 02:21:52 -0800 Received: from kk-box-0.marvell.com (unknown [10.95.130.41]) by maili.marvell.com (Postfix) with ESMTP id E48DE3F703F; Fri, 8 Nov 2019 02:21:50 -0800 (PST) From: To: , , CC: Krzysztof Kanas Date: Fri, 8 Nov 2019 11:21:35 +0100 Message-ID: <20191108102135.7249-4-kkanas@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191108102135.7249-1-kkanas@marvell.com> References: <20191108102135.7249-1-kkanas@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-08_02:2019-11-07,2019-11-08 signatures=0 Subject: [dpdk-dev] [PATCH v3 3/3] test: fix FreeBSD file closing function 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 The FreeBSD was iterating over non existing procfs entries, where sysctl could give same information. Signed-off-by: Krzysztof Kanas --- app/test/process.h | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/app/test/process.h b/app/test/process.h index 34afac5a1f39..77bf11316355 100644 --- a/app/test/process.h +++ b/app/test/process.h @@ -16,6 +16,13 @@ #include /* strlcpy */ +#ifdef RTE_EXEC_ENV_FREEBSD +#include +#include +#include +#include +#endif + #ifdef RTE_EXEC_ENV_FREEBSD #define self "curproc" #define exe "file" @@ -34,7 +41,49 @@ extern uint16_t flag_for_send_pkts; /* close all open file descriptors, check /proc/self/fd to only * call close on open fds. Exclude fds 0, 1 and 2 */ -#ifdef RTE_EXEC_ENV_LINUX +#ifdef RTE_EXEC_ENV_FREEBSD +static inline void +close_files(void) +{ + int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC }; + size_t sysctl_len; + void *oldp; + int ret; + + mib[3] = getpid(); + ret = sysctl(mib, 4, NULL, &sysctl_len, NULL, 0); + if (ret < 0) { + rte_panic("Error sysctl failed %d %d %s\n", ret, errno, + strerror(errno)); + return; + } + oldp = malloc(sysctl_len); + if (!oldp) { + rte_panic("Error malloc failed\n"); + return; + } + ret = sysctl(mib, 4, oldp, &sysctl_len, NULL, 0); + if (ret < 0) { + ret = errno; + free(oldp); + rte_panic("Error sysctl failed %d %d %s\n", ret, errno, + strerror(errno)); + } + char *curr = oldp, *end = (char *)oldp + sysctl_len; + struct kinfo_file *kf_info; + while (curr < end) { + kf_info = (struct kinfo_file *)curr; + if (kf_info->kf_fd <= 2) { + curr += kf_info->kf_structsize; + continue; + } + close(kf_info->kf_fd); + curr += kf_info->kf_structsize; + } + free(oldp); +} + +#else static inline void close_files(void) {