中断绑核:
API_InterVectorConnect(SPI_GMAC, // 中断号
(PINT_SVR_ROUTINE)__emacIsr,
(PVOID)pNetDev,
"enet_isr");
API_InterVectorEnable(SPI_GMAC);
LW_CPU_ZERO(&cpuset);
LW_CPU_SET(1, &cpuset);
API_InterSetTarget(SPI_GMAC, sizeof(cpuset), &cpuset); /* 默认中断绑 1 核 */
线程绑核:
#include <SylixOS.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//绑核操作
PVOID tTest(PVOID pvArg)
{
CPU_ZERO(&cpuset);
CPU_SET(2,&cpuset); //设置为绑核为 2
pthread_setaffinity_np(API_ThreadIdSelf(),sizeof(cpu_set_t),&cpuset); // 将线程绑定
while(1) {
sleep(1);
}
return NULL;
}
int main(int argc, char **argv)
{
LW_CLASS_THREADATTR threadattr;
LW_HANDLE hThreadId;
cpu_set_t cpuset;
Lw_ThreadAttr_Build(&threadattr,
4 * LW_CFG_KB_SIZE,
LW_PRIO_NORMAL,
LW_OPTION_THREAD_STK_CHK,
LW_NULL);
hThreadId = Lw_Thread_Create("t_test", tTest, &threadattr, LW_NULL);
if (hThreadId == LW_OBJECT_HANDLE_INVALID) {
return (PX_ERROR);
}
Lw_Thread_Join(hThreadId, LW_NULL);
return 0;
}