From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83C94C11F65 for ; Wed, 30 Jun 2021 06:35:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F47E608FC for ; Wed, 30 Jun 2021 06:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232444AbhF3GiA (ORCPT ); Wed, 30 Jun 2021 02:38:00 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:38678 "EHLO mail-lf1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhF3Gh6 (ORCPT ); Wed, 30 Jun 2021 02:37:58 -0400 Received: by mail-lf1-f45.google.com with SMTP id w19so3055922lfk.5 for ; Tue, 29 Jun 2021 23:35:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h/tLGN3hRZj0zANfVL6Q277rdmp7F9TE5YlLbVXnOt4=; b=DPFPhVcoce7xQhvsFqUDq/krO2kPrlT1HogtgckyFvGEjx+NXa8KQCjnyycNLxgbvO MVKmr3nS/jPc6X6MUcDxY4wIgV0BM4zNfgcBPgMA3Z5fCSz7Lk9rJJkr4XbKmIneCVdL M1+FTBc039L5VjzkVVlrlmYSylDxFLzkDu/oVzQvO6NBt9yTGL5d+LBUf5oyJB9mKFc5 7iAuYg9vRma+yWWDB0ngu4uuZ7FMQ316vMRZg8fVut5YME1idgmAes/oKR8urRYQjIzL LyRuajOzVwMKkfGDgkqtrzu5+M10hIN6/swK5MII86oA6s6klVVMWfEdHyXFRWOz8Rmp xRrA== X-Gm-Message-State: AOAM533UBl5kNM82cEMFjxTJzQKgzTZBiGFHg4f4seHrHl0ttOcpZHz3 Y4ZAR+M4TBN8m3UDbJoiXaLf35StsSSltvNz4LI= X-Google-Smtp-Source: ABdhPJw3/8y5ByRxr2zDzj1BO0+/VKGk9doSoT+EA1HcHznuL9vKzdPVhzx5ogdAblvdfTyb435FARtrsF0VUtMWfbo= X-Received: by 2002:a19:4916:: with SMTP id w22mr27126889lfa.374.1625034928338; Tue, 29 Jun 2021 23:35:28 -0700 (PDT) MIME-Version: 1.0 References: <20210625071826.608504-1-namhyung@kernel.org> <20210625071826.608504-3-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Tue, 29 Jun 2021 23:35:17 -0700 Message-ID: Subject: Re: [PATCH 2/4] perf tools: Add cgroup_is_v2() helper To: Ian Rogers Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Stephane Eranian , Song Liu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ian, On Tue, Jun 29, 2021 at 8:51 AM Ian Rogers wrote: > > On Fri, Jun 25, 2021 at 12:18 AM Namhyung Kim wrote: > > > > The cgroup_is_v2() is to check if the given subsystem is mounted on > > cgroup v2 or not. It'll be used by BPF cgroup code later. > > > > Signed-off-by: Namhyung Kim > > --- > > tools/perf/util/cgroup.c | 19 +++++++++++++++++++ > > tools/perf/util/cgroup.h | 2 ++ > > 2 files changed, 21 insertions(+) > > > > diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c > > index ef18c988c681..e819a4f30fc2 100644 > > --- a/tools/perf/util/cgroup.c > > +++ b/tools/perf/util/cgroup.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -70,6 +71,24 @@ int read_cgroup_id(struct cgroup *cgrp) > > } > > #endif /* HAVE_FILE_HANDLE */ > > > > +#ifndef CGROUP2_SUPER_MAGIC > > +#define CGROUP2_SUPER_MAGIC 0x63677270 > > +#endif > > + > > +int cgroup_is_v2(const char *subsys) > > +{ > > + char mnt[PATH_MAX + 1]; > > + struct statfs stbuf; > > + > > + if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1, subsys)) > > + return -1; > > + > > + if (statfs(mnt, &stbuf) < 0) > > + return -1; > > + > > + return (stbuf.f_type == CGROUP2_SUPER_MAGIC); > > +} > > + > > static struct cgroup *evlist__find_cgroup(struct evlist *evlist, const char *str) > > { > > struct evsel *counter; > > diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h > > index 707adbe25123..1549ec2fd348 100644 > > --- a/tools/perf/util/cgroup.h > > +++ b/tools/perf/util/cgroup.h > > @@ -47,4 +47,6 @@ int read_cgroup_id(struct cgroup *cgrp) > > } > > #endif /* HAVE_FILE_HANDLE */ > > > > +int cgroup_is_v2(const char *subsys); > > + > > I think this is okay. It may make sense to have this in > tools/lib/api/fs/fs.h, for example fs__valid_mount is already checking > magic numbers. Perhaps we can avoid a statfs call, but it'd need some > reorganization of the fs.h code. > > Acked-by: Ian Rogers Thanks for your review! Actually I'm ok with moving it to tools/lib. Will do it in the next spin, if it needs one. :) Thanks, Namhyung