Skip to content

Commit ad3003a

Browse files
captain5050acmel
authored andcommitted
perf mem-info: Move mem-info out of mem-events and symbol
Move mem-info to its own header rather than having it split between mem-events and symbol. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Ben Gainey <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: K Prateek Nayak <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Li Dong <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Paran Lee <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sun Haiyong <[email protected]> Cc: Tim Chen <[email protected]> Cc: Yanteng Si <[email protected]> Cc: Yicong Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 13ca628 commit ad3003a

File tree

15 files changed

+85
-63
lines changed

15 files changed

+85
-63
lines changed

tools/perf/builtin-c2c.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "ui/browsers/hists.h"
3939
#include "thread.h"
4040
#include "mem2node.h"
41+
#include "mem-info.h"
4142
#include "symbol.h"
4243
#include "ui/ui.h"
4344
#include "ui/progress.h"

tools/perf/builtin-report.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "util/evsel.h"
3232
#include "util/evswitch.h"
3333
#include "util/header.h"
34+
#include "util/mem-info.h"
3435
#include "util/session.h"
3536
#include "util/srcline.h"
3637
#include "util/tool.h"

tools/perf/builtin-script.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "util/time-utils.h"
3333
#include "util/path.h"
3434
#include "util/event.h"
35+
#include "util/mem-info.h"
3536
#include "ui/ui.h"
3637
#include "print_binary.h"
3738
#include "print_insn.h"

tools/perf/tests/mem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include "util/map_symbol.h"
33
#include "util/mem-events.h"
4+
#include "util/mem-info.h"
45
#include "util/symbol.h"
56
#include "linux/perf_event.h"
67
#include "util/debug.h"

tools/perf/util/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ perf-y += term.o
141141
perf-y += help-unknown-cmd.o
142142
perf-y += dlfilter.o
143143
perf-y += mem-events.o
144+
perf-y += mem-info.o
144145
perf-y += vsprintf.o
145146
perf-y += units.o
146147
perf-y += time-utils.o

tools/perf/util/hist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "map_symbol.h"
1010
#include "branch.h"
1111
#include "mem-events.h"
12+
#include "mem-info.h"
1213
#include "session.h"
1314
#include "namespaces.h"
1415
#include "cgroup.h"

tools/perf/util/machine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "map_symbol.h"
1717
#include "branch.h"
1818
#include "mem-events.h"
19+
#include "mem-info.h"
1920
#include "path.h"
2021
#include "srcline.h"
2122
#include "symbol.h"

tools/perf/util/mem-events.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <linux/kernel.h>
1111
#include "map_symbol.h"
1212
#include "mem-events.h"
13+
#include "mem-info.h"
1314
#include "debug.h"
15+
#include "evsel.h"
1416
#include "symbol.h"
1517
#include "pmu.h"
1618
#include "pmus.h"
@@ -281,7 +283,7 @@ static const char * const tlb_access[] = {
281283
"Fault",
282284
};
283285

284-
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
286+
int perf_mem__tlb_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
285287
{
286288
size_t l = 0, i;
287289
u64 m = PERF_MEM_TLB_NA;
@@ -359,7 +361,7 @@ static const char * const mem_hops[] = {
359361
"board",
360362
};
361363

362-
static int perf_mem__op_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
364+
static int perf_mem__op_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
363365
{
364366
u64 op = PERF_MEM_LOCK_NA;
365367
int l;
@@ -383,7 +385,7 @@ static int perf_mem__op_scnprintf(char *out, size_t sz, struct mem_info *mem_inf
383385
return l;
384386
}
385387

386-
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
388+
int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
387389
{
388390
union perf_mem_data_src data_src;
389391
int printed = 0;
@@ -465,7 +467,7 @@ static const char * const snoopx_access[] = {
465467
"Peer",
466468
};
467469

468-
int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
470+
int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
469471
{
470472
size_t i, l = 0;
471473
u64 m = PERF_MEM_SNOOP_NA;
@@ -507,7 +509,7 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
507509
return l;
508510
}
509511

510-
int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
512+
int perf_mem__lck_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
511513
{
512514
u64 mask = PERF_MEM_LOCK_NA;
513515
int l;
@@ -525,7 +527,7 @@ int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
525527
return l;
526528
}
527529

528-
int perf_mem__blk_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
530+
int perf_mem__blk_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
529531
{
530532
size_t l = 0;
531533
u64 mask = PERF_MEM_BLK_NA;
@@ -548,7 +550,7 @@ int perf_mem__blk_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
548550
return l;
549551
}
550552

551-
int perf_script__meminfo_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
553+
int perf_script__meminfo_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
552554
{
553555
int i = 0;
554556

tools/perf/util/mem-events.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
#define __PERF_MEM_EVENTS_H
44

55
#include <stdbool.h>
6-
#include <stdint.h>
7-
#include <stdio.h>
86
#include <linux/types.h>
9-
#include <linux/refcount.h>
10-
#include <linux/perf_event.h>
11-
#include "stat.h"
12-
#include "evsel.h"
137

148
struct perf_mem_event {
159
bool record;
@@ -21,20 +15,17 @@ struct perf_mem_event {
2115
const char *event_name;
2216
};
2317

24-
struct mem_info {
25-
struct addr_map_symbol iaddr;
26-
struct addr_map_symbol daddr;
27-
union perf_mem_data_src data_src;
28-
refcount_t refcnt;
29-
};
30-
3118
enum {
3219
PERF_MEM_EVENTS__LOAD,
3320
PERF_MEM_EVENTS__STORE,
3421
PERF_MEM_EVENTS__LOAD_STORE,
3522
PERF_MEM_EVENTS__MAX,
3623
};
3724

25+
struct evsel;
26+
struct mem_info;
27+
struct perf_pmu;
28+
3829
extern unsigned int perf_mem_events__loads_ldlat;
3930
extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
4031

@@ -49,13 +40,13 @@ bool is_mem_loads_aux_event(struct evsel *leader);
4940
void perf_pmu__mem_events_list(struct perf_pmu *pmu);
5041
int perf_mem_events__record_args(const char **rec_argv, int *argv_nr);
5142

52-
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
53-
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
54-
int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
55-
int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
56-
int perf_mem__blk_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
43+
int perf_mem__tlb_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
44+
int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
45+
int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
46+
int perf_mem__lck_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
47+
int perf_mem__blk_scnprintf(char *out, size_t sz, const struct mem_info *mem_info);
5748

58-
int perf_script__meminfo_scnprintf(char *bf, size_t size, struct mem_info *mem_info);
49+
int perf_script__meminfo_scnprintf(char *bf, size_t size, const struct mem_info *mem_info);
5950

6051
struct c2c_stats {
6152
u32 nr_entries;

tools/perf/util/mem-info.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/zalloc.h>
3+
#include "mem-info.h"
4+
5+
struct mem_info *mem_info__get(struct mem_info *mi)
6+
{
7+
if (mi)
8+
refcount_inc(&mi->refcnt);
9+
return mi;
10+
}
11+
12+
void mem_info__put(struct mem_info *mi)
13+
{
14+
if (mi && refcount_dec_and_test(&mi->refcnt)) {
15+
addr_map_symbol__exit(&mi->iaddr);
16+
addr_map_symbol__exit(&mi->daddr);
17+
free(mi);
18+
}
19+
}
20+
21+
struct mem_info *mem_info__new(void)
22+
{
23+
struct mem_info *mi = zalloc(sizeof(*mi));
24+
25+
if (mi)
26+
refcount_set(&mi->refcnt, 1);
27+
return mi;
28+
}

0 commit comments

Comments
 (0)