| 94 | |
| 95 | #if RT_CPUS_NR > 1 |
| 96 | static int cmd_bind(int argc, char **argv) |
| 97 | { |
| 98 | rt_err_t result; |
| 99 | rt_ubase_t thread_id; |
| 100 | rt_ubase_t core_id; |
| 101 | rt_thread_t thread; |
| 102 | char *endptr; |
| 103 | |
| 104 | if (argc != 3) |
| 105 | { |
| 106 | rt_kprintf("Usage: bind <thread_id> <core_id>\n"); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | /* Parse thread_id */ |
| 111 | thread_id = (rt_ubase_t)strtoul(argv[1], &endptr, 0); |
| 112 | if (*endptr != '\0') |
| 113 | { |
| 114 | rt_kprintf("Error: Invalid thread ID '%s'\n", argv[1]); |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* Parse core_id */ |
| 119 | core_id = (rt_uint8_t)strtoul(argv[2], &endptr, 0); |
| 120 | if (*endptr != '\0') |
| 121 | { |
| 122 | rt_kprintf("Error: Invalid core ID '%s'\n", argv[2]); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | thread = (rt_thread_t)thread_id; |
| 127 | |
| 128 | if (rt_object_get_type(&thread->parent) != RT_Object_Class_Thread) |
| 129 | { |
| 130 | rt_kprintf("Error: Invalid thread ID %#lx\n", thread_id); |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | result = rt_thread_control(thread, RT_THREAD_CTRL_BIND_CPU, (void *)core_id); |
| 135 | if (result == RT_EOK) |
| 136 | { |
| 137 | rt_kprintf("Thread 0x%lx bound to core %d successfully\n", |
| 138 | thread_id, core_id); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | rt_kprintf("Failed to bind thread 0x%lx to core %d\n", |
| 143 | thread_id, core_id); |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | MSH_CMD_EXPORT_ALIAS(cmd_bind, bind, Binding thread to core); |
| 148 | #endif /* RT_CPUS_NR > 1 */ |
| 149 |
nothing calls this directly
no test coverage detected