RE: User Level Threads implementation by Linux kernel

2010-03-03 Thread Gaurav Dhiman
Hi Ravi,

 

Find my inline responses.

 

From: kernelnewbies-bou...@nl.linux.org
[mailto:kernelnewbies-bou...@nl.linux.org] On Behalf Of ravikumar
Sent: Tuesday, March 02, 2010 4:20 PM
To: Kernel Newbies
Subject: User Level Threads implementation by Linux kernel

 

Hi all,

Currently I'm going through book 'development of Linux kernel' by Robert
Love.
In the chapter 'Process  Management' I read below sentence
"Linux has a unique implementation of threads: It does not differentiate
between threads and processes. To Linux, a thread is just a special kind
of process."
In kernel everything is a just task represented by  task_struct

And from some other sources I understand that there is a one-one mapping
between threads created by library API and kernel threads.

Now my questions are :
1. I have Program  and I've created two threads say T1 and T2 using
Posix Thread Library. see below
void* function2()
{
   while(1)
   {
printf("I'm Thread 2\n");
sleep(1);
   }
}
void* function1()
{
printf("I'm Thread 1\n");
char buf[1024];
read(1,buf,1023); // Thread 1 will block here
}
int main(int argc,char *argv[])
{

 pthread_t pid1,pid2;
 pthread_create(&pid1,NULL,function1,NULL);
 pthread_create(&pid2,NULL,function2,NULL);
 while(1)
 {
printf("I'm Main Thread\n");
sleep(1);
 }
}

   
According my understanding there will be three tasks will be created in
the kernel after I ran this program. One is for main process say P and
other two for T1 and T2.
And T1 & T2 share the address space of P. Is my understanding is
correct?


2.Regarding the scheduling.
Upon running the above program , the output is:
I'm Main Thread
I'm Thread 1
I'm Thread 2
I'm Main Thread
I'm Thread 2
I'm Main Thread
I'm Thread 2
I'm Main Thread
I'm Thread 2
I'm Main Thread
I'm Thread 2
Though Thread  1 is blocked Main Thread  and Thread 2 are still
running.
 That means different user-level threads are scheduled by kernel
separately.Is this correct ?

 

As per my understanding, yes, for every user thread kernel creates a
separate task_struct. In kernel, scheduling entity is task_struct, so
each user thread will be scheduled independently and will be given its
own time slice for execution. Scheduling will only happen on the
task_struct in run queue (in this case only main thread and thread 2 ,
not thread 1).


 If this is correct how time slices will be allocated?

   Do please some body clarify my questions  and also provide some good
links as references

   Thank you all

Regards,
Ravikumar




DISCLAIMER: 
---
 
The contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only.  
It shall not attach any liability on the originator or NECHCL or its 
affiliates. Any views or opinions presented in  
this email are solely those of the author and may not necessarily reflect the 
opinions of NECHCL or its affiliates.  
Any form of reproduction, dissemination, copying, disclosure, modification, 
distribution and / or publication of  
this message without the prior written consent of the author of this e-mail is 
strictly prohibited. If you have  
received this email in error please delete it and notify the sender 
immediately. . 
---

Re: User Level Threads implementation by Linux kernel

2010-03-03 Thread ravikumar


Sangman Kim wrote:

Hi Ravikumar,

**
And from some other sources I understand that there is a one-one
mapping between threads created by library API and kernel threads.


I think kernel threads here do not seem to indicate conventional 
kernel threads. There are kernel thread which handle interrupts, and 
there is user-context kernel code on behalf of user threads. I think 
what you are mentioning here is the latter, which is not regarded as 
kernel "thread," even though they are part of kernel.
 


Now my questions are :
1. I have Program  and I've created two threads say T1 and T2
using Posix Thread Library. see below
*void* function2()
{
   while(1)
   {
printf("I'm Thread 2\n");
sleep(1);
   }
}
void* function1()
{
printf("I'm Thread 1\n");
char buf[1024];
read(0,buf,1023); // Thread 1 will block here
}
int main(int argc,char *argv[])
{

 pthread_t pid1,pid2;
 pthread_create(&pid1,NULL,function1,NULL);
 pthread_create(&pid2,NULL,function2,NULL);
 while(1)
 {
printf("I'm Main Thread\n");
sleep(1);
 }
}

*  
According my understanding there will be three tasks will be

created in the kernel after I ran this program. One is for main
process say P and other two for T1 and T2.
And T1 & T2 share the address space of P. Is my understanding is
correct?


Yeah, that's correct. pthread_create() calls create_thread 
() 
in glibc, and the clone flag contains CLONE_VM flag in calling do_clone().



2.Regarding the scheduling. 




*read(0,buf,1023); // Thread 1 will block here

*The integer 1 for fd means reading standard output of itself, which 
usually does not make sense.
Even reading from stdin should stall at this point because it is 
synchronous read.
   Yes your correct 1 is for STDOUT , but I just wanted to block that 
thread  and just wanted to know  how threads will be scheduled.
   Thank you for valuable answers. Could you/somebody please share how 
user level thread scheduling will be done in the above example




Sangman


Thanks
Ravikumar



Re: BUG: scheduling while atomic

2010-03-03 Thread Mulyadi Santosa
Hi Vikash...

On Tue, Mar 2, 2010 at 1:14 PM, Vikash Kumar  wrote:
> Hi all,
>
> I am developing a raid system and I am getting following BUG when I
> issue lots of parallel IO.
> I am not able to figure out how to go about debugging this dump. It's
> evident here that RAID_LAZY_WRITE thread is trying to
> schedule while it has locked the CPU but I am not able to trace it
> exactly how and why it's happening.
> As I don't acquire any lock to issue IO to block layer.
>
> I enabled spin lock debugging and lock dependency checking so that I
> could get detailed debug info.
> Here is the whole dump which I got, please provide me tips, ideas on
> how to analyze and debug using
> this dump.

IMHO there are many possibilities here. The best thing to do here is
to check the related functions mentioned in the stack frames.

Are they really don't schedule while holding any locks on any
situations? Are they somekind of callbacks that must satisfy certain
kind of rules? Maybe it's like signal handler in user space which must
avoid reentrancy etc.

Sorry, this tip might sounds blurry for now, but this is the best idea
I can offer right now.

PS: When you mention "developing RAID system", do you mean "developing
RAID handling code"? Or simply implementing RAID
0/1/5/01/10/1+5/5+1/etc disk array?

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: Allocating memory with spinlock held

2010-03-03 Thread Manish Katiyar
On Thu, Mar 4, 2010 at 2:16 AM, Frederic Weisbecker  wrote:
> On Tue, Mar 02, 2010 at 09:32:16AM +0530, Manish Katiyar wrote:
>> Hello all,
>>
>> Is the following code valid ???
>>
>> foo() {
>> ...
>> spin_lock(lock);
>> ptr = kzalloc(size, GFP_KERNEL);
>> spin_unlock(lock);
>> .
>> }
>
>
>
> You can't because GFP_KERNEL involves the fact
> kzalloc might sleep while looking for memory
> somewhere (swapping out pages to get some free
> rooms).
>
> And sleeping while holding a spinlock may
> lead to a deadlock:
>
> Task A holds spinlock in cpu0. Task A sleeps.
> Task B is scheduled in cpu0, tries to take the
> spinlock and then deadlock for ever.
>
> You can use GFP_ATOMIC instead, but it's usually
> not recommended as the GFP_ATOMIC pool is a pretty
> limited resource.

Hi,

Thanks for the clarification. That is what I had suspected too and
wanted to clarify.

>
> The best is to allocate before you take the spinlock.
Yes, that is what I ended coding up.

Thanks again -
Manish
>
>



-- 
Thanks -
Manish
==
[$\*.^ -- I miss being one of them
==

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: User Level Threads implementation by Linux kernel

2010-03-03 Thread Sangman Kim
Hi Ravikumar,

* *
> And from some other sources I understand that there is a one-one mapping
> between threads created by library API and kernel threads.
>
>
I think kernel threads here do not seem to indicate conventional kernel
threads. There are kernel thread which handle interrupts, and there is
user-context kernel code on behalf of user threads. I think what you are
mentioning here is the latter, which is not regarded as kernel "thread,"
even though they are part of kernel.


> Now my questions are :
> 1. I have Program  and I've created two threads say T1 and T2 using Posix
> Thread Library. see below
> *void* function2()
> {
>while(1)
>{
> printf("I'm Thread 2\n");
> sleep(1);
>}
> }
> void* function1()
> {
> printf("I'm Thread 1\n");
> char buf[1024];
> read(1,buf,1023); // Thread 1 will block here
> }
> int main(int argc,char *argv[])
> {
>
>  pthread_t pid1,pid2;
>  pthread_create(&pid1,NULL,function1,NULL);
>  pthread_create(&pid2,NULL,function2,NULL);
>  while(1)
>  {
> printf("I'm Main Thread\n");
> sleep(1);
>  }
> }
>
> *
> According my understanding there will be three tasks will be created in the
> kernel after I ran this program. One is for main process say P and other two
> for T1 and T2.
> And T1 & T2 share the address space of P. Is my understanding is correct?
>
>
Yeah, that's correct. pthread_create() calls
create_thread()
in glibc, and the clone flag contains CLONE_VM flag in calling do_clone().


> 2.Regarding the scheduling.
>


*read(1,buf,1023); // Thread 1 will block here

*The integer 1 for fd means reading standard output of itself, which usually
does not make sense.
Even reading from stdin should stall at this point because it is synchronous
read.

Sangman


Re: Allocating memory with spinlock held

2010-03-03 Thread Matthias Kaehlcke
El Wed, Mar 03, 2010 at 11:14:35AM +0530 Manish Katiyar ha dit:

> Hello all,
> 
> Is the following code valid ???
> 
> foo() {
> ...
> spin_lock(lock);
> ptr = kzalloc(size, GFP_KERNEL);
> spin_unlock(lock);
> .
> }
> 
> 
> I guess the answer is no, but would like to confirm. Detailed/all
> possible reasons for not doing so are welcome. IIRC, I was getting a
> kernel crash with similar code with error message as "spinlock bug :
> unlocked on wrong CPU" which looked like it was getting locked on one
> cpu and due to memory allocation was getting unlocked from another
> cpu.

preemption is disabled when a spinlock is held. memory allocation can
cause the current process to be scheduled out if the requested amount
of memory isn't available immediately, but preemption is disabled due
to the spinlock.

if you *really* need to allocate memory while holding the spinlock you
must use GFP_ATOMIC instead of GFP_KERNEL, but remember that the
allocation can fail and thus you must check the return value

best regards

-- 
Matthias Kaehlcke
Embedded Linux Developer
Barcelona

   For to be free is not merely to cast off
   one's chains, but to live in a way that
  respects and enhances the freedom of others
   (Nelson Mandela)
 .''`.
using free software / Debian GNU/Linux | http://debian.org  : :'  :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4  `-

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



User Level Threads implementation by Linux kernel

2010-03-03 Thread ravikumar

Hi all,

Currently I'm going through book 'development of Linux kernel' by Robert 
Love.

In the chapter 'Process  Management' I read below sentence
"Linux has a unique implementation of threads: It does not differentiate 
between threads and processes. To Linux, a thread is just a special kind 
of process."

In kernel everything is a just task represented by  *task_struct
*
And from some other sources I understand that there is a one-one mapping 
between threads created by library API and kernel threads.


Now my questions are :
1. I have Program  and I've created two threads say T1 and T2 using 
Posix Thread Library. see below

   *void* function2()
{
  while(1)
  {
   printf("I'm Thread 2\n");
   sleep(1);
  }
}
void* function1()
{
   printf("I'm Thread 1\n");
   char buf[1024];
   read(1,buf,1023); // Thread 1 will block here
}
int main(int argc,char *argv[])
{

pthread_t pid1,pid2;
pthread_create(&pid1,NULL,function1,NULL);
pthread_create(&pid2,NULL,function2,NULL);
while(1)
{
   printf("I'm Main Thread\n");
   sleep(1);
}
}

*  
According my understanding there will be three tasks will be created in 
the kernel after I ran this program. One is for main process say P and 
other two for T1 and T2.

And T1 & T2 share the address space of P. Is my understanding is correct?


2.Regarding the scheduling.
   Upon running the above program , the output is:
*I'm Main Thread
   I'm Thread 1
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
*Though Thread  1 is blocked Main Thread  and Thread 2 are still 
running.
That means different user-level threads are scheduled by kernel 
separately.Is this correct ?

If this is correct how time slices will be allocated?

  Do please some body clarify my questions  and also provide some good 
links as references


  Thank you all

Regards,
Ravikumar


Kernel tunnel driver and routing?

2010-03-03 Thread Robin Gilks
Greetings

I put a question mark at the end of the subject line because I'm not sure
if the problem I have is to do with routing or not... First of all, define
the problem.

I'm using the tun driver within an application that opens a tunnel and
reads encapsulated data from the tunnel, munges it about (as applications
do!!) and then sends the reply back down the tunnel.

So far, I can open the tunnel and read data but the send data seems to
just disappear. Looking at ifconfig I see the send packet count and the
send byte counts increment but nothing traced on my wireshark monitor:-(

I've so far tried 3 methods of handling the IP/IP encap  data, all of
which have problems - the tun driver is what I'd prefer.

1. a raw-ip socket opened with a protocol value of 4 (IPIP encap type).
This receives and transmits the data OK but it appears that the socket is
not an exclusive listener because the encap'ed packets result in ICMP
messages being returned to the originator of the tunnel.

2. opening a socket and then doing an SIOCADDTUNNEL ioctl on it to create
a tunnel. There are no failures but my application doesn't receive any
data so it never sends anything!! ifconfig indicates RX packets and data
count but no idea where they go!

3. using the tun device as per the example in tuntap.txt. This is the one
that receives but doesn't transmit. I have notices that 'ip link' reports
that the encap type is ppp but I haven't found a way of changing that yet.

I've spent over 100 hours on this now, I seem to have read the iproute2
and iptables code a dozen times but still no further in understanding what
is going on...

-- 
Robin Gilks zl3rob/g8ecj
Internet: g8...@gilks.orghttp://www.gilks.org




--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Allocating memory with spinlock held

2010-03-03 Thread Manish Katiyar
Hello all,

Is the following code valid ???

foo() {
...
spin_lock(lock);
ptr = kzalloc(size, GFP_KERNEL);
spin_unlock(lock);
.
}


I guess the answer is no, but would like to confirm. Detailed/all
possible reasons for not doing so are welcome. IIRC, I was getting a
kernel crash with similar code with error message as "spinlock bug :
unlocked on wrong CPU" which looked like it was getting locked on one
cpu and due to memory allocation was getting unlocked from another
cpu.

-- 
Thanks -
Manish
==
[$\*.^ -- I miss being one of them
==

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



User Level Threads implementation by Linux kernel

2010-03-03 Thread ravikumar

Hi all,

Currently I'm going through book 'development of Linux kernel' by Robert 
Love.

In the chapter 'Process  Management' I read below sentence
"Linux has a unique implementation of threads: It does not differentiate 
between threads and processes. To Linux, a thread is just a special kind 
of process."

In kernel everything is a just task represented by  *task_struct
*
And from some other sources I understand that there is a one-one mapping 
between threads created by library API and kernel threads.


Now my questions are :
1. I have Program  and I've created two threads say T1 and T2 using 
Posix Thread Library. see below

   *void* function2()
{
  while(1)
  {
   printf("I'm Thread 2\n");
   sleep(1);
  }
}
void* function1()
{
   printf("I'm Thread 1\n");
   char buf[1024];
   read(1,buf,1023); // Thread 1 will block here
}
int main(int argc,char *argv[])
{

pthread_t pid1,pid2;
pthread_create(&pid1,NULL,function1,NULL);
pthread_create(&pid2,NULL,function2,NULL);
while(1)
{
   printf("I'm Main Thread\n");
   sleep(1);
}
}

*  
According my understanding there will be three tasks will be created in 
the kernel after I ran this program. One is for main process say P and 
other two for T1 and T2.

And T1 & T2 share the address space of P. Is my understanding is correct?


2.Regarding the scheduling.
   Upon running the above program , the output is:
*I'm Main Thread
   I'm Thread 1
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
   I'm Main Thread
   I'm Thread 2
*Though Thread  1 is blocked Main Thread  and Thread 2 are still 
running.
That means different user-level threads are scheduled by kernel 
separately.Is this correct ?

If this is correct how time slices will be allocated?

  Do please some body clarify my questions  and also provide some good 
links as references


  Thank you all

Regards,
Ravikumar



BUG: scheduling while atomic

2010-03-03 Thread Vikash Kumar
Hi all,

I am developing a raid system and I am getting following BUG when I
issue lots of parallel IO.
I am not able to figure out how to go about debugging this dump. It's
evident here that RAID_LAZY_WRITE thread is trying to
schedule while it has locked the CPU but I am not able to trace it
exactly how and why it's happening.
As I don't acquire any lock to issue IO to block layer.

I enabled spin lock debugging and lock dependency checking so that I
could get detailed debug info.
Here is the whole dump which I got, please provide me tips, ideas on
how to analyze and debug using
this dump.


BUG: scheduling while atomic: RAID_LAZY_WRITE/102/0x0205
no locks held by RAID_LAZY_WRITE/102.

Showing all locks held in the system:

=

Pid: 102, comm:  RAID_LAZY_WRITE
CPU: 0Not tainted  (2.6.24 #274)
PC is at add_preempt_count+0xa0/0xbc
LR is at raid_write_stripe+0x388/0x544
pc : []lr : []psr: 8013
sp : cfc63ec4  ip : cfc63ed4  fp : cfc63ed0
r10: cf5ce118  r9 : 0001  r8 : 00b4
r7 : 0001  r6 : cf403cd8  r5 : cfc62000  r4 : 0002
r3 : 0001  r2 : 0001  r1 : cfc62000  r0 : 0001
Flags: Nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
Control: 397f  Table: 0f558000  DAC: 0017
[] (show_regs+0x0/0x4c) from [] (__schedule_bug+0x54/0x68)
 r4:cfc9b0a0
[] (__schedule_bug+0x0/0x68) from [] (schedule+0x74/0x2f4)
 r5:cfc9b0a0 r4:c034d13c
[] (schedule+0x0/0x2f4) from [] (io_schedule+0x30/0x54)
[] (io_schedule+0x0/0x54) from []
(get_request_wait+0xac/0x140)
 r4:
[] (get_request_wait+0x0/0x140) from []
(__make_request+0x478/0x544)
[] (__make_request+0x0/0x544) from []
(generic_make_request+0x2a8/0x2f0)
[] (generic_make_request+0x0/0x2f0) from []
(raid_submit_disk_io+0x348/0x37c)
[] (raid_submit_disk_io+0x0/0x37c) from []
(perform_raid5_ops+0xdc8/0x1100)
[] (perform_raid5_ops+0x0/0x1100) from []
(raid5_RCW_postXOR+0x438/0x4c4)
[] (raid5_RCW_postXOR+0x0/0x4c4) from []
(raid5_xor_completed+0x2a4/0x3b0)
[] (raid5_xor_completed+0x0/0x3b0) from []
(iop_adma_run_tx_complete_actions+0x64/0xe8)
[] (iop_adma_run_tx_complete_actions+0x0/0xe8) from
[] (__iop_adma_slot_cleanup+0x2f8/0x3c0)
 r8:c0352f24 r7: r6: r5: r4:cf4faa7c
[] (__iop_adma_slot_cleanup+0x0/0x3c0) from []
(iop_adma_tasklet+0x10/0x14)
[] (iop_adma_tasklet+0x0/0x14) from []
(run_timer_softirq+0x17c/0x208)
[] (run_timer_softirq+0x0/0x208) from []
(__do_softirq+0x64/0xd0)
[] (__do_softirq+0x0/0xd0) from [] (irq_exit+0x48/0x5c)
[] (irq_exit+0x0/0x5c) from []
(__exception_text_start+0x48/0x60)
[] (__exception_text_start+0x0/0x60) from []
(__irq_svc+0x50/0x7c)
Exception stack(0xcfc63e7c to 0xcfc63ec4)
3e60:0001
3e80: cfc62000 0001 0001 0002 cfc62000 cf403cd8 0001 00b4
3ea0: 0001 cf5ce118 cfc63ed0 cfc63ed4 cfc63ec4 c015a83c c004b014 8013
3ec0: 
 r6:0020 r5:cfc63eb0 r4:
[] (add_preempt_count+0x0/0xbc) from []
(raid_write_stripe+0x388/0x544)
[] (raid_write_stripe+0x0/0x544) from []
(raid_lazy_writer+0x4c4/0x6b8)
[] (raid_lazy_writer+0x0/0x6b8) from []
(raid_thread_daemon+0x140/0x15c)
[] (raid_thread_daemon+0x0/0x15c) from []
(kthread+0x58/0x90)
[] (kthread+0x0/0x90) from [] (do_exit+0x0/0x764)
 r6: r5: r4:


BUG: spinlock cpu recursion on CPU#0, RAID_DAEMON/101
 lock: cf4faae0, .magic: dead4ead, .owner: RAID_LAZY_WRITE/102, .owner_cpu: 0
[] (dump_stack+0x0/0x14) from [] (spin_bug+0x90/0xa4)
[] (spin_bug+0x0/0xa4) from [] (_raw_spin_lock+0x68/0x15c)
 r5:c01fb378 r4:cf4faae0
[] (_raw_spin_lock+0x0/0x15c) from []
(_spin_lock_bh+0x4c/0x54)
[] (_spin_lock_bh+0x0/0x54) from []
(iop_adma_run_tx_complete_actions+0x38/0xe8)
 r5: r4:cf4faa7c
[] (iop_adma_run_tx_complete_actions+0x0/0xe8) from
[] (__iop_adma_slot_cleanup+0x2f8/0x3c0)
 r8:0001 r7: r6: r5: r4:cf4faa7c
[] (__iop_adma_slot_cleanup+0x0/0x3c0) from []
(iop_adma_tasklet+0x10/0x14)
[] (iop_adma_tasklet+0x0/0x14) from []
(tasklet_action+0x8c/0xe4)
[] (tasklet_action+0x0/0xe4) from []
(__do_softirq+0x64/0xd0)
 r6:000a r5:0001 r4:c0351f44
[] (__do_softirq+0x0/0xd0) from [] (irq_exit+0x48/0x5c)
[] (irq_exit+0x0/0x5c) from []
(__exception_text_start+0x48/0x60)
[] (__exception_text_start+0x0/0x60) from []
(__irq_svc+0x50/0x7c)
Exception stack(0xcfcb1e64 to 0xcfcb1eac)
1e60:  cf652404 0001  0001 cf652404 4013 c0417bec
1e80: 7fff cea81d88  cf6523e0 cfcb1ec0 cfcb1eac cfcb1eac c0298d00
1ea0: c0298d04 6013 
 r6:0064 r5:cfcb1e98 r4:
[] (_spin_unlock_irqrestore+0x0/0x54) from []
(raid_read_stripe+0x204/0x560)
 r5:0008 r4:cf652404
[] (raid_read_stripe+0x0/0x560) from []
(raid_daemon+0x1d4/0x1110)
[] (raid_daemon+0x0/0x1110) from []
(raid_thread_daemon+0x140/0x15c)
[] (raid_thread_daemon+0x0/0x15c) from []
(kthread+0x58/0x90)
[] (kthread+0x0/0x90) from [] (do_ex

Re: Allocating memory with spinlock held

2010-03-03 Thread Frederic Weisbecker
On Tue, Mar 02, 2010 at 09:32:16AM +0530, Manish Katiyar wrote:
> Hello all,
> 
> Is the following code valid ???
> 
> foo() {
> ...
> spin_lock(lock);
> ptr = kzalloc(size, GFP_KERNEL);
> spin_unlock(lock);
> .
> }



You can't because GFP_KERNEL involves the fact
kzalloc might sleep while looking for memory
somewhere (swapping out pages to get some free
rooms).

And sleeping while holding a spinlock may
lead to a deadlock:

Task A holds spinlock in cpu0. Task A sleeps.
Task B is scheduled in cpu0, tries to take the
spinlock and then deadlock for ever.

You can use GFP_ATOMIC instead, but it's usually
not recommended as the GFP_ATOMIC pool is a pretty
limited resource.

The best is to allocate before you take the spinlock.


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Allocating memory with spinlock held

2010-03-03 Thread Manish Katiyar
Hello all,

Is the following code valid ???

foo() {
...
spin_lock(lock);
ptr = kzalloc(size, GFP_KERNEL);
spin_unlock(lock);
.
}


I guess the answer is no, but would like to confirm. Detailed/all
possible reasons for not doing so are welcome. IIRC, I was getting a
kernel crash with similar code with error message as "spinlock bug :
unlocked on wrong CPU" which looked like it was getting locked on one
cpu and due to memory allocation was getting unlocked from another
cpu.

-- 
Thanks -
Manish
==
[$\*.^ -- I miss being one of them
==

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: UTS Version

2010-03-03 Thread Mulyadi Santosa
Hi...

On Tue, Mar 2, 2010 at 10:15 PM, Arigead  wrote:
> I'm getting an error on the UTS Version. I've been searching on the
> internet and there is a fix posted on a mailing list for this problem on
> a 2.6.18 kernel but the fix, editing a file, does not correspond to the
> file I have in my linux source tree for 2.6.33.

I am not sure what UTS really means, but I have strong sense it is related to:
CONFIG_LOCALVERSION=
we usually see in .config file found in top directory of kernel source
tree after you do initial make *config.

I suggest try to edit that line and change into something like:
CONFIG_LOCALVERSION="-custom"
and see if it works.

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ