NMI while trying to read acpi timer register

2013-01-28 Thread Andriy Gapon

Guys,

is there any reasonable explanation for getting an NMI while trying to read acpi
timer register?
Note: this happens only after ACPI suspend/resume.
-- 
Andriy Gapon
___
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"


Sockets programming question

2013-01-28 Thread Ian Lepore
I've got a question that isn't exactly freebsd-specific, but
implemenation-specific behavior may be involved.

I've got a server process that accepts connections from clients on a
PF_LOCAL stream socket.  Multiple clients can be connected at once; a
list of them is tracked internally.  The server occasionally sends data
to each client.  The time between messages to clients can range
literally from milliseconds to months.  Clients never send any data to
the server, indeed they may shutdown that side of the connection and
just receive data.

The only way I can find to discover that a client has disappeared is by
trying to send them a message and getting an error because they've
closed the socket or died completely.  At that point I can reap the
resources and remove them from the client list.  This is problem because
of the "months between messages" thing.  A lot of clients can come and
go during those months and I've got this ever-growing list of open
socket descriptors because I never had anything to say the whole time
they were connected.

By trial and error I've discovered that I can sort of "poll" for their
presence by writing a zero-length message.  If the other end of the
connection is gone I get the expected error and can reap the client,
otherwise it appears to quietly write nothing and return zero and have
no other side effects than polling the status of the server->client side
of the pipe.

My problem with this "polling" is that I can't find anything in writing
that sanctions this behavior.  Would this amount to relying on a
non-portable accident of the current implementation?  

Also, am I missing something simple and there's a cannonical way to
handle this?  In all the years I've done client/server stuff I've never
had quite this type of interaction (or lack thereof) between client and
server before.

-- Ian


___
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: Sockets programming question

2013-01-28 Thread Alfred Perlstein

On 1/28/13 10:11 AM, Ian Lepore wrote:

I've got a question that isn't exactly freebsd-specific, but
implemenation-specific behavior may be involved.

I've got a server process that accepts connections from clients on a
PF_LOCAL stream socket.  Multiple clients can be connected at once; a
list of them is tracked internally.  The server occasionally sends data
to each client.  The time between messages to clients can range
literally from milliseconds to months.  Clients never send any data to
the server, indeed they may shutdown that side of the connection and
just receive data.

The only way I can find to discover that a client has disappeared is by
trying to send them a message and getting an error because they've
closed the socket or died completely.  At that point I can reap the
resources and remove them from the client list.  This is problem because
of the "months between messages" thing.  A lot of clients can come and
go during those months and I've got this ever-growing list of open
socket descriptors because I never had anything to say the whole time
they were connected.

By trial and error I've discovered that I can sort of "poll" for their
presence by writing a zero-length message.  If the other end of the
connection is gone I get the expected error and can reap the client,
otherwise it appears to quietly write nothing and return zero and have
no other side effects than polling the status of the server->client side
of the pipe.

My problem with this "polling" is that I can't find anything in writing
that sanctions this behavior.  Would this amount to relying on a
non-portable accident of the current implementation?

Also, am I missing something simple and there's a cannonical way to
handle this?  In all the years I've done client/server stuff I've never
had quite this type of interaction (or lack thereof) between client and
server before.

I may be mistaken, but doesn't poll(2) allow you to see this as well?

I think you should see POLLHUP in revents if POLLOUT is set in events.

I think there also is an analogous way to do this with kevent as well.

-Alfred
___
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: Sockets programming question

2013-01-28 Thread Konstantin Belousov
On Mon, Jan 28, 2013 at 08:11:47AM -0700, Ian Lepore wrote:
> I've got a question that isn't exactly freebsd-specific, but
> implemenation-specific behavior may be involved.
> 
> I've got a server process that accepts connections from clients on a
> PF_LOCAL stream socket.  Multiple clients can be connected at once; a
> list of them is tracked internally.  The server occasionally sends data
> to each client.  The time between messages to clients can range
> literally from milliseconds to months.  Clients never send any data to
> the server, indeed they may shutdown that side of the connection and
> just receive data.
> 
> The only way I can find to discover that a client has disappeared is by
> trying to send them a message and getting an error because they've
> closed the socket or died completely.  At that point I can reap the
> resources and remove them from the client list.  This is problem because
> of the "months between messages" thing.  A lot of clients can come and
> go during those months and I've got this ever-growing list of open
> socket descriptors because I never had anything to say the whole time
> they were connected.
> 
> By trial and error I've discovered that I can sort of "poll" for their
> presence by writing a zero-length message.  If the other end of the
> connection is gone I get the expected error and can reap the client,
> otherwise it appears to quietly write nothing and return zero and have
> no other side effects than polling the status of the server->client side
> of the pipe.
> 
> My problem with this "polling" is that I can't find anything in writing
> that sanctions this behavior.  Would this amount to relying on a
> non-portable accident of the current implementation?  
> 
> Also, am I missing something simple and there's a cannonical way to
> handle this?  In all the years I've done client/server stuff I've never
> had quite this type of interaction (or lack thereof) between client and
> server before.

Check for the IN events as well. I would not trust the mere presence
of the IN in the poll result, but consequent read should return EOF
and this is good indicator of the dead client.


pgpetdMu2vn_M.pgp
Description: PGP signature


Re: some questions on kern_linker and pre-loaded modules

2013-01-28 Thread John Baldwin
On Saturday, January 26, 2013 6:52:01 am Andriy Gapon wrote:
> 
> I.
> It seems that linker_preload checks a  module for being a duplicate module 
> only
> if the module has MDT_VERSION.
> 
> This is probably designed to allow different version of the same module to
> co-exist (for some definition of co-exist)?

Yes, that is likely true, but it is a bit dubious.

> But, OTOH, this doesn't work well if the module is version-less (no
> MODULE_VERSION in the code) and is pre-loaded twice (e.g. once in kernel and
> once in a preloaded file).

Yes.

> At present a good example of this is zfsctrl module, which could be present 
> both
> in kernel (options ZFS) and in zfs.ko.
> 
> I haven't thought about any linker-level resolution for this issue.
> I've just tried a plug the ZFS hole for now.

I think we should require all modules declared by DECLARE_MODULE() to have a
version.  You might be able to enforce that by failing to register a linker
file if it contains any modules that do not include at least one version
metadata note in the same linker file.  You could check this before running
the MOD_LOAD handlers (though after running SYSINITs).  Truly fixing this would
mean making module data true metadata that is parsed by the linker rather than
having it all provided to the kernel via SYSINITs so that you could evaluate
this before running SYSINITs.  That is a larger project however.  I think your
fix for zfsctrl is correct.
 
> II.
> It seems that linker_file_register_modules() for the kernel is called after
> linker_file_register_modules() is called for all the pre-loaded files.
> linker_file_register_modules() for the kernel is called from
> linker_init_kernel_modules via SYSINIT(SI_SUB_KLD, SI_ORDER_ANY) and that
> happens after linker_preload() which is executed via SYSINIT(SI_SUB_KLD,
> SI_ORDER_MIDDLE).
> 
> Perhaps this is designed to allow modules in the preloaded files to override
> modules compiled into the kernel?

Yes, likely so.

> But this doesn't seem to work well.
> Because modules from the kernel are not registered yet,
> linker_file_register_modules() would be successful for the duplicate modules 
> in
> a preloaded file and thus any sysinits present in the file will also be 
> registered.
> So, if the module is present both in the kernel and in the preloaded file and
> the module has a module event handler (modeventhand_t), then the handler will
> registered and called twice.

Yes, I think it is too hard at present to safely allow a linker file to
override the same module in a kernel, so the duplicate linker file should
just be rejected entirely.  I'm not sure if your change is completely
correct for that.

-- 
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: Testing SIOCADDMULTI?

2013-01-28 Thread John Baldwin
On Sunday, January 27, 2013 1:51:12 am Tim Kientzle wrote:
> 
> On Jan 26, 2013, at 3:56 PM, Tim Kientzle wrote:
> 
> > My next TODO items for this network driver is to implement
> > the SIOCADDMULTI and SIOCDELMULTI ioctls.
> 
> Looking through other drivers (and net/if.c), I've
> managed to implement ADDMULTI by adding
> the multicast ethernet address to the list maintained
> by the controller.
> 
> DELMULTI seems trickier.   Since if.c does not pass
> the specific address being removed down to the
> driver, it looks like I have no choice but to remove
> every multicast address from the controller and then
> re-insert all of the ones that are still valid.
> 
> (This controller doesn't use a hash filter; it uses
> a list of valid multicast addresses.)
> 
> Is there a better approach?

You should always reprogram the full table while holding if_maddr_rlock().
All the ioctl's tell you is that an entry was added or removed from that
list.  There is currently no race-free way for the stack to tell you which
specific address to add or remove.

> > I'm not quite sure what they do, though, and have
> > no idea how to test them to see if they are working
> > correctly.
> 
> Would still appreciate any suggestions for how to test these.

You can write a simple app to listen for UDP packets and have it join a 
multicast group and have another machine on the same network write a packet to 
the multicast group.

However, a simpler test is to toggle the sysctl to enable multicast ping 
replies and to ping a multicast address from another machine after joining it 
on the test machine using mtest.

-- 
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"