Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1576809pxa; Thu, 6 Aug 2020 10:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZn/GqB0UhlzrvC/tdIqd+oPvxE7H5Fb04L6e2+yAFtMjX45rD5YPItqUyTK/GmjC6511d X-Received: by 2002:a17:906:1f8e:: with SMTP id t14mr5531877ejr.336.1596735576136; Thu, 06 Aug 2020 10:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596735576; cv=none; d=google.com; s=arc-20160816; b=PyqdUjtTyl3po0+Z7+0msSuh+ATMkTJY1WsmdRiAlWJ3Li1+ufzHeHkBmahI9PQoy/ mtPYpL8Dh0h4Hdd2hJ9hnlWstvmHUZMHt/PCtd3ZZtoHjBWlaBBviVamVEt53IGLrbwZ MogmMALDTxSdwHgA/KA2FLf7d0YFJjro5cy1JC98S3PY2SYgNS3HXNsF59q/Dz/Aq1rb lOO5e2paYAPZMEHLmn4FgcAdC980FbMrpXUEzrKtW5MR5V+tk0nOPrx4DqdYHFQmHAAL NT7vtfKJPhoVs2xqpEDJPux+4+LBxDj8QitPE+ZyDa/mzPP4PnQ+OPUeRcZr347e7u9B YllA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=AEKXDM5AqGWbqZfvmgTnFzC1WvH0JUmplFSiAzaLbI4=; b=NaoDm/WKO0mmqD+fEgyIwvcLDCcDHqLWfZzm7cCADpNjnqImVTMUPc4554E06FV6lg SBGvwOihpIimQPJxEuv+XVOUC65LnTjmehVPd91mWod9VNPZ22VDRB6z5496sVYXumQO RYwNGxQ5Lpi37Kn04Iq+t9hmimgrQX9z5D8gPqj9RroYXghkAvo0+8jkVftz16faFqqr uVKtufhbz8UQ5mjHQOwsQgMNNpsh31bB+J8Uy7PtqU9VwHUXk3NO78sWLIvTO/CF81sJ DoBJ/yi1iFUqdCMXuGa8m0wQPb0zY6FN0mZKn2sEG/jfVyopzONq1PKqPfPa9yXqdb72 c+Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lnUT1r8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g15si3422104edy.601.2020.08.06.10.39.13; Thu, 06 Aug 2020 10:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lnUT1r8w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1729699AbgHFRij (ORCPT + 99 others); Thu, 6 Aug 2020 13:38:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:54634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729357AbgHFRbn (ORCPT ); Thu, 6 Aug 2020 13:31:43 -0400 Received: from quaco.ghostprotocols.net (unknown [179.162.129.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 26FF222DFB; Thu, 6 Aug 2020 12:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596717225; bh=NooNHalXJIVBoDLR8ZhPokCwAJpcAbxaJBVRP7ZrCKg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lnUT1r8wu/HTd5VrHZTX7yU3Ju3TBdEHFLvNGAQWxs8MTHMUxMKDKFYW2F9ECcck5 /FBJ/mshB+YVaD41Ph07ywpVIjJHtKdiIeXjEoVOOyKR/564Po7jqS8hJ8XWFIzz/T wrhgteYpKwB644ThoVl63kIAK5Cpf9eQgaVOvaYE= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 6714640524; Thu, 6 Aug 2020 09:33:42 -0300 (-03) Date: Thu, 6 Aug 2020 09:33:42 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Ian Rogers , Andi Kleen , David Ahern , =?iso-8859-1?Q?Genevi=E8ve?= Bastien , Wang Nan , Jeremie Galarneau Subject: Re: [PATCH v2 1/7] perf tools: Move parse_clockid into clockid object Message-ID: <20200806123342.GD71359@kernel.org> References: <20200805093444.314999-1-jolsa@kernel.org> <20200805093444.314999-2-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200805093444.314999-2-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Aug 05, 2020 at 11:34:38AM +0200, Jiri Olsa escreveu: > Move parse_clockid and all needed clcckid related stuff > into clockid object. We are going to add clockid_name > function in following change, so it's better it's placed > in separated object and not in builtin-record.c. > > No functional change is intended. Thanks, applied. - Arnaldo > Signed-off-by: Jiri Olsa > --- > tools/perf/builtin-record.c | 98 +------------------------------- > tools/perf/util/Build | 1 + > tools/perf/util/clockid.c | 108 ++++++++++++++++++++++++++++++++++++ > tools/perf/util/clockid.h | 9 +++ > 4 files changed, 119 insertions(+), 97 deletions(-) > create mode 100644 tools/perf/util/clockid.c > create mode 100644 tools/perf/util/clockid.h > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > index b6bdccd875bc..eb42d2d9d16b 100644 > --- a/tools/perf/builtin-record.c > +++ b/tools/perf/builtin-record.c > @@ -46,6 +46,7 @@ > #include "util/bpf-event.h" > #include "util/util.h" > #include "util/pfm.h" > +#include "util/clockid.h" > #include "asm/bug.h" > #include "perf.h" > > @@ -2078,103 +2079,6 @@ static int perf_record_config(const char *var, const char *value, void *cb) > return 0; > } > > -struct clockid_map { > - const char *name; > - int clockid; > -}; > - > -#define CLOCKID_MAP(n, c) \ > - { .name = n, .clockid = (c), } > - > -#define CLOCKID_END { .name = NULL, } > - > - > -/* > - * Add the missing ones, we need to build on many distros... > - */ > -#ifndef CLOCK_MONOTONIC_RAW > -#define CLOCK_MONOTONIC_RAW 4 > -#endif > -#ifndef CLOCK_BOOTTIME > -#define CLOCK_BOOTTIME 7 > -#endif > -#ifndef CLOCK_TAI > -#define CLOCK_TAI 11 > -#endif > - > -static const struct clockid_map clockids[] = { > - /* available for all events, NMI safe */ > - CLOCKID_MAP("monotonic", CLOCK_MONOTONIC), > - CLOCKID_MAP("monotonic_raw", CLOCK_MONOTONIC_RAW), > - > - /* available for some events */ > - CLOCKID_MAP("realtime", CLOCK_REALTIME), > - CLOCKID_MAP("boottime", CLOCK_BOOTTIME), > - CLOCKID_MAP("tai", CLOCK_TAI), > - > - /* available for the lazy */ > - CLOCKID_MAP("mono", CLOCK_MONOTONIC), > - CLOCKID_MAP("raw", CLOCK_MONOTONIC_RAW), > - CLOCKID_MAP("real", CLOCK_REALTIME), > - CLOCKID_MAP("boot", CLOCK_BOOTTIME), > - > - CLOCKID_END, > -}; > - > -static int get_clockid_res(clockid_t clk_id, u64 *res_ns) > -{ > - struct timespec res; > - > - *res_ns = 0; > - if (!clock_getres(clk_id, &res)) > - *res_ns = res.tv_nsec + res.tv_sec * NSEC_PER_SEC; > - else > - pr_warning("WARNING: Failed to determine specified clock resolution.\n"); > - > - return 0; > -} > - > -static int parse_clockid(const struct option *opt, const char *str, int unset) > -{ > - struct record_opts *opts = (struct record_opts *)opt->value; > - const struct clockid_map *cm; > - const char *ostr = str; > - > - if (unset) { > - opts->use_clockid = 0; > - return 0; > - } > - > - /* no arg passed */ > - if (!str) > - return 0; > - > - /* no setting it twice */ > - if (opts->use_clockid) > - return -1; > - > - opts->use_clockid = true; > - > - /* if its a number, we're done */ > - if (sscanf(str, "%d", &opts->clockid) == 1) > - return get_clockid_res(opts->clockid, &opts->clockid_res_ns); > - > - /* allow a "CLOCK_" prefix to the name */ > - if (!strncasecmp(str, "CLOCK_", 6)) > - str += 6; > - > - for (cm = clockids; cm->name; cm++) { > - if (!strcasecmp(str, cm->name)) { > - opts->clockid = cm->clockid; > - return get_clockid_res(opts->clockid, > - &opts->clockid_res_ns); > - } > - } > - > - opts->use_clockid = false; > - ui__warning("unknown clockid %s, check man page\n", ostr); > - return -1; > -} > > static int record__parse_affinity(const struct option *opt, const char *str, int unset) > { > diff --git a/tools/perf/util/Build b/tools/perf/util/Build > index 380e6a9f564d..494626e303f5 100644 > --- a/tools/perf/util/Build > +++ b/tools/perf/util/Build > @@ -128,6 +128,7 @@ perf-y += expr-bison.o > perf-y += expr.o > perf-y += branch.o > perf-y += mem2node.o > +perf-y += clockid.o > > perf-$(CONFIG_LIBBPF) += bpf-loader.o > perf-$(CONFIG_LIBBPF) += bpf_map.o > diff --git a/tools/perf/util/clockid.c b/tools/perf/util/clockid.c > new file mode 100644 > index 000000000000..b7a08606dc3e > --- /dev/null > +++ b/tools/perf/util/clockid.c > @@ -0,0 +1,108 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > +#include > +#include > +#include > +#include "debug.h" > +#include "clockid.h" > +#include "record.h" > + > +struct clockid_map { > + const char *name; > + int clockid; > +}; > + > +#define CLOCKID_MAP(n, c) \ > + { .name = n, .clockid = (c), } > + > +#define CLOCKID_END { .name = NULL, } > + > + > +/* > + * Add the missing ones, we need to build on many distros... > + */ > +#ifndef CLOCK_MONOTONIC_RAW > +#define CLOCK_MONOTONIC_RAW 4 > +#endif > +#ifndef CLOCK_BOOTTIME > +#define CLOCK_BOOTTIME 7 > +#endif > +#ifndef CLOCK_TAI > +#define CLOCK_TAI 11 > +#endif > + > +static const struct clockid_map clockids[] = { > + /* available for all events, NMI safe */ > + CLOCKID_MAP("monotonic", CLOCK_MONOTONIC), > + CLOCKID_MAP("monotonic_raw", CLOCK_MONOTONIC_RAW), > + > + /* available for some events */ > + CLOCKID_MAP("realtime", CLOCK_REALTIME), > + CLOCKID_MAP("boottime", CLOCK_BOOTTIME), > + CLOCKID_MAP("tai", CLOCK_TAI), > + > + /* available for the lazy */ > + CLOCKID_MAP("mono", CLOCK_MONOTONIC), > + CLOCKID_MAP("raw", CLOCK_MONOTONIC_RAW), > + CLOCKID_MAP("real", CLOCK_REALTIME), > + CLOCKID_MAP("boot", CLOCK_BOOTTIME), > + > + CLOCKID_END, > +}; > + > +static int get_clockid_res(clockid_t clk_id, u64 *res_ns) > +{ > + struct timespec res; > + > + *res_ns = 0; > + if (!clock_getres(clk_id, &res)) > + *res_ns = res.tv_nsec + res.tv_sec * NSEC_PER_SEC; > + else > + pr_warning("WARNING: Failed to determine specified clock resolution.\n"); > + > + return 0; > +} > + > +int parse_clockid(const struct option *opt, const char *str, int unset) > +{ > + struct record_opts *opts = (struct record_opts *)opt->value; > + const struct clockid_map *cm; > + const char *ostr = str; > + > + if (unset) { > + opts->use_clockid = 0; > + return 0; > + } > + > + /* no arg passed */ > + if (!str) > + return 0; > + > + /* no setting it twice */ > + if (opts->use_clockid) > + return -1; > + > + opts->use_clockid = true; > + > + /* if its a number, we're done */ > + if (sscanf(str, "%d", &opts->clockid) == 1) > + return get_clockid_res(opts->clockid, &opts->clockid_res_ns); > + > + /* allow a "CLOCK_" prefix to the name */ > + if (!strncasecmp(str, "CLOCK_", 6)) > + str += 6; > + > + for (cm = clockids; cm->name; cm++) { > + if (!strcasecmp(str, cm->name)) { > + opts->clockid = cm->clockid; > + return get_clockid_res(opts->clockid, > + &opts->clockid_res_ns); > + } > + } > + > + opts->use_clockid = false; > + ui__warning("unknown clockid %s, check man page\n", ostr); > + return -1; > +} > diff --git a/tools/perf/util/clockid.h b/tools/perf/util/clockid.h > new file mode 100644 > index 000000000000..8e567b3ebbbd > --- /dev/null > +++ b/tools/perf/util/clockid.h > @@ -0,0 +1,9 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > + > +#ifndef __PERF_CLOCKID_H > +#define __PERF_CLOCKID_H > + > +struct option; > +int parse_clockid(const struct option *opt, const char *str, int unset); > + > +#endif > -- > 2.25.4 > -- - Arnaldo