From patchwork Fri Mar 1 07:46:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13578080 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 3590F6995D for ; Fri, 1 Mar 2024 07:47:02 +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=1709279224; cv=none; b=pw9LWOxRQdKIXUAs4a6KVAH2bks1E+1iX5PTm9XoX11GEqFukm17/Cz9w84lsZ/Q1Rxo5UY6Wl0VipmXaToV2Y9K0EFqEp7lvyHauUPHGfEeZ8r3UjIcnlOYh6l7f4lVfNYgxVWQUy4e4MLuQ3qXbJFDUmlI1MvJ/nSY33k14YI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709279224; c=relaxed/simple; bh=/sx6SEtFquJtDyl4dFJaKZNITaLfCxUGF+8rTsmsL5I=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=hZr0bSqYiEIOoeuIrYDtZlMHqBaIpajsgzF5Sl61vDvFWrf0HuBca6GuBNyPoR5aNQCZdHNtBpeMZyeMi67KR89hbFXVAqn9Hm2nZc0MKCU0EFdsReQ85qLAUxrRCXhz1j+3e+GbqoN8JsI3shI1FO504Jp4OQfXmslH2YFRSt8= 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=X5CuGzuE; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X5CuGzuE" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc3645a6790so3435504276.0 for ; Thu, 29 Feb 2024 23:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709279221; x=1709884021; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=2vDtF8jsZ47KJFPdTHlyCCCvC1lX3V2rNBLzzEwdQPY=; b=X5CuGzuEbpnd08seUNciEd2ZFar+I8pfG77yKvaboqu0k1oqz2VsNIAGgeHsJtXoVc Djc/WfsRTbCtqb9JEQO1R7EwaBXSYTMCRaM7GSHBjGoS6tFDvhaK7FvAcnsoQEmS3Iiu L/C5d98BhT42uyeHopNw5oXln845w5RwNqhhPypS2E0rvwymrcYExdx+Q6xH++Y+JBC6 KQ1L7nrIUCMsPzi3nxupvoP9zFNCrlJ4tuXia3/pqna0ndAfYXv9RS7hdxmxTAM2VZoh JjB1eIlDSBVvDN4wWys8X+9kRBGr5KRau0lFnb4NUi2LXPM5lM80KNmqshwhU+2SECWF cVww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709279221; x=1709884021; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2vDtF8jsZ47KJFPdTHlyCCCvC1lX3V2rNBLzzEwdQPY=; b=aMmyvemEIZrG+uAJLl6bHeMsujXR2CaotmALMlrqPMnDWsbBUJw1ZV6n48Hn73nJgK OyT4oqh5qLQM0l8XEMYqNSrBbSJdQkDiRGy/DO4NjhXP18dGx1LNmIJci2M+selX8V/J IxrkYOmOLT9Oy4SM/LeBLhOfXBSKLcao64FxU3VRVN8YRuc+Rf88fMLR2C0W5CRIJ1jv c80UHXFUpdZ8ZkNGI9y9LAmJ1kk/yPqJ+eIdPSfHeWW6YR8M+gTP64HjV8kLheEPWf4f CJfD7vCuFNImvI/Y/j3/xNtYKRKdRBDDrg9pAPruiOd9CSP5YHg+57sHGzuJQHHV3e9x fLOA== X-Forwarded-Encrypted: i=1; AJvYcCWNBWICl3vTcOd+FR1WSUVMR/bbK23krnOZ3uU7/4CPQw/maTCU6DsAtt0tElbxB/sTmCNn4aaFjJpZGrCuxsi9sqkg X-Gm-Message-State: AOJu0YyIsws8AAbDON7iRe8T4DYObuuQHw23zACWqEP2ItgK0S8d6+h5 R78/mgr41rzVvUooCdgv++4O0n6Dz5R5PAnhlTX/zLA8fO3VZpf8E7rT1JFspFrMO1PE2LyJoXc cr9zgXA== X-Google-Smtp-Source: AGHT+IHrBfzUxQP1oIvterNW8El5bqvNoQh6OVy17grQnyfwObnPYeXNFK/EoKiNIoBpOKL59O1t8A9qZGIg X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a5b:f05:0:b0:dca:33b8:38d7 with SMTP id x5-20020a5b0f05000000b00dca33b838d7mr193989ybr.11.1709279221335; Thu, 29 Feb 2024 23:47:01 -0800 (PST) Date: Thu, 29 Feb 2024 23:46:36 -0800 Message-Id: <20240301074639.2260708-1-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 1/4] perf record: Delete session after stopping sideband thread 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 The session has a header in it which contains a perf env with bpf_progs. The bpf_progs are accessed by the sideband thread and so the sideband thread must be stopped before the session is deleted, to avoid a use after free. This error was detected by AddressSanitizer in the following: ``` ==2054673==ERROR: AddressSanitizer: heap-use-after-free on address 0x61d000161e00 at pc 0x55769289de54 bp 0x7f9df36d4ab0 sp 0x7f9df36d4aa8 READ of size 8 at 0x61d000161e00 thread T1 #0 0x55769289de53 in __perf_env__insert_bpf_prog_info util/env.c:42 #1 0x55769289dbb1 in perf_env__insert_bpf_prog_info util/env.c:29 #2 0x557692bbae29 in perf_env__add_bpf_info util/bpf-event.c:483 #3 0x557692bbb01a in bpf_event__sb_cb util/bpf-event.c:512 #4 0x5576928b75f4 in perf_evlist__poll_thread util/sideband_evlist.c:68 #5 0x7f9df96a63eb in start_thread nptl/pthread_create.c:444 #6 0x7f9df9726a4b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 0x61d000161e00 is located 384 bytes inside of 2136-byte region [0x61d000161c80,0x61d0001624d8) freed by thread T0 here: #0 0x7f9dfa6d7288 in __interceptor_free libsanitizer/asan/asan_malloc_linux.cpp:52 #1 0x557692978d50 in perf_session__delete util/session.c:319 #2 0x557692673959 in __cmd_record tools/perf/builtin-record.c:2884 #3 0x55769267a9f0 in cmd_record tools/perf/builtin-record.c:4259 #4 0x55769286710c in run_builtin tools/perf/perf.c:349 #5 0x557692867678 in handle_internal_command tools/perf/perf.c:402 #6 0x557692867a40 in run_argv tools/perf/perf.c:446 #7 0x557692867fae in main tools/perf/perf.c:562 #8 0x7f9df96456c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 ``` Fixes: 657ee5531903 ("perf evlist: Introduce side band thread") Signed-off-by: Ian Rogers --- tools/perf/builtin-record.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 92ccca9574ca..32df34dda9cd 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2881,10 +2881,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } #endif zstd_fini(&session->zstd_data); - perf_session__delete(session); - if (!opts->no_bpf_event) evlist__stop_sb_thread(rec->sb_evlist); + + perf_session__delete(session); return status; } From patchwork Fri Mar 1 07:46:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13578081 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 CAB8A6996F for ; Fri, 1 Mar 2024 07:47:04 +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=1709279227; cv=none; b=nLUtZupYWo79LgLZ17GOzP9HC1lU1cDzVDFyix3EmL7yW65TdvIXFHaIMe8CcR1/yZ946yoCIEDR/89bE9yeKHGksOORiCk1hPbSEYH3sqrvdMC0ux6KRiR4VKRULBPfkbU9yBKGNce65CNfywOPNFjXDs346su8ZRiAFkpR/fY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709279227; c=relaxed/simple; bh=VOm7IPIBVo5PZ4RqJQ+la336Qu+bZ3B28KGc7lbQY1c=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DCLKUvNfdGdRDOLRm0vnxzjW2SD9qhwoRuiBCLdfwSbvQW7LdQUrGigWF6MWODR5NWsXQnjKN1CR6nJaH20/d3uo5BA6hwFDudroxlUj7QqkJ5AjRSm4eKGXxCb1yUEbWB09CUDTjtrORhqqVCWw+yfXfAQykYiK8iPRo829Vbg= 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=0FlNYgO2; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0FlNYgO2" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5f38d676cecso38366487b3.0 for ; Thu, 29 Feb 2024 23:47:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709279224; x=1709884024; 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=7Hog9+5whTjGin5G0M4AR3EFSxPaJm96RaOiuDoEPKc=; b=0FlNYgO2kqOhGSyfpAQQBJL1dd7rKBTXhz3pINcsFfaMqmJcqnTG38B6jaOJlZXlQY WlsuBT/nNTGPGC//5tqc4rpTUVLgYs4rpPPNsIzpypx8lnlebYPINeUbAMKDXKQ29chz LmHhrF1YPf+sJ4JZiSSvs1CnCaeR+eszxK/wEI/buDluavltGj5Zp0Ht9VOag+wmoP5l VDoLtK/uit8Qwl7HUGHYZa0xIVsnJ23fCW6CxulTSv6DVMQdI+l5fAmJTaQz5xPSYsXV NstLWqmsKtuX1zhq9l/EYAI9DC1uZmnzCfFvv/fUdPRFx4qfsdp+2pFqqs9yh4+jcOSO oIaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709279224; x=1709884024; 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=7Hog9+5whTjGin5G0M4AR3EFSxPaJm96RaOiuDoEPKc=; b=kXt85k43YzztfQlxcyYwagfniWdVArIpA+IRa/y91Ei5Licql66jXlN0LND0/AQcEK fnN5p2Az0Wlg983FyrghCRd2nuXBNjzCvbYy7+Jt+VAWkJrX2+CSTG9gB6+HOp51GamK hITOnHYJZB6voEWLIIR+ibqIRBRZBmXT/Z24rxs0LwL1zxbFBatQClZklYlPe5EHp52p AC2svmiOHfqUQL0y8u7zMajB1NUWphFcT0mZLRvH11QEtOQznO2bfcRIjEbmyJx89yem jb2cOAPWIQpojWlp0t4B0yjzB+swJbHA+p9VUlRLystn3pVSDpOmpkQKKiSPGgQI5XqG 4clg== X-Forwarded-Encrypted: i=1; AJvYcCWcA/vlIA23tR4zbz7YP38HWSwatooHiIuFz8w/+42ihNnb7rWSCbfEkRdT+UkfeDNs45rybvKJUg/XVbS43mNmkIS0 X-Gm-Message-State: AOJu0Ywfq1hPd1R9DzrxKNOZGZZXtcM7mg6GLC54TeEwQz8UlBKzQonn APUSlgnN/sTWcf+MXw1ITBmg7gWKv3lGShlBQ+rrPkCIbzchox7KXx97pTcTvYcPAzjyLIqt3qB bG03l7Q== X-Google-Smtp-Source: AGHT+IHKnx/facVcMyKr/hM0f0jmf4jq5UVVg3iquQ7IDVrMzo2HlC4fnlqQ5hwy6KtgmHf4sM/6I4lkCclf X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:6902:1249:b0:dc7:7655:46ce with SMTP id t9-20020a056902124900b00dc7765546cemr280153ybu.2.1709279223896; Thu, 29 Feb 2024 23:47:03 -0800 (PST) Date: Thu, 29 Feb 2024 23:46:37 -0800 In-Reply-To: <20240301074639.2260708-1-irogers@google.com> Message-Id: <20240301074639.2260708-2-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 2/4] perf test: stat output per thread of just the parent process 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 Per-thread mode requires either system-wide (-a), a pid (-p) or a tid (-t). The stat output tests were using system-wide mode but this is racy when threads are starting and exiting - something that happens a lot when running the tests in parallel (perf test -p). Avoid the race conditions by using pid mode with the pid of the parent process. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/lib/stat_output.sh | 2 +- tools/perf/tests/shell/stat+json_output.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/shell/lib/stat_output.sh b/tools/perf/tests/shell/lib/stat_output.sh index c81d6a9f7983..9a176ceae4a3 100644 --- a/tools/perf/tests/shell/lib/stat_output.sh +++ b/tools/perf/tests/shell/lib/stat_output.sh @@ -79,7 +79,7 @@ check_per_thread() echo "[Skip] paranoid and not root" return fi - perf stat --per-thread -a $2 true + perf stat --per-thread -p $$ $2 true commachecker --per-thread echo "[Success]" } diff --git a/tools/perf/tests/shell/stat+json_output.sh b/tools/perf/tests/shell/stat+json_output.sh index 2b9c6212dffc..6b630d33c328 100755 --- a/tools/perf/tests/shell/stat+json_output.sh +++ b/tools/perf/tests/shell/stat+json_output.sh @@ -105,7 +105,7 @@ check_per_thread() echo "[Skip] paranoia and not root" return fi - perf stat -j --per-thread -a -o "${stat_output}" true + perf stat -j --per-thread -p $$ -o "${stat_output}" true $PYTHON $pythonchecker --per-thread --file "${stat_output}" echo "[Success]" } 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: 13578082 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 EDA4D69D26 for ; Fri, 1 Mar 2024 07:47:06 +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=1709279228; cv=none; b=cLw7s6jGLV4SG7dhSsQZy/ivlxEj7b8fs2aRu/R2MxA4uTEpN9u8Nk8GPXXCZTswBXs1Cis+LDmU5WgYXGtucK+aEJ4+nOp+UTVbqM/OigpS/POaxfzyvJMGvR0HpjeAERJwjXyvZno4wJtte2vSVkK3sPUFKAg1mq5qGYeLtRw= 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.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ecohGLLs" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6087ffdac8cso27719077b3.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=sDa+bI+XivOCO7xjtrEwVEGBUUccc3ZqbF/jnkj56g0b2XAwmqzihCppCLyOMZ6tiw iKVqiiEOdb/s/gQ/oRHUitWu+a+D73OnppB16IvMyRX2IOZmXf/5Pc4Owu8EMM2cDYhQ cmUijIvasTRqmLUcxwW0reTOIbnjV5wh0+9CXS9A6Sh+igtf52yog8++G7W3NK29e1kt y0CDYFwx2Po05i94jP4RMFQGiQPSVT/D2AEfXg9X5t+5nToYsUsiuiMCNXKjutcmKOY2 p4vTlJMU31fjYBjJ8nDaJsA3a93SoOarWjp0PFt4QGNQl6+CEFtQgZ7BBTbi8ipQCIKh 066g== X-Forwarded-Encrypted: i=1; AJvYcCVuNOrZJhOZy7W079ZrSsx2J5BIwWAYzpVZnXntDRzGv8oR39T736aEJP/FKCrrpNtMbhZvZ7ouplBHSDcwi5EIMCv3 X-Gm-Message-State: AOJu0Yy/rA3sXYeua7hj0oWw8vYqavaEIbtWpKmuz0m5reP/ZNBZK/9K HiH42Uedku9Sm9mvvOOSquCFxj6Lgvt/STE8j2ALOEoOEI0Imp/sAmoDRSYY9/J/xZV3YHRaeJy EfduzNg== X-Google-Smtp-Source: AGHT+IHnnjJ/HkjdhIOLTn0brjPQIsb8rznG0WYtYw+2K/eNV8iOBDmIX+HMqsIRSi2MJeWZMo8AmSHlGGNN 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: bpf@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 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; } From patchwork Fri Mar 1 07:46:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13578083 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 3E4B569D26 for ; Fri, 1 Mar 2024 07:47:09 +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=1709279230; cv=none; b=u1Q8khRl+Pn2KLalY4urxlIz5b+/3L5BBc0sl8Ivr8NsZm572JvAcfGw0dSnDSlxbA15yhCs0Un8+5a3iOC9U08shjXHWdn+apiNfsorYksker3PGYUDQceJJJKe8KSUAj2kWAl6CF9iC4HQ+bj/Uaw21UFR2Wa04NBffQ1Wodw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709279230; c=relaxed/simple; bh=tJ5hV3qK33fMQXhssQ6GzZXnGcMVFTbMlJ9s5yCl8rw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KVPbuc0M9VQwd05IqfkeRY3/YFKdgaIUJKeI1aE/d0sksTrAOqiylEdt+fO8GWO3xR9sqjNWEB/bzkyWru/C9EYkDCStXVnTF9YEpNBAUcbtSiYNRB2h3D+4ebpdwFPJOm0BMRw+e/Vq/H9cNyBKO8+RKSrt8P06ZDmsBVuZosc= 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=EwkVXkq+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EwkVXkq+" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60810219282so24547377b3.0 for ; Thu, 29 Feb 2024 23:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709279228; x=1709884028; 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=6cr3bvTQSOwUcL44V3OWG/EQ3k43z0nNlQO3ZPO+cuQ=; b=EwkVXkq+HbPb74rzNH68QmLtn6Ppye5ynfhaCcxaVindUJY2fnUUTxOl6phR/W9iis DSK1brP5QcrWwtx8RfU9RpOyBarasX8nAOqnHiMBchgWCJxQISUylYpnD5lIrHIm/K6b GdLrOQv4sRYp+EdxLOxb99MEoOXb/7TjaH63l4kJcyz2kXtbKVaAVPQ0mob1zHsfT/Ug hAMTRvHg2UluIa2p+HCZqnJeGst9UFhWVUYe1/bARNHYjI79upfvSeu7OKNSfviHR4CI FbDAJ8poWge5Oc70UzqbtyECHW3kttpR9aBWk+gMpICRN/P9Maa5MmWKH2nZ1Bc6Ob+X ZBuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709279228; x=1709884028; 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=6cr3bvTQSOwUcL44V3OWG/EQ3k43z0nNlQO3ZPO+cuQ=; b=n6AoKjd2fdclr5l0B/RGZhIax04KyEeKmrSuVBWba7XaeeWoeiAR8GI7OJnYd/Z+R1 961ANY8y2feNI8V++yFRSvRhUnCSkY+lfWg5OW/pB3+HnGmcM16nZl53VkqPOn1f5sjK W7CQVqWlaIGHfZe/jpmUaHqaed3PWn/SJBnC0dEjC9JxvJAnt3tEL1eU+5tflLsMBcgW dE1kVpR9CapouL+2EWw/qBlpWn06OkQMqrt5XSUEBAsRmIcxB9H6flRAJDuv8jVFgx1I ZGmTkwDff2dhbcg0xTldqfjM5xgvmX0sygGcZOBRxJB5867lB0TISnWLhQORBwAlevcJ JGGQ== X-Forwarded-Encrypted: i=1; AJvYcCXNMzM72tYs1BkdZa2/CELI4Ir8gFG+eqSSN/MsPbkVPsPe7009V32vXLaMCmUkjiIgu01YcwNpTXrGXgEcM63XFVez X-Gm-Message-State: AOJu0YyJ5291N8SulNnsvINyKR3+lPGh6Rg/WEef7kRSA11rcXVnnlTf VH9Wi1B11LxuzNe+j3c6WR79Nf/5wSr6LAe9zLhS52VnB5l2pBR7ZFHo5xf8BBmYc3b260dVLzL tKyH7yQ== X-Google-Smtp-Source: AGHT+IGz1E1c7M47HvG6AVrMNEVgIWHJwWURRdJYBFX7yDtVHORL5Dpa11qv+CBdBUGG0mIB6skYqMmLlkT9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:af4b:7fc1:b7be:fcb7]) (user=irogers job=sendgmr) by 2002:a05:690c:c92:b0:609:3bd3:31fd with SMTP id cm18-20020a05690c0c9200b006093bd331fdmr161226ywb.2.1709279228547; Thu, 29 Feb 2024 23:47:08 -0800 (PST) Date: Thu, 29 Feb 2024 23:46:39 -0800 In-Reply-To: <20240301074639.2260708-1-irogers@google.com> Message-Id: <20240301074639.2260708-4-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 4/4] perf test: Read child test 10 times a second rather than 1 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 Make the perf test output smoother by timing out the poll of the child process after 100ms rather than 1s. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index e05b370b1e2b..ddb2f4e38ea5 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -307,8 +307,8 @@ static int finish_test(struct child_test *child_test, int width) char buf[512]; ssize_t len; - /* Poll to avoid excessive spinning, timeout set for 1000ms. */ - poll(pfds, ARRAY_SIZE(pfds), /*timeout=*/1000); + /* Poll to avoid excessive spinning, timeout set for 100ms. */ + poll(pfds, ARRAY_SIZE(pfds), /*timeout=*/100); if (!err_done && pfds[0].revents) { errno = 0; len = read(err, buf, sizeof(buf) - 1);