[BUG] Idle task affinity is set to the default on all cores, causing issues when default is not `tskNO_AFFINITY`
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 66/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c, raspberry-pi
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Start by tracing how the kernel creates idle tasks and assigns task affinity when configUSE_CORE_AFFINITY is enabled; compare the resulting affinity with each task's assigned core. Reproduce with two cores, configTASK_DEFAULT_CORE_AFFINITY set to 2, and configRUN_MULTIPLE_PRIORITIES enabled. Done when each idle task is restricted to its own core and the reported queue receive hang no longer occurs.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When task affinity is enabled, idle tasks for each core are created with the default affinity, which causes various issues when the default affinity is not tskNO_AFFINITY. Cores that are excluded from the default affinity will never run the idle task for their core.
One issue that can occur without an idle task present is that xQueueReceive places the task in the receive queue, yields, and because there is no idle task to return to, it loops, places the task in the queue again (due to no check for its presence before adding), and then gets stuck in an infinite loop.
Target
- Development board: Raspberry Pi Pico 2
- Instruction Set Architecture: ARM Cortex-M33
- IDE and version: Visual Studio Code/CMake
- Toolchain and version: arm-none-eabi-gcc 15.2.1
Host
- Host OS: Arch Linux
- Version: Latest as of a month ago
To Reproduce
Example program, which should print a number every second when working:
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <semphr.h>
#include <stdio.h>
TaskHandle_t mainTask, otherTask1, otherTask2;
QueueHandle_t queue;
QueueHandle_t semaphore;
void other_task1(void* unused) {
while (1) {
xSemaphoreGive(semaphore);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
void other_task2(void* unused) {
for (int i = 0; ; i++) {
xSemaphoreTake(semaphore, portMAX_DELAY);
xQueueSend(queue, &i, portMAX_DELAY);
}
}
void app_main(void* unused) {
//vTaskCoreAffinitySet(xTaskGetIdleTaskHandleForCore(0), 1); // this line resolves the issue
queue = xQueueCreate(16, sizeof(int));
semaphore = xSemaphoreCreateBinary();
vQueueAddToRegistry(queue, "queue");
vQueueAddToRegistry(semaphore, "semaphore");
xTaskCreateAffinitySet(other_task1, "other1", 256, NULL, 4, 2, &otherTask1);
xTaskCreateAffinitySet(other_task2, "other2", 256, NULL, 4, 2, &otherTask2);
while (1) {
int n;
xQueueReceive(queue, &n, portMAX_DELAY);
printf("%d\n", n);
}
}
int main() {
xTaskCreateAffinitySet(app_main, "main", 256, NULL, 1, 1, &mainTask);
vTaskStartScheduler();
}
Relevant configuration settings:
#define configNUMBER_OF_CORES 2
/* if this is not enabled, the core without an idle task is forced to yield while the other
core runs other priorities, mitigating the issue but causing performance problems */
#define configRUN_MULTIPLE_PRIORITIES 1
#define configUSE_CORE_AFFINITY 1
/* core 0 runs main task only, core 1 runs other tasks */
#define configTASK_DEFAULT_CORE_AFFINITY 2
As written, core 0 gets stuck in xQueueReceive as described above, while core 1 waits for the scheduler (which was suspended as part of xQueueReceive) to resume. When the affinity of core 0's idle task is set using the commented out line, the program works as expected.
Expected behavior
The idle tasks should have their affinity set to only run on the core they are assigned to.
Additional context
Stack trace when it hangs in xQueueReceive:
Queue receive task list looping:
The queue issue was reported on the forums years ago but was dismissed as a side effect of user error. While I initially thought the bug came from the queue, I eventually found the underlying idle task issue. Regardless, it may be useful to add an assertion that the task isn't already in the list before adding it (which would be ignored in release mode), to avoid issues like this giving confusing errors.
- Ngôn ngữ chính
- C
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FreeRTOS/FreeRTOS-Kernel
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] event_wait_timed can't return falseCó thể đã có người làm @TedLyngmo đã nhận 39 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của FreeRTOS/FreeRTOS-Kernel
Issue tương tự
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
shinyquagsire23/OpenJKDF2#540 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Life-Framework/Life-Framework#5939 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
autoconf failes to find libsodium even when present due to implicit function declarationCó thể đã có người làm @coderjoe đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 13 ngày
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationĐang mởBug Status: Needs Triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalĐang mởbug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Jstar269/nakagawa-recomp#3521 ·
Maintainer thường phản hồi trong vòng 1 ngày