Skip to content

Commit f1288bd

Browse files
carstenhaitzleracmel
authored andcommitted
perf test coresight: Add memcpy thread test tool
Add test tool to be driven by further test scripts. This is a simple C based memcpy with threads test to drive from scripts. 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 6ea586b commit f1288bd

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

tools/perf/tests/shell/coresight/Makefile

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

77
SUBDIRS = \
8-
asm_pure_loop
8+
asm_pure_loop \
9+
memcpy_thread
910

1011
all: $(SUBDIRS)
1112
$(SUBDIRS):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
memcpy_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=memcpy_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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
unsigned long loops;
11+
unsigned long size;
12+
pthread_t th;
13+
void *ret;
14+
};
15+
16+
static void *thrfn(void *arg)
17+
{
18+
struct args *a = arg;
19+
unsigned long i, len = a->loops;
20+
unsigned char *src, *dst;
21+
22+
src = malloc(a->size * 1024);
23+
dst = malloc(a->size * 1024);
24+
if ((!src) || (!dst)) {
25+
printf("ERR: Can't allocate memory\n");
26+
exit(1);
27+
}
28+
for (i = 0; i < len; i++)
29+
memcpy(dst, src, a->size * 1024);
30+
}
31+
32+
static pthread_t new_thr(void *(*fn) (void *arg), void *arg)
33+
{
34+
pthread_t t;
35+
pthread_attr_t attr;
36+
37+
pthread_attr_init(&attr);
38+
pthread_create(&t, &attr, fn, arg);
39+
return t;
40+
}
41+
42+
int main(int argc, char **argv)
43+
{
44+
unsigned long i, len, size, thr;
45+
pthread_t threads[256];
46+
struct args args[256];
47+
long long v;
48+
49+
if (argc < 4) {
50+
printf("ERR: %s [copysize Kb] [numthreads] [numloops (hundreds)]\n", argv[0]);
51+
exit(1);
52+
}
53+
54+
v = atoll(argv[1]);
55+
if ((v < 1) || (v > (1024 * 1024))) {
56+
printf("ERR: max memory 1GB (1048576 KB)\n");
57+
exit(1);
58+
}
59+
size = v;
60+
thr = atol(argv[2]);
61+
if ((thr < 1) || (thr > 256)) {
62+
printf("ERR: threads 1-256\n");
63+
exit(1);
64+
}
65+
v = atoll(argv[3]);
66+
if ((v < 1) || (v > 40000000000ll)) {
67+
printf("ERR: loops 1-40000000000 (hundreds)\n");
68+
exit(1);
69+
}
70+
len = v * 100;
71+
for (i = 0; i < thr; i++) {
72+
args[i].loops = len;
73+
args[i].size = size;
74+
args[i].th = new_thr(thrfn, &(args[i]));
75+
}
76+
for (i = 0; i < thr; i++)
77+
pthread_join(args[i].th, &(args[i].ret));
78+
return 0;
79+
}

0 commit comments

Comments
 (0)