Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp320601ybt; Wed, 17 Jun 2020 01:37:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuci1XYEncnR38xRit4m4vN6zekXZulmN4vCLmJg5Mp6QD3DeveiCZ2tVbc0dQ9H4Xi3Vu X-Received: by 2002:a17:906:d933:: with SMTP id rn19mr6706450ejb.158.1592383039866; Wed, 17 Jun 2020 01:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592383039; cv=none; d=google.com; s=arc-20160816; b=bR6/rSFM0pyreyROzgGdjaptsYd7quEcREsYahzFS/2YSQul8DPGuaYAc3d+RdkIUv shFe3o7BgP0o/HxAdZlm0kmJEwdWI1FRx4xfT01rcjGNuMvo2MAOA3VmabeA4Th1KFr4 zA28XtWAu3lAtg3VYs+P2+iCy+BFCpflYeAFo3l5gd5w8BFKGT/CaN9nIPvVfpD6L6Tx 70a0OSI5vv4FavIo0mpY9ccQtLIZUNmHjoIzqMEbq9PD2R4yj98gugniNjNkioIrCR3I ome/0sldcBo3NXLofD1lEinYdO7gFoxPmIm+UqBIymQMnC2itg1PuVOhy7QpALCfM1PS sNDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=5H+jT63NAxBBST7kOx/P1a/pW2h6/MqbMo3gFh57CjI=; b=zlvAaRTE31aii9PPxmksHTX1KpgJx43OBD6K0YuSCjj4MCdfUlRacFu+D3fAwqIMof f5WSOtikVHxQN+uTdoXPm9rjqN29zxkqZHqu5IGXs9DEciVZwwGDUB8U7gskxKPz05Mb VT3iul6PBVkYz+3/nW4xeizA9Jl+3LD9OtknkBOyIB4OaxYufiDxlJXucmZtEs/aRqGQ TnkZp02AqhFC9mfZtQWJJwhX8p6gtEA9hkXyD96IbSHiOw+HXEIqCKrQR7u4etleLebu ldsVe/M67IHrbydeNe/q60xzaqP12OQRYCeUGtNmjCIAPTA5YywSvgxNGMXSo1+W2CFi bF9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt2si17306893ejc.596.2020.06.17.01.36.57; Wed, 17 Jun 2020 01:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbgFQIfP (ORCPT + 99 others); Wed, 17 Jun 2020 04:35:15 -0400 Received: from mga09.intel.com ([134.134.136.24]:54407 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbgFQIfP (ORCPT ); Wed, 17 Jun 2020 04:35:15 -0400 IronPort-SDR: qXqrtrXfFse8L5uWRcPTIcU8M6fviWNgYm//+Go/Wb8wUqBjTOHHrftrLOm9tKSRLVf33Gn0jj D18SQvKPflqQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2020 01:35:14 -0700 IronPort-SDR: CPl2CAlGSHear34zg8DRRs2qY4HgWSkP5KExPyafBurCQ2F9vlc6vK65blbeJgeng2Ekj631cJ krCOo1coEnMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,522,1583222400"; d="scan'208";a="273449186" Received: from linux.intel.com ([10.54.29.200]) by orsmga003.jf.intel.com with ESMTP; 17 Jun 2020 01:35:14 -0700 Received: from [10.249.225.191] (abudanko-mobl.ccr.corp.intel.com [10.249.225.191]) by linux.intel.com (Postfix) with ESMTP id BE20B580223; Wed, 17 Jun 2020 01:35:12 -0700 (PDT) Subject: [PATCH v8 01/13] tools/libperf: avoid moving of fds at fdarray__filter() call From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <0781a077-aa82-5b4a-273e-c17372a72b93@linux.intel.com> Organization: Intel Corp. Message-ID: <3d36dc7a-4249-096c-7554-80e6d290eac5@linux.intel.com> Date: Wed, 17 Jun 2020 11:35:11 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <0781a077-aa82-5b4a-273e-c17372a72b93@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Skip fds with zeroed revents field from count and avoid fds moving at fdarray__filter() call so fds indices returned by fdarray__add() call stay the same and can be used for direct access and processing of fd revents status field at entries array of struct fdarray object. Signed-off-by: Alexey Budankov --- tools/lib/api/fd/array.c | 11 +++++------ tools/perf/tests/fdarray.c | 20 ++------------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/tools/lib/api/fd/array.c b/tools/lib/api/fd/array.c index 58d44d5eee31..97843a837370 100644 --- a/tools/lib/api/fd/array.c +++ b/tools/lib/api/fd/array.c @@ -93,22 +93,21 @@ int fdarray__filter(struct fdarray *fda, short revents, return 0; for (fd = 0; fd < fda->nr; ++fd) { + if (!fda->entries[fd].revents) + continue; + if (fda->entries[fd].revents & revents) { if (entry_destructor) entry_destructor(fda, fd, arg); + fda->entries[fd].revents = fda->entries[fd].events = 0; continue; } - if (fd != nr) { - fda->entries[nr] = fda->entries[fd]; - fda->priv[nr] = fda->priv[fd]; - } - ++nr; } - return fda->nr = nr; + return nr; } int fdarray__poll(struct fdarray *fda, int timeout) diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c index c7c81c4a5b2b..d0c8a05aab2f 100644 --- a/tools/perf/tests/fdarray.c +++ b/tools/perf/tests/fdarray.c @@ -12,6 +12,7 @@ static void fdarray__init_revents(struct fdarray *fda, short revents) for (fd = 0; fd < fda->nr; ++fd) { fda->entries[fd].fd = fda->nr - fd; + fda->entries[fd].events = revents; fda->entries[fd].revents = revents; } } @@ -29,7 +30,7 @@ static int fdarray__fprintf_prefix(struct fdarray *fda, const char *prefix, FILE int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_unused) { - int nr_fds, expected_fd[2], fd, err = TEST_FAIL; + int nr_fds, err = TEST_FAIL; struct fdarray *fda = fdarray__new(5, 5); if (fda == NULL) { @@ -55,7 +56,6 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_ fdarray__init_revents(fda, POLLHUP); fda->entries[2].revents = POLLIN; - expected_fd[0] = fda->entries[2].fd; pr_debug("\nfiltering all but fda->entries[2]:"); fdarray__fprintf_prefix(fda, "before", stderr); @@ -66,17 +66,9 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_ goto out_delete; } - if (fda->entries[0].fd != expected_fd[0]) { - pr_debug("\nfda->entries[0].fd=%d != %d\n", - fda->entries[0].fd, expected_fd[0]); - goto out_delete; - } - fdarray__init_revents(fda, POLLHUP); fda->entries[0].revents = POLLIN; - expected_fd[0] = fda->entries[0].fd; fda->entries[3].revents = POLLIN; - expected_fd[1] = fda->entries[3].fd; pr_debug("\nfiltering all but (fda->entries[0], fda->entries[3]):"); fdarray__fprintf_prefix(fda, "before", stderr); @@ -88,14 +80,6 @@ int test__fdarray__filter(struct test *test __maybe_unused, int subtest __maybe_ goto out_delete; } - for (fd = 0; fd < 2; ++fd) { - if (fda->entries[fd].fd != expected_fd[fd]) { - pr_debug("\nfda->entries[%d].fd=%d != %d\n", fd, - fda->entries[fd].fd, expected_fd[fd]); - goto out_delete; - } - } - pr_debug("\n"); err = 0; -- 2.24.1