From: Jiri Olsa <jolsa@kernel.org> Date: Sun, 21 Jul 2019 11:24:44 +0000 (+0200) Subject: libperf: Adopt xyarray class from perf X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4b247fa7314ce48282f3da400a9ffb7f3fd3f863;p=linux.git libperf: Adopt xyarray class from perf Move the xyarray class from perf to libperf, because it's going to be used in both. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20190721112506.12306-58-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index c69ddc67c6723..1a4615a5f6c9d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -38,7 +38,6 @@ #include <subcmd/parse-options.h> #include "util/parse-events.h" #include "util/cpumap.h" -#include "util/xyarray.h" #include "util/sort.h" #include "util/string2.h" #include "util/term.h" diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build index faf64db13e377..4f78ec0b4e100 100644 --- a/tools/perf/lib/Build +++ b/tools/perf/lib/Build @@ -4,6 +4,7 @@ libperf-y += threadmap.o libperf-y += evsel.o libperf-y += evlist.o libperf-y += zalloc.o +libperf-y += xyarray.o $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE $(call rule_mkdir) diff --git a/tools/perf/lib/include/internal/xyarray.h b/tools/perf/lib/include/internal/xyarray.h new file mode 100644 index 0000000000000..3bf70e4d474c6 --- /dev/null +++ b/tools/perf/lib/include/internal/xyarray.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBPERF_INTERNAL_XYARRAY_H +#define __LIBPERF_INTERNAL_XYARRAY_H + +#include <sys/types.h> + +struct xyarray { + size_t row_size; + size_t entry_size; + size_t entries; + size_t max_x; + size_t max_y; + char contents[]; +}; + +struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size); +void xyarray__delete(struct xyarray *xy); +void xyarray__reset(struct xyarray *xy); + +static inline void *xyarray__entry(struct xyarray *xy, int x, int y) +{ + return &xy->contents[x * xy->row_size + y * xy->entry_size]; +} + +static inline int xyarray__max_y(struct xyarray *xy) +{ + return xy->max_y; +} + +static inline int xyarray__max_x(struct xyarray *xy) +{ + return xy->max_x; +} + +#endif /* __LIBPERF_INTERNAL_XYARRAY_H */ diff --git a/tools/perf/lib/xyarray.c b/tools/perf/lib/xyarray.c new file mode 100644 index 0000000000000..dcd901d154bb6 --- /dev/null +++ b/tools/perf/lib/xyarray.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <internal/xyarray.h> +#include <linux/zalloc.h> +#include <stdlib.h> +#include <string.h> + +struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) +{ + size_t row_size = ylen * entry_size; + struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); + + if (xy != NULL) { + xy->entry_size = entry_size; + xy->row_size = row_size; + xy->entries = xlen * ylen; + xy->max_x = xlen; + xy->max_y = ylen; + } + + return xy; +} + +void xyarray__reset(struct xyarray *xy) +{ + size_t n = xy->entries * xy->entry_size; + + memset(xy->contents, 0, n); +} + +void xyarray__delete(struct xyarray *xy) +{ + free(xy); +} diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 08f670d216153..7abf051318890 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -69,7 +69,6 @@ perf-y += svghelper.o perf-y += sort.o perf-y += hist.o perf-y += util.o -perf-y += xyarray.o perf-y += cpumap.o perf-y += cputopo.o perf-y += cgroup.o diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index 0f0cb2d8f70d3..bbfac9ecf6428 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -2,7 +2,7 @@ #ifndef __PERF_COUNTS_H #define __PERF_COUNTS_H -#include "xyarray.h" +#include <internal/xyarray.h> struct perf_counts_values { union { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 57b5523b480c6..1f9f66fe43f40 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -8,7 +8,7 @@ #include <linux/perf_event.h> #include <linux/types.h> #include <internal/evsel.h> -#include "xyarray.h" +#include <internal/xyarray.h> #include "symbol_conf.h" #include "cpumap.h" #include "counts.h" diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 2237bac9fadbb..235bd98033903 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -20,7 +20,6 @@ util/namespaces.c ../lib/vsprintf.c util/thread_map.c util/util.c -util/xyarray.c util/cgroup.c util/parse-branch-options.c util/rblist.c diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 95b4de7a9d51c..bcb376e1b3a7f 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -8,7 +8,6 @@ #include <sys/time.h> #include <sys/resource.h> #include <sys/wait.h> -#include "xyarray.h" #include "rblist.h" #include "perf.h" #include "event.h" diff --git a/tools/perf/util/xyarray.h b/tools/perf/util/xyarray.h deleted file mode 100644 index 7ffe562e7ae7f..0000000000000 --- a/tools/perf/util/xyarray.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _PERF_XYARRAY_H_ -#define _PERF_XYARRAY_H_ 1 - -#include <sys/types.h> - -struct xyarray { - size_t row_size; - size_t entry_size; - size_t entries; - size_t max_x; - size_t max_y; - char contents[]; -}; - -struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size); -void xyarray__delete(struct xyarray *xy); -void xyarray__reset(struct xyarray *xy); - -static inline void *xyarray__entry(struct xyarray *xy, int x, int y) -{ - return &xy->contents[x * xy->row_size + y * xy->entry_size]; -} - -static inline int xyarray__max_y(struct xyarray *xy) -{ - return xy->max_y; -} - -static inline int xyarray__max_x(struct xyarray *xy) -{ - return xy->max_x; -} - -#endif /* _PERF_XYARRAY_H_ */