File Index
Files and directories
Sign in
FILE

memcpy_thread.c

File preview with syntax highlighting.

linux-6.19.14/tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c 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
 9struct args {
10	unsigned long loops;
11	unsigned long size;
12	pthread_t th;
13	void *ret;
14};
15
16static 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	return NULL;
32}
33
34static pthread_t new_thr(void *(*fn) (void *arg), void *arg)
35{
36	pthread_t t;
37	pthread_attr_t attr;
38
39	pthread_attr_init(&attr);
40	pthread_create(&t, &attr, fn, arg);
41	return t;
42}
43
44int main(int argc, char **argv)
45{
46	unsigned long i, len, size, thr;
47	struct args args[256];
48	long long v;
49
50	if (argc < 4) {
51		printf("ERR: %s [copysize Kb] [numthreads] [numloops (hundreds)]\n", argv[0]);
52		exit(1);
53	}
54
55	v = atoll(argv[1]);
56	if ((v < 1) || (v > (1024 * 1024))) {
57		printf("ERR: max memory 1GB (1048576 KB)\n");
58		exit(1);
59	}
60	size = v;
61	thr = atol(argv[2]);
62	if ((thr < 1) || (thr > 256)) {
63		printf("ERR: threads 1-256\n");
64		exit(1);
65	}
66	v = atoll(argv[3]);
67	if ((v < 1) || (v > 40000000000ll)) {
68		printf("ERR: loops 1-40000000000 (hundreds)\n");
69		exit(1);
70	}
71	len = v * 100;
72	for (i = 0; i < thr; i++) {
73		args[i].loops = len;
74		args[i].size = size;
75		args[i].th = new_thr(thrfn, &(args[i]));
76	}
77	for (i = 0; i < thr; i++)
78		pthread_join(args[i].th, &(args[i].ret));
79	return 0;
80}
~/ Read-only file preview.