All of lore.kernel.org
 help / color / mirror / Atom feed
* cond_resched_lock and __might_sleep
@ 2011-10-25 20:45 Venkat Subbiah
  0 siblings, 0 replies; only message in thread
From: Venkat Subbiah @ 2011-10-25 20:45 UTC (permalink / raw)
  To: linux-rt-users@vger.kernel.org

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-25 20:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-25 20:45 cond_resched_lock and __might_sleep Venkat Subbiah

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.