Chinaunix首页 | 论坛 | 博客
  • 博客访问: 697578
  • 博文数量: 260
  • 博客积分: 7033
  • 博客等级: 少将
  • 技术积分: 2633
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-13 23:15
文章分类

全部博文(260)

文章存档

2012年(2)

2011年(41)

2010年(78)

2009年(139)

我的朋友

分类: LINUX

2009-05-03 17:38:47

这样可以看看其上下文信息,是从《Linux设备驱动程序3rd》中学来的。
 
虽然在这些中断程序中可以看到current指针,但是它们使用此current 也是没有意义的。
尤其是硬中断。
软中断还需要再确认一下。
 
硬中断,只要系统是可以被中断的,就可以响应,根据跟踪,硬中断可以抢占:
1、用户进程
2、内核线程(swapper、battery_thread等)

[PID:40 launch] in_interrupt: 65536, in_atomic 1, function as3604_irq_handler, line 1680
[PID:0 swapper] in_interrupt: 65536, in_atomic 1, function as3604_irq_handler, line 1680
[PID:13 battery_thread ] in_interrupt: 65536, in_atomic 1, function as3604_irq_handler, line 1680

tasklet是在硬中断处理完毕,返回的时候执行的,一般其抢占上下文都是和激活它的硬中断是相同的:
[PID:40 launch] in_interrupt: 256, in_atomic 1, function as3604_tasklet_handler, line 1659
[PID:0 swapper] in_interrupt: 256, in_atomic 1, function as3604_tasklet_handler, line 1659
[PID:13 battery_thread ] in_interrupt: 256, in_atomic 1, function as3604_tasklet_handler, line 1659

硬中断的in_interrupt返回65535,而tasklet的返回256

在tasklet中也可以使用定义在函数外面的变量啊,那么说tasklet调用时没有上下文是对的么?或者说其用current表示的上下文并不是其真正的上下文。

被schedule_work激活的,都会在events/0中执行:
[PID:3 events/0] in_interrupt: 0, in_atomic 0, function as3604_callback, line 1694
[PID:3 events/0] in_interrupt: 0, in_atomic 0, function as3604_longpowerkey_callback, line 1471

内核线程在运行时,都会处于其自己的上下文中:
[PID:13 battery_thread ] in_interrupt: 0, in_atomic 0, function battery_thread, line 481
虽然这时,它有可能被抢占:
[PID:13 battery_thread ] in_interrupt: 65536, in_atomic 1, function as3604_irq_handler, line 1680
 
在硬中断中,同时调度tasklet和work,tasklet会优先调用。

static irqreturn_t as3604_irq_handler(int irq, void *dev_id,
                struct pt_regs *regs)
{
        //unsigned int event;
        //u8 val;
        PRINT_CURRENT_INFO();

        printk("schedule_work(&as3604_work);\n");
    schedule_work(&as3604_work);

        printk("tasklet_schedule(&as3604_tasklet);\n");
        tasklet_schedule(&as3604_tasklet);

        return IRQ_HANDLED;
}

上个例子中,虽然tasklet比 work激活的晚,但是其会先得到执行。
 
 
在tasklet中一般不要做休眠的动作,如果在tasklet_handler中执行了msleep(5000),

void as3604_tasklet_handler(unsigned long ignore)
{
        PRINT_CURRENT_INFO();
        msleep(5000);
        printk("Test number is %d\n", iTestNumber);
}

由于 tasklet 休眠时间太长,内核还是会被调度,但是,这是一个不好的现象,内核会给出提示:

[PID:0 swapper] in_interrupt: 256, in_atomic 1, function as3604_tasklet_handler, line 1659
scheduling while atomic: swapper/0x00000100/0
bad: scheduling from the idle thread!
 
 
如果在tasklet中做了休眠动作,该tasklet仍然会被抢占,但是内核会给出提示,不建议在tasklet中加入延时的,应该尽快的处理完毕tasklet。

zImage magic = 0x016f2818
NOW, Booting Linux......
Uncompressing Linux................................................................................ done, booting the kernel.
Linux version 2.6.10 (xiewei@ibmGentoo) (gcc version 3.4.2 (release) (CodeSourcery ARM Q3 2004)) #37 Sun Oct 26 23:51:03 UTC 2008
CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)
CPU: D VIVT write-back cache
CPU: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Machine: SMDK2440
Warning: bad configuration page, trying to continue
Memory policy: ECC disabled, Data cache writeback
CPU S3C2442B (id 0x32440aab)
S3C2440: core 399.651 MHz, memory 133.217 MHz, peripheral 66.608 MHz
S3C2440 Clock control, (c) 2004 Simtec Electronics
Built 1 zonelists
Kernel command line: root=/dev/mtdblock/2 init=/linuxrc rootfstype=cramfs ro noinitrd console=ttySAC2,115200n8 mem=57M
irq: clearing subpending status 00000080
PID hash table entries: 256 (order: 8, 4096 bytes)
OK? timer tcon=00500000, tcnt 28a6, tcfg 00000f00,00000000, usec 0000170f
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 57MB = 57MB total
Memory: 55168KB available (1795K code, 615K data, 160K init)
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
S3C2440: Initialising architecture
Linux Plug and Play Support v0.97 (c) Adam Belay
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 65 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
rtc5372_REG_CTRL1=c0, rtc5372_REG_CTRL2=20
rtc5372_REG_CTRL1=c0, rtc5372_REG_CTRL2=20
i2c address 0x32 already in use.
i2c address 0x32 already in use.
as3604(chip id:0x33) detected.
[PID:1 swapper] in_interrupt: 65536, in_atomic 1, function as3604_irq_handler, line 1680
schedule_work(&as3604_work);
tasklet_schedule(&as3604_tasklet);
[PID:1 swapper] in_interrupt: 256, in_atomic 1, function as3604_tasklet_handler, line 1659
scheduling while atomic: swapper/0x00000100/1

[PID:3 events/0] in_interrupt: 0, in_atomic 0, function as3604_callback, line 1694
::hilbert:as3604 interrupt status = 0x12
Test number is 10
wake enabled for irq 0
S3C2440 DMA Driver, (c) 2003-2004 Simtec Electronics
DMA channel 0 at c4102000, irq 17
DMA channel 1 at c4102040, irq 18
DMA channel 2 at c4102080, irq 19
DMA channel 3 at c41020c0, irq 20
阅读(1596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~