Three questions about FreeBSD kernel internals

2008-01-13 Thread Ed Schouten
Hello everyone,

I've got three small questions about some of the source code in the
FreeBSD kernel, based on some of the source code and the manpages. I
didn't send it to questions@, because of their technical nature.

>>> Question 1:

Sleepqueues and turnstiles are allocated on thread creation. Why can't
they be allocated when needed?

I think the following answer should be quite okay:

I suspect because we can't always run sleepq_alloc(). That way we're
use we always have a sleepqueue for the process when we need it. We
always need these, because otherwise the process is doomed when it can't
allocate one.

It's also faster I guess, because we don't have to allocate a brand new
sleepqueue whenever we walk into a condition on which we have to wait
(which happens a real lot, because a real lot of processes sleep).

The reason why we don't keep them on the freelist as much as possible,
is because we don't have to lock the hash table that much. We've always
got one at hand.

>>> Question 2:

The kernel has three mechanisms to wait for an asynchronous event,
namely sema(9), condvar(9) and sleep(9). Strictly, there are only two
interfaces, because sema(9) is implemented using mutex(9) and
condvar(9). My question is: which interface is the preferred one when
writing new code?

>>> Question 3:

In the file tty_subr.c there is the following comment:

| /*
|  * Allocate an initial base set of cblocks as a 'slush'.
|  * We allocate non-slush cblocks with each initial tty_open() and
|  * deallocate them with each tty_close().
|  * We should adjust the slush allocation.  This can't be done in
|  * the i/o routines because they are sometimes called from
|  * interrupt handlers when it may be unsafe to call malloc().
|  */

My question is whether the bottom three lines of the comment are still
accurate. If I believe the manpage, it's safe to call malloc() in
interrupt handlers, if you use M_NOWAIT. I'm not really familiar with
older xBSD implementations, but is it true that the kernel couldn't
allocate memory in interrupt handlers back then?

Yours,
-- 
 Ed Schouten <[EMAIL PROTECTED]>
 WWW: http://g-rave.nl/


pgpsO62PnMEpU.pgp
Description: PGP signature


Re: NDIS debugging

2008-01-13 Thread Diego Giagio
I forgot to mention:

# uname -a
FreeBSD   8.0-CURRENT FreeBSD 8.0-CURRENT #4: Sun Jan 13 12:46:48 BRST
2008[EMAIL PROTECTED]:/usr/src/sys/amd64/compile/GENERICamd64
# uname -m
amd64
#

I'm using CURRENT as of 11/Jan/08.

On Jan 13, 2008 12:52 PM, Diego Giagio <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Recently i've bought a new laptop (Dell Precision M2300) which came
> with Intel 4965 Wifi chipset. Since there's no native driver available
> yet, I've been trying to get it to work throught Project Evil (NDIS
> Windows Driver NETw4x64).
>
> At first, the driver complained for "no match for
> InitializeSListHead". Then I figured it out how to implement that
> function (a simple bzero on slist_head, just like ndiswrapper on
> Linux) and it stopped complaining. I'm able to kldload NETx4x64_sys.ko
> with success, but it stays silent. It just loads two dependent modules
> (if_nids.ko and nids.ko) and nothing is printed into dmesg or console.
> Also, there's no ndis0 device.
>
> As far as I can get I could see that DriverEntry()'s module is working
> OK as it returns STATUS_SUCCESS on subr_windrv.c's windrv_load().
>
> So, the question is: Is there a way to turn on verbose debugging on
> the NDIS subsystem? Would be great if I could get some more info on
> what's going wrong.
>
> Thank you.
>
> --
> DG
>
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


NDIS debugging

2008-01-13 Thread Diego Giagio
Hi,

Recently i've bought a new laptop (Dell Precision M2300) which came
with Intel 4965 Wifi chipset. Since there's no native driver available
yet, I've been trying to get it to work throught Project Evil (NDIS
Windows Driver NETw4x64).

At first, the driver complained for "no match for
InitializeSListHead". Then I figured it out how to implement that
function (a simple bzero on slist_head, just like ndiswrapper on
Linux) and it stopped complaining. I'm able to kldload NETx4x64_sys.ko
with success, but it stays silent. It just loads two dependent modules
(if_nids.ko and nids.ko) and nothing is printed into dmesg or console.
Also, there's no ndis0 device.

As far as I can get I could see that DriverEntry()'s module is working
OK as it returns STATUS_SUCCESS on subr_windrv.c's windrv_load().

So, the question is: Is there a way to turn on verbose debugging on
the NDIS subsystem? Would be great if I could get some more info on
what's going wrong.

Thank you.

--
DG
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


mutex lock for filesystem list.

2008-01-13 Thread Fernando Apesteguía
Hi all,

I'm trying to write a patch to add a file to the linprocfs. This file
provides the list of filesystems present in the kernel.

Though I was able to create the file and traverse the list, it's
clearly unsafe. I would like to know wich semaphore I should lock
cause I can't find it in the kernel code.

In addition I'd like to know if there is a book similar to the
Understanding the Linux kernel, but for freebsd. What is the best
information source to get introduced in the freebsd kernel programming
(apart of the code itself)?

Thanks in advance
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: mutex lock for filesystem list.

2008-01-13 Thread Ed Schouten
* Fernando Apesteguía <[EMAIL PROTECTED]> wrote:
> I'm trying to write a patch to add a file to the linprocfs. This file
> provides the list of filesystems present in the kernel.
> 
> Though I was able to create the file and traverse the list, it's
> clearly unsafe. I would like to know wich semaphore I should lock
> cause I can't find it in the kernel code.
> 
> In addition I'd like to know if there is a book similar to the
> Understanding the Linux kernel, but for freebsd. What is the best
> information source to get introduced in the freebsd kernel programming
> (apart of the code itself)?

You're probably looking through the mountlist? Then you need to make
sure you lock the mountlist_mtx. See src/sys/kern/vfs_mount.c.

-- 
 Ed Schouten <[EMAIL PROTECTED]>
 WWW: http://g-rave.nl/


pgpGDJHYOuLMX.pgp
Description: PGP signature


Re: mutex lock for filesystem list.

2008-01-13 Thread Ed Schouten
And of course I forgot to answer all the questions.

* Fernando Apesteguía <[EMAIL PROTECTED]> wrote:
> In addition I'd like to know if there is a book similar to the
> Understanding the Linux kernel, but for freebsd. What is the best
> information source to get introduced in the freebsd kernel programming
> (apart of the code itself)?

I guess most people would say "The Design and Implementation of the
FreeBSD Operating System", by McKusick and Neville-Neil:


http://www.amazon.com/Design-Implementation-FreeBSD-Operating-System/dp/0201702452

Yours,
-- 
 Ed Schouten <[EMAIL PROTECTED]>
 WWW: http://g-rave.nl/


pgpumS3I1zaDJ.pgp
Description: PGP signature


Re: mutex lock for filesystem list.

2008-01-13 Thread Julian Elischer

Ed Schouten wrote:

And of course I forgot to answer all the questions.

* Fernando Apesteguía <[EMAIL PROTECTED]> wrote:

In addition I'd like to know if there is a book similar to the
Understanding the Linux kernel, but for freebsd. What is the best
information source to get introduced in the freebsd kernel programming
(apart of the code itself)?


I guess most people would say "The Design and Implementation of the
FreeBSD Operating System", by McKusick and Neville-Neil:


http://www.amazon.com/Design-Implementation-FreeBSD-Operating-System/dp/0201702452


but be warned that th at book was written part way through the SMP 
rewrite so a lot has changed... Dr McKusick said the words "Next 
edition" the other day but I think it's still just a glimmer in his eye.




Yours,


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Nvidia Driver w/RELENG_7

2008-01-13 Thread Ali Mashtizadeh
Hi,

Does anyone have the nvidia video driver working with releng 7? What I am
seeing is that the kernel module compiles and loads fine, but it will not
detect any video card. I've tried removing the agp device from my BSD kernel
and using nvidia's.

-- 
Ali Mashtizadeh
علی مشتی زاده
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Re: Nvidia Driver w/RELENG_7

2008-01-13 Thread Xin LI
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Ali Mashtizadeh wrote:
> Hi,
> 
> Does anyone have the nvidia video driver working with releng 7? What I am
> seeing is that the kernel module compiles and loads fine, but it will not
> detect any video card. I've tried removing the agp device from my BSD kernel
> and using nvidia's.

I'm using xf86-video-nv, I think you are referring the binary driver,
which is not this one?

- --
Xin LI <[EMAIL PROTECTED]>  http://www.delphij.net/
FreeBSD - The Power to Serve!
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFHisBAi+vbBBjt66ARAob/AKCQxMuw0DvAZixDm+8qvU+lGpLNhwCfdelk
at4T0KRlKFKfMq2sQiCElcE=
=oL2t
-END PGP SIGNATURE-
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Nvidia Driver w/RELENG_7

2008-01-13 Thread Daniel O'Connor
On Mon, 14 Jan 2008, Ali Mashtizadeh wrote:
> Does anyone have the nvidia video driver working with releng 7? What
> I am seeing is that the kernel module compiles and loads fine, but it
> will not detect any video card. I've tried removing the agp device
> from my BSD kernel and using nvidia's.

Load the module in the loader rather than after the kernel has booted.

acpi_video can also grab the device I believe.. I am running current (ie 
8) and I ran -current when it was 7.x and loading it from the loader 
has always worked (modulo incompatible source changes :)

-- 
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C


signature.asc
Description: This is a digitally signed message part.


Re: Nvidia Driver w/RELENG_7

2008-01-13 Thread Yuri Pankov
On Sun, Jan 13, 2008 at 05:22:46PM -0800, Ali Mashtizadeh wrote:
> Hi,
> 
> Does anyone have the nvidia video driver working with releng 7? What I am
> seeing is that the kernel module compiles and loads fine, but it will not
> detect any video card. I've tried removing the agp device from my BSD kernel
> and using nvidia's.
> 
> -- 
> Ali Mashtizadeh
> علی مشتی زاده

If you are sure that installed version of nvidia-driver supports your
card, try putting nvidia_load="YES" in /boot/loader.conf. I guess your
problem is vgapci attaching to device, leaving nvidia module without
hardware to attach, like below:

[EMAIL PROTECTED]:5:0:0: class=0x03 card=0x40161682 chip=0x040210de
rev=0xa1 hdr=0x00
vendor = 'Nvidia Corp'
device = 'GeForce 8600 GT'
class  = display
subclass   = VGA


HTH,
Yuri
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Nvidia Driver w/RELENG_7

2008-01-13 Thread lveax
it work right for me:

[EMAIL PROTECTED]:1:0:0:

#uname -srm
FreeBSD 7.0-RC1 i386
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: netgraph question

2008-01-13 Thread Lawrence Stewart

Subhash Gopinath wrote:

Thanks, looks interesting.
But I was looking at processing the packets in userspace. Sorry I
didn't mention it clearly.


Ah ok. I didn't get that from your initial email. Have you looked at the 
firewall (ipfw and/or pf) code at all? I believe you can use mechanisms 
like divert sockets (man 4 divert) to pass packets up from the kernel to 
userspace for processing, and then reinject the packets into the stack 
if they pass whatever criteria is required. I'm sure there are other 
mechanisms for getting packets up into userspace as well, but firewall 
code is probably a good place to start looking for ideas.




Thanks,
-Subhash

On Jan 11, 2008 10:32 PM, Lawrence Stewart <[EMAIL PROTECTED]> wrote:

Hi Subhash,

Subhash Gopinath wrote:

Hello folks,

I am looking at writing an application program to tap certain ipv6 packets
(say icmpv6)
using netgraph. The application has to do some processing, before kernel can
proceed
with those packets.

I have vaguely understood netgraph, and I see that I need a ng_socket node
in the application, an ng_bpf node, and an ng_ether or ng_iface node in the
kernel.

My question is. would I need to create such nodes for each interface. Then
it becomes unscalable..
Can I have just one socket, bpf, iface node that can tap icmpv6 packets on
all interfaces?

The PFIL(9) interface might also be of interest to you. If all you need
to do is packet interception and then allow/deny packets based on the
results of some processing, PFIL might be the way to go. We wrote some
code (SIFTR [1]) which uses PFIL in a similar capacity and you may want
to refer to it as an example.

Cheers,
Lawrence

[1] http://caia.swin.edu.au/urp/newtcp/tools.html




Cheers,
Lawrence
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"