From patchwork Fri Feb 16 23:51:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60396dyc; Fri, 16 Feb 2024 15:58:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfuQnZvS1fU091RIaTOMxvcceXT2vZhSRnpv9nhgXWy2gizsQ6yuHc1KPivzYdrt8F9erGsUcrx5/g03rJ7OROxXqCRA== X-Google-Smtp-Source: AGHT+IEEXD/BwAMZOZBtFfVhDO7Bbvp8McdYd76SgqYCb2eWvEhKJQiCSyGKWKJzq7od8pe8Qm+c X-Received: by 2002:a05:6a00:1da2:b0:6e1:1843:2e91 with SMTP id z34-20020a056a001da200b006e118432e91mr6916018pfw.9.1708127924804; Fri, 16 Feb 2024 15:58:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127924; cv=pass; d=google.com; s=arc-20160816; b=jsFiZmDZs8iJ3YgH+aUVZCQTfHtYWd1wkaDHvpuIrb/FfEHU/NrBzINf4pPNLAf+DZ N7/YVbQxPoo2X3ldUE4tQDpsh1b1NmRnNN79WGTlJv5nUSfW+HMHzmPgIYFz9N5kPDMc jrnjqq1Ye5CapLzJ76VGzt8WocVtnQvxnPmf+1p25rOHESWFAH1zOUdsECVQBqSpp4pv 8LNKk9n+qSb4MvPNI90Fv98WWUrc/5Ia5I+43hNJGS/ZbH28tBkKrPjIbsjEVQ2YSG7Y dga7jzHX5jhLTATxb4IwKoycOVX76Rcmu7WBzcvvK8dH9f7djHqvafHTDBk8TsKEtzf+ UcBA== 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=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; fh=sAp5eMLO6UZSk6Th+aoUoif94nv8sgeK6HtiiknbPqo=; b=sm/zOvv5PugEr01PmCfeP0+FE6UKE0Q204YI8Y44anRVpTNZ5SwPz0jGPfmerITXEo 9NuGd01dGH7KhDyp3ynacHFFZn+ImhtWaCYhM+7TD3SjcSHv0RU3bVtAugXQkZVhafmW vJu0VQtUSCnY12jlZ/jieBfSASRfOQ7+Rw7IjcqbpLAY2JiQBGyeydnKfvwx+8zm5zCl 0abFpZw2BBNKxwdAR8HhWqO7KDeqtkMmt43FEPLtWKLJGVpkHXEw5Oud9xE+eAjxJD3+ dUbYKnXj7s3CUpLUDvn+WxcGm1DnfdVGn1nO4xuAStstBctshSU4AtSStKymoks9Gt7z 5xMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SZ+5QDu5; 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-69509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69509-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j15-20020aa7800f000000b006e08197a06asi643952pfi.8.2024.02.16.15.58.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:58:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SZ+5QDu5; 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-69509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69509-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 A08AF289A4A for ; Fri, 16 Feb 2024 23:58:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6355C14A0B6; Fri, 16 Feb 2024 23:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SZ+5QDu5" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 B8DDF14A091 for ; Fri, 16 Feb 2024 23:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127717; cv=none; b=b9cWF/1sdlZncPXU4Ms3Sdjo/nopuGtWXfJHyv1il6JRXwlFD+ZlJoy6MdQxVcyX/mLPeClOnMGM2cfQ90WY5rLQVOl/M293zqxW3CkJxLRn6Kc6OKeu/jef8NLMwvURi8fd3GWjHbUk+C3Rt9BhYNjNAd9M/BYQoNLZDmQvXFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127717; c=relaxed/simple; bh=o/osGCI+hvlD14sD3OCM5ESdLYEEWx1V7jgoXENiCKc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BSZZeNj+PRjdQD3dA8LgZimFAnGtc9BMncbAFmpcatatFodj3H/rLtkfVOf69A+jVSnGC79BsY81RFYyB4f+pvuLSx4sBua/Uj8F0Wk1HMd7Ld1GOTTa0ykTmubriK6/bgnk1qAkmQmNgLAo3GOL7FlEU12KcBHD0DgDgsilqA8= 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=SZ+5QDu5; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-607fbfc2584so20320287b3.2 for ; Fri, 16 Feb 2024 15:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127715; x=1708732515; 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=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; b=SZ+5QDu5R4fz5A2dD5YZvaAP7J9N8Guflh0RU0g5Go1CFNPi6JcbOINcWrWPXCRA2O aZhS2P63yxw+1UYakL1ecPfbLgSJKLyYKzGD/DP0EA9UCoojUPgeA/pFfWQ6cR6jgP6d 7+yd5UBFdPXtAVHA52+9YdOUxB/gUdnVI8rNECKYgrR8l9Q5F9UcHA8xIr9WcUuXMvKG ixw/poJh2LPBB1qZyT0OaxU2vufxJP5wGaP6EMvh8VYcvmKcXz8Usajtqs4mQJCQ2alu baD887QMkIW2kMQ873abiAK8mLVM1VKT2pz+v6warnszU4j4+HgM2sUACUEAxvMWtF6x VMag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127715; x=1708732515; 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=uv/9NgKdLz0z52mqtvy0vTSbbBgaPJcb0Vk69+L979Q=; b=IJxaN9hmZIh5TapS+qLkg074LdGA5zrb2/QPPlNMNjvYPqUps8lqrEYCpV4nQsMcKD dJG2ziJ7HSeaCih4ehD8DGvqf3RcFRcZ8Oet2NG5yqoSp/asDU9Ymfi785TeH5QvUFSE UG1jfeYJgLyOHQOAdtKGDmQjPgOam25G9T9F0nnPn7B1w02abwIwXyv/mzkhmgRD+pOr 6eHiorkL7YzTg5mobntN56yvjJ2UQfdbNM0xBVxhp/mPPaC+tmixxEoq8Zdj2RfqJYZu mo57PSm8vxlAuIu/1xXeqtEZpgGdIAJq4osKFtLwQxNRRxhNgeaCOoEN5F0jnrPrV3FH 8buA== X-Forwarded-Encrypted: i=1; AJvYcCWTil4NnN9gvuzzGg2srlDDKSgDWN4n91M5UD4+GHRq41YVrjDcpsvBRVr9soRYQfXUQHSA/a1ZOAL8Wv2jA5+AFbNbbws1CRoS+sBE X-Gm-Message-State: AOJu0YzTtiXw2tSJp2+s8GORnUux2S21GVlcrCOyAG7gTrtZy4aWR8Eb 2BIlDIhp8ciGcvYQECCh6sacOW339+oEU/WhQwrj7ehk8VCXjZ/nT5HJtNmSYaGIQP7SmBd7jsk ciG7+hw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a81:4ec7:0:b0:608:cc1:f66f with SMTP id c190-20020a814ec7000000b006080cc1f66fmr155163ywb.6.1708127714785; Fri, 16 Feb 2024 15:55:14 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:55 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-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: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 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 , Athira Jajeev , James Clark , 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: 1791101947018257074 X-GMAIL-MSGID: 1791101947018257074 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; } From patchwork Fri Feb 16 23:51:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60481dyc; Fri, 16 Feb 2024 15:59:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWFYSnEdn/hRan5Yda86JbnfwNluCqg2bR5hqqf0VxdoXLf5aDzoek/QEsXmk42/VkpSLMAWFwxPx6czzIIONWs7sduMg== X-Google-Smtp-Source: AGHT+IF6OI2kZfiqjxJLOF1rjBbKLCdyyhh5d6sjcqL1eSei00ZxUxScn6YKI9AdLa5TxK7kudO9 X-Received: by 2002:a17:902:680a:b0:1d7:8f22:62f5 with SMTP id h10-20020a170902680a00b001d78f2262f5mr5372245plk.61.1708127942019; Fri, 16 Feb 2024 15:59:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127942; cv=pass; d=google.com; s=arc-20160816; b=uYl3el61+4E2nQFrVI+hciGvZMuy4GEd728eBHDnuTlaXVoJgJlHEGRXzShoqmf3Aw JVX37s5SBeftS3A2BqKiqf1lNBOiG+e8fIu5IXt6SFo3xpej7XI484mYWFIXOwR4equY PukxNHZ1Ek7AKRx74MDhWp+kEbJPYByK5tJ48MJk4t7He3hS67DPe20xyAOG9a2X3Fh1 hIx1GPFnnTfnDWzNDAsxYnYLlHoYBl5cQ7lG025urAgu492p5URcweYBH2b64z4aTQLf g4FaVl7+EOvkb2b2T2LJUQYCbVLzMSqRyQiTFtcPOZgCmql326sZMml42KbBsW0/9PNt bxNg== 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=5lEV9flhamU87tdGpQxKOQUuN3cEGzsZvh7EhlSuOZU=; fh=DUVtuYX+Sx6wW5XeYmHAwXtlcq8xZKxtajYCRZQiMgE=; b=GHAdgfiamsq/XDYUDEIwlIJC/w0M+nc/jNMJNWfsqKag+YZMzNe2ZBA9Zz5lI4ebIK D3P3gjIJkR5By5PfwK9tHTyLgfnNlr0Qe2zXXUCx9V37DjDlFqPz/JlLtGTK8o38Qp9W EX2VgnCaEdP6yzDFxxQrLE0vm1uJ0mUXMktZqj87fjDuh5zzkP7R5c9wrHwtHfnX3t1f tUkEaSSrBXD4vfMRrxl2hiLaDxFn3EFtXLgczGGLLqiTBbpwWTCZtLqG0pMu5zFIx5ct I+9v7k884Z1qvrUHWWQlItInLodZVx1XKZhGjI7JTB+EW9sQ6AnVySVD6Tfk1adpxCap eBxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ACuy2cBZ; 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-69510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l9-20020a170902f68900b001db3a062d35si596288plg.371.2024.02.16.15.59.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ACuy2cBZ; 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-69510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69510-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 CEF8A289AA4 for ; Fri, 16 Feb 2024 23:59:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E4CA1534EC; Fri, 16 Feb 2024 23:55:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ACuy2cBZ" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 193D114A0B5 for ; Fri, 16 Feb 2024 23:55:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127719; cv=none; b=jMGwwby5shnQoNKOg7lhnRnh+dpEPrrzr+1yFzfwYTmgxGLl96pmjrLGnIKNMaymkFIIaivue/NdgZW0/WB14d9BsDCZ6jW3Xqq+mMwtSAAicsbUEkmaEFzBKkikGWQmrZZYJ0I8OstnFFe91KGMEwtZKZ9gbPiZGB/7L4NZA8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127719; c=relaxed/simple; bh=mlDvuBmPP3TrmLBy1TVdW9K7nfBnqAONps2iWBo5bv4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=GbGGREe5y0p1NeH5DjEB2r6PbarjzeZCrO7tLSMR8r419gsl3Rv946TiQgFu4rE/KgRTJUCRqFKE0C2QLss2gCy7WCbg+uonv6kE0rLkVLAxO79tbOOUShpu8SI/caE4FkHX3de30BWO2hkfPOrYxFhufk/e0Np1lOkGHj2yzEY= 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=ACuy2cBZ; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-d9a541b720aso4323355276.0 for ; Fri, 16 Feb 2024 15:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127717; x=1708732517; 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=5lEV9flhamU87tdGpQxKOQUuN3cEGzsZvh7EhlSuOZU=; b=ACuy2cBZWhiTW9+iKRzz655YFWBTVgzPe+DXgBwi1Ie6wzzjfJJikFzV9VyIzOa04C ThrU24fX5R6o2JIeR613xK/c57JHWCEEJCiS75QExDwZFMnvNvhfzT/yuu6vOwqigEkq h4kjYkhcANSFBveK1PTOYRX5hkzQPl20spH3AQTPNYZZVzJvgQqzM5QNaHjNdmp4yKOP exmPdVqYiV3REVqSmtA/6ndsN3yDkX+bonf3bVGSBIEt6/7dc7arnMjvjZXGuMPejJGo ItGGHEg4x+8NTbP7GG/p6FL7nkG9P8SWKxcLj2EcGoqw7qlfmgQEWqb51QnoM+1W0m3r ttmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127717; x=1708732517; 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=5lEV9flhamU87tdGpQxKOQUuN3cEGzsZvh7EhlSuOZU=; b=rxw2HQUxKQtVUt6xilEXcfAAw91TZHQ9BY+H5+ubXiP8oZ6POmIKpz4GQtnK/s66I7 JOFceKWSn+pHBoQ/uSM7P3EDDP11q9xZN7V/nh4Ovkaln5kQDZznlBx5uAca4pYyEdKu kzK7MSSZ4t7Qbtz0ekYrJK4nZZFNvBag9Wqlw10cg45PxTe/Gba3/AyhdZB5sDYiMZIb Jl2HZYTyszILSDCbbTot1XhnrEzMZGK2Cky/Uen2WE2ASbHuQwVSOSoIBLIW6LVwY/TU DHGIxsDUcTwL160+TIvoo4702dJu/0O9rojoq+JH8Gcj0VfREb09qon+5xPoq1nP8XrD qBJg== X-Forwarded-Encrypted: i=1; AJvYcCUanLc9dkwiJMYlvVk7cm3XwhpCqAR99/E0KAckDegiMNmhqkqKO2l2XG7/iYAkuya//4NRqZmJ8VSY+GdVjU0OdazH0s6Q9BHB38WK X-Gm-Message-State: AOJu0YzN7c/L6IgveVqvJd79L2qbU5qqqxTjNFUqDJ/ItoebI95pUDsO 9L935dJ5n9mSvSp7DBXr/Q4MZPqtbBvlD4l/euc2ojVjE9J1Hb+gScQsTG6sEVMMr8l228l7/yP Wc6PZTQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a25:b20e:0:b0:dc6:ff54:249f with SMTP id i14-20020a25b20e000000b00dc6ff54249fmr1454658ybj.8.1708127717121; Fri, 16 Feb 2024 15:55:17 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:56 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 2/8] perf list: Add scandirat compatibility function 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 , Athira Jajeev , James Clark , 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: 1791101964552838663 X-GMAIL-MSGID: 1791101964552838663 scandirat is used during the printing of tracepoint events but may be missing from certain libcs. Add a compatibility implementation that uses the symlink of an fd in /proc as a path for the reliably present scandir. Signed-off-by: Ian Rogers --- tools/perf/util/print-events.c | 12 +++--------- tools/perf/util/util.c | 19 +++++++++++++++++++ tools/perf/util/util.h | 8 ++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 9e47712507cc..bf79dd366e2e 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -63,6 +63,8 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus { char *events_path = get_tracing_file("events"); int events_fd = open(events_path, O_PATH); + struct dirent **sys_namelist = NULL; + int sys_items; put_tracing_file(events_path); if (events_fd < 0) { @@ -70,10 +72,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus return; } -#ifdef HAVE_SCANDIRAT_SUPPORT -{ - struct dirent **sys_namelist = NULL; - int sys_items = tracing_events__scandir_alphasort(&sys_namelist); + sys_items = tracing_events__scandir_alphasort(&sys_namelist); for (int i = 0; i < sys_items; i++) { struct dirent *sys_dirent = sys_namelist[i]; @@ -130,11 +129,6 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus } free(sys_namelist); -} -#else - printf("\nWARNING: Your libc doesn't have the scandirat function, please ask its maintainers to implement it.\n" - " As a rough fallback, please do 'ls %s' to see the available tracepoint events.\n", events_path); -#endif close(events_fd); } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index c1fd9ba6d697..4f561e5e4162 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -552,3 +552,22 @@ int sched_getcpu(void) return -1; } #endif + +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)) +{ + char path[PATH_MAX]; + int err, fd = openat(dirfd, dirp, O_PATH); + + if (fd < 0) + return fd; + + snprintf(path, sizeof(path), "/proc/%d/fd/%d", getpid(), fd); + err = scandir(path, namelist, filter, compar); + close(fd); + return err; +} +#endif diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 7c8915d92dca..9966c21aaf04 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -6,6 +6,7 @@ /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ #define _DEFAULT_SOURCE 1 +#include #include #include #include @@ -56,6 +57,13 @@ int perf_tip(char **strp, const char *dirpath); int sched_getcpu(void); #endif +#ifndef HAVE_SCANDIRAT_SUPPORT +int scandirat(int dirfd, const char *dirp, + struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); +#endif + extern bool perf_singlethreaded; void perf_set_singlethreaded(void); From patchwork Fri Feb 16 23:51:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60542dyc; Fri, 16 Feb 2024 15:59:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZm277jpE5mqE0ua9hfDvnZE1FGPXdOP569qnMP5xn5P+Nh5ocnRdcEJoFZ9cqJaMiOylrhxlD6BF0r7HJQNbK4E8ncg== X-Google-Smtp-Source: AGHT+IHeOGtRK5+y/ixA27RjQJCqCZLGMKEYmHkJelsTf+uEewNM4vOamUpthqtI0I90trk4djC6 X-Received: by 2002:a05:6402:699:b0:561:d726:201 with SMTP id f25-20020a056402069900b00561d7260201mr4882864edy.10.1708127956600; Fri, 16 Feb 2024 15:59:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127956; cv=pass; d=google.com; s=arc-20160816; b=D+PX5Pw+nqHJPu6vwuNS3AFa7+90EcWKv3RY69IyYIxp8UuDRm/HKGtzQjhBn8HGsR b2pBn1W8F2cHvrabrFF+yviTOvAc3fTDD8u+RlUCpx/ZffloeZ8nT/ZVjb8215nW8Bk/ F+EhVf55sJrj49Cf06F9A37P0MYQLQ33a/ffdqx1CQuoxuue8N/Ys/HbT31JxdsHLb7A oqdBC9zrCCR4QP05gMm0gURzk8IgmyU5mq7OwdBKA3+hCTgdrqwVWtiAYziWT8aFzMEa mujFUKt0skbRznZMKS2gvb2iz8ddRs8qJJsatknZ8K+ccQVJcfAarZ36ALt7yFKQENvT O6vA== 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=OwHudnCNl5wfpV2IMol1tp79ctLuVP/i5n4Lz8j3mXY=; fh=2lNIMF6FphtsC1VbX4rmrtJ3yi60xqrsS+T0ZSoIIVs=; b=dtEfDkhdF+OlLFf+1wp8dAvrK7TaAxDn3LtumR5NmuCLKt2TIuBhRI56ZVa476AWxm c/eaGsw7oXxCAy0dTyqeRCLM0s3YsJjJaHPp8MCI54MMF0m1tKJhNVPMDPuphdMpKypj FuyccMCEg9MDbj0rWq0FBMbslQj4qD9DRV8p1IPPiVXWSy1/csVkYHKRdeGAI81sSpC1 clF3CD3vUliZ7zTc6T1EzH1XCQ0oKoaOFHKhK9N8Jv/UEX2PWWPlkaqNUD6jIjpVh/OS ThIl+8BfdAES1AlFuM761yxYH4whii/1LJm07iLMd4zK6n2elAnnxHCL2AC4PyndgkCA f50Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Tk0vz6RX; 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-69511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cw13-20020a056402228d00b00561f629d5c7si393061edb.456.2024.02.16.15.59.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Tk0vz6RX; 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-69511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69511-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 398B41F22A75 for ; Fri, 16 Feb 2024 23:59:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3590514AD2C; Fri, 16 Feb 2024 23:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Tk0vz6RX" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 A9E2614A4F2 for ; Fri, 16 Feb 2024 23:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127722; cv=none; b=qCz/DtSL7v/8fK/xgBzHma2JUfuENJdtb1qLLVaPG9fNhJ6b2O+Xj5bRCABfjN3b31Qj/4mP7EqbgHr+QPgz1cC9ra6RtfFRO3nxsV2XOd6pPKpjUeQ7lPjhXm+ypAeWPL9zINWFQMQjPV/2a3xrfme77KiUphZ90fNP2CKm+Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127722; c=relaxed/simple; bh=9QHqj0EQvOX6+a6MNptism09KshtnOJS+VQ0pDYpZf8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=eOTevSDhb8Rk536hXm4L0KBCQ1iW6CQEz0XoIOAAmoJlQsgaAqx0cNMySdOmgUk7KzkigNwnpCSGapdqzD+RdKHQPkxzkvmjzKw7spDUqDEIKUV7cgdI6uTXPR/vYMYdkXtaP7ahOwXQ3hqF7z6FmENRbGl3luxgGLjhvCFD8FA= 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=Tk0vz6RX; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-dbf618042daso4283267276.0 for ; Fri, 16 Feb 2024 15:55:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127719; x=1708732519; 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=OwHudnCNl5wfpV2IMol1tp79ctLuVP/i5n4Lz8j3mXY=; b=Tk0vz6RXDKQnhcGr+DXY5W/BPJuZhyPUfT2SOUMyg/oXvpHj+Vdv+ABuPQw9kZehBM XIkmBgFT3cf9/Fqwi0+DhwCSqnnHhY82jVdYupN5nV2yEOp5e2XY8bxgApYeKN/f7G9a umFtZlghzhPR3SB322PueKQWg7GlWlPlfp5B2ubjSiCavMTE5WEcinVnDl+/C4h2OSxl Zin/X5QIDBNnE9lhKOjuz/xaeGPsVmLf8iI6gaH93RHqhZ+5K4weHb8ouvtww+04fNDF bndnB+JErGtBPvh6n35SCu5Vk/+j/BXzdmxS6nlF/MI1xJ24EGloLbeDTatxaJk6BA2t AgCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127719; x=1708732519; 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=OwHudnCNl5wfpV2IMol1tp79ctLuVP/i5n4Lz8j3mXY=; b=qEnYx7DWbqxJrQHljExgDIcRBKsHB77W2Yjk3FxLGy+ClioDr3IY7X1TfDDkquUvY+ g4jiFRNtWAav9lHWiSkzk2Qv5nnskkDj21DX1tuSJ5E2ZtHWGmzhRkYGL5bgYjmfch9v +xaahaocl3z5bIqvWb6tJmiV7Ka2xJi6l9LY4iVRYz7fuekFM4/JjeB+Sn6KIyLOW+zE Bmolw43rTUAlAFrINt8zhUtqw9GmYLUfUMB85FBBWNEokMfFZZ52FCR9HvFyfHBM6B/i tv6+CJwm7grBsX8Bh0sMeZUNryIrpBk+8RvOgvd65hPx2NU69dgtS0dL69LGlhnnewbv IqvQ== X-Forwarded-Encrypted: i=1; AJvYcCXJcOjlVuAdd5S2225pgZso57Ail+ImJOkpe+Uojd1p34raEClsRflr+fXAjsCSHNYs/DIzRpqY7TJnDbIRHBjrS9dFDItUyp6nr6Ne X-Gm-Message-State: AOJu0YwCZk9SGNqlZ277SxsE60WAMk2fAaaqfv+X0KUeE7AHmrmjmqa7 1HTm46ZwzeuPs+vxyhXSy4AKVZpeWSc7c6CBZwTKKw/uvR14CelqSnQ3NdwIttBjtacTo89NgOh boScU/A== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a05:6902:729:b0:dc2:5273:53f9 with SMTP id l9-20020a056902072900b00dc2527353f9mr224067ybt.1.1708127719606; Fri, 16 Feb 2024 15:55:19 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:57 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 3/8] perf tests: Avoid fork in perf_has_symbol test 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 , Athira Jajeev , James Clark , 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: 1791101980594000032 X-GMAIL-MSGID: 1791101980594000032 perf test -vv Symbols is used to indentify symbols within the perf binary. Add the -F flag so that the test command doesn't fork the test before running. This removes a little overhead. Acked-by: Adrian Hunter Signed-off-by: Ian Rogers --- tools/perf/tests/shell/lib/perf_has_symbol.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/lib/perf_has_symbol.sh b/tools/perf/tests/shell/lib/perf_has_symbol.sh index 5d59c32ae3e7..561c93b75d77 100644 --- a/tools/perf/tests/shell/lib/perf_has_symbol.sh +++ b/tools/perf/tests/shell/lib/perf_has_symbol.sh @@ -3,7 +3,7 @@ perf_has_symbol() { - if perf test -vv "Symbols" 2>&1 | grep "[[:space:]]$1$"; then + if perf test -vv -F "Symbols" 2>&1 | grep "[[:space:]]$1$"; then echo "perf does have symbol '$1'" return 0 fi From patchwork Fri Feb 16 23:51:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp70553dyc; Fri, 16 Feb 2024 16:22:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxv8WMT9nB3shJAK60bk5h9U4Ruvz8ezTRvMHWbBomtHynv95yfLcM+537N2mn09p3bZuyRVmBc6JQm/uGFW4nXtVJrw== X-Google-Smtp-Source: AGHT+IFAJ9YukdiH6nN61dB1bqNvRSdjRWdfFGOfkzb9QeXWViOmVVXBWCi+9AazEaQiGrTkewPD X-Received: by 2002:a05:6358:706:b0:178:92dc:8a32 with SMTP id e6-20020a056358070600b0017892dc8a32mr6751450rwj.20.1708129361842; Fri, 16 Feb 2024 16:22:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708129361; cv=pass; d=google.com; s=arc-20160816; b=domYhRuiS0ofO1kI0bktssLqxqN38pIP7QkLqgovPhnbgaGgaGQtD8vwG9hxEVPbu6 InVhmr8nhOZkEOtq4seCnY9FeHM/6EwBgsFLfh+vY2hFSbbJf+/RDoXRatFlbPErIc8T 7VqjXSHqdnVSZ2M6U+76OI9O2tWCi5zDpi0H6A9ehgbIe4yh/Lfwqz1FeNWO1SPlBX3f T4CsL3lSa9rPGN4rSAF2uS+WLWs4e/9gFhhzKQKDXV9/MKkY0YK9g6iz4q2p1OW45Y2n 0PIWRQNv4jWbjWSvglAyWMzVTqBjwdx8mxywaPSm8OmuD24sXrj68I2787ZDWzAFYyfl rcdw== 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; fh=DEVtZCU+UwPIV/qYU4Kf8V11ilXrf8vFGLwB6Nij0mA=; b=bjPNTh7oRB9hwEmg1uffw/WX3KyZcf3CpkyVy0E2xFwKp0BMZT+5UxqHPRYfVhqyeh sEueo70c3IrlRHRsI0XILaVk+4ALrdEtENdsVBOQGI/bdH2Suy15ZXRZpxxUAFfdfVeU yZOV5c1fU0JGF8Pjo000hW4yEu/pvjW5DdxQA/L4sEC4aq9T9ljkq53B9jXNsmY+lxCx 484fFnMxakxTQEA+yepICW52qpIReUKVG6+WvcqjFCj7wQJan7dRc9Fz8bAtyYCXpzTZ tp2nG1g9LZ6Kjn7o3pXoiG61E8eZI8Ex+uuQzIiPI1mQGU321608oXrx5ErV3HR6lM7x x3Dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PZy5ChhJ; 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-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m14-20020a63f60e000000b005dc81a30772si643017pgh.301.2024.02.16.16.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:22:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PZy5ChhJ; 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-69512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69512-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 82B8CB209F4 for ; Fri, 16 Feb 2024 23:59:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41CF015351D; Fri, 16 Feb 2024 23:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PZy5ChhJ" 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 E586214A4F4 for ; Fri, 16 Feb 2024 23:55:22 +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=1708127724; cv=none; b=kafgkKGGrVEys1pvrGi4CQ6fqQLlxYu0aOzyHS+4Iom/Y8aicrtn2yjB6k8VEl8O0to/yKn4ozTQ31XRPSFj31llvJK3Xo3517wXO0AkcIvtJT1mhCkpAgINRq9xCDbe6pKwjm7WnT8x6FOTQ7yIAYR0Cj+DYzZnx7midmYHIKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127724; c=relaxed/simple; bh=nIwADbFncYymlWUg/R60jRadSx8+xe1bkn0KEBii9rU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Z+bOxQUBHrwhKse4m2mI6syExfTfYpqxtP8uqJ+I1a98xRQ9AwnkT3QuoFN602fRtj9sUA+vcyOCwqM/HPoSfk/BJ2/zuLDRly2qgqK6gLHmfCvj0CwgzMPEf6EKO+7ySeqjD6Kj5ttjwK/MthpurveZ2VhnC4sh3CeMYOoTiys= 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=PZy5ChhJ; 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-dcc0bcf9256so1796733276.3 for ; Fri, 16 Feb 2024 15:55:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127722; x=1708732522; 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; b=PZy5ChhJk5JUXUDQLXMQvdXtEOXP11BPV4rBPvaGZpyQL1nyZRMDmOSwSNuxq0/eST upNa0E1k8pXZ1Nb7r02K+1hiRIoFDBWNHxZ90UAeLS33odaDXxKmuyFBweLwL7MbG+Yh DI95Z4Z/KUh4gmlIXnQINyvCcQAx1G0eSJKObAZ7ktCbNYGSQY2kE+JOlB+waObCy6az MO3t+tCD1ghKuN9fSaQ82Y9q+/pZAYUP0uRD3UuJY+PuWN+uT5qqVJVQrBISoG3ja9W+ h9LKbVLAykFBbsE4hY+V34WEDzWtIFvTMOggP3ux8RhEYtYEnvWhInUYixSrzm6lB6ZR tOVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127722; x=1708732522; 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=eF36kSIEMlGOGF+Ru4Ee+ArAeIU+1BDlU+YfXMm89FI=; b=QqYRrlcMgUIMZ64M7vk9w8DfGJRllNFUT6O20IJFkeP/VsWX10tkA6PUhVop+Pi7xb Bxo/vvEiNqRgfR1mMLSC1KNlXKDrzlZdtt3So1kPtoJRYaVBtmKO+bUX0eBb2Ym6rDGa 7/DML17lQSAaCNMg4YveNAPg88faXu2qPljgnih74OmJtX5WGRnxVrIZLIeRmgmMnwRV 2QKGFlH0ZKygs46DuGx9zCUxdXJxQ127QeW8LY1TjnRf/ds5AUu2bD2a+aqkaXk8+Np9 RCEf4C+3HmtRaDG5PxXdNvpT/dmrveZjJFgNDk2bRP2HMezSMHnzK7S0X0tyRlXenoCF +ELw== X-Forwarded-Encrypted: i=1; AJvYcCWFHFC8YOM0fJIwtJa2q4O4u3c7VYylEoS6bZBDVruoy2dHVWv8Q56NBEX8q0eSJ9A8flFPIxaLuoyvdU/+aqD6ePdfS9RM8UwHixOY X-Gm-Message-State: AOJu0YzBzW1eTyF7Mt7V0ThuonkTXXXkh+PUsXhWVxieKiUkX3IMb8de jdoe0EmdpxcYBO5m5+JZVE+xKhovqvhMq8MHjmVqSI8BL4GXEMI48QAXfrZ+UsNzkJQz+tbclcU WTAw1kg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a05:6902:704:b0:dc7:6f13:61d9 with SMTP id k4-20020a056902070400b00dc76f1361d9mr242453ybt.4.1708127721847; Fri, 16 Feb 2024 15:55:21 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:58 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 4/8] tools subcmd: Add a no exec function call option 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 , Athira Jajeev , James Clark , 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: 1791103453591787904 X-GMAIL-MSGID: 1791103453591787904 Tools like perf fork tests in case they crash, but they don't want to exec a full binary. Add an option to call a function rather than do an exec. The child process exits with the result of the function call and is passed the struct of the run_command, things like container_of can then allow the child process function to determine additional arguments. Signed-off-by: Ian Rogers --- tools/lib/subcmd/run-command.c | 2 ++ tools/lib/subcmd/run-command.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/lib/subcmd/run-command.c b/tools/lib/subcmd/run-command.c index 5cdac2162532..d435eb42354b 100644 --- a/tools/lib/subcmd/run-command.c +++ b/tools/lib/subcmd/run-command.c @@ -122,6 +122,8 @@ int start_command(struct child_process *cmd) } if (cmd->preexec_cb) cmd->preexec_cb(); + if (cmd->no_exec_cmd) + exit(cmd->no_exec_cmd(cmd)); if (cmd->exec_cmd) { execv_cmd(cmd->argv); } else { diff --git a/tools/lib/subcmd/run-command.h b/tools/lib/subcmd/run-command.h index 17d969c6add3..d794138a797f 100644 --- a/tools/lib/subcmd/run-command.h +++ b/tools/lib/subcmd/run-command.h @@ -47,6 +47,8 @@ struct child_process { unsigned exec_cmd:1; /* if this is to be external sub-command */ unsigned stdout_to_stderr:1; void (*preexec_cb)(void); + /* If set, call function in child rather than doing an exec. */ + int (*no_exec_cmd)(struct child_process *process); }; int start_command(struct child_process *); From patchwork Fri Feb 16 23:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60736dyc; Fri, 16 Feb 2024 15:59:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWrR9+n0sMlOZ/0f2nTX1ElbccYw4DIHRJZd0lk7y6bL/3WwnqYepHnmsKZqivXCpTd3oHI0xmEz5udjl77S/43oGUiAA== X-Google-Smtp-Source: AGHT+IG94GogIvQlw6AUXYec3gVwZhfGDEiqwjP8IQRfb6C/suIMb1SAAxTKsPNPKoQ1M3OPgm84 X-Received: by 2002:a05:6402:33d9:b0:564:116d:6653 with SMTP id a25-20020a05640233d900b00564116d6653mr962345edc.32.1708127986924; Fri, 16 Feb 2024 15:59:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127986; cv=pass; d=google.com; s=arc-20160816; b=U4Qog9brz+mYFmkkiha07WaXE696A3Od0Df2XuN4vFwtz75rknba/WD0Z/S+LM3Ome 3fkeUSKgjA8eSNffbNUjUQoOf4fcVGpYfUyghP2oYMhdX6tvRVnwGkKNSpRYw/fh646L u23r9AbrMhJDL4PrYmpXrRd5s8QstUiPxvbuRBZlvG5oJqv6+Be1pbcG5QETAy5iDujK KL59GCKPWKLqF4qUgv17IZZ4DRanNyF16O7EmAP1W+fSK7b74gVcUNJ4smOsG5aT++Qw 4ZfSTYxwJXI9vMJdGnSen7/PEAiGZIHbewxCGd5D6jifze0zJSp59aB16o966kbsJvpy I5ZA== 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=BDoXWFUllq5r9qvxHaqqdOtetQC7wmYhYSm0N03NFTM=; fh=Y9L1piLWeaTYu4QosCqlK5nYH5MtEnvKKaiR06Zjlok=; b=N98wAB1f/t/i9VVhlJQIFevWi+Y/YwnRSMiAVBgBhD15S1gkPeC/z59fHv8bctPsjZ 4D4DVAGty69bYrNu3uukeQ5mhLyvefuF9NNikPlUNSTK1fLo6xHTA3hPOHkw1517EZmH Lgn2JFvRSLG1YAuzMPBkAXcel+5/cYYEMLpJ3p7z/6Uu8cqrkGXWMD8Kq+/gTKLwN6wX XJ2CegZiwFMA18zBsqjRGPA8mEdDVCCH0yRDTzBlal9/eT/TR1rRtAyhl6wr/UMcKlmL vUy37CSzz07g/pKx7ck2/05/xQFYtNHKKTSxVdKvVH7zb4BHOglv8a78bXlEYUsqdazs kh4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0abjhKbL; 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-69513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69513-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bd26-20020a056402207a00b00560ef1cfc92si382594edb.218.2024.02.16.15.59.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:59:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0abjhKbL; 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-69513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69513-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 399951F22297 for ; Fri, 16 Feb 2024 23:59:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB1A014AD3E; Fri, 16 Feb 2024 23:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0abjhKbL" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 DE670153507 for ; Fri, 16 Feb 2024 23:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127727; cv=none; b=AaRkeD+h8ieOf7MLP0kJpasnc+NlVZ9eFhCKt6G14IxN5m9kkG1bOaN5XcLMqRNcRKD158w7chFrW9WtFJC5aXxd0iLugqLwD+dMxl8dhIFBupRz7oMgnMQHztKXOSLYZyVHeeB+j3cp2ynwR9uvtrkfAYzqoZKndWIMfuECptU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127727; c=relaxed/simple; bh=I+UE93RRTXaqRw/ye3XEqbtXPztsO4QkZJrrM8rzem4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=PEICb1lO4bH7Murr/bMCjjv9Jm4y+5D7mIzobnTRt9xjniQpfRr/qyzCQ97PcUafxAs0qTXzz2yz1HU6Owx6//+B+QLFrrcGBFfDLluyvzVa9qYfvQimzzWxs+cV+0MnOxGOPDfaoiCiyJnpUpdJsYzMv93TNU1jJ+BggvH2xhY= 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=0abjhKbL; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-5ffee6fcdc1so20402607b3.2 for ; Fri, 16 Feb 2024 15:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127724; x=1708732524; 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=BDoXWFUllq5r9qvxHaqqdOtetQC7wmYhYSm0N03NFTM=; b=0abjhKbLH+0b2/hA7gQDVaBkOkI5Oct22+pH28A+PD2G2f/N/kqBwB9BaVgzWabl06 j5rAY6TOX7i2WGcsMbZlh4ZNH9gifdumlY/oHNCVLxkcbxNunDMqh6kpDkLz996zZCax lgq0ULCvYzrJtLylrkwVirTBDCqZc6/CgXQMY+OVCApNYIHFVowUjj/VzuK+o+TJCVXg /gB8i71e6Kv6hWADwOUI9Q2k0Ft1UVRdMY8uC7nJZ4otmM4siwR/k1wg+Fl8sAGkKwqc R2lXOta0Snn33dttEvEy0wPYRO6yxmtZlEjfOweaYcSm3cFVK3fIJDa838bdIAuC4xwr UC1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127724; x=1708732524; 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=BDoXWFUllq5r9qvxHaqqdOtetQC7wmYhYSm0N03NFTM=; b=n74LjTPoMa8InSeyvr477swUu5Scd1ZBrUq+mZQ+6xdz9+M+I1UjbALoOkpRLr0G5s x4LXQy05mrw4Rgn7kLF+J2X9K3wW4BHIgUpY7T39aMCzMoMBwDXShdtxEbVtj1IgMDm5 wt4/Ezcf64VmFk9OgMpe4fojp9Mr2HME/cTMyj0fwfpkXWT9I69PmyxZaLz4WaTwmNC3 a720CkLygeinyc73CRlSzCbPYaMbivW324PGz0AhHE1Km+clZcLK+C8O9wXMK3/ocYy1 +OBVtZ75oRJRAew+1K8nJdyTN1bFJwfzh8NIOWJjY7GG3kvf91tlo3lyH8/AxyhtYAM4 EehQ== X-Forwarded-Encrypted: i=1; AJvYcCUXZ1lrJJ6nGi9O/qHa5dmEvw2n9BR+DKJJ/6EYfY8HN6u0zH+jL3RbxDNWXXAY6PKdbEvRbCxJciMbL63bB7d+U8gOtrMBOEsVSU52 X-Gm-Message-State: AOJu0YyF02h6OA30greYHWKC+l61zxraqhdsj5UJvvPqGNnQpitdjnx7 w9hLbdQt+YxYFDYLlu1jLaxdq8d0lDyD5z/37n9HmjIFb32fDzveXTd5xjtziAXIoLpwl+Yih2c YDL6r5g== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a0d:db4b:0:b0:607:81e1:8b83 with SMTP id d72-20020a0ddb4b000000b0060781e18b83mr1157396ywe.8.1708127724036; Fri, 16 Feb 2024 15:55:24 -0800 (PST) Date: Fri, 16 Feb 2024 15:51:59 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 5/8] perf test: Rename builtin-test-list and add missed header guard 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 , Athira Jajeev , James Clark , 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: 1791102012171075395 X-GMAIL-MSGID: 1791102012171075395 builtin-test-list is primarily concerned with shell script tests. Rename the file to better reflect this and add a missed header guard. Signed-off-by: Ian Rogers --- tools/perf/tests/Build | 2 +- tools/perf/tests/builtin-test.c | 2 +- tools/perf/tests/{builtin-test-list.c => tests-scripts.c} | 2 +- tools/perf/tests/{builtin-test-list.h => tests-scripts.h} | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) rename tools/perf/tests/{builtin-test-list.c => tests-scripts.c} (99%) rename tools/perf/tests/{builtin-test-list.h => tests-scripts.h} (79%) diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 53ba9c3e20e0..c7f9d9676095 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 perf-y += builtin-test.o -perf-y += builtin-test-list.o +perf-y += tests-scripts.o perf-y += parse-events.o perf-y += dso-data.o perf-y += attr.o diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 4a5973f9bb9b..eff3c62e9b47 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -29,7 +29,7 @@ #include #include -#include "builtin-test-list.h" +#include "tests-scripts.h" static bool dont_fork; const char *dso_to_test; diff --git a/tools/perf/tests/builtin-test-list.c b/tools/perf/tests/tests-scripts.c similarity index 99% rename from tools/perf/tests/builtin-test-list.c rename to tools/perf/tests/tests-scripts.c index a65b9e547d82..4ebd841da05b 100644 --- a/tools/perf/tests/builtin-test-list.c +++ b/tools/perf/tests/tests-scripts.c @@ -15,7 +15,7 @@ #include #include #include "builtin.h" -#include "builtin-test-list.h" +#include "tests-scripts.h" #include "color.h" #include "debug.h" #include "hist.h" diff --git a/tools/perf/tests/builtin-test-list.h b/tools/perf/tests/tests-scripts.h similarity index 79% rename from tools/perf/tests/builtin-test-list.h rename to tools/perf/tests/tests-scripts.h index eb81f3aa6683..3a3ec6191848 100644 --- a/tools/perf/tests/builtin-test-list.h +++ b/tools/perf/tests/tests-scripts.h @@ -1,4 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#ifndef TESTS_SCRIPTS_H +#define TESTS_SCRIPTS_H struct script_file { char *dir; @@ -10,3 +12,5 @@ struct script_file { const struct script_file *list_script_files(void); /* Get maximum width of description string */ int list_script_max_width(void); + +#endif /* TESTS_SCRIPTS_H */ From patchwork Fri Feb 16 23:52:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60835dyc; Fri, 16 Feb 2024 16:00:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWS8go+HoUCQ2sWSU76ngn8rIOZvRPQHWHqyIFiCby81tgrvxIGdYEWEWgqPLm67HmXK3sEz8Y3LrJdzqUqN+d8nzze8g== X-Google-Smtp-Source: AGHT+IG1gxqDF2rSKlCiaQt6E87y86rInbg6foZ2+3wpYrlN9ihoe/DZVvp3vXU7GYqhQNuNhI5Q X-Received: by 2002:a05:6214:4b07:b0:68f:1178:6911 with SMTP id pj7-20020a0562144b0700b0068f11786911mr12969056qvb.12.1708128002823; Fri, 16 Feb 2024 16:00:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708128002; cv=pass; d=google.com; s=arc-20160816; b=AeC/ihLI6DYBIj9WsJqW5DCY3aWFzqiGisHDJVZ576GVFWy+AvcxBnU00+lgIaNBxv jhGzDuhlEMqFw23jjmWswDcrRyZhip8ERqzAghnSpJQwEam864aID/M6Ugps2GWvGgxu vgz3TNeucwCdP7NsqwgXwAIq/ESvwhKIWjHBX17eAOK0OZVUFA3FMwcowHQB9wVULMu2 T+OPSHOEMEVYiNCA/wHmzJHKIhcsqZk8ZtSpzgXwprKh2Vsqc5GjVOwisglk20Qc7YIe PjNblC0f1lwRgTPwJfbil/I6wxizzPEsq5KXLxKB66KO5DO/NgSgmO2EPqCpYpeySDeR 5rJA== 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=1db4d5Ry/IAvhrQl71MJvl5OaxqbAsRxOegC78cfvLc=; fh=t2sIaiVXyDRtWBQWSdf9o58yEC2SGl+RqXMe3xJPUAk=; b=OJENO26pR7ZW0if8MV+GPMyAmx7MM9kpW3NvuUWlgpQ0lIKdxcmQovQhE1zbnQwZVZ 7wsyLLRcqK32Lgij6vnOu1V0cBolXjWgM1/rh36qTPSsxTBAfJEH7udRY+2VWexMnf+s QNzUQQgzrzga0M5jGe1jR3p3FCbQl1nMTn1gRkCMXEvzS3wLlBLSiNEkYsO7JnYX+n3j LHMp4l3RFXPqn7ceSWHkSuv+b3IeUaJNNdazBSsu7PZZ+AX3eh8UkE4IwbBbkpWdwm89 jw2blh+fGM4TJ7l26BCRmAh7ziVb3a37vQCcxoMYsqjC+Y63d1k1gG+dV6zDhRebBqkG t8mQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4fSi8R+f; 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-69514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69514-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kc3-20020a056214410300b0068d14cbf19csi916198qvb.345.2024.02.16.16.00.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:00:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4fSi8R+f; 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-69514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69514-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8D2561C223DB for ; Sat, 17 Feb 2024 00:00:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51C65153BE6; Fri, 16 Feb 2024 23:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4fSi8R+f" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 66BF315351F for ; Fri, 16 Feb 2024 23:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127729; cv=none; b=InDKanb3r47liweB8HWGdZEC7F41fDfobCqeYLj/zcq6aM6acO1/kRW+RQVNMkVe7mlHJ8V5Rm4Q9VPUkzsOsd9BHNYxcR3xvz1bwbiYRcA/4nYuYpf2OhLW0jtsgpvttPOEMV/6BwStr8jEE5YEFw7NC+4uEXQcrkI6+iIUwtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127729; c=relaxed/simple; bh=JvHCpgh4aCf+IBbox5C5R6/5SztYcmRnsES50kS19ls=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Ki70cpejn6xYh+sxC1L9a+y5+eHHjnseV0fFzU7IKzppWVisEjBvAkB07F5naCKRpsLR42WY/f1dzzGKWTCdHsIhaifarH0zLUpxsCzbxMu4Y60G3lyS71ym59/b0tQyvcUbQhtTNaoq1Uzd+v7agQkXBkf72TUS31Tbwnaeauk= 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=4fSi8R+f; arc=none smtp.client-ip=209.85.219.202 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-f202.google.com with SMTP id 3f1490d57ef6-dcc58cddb50so4312168276.0 for ; Fri, 16 Feb 2024 15:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127726; x=1708732526; 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=1db4d5Ry/IAvhrQl71MJvl5OaxqbAsRxOegC78cfvLc=; b=4fSi8R+fuMSKqV1UwAaSrUGj/dbTgXTrTFZsM7KiV8RXTAHkVqogqvGTQuELMGQYPk 5kEC5IoeJEfOcGx3OF6u4AdJuw0306+VlJjPxWrHlgG6xoftNJqGGRf9dCOJtoxRdDh7 RyiczqPYvXBFxcC/t4SwPUJ5WdIVZLfFh1zQg2qZMSfdnIT6nnLNamV2ANBO4Krf8q0Q yNGtFq74DaWerMbkZ4xnp9+LmXi6BM9BvHmu/zTq41EsfxMra9SMX+QgxYShABrJbybu 2N2LppyUgJ5K44yeOzse0++s+ZLZ+H2BuQCTlbKvK6N1DXH9rqDrdlYbpEwx/zBs6P28 omSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127726; x=1708732526; 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=1db4d5Ry/IAvhrQl71MJvl5OaxqbAsRxOegC78cfvLc=; b=eZJFiUckIUGLB375gnn2riOu5KfWcn0Necv5CETNVtwwYzTXKocCS9hmw/CjhJRAmX Ffeb8j7h+pySGtV4BtUORSU4raNy/lA7CdoSGWLYJD1qUlCcidXBQT1Al5g1L0fk4keP DBzU7IXFbc0T+Wjc0r0/Zuc6u9faFKTdn1CqTkzZeTkXEP4S1o+k6gdqqdw6PcK5UyJB ikawqjClKbecxndCCJNb86HGkoDBmMq1hUIPcFcwwW0ZKgDuk8RZ6i8ouVJws4Rsn4lc MExHxxqsxaPIKVcm6onXclBfw+AQo+cy/9R1M+OzCSZXhD9ywNXk4i/5o3rOUeiKkMRc vnkA== X-Forwarded-Encrypted: i=1; AJvYcCUrHKHi8MatKFdwtNKDZA6L1leHNySpyssE7nSsceTs4YmN2rWKB/fDH55s9GTvYwXAs2ff9ZDISkUJ8prIqn5dv3PyIudhjfoJSFvv X-Gm-Message-State: AOJu0YwPC9JmDjyQvxEkfdX/1qWkqDesr+IU4eRtMScl8Chy04F5ki7g fqDuJErr1Ofj74whbhs3vauld7a6tovD8wU8Djl0hkoOOAlHjwNnQbdd90DAlFBFPNtPn1hQ6sD wMZr8Cw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a25:bc92:0:b0:dcb:bc80:8333 with SMTP id e18-20020a25bc92000000b00dcbbc808333mr653600ybk.13.1708127726529; Fri, 16 Feb 2024 15:55:26 -0800 (PST) Date: Fri, 16 Feb 2024 15:52:00 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 6/8] perf tests: Use scandirat for shell script finding 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 , Athira Jajeev , James Clark , 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: 1791102028561332501 X-GMAIL-MSGID: 1791102028561332501 Avoid filename appending buffers by using openat, faccessat and scandirat more widely. Turn the script's path back to a file name using readlink from /proc//fd/. Read the script's description using api/io.h to avoid fdopen conversions. Whilst reading perform additional sanity checks on the script's contents. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 20 ++--- tools/perf/tests/tests-scripts.c | 144 ++++++++++++++++++------------- tools/perf/tests/tests-scripts.h | 1 - 3 files changed, 94 insertions(+), 71 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index eff3c62e9b47..162f9eb090ac 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -300,22 +300,19 @@ static int test_and_print(struct test_suite *t, int subtest) } struct shell_test { - const char *dir; const char *file; }; static int shell_test__run(struct test_suite *test, int subdir __maybe_unused) { int err; - char script[PATH_MAX]; struct shell_test *st = test->priv; + char *cmd = NULL; - path__join(script, sizeof(script) - 3, st->dir, st->file); - - if (verbose > 0) - strncat(script, " -v", sizeof(script) - strlen(script) - 1); - - err = system(script); + if (asprintf(&cmd, "%s%s", st->file, verbose ? " -v" : "") < 0) + return TEST_FAIL; + err = system(cmd); + free(cmd); if (!err) return TEST_OK; @@ -331,7 +328,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width, files = list_script_files(); if (!files) return 0; - for (file = files; file->dir; file++) { + for (file = files; file->file; file++) { int curr = i++; struct test_case test_cases[] = { { @@ -345,13 +342,12 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width, .test_cases = test_cases, .priv = &st, }; - st.dir = file->dir; + st.file = file->file; if (test_suite.desc == NULL || !perf_test__matches(test_suite.desc, curr, argc, argv)) continue; - st.file = file->file; pr_info("%3d: %-*s:", i, width, test_suite.desc); if (intlist__find(skiplist, i)) { @@ -455,7 +451,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i) files = list_script_files(); if (!files) return 0; - for (file = files; file->dir; file++) { + for (file = files; file->file; file++) { int curr = i++; struct test_suite t = { .desc = file->desc diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c index 4ebd841da05b..9b3b66dd5508 100644 --- a/tools/perf/tests/tests-scripts.c +++ b/tools/perf/tests/tests-scripts.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "builtin.h" #include "tests-scripts.h" #include "color.h" @@ -35,55 +36,69 @@ static size_t files_num = 0; static struct script_file *files = NULL; static int files_max_width = 0; -static const char *shell_tests__dir(char *path, size_t size) +static int shell_tests__dir_fd(void) { - const char *devel_dirs[] = { "./tools/perf/tests", "./tests", }; - char *exec_path; - unsigned int i; + char path[PATH_MAX], *exec_path; + static const char * const devel_dirs[] = { "./tools/perf/tests/shell", "./tests/shell", }; - for (i = 0; i < ARRAY_SIZE(devel_dirs); ++i) { - struct stat st; + for (size_t i = 0; i < ARRAY_SIZE(devel_dirs); ++i) { + int fd = open(devel_dirs[i], O_PATH); - if (!lstat(devel_dirs[i], &st)) { - scnprintf(path, size, "%s/shell", devel_dirs[i]); - if (!lstat(devel_dirs[i], &st)) - return path; - } + if (fd >= 0) + return fd; } /* Then installed path. */ exec_path = get_argv_exec_path(); - scnprintf(path, size, "%s/tests/shell", exec_path); + scnprintf(path, sizeof(path), "%s/tests/shell", exec_path); free(exec_path); - return path; + return open(path, O_PATH); } -static const char *shell_test__description(char *description, size_t size, - const char *path, const char *name) +static char *shell_test__description(int dir_fd, const char *name) { - FILE *fp; - char filename[PATH_MAX]; - int ch; + struct io io; + char buf[128], desc[256]; + int ch, pos = 0; - path__join(filename, sizeof(filename), path, name); - fp = fopen(filename, "r"); - if (!fp) + io__init(&io, openat(dir_fd, name, O_RDONLY), buf, sizeof(buf)); + if (io.fd < 0) return NULL; /* Skip first line - should be #!/bin/sh Shebang */ + if (io__get_char(&io) != '#') + goto err_out; + if (io__get_char(&io) != '!') + goto err_out; do { - ch = fgetc(fp); - } while (ch != EOF && ch != '\n'); - - description = fgets(description, size, fp); - fclose(fp); + ch = io__get_char(&io); + if (ch < 0) + goto err_out; + } while (ch != '\n'); - /* Assume first char on line is omment everything after that desc */ - return description ? strim(description + 1) : NULL; + do { + ch = io__get_char(&io); + if (ch < 0) + goto err_out; + } while (ch == '#' || isspace(ch)); + while (ch > 0 && ch != '\n') { + desc[pos++] = ch; + if (pos >= (int)sizeof(desc) - 1) + break; + ch = io__get_char(&io); + } + while (pos > 0 && isspace(desc[--pos])) + ; + desc[++pos] = '\0'; + close(io.fd); + return strdup(desc); +err_out: + close(io.fd); + return NULL; } /* Is this full file path a shell script */ -static bool is_shell_script(const char *path) +static bool is_shell_script(int dir_fd, const char *path) { const char *ext; @@ -91,20 +106,16 @@ static bool is_shell_script(const char *path) if (!ext) return false; if (!strcmp(ext, ".sh")) { /* Has .sh extension */ - if (access(path, R_OK | X_OK) == 0) /* Is executable */ + if (faccessat(dir_fd, path, R_OK | X_OK, 0) == 0) /* Is executable */ return true; } return false; } /* Is this file in this dir a shell script (for test purposes) */ -static bool is_test_script(const char *path, const char *name) +static bool is_test_script(int dir_fd, const char *name) { - char filename[PATH_MAX]; - - path__join(filename, sizeof(filename), path, name); - if (!is_shell_script(filename)) return false; - return true; + return is_shell_script(dir_fd, name); } /* Duplicate a string and fall over and die if we run out of memory */ @@ -120,12 +131,21 @@ static char *strdup_check(const char *str) return newstr; } -static void append_script(const char *dir, const char *file, const char *desc) +static void append_script(int dir_fd, const char *name, char *desc) { + char filename[PATH_MAX], link[128]; struct script_file *files_tmp; - size_t files_num_tmp; + size_t files_num_tmp, len; int width; + snprintf(link, sizeof(link), "/proc/%d/fd/%d", getpid(), dir_fd); + len = readlink(link, filename, sizeof(filename)); + if (len < 0) { + pr_err("Failed to readlink %s", link); + return; + } + filename[len++] = '/'; + strcpy(&filename[len], name); files_num_tmp = files_num + 1; if (files_num_tmp >= SIZE_MAX) { pr_err("Too many script files\n"); @@ -142,10 +162,8 @@ static void append_script(const char *dir, const char *file, const char *desc) /* Add file to end and NULL terminate the struct array */ files = files_tmp; files_num = files_num_tmp; - files[files_num - 1].dir = strdup_check(dir); - files[files_num - 1].file = strdup_check(file); - files[files_num - 1].desc = strdup_check(desc); - files[files_num].dir = NULL; + files[files_num - 1].file = strdup_check(filename); + files[files_num - 1].desc = desc; files[files_num].file = NULL; files[files_num].desc = NULL; @@ -154,32 +172,39 @@ static void append_script(const char *dir, const char *file, const char *desc) files_max_width = width; } -static void append_scripts_in_dir(const char *path) +static void append_scripts_in_dir(int dir_fd) { struct dirent **entlist; struct dirent *ent; int n_dirs, i; - char filename[PATH_MAX]; /* List files, sorted by alpha */ - n_dirs = scandir(path, &entlist, NULL, alphasort); + n_dirs = scandirat(dir_fd, ".", &entlist, NULL, alphasort); if (n_dirs == -1) return; for (i = 0; i < n_dirs && (ent = entlist[i]); i++) { + int fd; + if (ent->d_name[0] == '.') continue; /* Skip hidden files */ - if (is_test_script(path, ent->d_name)) { /* It's a test */ - char bf[256]; - const char *desc = shell_test__description - (bf, sizeof(bf), path, ent->d_name); + if (is_test_script(dir_fd, ent->d_name)) { /* It's a test */ + char *desc = shell_test__description(dir_fd, ent->d_name); if (desc) /* It has a desc line - valid script */ - append_script(path, ent->d_name, desc); - } else if (is_directory(path, ent)) { /* Scan the subdir */ - path__join(filename, sizeof(filename), - path, ent->d_name); - append_scripts_in_dir(filename); + append_script(dir_fd, ent->d_name, desc); + continue; + } + if (ent->d_type != DT_DIR) { + struct stat st; + + if (ent->d_type != DT_UNKNOWN) + continue; + fstatat(dir_fd, ent->d_name, &st, 0); + if (!S_ISDIR(st.st_mode)) + continue; } + fd = openat(dir_fd, ent->d_name, O_PATH); + append_scripts_in_dir(fd); } for (i = 0; i < n_dirs; i++) /* Clean up */ zfree(&entlist[i]); @@ -188,14 +213,17 @@ static void append_scripts_in_dir(const char *path) const struct script_file *list_script_files(void) { - char path_dir[PATH_MAX]; - const char *path; + int dir_fd; if (files) return files; /* Singleton - we already know our list */ - path = shell_tests__dir(path_dir, sizeof(path_dir)); /* Walk dir */ - append_scripts_in_dir(path); + dir_fd = shell_tests__dir_fd(); /* Walk dir */ + if (dir_fd < 0) + return NULL; + + append_scripts_in_dir(dir_fd); + close(dir_fd); return files; } diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h index 3a3ec6191848..3508a293aaf9 100644 --- a/tools/perf/tests/tests-scripts.h +++ b/tools/perf/tests/tests-scripts.h @@ -3,7 +3,6 @@ #define TESTS_SCRIPTS_H struct script_file { - char *dir; char *file; char *desc; }; From patchwork Fri Feb 16 23:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp60984dyc; Fri, 16 Feb 2024 16:00:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUSZQKpF30aTac9ASpKweBDNIwCmr0yfFA23DVUzsmglAE7nwn/+ojXHAIAAmSudz3Stkwe0FMOfSV32uqXNUIw5F1DKA== X-Google-Smtp-Source: AGHT+IGQsBOZyJsyWKrjRIoTAmB5+TUQ/DhJFx3XB9wMpDBgTFqqpKPSOTN3edssqIOCqY72HkN5 X-Received: by 2002:a05:6808:3006:b0:3c0:32f9:8a38 with SMTP id ay6-20020a056808300600b003c032f98a38mr6615685oib.52.1708128016312; Fri, 16 Feb 2024 16:00:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708128016; cv=pass; d=google.com; s=arc-20160816; b=WejF2ipgi8WhJjX9RH201WoPu+tFO0nK3eAEfAta0rWggjytNbEtcxgQTqIwJsD55I 46vh8XagNisX7VbTYpR9JiBU0EoFEVlPNVi8H17npaKjaRfYkr2J0/uZJUyyD0JHrK2g /PtBNbiNzj6SAdp1/4MbvZWazG3b1BWJY30roMB9qKBDLiRqg89Qgo4fx/J5wYeIniMg zNClIsW0HCVBydXMk5B7LWhC/M+FhQYDOyovAEyELGJHfERqhGRSS9D1opWqbqJVqAP4 GPer6BU+5lhO6Yu2AcVITHCESo6gU2zns0+2AOGSl9Y4JPhF0Ccl7liARLAoMROTQwV5 qVgg== 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; fh=4EGySIOEOaKA+L8CsO/AmqQaOFKOeWUiBZrwZivZWdM=; b=B1XolktX6uy7hd5Ru2UFk1tSnm+2b0zuy9W6xu7WRhebPNmZ9D7nLEibb6GqC6gQrN e0e1Nj/mGElyqrEK2+TWKq70uCe2i10TV4mu/LQfZ2uCe0ICQJtNxTMJ6vYMK1Yep34v B9Q0aINpMbGOlIJvNnvETbsY7rJgjn28m0g1pgHb1h2Dq+vdiOdV53NLH/sj0HYbtJ/U CzyBjsJlQgqLSpiQUlSc2P2+LtSWWw61LFypYYPEMP2FlEc2gl5CSNkFwrDums+4BmoD DxGdoAha5wLnpUSG3iV+jxceDb8Wttffkekjys16HsGubtObPY48ejYsLUn6DEshx02N 2N5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="n01txE/T"; 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-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h1-20020a0562140da100b0068cb07848a0si1011203qvh.477.2024.02.16.16.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:00:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="n01txE/T"; 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-69515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69515-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EE9541C21D9D for ; Sat, 17 Feb 2024 00:00:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60C27154432; Fri, 16 Feb 2024 23:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n01txE/T" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 8FCAE153BD4 for ; Fri, 16 Feb 2024 23:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127731; cv=none; b=n8HsfFNP1c2bP2dwy4srM48NJ2Zk9EMDU/QU2K9grGV0tBLTzATRfU4yl4te42uERBgbWiK8UHsxeJrnjAFRAFJDZFo9903foo+KQPfgM2MBipKGOnObwhRJgxkFglYR+FM8D7jTTpzGN7VR+kVYi966A/L4nYr8MU79+gDg/0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127731; c=relaxed/simple; bh=bFrvnWICKZ7AZF3dktZ2KHx1E9RGrF6vgCjDjEm+vlk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DMXAO2Am+c9VikAgdpuXNamBjffQ0o8WDYib2cWHA+oGGTjFVysJ9U6q2rnDrrCDdFN2iyGhYtZngHUYcxSHx9149xzet0Zisw+DUZCnBj4Ng03/3qNS2XAPHdCqfAAoFHWwAGK4yfOU7lMf9P9OaAaTda9Eu549ikunW9Vtin4= 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=n01txE/T; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-607cef709dcso43647247b3.1 for ; Fri, 16 Feb 2024 15:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127728; x=1708732528; 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; b=n01txE/TGcn6iP/DugKR85/L0K1Au9W0sxLwbsiI4PC4WPPpFOc+Dpk4MdGdbEE5rf t9qq3og0Ej811AxJiWLdENdLDgFU7YNhK2I6+XkZuDhouAPsCfPaQLKjEfPEH3+U//Ay opJz/wL63OGmSSYC5Lg44nZUabqYJ0j7VCfH6THxI5mPVo7eAO8DvRhLCIv249+dBE+1 y3tjr3NlhkWJaj5H4SqFlXRQ4OOuKxZP0i98dYiRAtNSI2kQwebiC6W9qfQd2PgjC6f5 VOxFN4Pa8c/7yWu8WBoz2+17X723k5+VA98fDqO/rLxe/WBKjg6u4BBXDr2m5GRCEWKQ OYPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127728; x=1708732528; 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=poJvPdqYu3wRi085PL1Kek3TRdO+XaNmw3RkdStDr4c=; b=LduuhFzzy21mEzD++wNUxCQB7voEpm9UlpbIWSFfPoPCJbduA4jFZC3iNew5EkqFeO nM87FAZEQxZEODVMQk8lQvos6k2NHtUQt+rrzsZCgPOSEbPg4E7T2O5cBxSyPEEbWLBD oKCF+PXXdIX+Ytil+X4cdxeaY1kVj47iT8GUKqh1gvpFUlwQEBEUNYzT/6rtzEBS1jjh rJl9SH6D6ZgFJskqyXS7VCxlDh8VUxLOz/LouIv3c9OOM56aGUs6Bu8LtXEgtjV+wd4i IoxxNA/Xk3EbVUldnl+TBI/Utj3yVqLr6bn7VH6SpN2/yK5IO0C6kkr7sUuY8G6D4Env xjwQ== X-Forwarded-Encrypted: i=1; AJvYcCU3qfUJmopaXMB7ozi3QgyAhKJYwKm8T6fnjpEe5bovXAFtLF0DgCyvq55ev03zGn/7UsqUsLARAvJwxqz1tdLLj12GY9tRm2GVesTD X-Gm-Message-State: AOJu0Yz4jiUohfLlaELoNBpDAqvwD7KrPqS2nY1MXp+WBSgn6+wSW3vp lSyjt51d1qHuzKW/JjSvTVx1o8g5277giC/R2JdaH1D3WeaMXalx80bt2kLzUSBSSdaTMR4rgXD 4bQqADw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a0d:cc81:0:b0:604:103:567d with SMTP id o123-20020a0dcc81000000b006040103567dmr1503270ywd.0.1708127728643; Fri, 16 Feb 2024 15:55:28 -0800 (PST) Date: Fri, 16 Feb 2024 15:52:01 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 7/8] perf tests: Run time generate shell test suites 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 , Athira Jajeev , James Clark , 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: 1791102042610624493 X-GMAIL-MSGID: 1791102042610624493 Rather than special shell test logic, do a single pass to create an array of test suites. Hold the shell test file name in the test suite priv field. This makes the special shell test logic in builtin-test.c redundant so remove it. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 90 +-------------------- tools/perf/tests/tests-scripts.c | 129 ++++++++++++++++++------------- tools/perf/tests/tests-scripts.h | 10 +-- 3 files changed, 80 insertions(+), 149 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 162f9eb090ac..c42cb40fc242 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -130,6 +130,7 @@ static struct test_suite *generic_tests[] = { static struct test_suite **tests[] = { generic_tests, arch_tests, + NULL, /* shell tests created at runtime. */ }; static struct test_workload *workloads[] = { @@ -299,73 +300,12 @@ static int test_and_print(struct test_suite *t, int subtest) return err; } -struct shell_test { - const char *file; -}; - -static int shell_test__run(struct test_suite *test, int subdir __maybe_unused) -{ - int err; - struct shell_test *st = test->priv; - char *cmd = NULL; - - if (asprintf(&cmd, "%s%s", st->file, verbose ? " -v" : "") < 0) - return TEST_FAIL; - err = system(cmd); - free(cmd); - if (!err) - return TEST_OK; - - return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL; -} - -static int run_shell_tests(int argc, const char *argv[], int i, int width, - struct intlist *skiplist) -{ - struct shell_test st; - const struct script_file *files, *file; - - files = list_script_files(); - if (!files) - return 0; - for (file = files; file->file; file++) { - int curr = i++; - struct test_case test_cases[] = { - { - .desc = file->desc, - .run_case = shell_test__run, - }, - { .name = NULL, } - }; - struct test_suite test_suite = { - .desc = test_cases[0].desc, - .test_cases = test_cases, - .priv = &st, - }; - st.file = file->file; - - if (test_suite.desc == NULL || - !perf_test__matches(test_suite.desc, curr, argc, argv)) - continue; - - pr_info("%3d: %-*s:", i, width, test_suite.desc); - - if (intlist__find(skiplist, i)) { - color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); - continue; - } - - test_and_print(&test_suite, 0); - } - return 0; -} - static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) { struct test_suite *t; unsigned int j, k; int i = 0; - int width = list_script_max_width(); + int width = 0; for_each_test(j, k, t) { int len = strlen(test_description(t, -1)); @@ -440,28 +380,6 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) } } } - - return run_shell_tests(argc, argv, i, width, skiplist); -} - -static int perf_test__list_shell(int argc, const char **argv, int i) -{ - const struct script_file *files, *file; - - files = list_script_files(); - if (!files) - return 0; - for (file = files; file->file; file++) { - int curr = i++; - struct test_suite t = { - .desc = file->desc - }; - - if (!perf_test__matches(t.desc, curr, argc, argv)) - continue; - - pr_info("%3d: %s\n", i, t.desc); - } return 0; } @@ -488,9 +406,6 @@ static int perf_test__list(int argc, const char **argv) test_description(t, subi)); } } - - perf_test__list_shell(argc, argv, i); - return 0; } @@ -550,6 +465,7 @@ int cmd_test(int argc, const char **argv) /* Unbuffered output */ setvbuf(stdout, NULL, _IONBF, 0); + tests[2] = create_script_test_suites(); argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0); if (argc >= 1 && !strcmp(argv[0], "list")) return perf_test__list(argc - 1, argv + 1); diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c index 9b3b66dd5508..1b99af5c353e 100644 --- a/tools/perf/tests/tests-scripts.c +++ b/tools/perf/tests/tests-scripts.c @@ -26,16 +26,6 @@ #include "tests.h" #include "util/rlimit.h" - -/* - * As this is a singleton built once for the run of the process, there is - * no value in trying to free it and just let it stay around until process - * exits when it's cleaned up. - */ -static size_t files_num = 0; -static struct script_file *files = NULL; -static int files_max_width = 0; - static int shell_tests__dir_fd(void) { char path[PATH_MAX], *exec_path; @@ -131,12 +121,30 @@ static char *strdup_check(const char *str) return newstr; } -static void append_script(int dir_fd, const char *name, char *desc) +static int shell_test__run(struct test_suite *test, int subtest __maybe_unused) +{ + const char *file = test->priv; + int err; + char *cmd = NULL; + + if (asprintf(&cmd, "%s%s", file, verbose ? " -v" : "") < 0) + return TEST_FAIL; + err = system(cmd); + free(cmd); + if (!err) + return TEST_OK; + + return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL; +} + +static void append_script(int dir_fd, const char *name, char *desc, + struct test_suite ***result, + size_t *result_sz) { char filename[PATH_MAX], link[128]; - struct script_file *files_tmp; - size_t files_num_tmp, len; - int width; + struct test_suite *test_suite, **result_tmp; + struct test_case *tests; + size_t len; snprintf(link, sizeof(link), "/proc/%d/fd/%d", getpid(), dir_fd); len = readlink(link, filename, sizeof(filename)); @@ -146,33 +154,43 @@ static void append_script(int dir_fd, const char *name, char *desc) } filename[len++] = '/'; strcpy(&filename[len], name); - files_num_tmp = files_num + 1; - if (files_num_tmp >= SIZE_MAX) { - pr_err("Too many script files\n"); - abort(); + + tests = calloc(2, sizeof(*tests)); + if (!tests) { + pr_err("Out of memory while building script test suite list\n"); + return; } + tests[0].name = strdup_check(name); + tests[0].desc = strdup_check(desc); + tests[0].run_case = shell_test__run; + + test_suite = zalloc(sizeof(*test_suite)); + if (!test_suite) { + pr_err("Out of memory while building script test suite list\n"); + free(tests); + return; + } + test_suite->desc = desc; + test_suite->test_cases = tests; + test_suite->priv = strdup_check(filename); /* Realloc is good enough, though we could realloc by chunks, not that * anyone will ever measure performance here */ - files_tmp = realloc(files, - (files_num_tmp + 1) * sizeof(struct script_file)); - if (files_tmp == NULL) { - pr_err("Out of memory while building test list\n"); - abort(); + result_tmp = realloc(*result, (*result_sz + 1) * sizeof(*result_tmp)); + if (result_tmp == NULL) { + pr_err("Out of memory while building script test suite list\n"); + free(tests); + free(test_suite); + return; } /* Add file to end and NULL terminate the struct array */ - files = files_tmp; - files_num = files_num_tmp; - files[files_num - 1].file = strdup_check(filename); - files[files_num - 1].desc = desc; - files[files_num].file = NULL; - files[files_num].desc = NULL; - - width = strlen(desc); /* Track max width of desc */ - if (width > files_max_width) - files_max_width = width; + *result = result_tmp; + (*result)[*result_sz] = test_suite; + (*result_sz)++; } -static void append_scripts_in_dir(int dir_fd) +static void append_scripts_in_dir(int dir_fd, + struct test_suite ***result, + size_t *result_sz) { struct dirent **entlist; struct dirent *ent; @@ -191,7 +209,7 @@ static void append_scripts_in_dir(int dir_fd) char *desc = shell_test__description(dir_fd, ent->d_name); if (desc) /* It has a desc line - valid script */ - append_script(dir_fd, ent->d_name, desc); + append_script(dir_fd, ent->d_name, desc, result, result_sz); continue; } if (ent->d_type != DT_DIR) { @@ -204,32 +222,35 @@ static void append_scripts_in_dir(int dir_fd) continue; } fd = openat(dir_fd, ent->d_name, O_PATH); - append_scripts_in_dir(fd); + append_scripts_in_dir(fd, result, result_sz); } for (i = 0; i < n_dirs; i++) /* Clean up */ zfree(&entlist[i]); free(entlist); } -const struct script_file *list_script_files(void) +struct test_suite **create_script_test_suites(void) { - int dir_fd; - - if (files) - return files; /* Singleton - we already know our list */ - - dir_fd = shell_tests__dir_fd(); /* Walk dir */ - if (dir_fd < 0) - return NULL; + struct test_suite **result = NULL, **result_tmp; + size_t result_sz = 0; + int dir_fd = shell_tests__dir_fd(); /* Walk dir */ - append_scripts_in_dir(dir_fd); - close(dir_fd); + /* + * Append scripts if fd is good, otherwise return a NULL terminated zero + * length array. + */ + if (dir_fd >= 0) + append_scripts_in_dir(dir_fd, &result, &result_sz); - return files; -} - -int list_script_max_width(void) -{ - list_script_files(); /* Ensure we have scanned all scripts */ - return files_max_width; + result_tmp = realloc(result, (result_sz + 1) * sizeof(*result_tmp)); + if (result_tmp == NULL) { + pr_err("Out of memory while building script test suite list\n"); + abort(); + } + /* NULL terminate the test suite array. */ + result = result_tmp; + result[result_sz] = NULL; + if (dir_fd >= 0) + close(dir_fd); + return result; } diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h index 3508a293aaf9..b553ad26ea17 100644 --- a/tools/perf/tests/tests-scripts.h +++ b/tools/perf/tests/tests-scripts.h @@ -2,14 +2,8 @@ #ifndef TESTS_SCRIPTS_H #define TESTS_SCRIPTS_H -struct script_file { - char *file; - char *desc; -}; +#include "tests.h" -/* List available script tests to run - singleton - never freed */ -const struct script_file *list_script_files(void); -/* Get maximum width of description string */ -int list_script_max_width(void); +struct test_suite **create_script_test_suites(void); #endif /* TESTS_SCRIPTS_H */ From patchwork Fri Feb 16 23:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 202473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp70898dyc; Fri, 16 Feb 2024 16:23:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWjVQm6jQoW5JRUhzatJGIH2VtAVcmmeEWyxPSMwFYEYxSETJBWNSRAEzxEEcli5dEysDPGMVQYxIjq27CGWkY3vI0+zA== X-Google-Smtp-Source: AGHT+IGdcZGURAxuUFbpgvxwT+t6Pe41c5GEb8Mvw6pXcFbArVc4LOnjQ591Jdh39+agL48ObS5H X-Received: by 2002:a17:90a:b114:b0:296:7bc4:5926 with SMTP id z20-20020a17090ab11400b002967bc45926mr6107338pjq.10.1708129422421; Fri, 16 Feb 2024 16:23:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708129422; cv=pass; d=google.com; s=arc-20160816; b=VXD7AhulIQz4UuNwtzHun5eolIS4UWadx+CfrvcKUWzsDz0CFphLhwQJ3k39YP3ETq Kh94GdZUWV/FH5oSEBfBbK/ALa1SmNpi9u7Zqve3XQJBPw7vt4mNDmIRhXinilQkJC/R xv+/lUpG59bbt3ftLwmzyXc/eSsW5CbgGcFHPiB2L1HA4zgOA6Qwti/g+XB8H2s1jVn2 4WpNgP4wpQ3SIlZJjBljNua4F4iE/sG026T9VEO+quXKzJzz2mBlzI1V7tmmrkEPGLTO J+CbvZHxXFOVwqGRUjsa9+jTNfxKvqjY/XkWtL3zAjYZ1cdgXSL+zUqtmdBWmlRYXkFv GPcg== 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=46NbERsw+rX6VfHxglAqwzl8LfYw4J5J2BPeonbB4cQ=; fh=e3XXP45QbWO04fh+viHluOFy9rDi/W7H4hE6jFFsobc=; b=NISpumTpywhYRbGDqFZZLxbyFn3dmxlH7fs7MD8BWD9sdIjHjLfD+eQ4E/G7noH5ef bOim7J0apuZ7sJ5zGwwOdXsMsKGZ3EX1veDibG8mEzmE4cL9hsC+/G20jNwxAxsFSkRs aDRIymQj40cSfi7FipxmlGfExqSEXvGTC2BJAsO+I3Vv18+qVcJopa70Zb15IsWeRSxn qmvzFG8tk0k/M6EJXb4wacz8Sa385E7VAdPh3DmouVk86HftEuEvNluWsSzJYOyY4C18 fbVKGIx/Hr+r5C8csTNjZIcD9VGkh3dseYaJ/0gCm6KE8W/iuSnc9g+MA/9XRPO2Q46p OLFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="2xD/XWI8"; 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-69516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69516-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lr2-20020a17090b4b8200b002968659919csi725832pjb.112.2024.02.16.16.23.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 16:23:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="2xD/XWI8"; 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-69516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69516-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0F3A0B283AD for ; Sat, 17 Feb 2024 00:00:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F4E615443A; Fri, 16 Feb 2024 23:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2xD/XWI8" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 39D00153BF3 for ; Fri, 16 Feb 2024 23:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127735; cv=none; b=XDf5R/HGlJhcw1mYEpmAD0uWQs535DIzjIqXDAVJm1ANV4VRU8UF2dtLe5+oUdp5g1xMiFLloVrMEv0yl0+dFWxwfbqu5K2au1yMTXwX4hlwOnHUH96tFDqxzvsP5hxm5IE6h47C8Deu6uVeMGJ85bKH3owUjaqx7bAEhsC0rqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127735; c=relaxed/simple; bh=SV8Q2XP3AEzUCdEScST86iV7qnjMAWaIiYJHWAwVraA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ICBmG7OzFM41ihTDNIPr5vIIdqFugbHv8HSkIQtdkZ9NZbwXWr4e+bZFUj1novtfXXzUSqzO+at3nOO6lmgMTja/NNzThwU66qn8ju/qtwcsO0b9jbNP+NBnWKaTQE8TX8Mfvyd9h50nd86ytwl7NCQVaU8o2aV/21nh79zbpNY= 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=2xD/XWI8; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-607d0180d2fso44625647b3.1 for ; Fri, 16 Feb 2024 15:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708127731; x=1708732531; 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=46NbERsw+rX6VfHxglAqwzl8LfYw4J5J2BPeonbB4cQ=; b=2xD/XWI8RWCfnnKUbC38A//aRCb+RsD1YE8l7g1oiyqkreszbQPb5/4ufZ4GiCsyV9 u+WthsJqknGcI7IYxeM61+ddnm1GY1MuSAfgmdfta4ieml94fvIKpv0l599MpcbW0JIt lddrokNFfGW+feWLmcuTmjRsjEQQaxRlRA1cfPhVNXWj3P7aa+yZLWXwaTglv3khOjS7 bsKXGvBMvdOKGl1zvJLG+KOymwnLd+V4+uj6LhMggok0B4nWewG/g4UoPdgTVH/bY3RS xp5i92yyD4biAVqBMsneNL+dIYAJP+kDWuLIdVqGO9c9t7D4VZlBk3lYfwqHMYs413Fu pgyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708127731; x=1708732531; 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=46NbERsw+rX6VfHxglAqwzl8LfYw4J5J2BPeonbB4cQ=; b=Bi1b29Q47W2j5u0NF9GbaReYjqZ9sE9hbebnaN5rA+KDK+ksJQa3BFO2OLOFjSyrUE y/qTw6dW1tWFXzDHggcllKs54FDupR64YldNJAEDDV9ElenJ3c5K/TWGL0N7heeRrbfu y/lvcgM582DLStz8Vhc6YB85FjSIy41scdnUU5V0Q3V/mHEjnMAIldeBpxFIAQgpEFjM wZ2X6aWylsheo1AHAUL+yab6hTqjFdSu1TIsGIrq9frUCLVG1er7OQebfBXztrCKoHph UBdfswyVbae8Kd6D0uOGWZAAJL3Yu8GdREBK6x/F7FgTWC2n7/vwEASVROX/bkE8AG9v fQVw== X-Forwarded-Encrypted: i=1; AJvYcCVgE5I0y3+w/ttktb6B7nVGzkqdQvDzikUpOc8o4dW21gSx6t0H2ghpPdf9SdbPw/2BXKBUI8vncX9/xecZwVmyWy+HiHYbuwxuZakb X-Gm-Message-State: AOJu0YzBnCZPMY9Nuwy1Q5zSjQy60pXg4u6WzY2sWaSfTHXZwzsRR8Y+ fPfmwUohh96aEtB/QssQj0rstxEwD5WctVqK9waET60yaMwZw8xIvJJCZaF4Z8yWDGV5RE4H/25 WgbknGA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4b5c:352:4272:e34e]) (user=irogers job=sendgmr) by 2002:a25:a4c9:0:b0:dcd:25be:aefb with SMTP id g67-20020a25a4c9000000b00dcd25beaefbmr1583424ybi.13.1708127731233; Fri, 16 Feb 2024 15:55:31 -0800 (PST) Date: Fri, 16 Feb 2024 15:52:02 -0800 In-Reply-To: <20240216235203.229256-1-irogers@google.com> Message-Id: <20240216235203.229256-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240216235203.229256-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Subject: [PATCH v5 8/8] perf tests: Add option to run tests in parallel 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 , Athira Jajeev , James Clark , 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: 1791103517617865299 X-GMAIL-MSGID: 1791103517617865299 By default tests are forked, add an option (-p or --parallel) so that the forked tests are all started in parallel and then their output gathered serially. This is opt-in as running in parallel can cause test flakes. Rather than fork within the code, the start_command/finish_command from libsubcmd are used. This changes how stderr and stdout are handled. The child stderr and stdout are always read to avoid the child blocking. If verbose is 1 (-v) then if the test fails the child stdout and stderr are displayed. If the verbose is >1 (e.g. -vv) then the stdout and stderr from the child are immediately displayed. An unscientific test on my laptop shows the wall clock time for perf test without parallel being 5 minutes 21 seconds and with parallel (-p) being 1 minute 50 seconds. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 314 ++++++++++++++++++++++---------- 1 file changed, 215 insertions(+), 99 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index c42cb40fc242..d13ee7683d9d 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -21,9 +22,11 @@ #include "debug.h" #include "color.h" #include +#include #include "string2.h" #include "symbol.h" #include "util/rlimit.h" +#include "util/strbuf.h" #include #include #include @@ -31,7 +34,13 @@ #include "tests-scripts.h" +/* + * Command line option to not fork the test running in the same process and + * making them easier to debug. + */ static bool dont_fork; +/* Fork the tests in parallel and then wait for their completion. */ +static bool parallel; const char *dso_to_test; const char *test_objdump_path = "objdump"; @@ -209,76 +218,36 @@ static bool perf_test__matches(const char *desc, int curr, int argc, const char return false; } -static int run_test(struct test_suite *test, int subtest) -{ - int status, err = -1, child = dont_fork ? 0 : fork(); - char sbuf[STRERR_BUFSIZE]; - - if (child < 0) { - pr_err("failed to fork test: %s\n", - str_error_r(errno, sbuf, sizeof(sbuf))); - return -1; - } - - if (!child) { - if (!dont_fork) { - pr_debug("test child forked, pid %d\n", getpid()); - - if (verbose <= 0) { - int nullfd = open("/dev/null", O_WRONLY); - - if (nullfd >= 0) { - close(STDERR_FILENO); - close(STDOUT_FILENO); - - dup2(nullfd, STDOUT_FILENO); - dup2(STDOUT_FILENO, STDERR_FILENO); - close(nullfd); - } - } else { - signal(SIGSEGV, sighandler_dump_stack); - signal(SIGFPE, sighandler_dump_stack); - } - } - - err = test_function(test, subtest)(test, subtest); - if (!dont_fork) - exit(err); - } - - if (!dont_fork) { - wait(&status); +struct child_test { + struct child_process process; + struct test_suite *test; + int test_num; + int subtest; +}; - if (WIFEXITED(status)) { - err = (signed char)WEXITSTATUS(status); - pr_debug("test child finished with %d\n", err); - } else if (WIFSIGNALED(status)) { - err = -1; - pr_debug("test child interrupted\n"); - } - } +static int run_test_child(struct child_process *process) +{ + struct child_test *child = container_of(process, struct child_test, process); + int err; - return err; + pr_debug("--- start ---\n"); + pr_debug("test child forked, pid %d\n", getpid()); + err = test_function(child->test, child->subtest)(child->test, child->subtest); + pr_debug("---- end(%d) ----\n", err); + fflush(NULL); + return -err; } -#define for_each_test(j, k, t) \ - for (j = 0, k = 0; j < ARRAY_SIZE(tests); j++, k = 0) \ - while ((t = tests[j][k++]) != NULL) - -static int test_and_print(struct test_suite *t, int subtest) +static int print_test_result(struct test_suite *t, int i, int subtest, int result, int width) { - int err; + if (has_subtests(t)) { + int subw = width > 2 ? width - 2 : width; - pr_debug("\n--- start ---\n"); - err = run_test(t, subtest); - pr_debug("---- end ----\n"); + pr_info("%3d.%1d: %-*s:", i + 1, subtest + 1, subw, test_description(t, subtest)); + } else + pr_info("%3d: %-*s:", i + 1, width, test_description(t, subtest)); - if (!has_subtests(t)) - pr_debug("%s:", t->desc); - else - pr_debug("%s subtest %d:", t->desc, subtest + 1); - - switch (err) { + switch (result) { case TEST_OK: pr_info(" Ok\n"); break; @@ -297,34 +266,186 @@ static int test_and_print(struct test_suite *t, int subtest) break; } - return err; + return 0; +} + +static int finish_test(struct child_test *child_test, int width) +{ + struct test_suite *t = child_test->test; + int i = child_test->test_num; + int subi = child_test->subtest; + int out = child_test->process.out; + int err = child_test->process.err; + bool out_done = out <= 0; + bool err_done = err <= 0; + struct strbuf out_output = STRBUF_INIT; + struct strbuf err_output = STRBUF_INIT; + int ret; + + /* + * For test suites with subtests, display the suite name ahead of the + * sub test names. + */ + if (has_subtests(t) && subi == 0) + pr_info("%3d: %-*s:\n", i + 1, width, test_description(t, -1)); + + /* + * Busy loop reading from the child's stdout and stderr that are set to + * be non-blocking until EOF. + */ + if (!out_done) + fcntl(out, F_SETFL, O_NONBLOCK); + if (!err_done) + fcntl(err, F_SETFL, O_NONBLOCK); + if (verbose > 1) { + if (has_subtests(t)) + pr_info("%3d.%1d: %s:\n", i + 1, subi + 1, test_description(t, subi)); + else + pr_info("%3d: %s:\n", i + 1, test_description(t, -1)); + } + while (!out_done || !err_done) { + struct pollfd pfds[2] = { + { .fd = out, + .events = POLLIN | POLLERR | POLLHUP | POLLNVAL, + }, + { .fd = err, + .events = POLLIN | POLLERR | POLLHUP | POLLNVAL, + }, + }; + char buf[512]; + ssize_t len; + + /* Poll to avoid excessive spinning, timeout set for 1000ms. */ + poll(pfds, ARRAY_SIZE(pfds), /*timeout=*/1000); + if (!out_done && pfds[0].revents) { + errno = 0; + len = read(out, buf, sizeof(buf) - 1); + + if (len <= 0) { + out_done = errno != EAGAIN; + } else { + buf[len] = '\0'; + if (verbose > 1) + fprintf(stdout, "%s", buf); + else + strbuf_addstr(&out_output, buf); + } + } + if (!err_done && pfds[1].revents) { + errno = 0; + len = read(err, buf, sizeof(buf) - 1); + + if (len <= 0) { + err_done = errno != EAGAIN; + } else { + buf[len] = '\0'; + if (verbose > 1) + fprintf(stdout, "%s", buf); + else + strbuf_addstr(&err_output, buf); + } + } + } + /* Clean up child process. */ + ret = finish_command(&child_test->process); + if (verbose == 1 && ret == TEST_FAIL) { + /* Add header for test that was skipped above. */ + if (has_subtests(t)) + pr_info("%3d.%1d: %s:\n", i + 1, subi + 1, test_description(t, subi)); + else + pr_info("%3d: %s:\n", i + 1, test_description(t, -1)); + fprintf(stdout, "%s", out_output.buf); + fprintf(stderr, "%s", err_output.buf); + } + strbuf_release(&out_output); + strbuf_release(&err_output); + print_test_result(t, i, subi, ret, width); + if (out > 0) + close(out); + if (err > 0) + close(err); + return 0; +} + +static int start_test(struct test_suite *test, int i, int subi, struct child_test **child, + int width) +{ + int err; + + *child = NULL; + if (dont_fork) { + pr_debug("--- start ---\n"); + err = test_function(test, subi)(test, subi); + pr_debug("---- end ----\n"); + print_test_result(test, i, subi, err, width); + return 0; + } + + *child = zalloc(sizeof(**child)); + if (!*child) + return -ENOMEM; + + (*child)->test = test; + (*child)->test_num = i; + (*child)->subtest = subi; + (*child)->process.pid = -1; + (*child)->process.no_stdin = 1; + if (verbose <= 0) { + (*child)->process.no_stdout = 1; + (*child)->process.no_stderr = 1; + } else { + (*child)->process.out = -1; + (*child)->process.err = -1; + } + (*child)->process.no_exec_cmd = run_test_child; + err = start_command(&(*child)->process); + if (err || parallel) + return err; + return finish_test(*child, width); } +#define for_each_test(j, k, t) \ + for (j = 0, k = 0; j < ARRAY_SIZE(tests); j++, k = 0) \ + while ((t = tests[j][k++]) != NULL) + static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) { struct test_suite *t; unsigned int j, k; int i = 0; int width = 0; + size_t num_tests = 0; + struct child_test **child_tests; + int child_test_num = 0; for_each_test(j, k, t) { int len = strlen(test_description(t, -1)); if (width < len) width = len; + + if (has_subtests(t)) { + for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) { + len = strlen(test_description(t, subi)); + if (width < len) + width = len; + num_tests++; + } + } else { + num_tests++; + } } + child_tests = calloc(num_tests, sizeof(*child_tests)); + if (!child_tests) + return -ENOMEM; for_each_test(j, k, t) { int curr = i++; - int subi; if (!perf_test__matches(test_description(t, -1), curr, argc, argv)) { bool skip = true; - int subn; - - subn = num_subtests(t); - for (subi = 0; subi < subn; subi++) { + for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) { if (perf_test__matches(test_description(t, subi), curr, argc, argv)) skip = false; @@ -334,52 +455,45 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) continue; } - pr_info("%3d: %-*s:", i, width, test_description(t, -1)); - if (intlist__find(skiplist, i)) { + pr_info("%3d: %-*s:", curr + 1, width, test_description(t, -1)); color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); continue; } if (!has_subtests(t)) { - test_and_print(t, -1); - } else { - int subn = num_subtests(t); - /* - * minus 2 to align with normal testcases. - * For subtest we print additional '.x' in number. - * for example: - * - * 35: Test LLVM searching and compiling : - * 35.1: Basic BPF llvm compiling test : Ok - */ - int subw = width > 2 ? width - 2 : width; - - if (subn <= 0) { - color_fprintf(stderr, PERF_COLOR_YELLOW, - " Skip (not compiled in)\n"); - continue; - } - pr_info("\n"); + int err = start_test(t, curr, -1, &child_tests[child_test_num++], width); - for (subi = 0; subi < subn; subi++) { - int len = strlen(test_description(t, subi)); - - if (subw < len) - subw = len; + if (err) { + /* TODO: if parallel waitpid the already forked children. */ + free(child_tests); + return err; } + } else { + for (int subi = 0, subn = num_subtests(t); subi < subn; subi++) { + int err; - for (subi = 0; subi < subn; subi++) { if (!perf_test__matches(test_description(t, subi), curr, argc, argv)) continue; - pr_info("%3d.%1d: %-*s:", i, subi + 1, subw, - test_description(t, subi)); - test_and_print(t, subi); + err = start_test(t, curr, subi, &child_tests[child_test_num++], + width); + if (err) + return err; } } } + for (i = 0; i < child_test_num; i++) { + if (parallel) { + int ret = finish_test(child_tests[i], width); + + if (ret) + return ret; + } + free(child_tests[i]); + } + free(child_tests); return 0; } @@ -447,6 +561,8 @@ int cmd_test(int argc, const char **argv) "be more verbose (show symbol address, etc)"), OPT_BOOLEAN('F', "dont-fork", &dont_fork, "Do not fork for testcase"), + OPT_BOOLEAN('p', "parallel", ¶llel, + "Run the tests altogether in parallel"), OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"), OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"), OPT_STRING(0, "objdump", &test_objdump_path, "path",