From patchwork Wed Jan 4 06:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 38770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4999966wrt; Tue, 3 Jan 2023 22:45:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXu7zV9LYrR4K5ZXZo9oB33LX6r+qL1hRyMCa2hFYQxC9uQrilmT/Hbb0kc6wLDgk+vbtmYP X-Received: by 2002:a17:902:da86:b0:189:747e:97cc with SMTP id j6-20020a170902da8600b00189747e97ccmr64358043plx.26.1672814748542; Tue, 03 Jan 2023 22:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672814748; cv=none; d=google.com; s=arc-20160816; b=wDEqcc3x7S4Hy1SAGJ8UHnxsJu+yDj0Z7fW53e6wnG9TnZPDSkW745zJCBh6ARNbpF oDNI3kBvh3Gdijt/MdwOr/EA8B/AHhea0ShhgYr46gihWES0rs552UIbaVZbqjXtCuqv 2EwKWOlNjaCK1k/ZFwNJrqf2eF0K7fXY3PU0cEu7mZtR+wyjBTiH89cJXFBKxp5vSQ5C D0RmjRFp+MmIu1MVTyPVBSn1GgKbD8HrItkZJHzCeAqyq/0y+0Gc8jT/cWD+GbpIjoov HYmNlOEd5u+abWv79KRfv64F/EgvyaDod4SHySUH/2nH2mErv8IfnY1ed1J2maV7Xmn2 x5nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=xp5Hj1uOMunUvWIMLUWPDJI/aB8Townrf00dqDCpqV0=; b=tcTXLfazx1gIMCgjM903h39V/LNPMqUdEkf0dfyp7ZmiEzTuyrOuHKqvSBzB9+1pvu AIwQJJ2dG+x7JibzwyATt51UufwT7H7dSg0e1WGXhfzCmsRSyJIeaO+HqLSfqk+cxuZL LQmVUCEf1WPClNi8jJOlCpqedskV2l78h/yi9IfW4MyO2ynTyYLwk0V7ozd0AGyBIfDO ixiYVE5WkipXQXoRoqC+g8GDZ2mT53EdnoGPqs4qeXjrNzlkM/ki6ZGJ6A8mjOH/LaRv FJmLeS/dpcclzjWrVow+/Z62b6SEcXb67AksgUkl1QWFRotYZBIawXDpFNn9pchkWgfY QqMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LkFL3IY5; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l2-20020a632502000000b00478bf137d96si34677822pgl.462.2023.01.03.22.45.36; Tue, 03 Jan 2023 22:45:48 -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=@gmail.com header.s=20210112 header.b=LkFL3IY5; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233583AbjADGoe (ORCPT + 99 others); Wed, 4 Jan 2023 01:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233260AbjADGoI (ORCPT ); Wed, 4 Jan 2023 01:44:08 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2392D1157; Tue, 3 Jan 2023 22:44:08 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id v3so21612939pgh.4; Tue, 03 Jan 2023 22:44:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=xp5Hj1uOMunUvWIMLUWPDJI/aB8Townrf00dqDCpqV0=; b=LkFL3IY5NRqL+oGa6Y7xnMopkhn4Ww6YfUfKJd8GzoypjwuYO2qNLNOOUS2sVoEtsV xxm96hfdketMDudUKLcqBH2Ufj3pLbhEjIkTA//n8RILprvvg8r1zrgPtYGnMk9//JLk XJzzcpoWg55qyInfWCpkWUB7ExANRRbI/0k/BFtT4mvBYnMCJeiV8P2KC0HOcUO88Q9u Ok1rrQXTqejGtiGFpFX6BEPVNnc2WHUU2OHhnwMOPELKTUhQzyDFMog8J6W+WWtpdzBZ 8rxrRsLnYfS+lbARtTAvzd7ai4wwk4/80okYyF8WiPfzNADuIgFwIxhpLd4cO1/kcJrn uFdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xp5Hj1uOMunUvWIMLUWPDJI/aB8Townrf00dqDCpqV0=; b=tMQCkbFwWVB62nIvaA1KElf8vm1z/LAQ88xrsPKS3YJtnujy6H3qHwK6OXNfPgRuCQ Tl6ITTiYy3bY0mCR20NUP5GRGUYIh/JWq3Xj9oOeaxHr2BfCWTJcCKeIeGDkMLMsXjRk cF2NOOFx2F3l0HuEIehQ0qkNYdB4HJVTDY4fkYa3OBHnlHW4I0tGI/jfBnAOGA09xCEO RCNEj69lqIM4YKtCKeeltBLO8BmeihPjUt+KR7fYy3+MHo6bdICuZq6BxeSBZBiasrh+ vWMrykGHi3TVoQ2AvTiwDzinhA4IPX5LBNEwqrdStKMxxqrbv4oIHKzC7ftDzQJ+Us7P posA== X-Gm-Message-State: AFqh2ko6jLEROWqa4l6VQzy0zEn5aIePlrcmOVq/ax39apJdX1W8AZHe P9ZBpEY/yrdbJHee7dECHco= X-Received: by 2002:a05:6a00:1a45:b0:582:294d:f465 with SMTP id h5-20020a056a001a4500b00582294df465mr15550932pfv.13.1672814647626; Tue, 03 Jan 2023 22:44:07 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:d1f4:a47f:3a41:e1a2]) by smtp.gmail.com with ESMTPSA id e28-20020a056a0000dc00b00576f7bd92cdsm11829257pfj.14.2023.01.03.22.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:44:07 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: [PATCH 1/4] perf bpf_counter: Add more error messages for bperf Date: Tue, 3 Jan 2023 22:43:59 -0800 Message-Id: <20230104064402.1551516-2-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230104064402.1551516-1-namhyung@kernel.org> References: <20230104064402.1551516-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754073397810993227?= X-GMAIL-MSGID: =?utf-8?q?1754073397810993227?= I found perf stat silently exits when it failed in bperf__load(). Let's add some error messages to notify users. $ sudo ./perf stat -a --bpf-counters -ddd sleep 1 bpf_map_update_elem failed: err=-7 Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_counter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index eeee899fcf34..7f5cc1aa4903 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -471,8 +471,10 @@ static int bperf__load(struct evsel *evsel, struct target *target) if (!all_cpu_map) { all_cpu_map = perf_cpu_map__new(NULL); - if (!all_cpu_map) + if (!all_cpu_map) { + pr_err("failed to create all cpu map\n"); return -1; + } } evsel->bperf_leader_prog_fd = -1; @@ -493,13 +495,16 @@ static int bperf__load(struct evsel *evsel, struct target *target) err = bpf_map_lookup_elem(attr_map_fd, &evsel->core.attr, &entry); if (err) { err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, &entry, BPF_ANY); - if (err) + if (err) { + pr_err("updating perf_event_attr map failed: err=%d\n", err); goto out; + } } evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry.link_id); if (evsel->bperf_leader_link_fd < 0 && bperf_reload_leader_program(evsel, attr_map_fd, &entry)) { + pr_err("reload leader program failed\n"); err = -1; goto out; } From patchwork Wed Jan 4 06:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 38769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4999812wrt; Tue, 3 Jan 2023 22:45:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJtsCmA2v4uUXgsanzzhfgKkAtdgiyq5mnrDekh6XceZ77AR+zDdkVkvI/kFOGloQrLN50 X-Received: by 2002:a62:ee0e:0:b0:580:cf1a:f2b5 with SMTP id e14-20020a62ee0e000000b00580cf1af2b5mr38044767pfi.12.1672814718754; Tue, 03 Jan 2023 22:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672814718; cv=none; d=google.com; s=arc-20160816; b=WTOa2k9PASlI2CxJWEjK3jvYBJ+b63yx/zjt8hfpbkG9NkeP3BKgfugECBi804ls7V diK3x1G6bkqUkibutubv40WGmXrz0M5kzduVIYrVshneKg7L5sRXrNT2XMdHXtuMXLU4 AWBWSNjEa/y+YvbibrnaBAs8PKOep9PK8V24vpjTNjeZzZpzRysw+z7YOsYDPQMiHqlp jwD/0+dldb6jdhjvIk7kPxlM7EFQfoyYimDGjAB8kltPO82BW266oyISHUvsbc8zhNlZ Aa3bFpt1kCrzCDeRvWLDUDf2uE0a/lfQtWXFtiySQBbRA6GEN3kQbYyBC04Jlufjh+3o ktVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=qYyFBSOYl+N37EChskGvYBFRtSPcjv1yDLUNKRSs7MM=; b=BD+Fcyv9DEcMAHECoccoY4xmFgp+/SLCOEpHVSmrtEr7XTT/q1rx0uKdhBph5Pi8Hs IL08XAbZIGZYZmeX8UP/3+l1NwttjJq2WjHQekTvbJcGjj5ehSFh099wXIhUd2AQUD0F 64CfviIuj8zvIfeX6gaiMdbDboxx2vBCC9ilkoKmeYfN47HtsoP/hM/pftJXAC/pHJrY 5Eqv3JOOGg2ZTGB/b6V0HawfOSspIezQP5NAY4WxgHJKWop9kF6Frx3w5wTb3L6SVyXN uZKpDoKICKKYiQjL/L/X+Ngohev6e3xBHRvj7ydTziuz5l7qqnJECm8C6iURGpKJW3Kz jtAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=UxEyTrBR; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a056a00158300b005785dbe7066si33443194pfk.187.2023.01.03.22.45.06; Tue, 03 Jan 2023 22:45:18 -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=@gmail.com header.s=20210112 header.b=UxEyTrBR; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233543AbjADGo2 (ORCPT + 99 others); Wed, 4 Jan 2023 01:44:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233306AbjADGoK (ORCPT ); Wed, 4 Jan 2023 01:44:10 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B3DA2E5; Tue, 3 Jan 2023 22:44:09 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id s67so12303129pgs.3; Tue, 03 Jan 2023 22:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=qYyFBSOYl+N37EChskGvYBFRtSPcjv1yDLUNKRSs7MM=; b=UxEyTrBRmwjsHTMfS+syQvxgGQTx/wNtXpdL5cuHQwnv9y5GBApVJRFXRBX4qaXd3c CwhCtWGNf0BEazBtrSOOwhtX3Dvz4ur/jOWBK9OXMbdOcYgj3FFm4sJUkLqbMSQw7Eqc iJMM7atv89+rSMEBWArvTDyEo0rwYtrssbu1saCb4XvzdJowP/7WffiCb78dvuPvNzv9 bT3C7pAQHqFYHGF+Dchsf8onVKCCoWfcYY5Uh7D+aI4zkMGI4B4B9PW5Ymcyue6X9stj YejIXrbKqCJWO9dPG7TbBSIEyBp8vL3y0/fsFRTfg+Snd0+boMjNhPYVxN0Jum3RT7t5 DsSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qYyFBSOYl+N37EChskGvYBFRtSPcjv1yDLUNKRSs7MM=; b=wIACj2qh0PetSc57r9qphdmRTGZvSiW5IxCZ8iOF3HmWPCkiiLEl7X4n/RLZasZgXY pGeCUtzAmSoBMzOCceIolSXrAPzvo2PBILK1t6OhoUhtwxhCLx23KWN2BRc1fE2SeSwL 9O7VHeeWjTDfTlfvq2/g/PvWdDuwRsvIJtgJJGJ8d/j4bnirtdXNW0k5WvJ+NT6aSlXq 2XKZkeQp1TXCOiAMqBkqsFg0/Ak6eoESgUH8k8GUJ7mnte659GzglTQqoW+cH0eVhPxM INSvcJVnxfg+mGbbMPrcAr3yeoM8IQpcWA/Au6d0WtB/4IfiLb/dKtLef59AWxXmwixR I66w== X-Gm-Message-State: AFqh2kp2V+KvrDuca9QRvWnWanriHJ0eJl0v5Vp29sd9dykIw1BkdIYs Y3uq1Jj25uO8/qL99S6+DgU= X-Received: by 2002:a05:6a00:84c:b0:581:1ee0:75a with SMTP id q12-20020a056a00084c00b005811ee0075amr40159114pfk.32.1672814649048; Tue, 03 Jan 2023 22:44:09 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:d1f4:a47f:3a41:e1a2]) by smtp.gmail.com with ESMTPSA id e28-20020a056a0000dc00b00576f7bd92cdsm11829257pfj.14.2023.01.03.22.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:44:08 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: [PATCH 2/4] perf bpf_counter: Increase perf_attr_map entries to 32 Date: Tue, 3 Jan 2023 22:44:00 -0800 Message-Id: <20230104064402.1551516-3-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230104064402.1551516-1-namhyung@kernel.org> References: <20230104064402.1551516-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754073366292388152?= X-GMAIL-MSGID: =?utf-8?q?1754073366292388152?= The current size 16 cannot hold all events when user gave -dd or -ddd. As it's a part of perf stat, let's increase the size to 32. # unlink previous map to change the size $ sudo unlink /sys/fs/bpf/perf_attr_map $ sudo ./perf stat -a --bpf-counters -ddd sleep 1 Performance counter stats for 'system wide': 35,927.41 msec cpu-clock # 35.802 CPUs utilized 12,629 context-switches # 351.514 /sec 209 cpu-migrations # 5.817 /sec 826 page-faults # 22.991 /sec 2,155,729,621 cycles # 0.060 GHz (30.43%) 1,053,849,500 instructions # 0.49 insn per cycle (38.18%) 232,711,500 branches # 6.477 M/sec (38.44%) 10,693,352 branch-misses # 4.60% of all branches (31.27%) 267,561,655 L1-dcache-loads # 7.447 M/sec (30.58%) 27,290,728 L1-dcache-load-misses # 10.20% of all L1-dcache accesses (30.48%) 12,651,208 LLC-loads # 352.133 K/sec (30.78%) 1,274,018 LLC-load-misses # 10.07% of all LL-cache accesses (38.70%) L1-icache-loads 75,916,358 L1-icache-load-misses # 0.00% of all L1-icache accesses (38.11%) 273,330,559 dTLB-loads # 7.608 M/sec (30.54%) 2,864,458 dTLB-load-misses # 1.05% of all dTLB cache accesses (38.77%) 361,507 iTLB-loads # 10.062 K/sec (30.59%) 848,031 iTLB-load-misses # 234.58% of all iTLB cache accesses (31.30%) L1-dcache-prefetches L1-dcache-prefetch-misses Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_counter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index 7f5cc1aa4903..de6331f5263c 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -28,7 +28,7 @@ #include "bpf_skel/bperf_leader.skel.h" #include "bpf_skel/bperf_follower.skel.h" -#define ATTR_MAP_SIZE 16 +#define ATTR_MAP_SIZE 32 static inline void *u64_to_ptr(__u64 ptr) { From patchwork Wed Jan 4 06:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 38771 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5000049wrt; Tue, 3 Jan 2023 22:46:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXv7065FbCs8qutdzPFst7mVwrg0RNApj3ehF645gVgL6+sbvTVJCbjJkaXX3Edjxz/fQ9Bg X-Received: by 2002:a62:1c52:0:b0:581:f654:a37d with SMTP id c79-20020a621c52000000b00581f654a37dmr18140301pfc.17.1672814762927; Tue, 03 Jan 2023 22:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672814762; cv=none; d=google.com; s=arc-20160816; b=Q0hTic1wdzMdPUXqBIR/hZHVU5xOMQtXgbdEldi7xTxhUW1uROGjPPTfxRvCWGBVo4 OHwZSs82wvzb8LbqAcaAdkOJ162NGmVURaPcikpFaESNMqSGdA7dxzRkiDqef0g4hr16 tmdq71SlC47FvZ3C+dZibywWv4LuK3NHLZ189oHkKOixzW/m2gEe89XwjFtDe/Wiq4Jm 6O8aly5ynO+hydWVlWhlNI3AyQX3bI2oNBo77P4zoKhd6o1uEA5o2revDVUVXcdjfdHC cR6Jzf+0ZTKwyebIJRgjUclRYRcIfyLiag0a5hw+jD8njsnm5scab8pIDwEfdf+kKSzt iQqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=4cgcHCT3G9N5bTmGeqZ7j5U+CmWU3a6ei0Q30f2GNqI=; b=1KvrKoRpJiA5LLNoCVp/kgbGXFZK8sqkGJOmSrHhBmx0Wx990LA3KXy3FLweEc7aNA fZoSS6TEhBa/0aM/yFX1F0OyLR3EtFdXgPY4D8hT9puGH5b0PTqi6WLUuFEiOFUPlV3/ uKnci41kjcobYLyBn4a8GErRHSevq9oreJSzNUYYO1y2jcJDKtedCVxBaePd5F6rB8WW k+VcnPXodmMHz3SjVnjjjnw0HyhX7Y4hKrpQ4/Osj6Y9BRbf24zF4cOzKak8ndm29d9x 9SU1ug3O/qwYpiu2rqozBXwSJTZJstFwafye37AJOpGyjhvxmlnq3xoeTdLMcH6eV+8B w2IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="H4XigTn/"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 205-20020a6218d6000000b0057fadf9ef57si24208558pfy.254.2023.01.03.22.45.50; Tue, 03 Jan 2023 22:46:02 -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=@gmail.com header.s=20210112 header.b="H4XigTn/"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233604AbjADGoj (ORCPT + 99 others); Wed, 4 Jan 2023 01:44:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbjADGoL (ORCPT ); Wed, 4 Jan 2023 01:44:11 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149232E5; Tue, 3 Jan 2023 22:44:11 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id a30so6550984pfr.6; Tue, 03 Jan 2023 22:44:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=4cgcHCT3G9N5bTmGeqZ7j5U+CmWU3a6ei0Q30f2GNqI=; b=H4XigTn/KLhd6ZcA1McBlsmhzTWkRx7D+UVTw8GwUYTqFDz3RaJToZj0GC9EQNCsl9 7hNBQ2S0GOYoQYJyZJTz/KLsD0RZwG9XIwHf+5VTu8lx0+YA2LP3u5zumDRUAsf1Qnyi FUJZgIGolIhocllM3NyrARFA/PJ2naa4TT4ipJTu4Rv76MOyU6HVPuG8ZEEiBB08wqTz gRjKhdzIZVBcH6hgWIYohNzA7Dz20vBQet+V4U0eZ6bDH3kZmJSbMAJKOYViwYeuIffU 6VR1ypLTxSiAZ40307j6IfxmskOQHHQSOkjfhSWVUgPZO7ND9PTfAbUq7RJBL7tPmxHr d99w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4cgcHCT3G9N5bTmGeqZ7j5U+CmWU3a6ei0Q30f2GNqI=; b=AXt0keKTznIBlU5DvsUcVCV8G3PTb9OC/LM9oMlgyyKcUTjAGtQqQzFu0fiCwsyupx a5RHzeHPrN6gzEoxNKJsKGW2MBN6uMveUS5wcylnzSlIfl+afO5TlfrWbLl8eqDe8lQG G3W8uHbqXGMGDdT7BnyZO4u6yT22HR0KjQOG3q9g1pwEWtvhO2MRxO20iTWr48nzloKy sC0hcF3rpDtVNMbs4lfkVOOclLu10B5NzNzovV7fTBKf8v5eKwbG1GN2sjCJvXCO01BE I/2e55Zwpr/DqEjt69dNxx1SIJrpeJT/iqp/wBmaMI+yQwvdJNlWQCMhRUTBn/iBP6Ow TlTw== X-Gm-Message-State: AFqh2kqzQHTvcYuzO/RgryoW6RZINTZSEWzapro/8vbqxATvzSCKT5S/ UYz6FM4uSPRk3CNYMdnZqWY= X-Received: by 2002:a62:32c3:0:b0:580:f1b0:2211 with SMTP id y186-20020a6232c3000000b00580f1b02211mr32038887pfy.18.1672814650468; Tue, 03 Jan 2023 22:44:10 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:d1f4:a47f:3a41:e1a2]) by smtp.gmail.com with ESMTPSA id e28-20020a056a0000dc00b00576f7bd92cdsm11829257pfj.14.2023.01.03.22.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:44:09 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: [PATCH 3/4] perf bpf_counter: Handle unsupported cgroup events Date: Tue, 3 Jan 2023 22:44:01 -0800 Message-Id: <20230104064402.1551516-4-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230104064402.1551516-1-namhyung@kernel.org> References: <20230104064402.1551516-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754073412834013078?= X-GMAIL-MSGID: =?utf-8?q?1754073412834013078?= When --for-each-cgroup option is used, it failed when any of events is not supported and it exited immediately. This is not how perf stat handles the unsupported events. Let's ignore the failure and proceed with others. Before: $ sudo ./perf stat -a --bpf-counters -e L1-icache-loads,L1-dcache-loads \ > --for-each-cgroup system.slice,user.slice sleep 1 Failed to open first cgroup events After: $ sudo ./perf stat -a --bpf-counters -e L1-icache-loads,L1-dcache-loads \ > --for-each-cgroup system.slice,user.slice sleep 1 Performance counter stats for 'system wide': L1-icache-loads system.slice 29,892,418 L1-dcache-loads system.slice L1-icache-loads user.slice 52,497,220 L1-dcache-loads user.slice Fixes: 944138f048f7d ("perf stat: Enable BPF counter with --for-each-cgroup") Signed-off-by: Namhyung Kim --- tools/perf/util/bpf_counter_cgroup.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c index 3c2df7522f6f..1c82377ed78b 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -116,27 +116,19 @@ static int bperf_load_program(struct evlist *evlist) /* open single copy of the events w/o cgroup */ err = evsel__open_per_cpu(evsel, evsel->core.cpus, -1); - if (err) { - pr_err("Failed to open first cgroup events\n"); - goto out; - } + if (err == 0) + evsel->supported = true; map_fd = bpf_map__fd(skel->maps.events); perf_cpu_map__for_each_cpu(cpu, j, evsel->core.cpus) { int fd = FD(evsel, j); __u32 idx = evsel->core.idx * total_cpus + cpu.cpu; - err = bpf_map_update_elem(map_fd, &idx, &fd, - BPF_ANY); - if (err < 0) { - pr_err("Failed to update perf_event fd\n"); - goto out; - } + bpf_map_update_elem(map_fd, &idx, &fd, BPF_ANY); } evsel->cgrp = leader_cgrp; } - evsel->supported = true; if (evsel->cgrp == cgrp) continue; From patchwork Wed Jan 4 06:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 38772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5000406wrt; Tue, 3 Jan 2023 22:47:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0LcdPVqWEk+ZP1lsFfFLZI0WVAgGGTGaQ8NeQlz/2NU90+gNujOq7HLdAizxoy5qHSAbh X-Received: by 2002:a05:6a20:1455:b0:b0:7873:dda9 with SMTP id a21-20020a056a20145500b000b07873dda9mr72008211pzi.3.1672814854000; Tue, 03 Jan 2023 22:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672814853; cv=none; d=google.com; s=arc-20160816; b=IAt3kUHYEas/Lk16mIEWXv7RwAKsinpU+J2R2HqRh/sj9vw60CCfudlhyiRsJhZTxW r1y5uDze8vmWA+Acpm7aAvXQx0tNN9iw4QIBoMzYWsK/usCiSGMtORTuZN1JctUz+fBz PXyvdnxRmGP0IgHB2X2yHIkHox8v6zJFrjVWdGX2Fvm1Ik73rF0ENGDfTeVHZep3efEb o6joPbVqc63bViilwydb31oeh61mhkC+yj10HBGwOHo8oSiN8Rkwmk0ObIQJd1U8BKhR LfE6NtRlbDhsbr8JrGeOK7f82xI88kcNDrpyQBD8X6E6qI4zsXtkzsKDFRw7gQ8fp+y/ dwoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=+bliKfRbQDwAdV97iBZEDSuzGn0Y1LH+Sf/kDY4qOSE=; b=nOugu2nSSKbid3gM1SOIPeH9A5OC9OPayj8R4QrdjMNFxKN6Kpk8vmvV8PJPeT7Wjc ULx5gPrvBvuv/sASh7BBCYCKLpnk57bRXQ5lF02jJ1fkLxJg4bHFoWUfpWv8YSr3hvAP Y257LntQi1rGwVncyKiPl9FRDIle9IH0yW9l23qV1625F/T9Vzmp2foXB9IMyY8uFHVe b2b0+NTS8jFhQPAWekoqAJR8J9Js0ah9Pe0KKFU5q0mDCuTb4lDQDzuKHpQctO/AzNx7 WJD9AjXwlJGGtqX6/MI2/pgOtV4O/sciCDLMmhamwaI6oSSA/xeiy762gRZdeTCi2Lv8 GBiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cxIOOkUt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h70-20020a638349000000b004a46963e2b7si4659094pge.313.2023.01.03.22.47.21; Tue, 03 Jan 2023 22:47:33 -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=@gmail.com header.s=20210112 header.b=cxIOOkUt; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233551AbjADGop (ORCPT + 99 others); Wed, 4 Jan 2023 01:44:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233329AbjADGoN (ORCPT ); Wed, 4 Jan 2023 01:44:13 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCFB2E5; Tue, 3 Jan 2023 22:44:12 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id o21so5092701pjw.0; Tue, 03 Jan 2023 22:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+bliKfRbQDwAdV97iBZEDSuzGn0Y1LH+Sf/kDY4qOSE=; b=cxIOOkUt8IWLH0cIGaDmPPocHS4+b8nZeOZSKJTwIzIioIzzrJEWbsBdB20yQSLTiB rv8aZVuBiQlm99kquR8FaBb5qXjzD79AkKjTdku4QyfvVOwmu8K78HoD/z1UNroLYNP5 uvhs7YDAwdb/IZ9WOWNum7qPngiGL0EOxJHL5VqnCJFRbY3AhYhmuDygjdIqjcS3vLHB 5Iq7jDnCGpfFyzMHVh47Q0pUyrTzYlbqy9HNk5ZUuHdSiePuspbY78ZhES0RlLlYoiaY 7C6x/p60oVKAZENXtwlbtXZ4qsjWf0yKWuQmEQX7N3WZ8qyYmTDPAx6YW9zPCi4QPykU 2eTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+bliKfRbQDwAdV97iBZEDSuzGn0Y1LH+Sf/kDY4qOSE=; b=3Mp2WTqkhoHjIxIR+9ORj+TBZL16Xc60e1/Q/sKuFFM+uLUcO/h0jdcq8DprogvWIw UfQE5nV1f8JS8vOJil6mE0DCYRa+JMNq+9TWPPlHv7O/xiYAoneSzeuNekm8P+n2kXDm us6ALSvGpeSk8N9cAYZp/wXuOH7M3f9jEPToqUsGiDj/SEzqrkUgtzM1JFYpV8tEdPYD f7jO5BiSqeEMk+04GsTpeDDrndI8CuvJP0zc5gcFWqPcKbSwqyMgtsrqz3d14SH6Gy8E +b6E3Va5+bmnx988VWHivGnX5NUzSD5X7BYszdqFh5lcUnaPvQGWOhA56d/2m1O2C60A hK6w== X-Gm-Message-State: AFqh2kosCJs5JRPHsQ/cl2XDeORLQIxQjQgmkYyNJo2Qwe32q1JaUDih D5sgBbDWWho8M85BmT+jwzM= X-Received: by 2002:a05:6a20:659d:b0:b0:275d:3036 with SMTP id p29-20020a056a20659d00b000b0275d3036mr56741439pzh.24.1672814651855; Tue, 03 Jan 2023 22:44:11 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:d1f4:a47f:3a41:e1a2]) by smtp.gmail.com with ESMTPSA id e28-20020a056a0000dc00b00576f7bd92cdsm11829257pfj.14.2023.01.03.22.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 22:44:11 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Song Liu , bpf@vger.kernel.org Subject: [PATCH 4/4] perf stat: Do not use the same cgroup more than once Date: Tue, 3 Jan 2023 22:44:02 -0800 Message-Id: <20230104064402.1551516-5-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230104064402.1551516-1-namhyung@kernel.org> References: <20230104064402.1551516-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754073508130098098?= X-GMAIL-MSGID: =?utf-8?q?1754073508130098098?= The --for-each-cgroup can have the same cgroup multiple times, but it makes bpf counters confused (since they have the same cgroup id), and the last cgroup events are counted only. Let's check the cgroup name before adding a new entry. Before: $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1 Performance counter stats for 'system wide': msec cpu-clock / context-switches / cpu-migrations / page-faults / cycles / instructions / branches / branch-misses / 8,016.04 msec cpu-clock / # 7.998 CPUs utilized 6,152 context-switches / # 767.461 /sec 250 cpu-migrations / # 31.187 /sec 442 page-faults / # 55.139 /sec 613,111,487 cycles / # 0.076 GHz 280,599,604 instructions / # 0.46 insn per cycle 57,692,724 branches / # 7.197 M/sec 3,385,168 branch-misses / # 5.87% of all branches 1.002220125 seconds time elapsed After: $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1 Performance counter stats for 'system wide': 8,013.38 msec cpu-clock / # 7.998 CPUs utilized 6,859 context-switches / # 855.944 /sec 334 cpu-migrations / # 41.680 /sec 345 page-faults / # 43.053 /sec 782,326,119 cycles / # 0.098 GHz 471,645,724 instructions / # 0.60 insn per cycle 94,963,430 branches / # 11.851 M/sec 3,685,511 branch-misses / # 3.88% of all branches 1.001864539 seconds time elapsed Fixes: bb1c15b60b981 ("perf stat: Support regex pattern in --for-each-cgroup") Signed-off-by: Namhyung Kim --- tools/perf/util/cgroup.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index e99b41f9be45..cd978c240e0d 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -224,6 +224,19 @@ static int add_cgroup_name(const char *fpath, const struct stat *sb __maybe_unus return 0; } +static int check_and_add_cgroup_name(const char *fpath) +{ + struct cgroup_name *cn; + + list_for_each_entry(cn, &cgroup_list, list) { + if (!strcmp(cn->name, fpath)) + return 0; + } + + /* pretend if it's added by ftw() */ + return add_cgroup_name(fpath, NULL, FTW_D, NULL); +} + static void release_cgroup_list(void) { struct cgroup_name *cn; @@ -242,7 +255,7 @@ static int list_cgroups(const char *str) struct cgroup_name *cn; char *s; - /* use given name as is - for testing purpose */ + /* use given name as is when no regex is given */ for (;;) { p = strchr(str, ','); e = p ? p : eos; @@ -253,13 +266,13 @@ static int list_cgroups(const char *str) s = strndup(str, e - str); if (!s) return -1; - /* pretend if it's added by ftw() */ - ret = add_cgroup_name(s, NULL, FTW_D, NULL); + + ret = check_and_add_cgroup_name(s); free(s); - if (ret) + if (ret < 0) return -1; } else { - if (add_cgroup_name("", NULL, FTW_D, NULL) < 0) + if (check_and_add_cgroup_name("/") < 0) return -1; }