On 4/23/06, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote: > Hi... > > Don't forget to CC to kernelnewbies too.... Our discussion will be > archieved, so someone else can learn something from this in the future. > > > BTW, my kernel is linux-2.4.18 with preempt patch, and these code > > runs on an ARM board. > > Hm...ARM. OK, just FYI, I know nothing about ARM, all I say previously > and now are based on x86 32 bit, so some assumptions might be wrong. > > > like this: > > 532 spinlock_t my_lock = SPIN_LOCK_UNLOCKED; > > 533 > > 534 void dummy_loop() > > 535 { > > 536 pid_t mypid = current->pid; > > 537 unsigned long long i; > > 538 for (i = 0; i < 1000; i++) { > > 539 spin_lock(&my_lock); > > 540 printk("thread %d, loop: %u " > > 541 ,mypid,i); > > 542 printk("jiffies: %u, time slice: %d\n" > > 543 ,jiffies,current->counter); > > 544 spin_unlock(&my_lock); > > 545 } > > 546 printk("this is thread %d, total: > > %u\n",current->pid,i); > > 547 for (;;); > > 548 } > > Hm..very strange. Somehow, if we grab spin lock, pid is printed > consistently. And you said, you patch your kernel with preempt patch. > This made me suspect....could this be a bug inside that preempt patch? > > > I print loop number and I expect to see it prints > > > > 139 thread 11, loop: 21 jiffies: 113, time slice: 2 > > 140 thread 11, loop: 22 jiffies: 113, time slice: 2 > > 141 thread 11, loop: 23 jiffies: 113, time slice: 2 > > 142 thread 11, loop: 24 jiffies: 114, time slice: 1 > > 143 thread 11, loop: 25 jiffies: 114, time slice: 1 > > 144 thread 10, loop: 20 jiffies: 115, time slice: 6 > > 145 thread 10, loop: 21 jiffies: 115, time slice: 6 > > 146 thread 10, loop: 22 jiffies: 116, time slice: 5 > You are getting the right output. See when the timeslice of thread 11 expires at taht time the value of its local loop variable was 25 and then the scheduler switcehd the CPU to another process, which is thread 10 and then you start prining the local loop variable of that thread which was at 20 for that loop, which you must have left when that thread 10 was last executed. So preemption is taking place. Hope it helps. Gaurav What? "loop" goes to 25 and then goes back to 20? How come? BTW, how > many kernel thread did you make? 1? 2? More? Can you paste your entire > code please? This guessing game isn't effective at all. > > > regards, > > Mulyadi > > -- -- -Gaurav Email: gauravd.chd@xxxxxxxxx --------------------------------- Read my blog at: http://lkdp.blogspot.com/ --------------------------------- -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/