Question

When trying to log/debug an ISR, I've seen:

1) sprintf() used as example in 'O'Reilly Linux Device Drivers'

irqreturn_t short_interrupt(int irq, void *dev_id, struct pt_regs *regs)

{

    struct timeval tv;
    int written;

    do_gettimeofday(&tv);


    /* Write a 16 byte record. Assume PAGE_SIZE is a multiple of 16 */

    written = sprintf((char *)short_head,"%08u.%06u\n",

            (int)(tv.tv_sec % 100000000), (int)(tv.tv_usec));

    BUG_ON(written != 16);

    short_incr_bp(&short_head, written);

    wake_up_interruptible(&short_queue); /* awake any reading process */

    return IRQ_HANDLED;

}

unlike printf(), sprintf() write to memory instead of to console, and does not seem to have re-entrant or blocking issue, correct? but I've seen words against sprintf() on other forum. I am not sure if it's only because of its performance overhead, or else?

2) printk() is another one i've seen people used but blamed for, again performance issue (maybe nothing else?)

What is a generally good method/function to use when logging, or debugging ISR in Linux these days?

Was it helpful?

Solution

Regarding sprintf(). Do the search in any LXR site, for example here:

Freetext search: sprintf (4096 estimated hits)
drivers/video/mbx/mbxdebugfs.c, line 100 (100%)
drivers/isdn/hisax/q931.c, line 1207 (100%)
drivers/scsi/aic7xxx_old/aic7xxx_proc.c, line 141

I think this eliminates any doubts.

As for printk(), printk.h says:

/* If you are writing a driver, please use dev_dbg instead */

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top