Skip to content

Commit fc0a0ea

Browse files
carstenhaitzleracmel
authored andcommitted
perf test coresight: Add unroll thread test tool
Add test tool to be driven by further test scripts. This is a simple C based test that is for arm64 with some inline ASM to manually unroll a lot of code to have a very long sequence of commands. Reviewed-by: James Clark <[email protected]> Signed-off-by: Carsten Haitzler <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: Mike Leach <[email protected]> Cc: Suzuki Poulouse <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 74c62b8 commit fc0a0ea

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

tools/perf/tests/shell/coresight/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ include ../../../../../tools/scripts/utilities.mak
77
SUBDIRS = \
88
asm_pure_loop \
99
memcpy_thread \
10-
thread_loop
10+
thread_loop \
11+
unroll_loop_thread
1112

1213
all: $(SUBDIRS)
1314
$(SUBDIRS):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unroll_loop_thread
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Carsten Haitzler <[email protected]>, 2021
3+
include ../Makefile.miniconfig
4+
5+
# Binary to produce
6+
BIN=unroll_loop_thread
7+
# Any linking/libraries needed for the binary - empty if none needed
8+
LIB=-pthread
9+
10+
all: $(BIN)
11+
12+
$(BIN): $(BIN).c
13+
ifdef CORESIGHT
14+
ifeq ($(ARCH),arm64)
15+
# Build line
16+
$(Q)$(CC) $(BIN).c -o $(BIN) $(LIB)
17+
endif
18+
endif
19+
20+
install-tests: all
21+
ifdef CORESIGHT
22+
ifeq ($(ARCH),arm64)
23+
# Install the test tool in the right place
24+
$(call QUIET_INSTALL, tests) \
25+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$(INSTDIR_SUB)/$(BIN)'; \
26+
$(INSTALL) $(BIN) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$(INSTDIR_SUB)/$(BIN)/$(BIN)'
27+
endif
28+
endif
29+
30+
clean:
31+
$(Q)$(RM) -f $(BIN)
32+
33+
.PHONY: all clean install-tests
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Carsten Haitzler <[email protected]>, 2021
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <unistd.h>
6+
#include <string.h>
7+
#include <pthread.h>
8+
9+
struct args {
10+
pthread_t th;
11+
unsigned int in;
12+
void *ret;
13+
};
14+
15+
static void *thrfn(void *arg)
16+
{
17+
struct args *a = arg;
18+
unsigned int i, in = a->in;
19+
20+
for (i = 0; i < 10000; i++) {
21+
asm volatile (
22+
// force an unroll of thia add instruction so we can test long runs of code
23+
#define SNIP1 "add %[in], %[in], #1\n"
24+
// 10
25+
#define SNIP2 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1
26+
// 100
27+
#define SNIP3 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2 SNIP2
28+
// 1000
29+
#define SNIP4 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3 SNIP3
30+
// 10000
31+
#define SNIP5 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4 SNIP4
32+
// 100000
33+
SNIP5 SNIP5 SNIP5 SNIP5 SNIP5 SNIP5 SNIP5 SNIP5 SNIP5 SNIP5
34+
: /* out */
35+
: /* in */ [in] "r" (in)
36+
: /* clobber */
37+
);
38+
}
39+
}
40+
41+
static pthread_t new_thr(void *(*fn) (void *arg), void *arg)
42+
{
43+
pthread_t t;
44+
pthread_attr_t attr;
45+
46+
pthread_attr_init(&attr);
47+
pthread_create(&t, &attr, fn, arg);
48+
return t;
49+
}
50+
51+
int main(int argc, char **argv)
52+
{
53+
unsigned int i, thr;
54+
pthread_t threads[256];
55+
struct args args[256];
56+
57+
if (argc < 2) {
58+
printf("ERR: %s [numthreads]\n", argv[0]);
59+
exit(1);
60+
}
61+
62+
thr = atoi(argv[1]);
63+
if ((thr > 256) || (thr < 1)) {
64+
printf("ERR: threads 1-256\n");
65+
exit(1);
66+
}
67+
for (i = 0; i < thr; i++) {
68+
args[i].in = rand();
69+
args[i].th = new_thr(thrfn, &(args[i]));
70+
}
71+
for (i = 0; i < thr; i++)
72+
pthread_join(args[i].th, &(args[i].ret));
73+
return 0;
74+
}

0 commit comments

Comments
 (0)