Multithreading 在独立的cpu内核上运行内核线程
我启动我的内核Multithreading 在独立的cpu内核上运行内核线程,multithreading,linux-kernel,kernel,Multithreading,Linux Kernel,Kernel,我启动我的内核 with isolcpus=3-7 我想在一个孤立的CPU核上运行一个线程 基于此,我认为: 但它不起作用。以下代码报告0: static void my_work(struct work_struct *w) { printk("CPU is: %d\n", get_cpu()); put_cpu(); 如何在特定的内核上运行此工作队列线程(如果可能是一个独立的内核)?主线内核中已经有一个API调度工作,您可以使用它在特定的内核上运行您的工作队列线程 几年前
with isolcpus=3-7
我想在一个孤立的CPU核上运行一个线程
基于此,我认为:
但它不起作用。以下代码报告0:
static void my_work(struct work_struct *w) {
printk("CPU is: %d\n", get_cpu());
put_cpu();
如何在特定的内核上运行此工作队列线程(如果可能是一个独立的内核)?主线内核中已经有一个API
调度工作,您可以使用它在特定的内核上运行您的工作队列线程
几年前,我为了同样的目的使用了相同的API。
请查看示例代码
static void
myworkmod_work_handler(struct work_struct *w)
{
printk(KERN_ERR "CPU is: %d\n", get_cpu());
pr_info("work %u jiffies\n", (unsigned)onesec);
put_cpu();
}
static int myworkmod_init(void)
{
onesec = msecs_to_jiffies(1000);
pr_info("module loaded: %u jiffies\n", (unsigned)onesec);
if (!wq)
wq = create_singlethread_workqueue("myworkmod");
if (wq)
queue_delayed_work_on(2,wq, &myworkmod_work, onesec); //2 CPU no
return 0;
}
在您的情况下,我认为您使用的是始终保持默认CPU数量的调度\u workAPI。这就是为什么您将获得CPU 0。因此,您必须尝试以下方法:
schedule_work_on(cpu_nr, &ctx->work); //cpu_nr will the CPU no to be used.
schedule_work_on(cpu_nr, &ctx->work); //cpu_nr will the CPU no to be used.