Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp226313rwb; Tue, 13 Dec 2022 16:38:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf60JpHwfta+pq9DCnJDDrRmC/1bPx0JugqRT2hjGU7Ru1kYj+yBJgtK9oBphO16/Odg+wQo X-Received: by 2002:a17:903:d2:b0:189:cc72:9602 with SMTP id x18-20020a17090300d200b00189cc729602mr18459977plc.18.1670978336982; Tue, 13 Dec 2022 16:38:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670978336; cv=none; d=google.com; s=arc-20160816; b=flxQpB8aV8j2u0ZpknB49+9Bkv0mpllx/Pqw14oWR2iOAt2y6XvdBAzcn8+pA0u8LT FwUXWTqJeCIVOpr8NjyOXEmKRBWK446jMKSalSbozPmIO6XJZHZw60V5kXUD4bPgUvfX HRVrs5ehtEL3iEsQHvf4K8eWph9yjtxf6JECCaQXseImFTfYPA6zKbM4KeW1HyqKo38b 9u5Tu46G/OcQFlwmdoUfloLkIxiawiNpTcv+pDbK+GKrhm+KAaGZQhkiPLWQ0ZwWMxjE Lv2g5+KEs0XMz9WsrzQtXG4BIodKjImlbU+cyDftF7Je28ATZLkMhkEoUwiz2ISEVZCG 5eCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=E8lBAvMUbSarOvBnBi7Cy+Xm1lvvYValWY+7vlRPdgA=; b=G9bkjyanBvPmXjLpS43NvbEvktzrmJIrX7LsnAMLeXOaNbQHszNNzm5urTlOLVtRu+ tPpZNdgxg4u8cDsSAmCL90YUtmMoJJ/SqsqEG2J49HPXVhCxtntOe9q67wYO3D57lC8E 4Rk6D1RKtWdvG3vVGeQ7MMsYCB07BDc8Kr57qKs9PhUiMyqIpcGxzafynPbfE4aVrm8N tUTtc+hO1ymGX3x6CAtfnv5mQCJo05Z6Y3ExUUehednmjdU6rS4A98PBhIz6PwnLXA6T UG91uQ6qkNL+B4XoXSY0F024qr8v3L063vWWSC/37qSVkawwx3fgrvQH4FPjcfrZ0EXv hGJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E78rr4cb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x77-20020a633150000000b00463fc72dae9si14193489pgx.144.2022.12.13.16.38.47; Tue, 13 Dec 2022 16:38:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E78rr4cb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235717AbiLNATw (ORCPT + 73 others); Tue, 13 Dec 2022 19:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiLNATa (ORCPT ); Tue, 13 Dec 2022 19:19:30 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA4965CC for ; Tue, 13 Dec 2022 16:18:40 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id ay2-20020a05600c1e0200b003d22e3e796dso3778476wmb.0 for ; Tue, 13 Dec 2022 16:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=E8lBAvMUbSarOvBnBi7Cy+Xm1lvvYValWY+7vlRPdgA=; b=E78rr4cbJo6XYu+wDZPWGNQuktj7gpgEnD45pbxHQN63on6NbyD1u7Az5EtM7RgzxM 3Ufry04woZyjm6S8qtJb7uoTAZ9TW4/0nyI+jVTGgle0j9fOrqdRrey5CCC8GAglznaA DKh3ts2gKmQQPYIXWsOopNEoGtXvXmQ2CklP5EuF7+1p11z9iMOseglGg6D8gA78CvlX 6MAKdUsaNo1yiS8aYS8g32Z0g/i57rbvIXCli90IkLBZq7hUe1MjyGOF/mR+4SR2DOhg ccYklEhGXQGHZaw+ik/s2jaVkgLtQIT99w/w8b1YG8rZjbtjRJDw5UbaSh04PXoiO1uO tGcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E8lBAvMUbSarOvBnBi7Cy+Xm1lvvYValWY+7vlRPdgA=; b=7rJmRjgmtsr5T3Bt5U8Z2n5DwP4o3EEWWN3f3EyA5hWqK4//u8uIXmuFUZSc4uu08k MbB+/F2XEG1LTuOUkHQD7TUHocnY1znppvf9nh2Q928jDImFQNvUZZR/h6mIf2z2BJ+E Nnmp1NIIR4G5dhOa1q7Wxc4CFUjJ1B2R5Q02DBc4nXpnlgJWv0a/ZBlfunn9iBu7jAcV 90LfgTOCHbDv9oQpQUz+uJ62dyQxdqYNImIKqAw8Ade67R9DCOMqHeirY/lCqgbCh6Qy JAjbbrEJ6GWujNbdZa4beoW4wSjcAi07ORtZd9lIrL3A0tL2MOAw0vm3y79Mc08q7jXD OhOg== X-Gm-Message-State: ANoB5pnj958hFce9elNmSeQw00GEkNh0r4ZKwG+Cv+gjkw7gjipqq01W b7QmXFYhYHCWytQeaXI4Tom1vra29a9TNfecw+nw/g== X-Received: by 2002:a1c:7c05:0:b0:3cf:cb16:f24a with SMTP id x5-20020a1c7c05000000b003cfcb16f24amr24690wmc.182.1670977118978; Tue, 13 Dec 2022 16:18:38 -0800 (PST) MIME-Version: 1.0 References: <20221212230820.901382-1-namhyung@kernel.org> In-Reply-To: <20221212230820.901382-1-namhyung@kernel.org> From: Ian Rogers Date: Tue, 13 Dec 2022 16:18:26 -0800 Message-ID: Subject: Re: [PATCH] perf stat: Do not delay the workload with --delay To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Peter Zijlstra , LKML , Adrian Hunter , linux-perf-users@vger.kernel.org, Sumanth Korikkar , Thomas Richter , Kevin Nomura Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 12, 2022 at 3:08 PM Namhyung Kim wrote: > > The -D/--delay option is to delay the measure after the program starts. > But the current code goes to sleep before starting the program so the > program is delayed too. This is not the intention, let's fix it. > > Before: > > $ time sudo ./perf stat -a -e cycles -D 3000 sleep 4 > Events disabled > Events enabled > > Performance counter stats for 'system wide': > > 4,326,949,337 cycles > > 4.007494118 seconds time elapsed > > real 0m7.474s > user 0m0.356s > sys 0m0.120s > > It ran the workload for 4 seconds and gave the 3 second delay. So it > should skip the first 3 second and measure the last 1 second only. But > as you can see, it delays 3 seconds and ran the workload after that for > 4 seconds. So the total time (real) was 7 seconds. > > After: > > $ time sudo ./perf stat -a -e cycles -D 3000 sleep 4 > Events disabled > Events enabled > > Performance counter stats for 'system wide': > > 1,063,551,013 cycles > > 1.002769510 seconds time elapsed > > real 0m4.484s > user 0m0.385s > sys 0m0.086s The commit message feels like it could almost be turned into a shell test. The test would need some fudge factors in case of load on the test system. Any thoughts if we could add this? We wouldn't need to rely on 'time' as we have tool events of user_time, system_time, etc. Thanks, Ian > The bug was introduced when it changed enablement of system-wide events > with a command line workload. But it should've considered the initial > delay case. The code was reworked since then (in bb8bc52e7578) so I'm > afraid it won't be applied cleanly. > > Fixes: d0a0a511493d ("perf stat: Fix forked applications enablement of counters") > Cc: Sumanth Korikkar > Cc: Thomas Richter > Reported-by: Kevin Nomura > Signed-off-by: Namhyung Kim > --- > tools/perf/builtin-stat.c | 33 +++++++++++++++++---------------- > 1 file changed, 17 insertions(+), 16 deletions(-) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index d040fbcdcc5a..b39bf785a16e 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -540,26 +540,14 @@ static int enable_counters(void) > return err; > } > > - if (stat_config.initial_delay < 0) { > - pr_info(EVLIST_DISABLED_MSG); > - return 0; > - } > - > - if (stat_config.initial_delay > 0) { > - pr_info(EVLIST_DISABLED_MSG); > - usleep(stat_config.initial_delay * USEC_PER_MSEC); > - } > - > /* > * We need to enable counters only if: > * - we don't have tracee (attaching to task or cpu) > * - we have initial delay configured > */ > - if (!target__none(&target) || stat_config.initial_delay) { > + if (!target__none(&target)) { > if (!all_counters_use_bpf) > evlist__enable(evsel_list); > - if (stat_config.initial_delay > 0) > - pr_info(EVLIST_ENABLED_MSG); > } > return 0; > } > @@ -930,14 +918,27 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) > return err; > } > > - err = enable_counters(); > - if (err) > - return -1; > + if (stat_config.initial_delay) { > + pr_info(EVLIST_DISABLED_MSG); > + } else { > + err = enable_counters(); > + if (err) > + return -1; > + } > > /* Exec the command, if any */ > if (forks) > evlist__start_workload(evsel_list); > > + if (stat_config.initial_delay > 0) { > + usleep(stat_config.initial_delay * USEC_PER_MSEC); > + err = enable_counters(); > + if (err) > + return -1; > + > + pr_info(EVLIST_ENABLED_MSG); > + } > + > t0 = rdclock(); > clock_gettime(CLOCK_MONOTONIC, &ref_time); > > -- > 2.39.0.rc1.256.g54fd8350bd-goog >