Skip to content

Commit e9664b9

Browse files
carstenhaitzleracmel
authored andcommitted
perf test coresight: Add thread loop test tool
Add test tool to be driven by further test scripts. This is a simple C based loop with threads test to drive from scripts that can output TIDs for tracking/checking. 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 b76692f commit e9664b9

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

tools/perf/tests/shell/coresight/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ include ../../../../../tools/scripts/utilities.mak
66

77
SUBDIRS = \
88
asm_pure_loop \
9-
memcpy_thread
9+
memcpy_thread \
10+
thread_loop
1011

1112
all: $(SUBDIRS)
1213
$(SUBDIRS):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
thread_loop
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=thread_loop
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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Carsten Haitzler <[email protected]>, 2021
3+
4+
// define this for gettid()
5+
#define _GNU_SOURCE
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <unistd.h>
10+
#include <string.h>
11+
#include <pthread.h>
12+
#include <sys/syscall.h>
13+
#ifndef SYS_gettid
14+
// gettid is 178 on arm64
15+
# define SYS_gettid 178
16+
#endif
17+
#define gettid() syscall(SYS_gettid)
18+
19+
struct args {
20+
unsigned int loops;
21+
pthread_t th;
22+
void *ret;
23+
};
24+
25+
static void *thrfn(void *arg)
26+
{
27+
struct args *a = arg;
28+
int i = 0, len = a->loops;
29+
30+
if (getenv("SHOW_TID")) {
31+
unsigned long long tid = gettid();
32+
33+
printf("%llu\n", tid);
34+
}
35+
asm volatile(
36+
"loop:\n"
37+
"add %[i], %[i], #1\n"
38+
"cmp %[i], %[len]\n"
39+
"blt loop\n"
40+
: /* out */
41+
: /* in */ [i] "r" (i), [len] "r" (len)
42+
: /* clobber */
43+
);
44+
return (void *)(long)i;
45+
}
46+
47+
static pthread_t new_thr(void *(*fn) (void *arg), void *arg)
48+
{
49+
pthread_t t;
50+
pthread_attr_t attr;
51+
52+
pthread_attr_init(&attr);
53+
pthread_create(&t, &attr, fn, arg);
54+
return t;
55+
}
56+
57+
int main(int argc, char **argv)
58+
{
59+
unsigned int i, len, thr;
60+
pthread_t threads[256];
61+
struct args args[256];
62+
63+
if (argc < 3) {
64+
printf("ERR: %s [numthreads] [numloops (millions)]\n", argv[0]);
65+
exit(1);
66+
}
67+
68+
thr = atoi(argv[1]);
69+
if ((thr < 1) || (thr > 256)) {
70+
printf("ERR: threads 1-256\n");
71+
exit(1);
72+
}
73+
len = atoi(argv[2]);
74+
if ((len < 1) || (len > 4000)) {
75+
printf("ERR: max loops 4000 (millions)\n");
76+
exit(1);
77+
}
78+
len *= 1000000;
79+
for (i = 0; i < thr; i++) {
80+
args[i].loops = len;
81+
args[i].th = new_thr(thrfn, &(args[i]));
82+
}
83+
for (i = 0; i < thr; i++)
84+
pthread_join(args[i].th, &(args[i].ret));
85+
return 0;
86+
}

0 commit comments

Comments
 (0)