Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp687814ybh; Tue, 21 Jul 2020 05:41:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKZEvSM/E0KI81FPPCKY0UObHjgH2CHxRXufT9nvn+d0N+9BqGa/IU8DUfsv61tmpkGgTc X-Received: by 2002:a05:6402:304a:: with SMTP id bu10mr24969688edb.70.1595335283622; Tue, 21 Jul 2020 05:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595335283; cv=none; d=google.com; s=arc-20160816; b=lsH/23OO7d5JYJzgBZt0bywawM1jzsy1F6uRkZT42sWjDLTQWNXITZZcka3T5phvZj /Fa5/O87ojmzriAij279Kqwi3tOnLKDDQNqufF1shn+jA7BuLwmTg55jNAduecpEIXNF UQJHJh/z6Ngmo1MsOCEd4yPExTvzVKeyLheY+34rNzmqChk4VYQqkVaN2/bPQDvboZOB yr3YSJIArY2X5KjlSJh4es20MXRtIVETx5vqioNnqohdT50R21rODOaW1KB/WT4HwICh Q4+nlhA5zJGU4vCCeeZTmMtfwSe2h/FvlqkipN28j9zJWcqqcVoy8NeYWPf+8nqW4jnM JgHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HNTQvmQ2hU7NipfvgwBAl01T9MmHqSTQ1GxJdIQBQ5s=; b=Gd4SeKGpHkrtR3JROHaLDlBvYN3aDb9m4U0WTLp9ZR7/xtQ9ewerD/0BP0VHbKlx1z ATISnDjA3bh8z5Jgu6izNHaTckS6YXkUAJAOHjqJyrlf51NT0kCzt/oYTWU4s5ZWBJ7b hbo4veY5W+hp7f5JVBrcZdxRhAsIMCKJHaVCH8jfz+c1FmtKChDhOmWOOHl8HqW7jhJG qb4cflrRzoP4+Ete8zxNRxWcvZ8ugFdnhNSrLJhHFAlBrDPxSlkbnqVZYKkGrjNVZOmo x6rrr+mKcfx4HTnEfMmC8xMj/rsU8oO6FPxXzUNvmQOHv2WjMSGXUVe1Yi5hbO+Gc5Bh cODA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D0wW7qRF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si13875529edw.59.2020.07.21.05.40.59; Tue, 21 Jul 2020 05:41:23 -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; dkim=pass header.i=@kernel.org header.s=default header.b=D0wW7qRF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728445AbgGUMke (ORCPT + 99 others); Tue, 21 Jul 2020 08:40:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:55210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726904AbgGUMke (ORCPT ); Tue, 21 Jul 2020 08:40:34 -0400 Received: from quaco.ghostprotocols.net (unknown [177.158.183.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7C111206E3; Tue, 21 Jul 2020 12:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595335233; bh=zhtZfIB5BknCY+2bjoZCAiIbHEgljW5xXcIqk2SSHKY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=D0wW7qRFmK73FBm5LYU2Fjxhk7CtdTXjM0+Hlwol6FL+EOBGffa6UDmfG4ryhGEQb DnFzh8nKSIg20b31y9LaK0ZpSM9W2gntOa4e2CUKtP424bN7CvehJoOeR7mrnmRxA8 VXlR2dOnsx4urAheU661pVYGdfoM685hh8qCFzWc= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 85769404B1; Tue, 21 Jul 2020 09:40:31 -0300 (-03) Date: Tue, 21 Jul 2020 09:40:31 -0300 From: Arnaldo Carvalho de Melo To: Alexey Budankov Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel Subject: Re: [PATCH v12 01/15] tools/libperf: avoid internal moving of fdarray fds Message-ID: <20200721124031.GF77866@kernel.org> References: <8d91c3a0-3db4-0a7a-ae13-299adb444bd6@linux.intel.com> <676844f8-55d3-c628-23db-aa163a81519e@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <676844f8-55d3-c628-23db-aa163a81519e@linux.intel.com> X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Jul 17, 2020 at 09:59:12AM +0300, Alexey Budankov escreveu: > > Avoid moving of fds by fdarray__filter() so fds indices returned > by fdarray__add() can be used for access and processing of > objects at struct pollfd *entries. Thanks, applied. - Arnaldo > Signed-off-by: Alexey Budankov > Acked-by: Jiri Olsa > Acked-by: Namhyung Kim > --- > 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..89f9a2193c2d 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].events) > + 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 > > -- - Arnaldo