Re: Problems understanding this piece of code...

2010-03-29 Thread Gary Jennejohn
On Mon, 29 Mar 2010 00:06:49 -0400
Sergio Andr__s G__mez del Real sergio.g.delr...@gmail.com wrote:

 Hi.
 I can't seem to understand this piece of i386 boot code:
 What I understand is that BIOS loads MBR at 0x7c00, then jumps to the
 code there, code that relocates itself to and jumps to 0x600, but what
 does movw $main-EXEC+LOAD,%si mean? if it's the source address to copy
 from, why is it $main (0x7c00) - EXEC (0x600) + LOAD (0x7c00) above
 main? then, movw $main,%di is the address to copy to... wasn't 0x600
 the address to copy to? then jump to jmp main-LOAD+EXEC (0x600)?
 
 I guess I am really missing something here, but I can't get to
 understand what's happening.
 
 start:cld # String ops inc
   xorw %ax,%ax# Zero
   movw %ax,%es# Address
   movw %ax,%ds#  data
   movw %ax,%ss# Set up
   movw $LOAD,%sp  #  stack
 #
 # Relocate ourself to a lower address so that we are out of the way when
 # we load in the bootstrap from the partition to boot.
 #
   movw $main-EXEC+LOAD,%si# Source
   movw $main,%di  # Destination
   movw $0x200-(main-start),%cx# Byte count
   rep # Relocate
   movsb   #  code
 #
 # Jump to the relocated code.
 #
   jmp main-LOAD+EXEC  # To relocated code


The boot loader was linked to run at EXEC, so main is actually EXEC plus
the offset to main from EXEC.

So main-EXEC+LOAD results in calculating the offset to main at the place
where the BIOS loaded it == LOAD+offset_to_main.  This must be used as
the source address for the movsb.

--
Gary Jennejohn
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: random FreeBSD panics

2010-03-29 Thread John Baldwin
On Sunday 28 March 2010 4:28:29 am Masoom Shaikh wrote:
 Hello List,
 
 I was a happy FreeBSD user, just before I installed FreeBSD8.0-RC1. Since
 then, system randomly just freezes, and there is no option other than hard
 boot. I guessed this will get solved in 8.0-RELEASE, but it was not :(
 
 Many times I get vmcore files, not always. I have dumpdev set to AUTO in my
 rc.conf. Almost every time it just fsck's the file-system on reboot. I have
 not lost any files though. This is a Dell Inspiron 1525 Laptop with 1GB ram,
 Intel Core2 Duo T5500 with ATI Radeon X1400 card. The installation in
 question is KDE4 from ports, with radeon/ati driver.
 
 I felt the problem is with wpi driver, then suspected dri driver of X. Then
 I observed system freezes even if none of this is installed. e.g. if it is
 under some load, like building a port and simultaneously fetching something
 over network it hangs, and hangs hard. This persuaded me to think something
 is wrong in kernel scheduling itself. May be it is lost in some deadlock,
 etc... Thus last weekend I thought I would see how immediate previous
 version i.e. FreeBSD-7.3-RELEASE would behave.
 
 I reinstalled FreeBSD7.1 from iso images, svn up'ed FreeBSD7.3 source, did
 the normal buildworld, buildkernel, installkernel, installworld cycle.
 Unfortunatly this kernel is naughty as well ;-), it also freezes with same
 stubbornness. But difference is this time I happen to catch something
 interesting.
 
 It panics on NMI, fatal trap 19 while in kernel mode. Loaded the vmcore file
 in kgdb and got the backtrace. I obtained vmcore files on two occasions. I
 have attached both the back traces. This error most likely suggests hardware
 error in RAM, but Windox7 and XP boot just fine and never caused any errors.

Yes, and note that the chipset has set a register to indicate a RAM parity 
error as well, so it is not a random NMI.  Have you checked your BIOS' event 
log?  You may also want to try running with machine checks enabled 
(hw.mca.enabled=1 in loader.conf, but it would have to be on very recent 7/8-
stable) to see if you get machine checks for ECC errors.  OTOH, if you do not 
have ECC memory then this will probably not help.

 To verify if I have errors in my RAM I let run sysutils/memtest86+
 overnight, to double verify I also executed Windows Memory Diagnostic test
 for four times. None of them reported errors. Can anyone here suggest any
 solution.

You can still have bad RAM even if those do not fail.

-- 
John Baldwin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: periodically save current time to time-of-day hardware

2010-03-29 Thread John Baldwin
On Sunday 28 March 2010 7:45:25 am Dag-Erling Smørgrav wrote:
 Peter Jeremy peterjer...@acm.org writes:
  A new kthread which sleeps on channel update_rtc.  When woken, it
  checks to see if it's within (say) 50msec of a second boundary and so,
  it does a trylock on the (new) RTC mutex.  If it grabs the mutex then
  it performs the update.  If it was too far from the second boundary or
  it fails to grab the mutex then it sleeps until the next second
  boundary and tries again.
 
  The existing resettodr() would then turn into a wakeup(update_rtc).
 
 Sounds good to me, but if only that thread has access to the RTC, why
 bother with a mutex?

I would dispense with the kthread and just use a callout (or have a callout 
schedule a task for taskqueue_thread).

-- 
John Baldwin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: random FreeBSD panics

2010-03-29 Thread Masoom Shaikh
On Sun, Mar 28, 2010 at 5:38 PM, Ivan Voras ivo...@freebsd.org wrote:
 On 28 March 2010 16:42, Masoom Shaikh masoom.sha...@gmail.com wrote:

 lets assume if this is h/w problem, then how can other OSes overcome
 this ? is there a way to make FreeBSD ignore this as well, let it
 result in reasonable performance penalty.

 Very probably, if only we could detect where the problem is.
 Try adding options     PRINTF_BUFR_SIZE=128 to the kernel

this option is already there

 configuration file if you can, to see if you can get a less mangled
 log outout.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


virtual memory question

2010-03-29 Thread Dr. Baud

Should I be able to recover the physical address of a memory region 
allocated by configmalloc in a kernel module and mapped to a virtual address by 
a user application?

Dr


  

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: random FreeBSD panics

2010-03-29 Thread Jeremy Chadwick
On Mon, Mar 29, 2010 at 05:01:02PM +, Masoom Shaikh wrote:
 On Sun, Mar 28, 2010 at 5:38 PM, Ivan Voras ivo...@freebsd.org wrote:
  On 28 March 2010 16:42, Masoom Shaikh masoom.sha...@gmail.com wrote:
 
  lets assume if this is h/w problem, then how can other OSes overcome
  this ? is there a way to make FreeBSD ignore this as well, let it
  result in reasonable performance penalty.
 
  Very probably, if only we could detect where the problem is.
  Try adding options     PRINTF_BUFR_SIZE=128 to the kernel
 
 this option is already there

The key word in Ivan's phrase is less mangled.  Neither use of or
increasing PRINTF_BUFR_SIZE solves the problem of interspersed console
output.  I've been ranting/raving about this problem for years now; it
truly looks like a mutex lock issue (or lack of such lock), but I've
been told numerous times that isn't the case.

To developers: what incentives would help get this issue well-needed
attention?  This problem makes kernel debugging, panic analysis, and
other console-oriented viewing basically impossible.

-- 
| Jeremy Chadwick   j...@parodius.com |
| Parodius Networking   http://www.parodius.com/ |
| UNIX Systems Administrator  Mountain View, CA, USA |
| Making life hard for others since 1977.  PGP: 4BD6C0CB |

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: random FreeBSD panics

2010-03-29 Thread John Baldwin
On Monday 29 March 2010 1:30:38 pm Jeremy Chadwick wrote:
 On Mon, Mar 29, 2010 at 05:01:02PM +, Masoom Shaikh wrote:
  On Sun, Mar 28, 2010 at 5:38 PM, Ivan Voras ivo...@freebsd.org wrote:
   On 28 March 2010 16:42, Masoom Shaikh masoom.sha...@gmail.com wrote:
  
   lets assume if this is h/w problem, then how can other OSes overcome
   this ? is there a way to make FreeBSD ignore this as well, let it
   result in reasonable performance penalty.
  
   Very probably, if only we could detect where the problem is.
   Try adding options PRINTF_BUFR_SIZE=128 to the kernel
  
  this option is already there
 
 The key word in Ivan's phrase is less mangled.  Neither use of or
 increasing PRINTF_BUFR_SIZE solves the problem of interspersed console
 output.  I've been ranting/raving about this problem for years now; it
 truly looks like a mutex lock issue (or lack of such lock), but I've
 been told numerous times that isn't the case.
 
 To developers: what incentives would help get this issue well-needed
 attention?  This problem makes kernel debugging, panic analysis, and
 other console-oriented viewing basically impossible.

I was recently going to look at it.  The somewhat drastic approach I was going 
to take was to add a simple serializing lock around trap_fatal() and a few 
other places that do similar block prints (e.g. mca_log()).  One of the issues 
with fixing this in printf itself is that you'd want probably want to 
serialize complete lines of text on a per-thread basis.  You would want to be 
able to accumulate this line of text across multiple calls to printf (think of 
it as line-buffering ala stdio).  However, some folks may be nervous about 
printf not printing things immediately.

The other issue is that lots of code assumes it can call printf from anywhere 
and everywhere.  Mostly this just means that if you add locking and line-
buffering to printf(9) you have to be very careful to make sure it works in 
odd places.  Probably a lot of this could be solved by deferring things like 
trap_fatal() until panic() has already been called (which is bde's preferred
solution I think).

-- 
John Baldwin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: random FreeBSD panics

2010-03-29 Thread Jeremy Chadwick
On Mon, Mar 29, 2010 at 02:27:34PM -0400, John Baldwin wrote:
 On Monday 29 March 2010 1:30:38 pm Jeremy Chadwick wrote:
  On Mon, Mar 29, 2010 at 05:01:02PM +, Masoom Shaikh wrote:
   On Sun, Mar 28, 2010 at 5:38 PM, Ivan Voras ivo...@freebsd.org wrote:
On 28 March 2010 16:42, Masoom Shaikh masoom.sha...@gmail.com wrote:
   
lets assume if this is h/w problem, then how can other OSes overcome
this ? is there a way to make FreeBSD ignore this as well, let it
result in reasonable performance penalty.
   
Very probably, if only we could detect where the problem is.
Try adding options PRINTF_BUFR_SIZE=128 to the kernel
   
   this option is already there
  
  The key word in Ivan's phrase is less mangled.  Neither use of or
  increasing PRINTF_BUFR_SIZE solves the problem of interspersed console
  output.  I've been ranting/raving about this problem for years now; it
  truly looks like a mutex lock issue (or lack of such lock), but I've
  been told numerous times that isn't the case.
  
  To developers: what incentives would help get this issue well-needed
  attention?  This problem makes kernel debugging, panic analysis, and
  other console-oriented viewing basically impossible.
 
 I was recently going to look at it.  The somewhat drastic approach I was 
 going 
 to take was to add a simple serializing lock around trap_fatal() and a few 
 other places that do similar block prints (e.g. mca_log()).  One of the 
 issues 
 with fixing this in printf itself is that you'd want probably want to 
 serialize complete lines of text on a per-thread basis.  You would want to be 
 able to accumulate this line of text across multiple calls to printf (think 
 of 
 it as line-buffering ala stdio).  However, some folks may be nervous about 
 printf not printing things immediately.
 
 The other issue is that lots of code assumes it can call printf from anywhere 
 and everywhere.  Mostly this just means that if you add locking and line-
 buffering to printf(9) you have to be very careful to make sure it works in 
 odd places.  Probably a lot of this could be solved by deferring things like 
 trap_fatal() until panic() has already been called (which is bde's preferred
 solution I think).

John,

Thanks for the insights, they're greatly appreciated.

I went looking this morning to see how Linux addressed this issue (if at
all), and it's been discussed a few times in the past.  The longest lkml
thread I could find that mentioned the problem was circa 2002.  Probably
not worth reading as there was work done in 2009 to solve the issue.

http://lkml.indiana.edu/hypermail/linux/kernel/0204.1/index.html#161

Work done by RedHat in 2009 details how they implemented a lockless
version of their kernel ring buffer (similar to our system message
buffer, but probably a lot more complex):

http://lwn.net/Articles/340400/
http://lwn.net/Articles/340443/

Supposedly having multiple writers to the ring is 100% safe; no
interspersed output.  Same goes for interrupt-generated stuff.  There's
some comments in the technical document (2nd link) that imply there's an
individual ring buffer for each CPU; possibly per-CPU kernel message
buffers would solve our issue?

-- 
| Jeremy Chadwick   j...@parodius.com |
| Parodius Networking   http://www.parodius.com/ |
| UNIX Systems Administrator  Mountain View, CA, USA |
| Making life hard for others since 1977.  PGP: 4BD6C0CB |

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


book on parallel programming

2010-03-29 Thread Sergey Babkin
Hi all,

For everyone who asked about my book The Practice of Parallel
Programming being printed, I've got it self-published
through CreateSpace:

https://www.createspace.com/3438465

They say it should get to Amazon too, in 3 weeks or so.
The discount code RYM7VM5Q gives $14 off the list price at the
CreateSpace store. 

The online free version is still available at 
http://members.verizon.net/~babkin/tpopp/

Though the printed edition has quite a few improvements in it :-)

-SB
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org