arch/xtensa/esp32,esp32s3: Start the "spiflash_op" thread with correct affinity

Set the affinity of the task before activating it. There is no parameter
or other interface in "kthread_create" to set the affinity mask,
like in "pthread_create".

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen 2025-08-14 08:23:06 +03:00 committed by Filipe do Ó Cavalcanti
parent eec50c183c
commit 80cb2cf9c6
2 changed files with 64 additions and 40 deletions

View file

@ -2560,8 +2560,8 @@ static int spi_flash_op_block_task(int argc, char *argv[])
int spiflash_init_spi_flash_op_block_task(int cpu)
{
int pid;
int ret = OK;
FAR struct tcb_s *tcb;
int ret;
char *argv[2];
char arg1[32];
cpu_set_t cpuset;
@ -2570,29 +2570,41 @@ int spiflash_init_spi_flash_op_block_task(int cpu)
argv[0] = arg1;
argv[1] = NULL;
pid = kthread_create("spiflash_op",
SCHED_PRIORITY_MAX,
CONFIG_ESP32_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task,
argv);
if (pid > 0)
/* Allocate a TCB for the new task. */
tcb = kmm_zalloc(sizeof(struct tcb_s));
if (!tcb)
{
if (cpu < CONFIG_SMP_NCPUS)
{
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
ret = nxsched_set_affinity(pid, sizeof(cpuset), &cpuset);
if (ret < 0)
{
return ret;
}
}
serr("ERROR: Failed to allocate TCB\n");
return -ENOMEM;
}
else
/* Setup the task type */
tcb->flags = TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_FREE_TCB;
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, CONFIG_ESP32_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
if (ret < OK)
{
return -EPERM;
kmm_free(tcb);
return ret;
}
/* Set the affinity */
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
tcb->affinity = cpuset;
/* Activate the task */
nxtask_activate(tcb);
return ret;
}
#endif /* CONFIG_SMP */

View file

@ -999,8 +999,8 @@ static int spi_flash_op_block_task(int argc, char *argv[])
static int spiflash_init_spi_flash_op_block_task(int cpu)
{
int pid;
int ret = OK;
FAR struct tcb_s *tcb;
int ret;
char *argv[2];
char arg1[32];
cpu_set_t cpuset;
@ -1009,29 +1009,41 @@ static int spiflash_init_spi_flash_op_block_task(int cpu)
argv[0] = arg1;
argv[1] = NULL;
pid = kthread_create("spiflash_op",
SCHED_PRIORITY_MAX,
CONFIG_ESP32S3_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task,
argv);
if (pid > 0)
/* Allocate a TCB for the new task. */
tcb = kmm_zalloc(sizeof(struct tcb_s));
if (!tcb)
{
if (cpu < CONFIG_SMP_NCPUS)
{
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
ret = nxsched_set_affinity(pid, sizeof(cpuset), &cpuset);
if (ret < 0)
{
return ret;
}
}
serr("ERROR: Failed to allocate TCB\n");
return -ENOMEM;
}
else
/* Setup the task type */
tcb->flags = TCB_FLAG_TTYPE_KERNEL | TCB_FLAG_FREE_TCB;
/* Initialize the task */
ret = nxtask_init((FAR struct task_tcb_s *)tcb, "spiflash_op",
SCHED_PRIORITY_MAX,
NULL, CONFIG_ESP32S3_SPIFLASH_OP_TASK_STACKSIZE,
spi_flash_op_block_task, argv, environ, NULL);
if (ret < OK)
{
return -EPERM;
kmm_free(tcb);
return ret;
}
/* Set the affinity */
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
tcb->affinity = cpuset;
/* Activate the task */
nxtask_activate(tcb);
return ret;
}
#endif /* CONFIG_SMP */