'The SMP kernel timer has only one CPU executing?
In the SMP system, register the timer on each CPU. The code is as follows. The execution result is that only one CPU timer processing function is called, and the CPU is random. why ?
...............................................................................................
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/pm.h>
#include <linux/platform_device.h>
static DEFINE_PER_CPU(struct timer_list, my_timer);
static void timer_handle_fun(unsigned long arg)
{
int cpu = smp_processor_id();
struct timer_list *t = this_cpu_ptr(&my_timer);
printk("**%s %d cpu=%d**\n",__FUNCTION__,__LINE__,cpu);
mod_timer(t, jiffies + (5 * HZ));
}
static void each_timer_start(void *arg)
{
int cpu = smp_processor_id();
struct timer_list *t = this_cpu_ptr(&my_timer);
printk("**%s %d cpu=%d**\n",__FUNCTION__,__LINE__,cpu);
mod_timer(t, jiffies + (5 * HZ));
}
static void init_timer(void *arg){
struct timer_list *t = this_cpu_ptr(&my_timer);
int cpu = smp_processor_id();
printk("**%s %d cpu=%d**\n",__FUNCTION__,__LINE__,cpu);
setup_timer(t, timer_handle_fun,0);
}
static void start_timers(void *arg)
{
int cpu = smp_processor_id();
printk("**%s %d cpu=%d**\n",__FUNCTION__,__LINE__,cpu);
on_each_cpu(each_timer_start, NULL, 1);
}
static int timer_drv_probe(struct platform_device *pdev)
{
on_each_cpu(init_timer, NULL, 1);
on_each_cpu(start_timers, NULL, 1);
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
