@@ -90,6 +90,62 @@ static int cmd_free(int argc, char **argv)
90
90
}
91
91
MSH_CMD_EXPORT_ALIAS (cmd_free , free , Show the memory usage in the system );
92
92
#endif /* RT_USING_HEAP */
93
+
94
+ #if RT_CPUS_NR > 1
95
+ static int cmd_bind (int argc , char * * argv )
96
+ {
97
+ rt_err_t result ;
98
+ rt_ubase_t thread_id ;
99
+ rt_ubase_t core_id ;
100
+ rt_thread_t thread ;
101
+ char * endptr ;
102
+
103
+ if (argc != 3 )
104
+ {
105
+ rt_kprintf ("Usage: bind <thread_id> <core_id>\n" );
106
+ return 0 ;
107
+ }
108
+
109
+ /* Parse thread_id */
110
+ thread_id = (rt_ubase_t )strtoul (argv [1 ], & endptr , 0 );
111
+ if (* endptr != '\0' )
112
+ {
113
+ rt_kprintf ("Error: Invalid thread ID '%s'\n" , argv [1 ]);
114
+ return 0 ;
115
+ }
116
+
117
+ /* Parse core_id */
118
+ core_id = (rt_uint8_t )strtoul (argv [2 ], & endptr , 0 );
119
+ if (* endptr != '\0' )
120
+ {
121
+ rt_kprintf ("Error: Invalid core ID '%s'\n" , argv [2 ]);
122
+ return 0 ;
123
+ }
124
+
125
+ thread = (rt_thread_t )thread_id ;
126
+
127
+ if (rt_object_get_type (& thread -> parent ) != RT_Object_Class_Thread )
128
+ {
129
+ rt_kprintf ("Error: Invalid thread ID %#lx\n" , thread_id );
130
+ return 0 ;
131
+ }
132
+
133
+ result = rt_thread_control (thread , RT_THREAD_CTRL_BIND_CPU , (void * )core_id );
134
+ if (result == RT_EOK )
135
+ {
136
+ rt_kprintf ("Thread 0x%lx bound to core %d successfully\n" ,
137
+ thread_id , core_id );
138
+ }
139
+ else
140
+ {
141
+ rt_kprintf ("Failed to bind thread 0x%lx to core %d\n" ,
142
+ thread_id , core_id );
143
+ }
144
+ return 0 ;
145
+ }
146
+ MSH_CMD_EXPORT_ALIAS (cmd_bind , bind , Binding thread to core );
147
+ #endif /* RT_CPUS_NR > 1 */
148
+
93
149
#endif /* MSH_USING_BUILT_IN_COMMANDS */
94
150
95
151
static int msh_split (char * cmd , rt_size_t length , char * argv [FINSH_ARG_MAX ])
0 commit comments