Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #8181 > unrolled thread
| Started by | fl <rxjwg98@gmail.com> |
|---|---|
| First post | 2013-05-19 10:11 -0700 |
| Last post | 2013-05-19 20:58 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.os.linux.misc
An interrupt handler can call function sprintf()? fl <rxjwg98@gmail.com> - 2013-05-19 10:11 -0700
Re: An interrupt handler can call function sprintf()? Jerry Peters <jerry@example.invalid> - 2013-05-19 20:38 +0000
Re: An interrupt handler can call function sprintf()? Jerry Peters <jerry@example.invalid> - 2013-05-19 20:58 +0000
| From | fl <rxjwg98@gmail.com> |
|---|---|
| Date | 2013-05-19 10:11 -0700 |
| Subject | An interrupt handler can call function sprintf()? |
| Message-ID | <6c25f801-621d-4484-a3b2-f5cc4491a4a6@googlegroups.com> |
Hi,
I remember it said that C lib function printf() cannot be called in a device driver in Linux. Today I come across the following code snippet. I wonder that sprintf function can be called in the interrupt function?
Interrupt function is part of device driver or not?
Please clarify those concepts if you can. Thanks.
......
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;
}
[toc] | [next] | [standalone]
| From | Jerry Peters <jerry@example.invalid> |
|---|---|
| Date | 2013-05-19 20:38 +0000 |
| Message-ID | <knbd90$qbd$1@dont-email.me> |
| In reply to | #8181 |
fl <rxjwg98@gmail.com> wrote:
> Hi,
>
> I remember it said that C lib function printf() cannot be called in a device driver in Linux. Today I come across the following code snippet. I wonder that sprintf function can be called in the interrupt function?
>
It can't, because it writes to a file, stdout. Sprintf "writes" to an
existing string so there's no i/o. Sprintf is just a convenient way to
construct a fancy formatted string.
There is another function, kprintf, which can be used similiarly to
printf, but it wrties to a kernel buffer.
Jerry
> Interrupt function is part of device driver or not?
>
> Please clarify those concepts if you can. Thanks.
>
>
>
>
>
>
> ......
> 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;
> }
[toc] | [prev] | [next] | [standalone]
| From | Jerry Peters <jerry@example.invalid> |
|---|---|
| Date | 2013-05-19 20:58 +0000 |
| Message-ID | <knbee5$a4f$1@dont-email.me> |
| In reply to | #8182 |
Jerry Peters <jerry@example.invalid> wrote: > fl <rxjwg98@gmail.com> wrote: >> Hi, >> >> I remember it said that C lib function printf() cannot be called in a device driver in Linux. Today I come across the following code snippet. I wonder that sprintf function can be called in the interrupt function? >> > It can't, because it writes to a file, stdout. Sprintf "writes" to an > existing string so there's no i/o. Sprintf is just a convenient way to > construct a fancy formatted string. > > There is another function, kprintf, which can be used similiarly to > printf, but it wrties to a kernel buffer. Oops, meant printk, not kprintf. Jerry
[toc] | [prev] | [standalone]
Back to top | Article view | comp.os.linux.misc
csiph-web