Which system do you use? Android, Ubuntu, OOWOW or others?
Ubuntu
Which version of system do you use? Khadas official images, self built images, or others?
Khadas official images
Please describe your issue below:
I want to bind one thread to one of two little CPU cores, core A, of the Khadas VIM3 Pro board. In my program, I need to repeat the thread binding multiple times. But when this program executes for a long time, it will generate an error, “Error setting thread affinity due to Invalid argument.” I suspect the system process would occupy core A, which fails the thread binding. Does anyone have any ideas to help resolve this issue?
Post a console log of your issue below:
C code used to bind the thread with core A is listed as follows.
CPU_ZERO(&cpuset1);
CPU_SET(1, &cpuset1);
ARM_COMPUTE_EXIT_ON_MSG(sched_setaffinity(0, sizeof(cpuset1), &cpuset1), "Error setting thread affinity"); // bind this thread with core 1 of little clsuter
@Yujie_Zhang the core indexing starts from 0, so the little cores in the system are cores 0, and 1, index 1 is actually the 2nd cpu core.
It shouldn’t be due to system process in that case. Perhaps you can try adding affinity to both cores in the little cluster. Mixing the affinity between big cores and little cores can cause some problems in coherent operations.
@Electr1 Index 1 is also the little core, right? I aimed to bind the thread with any little core and both core 0 and core 1 satisfy the requirement. In my program, I tried adding affinity to core 1 and did not mix the affinity between big and little cores. Do you know why core 1 was occupied so the program could not bind the thread with it?
Thread affinity doesn’t block other threads from running on that core. Perhaps you could increase the schedule priority for the thread as alternative to force it to execute.
Would you tell more details about your task ?, perhaps a better alternative solution can be provided
@Electr1 Yes, I used the following code to set the highest priority of the binding thread and executed the program with root priority.
setpriority(PRIO_PROCESS, 0, -20);
However, even so, the same problem still existed.
Regarding my task, I tried to use big/little CPU clusters to execute different tasks. I first created two threads with workloads allocated and bonded these threads with one big/little CPU core separately. Then when executing the workload, different CPU cores would be used based on the core the current thread executed on. For example, if the workload allocated on thread A on core 0 were invoked, core 0 and core 1 would be used for its execution.
@Yujie_Zhang I don’t think it is suitable to split tasks like that, it will cause issues as big cores are much more different than small cores when it comes to execution and prediction. It’s better to let the scheduler decide and take care of those operations in general.
@Electr1 Yes, allocating tasks onto big/little CPU clusters separately is tricky. I need this implementation to test some ideas. So, I want to figure out the binding issue.
I utilized perf tools to measure the context switch of core 1 and found that core 1 was used for isp_connection, which was not used in my program. I guess this may be the reason why core 1 cannot be set thread affinity to. Does anyone know how to turn off this isp_connection process?