UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2018-10-16 03:50 PM

useless79
Member
Registered: 2011-10-10
Posts: 32

why interrupts are not getting generated?

Hi ALL,

Following code is not generating interrupts on my Debian system, instead below message erupts on interrupt generation.

do_IRQ: 3.59 No irq handler for vector (irq -1)

My Debian machine has 3.16.51-2 Linux kernel.
Can any one help me to understand the behavior and fix?

ideally the program should generate interrupt IRQ11 when device file is read using   sudo cat /dev/etx_Dev

the same program is running on Debian 9 which has newer kernel version 4.9.x with proper irq handling.

#include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kdev_t.h>
    #include <linux/fs.h>
    #include <linux/cdev.h>
    #include <linux/device.h>
    #include<linux/slab.h>                 
    #include<linux/uaccess.h>           
    #include<linux/sysfs.h> 
    #include<linux/kobject.h> 
    #include <linux/interrupt.h>
    #include <asm/io.h>
     
    #define IRQ_NO 11
     
    //Interrupt handler for IRQ 11. 
     
    static irqreturn_t irq_handler(int irq,void *dev_id) {
      printk(KERN_ERR "Shared IRQ: Interrupt Occurred");
      return IRQ_HANDLED;
    }
     
     
    volatile int etx_value = 0;
     
     
    dev_t dev = 0;
    static struct class *dev_class;
    static struct cdev etx_cdev;
    struct kobject *kobj_ref;
     
    static int __init etx_driver_init(void);
    static void __exit etx_driver_exit(void);
     
    /*************** Driver Fuctions **********************/
    static int etx_open(struct inode *inode, struct file *file);
    static int etx_release(struct inode *inode, struct file *file);
    static ssize_t etx_read(struct file *filp, 
                    char __user *buf, size_t len,loff_t * off);
    static ssize_t etx_write(struct file *filp, 
                    const char *buf, size_t len, loff_t * off);
     
    /*************** Sysfs Fuctions **********************/
    static ssize_t sysfs_show(struct kobject *kobj, 
                    struct kobj_attribute *attr, char *buf);
    static ssize_t sysfs_store(struct kobject *kobj, 
                    struct kobj_attribute *attr,const char *buf, size_t count);
     
    struct kobj_attribute etx_attr = __ATTR(etx_value, 0660, sysfs_show, sysfs_store);
     
    static struct file_operations fops =
    {
            .owner          = THIS_MODULE,
            .read           = etx_read,
            .write          = etx_write,
            .open           = etx_open,
            .release        = etx_release,
    };
     
    static ssize_t sysfs_show(struct kobject *kobj, 
                    struct kobj_attribute *attr, char *buf)
    {
            printk(KERN_ERR "Sysfs - Read!!!\n");
            return sprintf(buf, "%d", etx_value);
    }
     
    static ssize_t sysfs_store(struct kobject *kobj, 
                    struct kobj_attribute *attr,const char *buf, size_t count)
    {
            printk(KERN_ERR "Sysfs - Write!!!\n");
            sscanf(buf,"%d",&etx_value);
            return count;
    }
     
    static int etx_open(struct inode *inode, struct file *file)
    {
            printk(KERN_ERR "Device File Opened...!!!\n");
            return 0;
    }
     
    static int etx_release(struct inode *inode, struct file *file)
    {
            printk(KERN_ERR "Device File Closed...!!!\n");
            return 0;
    }
     
    static ssize_t etx_read(struct file *filp, 
                    char __user *buf, size_t len, loff_t *off)
    {
            printk(KERN_ERR "Read function\n");
            asm("int $0x3B");  // Corresponding to irq 11
            return 0;
    }
    static ssize_t etx_write(struct file *filp, 
                    const char __user *buf, size_t len, loff_t *off)
    {
            printk(KERN_ERR "Write Function\n");
            return 0;
    }
     
     
    static int __init etx_driver_init(void)
    {
            printk(KERN_ERR "my_device: in etx_driver_init... ");
            /*Allocating Major number*/
            if((alloc_chrdev_region(&dev, 0, 1, "etx_Dev")) <0){
                    printk(KERN_ERR "Cannot allocate major number\n");
                    return -1;
            }
            printk(KERN_ERR "Major = %d Minor = %d \n",MAJOR(dev), MINOR(dev));
     
            /*Creating cdev structure*/
            cdev_init(&etx_cdev,&fops);
     
            /*Adding character device to the system*/
            if((cdev_add(&etx_cdev,dev,1)) < 0){
                printk(KERN_ERR "Cannot add the device to the system\n");
                goto r_class;
            }
     
            /*Creating struct class*/
            if((dev_class = class_create(THIS_MODULE,"etx_class")) == NULL){
                printk(KERN_ERR "Cannot create the struct class\n");
                goto r_class;
            }
     
            /*Creating device*/
            if((device_create(dev_class,NULL,dev,NULL,"etx_device")) == NULL){
                printk(KERN_ERR "Cannot create the Device 1\n");
                goto r_device;
            }
     
            /*Creating a directory in /sys/kernel/ */
            kobj_ref = kobject_create_and_add("etx_sysfs",kernel_kobj);
     
            /*Creating sysfs file for etx_value*/
            if(sysfs_create_file(kobj_ref,&etx_attr.attr)){
                    printk(KERN_ERR"Cannot create sysfs file......\n");
                    goto r_sysfs;
            }
            printk(KERN_ERR "my_device: calling request_irq... ");
            if (request_irq(IRQ_NO, irq_handler, IRQF_SHARED, "etx_device", (void *)(irq_handler))) {
                printk(KERN_ERR "my_device: cannot register IRQ ");
                        goto irq;
            }
            printk(KERN_ERR "Device Driver Insert...Done!!!\n");
        return 0;
     
    irq:
            free_irq(IRQ_NO,(void *)(irq_handler));
     
    r_sysfs:
            kobject_put(kobj_ref); 
            sysfs_remove_file(kernel_kobj, &etx_attr.attr);
     
    r_device:
            class_destroy(dev_class);
    r_class:
            unregister_chrdev_region(dev,1);
            cdev_del(&etx_cdev);
            return -1;
    }
     
    void __exit etx_driver_exit(void)
    {
            free_irq(IRQ_NO,(void *)(irq_handler));
            kobject_put(kobj_ref); 
            sysfs_remove_file(kernel_kobj, &etx_attr.attr);
            device_destroy(dev_class,dev);
            class_destroy(dev_class);
            cdev_del(&etx_cdev);
            unregister_chrdev_region(dev, 1);
            printk(KERN_ERR "Device Driver Remove...Done!!!\n");
    }
     
    module_init(etx_driver_init);
    module_exit(etx_driver_exit);
[email protected]:/home/ravi/cprog/>cat /proc/interrupts 
            CPU0       CPU1       CPU2       CPU3       
   0:         23          0          0          0  IR-IO-APIC-edge      timer
   1:       3568          0          0          0  IR-IO-APIC-edge      i8042
   8:          1          0          0          0  IR-IO-APIC-edge      rtc0
   9:   53291962          0          0          0  IR-IO-APIC-fasteoi   acpi
  11:          0          0          0          0  IR-IO-APIC-edge      etx_device
  12:     111320          0          0          0  IR-IO-APIC-edge      i8042
  16:         33          0          0          0  IR-IO-APIC-fasteoi   ehci_hcd:usb3
  17:         11          0          0          0  IR-IO-APIC-fasteoi 
  18:          0          0          0          0  IR-IO-APIC-fasteoi   ata_generic, i801_smbus
  19:          2          0          0          0  IR-IO-APIC-fasteoi   firewire_ohci
  20:     429103          0          0          0  IR-IO-APIC-fasteoi   eth0
  23:         35          0          0          0  IR-IO-APIC-fasteoi   ehci_hcd:usb4
  36:        980          0          0          0  IR-IO-APIC-fasteoi   snd_hda_intel
  64:          0          0          0          0  DMAR_MSI-edge      dmar0
  65:     416536          0          0          0  IR-PCI-MSI-edge      eth1
  66:          0          0          0          0  IR-PCI-MSI-edge      xhci_hcd
  67:          0          0          0          0  IR-PCI-MSI-edge      xhci_hcd
  68:          0          0          0          0  IR-PCI-MSI-edge      xhci_hcd
  69:          0          0          0          0  IR-PCI-MSI-edge      xhci_hcd
  70:          0          0          0          0  IR-PCI-MSI-edge      xhci_hcd
  71:          1          0          0          0  IR-PCI-MSI-edge      isci-msix
  72:          0          0          0          0  IR-PCI-MSI-edge      isci-msix
  73:      68826          0          0          0  IR-PCI-MSI-edge      ahci
  74:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  75:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  76:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  77:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  78:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  79:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  80:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  81:          2          0          0          0  IR-PCI-MSI-edge      ioat-msix
  82:         24          0          0          0  IR-PCI-MSI-edge      mei_me
  83:     173557          0          0          0  IR-PCI-MSI-edge      nouveau
  84:        339          0          0          0  IR-PCI-MSI-edge      snd_hda_intel
 NMI:        284         17         18         18   Non-maskable interrupts
 LOC:     782976     574541     745413     563495   Local timer interrupts
 SPU:          0          0          0          0   Spurious interrupts
 PMI:        284         17         18         18   Performance monitoring interrupts
 IWI:          1          0          0          0   IRQ work interrupts
 RTR:          0          0          0          0   APIC ICR read retries
 RES:      23038       6172       8407       5291   Rescheduling interrupts
 CAL:       1318      37438      39630      45364   Function call interrupts
 TLB:       1703        466        604        436   TLB shootdowns
 TRM:          0          0          0          0   Thermal event interrupts
 THR:          0          0          0          0   Threshold APIC interrupts
 MCE:          0          0          0          0   Machine check exceptions
 MCP:         11         11         11         11   Machine check polls
 HYP:          0          0          0          0   Hypervisor callback interrupts
 ERR:          0
 MIS:          0

Edit: Added code tags.

Last edited by i3839 (2018-10-17 07:49 PM)

Offline

#2 2018-10-17 07:55 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: why interrupts are not getting generated?

What is your dmesg output? And is this a real machine or a virtual machine?

Maybe the IRQ API changed between kernel 3 and 4.

Or it is not actually the kernel version difference that matters, but the hardware you are testing on.

Offline

Board footer

Powered by FluxBB