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>
This commit is contained in:

committed by
Arnaldo Carvalho de Melo

parent
453fa03090
commit
4b247fa731
@@ -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)
|
||||
|
35
tools/perf/lib/include/internal/xyarray.h
Normal file
35
tools/perf/lib/include/internal/xyarray.h
Normal file
@@ -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 */
|
33
tools/perf/lib/xyarray.c
Normal file
33
tools/perf/lib/xyarray.c
Normal file
@@ -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);
|
||||
}
|
Reference in New Issue
Block a user