Skip to content

Commit ddabb6e

Browse files
Fix-Pointxiaoxiang781216
authored andcommitted
benchmarks: support cyclictest
This commit supports cyclictest from RT-Tests for the timer jitter profiling. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
1 parent d9e178a commit ddabb6e

File tree

6 files changed

+334
-0
lines changed

6 files changed

+334
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From cbd7831e20f387a35e94a50b95e0b8db5c5e63dd Mon Sep 17 00:00:00 2001
2+
From: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
3+
Date: Mon, 8 Jul 2024 10:43:14 +0800
4+
Subject: [PATCH] rt-tests/cyclictest: Port for NuttX
5+
6+
VELAPLATFO-37815
7+
8+
This patch ports cyclictest for NuttX.
9+
10+
Change-Id: I918da053887aaba78910e230db0169239dba3b73
11+
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
12+
---
13+
src/cyclictest/cyclictest.c | 6 +++++-
14+
1 file changed, 5 insertions(+), 1 deletion(-)
15+
16+
diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
17+
index c5c3389..0edb684 100644
18+
--- a/src/cyclictest/cyclictest.c
19+
+++ b/src/cyclictest/cyclictest.c
20+
@@ -847,7 +847,11 @@ static void display_help(int error)
21+
static int use_nanosleep = MODE_CLOCK_NANOSLEEP;
22+
static int timermode = TIMER_ABSTIME;
23+
static int use_system;
24+
+#ifdef RTTESTS_PRIORITY
25+
+static int priority = RTTESTS_PRIORITY;
26+
+#else
27+
static int priority;
28+
+#endif
29+
static int policy = SCHED_OTHER; /* default policy if not specified */
30+
static int num_threads = 1;
31+
static int max_cycles;
32+
@@ -1224,7 +1228,7 @@ static void process_options(int argc, char *argv[], int max_cpus)
33+
if (distance == -1)
34+
distance = DEFAULT_DISTANCE;
35+
36+
- if (priority < 0 || priority > 99)
37+
+ if (priority < 0 || priority > 255)
38+
error = 1;
39+
40+
if (num_threads == -1)
41+
--
42+
2.34.1
43+

benchmarks/rt-tests/CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#
2+
# Copyright (C) 2024 Xiaomi Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
# use this file except in compliance with the License. You may obtain a copy of
6+
# the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations under
14+
# the License.
15+
#
16+
17+
if(CONFIG_BENCHMARK_RTTESTS)
18+
19+
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/rt-tests/.git)
20+
set(RTTESTS_URL
21+
"https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git")
22+
set(RTTESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rt-tests)
23+
24+
execute_process(
25+
COMMAND git clone ${RTTESTS_URL} ${RTTESTS_DIR}
26+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
27+
RESULT_VARIABLE GIT_CLONE_RESULT)
28+
29+
if(NOT ${GIT_CLONE_RESULT} EQUAL 0)
30+
message(FATAL_ERROR "Failed to clone rt-tests repository")
31+
endif()
32+
33+
execute_process(
34+
COMMAND cd ${RTTESTS_DIR} && git checkout -q ${RTTESTS_VERSION} && patch
35+
-p1 < ../0001-rt-tests-cyclictest-Port-for-NuttX.patch
36+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
37+
38+
add_custom_target(distclean COMMAND ${CMAKE_COMMAND} -E remove_directory
39+
${RTTESTS_DIR})
40+
endif()
41+
42+
list(
43+
APPEND
44+
SRCS
45+
rt-tests/src/cyclictest/cyclictest.c
46+
rt-tests/src/lib/rt-error.c
47+
rt-tests/src/lib/histogram.c
48+
rt-tests/src/lib/rt-utils.c
49+
rt-tests/src/lib/rt-numa.c)
50+
51+
list(
52+
APPEND
53+
CFLAGS
54+
-Irt-tests/src/include
55+
-I.
56+
-DVERSION=0.1
57+
-DSYS_gettid=0
58+
-Dgettid=rttest_gettid
59+
-D'syscall
60+
(x)
61+
=
62+
((pid_t) (x))
63+
'
64+
-w
65+
-DRTTESTS_PRIORITY=${CONFIG_BENCHMARK_RTTESTS_PRIORITY}+1)
66+
67+
nuttx_add_application(
68+
NAME
69+
cyclictest
70+
PRIORITY
71+
${CONFIG_BENCHMARK_RTTESTS_PRIORITY}
72+
STACKSIZE
73+
${CONFIG_BENCHMARK_RTTESTS_STACKSIZE}
74+
MODULE
75+
${CONFIG_BENCHMARK_RTTESTS}
76+
COMPILE_FLAGS
77+
${CFLAGS}
78+
SRCS
79+
${SRCS})
80+
endif()

benchmarks/rt-tests/Kconfig

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (C) 2024 Xiaomi Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
config BENCHMARK_RTTESTS
17+
tristate "RT-Tests"
18+
default n
19+
depends on PIPES && ALLOW_GPL_COMPONENTS
20+
---help---
21+
Measure the timer jitter
22+
23+
if BENCHMARK_RTTESTS
24+
25+
config BENCHMARK_RTTESTS_PRIORITY
26+
int "RT-Tests task priority"
27+
default 200
28+
29+
config BENCHMARK_RTTESTS_STACKSIZE
30+
int "RT-Tests stack size"
31+
default DEFAULT_TASK_STACKSIZE
32+
33+
endif

benchmarks/rt-tests/Make.defs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (C) 2024 Xiaomi Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
ifneq ($(CONFIG_BENCHMARK_RTTESTS),)
18+
CONFIGURED_APPS += $(APPDIR)/benchmarks/rt-tests
19+
endif

benchmarks/rt-tests/Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Copyright (C) 2024 Xiaomi Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
############################################################################
18+
# Targets
19+
############################################################################
20+
21+
22+
include $(APPDIR)/Make.defs
23+
24+
PROGNAME = cyclictest
25+
PRIORITY = $(CONFIG_BENCHMARK_RTTESTS_PRIORITY)
26+
STACKSIZE = $(CONFIG_BENCHMARK_RTTESTS_STACKSIZE)
27+
MODULE = $(CONFIG_BENCHMARK_RTTESTS)
28+
29+
RTTESTS_PATH = $(APPDIR)/benchmarks/rt-tests/rt-tests
30+
RTTESTS_URL = https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
31+
RTTESTS_VERSION = cadd661f984c0e6717e681fdaca1ce589b0ed964
32+
RTTESTS_GIT = rt-tests
33+
34+
ifeq ($(wildcard rt-tests/.git),)
35+
rt-tests:
36+
@echo "Git Cloning: $(RTTESTS_URL)"
37+
$(Q) git clone $(RTTESTS_URL)
38+
@echo "Checkout commit: $(RTTESTS_VERSION)"
39+
$(Q) cd $(RTTESTS_PATH) && \
40+
git checkout -q $(RTTESTS_VERSION)
41+
@echo "Patching: Applying patch"
42+
$(Q) cd $(RTTESTS_PATH) && \
43+
patch -p1 < ../0001-rt-tests-cyclictest-Port-for-NuttX.patch
44+
45+
context:: rt-tests
46+
endif
47+
48+
distclean::
49+
$(call DELDIR, $(RTTESTS_GIT))
50+
51+
MAINSRC = rt-tests/src/cyclictest/cyclictest.c
52+
CSRCS = rt-tests/src/lib/rt-error.c rt-tests/src/lib/histogram.c
53+
CSRCS += rt-tests/src/lib/rt-utils.c rt-tests/src/lib/rt-numa.c
54+
55+
CFLAGS += -Irt-tests/src/include -I. -DVERSION=0.1
56+
CFLAGS += -DSYS_gettid=0 -Dgettid=rttest_gettid -D'syscall(x)=((pid_t)(x))'
57+
CFLAGS += -w -DRTTESTS_PRIORITY=$(CONFIG_BENCHMARK_RTTESTS_PRIORITY)+1
58+
59+
include $(APPDIR)/Application.mk

benchmarks/rt-tests/numa.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/****************************************************************************
2+
* apps/benchmarks/rt-tests/numa.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __NUMA_H__
22+
#define __NUMA_H__
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <strings.h>
29+
30+
/****************************************************************************
31+
* Pre-processor Definitions
32+
****************************************************************************/
33+
34+
#define CACHE_LINESIZE (64)
35+
#define numa_run_on_node(...) (-1)
36+
#define numa_node_of_cpu(...) (-1)
37+
#define numa_alloc_onnode(size, node) memalign(CACHE_LINESIZE, size)
38+
#define numa_free(ptr, size) free(ptr)
39+
#define numa_available() (-1)
40+
41+
struct bitmask
42+
{
43+
unsigned long size; /* number of bits in the map */
44+
unsigned long *maskp;
45+
};
46+
47+
static inline
48+
struct bitmask *numa_allocate_cpumask(void)
49+
{
50+
return NULL;
51+
}
52+
53+
static inline void numa_bitmask_free(struct bitmask *mask)
54+
{
55+
return;
56+
}
57+
58+
static inline int numa_sched_getaffinity(pid_t pid, struct bitmask *mask)
59+
{
60+
return -1;
61+
}
62+
63+
static inline
64+
unsigned int numa_bitmask_isbitset(const struct bitmask *mask,
65+
unsigned int idx)
66+
{
67+
return mask->maskp[idx / sizeof(unsigned long)] &
68+
((unsigned long)1 << (idx % sizeof(unsigned long)));
69+
}
70+
71+
static inline
72+
struct bitmask *numa_bitmask_clearbit(struct bitmask *mask,
73+
unsigned int idx)
74+
{
75+
mask->maskp[idx / sizeof(unsigned long)] &=
76+
~((unsigned long)1 << (idx % sizeof(unsigned long)));
77+
return mask;
78+
}
79+
80+
static inline
81+
struct bitmask *numa_parse_cpustring_all(const char *s)
82+
{
83+
return NULL;
84+
}
85+
86+
static inline
87+
unsigned int numa_bitmask_weight(const struct bitmask *bitmap)
88+
{
89+
unsigned int idx;
90+
unsigned int ret = 0;
91+
for (idx = 0; idx < bitmap->size / sizeof(unsigned long); idx++)
92+
{
93+
ret += popcountl(bitmap->maskp[idx]);
94+
}
95+
return ret;
96+
}
97+
98+
#define numa_sched_setaffinity(...) (-1)
99+
100+
#endif

0 commit comments

Comments
 (0)