Message ID | 20231201235031.475293-1-irogers@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1487013vqy; Fri, 1 Dec 2023 15:51:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoEX7yVA/vCIw6/4pmhf6q574do04QslYp0TKVmdefypwsMGjm4fAkxIo6n+YJrE4K8ZnG X-Received: by 2002:a05:6871:e485:b0:1fb:75b:2fbd with SMTP id pz5-20020a056871e48500b001fb075b2fbdmr505978oac.84.1701474714314; Fri, 01 Dec 2023 15:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701474714; cv=none; d=google.com; s=arc-20160816; b=QS4ArFcevDjCMO653rdlkCCD3rKfj5xs3yk7mnaXfFkdPcRIAAtzb7iFyvyTx9Pz/q 0EzRrRgHkdBLf7y+JqGmEpYB+JwgFL5qgcSmBxvr2YxPJ2c73r+r7/5xntqckuxFNUcP aPorB7SRg1RA2bHQ4slCYUFPgeeUQrSigtn+HbOX99ryzlfy1OKl2qoaFW/L1tWgOSW/ py8PlateKNjbhIj0ZGJWvvFrOHYZUU5MtzzaEfOfEE/V2wfTN5Ss5qWtHhyejSPXzc7I O6Y8l3cYO8jIXfsU/LeaEBdiWq2EfGgRSILKDaPw4pfQxWcs5UrOn2uteiJmhlj2rYmo Y3ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:mime-version:message-id:date :dkim-signature; bh=PMWeTAylF3bUIvrApUeKD5Af/l0nzPxNAdOfQ8ZWtyk=; fh=C7ZN3tzOUVR3J206ZGKp6+yGr+dWwfty/7cvNxfc8X0=; b=h4xu4Dn/ebtj6hSHsFaSKxOwil7T00DKLQX0PuzaMy31ktm5WkHKwHTDpYZtYGaJM0 ywv1Yt5qoaroO38JzK/4bpCgxyQ1q1vQWsUO+1JeG/DLmvO043jaDNsp4kojOt7Vt/yN gnnrc2A2qCg/DudFl5wlYZxfZT6S4YlWwh2KOCQoZkpEXxqD12sdG3E6Vo31sa9tpgL7 MpuRpJImNSfP+4WJVeELaw/YoFdJC6LBL3syIqWJtJe3AItDq5tPYLW+DRN6gCv6j8xY eGC8LKPlcylo3olIu/CgNvUsDp2IsyDThhtFvAPCXeuy7k3RQebxFNoTgo8PyxiWmgmv bJjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VPLK8ylz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id r66-20020a632b45000000b005c203ad2343si4249141pgr.94.2023.12.01.15.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 15:51:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VPLK8ylz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 023E780A7CD9; Fri, 1 Dec 2023 15:50:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235262AbjLAXuh (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Fri, 1 Dec 2023 18:50:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjLAXuf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 1 Dec 2023 18:50:35 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AC9310E4 for <linux-kernel@vger.kernel.org>; Fri, 1 Dec 2023 15:50:40 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-db548f8dae4so1467234276.3 for <linux-kernel@vger.kernel.org>; Fri, 01 Dec 2023 15:50:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701474639; x=1702079439; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=PMWeTAylF3bUIvrApUeKD5Af/l0nzPxNAdOfQ8ZWtyk=; b=VPLK8ylzIs3LTjCvGHt2TOWKY6j5qZOCmv4K5x+D3BP3VeNe+ETocBZMJnW7kS1yll y+6h7yhVC1i4z8uHnSxkQNaSkXqru//4CzP2MMDfiP7wCnFg8otITcuVT+FsoH6jUj3d 2gcrgTVmlUXzYHWf5KFMzj+DORb8qHSNcYBy6xcZdZp/7kfU21r4N1pq8+R/J6W652Hf zbo4AEPvP6rgUEZzykB2T/fbB9zIoKZOlLhboNw9n4Sha4rfs3pF0GOB96zqh3W4E4wH 6RGZiXbOrUjKStkr4D/xw4udz48v5T2eyiN0+elVTmofHlCMLVP/Nz2LiLJy6lh32u4/ AsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701474639; x=1702079439; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PMWeTAylF3bUIvrApUeKD5Af/l0nzPxNAdOfQ8ZWtyk=; b=ofNVr5kglKDFkUVHbitCCqC8X/muTL/xEVlUwQefZEHlDDvlknq2Ro58mSaLvL23bd yD3VA/6gc9EgMjxJQHRPJBmay6vUXx7tjtpF9NrrUBrMqku+fRLA70eCePBxTb4zWOWl YKEnmU4n9QHpbjujO0CXGxGA8eDsvUmFzcuW2mBLyjKOUZZVSEhSND0g43UUG5A7zWX5 /sAwzsqLrgaiLCAybqS5RvzRBzkVAI8/KRvv1bWZezRt4kvxagDB+Q3CjgI2oyKBX95v o/RBJfhj/O+Ye0Y9dj+HJrWBH5pmHoILXRNSwarsPkS47W08498gIXSTCjKOs3rQUn/Z SQ7Q== X-Gm-Message-State: AOJu0YxFqsvKJsYgInnmY1cqxQ/dfsc9UtuwAD825XtB/AUHgsLMaUVR 8X0bTU3QuesBL/LaLwhnY3twlavjLI+t X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:df3:224b:7b7f:efc5]) (user=irogers job=sendgmr) by 2002:a25:dad3:0:b0:db5:3d61:8e63 with SMTP id n202-20020a25dad3000000b00db53d618e63mr241281ybf.13.1701474639430; Fri, 01 Dec 2023 15:50:39 -0800 (PST) Date: Fri, 1 Dec 2023 15:50:23 -0800 Message-Id: <20231201235031.475293-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Subject: [PATCH v1 1/9] perf thread_map: Skip exited threads when scanning /proc From: Ian Rogers <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Ravi Bangoria <ravi.bangoria@amd.com>, James Clark <james.clark@arm.com>, Kan Liang <kan.liang@linux.intel.com>, John Garry <john.g.garry@oracle.com>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 01 Dec 2023 15:50:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784125550210119039 X-GMAIL-MSGID: 1784125550210119039 |
Series |
[v1,1/9] perf thread_map: Skip exited threads when scanning /proc
|
|
Commit Message
Ian Rogers
Dec. 1, 2023, 11:50 p.m. UTC
Scanning /proc is inherently racy. Scanning /proc/pid/task within that
is also racy as the pid can terminate. Rather than failing in
__thread_map__new_all_cpus, skip pids for such failures.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/thread_map.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index e848579e61a8..18fbc41d09f3 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -109,9 +109,10 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid) snprintf(path, sizeof(path), "/proc/%d/task", pid); items = scandir(path, &namelist, filter, NULL); - if (items <= 0) - goto out_free_closedir; - + if (items <= 0) { + pr_debug("scandir for %d returned empty, skipping\n", pid); + continue; + } while (threads->nr + items >= max_threads) { max_threads *= 2; grow = true; @@ -152,8 +153,6 @@ static struct perf_thread_map *__thread_map__new_all_cpus(uid_t uid) for (i = 0; i < items; i++) zfree(&namelist[i]); free(namelist); - -out_free_closedir: zfree(&threads); goto out_closedir; }