Skip to content

Commit 83c1db6

Browse files
committed
apps/system : Add cputest application for Secondary CPUs management testing
Add cputest application with shell commands for testing CPU driver functionality. Provides commands to enable/disable CPU1 and check CPU status through device interface. Shell commands added: - cpu1on: Enable CPU1 - cpu1off: Disable CPU1 - cpustatus: Show status of all Secondary CPUs Test Cases: Default: TASH>smp - smp will run and all threads exit properly TASH>cpu1off - CPU1 Power off TASH>cpu1on - CPU1 turned back on TASH>smp - smp will run and all threads exit properly
1 parent a3d4d11 commit 83c1db6

File tree

5 files changed

+316
-0
lines changed

5 files changed

+316
-0
lines changed

apps/system/cputest/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
4+
#
5+
6+
config SYSTEM_CPUTEST
7+
bool "CPU Test commands"
8+
default n
9+
depends on SMP
10+
---help---
11+
Enable support for CPU test commands in TASH. This provides commands
12+
for testing CPU power management and status functionality on multi-core
13+
systems. Commands include cpu1on, cpu1off, cpustatus.

apps/system/cputest/Make.defs

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

apps/system/cputest/Makefile

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
############################################################################
2+
#
3+
# Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
# either express or implied.
15+
# See the License for the specific
16+
# language governing permissions and limitations under the License.
17+
#
18+
###########################################################################
19+
20+
-include $(TOPDIR)/.config
21+
-include $(TOPDIR)/Make.defs
22+
include $(APPDIR)/Make.defs
23+
24+
ifeq ($(WINTOOL),y)
25+
INCDIROPT = -w
26+
endif
27+
28+
# CPU Test System Utility
29+
30+
ASRCS =
31+
CSRCS =
32+
MAINSRC = cputest.c
33+
34+
AOBJS = $(ASRCS:.S=$(OBJEXT))
35+
COBJS = $(CSRCS:.c=$(OBJEXT))
36+
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
37+
38+
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
39+
OBJS = $(AOBJS) $(COBJS)
40+
41+
ifneq ($(CONFIG_BUILD_KERNEL),y)
42+
OBJS += $(MAINOBJ)
43+
endif
44+
45+
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
46+
BIN = ..\..\libapps$(LIBEXT)
47+
else
48+
ifeq ($(WINTOOL),y)
49+
BIN = ..\\..\\libapps$(LIBEXT)
50+
else
51+
BIN = ../../libapps$(LIBEXT)
52+
endif
53+
endif
54+
55+
ifeq ($(WINTOOL),y)
56+
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
57+
else
58+
INSTALL_DIR = $(BIN_DIR)
59+
endif
60+
61+
ROOTDEPPATH = --dep-path .
62+
63+
# Common build
64+
65+
VPATH =
66+
67+
all: .built
68+
.PHONY: context depend clean distclean
69+
70+
$(AOBJS): %$(OBJEXT): %.S
71+
$(call ASSEMBLE, $<, $@)
72+
73+
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
74+
$(call COMPILE, $<, $@)
75+
76+
.built: $(OBJS)
77+
$(call ARCHIVE, $(BIN), $(OBJS))
78+
$(Q) touch .built
79+
80+
install:
81+
82+
context:
83+
84+
# Create dependencies
85+
86+
.depend: Makefile $(SRCS)
87+
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
88+
$(Q) touch $@
89+
90+
depend: .depend
91+
92+
clean:
93+
$(call DELFILE, .built)
94+
$(call CLEAN)
95+
96+
distclean: clean
97+
$(call DELFILE, Make.dep)
98+
$(call DELFILE, .depend)
99+
100+
-include Make.dep
101+
.PHONY: preconfig
102+
preconfig:

apps/system/cputest/cputest.c

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/****************************************************************************
2+
*
3+
* Copyright 2025 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied.
15+
* See the License for the specific
16+
* language governing permissions and limitations under the License.
17+
*
18+
****************************************************************************/
19+
20+
/****************************************************************************
21+
* Included Files
22+
****************************************************************************/
23+
24+
#include <tinyara/config.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
#include <string.h>
28+
#include <fcntl.h>
29+
#include <sys/ioctl.h>
30+
#include <errno.h>
31+
#include <unistd.h>
32+
#include <tinyara/cpu_driver.h>
33+
#include <apps/shell/tash.h>
34+
35+
/****************************************************************************
36+
* Preprocessor Definitions
37+
****************************************************************************/
38+
39+
#define CPU1_DEVICE_PATH "/dev/cpu1"
40+
41+
const char *cpu_states[] = {
42+
"running", //0
43+
"hotplug", //1
44+
};
45+
46+
/****************************************************************************
47+
* Private Function Prototypes
48+
****************************************************************************/
49+
50+
static int cputest_cpu1_on(int argc, char *argv[]);
51+
static int cputest_cpu1_off(int argc, char *argv[]);
52+
static int cputest_cpu_status(int argc, char *argv[]);
53+
54+
/****************************************************************************
55+
* Private Functions
56+
****************************************************************************/
57+
58+
static int cputest_cpu1_on(int argc, char *argv[])
59+
{
60+
int fd;
61+
cpu_state_t state;
62+
63+
if (sched_getcpu() > 0) {
64+
printf("can only powerup cpu1 from cpu0!\n");
65+
return 0;
66+
}
67+
68+
printf("powering up cpu1!\n");
69+
70+
fd = open(CPU1_DEVICE_PATH, O_RDWR);
71+
if (fd < 0) {
72+
printf("Cannot open %s file with fd = %d errno = %d\n", CPU1_DEVICE_PATH, fd, errno);
73+
return 0;
74+
}
75+
76+
if (ioctl(fd, IOC_CPU_ENABLE, 1) < 0) {
77+
printf("ioctl failed errno = %d\n", errno);
78+
close(fd);
79+
return 0;
80+
}
81+
printf("cpu1 successfully enabled\n");
82+
83+
if (ioctl(fd, IOC_CPU_GET_STATE, &state) < 0) {
84+
printf("IOC_CPU_GET_STATE ioctl failed for %s : %d\n", CPU1_DEVICE_PATH, errno);
85+
close(fd);
86+
return 0;
87+
}
88+
89+
printf("state: %d (%s)\n", state, cpu_states[state]);
90+
close(fd);
91+
return 0;
92+
}
93+
94+
static int cputest_cpu1_off(int argc, char *argv[])
95+
{
96+
int fd;
97+
cpu_state_t state;
98+
99+
if (sched_getcpu() > 0) {
100+
printf("can only powerdown cpu1 from cpu0!\n");
101+
return 0;
102+
}
103+
printf("powering down cpu1!\n");
104+
105+
fd = open(CPU1_DEVICE_PATH, O_RDWR);
106+
if (fd < 0) {
107+
printf("Cannot open %s file with fd = %d errno = %d\n", CPU1_DEVICE_PATH, fd, errno);
108+
return 0;
109+
}
110+
111+
if (ioctl(fd, IOC_CPU_DISABLE, 1) < 0) {
112+
printf("ioctl failed errno = %d\n", errno);
113+
close(fd);
114+
return 0;
115+
}
116+
printf("cpu1 successfully disabled\n");
117+
118+
if (ioctl(fd, IOC_CPU_GET_STATE, &state) < 0) {
119+
printf("IOC_CPU_GET_STATE ioctl failed for %s : %d\n", CPU1_DEVICE_PATH, errno);
120+
close(fd);
121+
return 0;
122+
}
123+
printf("state: %d (%s)\n", state, cpu_states[state]);
124+
close(fd);
125+
return 0;
126+
}
127+
128+
static int cputest_cpu_status(int argc, char *argv[])
129+
{
130+
int fd;
131+
char devname[16];
132+
cpu_state_t state;
133+
134+
for (u8 i = 1; i < CONFIG_SMP_NCPUS; i++) {
135+
snprintf(devname, sizeof(devname), "/dev/cpu%d", i);
136+
137+
fd = open(devname, O_RDWR);
138+
if (fd < 0) {
139+
printf("Cannot open %s file with fd = %d errno = %d\n", devname, fd, errno);
140+
return 0;
141+
}
142+
143+
if (ioctl(fd, IOC_CPU_GET_STATE, &state) < 0) {
144+
printf("IOC_CPU_GET_STATE ioctl failed for %s : %d\n", devname, errno);
145+
close(fd);
146+
return 0;
147+
}
148+
149+
printf("cpu state for cpu%d: %d (%s)\n", i, state, cpu_states[state]);
150+
close(fd);
151+
}
152+
return 0;
153+
}
154+
155+
const static tash_cmdlist_t cputest_cmds[] = {
156+
{"cpu1on", cputest_cpu1_on, TASH_EXECMD_ASYNC},
157+
{"cpu1off", cputest_cpu1_off, TASH_EXECMD_ASYNC},
158+
{"cpustatus", cputest_cpu_status, TASH_EXECMD_ASYNC},
159+
{NULL, NULL, 0}
160+
};
161+
162+
/****************************************************************************
163+
* Public Functions
164+
****************************************************************************/
165+
166+
void cputest_register_cmds(void)
167+
{
168+
/* Register the CPU test commands during system initialization */
169+
tash_cmdlist_install(cputest_cmds);
170+
}

apps/system/init/init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
extern void iotjs_register_cmds(void);
7474
#endif
7575

76+
#ifdef CONFIG_SYSTEM_CPUTEST
77+
extern void cputest_register_cmds(void);
78+
#endif
79+
7680
/****************************************************************************
7781
* Pravite Functions
7882
****************************************************************************/
@@ -107,6 +111,10 @@ static void tash_register_cmds(void)
107111
#ifdef CONFIG_DEBUG_SYSTEM_APP
108112
sysdbgapp_init();
109113
#endif
114+
115+
#ifdef CONFIG_SYSTEM_CPUTEST
116+
cputest_register_cmds();
117+
#endif
110118
}
111119
#endif /* CONFIG_TASH */
112120

0 commit comments

Comments
 (0)