All of lore.kernel.org
 help / color / mirror / Atom feed
From: Venkat Subbiah <vsubbiah@caviumnetworks.com>
To: "linux-rt-users@vger.kernel.org" <linux-rt-users@vger.kernel.org>
Subject: cond_resched_lock and __might_sleep
Date: Tue, 25 Oct 2011 13:45:22 -0700	[thread overview]
Message-ID: <4EA71FE2.6010904@caviumnetworks.com> (raw)

Hello,

I am back porting an RT patch from 2.6.33 version to 2.6.32 version and 
this question
is in that context. Thanks in advance for you reply!

cond_resched_lock() calls __might_sleep with PREEMPT_LOCK_OFFSET as 1. 
And  when
preempt count is equal to 0 it would print the warning like below.

Warning
--------
BUG: sleeping function called from invalid context at fs/jbd/commit.c:902
pcnt: 0 1 in_atomic(): 0, irqs_disabled(): 0, pid: 818, name: kjournald


Q1. Why is it ok for preempt_count to be 1 when irqs are disabled but not
when preempt_count is 1?

I am getting the warning above when 
cond_resched_lock(&journal->j_list_lock) is invoked from
journal_commit_transaction(journal_t *journal) in fs/jbd/commit.c:902


cond_resched_lock code
----------------------
#ifdef CONFIG_PREEMPT
#define PREEMPT_LOCK_OFFSET    PREEMPT_OFFSET
#else
#define PREEMPT_LOCK_OFFSET    0
#endif

#define cond_resched_lock(lock) ({                \
     __might_sleep(__FILE__, __LINE__, PREEMPT_LOCK_OFFSET);    \
     __cond_resched_lock(lock);                \
})

__might_sleep code
--------------------

void __might_sleep(char *file, int line, int preempt_offset)
{
#ifdef in_atomic
     static unsigned long prev_jiffy;    /* ratelimiting */

     if ((preempt_count_equals(preempt_offset) && !irqs_disabled()) ||
         system_state != SYSTEM_RUNNING || oops_in_progress)
         return;
     if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy)
         return;
     prev_jiffy = jiffies;

     printk(KERN_ERR
         "BUG: sleeping function called from invalid context at %s:%d\n",
.......
.......
}

preempt_count_equals() code
----------------------------

#if defined(CONFIG_DEBUG_SPINLOCK_SLEEP) || defined(CONFIG_DEBUG_PREEMPT)
static inline int preempt_count_equals(int preempt_offset)
{
     int nested = (preempt_count() & ~PREEMPT_ACTIVE);

#ifndef CONFIG_PREEMPT_RT
     nested += rcu_preempt_depth();
#endif

     return (nested == preempt_offset);
}
-Venkat




                 reply	other threads:[~2011-10-25 20:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4EA71FE2.6010904@caviumnetworks.com \
    --to=vsubbiah@caviumnetworks.com \
    --cc=linux-rt-users@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.