kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: dhylands@gmail.com (Dave Hylands)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Calling printk with locks held
Date: Thu, 2 Jun 2011 15:54:56 -0700	[thread overview]
Message-ID: <BANLkTim0sHfM4ZewJNN1vrQYQLf1Uvp5XA@mail.gmail.com> (raw)
In-Reply-To: <BANLkTim4iXf79fnUswpEDdgZ5rQ7RfOFjA@mail.gmail.com>

Hi Neil,

On Thu, Jun 2, 2011 at 1:43 PM, Neil Baylis <neil.baylis@gmail.com> wrote:
> I've just been told that it's not OK to call printk while holding a lock.
> This came as a surprise to me, as I've written thousands of lines of code
> that calls printk while holding multiple locks, and have not seen any
> problem. The only explanation I was given was that it can deadlock.
> Is this correct? I thought there were very few places where it was not safe
> to call printk.

In general I don't think that there's any issue with calling printk
with locks held. If the lock was held within the console driver using
to send the printk data you might have trouble. I know its fine (but
not recommended for performance reasons) to call printk from interrupt
context.

printk uses the "try" variant on its own locks and if it can't get
that lock then it just adds the data to its internal buffer and
doesn't try to output anything.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

      parent reply	other threads:[~2011-06-02 22:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02 20:43 Calling printk with locks held Neil Baylis
2011-06-02 22:45 ` Mulyadi Santosa
2011-06-02 22:54 ` Dave Hylands [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTim0sHfM4ZewJNN1vrQYQLf1Uvp5XA@mail.gmail.com \
    --to=dhylands@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).