[BUG] Empty core affinity mask strands a ready task and permanently starves lower priority tasks (configRUN_MULTIPLE_PRIORITIES 0)

Ouverte
#1,504 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 3 jours

@artemkulyk y travaille déjà.

Depuis le 14/10/2026.

  • #1508 par @artemkulyk — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
15/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c

Piste de recherche

The relevant code is prvSelectHighestPriorityTask() in tasks.c, which handles ready-list selection and uxTopReadyPriority, and the affinity setters vTaskCoreAffinitySet() and the xTaskCreate*AffinitySet functions, which store the mask without validating it. Read how the selection loop skips tasks whose affinity excludes the current core, then reproduce with configNUMBER_OF_CORES 2 and configRUN_MULTIPLE_PRIORITIES 0. Done means either the zero mask is rejected at the API or the top-priority pin no longer starves eligible lower-priority tasks. The reporter says a fix is already prepared, so check for linked work before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Describe the bug

vTaskCoreAffinitySet() and xTaskCreateAffinitySet()/xTaskCreateStaticAffinitySet() store the mask unconditionally. A zero mask is accepted (task.h documents no non-zero precondition; no configASSERT rejects it) and makes the task ready but runnable on no core.

With configRUN_MULTIPLE_PRIORITIES 0 (the FreeRTOS.h default) the selection drop rule in prvSelectHighestPriorityTask() then pins uxTopReadyPriority on that task's ready list (the list is non-empty, so the top priority is not decremented), and every selection falls back to the idle tasks (uxCurrentPriority = tskIDLE_PRIORITY when below the top). Lower-priority tasks that are ready and eligible on every core are permanently starved while the system idles.

Target

  • Development board: any SMP target (reproduced on a POSIX host-port harness with configNUMBER_OF_CORES 2, configRUN_MULTIPLE_PRIORITIES 0, configUSE_CORE_AFFINITY 1)
  • Instruction Set Architecture: host arm64 reproduction
  • Toolchain and version: clang (host), FreeRTOS-Kernel 8be86d4a2

To Reproduce

Public APIs only. The mask is producible by a caller computing an allowed-core set dynamically (e.g. after offlining the last eligible core):

  1. Create tasks; set one task's mask to 0 via vTaskCoreAffinitySet( handle, 0 ) (or create with xTaskCreateAffinitySet(..., 0, ...)).
  2. Observe: the task stays eReady but never runs; every other task below its priority freezes (progress counters flat in the harness window while idle iterations run into the millions); only idle tasks run.

Control: the identical run with a valid non-empty mask keeps making progress.

Expected behavior

  • An empty mask should be rejected or ignored at the API (a configASSERT plus a documented non-zero precondition is the usual pattern; note asserts compile out in release builds, so an always-on guard is preferable here).
  • prvSelectHighestPriorityTask() must not pin uxTopReadyPriority on a ready list containing only tasks that are runnable on no core - no core can ever select from such a list, and leaving it pinned starves eligible tasks at lower priorities.

Additional context

  • Related but different: PR #1264 (closed, unmerged) publicly describes only the idle-absence -> stuck-SCHEDULED_TO_YIELD spin (tracked in a separate follow-up issue). #1086/PR #1123 fixed a different affinity mechanism (missing re-select after affinity change).
  • A fix with regression tests is prepared; PRs will reference this issue.
Langage dominant
C
Étoiles
4.6k
Forks
1.6k
Merge moyen
2 j 22 h
PR mergées (30 j)
4

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de FreeRTOS/FreeRTOS-Kernel

Toutes les issues de FreeRTOS/FreeRTOS-Kernel

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.