Re: CVS commit: othersrc/zfs/external/cddl/osnet/dist

2009-03-26 Thread Andrew Doran
On Thu, Mar 26, 2009 at 10:21:49PM +, Andrew Doran wrote:
 On Fri, Mar 27, 2009 at 09:14:40AM +1100, Simon Burge wrote:
 
  +#ifdef __NetBSD__
  +#include uvm/uvm.h
  +#definebtop(x) ((x) * PAGE_SIZE)
[ ... ]
  
  Isn't that working out pages to bytes and not bytes to pages ?
  
  Unless btop() means something non-obvious in Solaris land...
 
 Probably, please fix ;-)

By the way, this is basically the tarball that I posted to tech-kern in
January: it doesn't work yet. Interest has been expressed in finishing it.


Re: CVS commit: src/sys/dev/sbus

2009-03-27 Thread Andrew Doran
On Fri, Mar 27, 2009 at 12:25:41PM +, Izumi Tsutsui wrote:

 Log Message:
 Use bus_space(9) to access registers.  SETREG() macro using bogus casts
 against packed structures doesn't work on gcc4. (no character on screen)
 See also:
 http://mail-index.NetBSD.org/port-sparc/2003/11/11/0002.html

It has been a long time, but from what I remember SETREG() was an invention
of mine to work around either a compiler or code bug. Maybe bus_space does
the same.



Re: CVS commit: src/sys/dev/sbus

2009-03-27 Thread Andrew Doran
On Fri, Mar 27, 2009 at 04:31:33PM -0400, Michael wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Hello,
 
 On Mar 27, 2009, at 9:07 AM, Izumi Tsutsui wrote:
 
 a...@netbsd.org wrote:
 
 On Fri, Mar 27, 2009 at 12:25:41PM +, Izumi Tsutsui wrote:
 
 Log Message:
 Use bus_space(9) to access registers.  SETREG() macro using bogus  
 casts
 against packed structures doesn't work on gcc4. (no character on  
 screen)
 See also:
 http://mail-index.NetBSD.org/port-sparc/2003/11/11/0002.html
 
 It has been a long time, but from what I remember SETREG() was an  
 invention
 of mine to work around either a compiler or code bug. Maybe  
 bus_space does
 the same.
 
 I'm not sure if it's a compiler bug or not, but SETREG() doesn't work
 on gcc4 while it's confirmed working on gcc3.
 (as the noted in the above mail, it looks generating byte access code)
 
 Removing __packed might also help, but bus_space(9) just works
 and it's a right way to go, I think.
 
 I strongly agree - I've been trying to get our zx driver to work for a  
 while but got sidetracked by other stuff ( mostly sgimips-related ) -  
 thanks for doing this. Writing an accelerated Xorg driver is next on  
 my todo list ( after adding wscons support to zx )

It worked for the console when I checked it in (haven't touched it since).
I think I remember now what SETREG() might have been about. The compiler
was generating sub-word writes, or something along those lines.


Re: CVS commit: src/sys/dev/acpi/acpica

2009-03-31 Thread Andrew Doran
On Tue, Mar 31, 2009 at 05:17:47PM +, Matthias Drochner wrote:

 Module Name:  src
 Committed By: drochner
 Date: Tue Mar 31 17:17:47 UTC 2009
 
 Modified Files:
   src/sys/dev/acpi/acpica: OsdSchedule.c OsdSynch.c
 
 Log Message:
 avoid tsleep also during shutdown (and in particular ACPI poweroff),
 should fix PR kern/39141 by Takahiro Kambe and PR port-i386/41110
 by Reinoud Zandijk

Thank you for fixing an annoying panic. However it's one of many hacks to be
applied to this. There's no good reason for interrupts to be off while the
shutdown hooks are being processed.


Re: CVS commit: src/sys/dev/acpi

2009-04-08 Thread Andrew Doran
On Wed, Apr 08, 2009 at 12:15:45AM +, David Young wrote:

 Modified Files:
   src/sys/dev/acpi: acpi_timer.c acpi_timer.h
 
 Log Message:
 Add acpitimer_detach() to eventually support acpi(4) detachment.

tc_detach() does not work correctly on a running system. It can race with
binuptime(), so the timecounter may still be in use when it is destroyed.

One solution would be to use the passive serialization patch that I posted
to tech-k...@. I believe rmind@ is working on it.


Re: CVS commit: src

2009-04-25 Thread Andrew Doran
On Sat, Apr 25, 2009 at 09:42:30PM +0100, Mindaugas Rasiukevicius wrote:

  Module Name:src
  Committed By:   ad
  Date:   Sun Apr 19 14:11:38 UTC 2009
  
  ...
 
  x86:
  
  - Make intr_establish, intr_disestablish safe to use when !cold.
  
  - Distribute hardware interrupts among the CPUs, instead of directing
everything to the boot CPU.
 
 This is cool!

Just a shame it doesn't work properly yet. The balancing code is OK I think,
something in the guts of APIC/SPL handling is busted.
 
 From sys/arch/x86/x86/intr.c:
 
 /*
  * A simple round-robin allocator to assign interrupts to CPUs.
  */
 static int __noinline
 intr_allocate_slot(struct pic *pic, int pin, int level,
  struct cpu_info **cip, int *index, int *idt_slot)
 {
 
 From what I read, it is no longer round-robin, right?

Right, the comment is stale.


Re: CVS commit: src/sys

2009-05-16 Thread Andrew Doran
On Sat, May 16, 2009 at 08:29:54AM +, YAMAMOTO Takashi wrote:

 Modified Files:
   src/sys/kern: vfs_subr.c
   src/sys/sys: vnode.h
 
 Log Message:
 put a flag bit into v_usecount to prevent vtryget during getcleanvnode.
 this fixes the following deadlock.

Thanks! How about this to avoid potential sign compare issues? I forgot
to e-mail you about it earlier.

@@ -252,8 +252,8 @@ typedef struct vnode vnode_t;
 /*
  * v_usecount; see the comment in vfs_subr.c
  */
-#defineVC_XLOCK0x8000
-#defineVC_MASK 0x7fff
+#defineVC_XLOCK0x4000
+#defineVC_MASK (0x  ~VC_XLOCK)


Re: CVS commit: src/sys

2009-06-23 Thread Andrew Doran
On Tue, Jun 23, 2009 at 07:36:41PM +, Elad Efrat wrote:

 Log Message:
 Move the implementation of vaccess() to genfs_can_access(), in line with
 the other routines of the same spirit.
...
 No objections on tech-kern@:
 
   http://mail-index.netbsd.org/tech-kern/2009/06/21/msg005310.html

48 hours is not long enough, it has been raised with you before. Are you
deliberately trying to piss everyone off? Because it certainly comes over
that way.


Re: CVS commit: src/external/cddl/osnet/dist/uts/common/sys

2009-08-11 Thread Andrew Doran
On Mon, Aug 10, 2009 at 10:47:09PM +, Adam Hamsik wrote:

 Added Files:
   src/external/cddl/osnet/dist/uts/common/sys: priv_names.h
 
 Log Message:
 Add missing header file.

We should tag this file with osnet-20081117 (cvs tag)



Re: CVS commit: src/sys/kern

2009-08-29 Thread Andrew Doran
On Wed, Aug 26, 2009 at 10:34:47PM +, Manuel Bouyer wrote:
 Module Name:  src
 Committed By: bouyer
 Date: Wed Aug 26 22:34:47 UTC 2009
 
 Modified Files:
   src/sys/kern: uipc_usrreq.c
 
 Log Message:
 In uipc_usrreq(PRU_ACCEPT), grab the unp_streamlock before unp_setpeerlocks().
 This fixes a race where, for a short period of time, so-so_lock and
 so2-so_lock are not sync. This makes solocked2() and solocked()
 unreliable and cause DIAGNOSTIC kernel panics. This also fixes a possible
 panic in unp_setaddr() which expects the socket locked.
 Should fix kern/38968, fix proposed in
 http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005863.html

I think this is wrong and could cause a deadlock.  We know that the modus
operandi breaks solocked2(), but does it really break solocked()? I think we
should revert this one.

Thanks.


Re: CVS commit: src

2010-01-26 Thread Andrew Doran
On Wed, Nov 18, 2009 at 11:35:15PM +, YAMAMOTO Takashi wrote:
 hi,
 
  On Wed, Nov 18, 2009 at 01:29:05AM +, YAMAMOTO Takashi wrote:
  hi,
  
   Module Name: src
   Committed By:dyoung
   Date:Tue Nov 17 18:36:07 UTC 2009
   
   Modified Files:
src/distrib/sets/lists/comp: mi
src/share/man/man9: Makefile spl.9
   
   Log Message:
   Describe spllower(9) and splraise(9).
  
  these are MD implementation details which are not appropriate to be
  described in this page.  please revert.
  adding xrefs to splraiseipl and makeiplcookie instead is probably
  a good idea.
  
  I see.  I will describe spllower(9) and splraise(9) in an i386 page,
  instead.
 
 imo, for internal functions like them, it's more appropriate to put
 comments in the source code than man pages.

... or in a book about the kernel.  Section 9 describes how to use kernel
facilities, not how they work internally.  By documenting this item you
give the impression of availability and stability, neither of which is
provided.




Re: CVS commit: src/sys

2010-02-23 Thread Andrew Doran
On Mon, Feb 22, 2010 at 11:31:31AM -0600, David Young wrote:
 On Sun, Feb 21, 2010 at 02:11:40AM +, Darran Hunt wrote:
  Module Name:src
  Committed By:   darran
  Date:   Sun Feb 21 02:11:40 UTC 2010
  
  Modified Files:
  src/sys/arch/i386/i386: trap.c vector.S
  src/sys/kern: kern_lwp.c kern_proc.c kern_synch.c
  src/sys/sys: lwp.h proc.h
  Added Files:
  src/sys/sys: dtrace_bsd.h
  
  Log Message:
  Add the DTrace hooks to the kernel (KDTRACE_HOOKS config option).
  DTrace adds a pointer to the lwp and proc structures which it uses to
  manage its state.  These are opaque from the kernel perspective to keep
  the kernel free of CDDL code. The state arenas are kmem_alloced and freed
  as proccesses and threads are created and destoyed.
  
  Also add a check for trap06 (privileged/illegal instruction) so that
  DTrace can check for D scripts that may have triggered the trap so it
  can clean up after them and resume normal operation.
  
  Ok with c...@.
 
 Wow, dtrace in the kernel!  This is exciting, thanks!
 
 #ifdef makes kernel code hard to read.  Will you help arrest the
 accretion of conditional compilation in kern_synch.c by consolidating
 the conditional compilation in a static subroutine, for example:
 
 static void
 dtrace_vtime_switch(lwp_t *newl)
 {
 #ifdef KDTRACE_HOOKS
   /*
* If DTrace has set the active vtime enum to anything
* other than INACTIVE (0), then it should have set the
* function to call.
*/
   if (dtrace_vtime_active) {
   (*dtrace_vtime_switch_func)(newl);
   }
 #endif

How much code do the hooks add?  If it is not very much, then just drop
the ifdefs completely..



Re: CVS commit: src/sys

2010-02-24 Thread Andrew Doran
On Tue, Feb 23, 2010 at 09:58:25AM +1300, Darran Hunt wrote:

 static void
 dtrace_vtime_switch(lwp_t *newl)
 {
 #ifdef KDTRACE_HOOKS
  /*
   * If DTrace has set the active vtime enum to anything
   * other than INACTIVE (0), then it should have set the
   * function to call.
   */
  if (dtrace_vtime_active) {
  (*dtrace_vtime_switch_func)(newl);
  }

One more comment... If these are not enabled, then presumably you can
simply set them to (void *)nullop and skip the conditional?

(Although I'm sure somebody will be along shortly to say that casting a
function pointer that way is a bad idea :-)



Re: CVS commit: src/sys/dev/ic

2010-03-31 Thread Andrew Doran
On Wed, Mar 31, 2010 at 09:45:40AM -0500, David Young wrote:
 On Wed, Mar 31, 2010 at 05:09:41AM +, Michael Lorenz wrote:
  Module Name:src
  Committed By:   macallan
  Date:   Wed Mar 31 05:09:41 UTC 2010
  
  Modified Files:
  src/sys/dev/ic: pcf8584.c
  
  Log Message:
  Do as OpenSolaris does and read the status register after each write.
  Now this driver works on my Blade 2500.
 
  void
  pcfiic_write(struct pcfiic_softc *sc, bus_size_t r, u_int8_t v)
  {
 +   volatile uint8_t junk;
 bus_space_write_1(sc-sc_iot, sc-sc_ioh, sc-sc_regmap[r], v);
 +   junk = bus_space_read_1(sc-sc_iot, sc-sc_ioh, PCF_S1);
 bus_space_barrier(sc-sc_iot, sc-sc_ioh, sc-sc_regmap[r], 1,
 BUS_SPACE_BARRIER_WRITE);
  }
 
 I wonder, does the device need the read, or is the bus_space_barrier()
 insufficient to flush the write to the device?

Additionally, should this read not be after the barrier?



Re: CVS commit: src/sys/miscfs/specfs

2010-04-13 Thread Andrew Doran
On Tue, Apr 13, 2010 at 10:47:51AM +0300, Antti Kantee wrote:
 On Tue Apr 13 2010 at 01:15:56 +, Adam Hoka wrote:
  Module Name:src
  Committed By:   ahoka
  Date:   Tue Apr 13 01:15:56 UTC 2010
  
  Modified Files:
  src/sys/miscfs/specfs: spec_vnops.c
  
  Log Message:
  Autoload modules with any class.
  
  This fixes autoloading of pf, zfs and possibly others.
 
 What is wrong with making drivers MODULE_CLASS_DRIVER?  I think we
 should limit autoload aiming for safety, not splatter it all over.
 
 Eventually everything will of course be fixed by, *tadaa*, devfs.
 Meanwhile, please back this out and if you don't think calling a driver
 a driver is the right thing to do, have a discussion.

What's the problem with autoloading any class?  Is it just a cosmetic thing?
One doesn't have to be an anointed driver to have an entry in /dev.

(It implies that the modules and devsw entries inhabit the same namespace.)



Re: CVS commit: src/sys/dist/pf/net

2010-04-13 Thread Andrew Doran
On Tue, Apr 13, 2010 at 02:54:23PM +0300, Antti Kantee wrote:
 On Tue Apr 13 2010 at 01:02:44 +, Adam Hoka wrote:
  Module Name:src
  Committed By:   ahoka
  Date:   Tue Apr 13 01:02:43 UTC 2010
  
  Modified Files:
  src/sys/dist/pf/net: pf_ioctl.c
  
  Log Message:
  Do not auto unload pf if it's enabled.
 
 Well what happens if you non-auto unload it when it's enabled?  Just let
 unload fail if it's busy.

There are a few issues with this:

- Unload should be atomic.  If it fails for some reason, we must not
  urinate in the user's corkflakes. So on that basis the EBUSY check
  belongs in the CMD_UNLOAD block.

- At the point this is called, only module_lock is held.  So there
  is no locking in at least the autounload case noted.  Presumably the
  same is true for unload?  That could cause crashes and is therefore
  unacceptable.  (A strong choice of words - I am not trying to frustrate
  or rile anyone.  As we say in Dublin the truth does be bitter. :-)

- ENOTTY implies I don't understand what you just asked, zero would
  be a better return code as in yes that's fine, whatever. :-)

This all needs to be written down somewhere, I'll have a look.

   #ifdef _KERNEL_OPT
   #include opt_inet.h
  @@ -3367,6 +3367,13 @@
  pfdetach();
  pflogdetach();
  return devsw_detach(NULL, pf_cdevsw);
  +   case MODULE_CMD_AUTOUNLOAD:
  +   /* Do not auto unload pf if it's enabled. */
  +   if (pf_status.running) {
  +   return EBUSY;
  +   } else {
  +   return ENOTTY;
  +   }
  default:
  return ENOTTY;
  }



Re: CVS commit: src/sys/miscfs/specfs

2010-04-13 Thread Andrew Doran
On Tue, Apr 13, 2010 at 03:27:11PM +0300, Antti Kantee wrote:
 On Tue Apr 13 2010 at 12:18:38 +, Andrew Doran wrote:
  On Tue, Apr 13, 2010 at 10:47:51AM +0300, Antti Kantee wrote:
   On Tue Apr 13 2010 at 01:15:56 +, Adam Hoka wrote:
Module Name:src
Committed By:   ahoka
Date:   Tue Apr 13 01:15:56 UTC 2010

Modified Files:
src/sys/miscfs/specfs: spec_vnops.c

Log Message:
Autoload modules with any class.

This fixes autoloading of pf, zfs and possibly others.
   
   What is wrong with making drivers MODULE_CLASS_DRIVER?  I think we
   should limit autoload aiming for safety, not splatter it all over.
   
   Eventually everything will of course be fixed by, *tadaa*, devfs.
   Meanwhile, please back this out and if you don't think calling a driver
   a driver is the right thing to do, have a discussion.
  
  What's the problem with autoloading any class?  Is it just a cosmetic thing?
 
 I already mentioned my opinion above: aim for safety.  Since there
 is currently no common place to manage the different names we have,
 I don't want to discover some day that e.g. some secmodel name matches
 a devsw name.

So the kernel of the problem is namespace collisions, correct?

Would you agree that's it's the kernel programmers responsibility
to avoid conflicts?

If so how about sprinkling a little process in order to make it harder to
screw up?



Re: CVS commit: src/sys/miscfs/specfs

2010-04-13 Thread Andrew Doran
On Tue, Apr 13, 2010 at 03:40:24PM +0300, Antti Kantee wrote:
 On Tue Apr 13 2010 at 12:32:38 +, Andrew Doran wrote:
  So the kernel of the problem is namespace collisions, correct?
 
 Mostly.  Though I still think it's not expected that opening a /dev
 node will load e.g. an exec package or secmodel even if that's what some
 programmer wants.
 
  Would you agree that's it's the kernel programmers responsibility
  to avoid conflicts?
  
  If so how about sprinkling a little process in order to make it harder to
  screw up?
 
 I'd say computers do conflict detection better.

So the result of our teeth-pulling so far is:

1. You are concerned about namespace conflicts.  I am too.
2. I would be happy to see these managed through documentation and
   a straightforward approval process for adding modules.
3. You suggest that it would be better for the computer to manage it.

Can you suggest an alternative mechanism that will (a) allow us to
autoload things that are not anointed device drivers and (b) satisfy
your concerns?

As an example of something that wants autoloading both as a file
system and a driver, see ZFS.



Re: CVS commit: src/sys

2010-04-29 Thread Andrew Doran
On Thu, Apr 29, 2010 at 09:39:50AM +1000, matthew green wrote:

Modified Files:
   src/sys/arch/amd64/amd64: busfunc.S genassym.cf mainbus.c
   src/sys/arch/i386/i386: apmbios.c busfunc.S genassym.cf ipkdb_glue.c
   mainbus.c
   src/sys/arch/i386/isa: isapnp_machdep.c
   src/sys/arch/i386/pci: pceb.c pcibios.c pcmb.c
   src/sys/arch/i386/pnpbios: pnpbios.c
   src/sys/arch/i386/xbox: xbox.c xboxfb.c
   src/sys/arch/x86/include: bus.h
   src/sys/arch/x86/pci: pcib.c
   src/sys/arch/x86/x86: acpi_machdep.c bus_space.c consinit.c
   genfb_machdep.c
   src/sys/arch/xen/x86: consinit.c mainbus.c
   src/sys/arch/xen/xen: hypervisor.c xpci_xenbus.c
   src/sys/compat/ndis: nbcompat.h
   src/sys/dev/if_ndis: if_ndis_pci.c
   src/sys/dev/pci: puccn.c

Log Message:
On x86, change the bus_space_tag_t to a pointer to a struct
bus_space_tag.  For now, bus_space_tag's only member is
bst_type, the type of space, which is either X86_BUS_SPACE_IO
or X86_BUS_SPACE_MEM.  In the future, new bus_space_tag members
will refer to override-functions installed by a new function,
bus_space_tag_create(9).

Add pointers to constant struct bus_space_tag, x86_bus_space_io and
x86_bus_space_mem.  Use them to replace most uses of X86_BUS_SPACE_IO
and X86_BUS_SPACE_MEM.

Add an x86-specific bus_space_is_equal(9) implementation that compares
the two tags' bst_type.
 
 this needs a kernel version bump i believe.  old drivers
 should be allowed to load anymore...  at the very least,
 the *drm driver modules will be broken.
 
 annoying that an MD change requires the MI version to bump
 but these sorts of changes aren't too common i guess.

Also annoying that so much of this code is MD.

Please run large x86 changes by me before commit.  I would have told you
what Matt just did :-).  FYI you can now remove the #error from both busfunc.S
and special _ALIGN_TEXT definitions since the sizes of the routines will be
quite different now.



Re: CVS commit: src/sys/kern

2010-08-17 Thread Andrew Doran
On Tue, Aug 17, 2010 at 04:45:36PM +0300, Antti Kantee wrote:
 On Tue Aug 17 2010 at 15:41:11 +0200, Juergen Hannken-Illjes wrote:
vp-v_freelisthd = NULL;
mutex_exit(vnode_free_list_lock);
 
-   if (vp-v_usecount != 0) {
-   /*
-* was referenced again before we got the interlock
-* Don't return to freelist - the holder of the last
-* reference will destroy it.
-*/
-   mutex_exit(vp-v_interlock);
-   mutex_enter(vnode_free_list_lock);
-   goto retry;
-   }
+   KASSERT(vp-v_usecount == 0);
   
   It's not obvious from your commit message what prevents it from gaining
   a reference after the lock is dropped.
  
  The interlock is taken before the freelist lock is dropped and vnodes on
  the free lists should never appear on other lists.
 
 Not even the name cache?
 
 (I can't remember off the top of my head, but IIRC there's something
 sneaky about it)

They can still appear on mount lists I think (it has been a while)..
Are these changes in diff format anywhere?



Re: CVS commit: src/sys/arch

2010-08-17 Thread Andrew Doran
Hi,

Why are any types other than in the pmap different between PAE and !PAE?

When this was originally proposed I asked for stuff like paddr_t to be 64
bits no matter what the kernel compile settings where.

Thanks.


On Mon, Aug 16, 2010 at 10:45:10PM +0200, Jean-Yves Migeon wrote:
 On 16.08.2010 22:22, matthew green wrote:
  Module Name:   src
  Committed By:  jym
  Date:  Mon Aug 16 19:39:06 UTC 2010
 
  Modified Files:
 src/sys/arch/i386/i386: machdep.c
 src/sys/arch/x86/include: cpu.h
 
  Log Message:
  Add machdep.pae sysctl(7) for i386. Thanks to Paul and Joerg for their
  reviews.
 
  In kernel, it matches the 'i386_use_pae' variable (0: kernel does not use
  PAE, 1: kernel uses PAE). Will be used by i386 kvm(3) to know the functions
  that should get called for VA = PA translations.
  
  does this work for core files as well?
 
  if not, wouldn't this feature be better done use ugly kvm/nlist so
  that it works with the same code on dead kernels?  getting a 0/1
  value via kvm shouldn't really be considered any real problem.
 
 That's the purpose; I don't know of any other way. The sysctl is only
 there for practical purposes: cpuctl(8) can indicate that the CPU
 supports PAE, but there is no easy way to know if it is active or not
 (unless playing with config -x together with the booted kernel, not very
 practical...). Hence, the sysctl machdep.
 
  (why the extern in cpu.h?  i doesn't seem necessary.)
 
 Yes; I wanted to place it at the same level as i386_use_fxsave.
 i386_use_pae may get use elsewhere eventually, so I added it to cpu.h.
 
 -- 
 Jean-Yves Migeon
 jeanyves.mig...@free.fr


Re: CVS commit: src

2010-10-08 Thread Andrew Doran
On Thu, Oct 07, 2010 at 01:33:46AM +0200, Jean-Yves Migeon wrote:
 On 06.10.2010 12:16, Manuel Bouyer wrote:
  On Tue, Oct 05, 2010 at 11:48:17PM +, Jean-Yves Migeon wrote:
  [...]
 
  XXX Currently, savecore(8) will fail to dump a PAE kernel in a !PAE
  environment (and reciprocally). So you need to sync and reboot
  with a kernel of the same mode as the one that crashed. Once the dump
  is successful, this does not matter anymore.
  
  Doesn't it work with savecore -N /the_right_kernel ?
 
 No; in fact, dumplo is complete garbage, so savecore fails dumping the
 image.
 
 I suspect that the KREAD() in savecore.c does not read at the correct
 offset, and just sets garbage for dumplo.
 
 I have to see what code path takes savecore with -N, and where it
 differs from the case where it goes through getbootfile(3) when the
 booted kernel is different from the one that is about to get dumped.

Just thinking out loud:

With the ksyms dump code I added, the kernel image is only used to find
the symbol table etc.  It would be nice to eventually ditch the need for
a kernel image.  Everything required is already in the dump, we just need
to extract the symbol table from ksyms.

Also, on reflection I think that crash(8) is a better all round deal than
the limited debug symbols we were thinking about previously.



Re: CVS commit: src/sys/kern

2010-10-14 Thread Andrew Doran
On Thu, Oct 14, 2010 at 04:59:42AM +0100, Mindaugas Rasiukevicius wrote:
 Hello,
 
 Masaru OKI o...@netbsd.org wrote:
  Module Name:src
  Committed By:   oki
  Date:   Thu Oct 14 03:07:52 UTC 2010
  
  Modified Files:
  src/sys/kern: uipc_socket.c
  
  Log Message:
  Wait for freeing mbuf cluster in sosend() causes freeze network stack.
  Don't wait for it.
  problem was found by iij seil team.
  it is similar to OpenBSD uipc_socket.c rev.1.72.
 
 Can you explain what the actual problem M_WAIT causes i.e. how would
 it freeze network stack?

I don't see what it would solve on the face of it, but regardless M_DONTWAIT
is almost certainly the wrong thing to do here.



Re: CVS commit: src/sys/kern

2010-10-15 Thread Andrew Doran
On Fri, Oct 15, 2010 at 05:30:52PM +0100, Mindaugas Rasiukevicius wrote:
 o...@netbsd.org wrote:
  In M_WAIT case, m_reclaim() will run and run until get mbuf cluster
  if mclpool limit reached.  If m_reclaim() repeatedly but cannot to
  get new mbuf cluster, m_clget() will not return.
  
  network stacks using mbufs is use with M_DONTWAIT, but it will failed
  to get new mbuf cluster in this case.  freeze means that.
 
 Yes, hitting the limit would trigger m_reclaim() and m_clget() would
 block.  It is a quite similar condition to memory or KVA starvation.
 However, why such blocking in sosend() is problematic, or, how is it
 different from any other WAITOK allocation?
 
 I see the point about the limit.  Inadequately low limit may cause many
 blocking processes, while there is still a lot of memory.  However, in
 such case, perhaps you want PR_LIMITFAIL, instead of PR_NOWAIT?  Note
 that PR_NOWAIT (M_DONTWAIT) has other implications, e.g. it might fail
 due to try-locks.  So, I think your fix is incorrect.

Agreed.  NOWAIT should almost never be used from thread/process context,
it indicates that an underlying problem is not being tackled properly.
In this case it may introduce sporadic and hard to reproduce failures.
If we're not going to fix the reclaim problem in the near future I suggest
it's better to change this back to WAITOK.



Re: CVS commit: src/sys/kern

2010-12-03 Thread Andrew Doran
On Fri, Oct 15, 2010 at 10:33:22PM +, Andrew Doran wrote:
 On Fri, Oct 15, 2010 at 05:30:52PM +0100, Mindaugas Rasiukevicius wrote:
  o...@netbsd.org wrote:
   In M_WAIT case, m_reclaim() will run and run until get mbuf cluster
   if mclpool limit reached.  If m_reclaim() repeatedly but cannot to
   get new mbuf cluster, m_clget() will not return.
   
   network stacks using mbufs is use with M_DONTWAIT, but it will failed
   to get new mbuf cluster in this case.  freeze means that.
  
  Yes, hitting the limit would trigger m_reclaim() and m_clget() would
  block.  It is a quite similar condition to memory or KVA starvation.
  However, why such blocking in sosend() is problematic, or, how is it
  different from any other WAITOK allocation?
  
  I see the point about the limit.  Inadequately low limit may cause many
  blocking processes, while there is still a lot of memory.  However, in
  such case, perhaps you want PR_LIMITFAIL, instead of PR_NOWAIT?  Note
  that PR_NOWAIT (M_DONTWAIT) has other implications, e.g. it might fail
  due to try-locks.  So, I think your fix is incorrect.
 
 Agreed.  NOWAIT should almost never be used from thread/process context,
 it indicates that an underlying problem is not being tackled properly.
 In this case it may introduce sporadic and hard to reproduce failures.
 If we're not going to fix the reclaim problem in the near future I suggest
 it's better to change this back to WAITOK.

Has this been fixed?

The least objectionable hack that I can see would be to add an analogue 
of PR_LIMITFAIL.

Thanks.
 


Re: CVS commit: src/sys

2011-03-01 Thread Andrew Doran
On Mon, Feb 28, 2011 at 04:48:43PM +, Mindaugas Rasiukevicius wrote:
 Jukka Ruohonen jru...@netbsd.org wrote:
  Module Name:src
  Committed By:   jruoho
  Date:   Fri Feb 25 09:16:00 UTC 2011
  
  Modified Files:
  src/sys/arch/x86/acpi: acpi_cpu_md.c
  src/sys/dev/acpi: acpi_cpu.h acpi_cpu_pstate.c
  
  Log Message:
  Add preliminary support for the IA32_APERF and IA32_MPERF frequency
  counters. These are not yet used for anything and only Intel is supported
  at the moment.
  
  ...
 
 From acpicpu_md_pstate_percent():
 
  +   x86_disable_intr();
  +
  +   aperf = sc-sc_pstate_aperf;
  +   mperf = sc-sc_pstate_mperf;
  +
  +   xc = xc_unicast(0, acpicpu_md_pstate_percent_status, sc, NULL, ci);
  +   xc_wait(xc);
  +
  +   x86_enable_intr();
 
 Why interrupts are disabled here?  Calling xc_wait() with interrupts
 disabled is, at minimum, very expensive, and I would say it is wrong.
 Note that xc_wait(9) does not necessary spin - it can block.

You must not call these interfaces or any kind of MI synchronization
interface, spin mutexes included, with interrupts switched off at the
machine level!



Re: CVS commit: src/sys

2011-03-01 Thread Andrew Doran
On Tue, Mar 01, 2011 at 01:17:11PM +0200, Jukka Ruohonen wrote:
 On Tue, Mar 01, 2011 at 09:53:24AM +, Andrew Doran wrote:
  You must not call these interfaces or any kind of MI synchronization
  interface, spin mutexes included, with interrupts switched off at the
  machine level!
 
 Yes, of course. It was a bug in a code that is not yet used. Already fixed,
 will not happen again.

Thanks.  Also in case it's not clear my e-mail was
intended to convey surprise and not much else!  The interrupt restriction
is true for atomic operations also, incidentally.

I think maybe the only MI sync interfaces we have where it's 
OK to disable interrupts on the CPU are __cpu_simple_lock_t and
the memory barriers (membar).

Where the raw spinlocks are used it's a case of all bets are off, you
need to be aware of the side effects.  E.g. there are restrictions on how
long you can hold the locks, what sort of events you can wait for and so
on.



CVS commit: src/sys/kern

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 20:07:53 UTC 2019

Modified Files:
src/sys/kern: sched_m2.c

Log Message:
sched_tick: examine the correct LWP, and lock it.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/sched_m2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sched_m2.c
diff -u src/sys/kern/sched_m2.c:1.33 src/sys/kern/sched_m2.c:1.34
--- src/sys/kern/sched_m2.c:1.33	Mon Sep  3 16:29:35 2018
+++ src/sys/kern/sched_m2.c	Fri Nov 22 20:07:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched_m2.c,v 1.33 2018/09/03 16:29:35 riastradh Exp $	*/
+/*	$NetBSD: sched_m2.c,v 1.34 2019/11/22 20:07:53 ad Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008 Mindaugas Rasiukevicius 
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.33 2018/09/03 16:29:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_m2.c,v 1.34 2019/11/22 20:07:53 ad Exp $");
 
 #include 
 
@@ -282,19 +282,20 @@ sched_oncpu(lwp_t *l)
  */
 
 /*
- * Called once per time-quantum.  This routine is CPU-local and runs at
- * IPL_SCHED, thus the locking is not needed.
+ * Called once per time-quantum, with the running LWP lock held (spc_lwplock).
  */
 void
 sched_tick(struct cpu_info *ci)
 {
 	struct schedstate_percpu *spc = >ci_schedstate;
-	struct lwp *l = curlwp;
+	struct lwp *l = ci->ci_data.cpu_onproc;
 	struct proc *p;
 
 	if (__predict_false(CURCPU_IDLE_P()))
 		return;
 
+	lwp_lock(l);
+	KASSERT(l->l_mutex != spc->spc_mutex);
 	switch (l->l_class) {
 	case SCHED_FIFO:
 		/*
@@ -303,6 +304,7 @@ sched_tick(struct cpu_info *ci)
 		 */
 		KASSERT(l->l_priority > PRI_HIGHEST_TS);
 		spc->spc_ticks = l->l_sched.timeslice;
+		lwp_unlock(l);
 		return;
 	case SCHED_OTHER:
 		/*
@@ -328,9 +330,10 @@ sched_tick(struct cpu_info *ci)
 	 */
 	if (lwp_eprio(l) <= spc->spc_maxpriority || l->l_target_cpu) {
 		spc->spc_flags |= SPCF_SHOULDYIELD;
-		cpu_need_resched(ci, 0);
+		cpu_need_resched(ci, l, RESCHED_UPREEMPT);
 	} else
-		spc->spc_ticks = l->l_sched.timeslice;
+		spc->spc_ticks = l->l_sched.timeslice; 
+	lwp_unlock(l);
 }
 
 /*



CVS commit: src/sys/kern

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 20:07:53 UTC 2019

Modified Files:
src/sys/kern: sched_m2.c

Log Message:
sched_tick: examine the correct LWP, and lock it.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/sched_m2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 20:04:03 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_tlb.c
src/sys/kern: sys_select.c

Log Message:
Minor correction to previous.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/sys_select.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/x86_tlb.c
diff -u src/sys/arch/x86/x86/x86_tlb.c:1.9 src/sys/arch/x86/x86/x86_tlb.c:1.10
--- src/sys/arch/x86/x86/x86_tlb.c:1.9	Thu Nov 21 21:48:33 2019
+++ src/sys/arch/x86/x86/x86_tlb.c	Fri Nov 22 20:04:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_tlb.c,v 1.9 2019/11/21 21:48:33 ad Exp $	*/
+/*	$NetBSD: x86_tlb.c,v 1.10 2019/11/22 20:04:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008-2019 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.9 2019/11/21 21:48:33 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.10 2019/11/22 20:04:03 ad Exp $");
 
 #include 
 #include 
@@ -264,8 +264,7 @@ pmap_tlb_shootdown(struct pmap *pm, vadd
 	tp = (pmap_tlb_packet_t *)ci->ci_pmap_data;
 
 	/* Whole address flush will be needed if PTE_G is set. */
-	CTASSERT(PTE_G == (uint16_t)PTE_G);
-	tp->tp_global |= ((pte & PTE_G) != 0);;
+	tp->tp_global |= ((pte & PTE_G) != 0);
 	count = tp->tp_count;
 
 	if (count < TP_MAXVA && va != (vaddr_t)-1LL) {

Index: src/sys/kern/sys_select.c
diff -u src/sys/kern/sys_select.c:1.49 src/sys/kern/sys_select.c:1.50
--- src/sys/kern/sys_select.c:1.49	Thu Nov 21 21:42:30 2019
+++ src/sys/kern/sys_select.c	Fri Nov 22 20:04:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_select.c,v 1.49 2019/11/21 21:42:30 ad Exp $	*/
+/*	$NetBSD: sys_select.c,v 1.50 2019/11/22 20:04:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2019 The NetBSD Foundation, Inc.
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.49 2019/11/21 21:42:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.50 2019/11/22 20:04:03 ad Exp $");
 
 #include 
 #include 
@@ -114,9 +114,9 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c
 
 /*
  * Per-cluster state for select()/poll().  For a system with fewer
- * than 32 CPUs, this gives us per-CPU clusters.
+ * than 64 CPUs, this gives us per-CPU clusters.
  */
-#define	SELCLUSTERS	32
+#define	SELCLUSTERS	64
 #define	SELCLUSTERMASK	(SELCLUSTERS - 1)
 
 typedef struct selcluster {



CVS commit: src/sys

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 20:04:03 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_tlb.c
src/sys/kern: sys_select.c

Log Message:
Minor correction to previous.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/sys_select.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/ddb

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 23:01:49 UTC 2019

Modified Files:
src/sys/ddb: db_lex.c

Log Message:
Fix crash(8).  Will revisit.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/ddb/db_lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/ddb

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 23:01:49 UTC 2019

Modified Files:
src/sys/ddb: db_lex.c

Log Message:
Fix crash(8).  Will revisit.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/ddb/db_lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_lex.c
diff -u src/sys/ddb/db_lex.c:1.24 src/sys/ddb/db_lex.c:1.25
--- src/sys/ddb/db_lex.c:1.24	Wed Oct  2 09:36:30 2019
+++ src/sys/ddb/db_lex.c	Fri Nov 22 23:01:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_lex.c,v 1.24 2019/10/02 09:36:30 rin Exp $	*/
+/*	$NetBSD: db_lex.c,v 1.25 2019/11/22 23:01:49 ad Exp $	*/
 
 /*
  * Mach Operating System
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.24 2019/10/02 09:36:30 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.25 2019/11/22 23:01:49 ad Exp $");
 
 #include 
 #include 
@@ -62,11 +62,18 @@ db_read_line(void)
 {
 	int	i;
 
+#ifdef _KERNEL
+	/*
+	 * crash(8) prints the prompt using libedit.  That's why we used to
+	 * print it in db_readline().  But now people are using db_read_line()
+	 * for general purpose input, so..
+	 */
 #ifdef MULTIPROCESSOR
 	db_printf("db{%ld}> ", (long)cpu_number());
 #else
 	db_printf("db> ");
 #endif
+#endif
 	i = db_readline(db_line, sizeof(db_line));
 	if (i == 0)
 		return (0);	/* EOI */



CVS commit: src/sys/arch

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 23:36:25 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: locore.S
src/sys/arch/x86/x86: cpu.c

Log Message:
- On-demand zeroing pages with MOVNTI is crazy.  It empties L1/L2/L3.
- Disable zeroing in the idle loop.  That needs a cache-friendly strategy.

Result: 3 to 4% reduction in kernel build time on my test system.
Inspired by a discussion with Mateusz Guzik and David Maxwell.


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.174 -r1.175 src/sys/arch/x86/x86/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.191 src/sys/arch/amd64/amd64/locore.S:1.192
--- src/sys/arch/amd64/amd64/locore.S:1.191	Thu Nov 21 19:27:54 2019
+++ src/sys/arch/amd64/amd64/locore.S	Fri Nov 22 23:36:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.191 2019/11/21 19:27:54 ad Exp $	*/
+/*	$NetBSD: locore.S,v 1.192 2019/11/22 23:36:25 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1519,24 +1519,16 @@ END(sse2_idlezero_page)
 /*
  * void pagezero(vaddr_t va)
  *
- * Zero a page without polluting the cache.
+ * Zero a page.
  */
 ENTRY(pagezero)
-	movq	$-PAGE_SIZE,%rdx
-	subq	%rdx,%rdi
+	pushq	%rbp
+	movq	%rsp,%rbp
+	movq	$(PAGE_SIZE / 8),%rcx
 	xorq	%rax,%rax
-1:
-	movnti	%rax,(%rdi,%rdx)
-	movnti	%rax,8(%rdi,%rdx)
-	movnti	%rax,16(%rdi,%rdx)
-	movnti	%rax,24(%rdi,%rdx)
-	movnti	%rax,32(%rdi,%rdx)
-	movnti	%rax,40(%rdi,%rdx)
-	movnti	%rax,48(%rdi,%rdx)
-	movnti	%rax,56(%rdi,%rdx)
-	addq	$64,%rdx
-	jne	1b
-	sfence
+	rep
+	stosq
+	leave
 	ret
 END(pagezero)
 

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.174 src/sys/arch/x86/x86/cpu.c:1.175
--- src/sys/arch/x86/x86/cpu.c:1.174	Tue Nov  5 20:19:17 2019
+++ src/sys/arch/x86/x86/cpu.c	Fri Nov 22 23:36:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.174 2019/11/05 20:19:17 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.175 2019/11/22 23:36:25 ad Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.174 2019/11/05 20:19:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.175 2019/11/22 23:36:25 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -723,7 +723,7 @@ cpu_boot_secondary_processors(void)
 	tsc_tc_init();
 
 	/* Enable zeroing of pages in the idle loop if we have SSE2. */
-	vm_page_zero_enable = ((cpu_feature[0] & CPUID_SSE2) != 0);
+	vm_page_zero_enable = false; /* ((cpu_feature[0] & CPUID_SSE2) != 0); */
 }
 #endif
 



CVS commit: src/sys/sys

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 23:38:15 UTC 2019

Modified Files:
src/sys/sys: userret.h

Log Message:
Add a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/userret.h
diff -u src/sys/sys/userret.h:1.29 src/sys/sys/userret.h:1.30
--- src/sys/sys/userret.h:1.29	Thu Nov 21 19:24:02 2019
+++ src/sys/sys/userret.h	Fri Nov 22 23:38:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.29 2019/11/21 19:24:02 ad Exp $	*/
+/*	$NetBSD: userret.h,v 1.30 2019/11/22 23:38:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2003, 2006, 2008, 2019 The NetBSD Foundation, Inc.
@@ -101,6 +101,12 @@ mi_userret(struct lwp *l)
 		ci = l->l_cpu;
 	}
 	l->l_kpriority = false;
+	/*
+	 * lwp_eprio() is too involved to use here unlocked.  At this point
+	 * it only matters for PTHREAD_PRIO_PROTECT; setting a too low value
+	 * is OK because the scheduler will find out the true value if we
+	 * end up in mi_switch().
+	 */
 	ci->ci_schedstate.spc_curpriority = l->l_priority;
 	KPREEMPT_ENABLE(l);
 



CVS commit: src/sys/sys

2019-11-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 22 23:38:15 UTC 2019

Modified Files:
src/sys/sys: userret.h

Log Message:
Add a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:56:55 UTC 2019

Modified Files:
src/sys/kern: kern_sleepq.c kern_turnstile.c
src/sys/sys: sleepq.h

Log Message:
Sleep queues & turnstiles:

- Avoid false sharing.
- Make the turnstile hash function more suitable.
- Increase turnstile hash table size.
- Make amends by having only one set of system wide sleep queue hash locks.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.32 -r1.33 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.25 -r1.26 src/sys/sys/sleepq.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:56:55 UTC 2019

Modified Files:
src/sys/kern: kern_sleepq.c kern_turnstile.c
src/sys/sys: sleepq.h

Log Message:
Sleep queues & turnstiles:

- Avoid false sharing.
- Make the turnstile hash function more suitable.
- Increase turnstile hash table size.
- Make amends by having only one set of system wide sleep queue hash locks.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_sleepq.c
cvs rdiff -u -r1.32 -r1.33 src/sys/kern/kern_turnstile.c
cvs rdiff -u -r1.25 -r1.26 src/sys/sys/sleepq.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_sleepq.c
diff -u src/sys/kern/kern_sleepq.c:1.51 src/sys/kern/kern_sleepq.c:1.52
--- src/sys/kern/kern_sleepq.c:1.51	Sun Jul  3 14:24:58 2016
+++ src/sys/kern/kern_sleepq.c	Thu Nov 21 18:56:55 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_sleepq.c,v 1.51 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: kern_sleepq.c,v 1.52 2019/11/21 18:56:55 ad Exp $	*/
 
 /*-
- * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.51 2016/07/03 14:24:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.52 2019/11/21 18:56:55 ad Exp $");
 
 #include 
 #include 
@@ -65,7 +65,8 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sleepq.
 static int	sleepq_sigtoerror(lwp_t *, int);
 
 /* General purpose sleep table, used by mtsleep() and condition variables. */
-sleeptab_t	sleeptab	__cacheline_aligned;
+sleeptab_t	sleeptab __cacheline_aligned;
+kmutex_t	*sleepq_locks[SLEEPTAB_HASH_SIZE] __read_mostly;
 
 /*
  * sleeptab_init:
@@ -75,14 +76,11 @@ sleeptab_t	sleeptab	__cacheline_aligned;
 void
 sleeptab_init(sleeptab_t *st)
 {
-	sleepq_t *sq;
 	int i;
 
 	for (i = 0; i < SLEEPTAB_HASH_SIZE; i++) {
-		sq = >st_queues[i].st_queue;
-		st->st_queues[i].st_mutex =
-		mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
-		sleepq_init(sq);
+		sleepq_locks[i] = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED);
+		sleepq_init(>st_queue[i]);
 	}
 }
 
@@ -266,8 +264,12 @@ sleepq_block(int timo, bool catch_p)
 		/* The LWP and sleep queue are now unlocked. */
 		if (timo) {
 			/*
-			 * Even if the callout appears to have fired, we need to
-			 * stop it in order to synchronise with other CPUs.
+			 * Even if the callout appears to have fired, we
+			 * need to stop it in order to synchronise with
+			 * other CPUs.  It's important that we do this in
+			 * this LWP's context, and not during wakeup, in
+			 * order to keep the callout & its cache lines
+			 * co-located on the CPU with the LWP.
 			 */
 			if (callout_halt(>l_timeout_ch, NULL))
 error = EWOULDBLOCK;
@@ -333,10 +335,10 @@ sleepq_wake(sleepq_t *sq, wchan_t wchan,
  *
  *	Remove an LWP from its sleep queue and set it runnable again. 
  *	sleepq_unsleep() is called with the LWP's mutex held, and will
- *	always release it.
+ *	release it if "unlock" is true.
  */
 void
-sleepq_unsleep(lwp_t *l, bool cleanup)
+sleepq_unsleep(lwp_t *l, bool unlock)
 {
 	sleepq_t *sq = l->l_sleepq;
 	kmutex_t *mp = l->l_mutex;
@@ -345,7 +347,7 @@ sleepq_unsleep(lwp_t *l, bool cleanup)
 	KASSERT(l->l_wchan != NULL);
 
 	sleepq_remove(sq, l);
-	if (cleanup) {
+	if (unlock) {
 		mutex_spin_exit(mp);
 	}
 }

Index: src/sys/kern/kern_turnstile.c
diff -u src/sys/kern/kern_turnstile.c:1.32 src/sys/kern/kern_turnstile.c:1.33
--- src/sys/kern/kern_turnstile.c:1.32	Fri Jun 15 13:51:40 2012
+++ src/sys/kern/kern_turnstile.c	Thu Nov 21 18:56:55 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_turnstile.c,v 1.32 2012/06/15 13:51:40 yamt Exp $	*/
+/*	$NetBSD: kern_turnstile.c,v 1.33 2019/11/21 18:56:55 ad Exp $	*/
 
 /*-
- * Copyright (c) 2002, 2006, 2007, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2006, 2007, 2009, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -56,11 +56,11 @@
  * grabs a free turnstile off the free list.  Otherwise, it can take back
  * the active turnstile from the lock (thus deactivating the turnstile).
  *
- * Turnstiles are the place to do priority inheritence.
+ * Turnstiles are where we do priority inheritence.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.32 2012/06/15 13:51:40 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.33 2019/11/21 18:56:55 ad Exp $");
 
 #include 
 #include 
@@ -69,17 +69,23 @@ __KERNEL_RCSID(0, "$NetBSD: kern_turnsti
 #include 
 #include 
 
-#define	TS_HASH_SIZE	64
+/*
+ * Shift of 6 aligns to typical cache line size of 64 bytes;  there's no
+ * point having two turnstile locks to back two lock objects that share 

CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:50:49 UTC 2019

Modified Files:
src/sys/kern: kern_resource.c kern_softint.c

Log Message:
calcru: ignore running softints, unless softint_timing is on.
Fixes crazy times reported for proc0.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/kern_softint.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:50:49 UTC 2019

Modified Files:
src/sys/kern: kern_resource.c kern_softint.c

Log Message:
calcru: ignore running softints, unless softint_timing is on.
Fixes crazy times reported for proc0.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/kern/kern_resource.c
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/kern_softint.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_resource.c
diff -u src/sys/kern/kern_resource.c:1.182 src/sys/kern/kern_resource.c:1.183
--- src/sys/kern/kern_resource.c:1.182	Fri Apr  5 00:33:21 2019
+++ src/sys/kern/kern_resource.c	Thu Nov 21 17:50:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_resource.c,v 1.182 2019/04/05 00:33:21 mlelstv Exp $	*/
+/*	$NetBSD: kern_resource.c,v 1.183 2019/11/21 17:50:49 ad Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.182 2019/04/05 00:33:21 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.183 2019/11/21 17:50:49 ad Exp $");
 
 #include 
 #include 
@@ -506,7 +506,8 @@ calcru(struct proc *p, struct timeval *u
 	LIST_FOREACH(l, >p_lwps, l_sibling) {
 		lwp_lock(l);
 		bintime_add(, >l_rtime);
-		if ((l->l_pflag & LP_RUNNING) != 0) {
+		if ((l->l_pflag & LP_RUNNING) != 0 &&
+		(l->l_pflag & (LP_INTR | LP_TIMEINTR)) != LP_INTR) {
 			struct bintime diff;
 			/*
 			 * Adjust for the current time slice.  This is
@@ -516,6 +517,7 @@ calcru(struct proc *p, struct timeval *u
 			 * error.
 			 */
 			binuptime();
+			membar_consumer(); /* for softint_dispatch() */
 			bintime_sub(, >l_stime);
 			bintime_add(, );
 		}

Index: src/sys/kern/kern_softint.c
diff -u src/sys/kern/kern_softint.c:1.48 src/sys/kern/kern_softint.c:1.49
--- src/sys/kern/kern_softint.c:1.48	Sun Oct  6 15:11:17 2019
+++ src/sys/kern/kern_softint.c	Thu Nov 21 17:50:49 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_softint.c,v 1.48 2019/10/06 15:11:17 uwe Exp $	*/
+/*	$NetBSD: kern_softint.c,v 1.49 2019/11/21 17:50:49 ad Exp $	*/
 
 /*-
- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2008, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -170,7 +170,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.48 2019/10/06 15:11:17 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.49 2019/11/21 17:50:49 ad Exp $");
 
 #include 
 #include 
@@ -866,14 +866,16 @@ softint_dispatch(lwp_t *pinned, int s)
 	timing = (softint_timing ? LP_TIMEINTR : 0);
 	l->l_switchto = pinned;
 	l->l_stat = LSONPROC;
-	l->l_pflag |= (LP_RUNNING | timing);
 
 	/*
 	 * Dispatch the interrupt.  If softints are being timed, charge
 	 * for it.
 	 */
-	if (timing)
+	if (timing) {
 		binuptime(>l_stime);
+		membar_producer();	/* for calcru */
+	}
+	l->l_pflag |= (LP_RUNNING | timing);
 	softint_execute(si, l, s);
 	if (timing) {
 		binuptime();



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:17:36 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c kern_sig.c

Log Message:
- lwp_need_userret(): only do it if ONPROC and !curlwp, and explain why.
- Use signotify() in a couple more places.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.379 -r1.380 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:17:36 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c kern_sig.c

Log Message:
- lwp_need_userret(): only do it if ONPROC and !curlwp, and explain why.
- Use signotify() in a couple more places.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.379 -r1.380 src/sys/kern/kern_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.208 src/sys/kern/kern_lwp.c:1.209
--- src/sys/kern/kern_lwp.c:1.208	Thu Nov 14 16:23:52 2019
+++ src/sys/kern/kern_lwp.c	Thu Nov 21 18:17:36 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_lwp.c,v 1.208 2019/11/14 16:23:52 maxv Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.209 2019/11/21 18:17:36 ad Exp $	*/
 
 /*-
- * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.208 2019/11/14 16:23:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.209 2019/11/21 18:17:36 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1147,7 +1147,7 @@ lwp_exit(struct lwp *l)
 	firstsig(>p_sigpend.sp_set) != 0) {
 		LIST_FOREACH(l2, >p_lwps, l_sibling) {
 			lwp_lock(l2);
-			l2->l_flag |= LW_PENDSIG;
+			signotify(l2);
 			lwp_unlock(l2);
 		}
 	}
@@ -1616,15 +1616,26 @@ lwp_userret(struct lwp *l)
 void
 lwp_need_userret(struct lwp *l)
 {
+
+	KASSERT(!cpu_intr_p());
 	KASSERT(lwp_locked(l, NULL));
 
 	/*
-	 * Since the tests in lwp_userret() are done unlocked, make sure
-	 * that the condition will be seen before forcing the LWP to enter
-	 * kernel mode.
-	 */
-	membar_producer();
-	cpu_signotify(l);
+	 * If the LWP is in any state other than LSONPROC, we know that it
+	 * is executing in-kernel and will hit userret() on the way out. 
+	 *
+	 * If the LWP is curlwp, then we know we'll be back out to userspace
+	 * soon (can't be called from a hardware interrupt here).
+	 *
+	 * Otherwise, we can't be sure what the LWP is doing, so first make
+	 * sure the update to l_flag will be globally visible, and then
+	 * force the LWP to take a trip through trap() where it will do
+	 * userret().
+	 */
+	if (l->l_stat == LSONPROC && l != curlwp) {
+		membar_producer();
+		cpu_signotify(l);
+	}
 }
 
 /*

Index: src/sys/kern/kern_sig.c
diff -u src/sys/kern/kern_sig.c:1.379 src/sys/kern/kern_sig.c:1.380
--- src/sys/kern/kern_sig.c:1.379	Wed Nov 20 19:37:53 2019
+++ src/sys/kern/kern_sig.c	Thu Nov 21 18:17:36 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_sig.c,v 1.379 2019/11/20 19:37:53 pgoyette Exp $	*/
+/*	$NetBSD: kern_sig.c,v 1.380 2019/11/21 18:17:36 ad Exp $	*/
 
 /*-
- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.379 2019/11/20 19:37:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.380 2019/11/21 18:17:36 ad Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -710,6 +710,9 @@ sigclearall(struct proc *p, const sigset
  *	current LWP.  May be called unlocked provided that LW_PENDSIG is set,
  *	and that the signal has been posted to the appopriate queue before
  *	LW_PENDSIG is set.
+ *
+ *	This should only ever be called with (l == curlwp), unless the
+ *	result does not matter (procfs, sysctl).
  */ 
 int
 sigispending(struct lwp *l, int signo)
@@ -1133,7 +1136,7 @@ sigpost(struct lwp *l, sig_t action, int
 	 * Have the LWP check for signals.  This ensures that even if no LWP
 	 * is found to take the signal immediately, it should be taken soon.
 	 */
-	l->l_flag |= LW_PENDSIG;
+	signotify(l);
 
 	/*
 	 * SIGCONT can be masked, but if LWP is stopped, it needs restart.
@@ -1167,7 +1170,6 @@ sigpost(struct lwp *l, sig_t action, int
 	switch (l->l_stat) {
 	case LSRUN:
 	case LSONPROC:
-		lwp_need_userret(l);
 		rv = 1;
 		break;
 



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:57:40 UTC 2019

Modified Files:
src/sys/kern: kern_timeout.c

Log Message:
Break the slow path for callout_halt() out into its own routine.
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_timeout.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_timeout.c
diff -u src/sys/kern/kern_timeout.c:1.56 src/sys/kern/kern_timeout.c:1.57
--- src/sys/kern/kern_timeout.c:1.56	Sun Mar 10 13:44:49 2019
+++ src/sys/kern/kern_timeout.c	Thu Nov 21 17:57:40 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_timeout.c,v 1.56 2019/03/10 13:44:49 kre Exp $	*/
+/*	$NetBSD: kern_timeout.c,v 1.57 2019/11/21 17:57:40 ad Exp $	*/
 
 /*-
- * Copyright (c) 2003, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.56 2019/03/10 13:44:49 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.57 2019/11/21 17:57:40 ad Exp $");
 
 /*
  * Timeouts are kept in a hierarchical timing wheel.  The c_time is the
@@ -185,8 +185,10 @@ struct callout_cpu {
 #ifndef CRASH
 
 static void	callout_softclock(void *);
-static struct callout_cpu callout_cpu0;
-static void *callout_sih;
+static void	callout_wait(callout_impl_t *, void *, kmutex_t *);
+
+static struct callout_cpu callout_cpu0 __cacheline_aligned;
+static void *callout_sih __read_mostly;
 
 static inline kmutex_t *
 callout_lock(callout_impl_t *c)
@@ -466,24 +468,42 @@ bool
 callout_halt(callout_t *cs, void *interlock)
 {
 	callout_impl_t *c = (callout_impl_t *)cs;
-	struct callout_cpu *cc;
-	struct lwp *l;
-	kmutex_t *lock, *relock;
-	bool expired;
+	kmutex_t *lock;
+	int flags;
 
 	KASSERT(c->c_magic == CALLOUT_MAGIC);
 	KASSERT(!cpu_intr_p());
 	KASSERT(interlock == NULL || mutex_owned(interlock));
 
+	/* Fast path. */
 	lock = callout_lock(c);
-	relock = NULL;
-
-	expired = ((c->c_flags & CALLOUT_FIRED) != 0);
-	if ((c->c_flags & CALLOUT_PENDING) != 0)
+	flags = c->c_flags;
+	if ((flags & CALLOUT_PENDING) != 0)
 		CIRCQ_REMOVE(>c_list);
-	c->c_flags &= ~(CALLOUT_PENDING|CALLOUT_FIRED);
+	c->c_flags = flags & ~(CALLOUT_PENDING|CALLOUT_FIRED);
+	if (__predict_false(flags & CALLOUT_FIRED)) {
+		callout_wait(c, interlock, lock);
+		return true;
+	}
+	mutex_spin_exit(lock);
+	return false;
+}
+
+/*
+ * callout_wait:
+ *
+ *	Slow path for callout_halt().  Deliberately marked __noinline to
+ *	prevent unneeded overhead in the caller.
+ */
+static void __noinline
+callout_wait(callout_impl_t *c, void *interlock, kmutex_t *lock)
+{
+	struct callout_cpu *cc;
+	struct lwp *l;
+	kmutex_t *relock;
 
 	l = curlwp;
+	relock = NULL;
 	for (;;) {
 		cc = c->c_cpu;
 		if (__predict_true(cc->cc_active != c || cc->cc_lwp == l))
@@ -515,8 +535,6 @@ callout_halt(callout_t *cs, void *interl
 	mutex_spin_exit(lock);
 	if (__predict_false(relock != NULL))
 		mutex_enter(relock);
-
-	return expired;
 }
 
 #ifdef notyet



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:57:40 UTC 2019

Modified Files:
src/sys/kern: kern_timeout.c

Log Message:
Break the slow path for callout_halt() out into its own routine.
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_timeout.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/alpha/alpha

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:02:43 UTC 2019

Modified Files:
src/sys/arch/alpha/alpha: ipifuncs.c

Log Message:
alpha_ipi_ast: use ci_data.cpu_onproc, not ci_curlwp.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/alpha/ipifuncs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/alpha/alpha

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:02:43 UTC 2019

Modified Files:
src/sys/arch/alpha/alpha: ipifuncs.c

Log Message:
alpha_ipi_ast: use ci_data.cpu_onproc, not ci_curlwp.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/alpha/ipifuncs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/ipifuncs.c
diff -u src/sys/arch/alpha/alpha/ipifuncs.c:1.48 src/sys/arch/alpha/alpha/ipifuncs.c:1.49
--- src/sys/arch/alpha/alpha/ipifuncs.c:1.48	Mon May 19 22:47:53 2014
+++ src/sys/arch/alpha/alpha/ipifuncs.c	Thu Nov 21 19:02:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ipifuncs.c,v 1.48 2014/05/19 22:47:53 rmind Exp $ */
+/* $NetBSD: ipifuncs.c,v 1.49 2019/11/21 19:02:43 ad Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.48 2014/05/19 22:47:53 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.49 2019/11/21 19:02:43 ad Exp $");
 
 /*
  * Interprocessor interrupt handlers.
@@ -263,8 +263,8 @@ static void
 alpha_ipi_ast(struct cpu_info *ci, struct trapframe *framep)
 {
 
-	if (ci->ci_curlwp != ci->ci_data.cpu_idlelwp)
-		aston(ci->ci_curlwp);
+	if (ci->ci_data.cpu_onproc != ci->ci_data.cpu_idlelwp)
+		aston(ci->ci_data.cpu_onproc);
 }
 
 static void



CVS commit: src/sys/dev/pci

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:47:23 UTC 2019

Modified Files:
src/sys/dev/pci: ichsmb.c

Log Message:
If attach fails, don't panic on detach.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pci/ichsmb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:54:04 UTC 2019

Modified Files:
src/sys/kern: sys_pset.c
src/sys/sys: pset.h

Log Message:
Simplify pset locking, making it easier to sync with LWP creation, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/kern/sys_pset.c
cvs rdiff -u -r1.6 -r1.7 src/sys/sys/pset.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:54:04 UTC 2019

Modified Files:
src/sys/kern: sys_pset.c
src/sys/sys: pset.h

Log Message:
Simplify pset locking, making it easier to sync with LWP creation, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/kern/sys_pset.c
cvs rdiff -u -r1.6 -r1.7 src/sys/sys/pset.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_pset.c
diff -u src/sys/kern/sys_pset.c:1.21 src/sys/kern/sys_pset.c:1.22
--- src/sys/kern/sys_pset.c:1.21	Sun Dec  9 23:05:02 2018
+++ src/sys/kern/sys_pset.c	Thu Nov 21 17:54:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_pset.c,v 1.21 2018/12/09 23:05:02 mlelstv Exp $	*/
+/*	$NetBSD: sys_pset.c,v 1.22 2019/11/21 17:54:04 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, Mindaugas Rasiukevicius 
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.21 2018/12/09 23:05:02 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pset.c,v 1.22 2019/11/21 17:54:04 ad Exp $");
 
 #include 
 
@@ -156,8 +156,6 @@ psid_validate(psetid_t psid, bool chkps)
 		return EINVAL;
 	if (psets[psid - 1] == NULL)
 		return EINVAL;
-	if (psets[psid - 1]->ps_flags & PSET_BUSY)
-		return EBUSY;
 
 	return 0;
 }
@@ -204,7 +202,6 @@ static int
 kern_pset_destroy(psetid_t psid)
 {
 	struct cpu_info *ci;
-	pset_info_t *pi;
 	struct lwp *l;
 	CPU_INFO_ITERATOR cii;
 	int error;
@@ -229,10 +226,6 @@ kern_pset_destroy(psetid_t psid)
 			continue;
 		spc->spc_psid = PS_NONE;
 	}
-	/* Mark that processor-set is going to be destroyed */
-	pi = psets[psid - 1];
-	pi->ps_flags |= PSET_BUSY;
-	mutex_exit(_lock);
 
 	/* Unmark the processor-set ID from each thread */
 	mutex_enter(proc_lock);
@@ -245,12 +238,11 @@ kern_pset_destroy(psetid_t psid)
 	mutex_exit(proc_lock);
 
 	/* Destroy the processor-set */
-	mutex_enter(_lock);
+	kmem_free(psets[psid - 1], sizeof(pset_info_t));
 	psets[psid - 1] = NULL;
 	psets_count--;
 	mutex_exit(_lock);
 
-	kmem_free(pi, sizeof(pset_info_t));
 	return 0;
 }
 
@@ -452,9 +444,6 @@ sys__pset_bind(struct lwp *l, const stru
 	}
 	if (psid == PS_MYID)
 		psid = curlwp->l_psid;
-	if (psid != PS_QUERY && psid != PS_NONE)
-		psets[psid - 1]->ps_flags |= PSET_BUSY;
-	mutex_exit(_lock);
 
 	/*
 	 * Get PID and LID from the ID.
@@ -463,6 +452,7 @@ sys__pset_bind(struct lwp *l, const stru
 	id1 = SCARG(uap, first_id);
 	id2 = SCARG(uap, second_id);
 
+	mutex_enter(proc_lock);
 	switch (SCARG(uap, idtype)) {
 	case P_PID:
 		/*
@@ -493,19 +483,13 @@ sys__pset_bind(struct lwp *l, const stru
 	}
 
 	/* Find the process */
-	mutex_enter(proc_lock);
 	p = proc_find(pid);
 	if (p == NULL) {
-		mutex_exit(proc_lock);
 		error = ESRCH;
 		goto error;
 	}
-	mutex_enter(p->p_lock);
-	mutex_exit(proc_lock);
-
 	/* Disallow modification of the system processes */
 	if (p->p_flag & PK_SYSTEM) {
-		mutex_exit(p->p_lock);
 		error = EPERM;
 		goto error;
 	}
@@ -513,6 +497,7 @@ sys__pset_bind(struct lwp *l, const stru
 	/* Find the LWP(s) */
 	lcnt = 0;
 	ci = NULL;
+	mutex_enter(p->p_lock);
 	LIST_FOREACH(t, >p_lwps, l_sibling) {
 		if (lid && lid != t->l_lid)
 			continue;
@@ -531,16 +516,12 @@ sys__pset_bind(struct lwp *l, const stru
 	mutex_exit(p->p_lock);
 	if (lcnt == 0) {
 		error = ESRCH;
-		goto error;
 	}
-	if (SCARG(uap, opsid))
-		error = copyout(, SCARG(uap, opsid), sizeof(psetid_t));
 error:
-	if (psid != PS_QUERY && psid != PS_NONE) {
-		mutex_enter(_lock);
-		psets[psid - 1]->ps_flags &= ~PSET_BUSY;
-		mutex_exit(_lock);
-	}
+	mutex_exit(proc_lock);
+	mutex_exit(_lock);
+	if (error == 0 && SCARG(uap, opsid))
+		error = copyout(, SCARG(uap, opsid), sizeof(psetid_t));
 	return error;
 }
 

Index: src/sys/sys/pset.h
diff -u src/sys/sys/pset.h:1.6 src/sys/sys/pset.h:1.7
--- src/sys/sys/pset.h:1.6	Mon May 28 21:05:02 2018
+++ src/sys/sys/pset.h	Thu Nov 21 17:54:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pset.h,v 1.6 2018/05/28 21:05:02 chs Exp $	*/
+/*	$NetBSD: pset.h,v 1.7 2019/11/21 17:54:04 ad Exp $	*/
 
 /*
  * Copyright (c) 2008, Mindaugas Rasiukevicius 
@@ -57,9 +57,6 @@ typedef struct {
 	int		ps_flags;
 } pset_info_t;
 
-/* Flags */
-#define	PSET_BUSY	0x01
-
 void	psets_init(void);
 
 #endif	/* _KERNEL */



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:22:05 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
lwp_create:
- Don't need to check for PK_SYSTEM when inheriting an affinity mask.
- Inherit processor set ID under proc_lock, to sync with pset syscalls.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 18:22:05 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c

Log Message:
lwp_create:
- Don't need to check for PK_SYSTEM when inheriting an affinity mask.
- Inherit processor set ID under proc_lock, to sync with pset syscalls.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/kern/kern_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.209 src/sys/kern/kern_lwp.c:1.210
--- src/sys/kern/kern_lwp.c:1.209	Thu Nov 21 18:17:36 2019
+++ src/sys/kern/kern_lwp.c	Thu Nov 21 18:22:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.209 2019/11/21 18:17:36 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.210 2019/11/21 18:22:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.209 2019/11/21 18:17:36 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.210 2019/11/21 18:22:05 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -952,26 +952,18 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 
 	KASSERT(l2->l_affinity == NULL);
 
-	if ((p2->p_flag & PK_SYSTEM) == 0) {
-		/* Inherit the affinity mask. */
+	/* Inherit the affinity mask. */
+	if (l1->l_affinity) {
+		/*
+		 * Note that we hold the state lock while inheriting
+		 * the affinity to avoid race with sched_setaffinity().
+		 */
+		lwp_lock(l1);
 		if (l1->l_affinity) {
-			/*
-			 * Note that we hold the state lock while inheriting
-			 * the affinity to avoid race with sched_setaffinity().
-			 */
-			lwp_lock(l1);
-			if (l1->l_affinity) {
-kcpuset_use(l1->l_affinity);
-l2->l_affinity = l1->l_affinity;
-			}
-			lwp_unlock(l1);
+			kcpuset_use(l1->l_affinity);
+			l2->l_affinity = l1->l_affinity;
 		}
-		lwp_lock(l2);
-		/* Inherit a processor-set */
-		l2->l_psid = l1->l_psid;
-		/* Look for a CPU to start */
-		l2->l_cpu = sched_takecpu(l2);
-		lwp_unlock_to(l2, l2->l_cpu->ci_schedstate.spc_mutex);
+		lwp_unlock(l1);
 	}
 	mutex_exit(p2->p_lock);
 
@@ -979,6 +971,8 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 
 	mutex_enter(proc_lock);
 	LIST_INSERT_HEAD(, l2, l_list);
+	/* Inherit a processor-set */
+	l2->l_psid = l1->l_psid;
 	mutex_exit(proc_lock);
 
 	SYSCALL_TIME_LWP_INIT(l2);



CVS commit: src/sys/uvm

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:47:53 UTC 2019

Modified Files:
src/sys/uvm: uvm_glue.c

Log Message:
Use lwp_changepri().


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/uvm/uvm_glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_glue.c
diff -u src/sys/uvm/uvm_glue.c:1.169 src/sys/uvm/uvm_glue.c:1.170
--- src/sys/uvm/uvm_glue.c:1.169	Thu Nov 14 16:48:51 2019
+++ src/sys/uvm/uvm_glue.c	Thu Nov 21 17:47:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uvm_glue.c,v 1.169 2019/11/14 16:48:51 maxv Exp $	*/
+/*	$NetBSD: uvm_glue.c,v 1.170 2019/11/21 17:47:53 ad Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.169 2019/11/14 16:48:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_glue.c,v 1.170 2019/11/21 17:47:53 ad Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_kstack.h"
@@ -496,8 +496,8 @@ uvm_scheduler(void)
 	lwp_t *l = curlwp;
 
 	lwp_lock(l);
-	l->l_priority = PRI_VM;
 	l->l_class = SCHED_FIFO;
+	lwp_changepri(l, PRI_VM);
 	lwp_unlock(l);
 
 	for (;;) {



CVS commit: src/sys/dev/pci

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:47:23 UTC 2019

Modified Files:
src/sys/dev/pci: ichsmb.c

Log Message:
If attach fails, don't panic on detach.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pci/ichsmb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/ichsmb.c
diff -u src/sys/dev/pci/ichsmb.c:1.60 src/sys/dev/pci/ichsmb.c:1.61
--- src/sys/dev/pci/ichsmb.c:1.60	Mon Dec 10 06:23:54 2018
+++ src/sys/dev/pci/ichsmb.c	Thu Nov 21 17:47:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ichsmb.c,v 1.60 2018/12/10 06:23:54 jdolecek Exp $	*/
+/*	$NetBSD: ichsmb.c,v 1.61 2019/11/21 17:47:23 ad Exp $	*/
 /*	$OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $	*/
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.60 2018/12/10 06:23:54 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.61 2019/11/21 17:47:23 ad Exp $");
 
 #include 
 #include 
@@ -265,7 +265,8 @@ ichsmb_detach(device_t self, int flags)
 		sc->sc_pihp = NULL;
 	}
 
-	bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_size);
+	if (sc->sc_size != 0)
+		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_size);
 
 	return 0;
 }



CVS commit: src/sys/uvm

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 17:47:53 UTC 2019

Modified Files:
src/sys/uvm: uvm_glue.c

Log Message:
Use lwp_changepri().


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/uvm/uvm_glue.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch

2019-11-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 23 16:36:39 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S
src/sys/arch/i386/i386: lock_stubs.S

Log Message:
For this case during build.sh:

rw_enter(lock, RW_READ);

Having instrumented it, it turns out that >99.5% of the time the lock is
completely unknowned.  Make this assumption in the assembly stub for
rw_enter(), and avoid the initial read of the lock word.  Where there are
existing read holds, we'll do an additional CMPXCHG but should already have
the cache line in the EXCLUSIVE state.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/i386/i386/lock_stubs.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.33 src/sys/arch/amd64/amd64/lock_stubs.S:1.34
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.33	Thu Nov 14 16:23:52 2019
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Sat Nov 23 16:36:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.33 2019/11/14 16:23:52 maxv Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.34 2019/11/23 16:36:38 ad Exp $	*/
 
 /*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -191,13 +191,15 @@ END(mutex_spin_exit)
  * Acquire one hold on a RW lock.
  */
 ENTRY(rw_enter)
-	cmpl	$RW_READER, %esi
+	xorl	%eax, %eax
+	testl	%esi, %esi	/* RW_READER = 0 */
 	jne	2f
 
 	/*
-	 * Reader: this is the most common case.
+	 * Reader, and no existing readers on the lock: this is a most
+	 * common case.  Instead of reading from the lock word, use cmpxchg
+	 * and get the cache line into the EXCLUSIVE state to begin with.
 	 */
-	movq	(%rdi), %rax
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	3f
@@ -213,7 +215,6 @@ ENTRY(rw_enter)
 	 * Writer: if the compare-and-set fails, don't bother retrying.
 	 */
 2:	movq	CPUVAR(CURLWP), %rcx
-	xorq	%rax, %rax
 	orq	$RW_WRITE_LOCKED, %rcx
 	LOCK
 	cmpxchgq %rcx, (%rdi)
@@ -268,13 +269,15 @@ END(rw_exit)
  * Try to acquire one hold on a RW lock.
  */
 ENTRY(rw_tryenter)
-	cmpl	$RW_READER, %esi
+	xorl	%eax, %eax
+	testl	%esi, %esi	/* RW_READER = 0 */
 	jne	2f
 
 	/*
-	 * Reader: this is the most common case.
+	 * Reader, and no existing readers on the lock: this is a most
+	 * common case.  Instead of reading from the lock word, use cmpxchg
+	 * and get the cache line into the EXCLUSIVE state to begin with.
 	 */
-	movq	(%rdi), %rax
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	4f
@@ -291,7 +294,6 @@ ENTRY(rw_tryenter)
 	 * Writer: if the compare-and-set fails, don't bother retrying.
 	 */
 2:	movq	CPUVAR(CURLWP), %rcx
-	xorq	%rax, %rax
 	orq	$RW_WRITE_LOCKED, %rcx
 	LOCK
 	cmpxchgq %rcx, (%rdi)

Index: src/sys/arch/i386/i386/lock_stubs.S
diff -u src/sys/arch/i386/i386/lock_stubs.S:1.30 src/sys/arch/i386/i386/lock_stubs.S:1.31
--- src/sys/arch/i386/i386/lock_stubs.S:1.30	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/i386/i386/lock_stubs.S	Sat Nov 23 16:36:38 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: lock_stubs.S,v 1.30 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.31 2019/11/23 16:36:38 ad Exp $	*/
 
 /*-
- * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.30 2019/02/11 14:59:32 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.31 2019/11/23 16:36:38 ad Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -104,13 +104,15 @@ END(mutex_exit)
  */
 ENTRY(rw_enter)
 	movl	4(%esp), %edx
+	xorl	%eax, %eax
 	cmpl	$RW_READER, 8(%esp)
 	jne	2f
 
 	/*
-	 * Reader
+	 * Reader, and no existing readers on the lock: this is a most
+	 * common case.  Instead of reading from the lock word, use cmpxchg
+	 * and get the cache line into the EXCLUSIVE state to begin with.
 	 */
-	movl	(%edx), %eax
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	3f
@@ -125,7 +127,7 @@ ENTRY(rw_enter)
 	/*
 	 * Writer
 	 */
-2:	xorl	%eax, %eax
+2:
 	movl	%fs:CPU_INFO_CURLWP(%eax), %ecx
 	orl	$RW_WRITE_LOCKED, %ecx
 	LOCK(3)
@@ -186,13 +188,15 @@ END(rw_exit)
  */
 ENTRY(rw_tryenter)
 	movl	4(%esp), %edx
+	xorl	%eax, %eax
 	cmpl	$RW_READER, 8(%esp)
 	jne	2f
 
 	/*
-	 * Reader
+	 * Reader, and no existing readers on the lock: this is a most
+	 * common case.  Instead of reading from the lock word, use cmpxchg
+	 * and get the cache line into the EXCLUSIVE state to begin with.
 	 */
-	movl	(%edx), %eax
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	4f
@@ -209,7 +213,6 @@ ENTRY(rw_tryenter)
 	 * Writer
 	 */
 2:
-	xorl	%eax, %eax
 	movl	%fs:CPU_INFO_CURLWP(%eax), %ecx
 	orl	$RW_WRITE_LOCKED, 

CVS commit: src/sys/arch

2019-11-23 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 23 16:36:39 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S
src/sys/arch/i386/i386: lock_stubs.S

Log Message:
For this case during build.sh:

rw_enter(lock, RW_READ);

Having instrumented it, it turns out that >99.5% of the time the lock is
completely unknowned.  Make this assumption in the assembly stub for
rw_enter(), and avoid the initial read of the lock word.  Where there are
existing read holds, we'll do an additional CMPXCHG but should already have
the cache line in the EXCLUSIVE state.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/i386/i386/lock_stubs.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:24:02 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/aarch64/include: cpu.h
src/sys/arch/alpha/alpha: trap.c
src/sys/arch/amd64/amd64: cpufunc.S trap.c
src/sys/arch/amd64/include: cpu.h
src/sys/arch/amiga/amiga: trap.c
src/sys/arch/arm/arm: ast.c
src/sys/arch/arm/include: cpu.h
src/sys/arch/atari/atari: trap.c
src/sys/arch/cesfic/cesfic: trap.c
src/sys/arch/hp300/hp300: trap.c
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/i386/i386: cpufunc.S trap.c
src/sys/arch/i386/include: cpu.h
src/sys/arch/luna68k/luna68k: trap.c
src/sys/arch/mac68k/mac68k: trap.c
src/sys/arch/mips/include: cpu.h
src/sys/arch/mvme68k/mvme68k: trap.c
src/sys/arch/news68k/news68k: trap.c
src/sys/arch/next68k/next68k: trap.c
src/sys/arch/or1k/include: cpu.h
src/sys/arch/riscv/include: cpu.h
src/sys/arch/riscv/riscv: trap.c
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/include: userret.h
src/sys/arch/sparc64/sparc64: trap.c
src/sys/arch/sun2/sun2: trap.c
src/sys/arch/sun3/sun3: trap.c
src/sys/arch/usermode/usermode: trap.c
src/sys/arch/vax/vax: trap.c
src/sys/arch/x68k/x68k: trap.c
src/sys/sys: userret.h

Log Message:
mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r1.134 -r1.135 src/sys/arch/alpha/alpha/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/amiga/amiga/trap.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/arm/ast.c
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/arm/include/cpu.h
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/atari/atari/trap.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/cesfic/cesfic/trap.c
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/hp300/hp300/trap.c
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.302 -r1.303 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.181 -r1.182 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/luna68k/luna68k/trap.c
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/mac68k/mac68k/trap.c
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/mips/include/cpu.h
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/mvme68k/mvme68k/trap.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/news68k/news68k/trap.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/next68k/next68k/trap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/or1k/include/cpu.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/riscv/include/cpu.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/riscv/riscv/trap.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/sparc/include/userret.h
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/sparc64/sparc64/trap.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/sun2/sun2/trap.c
cvs rdiff -u -r1.145 -r1.146 src/sys/arch/sun3/sun3/trap.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/usermode/usermode/trap.c
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/vax/vax/trap.c
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/x68k/x68k/trap.c
cvs rdiff -u -r1.28 -r1.29 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.19 src/sys/arch/aarch64/aarch64/trap.c:1.20
--- src/sys/arch/aarch64/aarch64/trap.c:1.19	Sat Sep 28 07:06:50 2019
+++ src/sys/arch/aarch64/aarch64/trap.c	Thu Nov 21 19:23:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.19 2019/09/28 07:06:50 skrll Exp $ */
+/* $NetBSD: trap.c,v 1.20 2019/11/21 19:23:58 ad Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.19 2019/09/28 07:06:50 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.20 2019/11/21 19:23:58 ad Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -158,7 +158,6 @@ trap_doast(struct trapframe *tf)
 	ci->ci_data.cpu_ntrap++;
 
 	KDASSERT(ci->ci_cpl == IPL_NONE);
-	const int want_resched = ci->ci_want_resched;
 #ifdef __HAVE_PREEMPTION
 	kpreempt_enable();
 #endif
@@ -168,9 +167,6 @@ trap_doast(struct trapframe *tf)
 		ADDUPROF(l);
 	}
 
-	/* Allow a forced task switch. */
-	if (want_resched)
-		preempt();
 	userret(l);
 }
 

Index: src/sys/arch/aarch64/include/cpu.h
diff -u src/sys/arch/aarch64/include/cpu.h:1.14 

CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:24:02 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/aarch64/include: cpu.h
src/sys/arch/alpha/alpha: trap.c
src/sys/arch/amd64/amd64: cpufunc.S trap.c
src/sys/arch/amd64/include: cpu.h
src/sys/arch/amiga/amiga: trap.c
src/sys/arch/arm/arm: ast.c
src/sys/arch/arm/include: cpu.h
src/sys/arch/atari/atari: trap.c
src/sys/arch/cesfic/cesfic: trap.c
src/sys/arch/hp300/hp300: trap.c
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/i386/i386: cpufunc.S trap.c
src/sys/arch/i386/include: cpu.h
src/sys/arch/luna68k/luna68k: trap.c
src/sys/arch/mac68k/mac68k: trap.c
src/sys/arch/mips/include: cpu.h
src/sys/arch/mvme68k/mvme68k: trap.c
src/sys/arch/news68k/news68k: trap.c
src/sys/arch/next68k/next68k: trap.c
src/sys/arch/or1k/include: cpu.h
src/sys/arch/riscv/include: cpu.h
src/sys/arch/riscv/riscv: trap.c
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/include: userret.h
src/sys/arch/sparc64/sparc64: trap.c
src/sys/arch/sun2/sun2: trap.c
src/sys/arch/sun3/sun3: trap.c
src/sys/arch/usermode/usermode: trap.c
src/sys/arch/vax/vax: trap.c
src/sys/arch/x68k/x68k: trap.c
src/sys/sys: userret.h

Log Message:
mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/aarch64/include/cpu.h
cvs rdiff -u -r1.134 -r1.135 src/sys/arch/alpha/alpha/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/amd64/amd64/cpufunc.S
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.137 -r1.138 src/sys/arch/amiga/amiga/trap.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/arm/arm/ast.c
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/arm/include/cpu.h
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/atari/atari/trap.c
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/cesfic/cesfic/trap.c
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/hp300/hp300/trap.c
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/i386/i386/cpufunc.S
cvs rdiff -u -r1.302 -r1.303 src/sys/arch/i386/i386/trap.c
cvs rdiff -u -r1.181 -r1.182 src/sys/arch/i386/include/cpu.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/luna68k/luna68k/trap.c
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/mac68k/mac68k/trap.c
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/mips/include/cpu.h
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/mvme68k/mvme68k/trap.c
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/news68k/news68k/trap.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/next68k/next68k/trap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/or1k/include/cpu.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/riscv/include/cpu.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/riscv/riscv/trap.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/sparc/include/userret.h
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/sparc64/sparc64/trap.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/sun2/sun2/trap.c
cvs rdiff -u -r1.145 -r1.146 src/sys/arch/sun3/sun3/trap.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/usermode/usermode/trap.c
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/vax/vax/trap.c
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/x68k/x68k/trap.c
cvs rdiff -u -r1.28 -r1.29 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:57:24 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: cpu_machdep.c
src/sys/arch/mips/mips: cpu_subr.c
src/sys/arch/powerpc/powerpc: powerpc_machdep.c
src/sys/arch/riscv/riscv: riscv_machdep.c
src/sys/arch/x86/include: cpu.h

Log Message:
mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/mips/mips/cpu_subr.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/powerpc/powerpc/powerpc_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/riscv/riscv_machdep.c
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/x86/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:57:24 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: cpu_machdep.c
src/sys/arch/mips/mips: cpu_subr.c
src/sys/arch/powerpc/powerpc: powerpc_machdep.c
src/sys/arch/riscv/riscv: riscv_machdep.c
src/sys/arch/x86/include: cpu.h

Log Message:
mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/mips/mips/cpu_subr.c
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/powerpc/powerpc/powerpc_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/riscv/riscv/riscv_machdep.c
cvs rdiff -u -r1.110 -r1.111 src/sys/arch/x86/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/cpu_machdep.c
diff -u src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.6 src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.7
--- src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.6	Fri Aug  3 17:04:30 2018
+++ src/sys/arch/aarch64/aarch64/cpu_machdep.c	Thu Nov 21 19:57:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_machdep.c,v 1.6 2018/08/03 17:04:30 ryo Exp $ */
+/* $NetBSD: cpu_machdep.c,v 1.7 2019/11/21 19:57:23 ad Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.6 2018/08/03 17:04:30 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.7 2019/11/21 19:57:23 ad Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -299,15 +299,6 @@ cpu_need_proftick(struct lwp *l)
 	setsoftast(l->l_cpu);
 }
 
-void
-cpu_set_curpri(int pri)
-{
-	kpreempt_disable();
-	curcpu()->ci_schedstate.spc_curpriority = pri;
-	kpreempt_enable();
-}
-
-
 #ifdef __HAVE_PREEMPTION
 bool
 cpu_kpreempt_enter(uintptr_t where, int s)

Index: src/sys/arch/mips/mips/cpu_subr.c
diff -u src/sys/arch/mips/mips/cpu_subr.c:1.34 src/sys/arch/mips/mips/cpu_subr.c:1.35
--- src/sys/arch/mips/mips/cpu_subr.c:1.34	Mon Jan 21 08:04:26 2019
+++ src/sys/arch/mips/mips/cpu_subr.c	Thu Nov 21 19:57:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_subr.c,v 1.34 2019/01/21 08:04:26 skrll Exp $	*/
+/*	$NetBSD: cpu_subr.c,v 1.35 2019/11/21 19:57:23 ad Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.34 2019/01/21 08:04:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.35 2019/11/21 19:57:23 ad Exp $");
 
 #include "opt_cputype.h"
 #include "opt_ddb.h"
@@ -567,15 +567,6 @@ cpu_need_proftick(struct lwp *l)
 	l->l_md.md_astpending = 1;		/* force call to ast() */
 }
 
-void
-cpu_set_curpri(int pri)
-{
-	kpreempt_disable();
-	curcpu()->ci_schedstate.spc_curpriority = pri;
-	kpreempt_enable();
-}
-
-
 #ifdef __HAVE_PREEMPTION
 bool
 cpu_kpreempt_enter(uintptr_t where, int s)

Index: src/sys/arch/powerpc/powerpc/powerpc_machdep.c
diff -u src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.72 src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.73
--- src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.72	Sun Sep 16 09:25:47 2018
+++ src/sys/arch/powerpc/powerpc/powerpc_machdep.c	Thu Nov 21 19:57:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: powerpc_machdep.c,v 1.72 2018/09/16 09:25:47 skrll Exp $	*/
+/*	$NetBSD: powerpc_machdep.c,v 1.73 2019/11/21 19:57:24 ad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.72 2018/09/16 09:25:47 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.73 2019/11/21 19:57:24 ad Exp $");
 
 #include "opt_altivec.h"
 #include "opt_ddb.h"
@@ -378,11 +378,6 @@ cpu_ast(struct lwp *l, struct cpu_info *
 		l->l_pflag &= ~LP_OWEUPC;
 		ADDUPROF(l);
 	}
-
-	/* Check whether we are being preempted. */
-	if (ci->ci_want_resched) {
-		preempt();
-	}
 }
 
 void

Index: src/sys/arch/riscv/riscv/riscv_machdep.c
diff -u src/sys/arch/riscv/riscv/riscv_machdep.c:1.4 src/sys/arch/riscv/riscv/riscv_machdep.c:1.5
--- src/sys/arch/riscv/riscv/riscv_machdep.c:1.4	Sat Apr  6 11:54:20 2019
+++ src/sys/arch/riscv/riscv/riscv_machdep.c	Thu Nov 21 19:57:24 2019
@@ -31,7 +31,7 @@
 
 #include "opt_modular.h"
 
-__RCSID("$NetBSD: riscv_machdep.c,v 1.4 2019/04/06 11:54:20 kamil Exp $");
+__RCSID("$NetBSD: riscv_machdep.c,v 1.5 2019/11/21 19:57:24 ad Exp $");
 
 #include 
 #include 
@@ -324,14 +324,6 @@ cpu_need_proftick(struct lwp *l)
 }
 
 void
-cpu_set_curpri(int pri)
-{
-	kpreempt_disable();
-	curcpu()->ci_schedstate.spc_curpriority = pri;
-	kpreempt_enable();
-}
-
-void
 cpu_reboot(int how, char *bootstr)
 {
 	for (;;) {

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.110 src/sys/arch/x86/include/cpu.h:1.111
--- src/sys/arch/x86/include/cpu.h:1.110	Sat Oct 12 06:31:03 2019
+++ 

CVS commit: src/sys/arch

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:27:54 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S
src/sys/arch/i386/i386: genassym.cf locore.S

Log Message:
x86: abort pageidlezero unconditionally if there is something to run.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.190 -r1.191 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.173 -r1.174 src/sys/arch/i386/i386/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:47:21 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c
src/sys/sys: lwp.h

Log Message:
lwp_setlock(): return pointer to the kmutex_t that we replaced


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.188 -r1.189 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.210 src/sys/kern/kern_lwp.c:1.211
--- src/sys/kern/kern_lwp.c:1.210	Thu Nov 21 18:22:05 2019
+++ src/sys/kern/kern_lwp.c	Thu Nov 21 19:47:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.210 2019/11/21 18:22:05 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.211 2019/11/21 19:47:21 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.210 2019/11/21 18:22:05 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.211 2019/11/21 19:47:21 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -1475,14 +1475,16 @@ lwp_locked(struct lwp *l, kmutex_t *mtx)
 /*
  * Lend a new mutex to an LWP.  The old mutex must be held.
  */
-void
+kmutex_t *
 lwp_setlock(struct lwp *l, kmutex_t *mtx)
 {
+	kmutex_t *oldmtx = l->l_mutex;
 
-	KASSERT(mutex_owned(l->l_mutex));
+	KASSERT(mutex_owned(oldmtx));
 
 	membar_exit();
 	l->l_mutex = mtx;
+	return oldmtx;
 }
 
 /*
@@ -1517,11 +1519,11 @@ lwp_trylock(struct lwp *l)
 }
 
 void
-lwp_unsleep(lwp_t *l, bool cleanup)
+lwp_unsleep(lwp_t *l, bool unlock)
 {
 
 	KASSERT(mutex_owned(l->l_mutex));
-	(*l->l_syncobj->sobj_unsleep)(l, cleanup);
+	(*l->l_syncobj->sobj_unsleep)(l, unlock);
 }
 
 /*

Index: src/sys/sys/lwp.h
diff -u src/sys/sys/lwp.h:1.188 src/sys/sys/lwp.h:1.189
--- src/sys/sys/lwp.h:1.188	Thu Nov 14 16:23:53 2019
+++ src/sys/sys/lwp.h	Thu Nov 21 19:47:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lwp.h,v 1.188 2019/11/14 16:23:53 maxv Exp $	*/
+/*	$NetBSD: lwp.h,v 1.189 2019/11/21 19:47:21 ad Exp $	*/
 
 /*
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010
@@ -326,7 +326,7 @@ void	lwp_startup(lwp_t *, lwp_t *);
 void	startlwp(void *);
 
 int	lwp_locked(lwp_t *, kmutex_t *);
-void	lwp_setlock(lwp_t *, kmutex_t *);
+kmutex_t *lwp_setlock(lwp_t *, kmutex_t *);
 void	lwp_unlock_to(lwp_t *, kmutex_t *);
 int	lwp_trylock(lwp_t *);
 void	lwp_addref(lwp_t *);



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 20:51:05 UTC 2019

Modified Files:
src/sys/kern: kern_synch.c

Log Message:
- Don't give up kpriority boost in preempt().  That's unfair and bad for
  interactive response.  It should only be dropped on final return to user.
- Clear l_dopreempt with atomics and add some comments around concurrency.
- Hold proc_lock over the lightning bolt and loadavg calc, no reason not to.
- cpu_did_preempt() is useless - don't call it.  Will remove soon.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/sys/kern/kern_synch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 20:51:05 UTC 2019

Modified Files:
src/sys/kern: kern_synch.c

Log Message:
- Don't give up kpriority boost in preempt().  That's unfair and bad for
  interactive response.  It should only be dropped on final return to user.
- Clear l_dopreempt with atomics and add some comments around concurrency.
- Hold proc_lock over the lightning bolt and loadavg calc, no reason not to.
- cpu_did_preempt() is useless - don't call it.  Will remove soon.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/sys/kern/kern_synch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_synch.c
diff -u src/sys/kern/kern_synch.c:1.324 src/sys/kern/kern_synch.c:1.325
--- src/sys/kern/kern_synch.c:1.324	Thu Oct  3 22:48:44 2019
+++ src/sys/kern/kern_synch.c	Thu Nov 21 20:51:05 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: kern_synch.c,v 1.324 2019/10/03 22:48:44 kamil Exp $	*/
+/*	$NetBSD: kern_synch.c,v 1.325 2019/11/21 20:51:05 ad Exp $	*/
 
 /*-
- * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
+ * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019
  *The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.324 2019/10/03 22:48:44 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.325 2019/11/21 20:51:05 ad Exp $");
 
 #include "opt_kstack.h"
 #include "opt_dtrace.h"
@@ -272,6 +272,7 @@ yield(void)
 	lwp_lock(l);
 	KASSERT(lwp_locked(l, l->l_cpu->ci_schedstate.spc_lwplock));
 	KASSERT(l->l_stat == LSONPROC);
+	/* Voluntary - ditch kpriority boost. */
 	l->l_kpriority = false;
 	(void)mi_switch(l);
 	KERNEL_LOCK(l->l_biglocks, l);
@@ -290,7 +291,7 @@ preempt(void)
 	lwp_lock(l);
 	KASSERT(lwp_locked(l, l->l_cpu->ci_schedstate.spc_lwplock));
 	KASSERT(l->l_stat == LSONPROC);
-	l->l_kpriority = false;
+	/* Involuntary - keep kpriority boost. */
 	l->l_pflag |= LP_PREEMPTING;
 	(void)mi_switch(l);
 	KERNEL_LOCK(l->l_biglocks, l);
@@ -324,12 +325,12 @@ kpreempt(uintptr_t where)
 			 * been blocked", since we're going to
 			 * context switch.
 			 */
-			l->l_dopreempt = 0;
+			atomic_swap_uint(>l_dopreempt, 0);
 			return true;
 		}
 		if (__predict_false((l->l_flag & LW_IDLE) != 0)) {
 			/* Can't preempt idle loop, don't count as failure. */
-			l->l_dopreempt = 0;
+			atomic_swap_uint(>l_dopreempt, 0);
 			return true;
 		}
 		if (__predict_false(l->l_nopreempt != 0)) {
@@ -342,7 +343,7 @@ kpreempt(uintptr_t where)
 		}
 		if (__predict_false((l->l_pflag & LP_INTR) != 0)) {
 			/* Can't preempt soft interrupts yet. */
-			l->l_dopreempt = 0;
+			atomic_swap_uint(>l_dopreempt, 0);
 			failed = (uintptr_t)_softint;
 			break;
 		}
@@ -484,8 +485,11 @@ nextlwp(struct cpu_info *ci, struct sche
 	}
 
 	/*
-	 * Only clear want_resched if there are no pending (slow)
-	 * software interrupts.
+	 * Only clear want_resched if there are no pending (slow) software
+	 * interrupts.  We can do this without an atomic, because no new
+	 * LWPs can appear in the queue due to our hold on spc_mutex, and
+	 * the update to ci_want_resched will become globally visible before
+	 * the release of spc_mutex becomes globally visible.
 	 */
 	ci->ci_want_resched = ci->ci_data.cpu_softints;
 	spc->spc_flags &= ~SPCF_SWITCHCLEAR;
@@ -606,10 +610,11 @@ mi_switch(lwp_t *l)
 	}
 
 	/*
-	 * Preemption related tasks.  Must be done with the current
-	 * CPU locked.
+	 * Preemption related tasks.  Must be done holding spc_mutex.  Clear
+	 * l_dopreempt without an atomic - it's only ever set non-zero by
+	 * sched_resched_cpu() which also holds spc_mutex, and only ever
+	 * cleared by the LWP itself (us) with atomics when not under lock.
 	 */
-	cpu_did_resched(l);
 	l->l_dopreempt = 0;
 	if (__predict_false(l->l_pfailaddr != 0)) {
 		LOCKSTAT_FLAG(lsflag);
@@ -830,12 +835,6 @@ lwp_exit_switchaway(lwp_t *l)
 	 */
 	ci->ci_data.cpu_onproc = newl;
 
-	/*
-	 * Preemption related tasks.  Must be done with the current
-	 * CPU locked.
-	 */
-	cpu_did_resched(l);
-
 	/* Unlock the run queue. */
 	spc_unlock(ci);
 
@@ -1215,7 +1214,6 @@ sched_pstats(void)
 			psignal(p, sig);
 		}
 	}
-	mutex_exit(proc_lock);
 
 	/* Load average calculation. */
 	if (__predict_false(lavg_count == 0)) {
@@ -1229,4 +1227,6 @@ sched_pstats(void)
 
 	/* Lightning bolt. */
 	cv_broadcast();
+
+	mutex_exit(proc_lock);
 }



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:47:21 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c
src/sys/sys: lwp.h

Log Message:
lwp_setlock(): return pointer to the kmutex_t that we replaced


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.188 -r1.189 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/x86

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 21:48:34 UTC 2019

Modified Files:
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: x86_tlb.c

Log Message:
x86 TLB shootdown IPI changes:

- Shave some time off processing.
- Reduce cacheline/bus traffic on systems with many CPUs.
- Reduce time spent at IPL_VM.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/x86_tlb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.111 src/sys/arch/x86/include/cpu.h:1.112
--- src/sys/arch/x86/include/cpu.h:1.111	Thu Nov 21 19:57:24 2019
+++ src/sys/arch/x86/include/cpu.h	Thu Nov 21 21:48:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.111 2019/11/21 19:57:24 ad Exp $	*/
+/*	$NetBSD: cpu.h,v 1.112 2019/11/21 21:48:33 ad Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -76,6 +76,7 @@
 
 struct intrsource;
 struct pmap;
+struct kcpuset;
 
 #ifdef __x86_64__
 #define	i386tss	x86_64_tss
@@ -135,7 +136,8 @@ struct cpu_info {
 	int ci_curldt;		/* current LDT descriptor */
 	int ci_nintrhand;	/* number of H/W interrupt handlers */
 	uint64_t ci_scratch;
-	uintptr_t ci_pmap_data[128 / sizeof(uintptr_t)];
+	uintptr_t ci_pmap_data[64 / sizeof(uintptr_t)];
+	struct kcpuset *ci_tlb_cpuset;
 
 #ifndef XENPV
 	struct intrsource *ci_isources[MAX_INTR_SOURCES];

Index: src/sys/arch/x86/x86/x86_tlb.c
diff -u src/sys/arch/x86/x86/x86_tlb.c:1.8 src/sys/arch/x86/x86/x86_tlb.c:1.9
--- src/sys/arch/x86/x86/x86_tlb.c:1.8	Mon May 27 17:32:36 2019
+++ src/sys/arch/x86/x86/x86_tlb.c	Thu Nov 21 21:48:33 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: x86_tlb.c,v 1.8 2019/05/27 17:32:36 maxv Exp $	*/
+/*	$NetBSD: x86_tlb.c,v 1.9 2019/11/21 21:48:33 ad Exp $	*/
 
 /*-
- * Copyright (c) 2008-2012 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008-2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.8 2019/05/27 17:32:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.9 2019/11/21 21:48:33 ad Exp $");
 
 #include 
 #include 
@@ -59,22 +59,33 @@ __KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 
 #include 
 
 /*
- * TLB shootdown structures.
+ * TLB shootdown packet.  Each CPU has a copy of this packet, where we build
+ * sets of TLB shootdowns.  If shootdowns need to occur on remote CPUs, the
+ * packet is copied into a shared mailbox kept on the initiator's kernel
+ * stack.  Once the copy is made, no further updates to the mailbox are made
+ * until the request is completed.  This keeps the cache line in the shared
+ * state, and bus traffic to a minimum.
+ *
+ * On i386 the packet is 28 bytes in size.  On amd64 it's 52 bytes.
  */
-
 typedef struct {
-#ifdef _LP64
-	uintptr_t		tp_va[14];	/* whole struct: 128 bytes */
-#else
-	uintptr_t		tp_va[13];	/* whole struct: 64 bytes */
-#endif
-	uint16_t		tp_count;
-	uint16_t		tp_pte;
-	int			tp_userpmap;
-	kcpuset_t *		tp_cpumask;
+	uintptr_t		tp_va[6];
+	uint8_t			tp_count;
+	uint8_t			tp_userpmap;
+	uint8_t			tp_global;
+	uint8_t			tp_done;
 } pmap_tlb_packet_t;
 
 /*
+ * Padded packet stored on the initiator's stack.
+ */
+typedef struct {
+	uint8_t			ts_pad1[COHERENCY_UNIT];
+	pmap_tlb_packet_t	ts_tp;
+	uint8_t			ts_pad2[COHERENCY_UNIT];
+} pmap_tlb_stackbuf_t;
+
+/*
  * No more than N separate invlpg.
  *
  * Statistically, a value of six is big enough to cover the requested number
@@ -82,14 +93,14 @@ typedef struct {
  * reach the limit, and increasing it can actually reduce the performance due
  * to the high cost of invlpg.
  */
-#define	TP_MAXVA		6
+#define	TP_MAXVA		6	/* for individual mappings */
+#define	TP_ALLVA		255	/* special: shoot all mappings */
 
 /*
  * TLB shootdown state.
  */
-static pmap_tlb_packet_t	pmap_tlb_packet		__cacheline_aligned;
+static volatile pmap_tlb_packet_t * volatile pmap_tlb_packet __cacheline_aligned;
 static volatile u_int		pmap_tlb_pendcount	__cacheline_aligned;
-static volatile u_int		pmap_tlb_gen		__cacheline_aligned;
 static struct evcnt		pmap_tlb_evcnt		__cacheline_aligned;
 
 /*
@@ -123,9 +134,7 @@ void
 pmap_tlb_init(void)
 {
 
-	memset(_tlb_packet, 0, sizeof(pmap_tlb_packet_t));
-	pmap_tlb_pendcount = 0;
-	pmap_tlb_gen = 0;
+	KASSERT(__arraycount(pmap_tlb_packet->tp_va) >= TP_MAXVA);
 
 	evcnt_attach_dynamic(_tlb_evcnt, EVCNT_TYPE_INTR,
 	NULL, "TLB", "shootdown");
@@ -158,7 +167,7 @@ pmap_tlb_cpu_init(struct cpu_info *ci)
 	pmap_tlb_packet_t *tp = (pmap_tlb_packet_t *)ci->ci_pmap_data;
 
 	memset(tp, 0, sizeof(pmap_tlb_packet_t));
-	kcpuset_create(>tp_cpumask, true);
+	kcpuset_create(>ci_tlb_cpuset, true);
 }
 
 static inline void
@@ -193,13 +202,13 @@ pmap_tlbstat_count(struct pmap 

CVS commit: src/sys/arch/x86

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 21:48:34 UTC 2019

Modified Files:
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: x86_tlb.c

Log Message:
x86 TLB shootdown IPI changes:

- Shave some time off processing.
- Reduce cacheline/bus traffic on systems with many CPUs.
- Reduce time spent at IPL_VM.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/x86_tlb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 19:27:54 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S
src/sys/arch/i386/i386: genassym.cf locore.S

Log Message:
x86: abort pageidlezero unconditionally if there is something to run.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.190 -r1.191 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.173 -r1.174 src/sys/arch/i386/i386/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.77 src/sys/arch/amd64/amd64/genassym.cf:1.78
--- src/sys/arch/amd64/amd64/genassym.cf:1.77	Sat Oct 12 06:31:03 2019
+++ src/sys/arch/amd64/amd64/genassym.cf	Thu Nov 21 19:27:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.77 2019/10/12 06:31:03 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.78 2019/11/21 19:27:54 ad Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -385,6 +385,4 @@ define	PGSHIFT			PGSHIFT
 
 define	VM_SPACE_SEP_HIGH32	(0x8000 >> 32)
 
-define	RESCHED_KPREEMPT	RESCHED_KPREEMPT
-
 define	SEL_RPL_MASK		SEL_RPL

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.190 src/sys/arch/amd64/amd64/locore.S:1.191
--- src/sys/arch/amd64/amd64/locore.S:1.190	Thu Nov 14 16:23:52 2019
+++ src/sys/arch/amd64/amd64/locore.S	Thu Nov 21 19:27:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.190 2019/11/14 16:23:52 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.191 2019/11/21 19:27:54 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1491,7 +1491,7 @@ ENTRY(sse2_idlezero_page)
 	xorq	%rax, %rax
 	.align	16
 1:
-	testl	$RESCHED_KPREEMPT, CPUVAR(RESCHED)
+	cmpl	$0, CPUVAR(RESCHED)
 	jnz	2f
 	movnti	%rax, 0(%rdi)
 	movnti	%rax, 8(%rdi)

Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.114 src/sys/arch/i386/i386/genassym.cf:1.115
--- src/sys/arch/i386/i386/genassym.cf:1.114	Sat Oct 12 06:31:03 2019
+++ src/sys/arch/i386/i386/genassym.cf	Thu Nov 21 19:27:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.114 2019/10/12 06:31:03 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.115 2019/11/21 19:27:54 ad Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -376,8 +376,6 @@ define	L2_FRAME		L2_FRAME
 define	PGOFSET			PGOFSET
 define	PGSHIFT			PGSHIFT
 
-define	RESCHED_KPREEMPT	RESCHED_KPREEMPT
-
 ifdef XEN
 define CPU_INFO_VCPU		offsetof(struct cpu_info, ci_vcpu)
 define CPU_INFO_XPENDING	offsetof(struct cpu_info, ci_xpending)

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.173 src/sys/arch/i386/i386/locore.S:1.174
--- src/sys/arch/i386/i386/locore.S:1.173	Fri Oct 18 01:38:28 2019
+++ src/sys/arch/i386/i386/locore.S	Thu Nov 21 19:27:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.173 2019/10/18 01:38:28 manu Exp $	*/
+/*	$NetBSD: locore.S,v 1.174 2019/11/21 19:27:54 ad Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.173 2019/10/18 01:38:28 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.174 2019/11/21 19:27:54 ad Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1590,7 +1590,7 @@ ENTRY(sse2_idlezero_page)
 	xorl	%eax, %eax
 	.align	16
 1:
-	testl	$RESCHED_KPREEMPT, CPUVAR(RESCHED)
+	cmpl	$0, CPUVAR(RESCHED)
 	jnz	2f
 	movnti	%eax, 0(%edx)
 	movnti	%eax, 4(%edx)



CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 21:42:31 UTC 2019

Modified Files:
src/sys/kern: sys_select.c
src/sys/sys: selinfo.h

Log Message:
Minor improvements to select/poll:

- Increase the maximum number of clusters from 32 to 64 for large systems.
  kcpuset_t could potentially be used here but that's an excursion I don't
  want to go on right now.  uint32_t -> uint64_t is very simple.

- In the case of a non-blocking select/poll, or where we won't block
  because there are events ready to report, stop registering interest in
  the back-end objects early.

- Change the wmesg for poll back to "poll".


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_select.c
cvs rdiff -u -r1.8 -r1.9 src/sys/sys/selinfo.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_select.c
diff -u src/sys/kern/sys_select.c:1.48 src/sys/kern/sys_select.c:1.49
--- src/sys/kern/sys_select.c:1.48	Fri Sep 20 15:00:47 2019
+++ src/sys/kern/sys_select.c	Thu Nov 21 21:42:30 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: sys_select.c,v 1.48 2019/09/20 15:00:47 kamil Exp $	*/
+/*	$NetBSD: sys_select.c,v 1.49 2019/11/21 21:42:30 ad Exp $	*/
 
 /*-
- * Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
+ * Copyright (c) 2007, 2008, 2009, 2010, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -84,7 +84,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.48 2019/09/20 15:00:47 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.49 2019/11/21 21:42:30 ad Exp $");
 
 #include 
 #include 
@@ -104,6 +104,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c
 #include 
 #include 
 #include 
+#include 
 
 /* Flags for lwp::l_selflag. */
 #define	SEL_RESET	0	/* awoken, interrupted, or not yet polling */
@@ -111,10 +112,6 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c
 #define	SEL_BLOCKING	2	/* blocking and waiting for event */
 #define	SEL_EVENT	3	/* interrupted, events set directly */
 
-/* Operations: either select() or poll(). */
-#define	SELOP_SELECT	1
-#define	SELOP_POLL	2
-
 /*
  * Per-cluster state for select()/poll().  For a system with fewer
  * than 32 CPUs, this gives us per-CPU clusters.
@@ -125,8 +122,8 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c
 typedef struct selcluster {
 	kmutex_t	*sc_lock;
 	sleepq_t	sc_sleepq;
+	uint64_t	sc_mask;
 	int		sc_ncoll;
-	uint32_t	sc_mask;
 } selcluster_t;
 
 static inline int	selscan(char *, const int, const size_t, register_t *);
@@ -150,6 +147,10 @@ static syncobj_t select_sobj = {
 static selcluster_t	*selcluster[SELCLUSTERS] __read_mostly;
 static int		direct_select __read_mostly = 0;
 
+/* Operations: either select() or poll(). */
+const char		selop_select[] = "select";
+const char		selop_poll[] = "poll";
+
 /*
  * Select system call.
  */
@@ -221,7 +222,7 @@ sys___select50(struct lwp *l, const stru
  * sel_do_scan: common code to perform the scan on descriptors.
  */
 static int
-sel_do_scan(const int op, void *fds, const int nf, const size_t ni,
+sel_do_scan(const char *opname, void *fds, const int nf, const size_t ni,
 struct timespec *ts, sigset_t *mask, register_t *retval)
 {
 	lwp_t		* const l = curlwp;
@@ -238,10 +239,17 @@ sel_do_scan(const int op, void *fds, con
 	if (__predict_false(mask))
 		sigsuspendsetup(l, mask);
 
+	/*
+	 * We may context switch during or at any time after picking a CPU
+	 * and cluster to associate with, but it doesn't matter.  In the
+	 * unlikely event we migrate elsewhere all we risk is a little lock
+	 * contention; correctness is not sacrificed.
+	 */
 	sc = curcpu()->ci_data.cpu_selcluster;
 	lock = sc->sc_lock;
 	l->l_selcluster = sc;
-	if (op == SELOP_SELECT) {
+
+	if (opname == selop_select) {
 		l->l_selbits = fds;
 		l->l_selni = ni;
 	} else {
@@ -261,10 +269,16 @@ sel_do_scan(const int op, void *fds, con
 		 * and lock activity resulting from fo_poll is enough to
 		 * provide an up to date value for new polling activity.
 		 */
-		l->l_selflag = SEL_SCANNING;
+		if (ts && (ts->tv_sec | ts->tv_nsec | direct_select) == 0) {
+			/* Non-blocking: no need for selrecord()/selclear() */
+			l->l_selflag = SEL_RESET;
+		} else {
+			l->l_selflag = SEL_SCANNING;
+		}
 		ncoll = sc->sc_ncoll;
+		membar_exit();
 
-		if (op == SELOP_SELECT) {
+		if (opname == selop_select) {
 			error = selscan((char *)fds, nf, ni, retval);
 		} else {
 			error = pollscan((struct pollfd *)fds, nf, retval);
@@ -301,7 +315,7 @@ state_check:
 		l->l_selflag = SEL_BLOCKING;
 		l->l_kpriority = true;
 		sleepq_enter(>sc_sleepq, l, lock);
-		sleepq_enqueue(>sc_sleepq, sc, "select", _sobj);
+		sleepq_enqueue(>sc_sleepq, sc, opname, _sobj);
 		error = sleepq_block(timo, true);
 		if (error != 0) {
 			break;
@@ -363,7 +377,7 @@ selcommon(register_t *retval, int nd, fd
 	getbits(ex, 2);
 #undef	getbits
 
-	

CVS commit: src/sys

2019-11-21 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Nov 21 21:42:31 UTC 2019

Modified Files:
src/sys/kern: sys_select.c
src/sys/sys: selinfo.h

Log Message:
Minor improvements to select/poll:

- Increase the maximum number of clusters from 32 to 64 for large systems.
  kcpuset_t could potentially be used here but that's an excursion I don't
  want to go on right now.  uint32_t -> uint64_t is very simple.

- In the case of a non-blocking select/poll, or where we won't block
  because there are events ready to report, stop registering interest in
  the back-end objects early.

- Change the wmesg for poll back to "poll".


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/kern/sys_select.c
cvs rdiff -u -r1.8 -r1.9 src/sys/sys/selinfo.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/arch/x86/x86

2019-12-03 Thread Andrew Doran
On Tue, Dec 03, 2019 at 01:14:14PM +0100, Kamil Rytarowski wrote:

> On 03.12.2019 12:50, Juergen Hannken-Illjes wrote:
> > Module Name:src
> > Committed By:   hannken
> > Date:   Tue Dec  3 11:50:45 UTC 2019
> > 
> > Modified Files:
> > src/sys/arch/x86/x86: x86_machdep.c
> > 
> > Log Message:
> > Make sure the assignment to "idepth" is done inside the loop to prevent
> > preemption between loop end and dereference of "l_cpu->ci_depth".
> > 
> > 
> > To generate a diff of this commit:
> > cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/x86/x86_machdep.c
> > 
> > Please note that diffs are not public domain; they are subject to the
> > copyright notices on the relevant files.
> > 
> > 
> > Modified files:
> > 
> > Index: src/sys/arch/x86/x86/x86_machdep.c
> > diff -u src/sys/arch/x86/x86/x86_machdep.c:1.131 
> > src/sys/arch/x86/x86/x86_machdep.c:1.132
> > --- src/sys/arch/x86/x86/x86_machdep.c:1.131Tue Dec  3 11:50:16 2019
> > +++ src/sys/arch/x86/x86/x86_machdep.c  Tue Dec  3 11:50:45 2019
> > @@ -1,4 +1,4 @@
> > -/* $NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 hannken Exp $
> > */
> > +/* $NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 hannken Exp $
> > */
> >  
> >  /*-
> >   * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
> > @@ -31,7 +31,7 @@
> >   */
> >  
> >  #include 
> > -__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.131 2019/12/03 11:50:16 
> > hannken Exp $");
> > +__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.132 2019/12/03 11:50:45 
> > hannken Exp $");
> >  
> >  #include "opt_modular.h"
> >  #include "opt_physmem.h"
> > @@ -350,7 +350,7 @@ bool
> >  cpu_intr_p(void)
> >  {
> > uint64_t ncsw;
> > -   int idepth;
> > +   volatile int idepth;
> > lwp_t *l;
> >  
> > l = curlwp;
> > 
> 
> Thanks!
> 
> This looks like to be in need to be propagated to:
> src/sys/arch/arm/arm/arm_machdep.c, src/sys/arch/mips/mips/cpu_subr.c,
> src/sys/arch/sparc/sparc/intr.c, src/sys/arch/sparc64/sparc64/machdep.c,
> src/sys/arch/usermode/dev/cpu.c,

I will take care of that later today.

Andrew




Re: CVS commit: src/sys

2019-12-06 Thread Andrew Doran
This is experimental: we use l_cpu to mean a number of things and this
involves changing it to a different value than curcpu() in a running LWP,
which we have not done before.  I'll see about making it more robust.

Andrew

On Fri, Dec 06, 2019 at 09:36:11PM +, Andrew Doran wrote:

> Module Name:  src
> Committed By: ad
> Date: Fri Dec  6 21:36:11 UTC 2019
> 
> Modified Files:
>   src/sys/kern: kern_exec.c kern_exit.c kern_idle.c kern_lwp.c kern_sig.c
>   kern_sleepq.c kern_softint.c kern_synch.c
>   src/sys/sys: sched.h
> 
> Log Message:
> Make it possible to call mi_switch() and immediately switch to another CPU.
> This seems to take about 3us on my Intel system.  Two changes required:
> 
> - Have the caller to mi_switch() be responsible for calling spc_lock().
> - Avoid using l->l_cpu in mi_switch().
> 
> While here:
> 
> - Add a couple of calls to membar_enter()
> - Have the idle LWP set itself to LSIDL, to match softint_thread().
> - Remove unused return value from mi_switch().
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.484 -r1.485 src/sys/kern/kern_exec.c
> cvs rdiff -u -r1.277 -r1.278 src/sys/kern/kern_exit.c
> cvs rdiff -u -r1.27 -r1.28 src/sys/kern/kern_idle.c
> cvs rdiff -u -r1.216 -r1.217 src/sys/kern/kern_lwp.c
> cvs rdiff -u -r1.380 -r1.381 src/sys/kern/kern_sig.c
> cvs rdiff -u -r1.53 -r1.54 src/sys/kern/kern_sleepq.c
> cvs rdiff -u -r1.54 -r1.55 src/sys/kern/kern_softint.c
> cvs rdiff -u -r1.328 -r1.329 src/sys/kern/kern_synch.c
> cvs rdiff -u -r1.79 -r1.80 src/sys/sys/sched.h
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 


Re: CVS commit: src/sys/kern

2019-12-10 Thread Andrew Doran
On Wed, Dec 11, 2019 at 09:06:33AM +1100, matthew green wrote:

> "Andrew Doran" writes:
> > Module Name:src
> > Committed By:   ad
> > Date:   Mon Dec  9 21:02:10 UTC 2019
> > 
> > Modified Files:
> > src/sys/kern: kern_rwlock.c
> > 
> > Log Message:
> > Expunge the panicstr checks, we don't need them.
> 
> can you explain why?

Sure, I have developed a bit of a feel for it after years off watching the
thing panic.  The checks to not go too hard on the assertions once panicstr
are set are pretty good in my experience - we don't want that to snowball.

The ones that disable locking were of some kind of use (at least to me) back
in 2007 before we had a decent LOCKDEBUG setup for the newlock2 primitives. 
So it sprang out of development requirements and an uncertainty about all
how this new synchronization stuff was going to behave in practice more than
a desire to do the right thing.

On a uniprocessor or dual core box back then the panicstr checks didn't
really seem to have many bad effects, but with more CPUs it often seems to
make the crash much worse than it needs to be and I keep bumping into the
effects of it.  Here's a craptacular example:

http://www.netbsd.org/~ad/

That's kind of amusing to look at and it's only my framebuffer memory but I
worry that it could just as well be inodes or mbufs or anything else that
belongs to the user, and I think that until the CPUs are locked up and
activity stopped, the thing needs to keep working as properly as it can.

> what sort of crash-time testing did you perform?

That the system can be debugged and reset cleanly.  If we've got code in DDB
that hangs up or crashdups don't work then that's something we should fix.
I've not run into any in a long time, they seem to get fixed.

Do you have a particular concern or something else in mind?

Cheers,
Andrew


Re: CVS commit: src/sys/arch

2019-12-06 Thread Andrew Doran
On Sat, Dec 07, 2019 at 07:12:10AM +1100, matthew green wrote:
> > > > Why? I consider this totaly useless bloat, what was wrong with the 
> > > > boot.cfg
> > > > solution?
> > > 
> > > policy:  no default modules in the installation unless licenses
> > > issues force such, until module+kernel solution.
> > 
> > OK, but this is gone awry. The boot.cfg solution is great if anoyne
> > really needs this dmesg sugar, everyone else can go on using pcictl 
> > later instead.
> > 
> > So now the (reasonable) policy forces a (relatively harmless, as easily
> > overidable but still useless) change into bloat for everyone. Can we
> > just revert to the state before the initial boot.cfg change instead?
> 
> i'm not really a fan of this solution.
> 
> this code was removed from GENERIC back when ad was pushing
> hard on modules and reducing memory consumption using them,
> but we've got problems still to resolve about their safe
> usage.  (i really can't agree with your "harmless" line
> above.  modules are dangerous even with careful usage
> currently.)
> 
> so, this change is really about reverting a bad choice made
> 11 years ago, that still has not been properly resolved.
> we lost that functionality in netbsd 5.0 GENERIC with the
> idea it would be resolved "soon".  it's been a long, long
> "soon"...

Right.  And since then the kernel has doubled in size.  I don't like the
bloat, very frustrating, and I still think modules are the way to go.  But
whatever about the correct direction technically, people really seem to like
PCIVERBOSE so I'm throwing my hands up and saying that in retrospect, given
the way things have panned out, removing it was the wrong choice.

Andrew


CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 20:50:54 UTC 2019

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
A couple more tweaks to avoid reading the lock word.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.56 src/sys/kern/kern_rwlock.c:1.57
--- src/sys/kern/kern_rwlock.c:1.56	Fri Nov 29 20:04:54 2019
+++ src/sys/kern/kern_rwlock.c	Fri Nov 29 20:50:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.56 2019/11/29 20:04:54 riastradh Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.56 2019/11/29 20:04:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -417,10 +417,11 @@ rw_vector_enter(krwlock_t *rw, const krw
 		 * No need for a memory barrier because of context switch.
 		 * If not handed the lock, then spin again.
 		 */
-		if (op == RW_READER || (rw->rw_owner & RW_THREAD) == curthread)
+		if (op == RW_READER)
 			break;
-
 		owner = rw->rw_owner;
+		if ((owner & RW_THREAD) == curthread)
+			break;
 	}
 	KPREEMPT_ENABLE(curlwp);
 
@@ -476,14 +477,13 @@ rw_vector_exit(krwlock_t *rw)
 	 * lock would become unowned.
 	 */
 	RW_MEMBAR_EXIT();
-	for (;;) {
+	for (;; owner = next) {
 		newown = (owner - decr);
 		if ((newown & (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS)
 			break;
 		next = rw_cas(rw, owner, newown);
 		if (__predict_true(next == owner))
 			return;
-		owner = next;
 	}
 
 	/*
@@ -568,15 +568,15 @@ rw_vector_tryenter(krwlock_t *rw, const 
 		need_wait = RW_WRITE_LOCKED | RW_THREAD;
 	}
 
-	for (owner = rw->rw_owner;; owner = next) {
-		if (__predict_false((owner & need_wait) != 0))
-			return 0;
+	for (owner = 0;; owner = next) {
 		next = rw_cas(rw, owner, owner + incr);
 		if (__predict_true(next == owner)) {
 			/* Got it! */
 			RW_MEMBAR_ENTER();
 			break;
 		}
+		if (__predict_false((owner & need_wait) != 0))
+			return 0;
 	}
 
 	RW_WANTLOCK(rw, op);



CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 20:50:54 UTC 2019

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
A couple more tweaks to avoid reading the lock word.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 18:27:33 UTC 2019

Modified Files:
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/sh3/include: userret.h
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/include: userret.h
src/sys/arch/usermode/usermode: trap.c

Log Message:
PR port-sparc/54718 (sparc install hangs since recent scheduler changes)

- userret() must be called every time we return to user, it's not optional.
- If clearing the AST with interrupts off, you must loop over userret().


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/sh3/include/userret.h
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sparc/include/userret.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/usermode/usermode/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hppa/hppa/trap.c
diff -u src/sys/arch/hppa/hppa/trap.c:1.112 src/sys/arch/hppa/hppa/trap.c:1.113
--- src/sys/arch/hppa/hppa/trap.c:1.112	Thu Nov 21 19:24:00 2019
+++ src/sys/arch/hppa/hppa/trap.c	Fri Nov 29 18:27:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.112 2019/11/21 19:24:00 ad Exp $	*/
+/*	$NetBSD: trap.c,v 1.113 2019/11/29 18:27:32 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.112 2019/11/21 19:24:00 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.113 2019/11/29 18:27:32 ad Exp $");
 
 /* #define INTRDEBUG */
 /* #define TRAPDEBUG */
@@ -202,10 +202,11 @@ userret(struct lwp *l, register_t pc, u_
 {
 	struct proc *p = l->l_proc;
 
-	l->l_md.md_astpending = 0;
-	//curcpu()->ci_data.cpu_nast++;
-
-	mi_userret(l);
+	do {
+		l->l_md.md_astpending = 0;
+		//curcpu()->ci_data.cpu_nast++;
+		mi_userret(l);
+	} while (l->l_md.md_astpending);
 
 	/*
 	 * If profiling, charge recent system time to the trapped pc.

Index: src/sys/arch/sh3/include/userret.h
diff -u src/sys/arch/sh3/include/userret.h:1.14 src/sys/arch/sh3/include/userret.h:1.15
--- src/sys/arch/sh3/include/userret.h:1.14	Wed Nov  2 00:11:59 2016
+++ src/sys/arch/sh3/include/userret.h	Fri Nov 29 18:27:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.14 2016/11/02 00:11:59 pgoyette Exp $	*/
+/*	$NetBSD: userret.h,v 1.15 2019/11/29 18:27:32 ad Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -52,7 +52,16 @@ userret(struct lwp *l)
 {
 
 	/* Invoke MI userret code */
-	mi_userret(l);
+	do {
+		//curcpu()->ci_data.cpu_nast++;
+		l->l_md.md_astpending = 0;
+		mi_userret(l);
+	} while (l->l_md.md_astpending);
+
+	if (l->l_pflag & LP_OWEUPC) {
+		l->l_pflag &= ~LP_OWEUPC;
+		ADDUPROF(l);
+	}
 
 #ifdef PTRACE_HOOKS
 	/* Check if lwp is being PT_STEP'ed */

Index: src/sys/arch/sh3/sh3/exception.c
diff -u src/sys/arch/sh3/sh3/exception.c:1.68 src/sys/arch/sh3/sh3/exception.c:1.69
--- src/sys/arch/sh3/sh3/exception.c:1.68	Thu Nov 21 19:24:01 2019
+++ src/sys/arch/sh3/sh3/exception.c	Fri Nov 29 18:27:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: exception.c,v 1.68 2019/11/21 19:24:01 ad Exp $	*/
+/*	$NetBSD: exception.c,v 1.69 2019/11/29 18:27:33 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.68 2019/11/21 19:24:01 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.69 2019/11/29 18:27:33 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -471,15 +471,5 @@ ast(struct lwp *l, struct trapframe *tf)
 	KDASSERT(l != NULL);
 	KDASSERT(l->l_md.md_regs == tf);
 
-	while (l->l_md.md_astpending) {
-		//curcpu()->ci_data.cpu_nast++;
-		l->l_md.md_astpending = 0;
-
-		if (l->l_pflag & LP_OWEUPC) {
-			l->l_pflag &= ~LP_OWEUPC;
-			ADDUPROF(l);
-		}
-
-		userret(l);
-	}
+	userret(l);
 }

Index: src/sys/arch/sparc/include/userret.h
diff -u src/sys/arch/sparc/include/userret.h:1.10 src/sys/arch/sparc/include/userret.h:1.11
--- src/sys/arch/sparc/include/userret.h:1.10	Sat Nov 23 16:50:39 2019
+++ src/sys/arch/sparc/include/userret.h	Fri Nov 29 18:27:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.10 2019/11/23 16:50:39 ad Exp $ */
+/*	$NetBSD: userret.h,v 1.11 2019/11/29 18:27:33 ad Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -63,13 +63,14 @@ userret(struct lwp *l, int pc, u_quad_t 
 {
 	struct proc *p = l->l_proc;
 
-	while (cpuinfo.ci_want_ast) {
+	do {
 		cpuinfo.ci_want_ast = 0;
 		mi_userret(l);
-		if (l->l_pflag & LP_OWEUPC) {
-			l->l_pflag &= ~LP_OWEUPC;
-			ADDUPROF(l);
-		}
+	} while (cpuinfo.ci_want_ast);
+
+	if (l->l_pflag & LP_OWEUPC) {
+		l->l_pflag &= ~LP_OWEUPC;
+		ADDUPROF(l);
 	}
 
 	/*

Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.71 src/sys/arch/usermode/usermode/trap.c:1.72
--- 

CVS commit: src/sys/arch

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 18:27:33 UTC 2019

Modified Files:
src/sys/arch/hppa/hppa: trap.c
src/sys/arch/sh3/include: userret.h
src/sys/arch/sh3/sh3: exception.c
src/sys/arch/sparc/include: userret.h
src/sys/arch/usermode/usermode: trap.c

Log Message:
PR port-sparc/54718 (sparc install hangs since recent scheduler changes)

- userret() must be called every time we return to user, it's not optional.
- If clearing the AST with interrupts off, you must loop over userret().


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/sys/arch/hppa/hppa/trap.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/sh3/include/userret.h
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/sh3/sh3/exception.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/sparc/include/userret.h
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/usermode/usermode/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 18:29:45 UTC 2019

Modified Files:
src/sys/kern: sched_4bsd.c

Log Message:
Don't try to kpreempt a CPU hog unless __HAVE_PREEMPTION (oops).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/kern/sched_4bsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 18:29:45 UTC 2019

Modified Files:
src/sys/kern: sched_4bsd.c

Log Message:
Don't try to kpreempt a CPU hog unless __HAVE_PREEMPTION (oops).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/kern/sched_4bsd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sched_4bsd.c
diff -u src/sys/kern/sched_4bsd.c:1.37 src/sys/kern/sched_4bsd.c:1.38
--- src/sys/kern/sched_4bsd.c:1.37	Sat Nov 23 22:35:08 2019
+++ src/sys/kern/sched_4bsd.c	Fri Nov 29 18:29:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched_4bsd.c,v 1.37 2019/11/23 22:35:08 ad Exp $	*/
+/*	$NetBSD: sched_4bsd.c,v 1.38 2019/11/29 18:29:45 ad Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2019
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.37 2019/11/23 22:35:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sched_4bsd.c,v 1.38 2019/11/29 18:29:45 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -128,8 +128,12 @@ sched_tick(struct cpu_info *ci)
 		break;
 	case SCHED_RR:
 		/* Force it into mi_switch() to look for other jobs to run. */
+#ifdef __HAVE_PREEMPTION
 		atomic_or_uint(>l_dopreempt, DOPREEMPT_ACTIVE);
 		cpu_need_resched(ci, l, RESCHED_KPREEMPT);
+#else
+		cpu_need_resched(ci, l, RESCHED_UPREEMPT);
+#endif
 		break;
 	default:
 		if (spc->spc_flags & SPCF_SHOULDYIELD) {
@@ -138,8 +142,12 @@ sched_tick(struct cpu_info *ci)
 			 * due to buggy or inefficient code.  Force a
 			 * kernel preemption.
 			 */
+#ifdef __HAVE_PREEMPTION
 			atomic_or_uint(>l_dopreempt, DOPREEMPT_ACTIVE);
 			cpu_need_resched(ci, l, RESCHED_KPREEMPT);
+#else
+			cpu_need_resched(ci, l, RESCHED_UPREEMPT);
+#endif
 		} else if (spc->spc_flags & SPCF_SEENRR) {
 			/*
 			 * The process has already been through a roundrobin



CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 19:44:59 UTC 2019

Modified Files:
src/sys/kern: kern_mutex.c

Log Message:
Get rid of MUTEX_RECEIVE/MUTEX_GIVE.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Fri Nov 29 19:44:59 UTC 2019

Modified Files:
src/sys/kern: kern_mutex.c

Log Message:
Get rid of MUTEX_RECEIVE/MUTEX_GIVE.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/kern/kern_mutex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.79 src/sys/kern/kern_mutex.c:1.80
--- src/sys/kern/kern_mutex.c:1.79	Thu May  9 05:00:31 2019
+++ src/sys/kern/kern_mutex.c	Fri Nov 29 19:44:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.79 2019/05/09 05:00:31 ozaki-r Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.80 2019/11/29 19:44:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.79 2019/05/09 05:00:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.80 2019/11/29 19:44:59 ad Exp $");
 
 #include 
 #include 
@@ -168,6 +168,17 @@ do {	\
 } while (/* CONSTCOND */ 0)
 
 /*
+ * Memory barriers.
+ */
+#ifdef __HAVE_ATOMIC_AS_MEMBAR
+#define	MUTEX_MEMBAR_ENTER()
+#define	MUTEX_MEMBAR_EXIT()
+#else
+#define	MUTEX_MEMBAR_ENTER()		membar_enter()
+#define	MUTEX_MEMBAR_EXIT()		membar_exit()
+#endif
+
+/*
  * For architectures that provide 'simple' mutexes: they provide a
  * CAS function that is either MP-safe, or does not need to be MP
  * safe.  Adaptive mutexes on these architectures do not require an
@@ -225,7 +236,7 @@ MUTEX_ACQUIRE(kmutex_t *mtx, uintptr_t c
 	MUTEX_INHERITDEBUG(oldown, mtx->mtx_owner);
 	MUTEX_INHERITDEBUG(newown, oldown);
 	rv = MUTEX_CAS(>mtx_owner, oldown, newown);
-	MUTEX_RECEIVE(mtx);
+	MUTEX_MEMBAR_ENTER();
 	return rv;
 }
 
@@ -234,7 +245,7 @@ MUTEX_SET_WAITERS(kmutex_t *mtx, uintptr
 {
 	int rv;
 	rv = MUTEX_CAS(>mtx_owner, owner, owner | MUTEX_BIT_WAITERS);
-	MUTEX_RECEIVE(mtx);
+	MUTEX_MEMBAR_ENTER();
 	return rv;
 }
 
@@ -243,7 +254,7 @@ MUTEX_RELEASE(kmutex_t *mtx)
 {
 	uintptr_t newown;
 
-	MUTEX_GIVE(mtx);
+	MUTEX_MEMBAR_EXIT();
 	newown = 0;
 	MUTEX_INHERITDEBUG(newown, mtx->mtx_owner);
 	mtx->mtx_owner = newown;



CVS commit: src/sys/kern

2019-11-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Nov 27 20:31:13 UTC 2019

Modified Files:
src/sys/kern: kern_runq.c

Log Message:
Don't try to IPI other CPUs early on.  Fixes a crash on sparc64.  Thanks
to martin@ for diagnosing.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/kern_runq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_runq.c
diff -u src/sys/kern/kern_runq.c:1.49 src/sys/kern/kern_runq.c:1.50
--- src/sys/kern/kern_runq.c:1.49	Sat Nov 23 22:35:08 2019
+++ src/sys/kern/kern_runq.c	Wed Nov 27 20:31:13 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_runq.c,v 1.49 2019/11/23 22:35:08 ad Exp $	*/
+/*	$NetBSD: kern_runq.c,v 1.50 2019/11/27 20:31:13 ad Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.49 2019/11/23 22:35:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_runq.c,v 1.50 2019/11/27 20:31:13 ad Exp $");
 
 #include "opt_dtrace.h"
 
@@ -368,7 +368,7 @@ sched_resched_cpu(struct cpu_info *ci, p
 	 * If the priority level we're evaluating wouldn't cause a new LWP
 	 * to be run on the CPU, then we have nothing to do.
 	 */
-	if (pri <= spc->spc_curpriority) {
+	if (pri <= spc->spc_curpriority || !mp_online) {
 		if (__predict_true(unlock)) {
 			spc_unlock(ci);
 		}



CVS commit: src/sys/kern

2019-11-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Nov 27 20:31:13 UTC 2019

Modified Files:
src/sys/kern: kern_runq.c

Log Message:
Don't try to IPI other CPUs early on.  Fixes a crash on sparc64.  Thanks
to martin@ for diagnosing.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/kern_runq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:45:54 UTC 2019

Modified Files:
src/sys/sys: lwp.h

Log Message:
Mark the context switch counters volatile (because preemption).


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:45:54 UTC 2019

Modified Files:
src/sys/sys: lwp.h

Log Message:
Mark the context switch counters volatile (because preemption).


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/sys/lwp.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/lwp.h
diff -u src/sys/sys/lwp.h:1.190 src/sys/sys/lwp.h:1.191
--- src/sys/sys/lwp.h:1.190	Sat Nov 23 19:42:52 2019
+++ src/sys/sys/lwp.h	Sat Nov 30 17:45:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: lwp.h,v 1.190 2019/11/23 19:42:52 ad Exp $	*/
+/*	$NetBSD: lwp.h,v 1.191 2019/11/30 17:45:54 ad Exp $	*/
 
 /*
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010, 2019
@@ -112,8 +112,8 @@ struct lwp {
 	pri_t		l_auxprio;	/* l: max(inherit,protect) priority */
 	int		l_protectdepth;	/* l: for PTHREAD_PRIO_PROTECT */
 	SLIST_HEAD(, turnstile) l_pi_lenders; /* l: ts lending us priority */
-	uint64_t	l_ncsw;		/* l: total context switches */
-	uint64_t	l_nivcsw;	/* l: involuntary context switches */
+	volatile uint64_t l_ncsw;	/* l: total context switches */
+	volatile uint64_t l_nivcsw;	/* l: involuntary context switches */
 	u_int		l_cpticks;	/* (: Ticks of CPU time */
 	fixpt_t		l_pctcpu;	/* p: %cpu during l_swtime */
 	fixpt_t		l_estcpu;	/* l: cpu time for SCHED_4BSD */



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:46:27 UTC 2019

Modified Files:
src/sys/sys: sched.h

Log Message:
Mark spc_curpriority volatile.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/sys/sched.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:46:27 UTC 2019

Modified Files:
src/sys/sys: sched.h

Log Message:
Mark spc_curpriority volatile.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/sys/sched.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/sched.h
diff -u src/sys/sys/sched.h:1.77 src/sys/sys/sched.h:1.78
--- src/sys/sys/sched.h:1.77	Sat Nov 23 19:42:52 2019
+++ src/sys/sys/sched.h	Sat Nov 30 17:46:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sched.h,v 1.77 2019/11/23 19:42:52 ad Exp $	*/
+/*	$NetBSD: sched.h,v 1.78 2019/11/30 17:46:27 ad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2007, 2008, 2019
@@ -154,16 +154,13 @@ __END_DECLS
  * c:	cpu_lock
  */
 struct schedstate_percpu {
-	/* First set of data is likely to be accessed by other CPUs. */
 	kmutex_t	*spc_mutex;	/* (: lock on below, runnable LWPs */
 	kmutex_t	*spc_lwplock;	/* (: general purpose lock for LWPs */
 	struct lwp	*spc_migrating;	/* (: migrating LWP */
-	pri_t		spc_curpriority;/* m: usrpri of curlwp */
+	volatile pri_t	spc_curpriority;/* m: usrpri of curlwp */
 	pri_t		spc_maxpriority;/* m: highest priority queued */
 	psetid_t	spc_psid;	/* c: processor-set ID */
 	time_t		spc_lastmod;	/* c: time of last cpu state change */
-
-	/* For the most part, this set of data is CPU-private. */
 	void		*spc_sched_info;/* (: scheduler-specific structure */
 	volatile int	spc_flags;	/* s: flags; see below */
 	u_int		spc_schedticks;	/* s: ticks for schedclock() */



CVS commit: src/sys/kern

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 20:45:49 UTC 2019

Modified Files:
src/sys/kern: tty_ptm.c

Log Message:
VOP_UNLOCK + vrele -> vput


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/kern/tty_ptm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/tty_ptm.c
diff -u src/sys/kern/tty_ptm.c:1.40 src/sys/kern/tty_ptm.c:1.41
--- src/sys/kern/tty_ptm.c:1.40	Fri Mar  1 11:06:57 2019
+++ src/sys/kern/tty_ptm.c	Sat Nov 30 20:45:49 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_ptm.c,v 1.40 2019/03/01 11:06:57 pgoyette Exp $	*/
+/*	$NetBSD: tty_ptm.c,v 1.41 2019/11/30 20:45:49 ad Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.40 2019/03/01 11:06:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.41 2019/11/30 20:45:49 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -234,8 +234,7 @@ pty_grant_slave(struct lwp *l, dev_t dev
 		error = VOP_SETATTR(vp, , lwp0.l_cred);
 		if (error) {
 			DPRINTF(("setattr %d\n", error));
-			VOP_UNLOCK(vp);
-			vrele(vp);
+			vput(vp);
 			return error;
 		}
 	}



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:49:03 UTC 2019

Modified Files:
src/sys/sys: userret.h

Log Message:
Avoid false sharing: only update spc_curpriority if value has changed.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/sys

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 17:49:03 UTC 2019

Modified Files:
src/sys/sys: userret.h

Log Message:
Avoid false sharing: only update spc_curpriority if value has changed.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/sys/userret.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/userret.h
diff -u src/sys/sys/userret.h:1.30 src/sys/sys/userret.h:1.31
--- src/sys/sys/userret.h:1.30	Fri Nov 22 23:38:15 2019
+++ src/sys/sys/userret.h	Sat Nov 30 17:49:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.30 2019/11/22 23:38:15 ad Exp $	*/
+/*	$NetBSD: userret.h,v 1.31 2019/11/30 17:49:03 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2003, 2006, 2008, 2019 The NetBSD Foundation, Inc.
@@ -100,14 +100,20 @@ mi_userret(struct lwp *l)
 		KPREEMPT_DISABLE(l);
 		ci = l->l_cpu;
 	}
-	l->l_kpriority = false;
 	/*
 	 * lwp_eprio() is too involved to use here unlocked.  At this point
 	 * it only matters for PTHREAD_PRIO_PROTECT; setting a too low value
 	 * is OK because the scheduler will find out the true value if we
 	 * end up in mi_switch().
+	 *
+	 * This is being called on every syscall and trap, and remote CPUs
+	 * regularly look at ci_schedstate.  Keep the cache line in the
+	 * SHARED state by only updating spc_curpriority if it has changed.
 	 */
-	ci->ci_schedstate.spc_curpriority = l->l_priority;
+	l->l_kpriority = false;
+	if (ci->ci_schedstate.spc_curpriority != l->l_priority) {
+		ci->ci_schedstate.spc_curpriority = l->l_priority;
+	}
 	KPREEMPT_ENABLE(l);
 
 	LOCKDEBUG_BARRIER(NULL, 0);



CVS commit: src/sys/dev/onewire

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 23:06:52 UTC 2019

Modified Files:
src/sys/dev/onewire: owtemp.c

Log Message:
Make owtemp reliable for me:

- Don't do the calculation if there is a CRC error.
- If we get any kind of error during a refresh, retry up to three times.
- Add event counters to report what's going on.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/onewire/owtemp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/onewire/owtemp.c
diff -u src/sys/dev/onewire/owtemp.c:1.18 src/sys/dev/onewire/owtemp.c:1.19
--- src/sys/dev/onewire/owtemp.c:1.18	Fri Oct 25 16:25:14 2019
+++ src/sys/dev/onewire/owtemp.c	Sat Nov 30 23:06:52 2019
@@ -1,6 +1,35 @@
-/*	$NetBSD: owtemp.c,v 1.18 2019/10/25 16:25:14 martin Exp $	*/
+/*	$NetBSD: owtemp.c,v 1.19 2019/11/30 23:06:52 ad Exp $	*/
 /*	$OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
 /*
  * Copyright (c) 2006 Alexander Yurchenko 
  *
@@ -22,7 +51,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.18 2019/10/25 16:25:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.19 2019/11/30 23:06:52 ad Exp $");
 
 #include 
 #include 
@@ -51,14 +80,20 @@ struct owtemp_softc {
 	uint32_t			(*sc_owtemp_decode)(const uint8_t *);
 
 	intsc_dying;
+
+	struct evcnt			sc_ev_update;
+	struct evcnt			sc_ev_rsterr;
+	struct evcnt			sc_ev_crcerr;
 };
 
 static int	owtemp_match(device_t, cfdata_t, void *);
 static void	owtemp_attach(device_t, device_t, void *);
 static int	owtemp_detach(device_t, int);
 static int	owtemp_activate(device_t, enum devact);
-
-static void	owtemp_update(void *);
+static bool	owtemp_update(struct owtemp_softc *sc, uint32_t *temp);
+static void	owtemp_refresh(struct sysmon_envsys *, envsys_data_t *);
+static uint32_t	owtemp_decode_ds18b20(const uint8_t *);
+static uint32_t	owtemp_decode_ds1920(const uint8_t *);
 
 CFATTACH_DECL_NEW(owtemp, sizeof(struct owtemp_softc),
 	owtemp_match, owtemp_attach, owtemp_detach, owtemp_activate);
@@ -71,10 +106,7 @@ static const struct onewire_matchfam owt
 	{ ONEWIRE_FAMILY_DS1822 },
 };
 
-static void	owtemp_refresh(struct sysmon_envsys *, envsys_data_t *);
-
-static uint32_t	owtemp_decode_ds18b20(const uint8_t *);
-static uint32_t	owtemp_decode_ds1920(const uint8_t *);
+int	owtemp_retries = 3;
 
 static int
 owtemp_match(device_t parent, cfdata_t match, void *aux)
@@ -110,6 +142,13 @@ owtemp_attach(device_t parent, device_t 
 		break;
 	}
 
+	evcnt_attach_dynamic(>sc_ev_update, EVCNT_TYPE_MISC, NULL,
+	   device_xname(self), "update");
+	evcnt_attach_dynamic(>sc_ev_rsterr, EVCNT_TYPE_MISC, NULL,
+	   device_xname(self), "reset error");
+	evcnt_attach_dynamic(>sc_ev_crcerr, EVCNT_TYPE_MISC, NULL,
+	   device_xname(self), "crc error");
+
 	sc->sc_sme = sysmon_envsys_create();
 
 	/* Initialize sensor */
@@ -144,6 +183,9 @@ owtemp_detach(device_t self, int flags)
 	struct owtemp_softc *sc = device_private(self);
 
 	sysmon_envsys_unregister(sc->sc_sme);
+	evcnt_detach(>sc_ev_rsterr);
+	evcnt_detach(>sc_ev_update);
+	evcnt_detach(>sc_ev_crcerr);
 
 	return 0;
 }
@@ -162,18 +204,12 @@ owtemp_activate(device_t self, enum deva
 	}
 }
 
-static void
-owtemp_update(void *arg)
+static bool
+owtemp_update(struct owtemp_softc *sc, uint32_t *temp)
 {
-	struct o

CVS commit: src/sys/dev/onewire

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 23:06:52 UTC 2019

Modified Files:
src/sys/dev/onewire: owtemp.c

Log Message:
Make owtemp reliable for me:

- Don't do the calculation if there is a CRC error.
- If we get any kind of error during a refresh, retry up to three times.
- Add event counters to report what's going on.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/onewire/owtemp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 20:45:49 UTC 2019

Modified Files:
src/sys/kern: tty_ptm.c

Log Message:
VOP_UNLOCK + vrele -> vput


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/kern/tty_ptm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/kern

2019-11-30 Thread Andrew Doran
Hi,

On Sat, Nov 30, 2019 at 04:52:38PM +0900, Rin Okuyama wrote:
> On 2019/11/30 5:50, Andrew Doran wrote:
> > Module Name:src
> > Committed By:   ad
> > Date:   Fri Nov 29 20:50:54 UTC 2019
> > 
> > Modified Files:
> > src/sys/kern: kern_rwlock.c
> > 
> > Log Message:
> > A couple more tweaks to avoid reading the lock word.
> > 
> > 
> > To generate a diff of this commit:
> > cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_rwlock.c
> > 
> > Please note that diffs are not public domain; they are subject to the
> > copyright notices on the relevant files.
> 
> Hi,
> 
> After this commit, GENERIC64 kernel on evbarm-aarch64 does no longer
> boot multiuser anymore with rwlock related panics:
> 
>   panic: kernel diagnostic assertion "vm_map_locked_p(map)" failed: file 
> "../../../../uvm/uvm_map.c", line 1315
> 
> or
> 
>   panic: kernel diagnostic assertion "rw_write_held(>lock)" failed: 
> file "../../../../uvm/uvm_map.c", line 701
> 
> By reverting kern_rwlock.c to rev 1.56, panics disappear as far as
> I can see.

Hmm, it works fine on amd64 and looks OK but me, but I have backed it out
for the time being.

Thank you,
Andrew


CVS commit: src/sys/kern

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 14:21:16 UTC 2019

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
Back out previous.  It works on amd64 under stress test but not
evbarm-aarch64 for some reason.  Will revisit.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.57 src/sys/kern/kern_rwlock.c:1.58
--- src/sys/kern/kern_rwlock.c:1.57	Fri Nov 29 20:50:54 2019
+++ src/sys/kern/kern_rwlock.c	Sat Nov 30 14:21:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.58 2019/11/30 14:21:16 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.58 2019/11/30 14:21:16 ad Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -417,11 +417,10 @@ rw_vector_enter(krwlock_t *rw, const krw
 		 * No need for a memory barrier because of context switch.
 		 * If not handed the lock, then spin again.
 		 */
-		if (op == RW_READER)
+		if (op == RW_READER || (rw->rw_owner & RW_THREAD) == curthread)
 			break;
+
 		owner = rw->rw_owner;
-		if ((owner & RW_THREAD) == curthread)
-			break;
 	}
 	KPREEMPT_ENABLE(curlwp);
 
@@ -477,13 +476,14 @@ rw_vector_exit(krwlock_t *rw)
 	 * lock would become unowned.
 	 */
 	RW_MEMBAR_EXIT();
-	for (;; owner = next) {
+	for (;;) {
 		newown = (owner - decr);
 		if ((newown & (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS)
 			break;
 		next = rw_cas(rw, owner, newown);
 		if (__predict_true(next == owner))
 			return;
+		owner = next;
 	}
 
 	/*
@@ -568,15 +568,15 @@ rw_vector_tryenter(krwlock_t *rw, const 
 		need_wait = RW_WRITE_LOCKED | RW_THREAD;
 	}
 
-	for (owner = 0;; owner = next) {
+	for (owner = rw->rw_owner;; owner = next) {
+		if (__predict_false((owner & need_wait) != 0))
+			return 0;
 		next = rw_cas(rw, owner, owner + incr);
 		if (__predict_true(next == owner)) {
 			/* Got it! */
 			RW_MEMBAR_ENTER();
 			break;
 		}
-		if (__predict_false((owner & need_wait) != 0))
-			return 0;
 	}
 
 	RW_WANTLOCK(rw, op);



CVS commit: src/sys/kern

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 14:21:16 UTC 2019

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
Back out previous.  It works on amd64 under stress test but not
evbarm-aarch64 for some reason.  Will revisit.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/sh3

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 15:53:36 UTC 2019

Modified Files:
src/sys/arch/sh3/include: userret.h
src/sys/arch/sh3/sh3: exception.c

Log Message:
Revert previous.  Looks like it requires a more extensive fix.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sh3/include/userret.h
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/sh3/sh3/exception.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/sh3

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 15:53:36 UTC 2019

Modified Files:
src/sys/arch/sh3/include: userret.h
src/sys/arch/sh3/sh3: exception.c

Log Message:
Revert previous.  Looks like it requires a more extensive fix.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sh3/include/userret.h
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/sh3/sh3/exception.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/sh3/include/userret.h
diff -u src/sys/arch/sh3/include/userret.h:1.15 src/sys/arch/sh3/include/userret.h:1.16
--- src/sys/arch/sh3/include/userret.h:1.15	Fri Nov 29 18:27:32 2019
+++ src/sys/arch/sh3/include/userret.h	Sat Nov 30 15:53:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: userret.h,v 1.15 2019/11/29 18:27:32 ad Exp $	*/
+/*	$NetBSD: userret.h,v 1.16 2019/11/30 15:53:36 ad Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -52,16 +52,7 @@ userret(struct lwp *l)
 {
 
 	/* Invoke MI userret code */
-	do {
-		//curcpu()->ci_data.cpu_nast++;
-		l->l_md.md_astpending = 0;
-		mi_userret(l);
-	} while (l->l_md.md_astpending);
-
-	if (l->l_pflag & LP_OWEUPC) {
-		l->l_pflag &= ~LP_OWEUPC;
-		ADDUPROF(l);
-	}
+	mi_userret(l);
 
 #ifdef PTRACE_HOOKS
 	/* Check if lwp is being PT_STEP'ed */

Index: src/sys/arch/sh3/sh3/exception.c
diff -u src/sys/arch/sh3/sh3/exception.c:1.69 src/sys/arch/sh3/sh3/exception.c:1.70
--- src/sys/arch/sh3/sh3/exception.c:1.69	Fri Nov 29 18:27:33 2019
+++ src/sys/arch/sh3/sh3/exception.c	Sat Nov 30 15:53:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: exception.c,v 1.69 2019/11/29 18:27:33 ad Exp $	*/
+/*	$NetBSD: exception.c,v 1.70 2019/11/30 15:53:36 ad Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc. All rights reserved.
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.69 2019/11/29 18:27:33 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exception.c,v 1.70 2019/11/30 15:53:36 ad Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -471,5 +471,15 @@ ast(struct lwp *l, struct trapframe *tf)
 	KDASSERT(l != NULL);
 	KDASSERT(l->l_md.md_regs == tf);
 
-	userret(l);
+	while (l->l_md.md_astpending) {
+		//curcpu()->ci_data.cpu_nast++;
+		l->l_md.md_astpending = 0;
+
+		if (l->l_pflag & LP_OWEUPC) {
+			l->l_pflag &= ~LP_OWEUPC;
+			ADDUPROF(l);
+		}
+
+		userret(l);
+	}
 }



CVS commit: src/sys/dev

2019-11-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Nov 30 23:04:12 UTC 2019

Modified Files:
src/sys/dev/gpio: gpioow.c
src/sys/dev/onewire: onewire.c onewire_bitbang.c onewirevar.h

Log Message:
onewire:

- Re-do the signalling to be a little more forgiving and efficient.
- If bus reset fails during probe, try a second time.
- Spread out kernel threads for many busses to avoid thundering herd effect.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/gpio/gpioow.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/onewire/onewire.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/onewire/onewire_bitbang.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/onewire/onewirevar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/gpio/gpioow.c
diff -u src/sys/dev/gpio/gpioow.c:1.15 src/sys/dev/gpio/gpioow.c:1.16
--- src/sys/dev/gpio/gpioow.c:1.15	Sat Oct 28 04:53:56 2017
+++ src/sys/dev/gpio/gpioow.c	Sat Nov 30 23:04:12 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioow.c,v 1.15 2017/10/28 04:53:56 riastradh Exp $ */
+/* $NetBSD: gpioow.c,v 1.16 2019/11/30 23:04:12 ad Exp $ */
 /*	$OpenBSD: gpioow.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gpioow.c,v 1.15 2017/10/28 04:53:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpioow.c,v 1.16 2019/11/30 23:04:12 ad Exp $");
 
 /*
  * 1-Wire bus bit-banging through GPIO pin.
@@ -57,7 +57,8 @@ int	gpioow_detach(device_t, int);
 int	gpioow_activate(device_t, enum devact);
 
 int	gpioow_ow_reset(void *);
-int	gpioow_ow_bit(void *, int);
+int	gpioow_ow_read_bit(void *);
+void	gpioow_ow_write_bit(void *, int);
 
 void	gpioow_bb_rx(void *);
 void	gpioow_bb_tx(void *);
@@ -143,7 +144,8 @@ gpioow_attach(device_t parent, device_t 
 	/* Attach 1-Wire bus */
 	sc->sc_ow_bus.bus_cookie = sc;
 	sc->sc_ow_bus.bus_reset = gpioow_ow_reset;
-	sc->sc_ow_bus.bus_bit = gpioow_ow_bit;
+	sc->sc_ow_bus.bus_read_bit = gpioow_ow_read_bit;
+	sc->sc_ow_bus.bus_write_bit = gpioow_ow_write_bit;
 
 	memset(, 0, sizeof(oba));
 	oba.oba_bus = >sc_ow_bus;
@@ -193,9 +195,15 @@ gpioow_ow_reset(void *arg)
 }
 
 int
-gpioow_ow_bit(void *arg, int value)
+gpioow_ow_read_bit(void *arg)
 {
-	return (onewire_bb_bit(_bbops, arg, value));
+	return (onewire_bb_read_bit(_bbops, arg));
+}
+
+void
+gpioow_ow_write_bit(void *arg, int value)
+{
+	onewire_bb_write_bit(_bbops, arg, value);
 }
 
 void

Index: src/sys/dev/onewire/onewire.c
diff -u src/sys/dev/onewire/onewire.c:1.17 src/sys/dev/onewire/onewire.c:1.18
--- src/sys/dev/onewire/onewire.c:1.17	Fri Oct 25 16:25:14 2019
+++ src/sys/dev/onewire/onewire.c	Sat Nov 30 23:04:12 2019
@@ -1,6 +1,35 @@
-/*	$NetBSD: onewire.c,v 1.17 2019/10/25 16:25:14 martin Exp $	*/
+/*	$NetBSD: onewire.c,v 1.18 2019/11/30 23:04:12 ad Exp $	*/
 /*	$OpenBSD: onewire.c,v 1.1 2006/03/04 16:27:03 grange Exp $	*/
 
+/*-
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Doran.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
 /*
  * Copyright (c) 2006 Alexander Yurchenko 
  *
@@ -18,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: onewire.c,v 1.17 2019/10/25 16:25:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: onewire.c,v 1.18 2019/11/30 23:04:12 ad Exp $");
 
 /*
  * 1-Wire bus driver.
@@ -202,14 +231,25 @@ onewire_reset(void *arg)
 }
 
 int
-onewire_bit(void *arg, int value)
+onewire_read_bit(void *arg)
 {
 	struct onewire_softc *sc = arg;
 	struct onewire_bus *bus = sc-&

  1   2   3   4   >