From: Jiri Olsa <jolsa@redhat.com>
To: Ian Rogers <irogers@google.com>, Sohaib Mohamed <sohaib.amhmd@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 05/59] tools api fs: Move in the fncache from perf
Date: Mon, 8 Nov 2021 22:15:01 +0100 [thread overview]
Message-ID: <YYmTVRkRQXqN/MrT@krava> (raw)
In-Reply-To: <CAP-5=fWuAY=ML81CnujKGLu=-6PKqj6udt0sMzdr038T9Vaycw@mail.gmail.com>
On Mon, Nov 08, 2021 at 09:46:43AM -0800, Ian Rogers wrote:
> On Mon, Nov 8, 2021 at 5:37 AM Jiri Olsa <jolsa@redhat.com> wrote:
> >
> > Moving fncache from perf under libapi.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/lib/api/fs/Build | 1 +
> > tools/lib/api/fs/fncache.c | 63 ++++++++++++++++++++++++++++++
> > tools/lib/api/fs/fs.h | 2 +
> > tools/perf/arch/x86/util/pmu.c | 1 -
> > tools/perf/tests/parse-events.c | 1 -
> > tools/perf/util/Build | 1 -
> > tools/perf/util/fncache.c | 63 ------------------------------
> > tools/perf/util/fncache.h | 7 ----
>
> This change looks like it could be independent. Could this code be
> simplified to just using a hashmap now that we have one?
true, Sohaib, perhaps you might be interest in this?
jirka
>
> Thanks,
> Ian
>
> > tools/perf/util/pmu-hybrid.c | 1 -
> > tools/perf/util/pmu.c | 1 -
> > tools/perf/util/python-ext-sources | 1 -
> > tools/perf/util/srccode.c | 10 ++++-
> > 12 files changed, 75 insertions(+), 77 deletions(-)
> > create mode 100644 tools/lib/api/fs/fncache.c
> > delete mode 100644 tools/perf/util/fncache.c
> > delete mode 100644 tools/perf/util/fncache.h
> >
> > diff --git a/tools/lib/api/fs/Build b/tools/lib/api/fs/Build
> > index 0f75b28654de..3af4b5265a5f 100644
> > --- a/tools/lib/api/fs/Build
> > +++ b/tools/lib/api/fs/Build
> > @@ -1,3 +1,4 @@
> > libapi-y += fs.o
> > libapi-y += tracing_path.o
> > libapi-y += cgroup.o
> > +libapi-y += fncache.o
> > diff --git a/tools/lib/api/fs/fncache.c b/tools/lib/api/fs/fncache.c
> > new file mode 100644
> > index 000000000000..7fb4586c341a
> > --- /dev/null
> > +++ b/tools/lib/api/fs/fncache.c
> > @@ -0,0 +1,63 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/* Manage a cache of file names' existence */
> > +#include <stdlib.h>
> > +#include <unistd.h>
> > +#include <string.h>
> > +#include <linux/list.h>
> > +#include "fs.h"
> > +
> > +struct fncache {
> > + struct hlist_node nd;
> > + bool res;
> > + char name[];
> > +};
> > +
> > +#define FNHSIZE 61
> > +
> > +static struct hlist_head fncache_hash[FNHSIZE];
> > +
> > +static unsigned shash(const unsigned char *s)
> > +{
> > + unsigned h = 0;
> > + while (*s)
> > + h = 65599 * h + *s++;
> > + return h ^ (h >> 16);
> > +}
> > +
> > +static bool lookup_fncache(const char *name, bool *res)
> > +{
> > + int h = shash((const unsigned char *)name) % FNHSIZE;
> > + struct fncache *n;
> > +
> > + hlist_for_each_entry(n, &fncache_hash[h], nd) {
> > + if (!strcmp(n->name, name)) {
> > + *res = n->res;
> > + return true;
> > + }
> > + }
> > + return false;
> > +}
> > +
> > +static void update_fncache(const char *name, bool res)
> > +{
> > + struct fncache *n = malloc(sizeof(struct fncache) + strlen(name) + 1);
> > + int h = shash((const unsigned char *)name) % FNHSIZE;
> > +
> > + if (!n)
> > + return;
> > + strcpy(n->name, name);
> > + n->res = res;
> > + hlist_add_head(&n->nd, &fncache_hash[h]);
> > +}
> > +
> > +/* No LRU, only use when bounded in some other way. */
> > +bool file_available(const char *name)
> > +{
> > + bool res;
> > +
> > + if (lookup_fncache(name, &res))
> > + return res;
> > + res = access(name, R_OK) == 0;
> > + update_fncache(name, res);
> > + return res;
> > +}
> > diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
> > index aa222ca30311..c42d4ff30ca7 100644
> > --- a/tools/lib/api/fs/fs.h
> > +++ b/tools/lib/api/fs/fs.h
> > @@ -59,4 +59,6 @@ int sysfs__read_str(const char *entry, char **buf, size_t *sizep);
> > int sysfs__read_bool(const char *entry, bool *value);
> >
> > int sysfs__write_int(const char *entry, int value);
> > +
> > +bool file_available(const char *name);
> > #endif /* __API_FS__ */
> > diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c
> > index 74d69db1ea99..c875dded65bb 100644
> > --- a/tools/perf/arch/x86/util/pmu.c
> > +++ b/tools/perf/arch/x86/util/pmu.c
> > @@ -13,7 +13,6 @@
> > #include "../../../util/intel-pt.h"
> > #include "../../../util/intel-bts.h"
> > #include "../../../util/pmu.h"
> > -#include "../../../util/fncache.h"
> >
> > #define TEMPLATE_ALIAS "%s/bus/event_source/devices/%s/alias"
> >
> > diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
> > index 8875e388563e..69381fe1655d 100644
> > --- a/tools/perf/tests/parse-events.c
> > +++ b/tools/perf/tests/parse-events.c
> > @@ -9,7 +9,6 @@
> > #include "pmu-hybrid.h"
> > #include <dirent.h>
> > #include <errno.h>
> > -#include "fncache.h"
> > #include <sys/types.h>
> > #include <sys/stat.h>
> > #include <unistd.h>
> > diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> > index 03d5d6ed7fe4..b93828aacc27 100644
> > --- a/tools/perf/util/Build
> > +++ b/tools/perf/util/Build
> > @@ -52,7 +52,6 @@ perf-y += header.o
> > perf-y += callchain.o
> > perf-y += values.o
> > perf-y += debug.o
> > -perf-y += fncache.o
> > perf-y += machine.o
> > perf-y += map.o
> > perf-y += pstack.o
> > diff --git a/tools/perf/util/fncache.c b/tools/perf/util/fncache.c
> > deleted file mode 100644
> > index 6225cbc52310..000000000000
> > --- a/tools/perf/util/fncache.c
> > +++ /dev/null
> > @@ -1,63 +0,0 @@
> > -// SPDX-License-Identifier: GPL-2.0-only
> > -/* Manage a cache of file names' existence */
> > -#include <stdlib.h>
> > -#include <unistd.h>
> > -#include <string.h>
> > -#include <linux/list.h>
> > -#include "fncache.h"
> > -
> > -struct fncache {
> > - struct hlist_node nd;
> > - bool res;
> > - char name[];
> > -};
> > -
> > -#define FNHSIZE 61
> > -
> > -static struct hlist_head fncache_hash[FNHSIZE];
> > -
> > -unsigned shash(const unsigned char *s)
> > -{
> > - unsigned h = 0;
> > - while (*s)
> > - h = 65599 * h + *s++;
> > - return h ^ (h >> 16);
> > -}
> > -
> > -static bool lookup_fncache(const char *name, bool *res)
> > -{
> > - int h = shash((const unsigned char *)name) % FNHSIZE;
> > - struct fncache *n;
> > -
> > - hlist_for_each_entry(n, &fncache_hash[h], nd) {
> > - if (!strcmp(n->name, name)) {
> > - *res = n->res;
> > - return true;
> > - }
> > - }
> > - return false;
> > -}
> > -
> > -static void update_fncache(const char *name, bool res)
> > -{
> > - struct fncache *n = malloc(sizeof(struct fncache) + strlen(name) + 1);
> > - int h = shash((const unsigned char *)name) % FNHSIZE;
> > -
> > - if (!n)
> > - return;
> > - strcpy(n->name, name);
> > - n->res = res;
> > - hlist_add_head(&n->nd, &fncache_hash[h]);
> > -}
> > -
> > -/* No LRU, only use when bounded in some other way. */
> > -bool file_available(const char *name)
> > -{
> > - bool res;
> > -
> > - if (lookup_fncache(name, &res))
> > - return res;
> > - res = access(name, R_OK) == 0;
> > - update_fncache(name, res);
> > - return res;
> > -}
> > diff --git a/tools/perf/util/fncache.h b/tools/perf/util/fncache.h
> > deleted file mode 100644
> > index fe020beaefb1..000000000000
> > --- a/tools/perf/util/fncache.h
> > +++ /dev/null
> > @@ -1,7 +0,0 @@
> > -#ifndef _FCACHE_H
> > -#define _FCACHE_H 1
> > -
> > -unsigned shash(const unsigned char *s);
> > -bool file_available(const char *name);
> > -
> > -#endif
> > diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c
> > index f51ccaac60ee..65fdce81a384 100644
> > --- a/tools/perf/util/pmu-hybrid.c
> > +++ b/tools/perf/util/pmu-hybrid.c
> > @@ -13,7 +13,6 @@
> > #include <stdarg.h>
> > #include <locale.h>
> > #include <api/fs/fs.h>
> > -#include "fncache.h"
> > #include "pmu-hybrid.h"
> >
> > LIST_HEAD(perf_pmu__hybrid_pmus);
> > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> > index 55d834160428..13e1835955e0 100644
> > --- a/tools/perf/util/pmu.c
> > +++ b/tools/perf/util/pmu.c
> > @@ -26,7 +26,6 @@
> > #include "header.h"
> > #include "string2.h"
> > #include "strbuf.h"
> > -#include "fncache.h"
> > #include "pmu-hybrid.h"
> >
> > struct perf_pmu perf_pmu__fake;
> > diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
> > index a685d20165f7..992a76c2af01 100644
> > --- a/tools/perf/util/python-ext-sources
> > +++ b/tools/perf/util/python-ext-sources
> > @@ -39,4 +39,3 @@ util/affinity.c
> > util/rwsem.c
> > util/hashmap.c
> > util/pmu-hybrid.c
> > -util/fncache.c
> > diff --git a/tools/perf/util/srccode.c b/tools/perf/util/srccode.c
> > index 476e99896d5e..5c1ff87eb98c 100644
> > --- a/tools/perf/util/srccode.c
> > +++ b/tools/perf/util/srccode.c
> > @@ -16,7 +16,7 @@
> > #include "srccode.h"
> > #include "debug.h"
> > #include <internal/lib.h> // page_size
> > -#include "fncache.h"
> > +#include <api/fs/fs.h>
> >
> > #define MAXSRCCACHE (32*1024*1024)
> > #define MAXSRCFILES 64
> > @@ -86,6 +86,14 @@ static void free_srcfile(struct srcfile *sf)
> > num_srcfiles--;
> > }
> >
> > +static unsigned shash(const unsigned char *s)
> > +{
> > + unsigned h = 0;
> > + while (*s)
> > + h = 65599 * h + *s++;
> > + return h ^ (h >> 16);
> > +}
> > +
> > static struct srcfile *find_srcfile(char *fn)
> > {
> > struct stat st;
> > --
> > 2.31.1
> >
>
next prev parent reply other threads:[~2021-11-08 21:15 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-08 13:36 [RFC 00/59] libperf: Move in event parse code Jiri Olsa
2021-11-08 13:36 ` [PATCH 01/59] libperf: Move pmu-events.h file to libperf Jiri Olsa
2021-11-08 13:36 ` [PATCH 03/59] libperf: Move pmu-events build " Jiri Olsa
2021-11-08 13:36 ` [PATCH 04/59] libperf: Move perf_pmu__format_parse " Jiri Olsa
2021-11-08 13:36 ` [PATCH 05/59] tools api fs: Move in the fncache from perf Jiri Olsa
2021-11-08 17:46 ` Ian Rogers
2021-11-08 21:15 ` Jiri Olsa [this message]
2021-11-08 13:36 ` [PATCH 06/59] libperf: Move in the pmu hybrid support Jiri Olsa
2021-11-08 13:36 ` [PATCH 07/59] libperf: Move name to perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 08/59] libperf: Move auto_merge_stats " Jiri Olsa
2021-11-08 13:36 ` [PATCH 09/59] libperf: Move config_terms " Jiri Olsa
2021-11-08 13:36 ` [PATCH 10/59] libperf: Move metric_id " Jiri Olsa
2021-11-08 13:36 ` [PATCH 11/59] libperf: Move tool_event " Jiri Olsa
2021-11-08 13:36 ` [PATCH 12/59] libperf: Move unit " Jiri Olsa
2021-11-08 13:36 ` [PATCH 13/59] libperf: Move exclude_GH " Jiri Olsa
2021-11-08 17:53 ` Ian Rogers
2021-11-08 21:16 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 14/59] libperf: Move sample_read " Jiri Olsa
2021-11-08 13:36 ` [PATCH 15/59] libperf: Move precise_max " Jiri Olsa
2021-11-08 13:36 ` [PATCH 16/59] libperf: Move weak_group " Jiri Olsa
2021-11-08 13:36 ` [PATCH 17/59] libperf: Move bpf_counter " Jiri Olsa
2021-11-08 13:36 ` [PATCH 18/59] libperf: Move group_name " Jiri Olsa
2021-11-08 17:58 ` Ian Rogers
2021-11-08 18:07 ` Arnaldo Carvalho de Melo
2021-11-08 21:19 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 19/59] perf tools: Fix parse_events_term__num call Jiri Olsa
2021-11-08 18:15 ` Ian Rogers
2021-11-08 21:21 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 20/59] perf tools: Pass parse_state all the way down to __add_event Jiri Olsa
2021-11-08 13:36 ` [PATCH 21/59] perf tools: Pass parse_state all the way down to add_tracepoint Jiri Olsa
2021-11-08 13:36 ` [PATCH 22/59] perf tools: Add evsel__new callback to parse_state_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 23/59] perf tools: Add evsel__new_tp " Jiri Olsa
2021-11-08 13:36 ` [PATCH 24/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__str Jiri Olsa
2021-11-08 13:36 ` [PATCH 25/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__num Jiri Olsa
2021-11-08 13:36 ` [PATCH 26/59] libperf: Move in the event_symbols_hw/event_symbols_sw Jiri Olsa
2021-11-08 13:36 ` [PATCH 27/59] libperf: Move in struct parse_events_term code Jiri Olsa
2021-11-08 13:36 ` [PATCH 28/59] perf tools: Add perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 29/59] perf tools: Change struct parse_events_state::evlist to perf_evlist Jiri Olsa
2021-11-08 13:36 ` [PATCH 30/59] libperf: Move in struct parse_events_state Jiri Olsa
2021-11-08 18:21 ` Ian Rogers
2021-11-08 21:24 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 31/59] perf tools: Move event_attr_init in evsel__new_idx function Jiri Olsa
2021-11-08 13:36 ` [PATCH 32/59] libperf: Move in perf_pmu__warn_invalid_config function Jiri Olsa
2021-11-08 13:36 ` [PATCH 33/59] libperf: Move in perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 34/59] perf tools: Move parse_events_update_lists to parser unit Jiri Olsa
2021-11-08 13:36 ` [PATCH 35/59] libperf: Add perf_evsel__is_group_leader function Jiri Olsa
2021-11-08 13:36 ` [PATCH 36/59] perf tools: Make parse_events__modifier_event work over perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 37/59] perf tool: Pass perf_guest in struct parse_events_state Jiri Olsa
2021-11-08 13:36 ` [PATCH 38/59] libperf: Move in parse_events__modifier_group/event functions Jiri Olsa
2021-11-08 13:36 ` [PATCH 39/59] libperf: Move in parse_events__handle_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 40/59] libperf: Move in parse_events_evlist_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 41/59] perf tools: Add perf_evsel__delete callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 42/59] libperf: Move in parse_events_name function Jiri Olsa
2021-11-08 18:23 ` Ian Rogers
2021-11-08 21:24 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 43/59] perf tools: Move out parse_events_add_pmu fallback from parser code Jiri Olsa
2021-11-08 13:36 ` [PATCH 44/59] perf tools: Add add_pmu callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 45/59] perf tools: Add add_pmu_multi " Jiri Olsa
2021-11-08 13:36 ` [PATCH 46/59] perf tools: Add add_numeric " Jiri Olsa
2021-11-08 18:27 ` Ian Rogers
2021-11-08 21:34 ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 47/59] perf tools: Add add_cache " Jiri Olsa
2021-11-08 13:36 ` [PATCH 48/59] perf tools: Add add_breakpoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 49/59] perf tools: Add add_tracepoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 50/59] perf tools: Add add_bpf " Jiri Olsa
2021-11-08 13:37 ` [PATCH 51/59] perf tools: Add add_tool " Jiri Olsa
2021-11-08 13:37 ` [PATCH 52/59] perf tools: Add set_leader " Jiri Olsa
2021-11-08 13:37 ` [PATCH 53/59] perf tools: Add parse_check " Jiri Olsa
2021-11-08 13:37 ` [PATCH 54/59] perf tools: Move PE_* enums in parse_events__scanner Jiri Olsa
2021-11-08 13:37 ` [PATCH 55/59] libperf: Move in parse-events flex/bison parser Jiri Olsa
2021-11-08 13:37 ` [PATCH 56/59] libperf: Move in parse_events_add_breakpoint function Jiri Olsa
2021-11-08 13:37 ` [PATCH 57/59] libperf: Move in some lib objects from perf Jiri Olsa
2021-11-08 13:37 ` [PATCH 58/59] libperf: Add libperf_parse_events function Jiri Olsa
2021-11-08 13:37 ` [PATCH 59/59] libperf: Add parse-events test Jiri Olsa
2021-11-08 18:32 ` Ian Rogers
2021-11-08 21:37 ` Jiri Olsa
2021-11-08 18:50 ` [RFC 00/59] libperf: Move in event parse code Ian Rogers
2021-11-08 21:50 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YYmTVRkRQXqN/MrT@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=sohaib.amhmd@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox