为什么hrtimer导致软中断死锁?

时间:2016-06-02 09:00:57

标签: linux timer linux-kernel kernel embedded-linux

我想使用hrtimer,但该模块无法正常工作。源代码是:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/hrtimer.h>

#define US_TO_NS(usec)      ((usec) * 1000)
#define MS_TO_US(msec)      ((msec) * 1000)
#define MS_TO_NS(msec)      ((msec) * 1000 * 1000)

DEFINE_PER_CPU(struct hrtimer, send_hr_timer);

enum hrtimer_restart hrtimer_send_skb(struct hrtimer *timer) 
{
    ktime_t ktime;    
    int cpu;
    unsigned long delay_in_ms = 10000L;                                                                                              //unsigned long delay_in_us = 5000L;                                                                                    
    ktime = ktime_set(0, MS_TO_NS(delay_in_ms));
    //ktime = ktime_set(0, US_TO_NS(delay_in_us));                                                                         

    cpu = get_cpu();    printk(KERN_INFO "hrtimer is on:%d", cpu);
    hrtimer_forward(&per_cpu(send_hr_timer, cpu), ktime_get(), ktime);
    put_cpu();

    return HRTIMER_RESTART;
    //return HRTIMER_NORESTART;
}


void init_hr_timer(void)
{  
    ktime_t ktime;
    int cpu;
    unsigned long delay_in_ms = 100L;

    ktime = ktime_set(0, MS_TO_NS(delay_in_ms));

    for_each_online_cpu(cpu) {
        hrtimer_init(&per_cpu(send_hr_timer, cpu), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        per_cpu(send_hr_timer, cpu).function = &hrtimer_send_skb;
        hrtimer_start(&per_cpu(send_hr_timer, cpu), ktime, HRTIMER_MODE_REL);
    }
}

void del_hr_timer(void)
{
    int cpu;

    for_each_online_cpu(cpu) {
        /* del hrtimer. */
        hrtimer_cancel(&per_cpu(send_hr_timer, cpu));
    }
}


static int minit(void)
{
    int rc = 0;

    printk("Start %s.\n", THIS_MODULE->name);
    init_hr_timer();

    return rc;
}

static void mexit(void)
{
    printk("Exit %s.\n", THIS_MODULE->name);
    del_hr_timer();
}

当我安装模块时,出现错误,消息为:

BUG: soft lockup - CPU#22 stuck for 67s! [migration/22:92]
Modules linked in: ws_hrtimer(U) wscubic(U) wsfasttcp(U) 8021q garp stp llc autofs4 cpufreq_ondemand acpi_cpufreq freq_table mperf be2iscsi iscsi_boot_sysfs ib_iser rdma_cm ib_cm iw_cm ib_sa ib_mad ib_core ib_addr iscsi_tcp bnx2i cnic uio ipv6 cxgb3i libcxgbi cxgb3 mdio libiscsi_tcp libiscsi scsi_transport_iscsi ext3 jbd dm_mirror dm_multipath video output sbs sbshc power_meter wsrelay(U) wsgetsnd(U) parport sg acpi_pad ses enclosure igb dca sb_edac edac_core i2c_i801 i2c_core pata_acpi ata_generic iTCO_wdt iTCO_vendor_support dm_raid45 dm_memcache xor dm_region_hash dm_log dm_mod usb_storage ata_piix isci libsas shpchp mpt2sas scsi_transport_sas raid_class ext4 mbcache jbd2 [last unloaded: microcode]
CPU 22
Modules linked in: ws_hrtimer(U) wscubic(U) wsfasttcp(U) 8021q garp stp llc autofs4 cpufreq_ondemand acpi_cpufreq freq_table mperf be2iscsi iscsi_boot_sysfs ib_iser rdma_cm ib_cm iw_cm ib_sa ib_mad ib_core ib_addr iscsi_tcp bnx2i cnic uio ipv6 cxgb3i libcxgbi cxgb3 mdio libiscsi_tcp libiscsi scsi_transport_iscsi ext3 jbd dm_mirror dm_multipath video output sbs sbshc power_meter wsrelay(U) wsgetsnd(U) parport sg acpi_pad ses enclosure igb dca sb_edac edac_core i2c_i801 i2c_core pata_acpi ata_generic iTCO_wdt iTCO_vendor_support dm_raid45 dm_memcache xor dm_region_hash dm_log dm_mod usb_storage ata_piix isci libsas shpchp mpt2sas scsi_transport_sas raid_class ext4 mbcache jbd2 [last unloaded: microcode]

Pid: 92, comm: migration/22 Not tainted 2.6.32-358.6.1.ws5.b.5.2.8 #1 Inspur SA5212H2/SA5212H2
RIP: 0010:[<ffffffff810c6709>]  [<ffffffff810c6709>] stop_machine_cpu_stop+0x59/0x100
RSP: 0018:ffff880874733de0  EFLAGS: 00000293
RAX: 0000000000000001 RBX: ffff880874733e10 RCX: 0000000000000028
RDX: ffffffff81c059e0 RSI: 0000000000000018 RDI: ffffffff81c059e0
RBP: ffffffff8100ba8e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000000 R14: ffff881074f0e040 R15: 0000000000000082
FS:  0000000000000000(0000) GS:ffff88089c540000(0000) knlGS:0000000000000000
CS:  0010 DS: 0018 ES: 0018 CR0: 000000008005003b
CR2: 000000373c89ac00 CR3: 0000000001a85000 CR4: 00000000000407e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process migration/22 (pid: 92, threadinfo ffff880874732000, task ffff880874731540)
Stack:
 0000001674733e00 ffff88089c550840 ffff880874731540 ffffffff810c66b0
<d> ffff8806fa783e68 ffff8806fa783dd8 ffff880874733ee0 ffffffff810c68d5
<d> 0000000000000000 0000002165ed0d57 0000000000000082 ffff880874415ca0
Call Trace:
 [<ffffffff810c66b0>] ? stop_machine_cpu_stop+0x0/0x100
 [<ffffffff810c68d5>] ? cpu_stopper_thread+0xa5/0x170
 [<ffffffff8105a992>] ? default_wake_function+0x12/0x20
 [<ffffffff8104e1eb>] ? __wake_up_common+0x5b/0x90
 [<ffffffff810c6830>] ? cpu_stopper_thread+0x0/0x170
 [<ffffffff810c6830>] ? cpu_stopper_thread+0x0/0x170
 [<ffffffff81090ce6>] ? kthread+0x96/0xa0
 [<ffffffff8100bfca>] ? child_rip+0xa/0x20
 [<ffffffff81090c50>] ? kthread+0x0/0xa0
 [<ffffffff8100bfc0>] ? child_rip+0x0/0x20
Code: 18 48 85 c0 0f 84 9b 00 00 00 0f a3 18 19 c0 85 c0 41 0f 95 c6 31 c0 45 31 ff eb 0d 66 0f 1f 44 00 00 83 fb 04 74 3b 89 d8 f3 90 <41> 8b 5c 24 20 39 c3 74 ee 83 fb 02 74 49 83 fb 03 74 54 f0 41
Call Trace:
 [<ffffffff810c66b0>] ? stop_machine_cpu_stop+0x0/0x100
 [<ffffffff810c68d5>] ? cpu_stopper_thread+0xa5/0x170
 [<ffffffff8105a992>] ? default_wake_function+0x12/0x20
 [<ffffffff8104e1eb>] ? __wake_up_common+0x5b/0x90
 [<ffffffff810c6830>] ? cpu_stopper_thread+0x0/0x170
 [<ffffffff810c6830>] ? cpu_stopper_thread+0x0/0x170
 [<ffffffff81090ce6>] ? kthread+0x96/0xa0
 [<ffffffff8100bfca>] ? child_rip+0xa/0x20
 [<ffffffff81090c50>] ? kthread+0x0/0xa0
 [<ffffffff8100bfc0>] ? child_rip+0x0/0x20

请帮帮我,谢谢。

0 个答案:

没有答案