Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <james.clark@arm.com>
Signed-off-by: Carsten Haitzler <carsten.haitzler@arm.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: coresight@lists.linaro.org
Link: https://lore.kernel.org/r/20220909152803.2317006-7-carsten.haitzler@foss.arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Carsten Haitzler and committed by
Arnaldo Carvalho de Melo
f1288bdb 6ea586b1

+115 -1
+2 -1
tools/perf/tests/shell/coresight/Makefile
··· 5 5 include ../../../../../tools/scripts/utilities.mak 6 6 7 7 SUBDIRS = \ 8 - asm_pure_loop 8 + asm_pure_loop \ 9 + memcpy_thread 9 10 10 11 all: $(SUBDIRS) 11 12 $(SUBDIRS):
+1
tools/perf/tests/shell/coresight/memcpy_thread/.gitignore
··· 1 + memcpy_thread
+33
tools/perf/tests/shell/coresight/memcpy_thread/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # Carsten Haitzler <carsten.haitzler@arm.com>, 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
+79
tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Carsten Haitzler <carsten.haitzler@arm.com>, 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 + }