Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1135320ybm; Fri, 29 May 2020 23:19:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykSzOQsQ/tlgLh5LfHWSZGho9S2+a4NZs9fTpQpwCcM6YpsyIXcGB/P/Mul9S8cT84tGL0 X-Received: by 2002:a17:906:c187:: with SMTP id g7mr7714115ejz.446.1590819550043; Fri, 29 May 2020 23:19:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590819550; cv=none; d=google.com; s=arc-20160816; b=fMBu6/lGrMDDm96DCBWfSxvjlv4Z4ZqspSh0pYjXIy1vJBdXmS/yHCKntk3mZh9f3F RftDAZNNqPKRxP/nG6yk3nmaSQVjn26HPGDZJjpTLUjmu+1XOWGbyQ2TBhOF1+yVcw+Y PO59UT1uYXepkq18p/gfqPWRrreGftAq83oMPKl0DsTUyv99nBETKWfIurabItnloEpb NhsgSS+6d5R7VgtXWTpEHb46lk++wU15ej1y9irx7Zpo2yT6CZlBu1t3aYaWZ29FF4E/ yXtsTJFNPOhlGGBSGBskujglGKab74s/k2idT2qLPX+Vcxxt10BIf/5mA5POpcLX5Naz j7sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=7ym9dNYVcJhlV13iO96/M0DbQ8okXb1QpSicHNCjNLw=; b=bEyMt3T+onLrKAgIier2wCyE0ANyAJbr++GX2z9LslsGCx0AVqg6tOMfjqfJxt7Deq SmeYN2okOKv8r59fGLoC8k6xdsnR0fYGVaOvMA7seyeWmhG47pot9g0S3JnfflnS2u8G vasP/8574BPwisvLyl0TfH1MgFO1c7pFs082SqtqJRsQ0Xhizt65awokl/aUcrbstGcF lqFxHJM5SAibC9A0r+BKMwvnEEcXRrdaD85Nz4ps2BXigpfZWopvYs02WVMx5f0f1lru Y8Ri9WCp6QLeBfSszpLwng/8R5baPfGRqNKhDHBsyO1uoKZt9AZ2AaC/6owlEqRU11aT /EFQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si6623505eja.739.2020.05.29.23.18.35; Fri, 29 May 2020 23:19:10 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728130AbgE3GPr (ORCPT + 99 others); Sat, 30 May 2020 02:15:47 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:56042 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725814AbgE3GPq (ORCPT ); Sat, 30 May 2020 02:15:46 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A1DD37C3AA285A8AC7D5; Sat, 30 May 2020 14:15:43 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Sat, 30 May 2020 14:15:36 +0800 From: Cheng Jian To: , CC: , , , Subject: [PATCH] perf/evsel: Fix missing close fd when ignore_missing_thread Date: Sat, 30 May 2020 06:15:35 +0000 Message-ID: <20200530061535.36360-1-cj.chengjian@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While monitoring a multithread process with pid option, if any of the threads exit before we open the event fd, we can ignore the missing thread. We use perf_evsel__remove_fd() to remove the FD of the missing thread, but we missed to close these fds. This patch explicitly closes the fd before remove it. Fixes: ca8000684ec4 ("perf evsel: Enable ignore_missing_thread for pid option") Signed-off-by: Cheng Jian --- tools/perf/util/evsel.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index eb880efbce16..cbb04a18839c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1489,9 +1489,13 @@ static void perf_evsel__remove_fd(struct evsel *pos, int nr_cpus, int nr_threads, int thread_idx) { - for (int cpu = 0; cpu < nr_cpus; cpu++) - for (int thread = thread_idx; thread < nr_threads - 1; thread++) + for (int cpu = 0; cpu < nr_cpus; cpu++) { + for (int thread = thread_idx; + thread < nr_threads - 1; thread++) { + close(FD(pos, cpu, thread)); FD(pos, cpu, thread) = FD(pos, cpu, thread + 1); + } + } } static int update_fds(struct evsel *evsel, -- 2.17.1