From patchwork Wed Feb 14 04:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 200805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp991423dyb; Tue, 13 Feb 2024 20:57:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXUnCkOnsP9PJRATMq6qG84NnGsq3mNujXGik1kM13aw1NpxI0sAPEIaDDt4faqoa3CR4T5Bki976j2IwJAitvRg/vEJA== X-Google-Smtp-Source: AGHT+IEJS6XmNISiVXTZ/Ggb2sFoUCFZA+DdsTM+crgPeenbEBUF80oxdv1iKWF7bQlHYq8Nzk1o X-Received: by 2002:a05:6358:708:b0:176:99f3:8d11 with SMTP id e8-20020a056358070800b0017699f38d11mr1177639rwj.32.1707886651707; Tue, 13 Feb 2024 20:57:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707886651; cv=pass; d=google.com; s=arc-20160816; b=rN/GeV+1DmDTA7u4/UPk9ydqVlj0LItpDdxeo06vDQxIPOkP/BONalW2DWrznuwGux 24Bwlg9KZhrDDx6qTPClvLsSnY5wOAC6P1Jt1dHBtn1SDwhFoS18p53xvXqw0ch9NTMQ rIeklZ3v9kVxUiYBw0wjmNUxTVT5RgK6trK1ZZ59cMOTBU33jonMiJ6clCM4iRhkGPDX Fzyw2nlDUOgSWNrlZsEUyC5w6Lw1ZBaplLu0kiaYnzVuKkQzqI1bpjhaFN1UA5RJQxCm c6f/WYLdag3WtKyPAH2NzS5nWxsYM5BzX9uFT7DlS9PF1vdNV7aQJS2SR7CHyWA6SeW1 DNBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; fh=VU2gOBkHnSAjjQAmdtXiZzDWQs0EKB7DH3lRv/VNdNY=; b=YL0WOB58GiNFVR2oajfCuk14Kr7d4pD79WD2+F608qxBXl/VoavVj/D9ElizjTBKm/ 254aM3BioE+BjdWL3LCJsQsWqMW0KLz9HV576I4DEDDPF/KSMemrYqjnFb9Y5TPY9Eh0 jBKnPOLasdlk2KivECSan7usRQndNDW2f1NK1+5TVcIlpR7jMNNjExO0SplJ0Bf2isSo u5GFmK/GWewkdl5cxgkAY1KEAnjNBRK1Kkmeg75nFLPi0SOEaPbUAiQCrU+z2krwbx03 0oF7yHdVFRLAfB/NsTcit/cy20b96H93zwFxAzYVBolHN7DlCAkitFhRATTbN4GhuQNJ vLow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xUNo3MuT; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64737-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64737-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXFClow+MH6DtWQTw3U8VQOAcrH7TmA+yjtCJ/OY/704s0WB0aj5E8NoIgpkKmLekn+fj7ho/kdqAXxuFog5ujzXiUEWA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l10-20020a65680a000000b005dc34078517si3110087pgt.538.2024.02.13.20.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 20:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64737-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xUNo3MuT; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64737-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64737-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B20D028B9E1 for ; Wed, 14 Feb 2024 04:55:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0333710A28; Wed, 14 Feb 2024 04:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xUNo3MuT" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8900C154 for ; Wed, 14 Feb 2024 04:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707886476; cv=none; b=qay91gEqLcet8LBdX0RznmUP0bLKoGOIppzCH1WOVAyh4qT7rHFCHvbT2dw8FiTqaOkPHvLJpRULZgRKX1PK7SdIItJOsR2GyItm5KNao7tGO5Te+m3XIMO99dDtJjrUTNGD7uOR7Mczv0vGSPXu9t32tzkJUtJsCglc9jkX6TQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707886476; c=relaxed/simple; bh=9GvaQ8U/ciyGf0POxeefEusSW20t+DHMSsugj/N6ETY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KXd0EB6GbFEiBbX/ZcW3RVpfO8sBARiA/4vB7pD0PqmW32R2ecgqqn2XK5HXQz5sUkZ/1Ct2pK4ypd6YtSMuqsuFGn2SQ5Xpvgwzo4qT6vypE6uLEhaOEpvSKp2PvP6vAL3pY0M9bccWlsLlvaZ7grMjodTa3EH/cG5C5e7tYr0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xUNo3MuT; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc74645bfa8so2588395276.1 for ; Tue, 13 Feb 2024 20:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707886474; x=1708491274; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; b=xUNo3MuTCHNPNBQSi0iOeCYRhkZNpLcWuhCz+RXhzVfhzxK+TFj5UCTqB1yjMiEgf4 Y2IG/TsNqIuLvuXhVgwCfrFqkulqkxzpGVoKkvlnkvgmtXb2fvm49DMi+Cx4GsUWHQrZ sWYmkj0jSbpPEK9d36KD+H81PqEqLB+Dy2jKJeYw3fZYvAS1ASJvzI4cLcAKXNtG/yUE TWjImoL4OLfJtmjCA1uNDwXgoX/RJOZzGnIhuSWn0e/QVWX2zxnobM7lxur5JaxWHXVI Q5X5Zf41wd99vLJfhXQ4rztXfxNuf+epH4qJaFXBRbgLreCLKQGyL2o/vWpZP1VeA/E9 3aAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707886474; x=1708491274; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F6UUwQ6uU0gh1AgBT5LAdlyWuLVQW/eRWP9wNVATd0w=; b=EVrpg7TZ7ydQjUykt3RJKokphZVTT/hi+i318IJJc+H5AhxtqXvCxWXVX0Pp2SsuaD GPIYRT62ID5n8BXhq9vYoRuzPLMSHPJPVstNQ/Hs1KvfVu2UHP7ewsRI0gYMXsU03s2v Dsjst4rClrj2WMSwfI5fi83f3UsuPj1Gh+Crkjisscmb/WyN8NtmLT92WXYcc3KKN68C JD/vzGltgKcWepqSmhHQU63/VylN/xwqH5rgxB4ewPL26tGHUe0pU4/wfDpwksvKwkEv Fka+txiiKAW2i4I2dXAI2aPAh80tZB+ENUib9uYJHCkmKze8bJP9qRjcVGbZeH2rX0Ct UGVA== X-Forwarded-Encrypted: i=1; AJvYcCXd5/Pp6ZXramDNMiZw1c3sLrdrnjnm1TTeILrSe6Q9NBrnHPiXLovtC6hRoz8CMgJzkicz9nI3mRpFJj2ZHwjhwe/S3rKXrvzZnf74 X-Gm-Message-State: AOJu0Yw7EmPzVEiZ/B6jdZciohlbrWXBUax8v89gsepi8YnY4bb2+VQr ePHlPdrpMWfVbbBIM5M6MSo4R5BlJkLY1EoYSOATNQljaMwiu0Znmf1/oU+759ZlZAzSVnxFiRl kWPzVBw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:6d92:85eb:9adc:66dd]) (user=irogers job=sendgmr) by 2002:a25:d3c6:0:b0:dc7:6cfa:dc59 with SMTP id e189-20020a25d3c6000000b00dc76cfadc59mr50124ybf.4.1707886473857; Tue, 13 Feb 2024 20:54:33 -0800 (PST) Date: Tue, 13 Feb 2024 20:53:49 -0800 In-Reply-To: <20240214045356.748330-1-irogers@google.com> Message-Id: <20240214045356.748330-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240214045356.748330-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Subject: [PATCH v4 1/8] perf thread_map: Skip exited threads when scanning /proc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , James Clark , Athira Jajeev , Kan Liang , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790848953794318390 X-GMAIL-MSGID: 1790848953794318390 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 ea3b431b9783..b5f12390c355 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; }