Skip to content

Commit 1250090

Browse files
committed
perf cacheline: Move cacheline related routines to separate files
To disentangle util/sort.h a bit more. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-6kbf2cauas06rbqp15pyter5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent aeb00b1 commit 1250090

8 files changed

Lines changed: 50 additions & 33 deletions

File tree

‎tools/perf/builtin-c2c.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "hist.h"
2727
#include "sort.h"
2828
#include "tool.h"
29+
#include "cacheline.h"
2930
#include "data.h"
3031
#include "event.h"
3132
#include "evlist.h"

‎tools/perf/util/Build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
perf-y += annotate.o
22
perf-y += block-range.o
33
perf-y += build-id.o
4+
perf-y += cacheline.o
45
perf-y += config.o
56
perf-y += ctype.o
67
perf-y += db-export.o

‎tools/perf/util/cacheline.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include "cacheline.h"
3+
#include "../perf.h"
4+
#include <unistd.h>
5+
6+
#ifdef _SC_LEVEL1_DCACHE_LINESIZE
7+
#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
8+
#else
9+
#include <api/fs/fs.h>
10+
#include "debug.h"
11+
static void cache_line_size(int *cacheline_sizep)
12+
{
13+
if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
14+
pr_debug("cannot determine cache line size");
15+
}
16+
#endif
17+
18+
int cacheline_size(void)
19+
{
20+
static int size;
21+
22+
if (!size)
23+
cache_line_size(&size);
24+
25+
return size;
26+
}

‎tools/perf/util/cacheline.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef PERF_CACHELINE_H
3+
#define PERF_CACHELINE_H
4+
5+
#include <linux/compiler.h>
6+
7+
int __pure cacheline_size(void);
8+
9+
static inline u64 cl_address(u64 address)
10+
{
11+
/* return the cacheline of the address */
12+
return (address & ~(cacheline_size() - 1));
13+
}
14+
15+
static inline u64 cl_offset(u64 address)
16+
{
17+
/* return the cacheline of the address */
18+
return (address & (cacheline_size() - 1));
19+
}
20+
21+
#endif // PERF_CACHELINE_H

‎tools/perf/util/sort.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/time64.h>
77
#include "sort.h"
88
#include "hist.h"
9+
#include "cacheline.h"
910
#include "comm.h"
1011
#include "map.h"
1112
#include "symbol.h"

‎tools/perf/util/sort.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,6 @@ static inline float hist_entry__get_percent_limit(struct hist_entry *he)
204204
return period * 100.0 / total_period;
205205
}
206206

207-
static inline u64 cl_address(u64 address)
208-
{
209-
/* return the cacheline of the address */
210-
return (address & ~(cacheline_size() - 1));
211-
}
212-
213-
static inline u64 cl_offset(u64 address)
214-
{
215-
/* return the cacheline of the address */
216-
return (address & (cacheline_size() - 1));
217-
}
218-
219207
enum sort_mode {
220208
SORT_MODE__NORMAL,
221209
SORT_MODE__BRANCH,

‎tools/perf/util/util.c‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ void perf_set_multithreaded(void)
4343

4444
unsigned int page_size;
4545

46-
#ifdef _SC_LEVEL1_DCACHE_LINESIZE
47-
#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
48-
#else
49-
static void cache_line_size(int *cacheline_sizep)
50-
{
51-
if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
52-
pr_debug("cannot determine cache line size");
53-
}
54-
#endif
55-
56-
int cacheline_size(void)
57-
{
58-
static int size;
59-
60-
if (!size)
61-
cache_line_size(&size);
62-
63-
return size;
64-
}
65-
6646
int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH;
6747
int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK;
6848

‎tools/perf/util/util.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
3434
size_t hex_width(u64 v);
3535

3636
extern unsigned int page_size;
37-
int __pure cacheline_size(void);
3837

3938
int sysctl__max_stack(void);
4039

0 commit comments

Comments
 (0)