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

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 <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-11-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
fc0a0ea0 74c62b8d

+110 -1
+2 -1
tools/perf/tests/shell/coresight/Makefile
··· 7 7 SUBDIRS = \ 8 8 asm_pure_loop \ 9 9 memcpy_thread \ 10 - thread_loop 10 + thread_loop \ 11 + unroll_loop_thread 11 12 12 13 all: $(SUBDIRS) 13 14 $(SUBDIRS):
+1
tools/perf/tests/shell/coresight/unroll_loop_thread/.gitignore
··· 1 + unroll_loop_thread
+33
tools/perf/tests/shell/coresight/unroll_loop_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=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
+74
tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_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 + 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 + }