From patchwork Fri Mar 1 07:46:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 208677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp920291dyb; Thu, 29 Feb 2024 23:48:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+M9ajvCCyCRmKVNnqHXY1+Z/iHpOsNtRCscj1/Q3/3t/2KGdeSygSKtAU1ojEj2VXYCsu1D5Ch4fHo0zavT4nXmxSRg== X-Google-Smtp-Source: AGHT+IEwxwcOL2Ryf93wLmX54fHyy2pFcUUN9HeymXhx63DyBqsdDGwD3IHIG0s2K8YVMCz5WQx7 X-Received: by 2002:a05:6214:186b:b0:690:1715:c022 with SMTP id eh11-20020a056214186b00b006901715c022mr901050qvb.3.1709279288908; Thu, 29 Feb 2024 23:48:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709279288; cv=pass; d=google.com; s=arc-20160816; b=UClfhdFrCsKC/zv6VjqIK/uI80tUix/IXeagpQuROJll4SF5e8PzuEkuN6LQmbkk/6 Rupf3fmQP3caZw6wcCl9DfDIfSGOEHkmiizBDPhmGeqcj0lt57204dzODYyLmkfR+WkB j73zeI3EWSiJJDC76I8YW7F5WjufovioaCjz2mJ5sf9WxZfBvhFMJR2vpQNtjBThakNv vx2OzO6R78tmeN1B3anK7jtBWpw//LXynO8tgD13dSGE4cINK6F2T/YQfHxYo5risWBH dSsd6UNwUFgf/sOHAREVvZRR7hmg4GFbjHh87zQ7nbQGettDxnkaaRapqkDid8nMTOzK uYEA== 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=5K+5oMd/UIqBC7bRKcwIBEqT27MHFEvvuXXTUo0sv5w=; fh=K04rDuOpP9AfjedjEg7u7Ij3zMQLy/q34kb7MPP49F0=; b=0sm0K/r5/rsJsgOFIqm202+fhwoni4FrbBvQPEitJkey1zr/dnrY13Vfsrserc7tOu noo8ZqrlSYcVVUqoClSLHVm1zONZzXRJZy+QzyFEv1+1W3iT9mgzNA8twImAYX1q2cm/ yvu/XkUfIofWWVRpuJg4c91GeA7szMQxjJJYD565ziVjxjPnS0sNXX0Zz6C32Kk67pdu SDRR3sBNHQIKGfl+bHPiBTPGvh01/2gR2IGGvHTDT6jS2oEAI17+c+JY0upNP39UHZU3 cbU1CRs6ZtjiuhIlJab+UCRTjkNx4xe2RI7tDTBzqMmjKzVI+5elW2gbIbgYDNjfE2jU 5XBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ecohGLLs; 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-88024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88024-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 kk25-20020a056214509900b0068ffe6f0833si2992293qvb.91.2024.02.29.23.48.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 23:48:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88024-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=ecohGLLs; 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-88024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88024-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 A0E191C20F96 for ; Fri, 1 Mar 2024 07:48:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D92AB69E0E; Fri, 1 Mar 2024 07:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ecohGLLs" 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 105FE69D28 for ; Fri, 1 Mar 2024 07:47:06 +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=1709279228; cv=none; b=TWGq+6TAaaWmsq042620ervSJooMRVT3VD4KrMnY+RgelO6OM/CDDA18BuLUlUz8aBQzsjBBNCjC8Kx6n1ijIHKiSLefT3LPPv2VBeHd1L0J/TspnshF8MCePsCw1c49nvpA9w0g4EdJAH7jlw5Cy9V+hw+mDXZe608GIORTf/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709279228; c=relaxed/simple; bh=wTr8XZF47y1mIM8sF/7w7Q/9jLsnFEsaFsOMi3gXkm0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=s8op6m67UZ8DUukZWgZVgZu1ARgPxeAkNtb71FLSr1WDanKTy8l7TlafX6zDsFyi/iM5GBS2bvy1kRr3igoA1sDvEm/DgyT44rYC4y4oVOdZEEOnGC5X96IpIVNggzBSTmq3yfWvz/l4hVdxbO9O/+84nUXqIUbExxIdrgvTyVs= 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=ecohGLLs; 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-dc647f65573so3313819276.2 for ; Thu, 29 Feb 2024 23:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709279226; x=1709884026; 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=5K+5oMd/UIqBC7bRKcwIBEqT27MHFEvvuXXTUo0sv5w=; b=ecohGLLs9wBizFLV4MPPvwm2TPxwM0HJkbZ/kTDh0+jFu59kzp+OvK/BC/FmJwUsdj +ePhYw9h7FYBN1+x0itIlkztuqoCRsL1XWjrQdk1JC4MI9ZmAmqpVuOlOR6JEuesc8vZ ptvNQXG42cwS8Hz2P39BNk7vvocLUs+I14mqwETrNVTHsuILlHfX4lBd9CZR1i4A6Etd RATx3HbL03Ef9YrH7Zc9T3+Ju0jO1YF+rEf8ukZ0tYU56GBAh2M3yrQ+wPW8bSx7eaKR GkTX31wwSch7OmQjdaN+OrUDcC6mYAZv8Gu1X/7cRQh+mlb/v6DnaD9GyHm5b/LLnH75 Obcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709279226; x=1709884026; 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=5K+5oMd/UIqBC7bRKcwIBEqT27MHFEvvuXXTUo0sv5w=; b=Fm1g1MAv8fHE1Dye8V807v6M2tarf8IipZqyNGu49Ed1B72TWNMECz5oXuChPS6G5f X41ry0t5oMCvqDXkLJL5kjyavcbSnbKMQs9cewnd5bBChtgvMDI7X4PXHOmNCjZjvEhv lUzzgWu34HHIVFmIwKMEdhSoEaXkQpp055i+n+Ql+Nkz+gafEwAqvXun9RVt+D3b/pZQ VjSDee+JvQI1cCEUV2r2b3t73jRKvbcrFEgjH8JLGcbTgqX6SF7rUIt/xaBi4VhQ8tab L7gPP0f4TFcdqVCAGoC0HeCTqyiYs5OHEVppkMJfd8zFNaIDPSRP3ixVGFdN352s0pCw exSQ== X-Forwarded-Encrypted: i=1; AJvYcCWpJxHReWxIk0rRiZ8iGXwWOqZWCwO4vf4E7X4QlxVXOo64KRT1whmh4gwkFmfnsKTMD0jfYoS7UavJvK2v/L8nFCo803OsL1nd1aga X-Gm-Message-State: AOJu0YxFI9yWeh8QdbZwnJeqtKl2cjD0M38qHn1ERtSmQL/awqNHz7GA VlWDCbmtgRL4yZ71pQK1z2h8NsBWgBG53ogpz64LXcD8Y0nGMTCcA6xutaKUF+BKDGyqwNqL09g nAU5Ggg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:6902:1004:b0:dc7:48ce:d17f with SMTP id w4-20020a056902100400b00dc748ced17fmr181054ybt.10.1709279226074; Thu, 29 Feb 2024 23:47:06 -0800 (PST) Date: Thu, 29 Feb 2024 23:46:38 -0800 In-Reply-To: <20240301074639.2260708-1-irogers@google.com> Message-Id: <20240301074639.2260708-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: <20240301074639.2260708-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 3/4] perf test: Use a single fd for the child process out/err From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Christian Brauner , James Clark , Kan Liang , Tim Chen , Athira Rajeev , Yicong Yang , Kajol Jain , Disha Goel , K Prateek Nayak , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792309239682988719 X-GMAIL-MSGID: 1792309239682988719 Switch from dumping err then out, to a single file descriptor for both of them. This allows the err and output to be correctly interleaved in verbose output. Fixes: b482f5f8e016 ("perf tests: Add option to run tests in parallel") Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 37 ++++++--------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index d13ee7683d9d..e05b370b1e2b 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -274,11 +274,8 @@ 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; @@ -290,11 +287,9 @@ static int finish_test(struct child_test *child_test, int width) 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. + * Busy loop reading from the child's stdout/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) { @@ -303,11 +298,8 @@ static int finish_test(struct child_test *child_test, int width) 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, - }, + while (!err_done) { + struct pollfd pfds[1] = { { .fd = err, .events = POLLIN | POLLERR | POLLHUP | POLLNVAL, }, @@ -317,21 +309,7 @@ static int finish_test(struct child_test *child_test, int width) /* 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) { + if (!err_done && pfds[0].revents) { errno = 0; len = read(err, buf, sizeof(buf) - 1); @@ -354,14 +332,10 @@ static int finish_test(struct child_test *child_test, int width) 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; @@ -394,6 +368,7 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes (*child)->process.no_stdout = 1; (*child)->process.no_stderr = 1; } else { + (*child)->process.stdout_to_stderr = 1; (*child)->process.out = -1; (*child)->process.err = -1; }