Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1398807rdb; Fri, 1 Dec 2023 15:51:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IExmjeVmLFVn3uUJkSBVy/opiPzN+9FXO9VajpvvB28AY5XMr2Ox8ETPVECqGiP7l0niPeK X-Received: by 2002:a9d:6a03:0:b0:6d8:74e2:a3cc with SMTP id g3-20020a9d6a03000000b006d874e2a3ccmr278159otn.40.1701474714359; 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=nw01JDutaueMU/19GlsKoIacsTHWgj1RZ8p3vLV0TdknDcmyZ8RGXL27jdm4cjrFn0 gDFYxPOuV2J8jiMsj9U/rgyCImLTkQbKXZ2QxNbSBGxHcQB22U3JRB160s3EoURaap7s x5nFDI7nGMFYKDd3dYe/0W8E6kE/LTDo01LdNfIlje9MubSuCMCY/7yYk51oywI6li1w VjWfrd5gpCzgMVvpE+Hf25WYGQHcbfx0F6QYHKbNrTm4bTN4906vzlfKeRJVgXPiLM2P 5Bh08ZR7SVgoRBtIGz3pOB0b4CKhNFCxGR31Z21CYv0oPFxMf6cTYtMJRLQz9/mCUZlO s6fA== 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 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id v6-20020a634646000000b005c1eadbacb3si4187198pgk.104.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 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; 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 2620:137:e000::3:2 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 3810680A7F00; Fri, 1 Dec 2023 15:50:59 -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 + 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 ); 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 ; Fri, 1 Dec 2023 15:50:40 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-db548f8dae4so1467234276.3 for ; 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 To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Tom Rix , Ravi Bangoria , James Clark , Kan Liang , John Garry , 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: 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:59 -0800 (PST) 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 --- 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; } -- 2.43.0.rc2.451.g8631bc7472-goog