Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Replace the xxx_acquire()/xxx_release() rwlocks ...
details: https://anonhg.NetBSD.org/src/rev/d81bbabf1d34
branches: trunk
changeset: 773728:d81bbabf1d34
user: pgoyette <pgoyette%NetBSD.org@localhost>
date: Tue Feb 14 15:08:07 2012 +0000
description:
Replace the xxx_acquire()/xxx_release() rwlocks with mutexes. There are
only RW_WRITERs for these, and no RW_READERs, so no need to incur the
extra overhead of allowing for both. As discussed on tech-kern.
For piixpm and ichsmb, the acquire/release protocol needs to be used,
even if the request is I2C_F_POLL'd (or if the device supports only
polled mode). Otherwise multiple requests can be running at the same
time, and they stomp on each other and create anomolous results.
Part 2 addresses my PR kern/45889
3 ACKs from releng
diffstat:
sys/dev/pci/amdpm_smbus.c | 12 ++++++------
sys/dev/pci/amdpmvar.h | 6 +++---
sys/dev/pci/ichsmb.c | 18 +++++++++---------
sys/dev/pci/nfsmb.c | 14 +++++++-------
sys/dev/pci/piixpm.c | 22 ++++++++++------------
5 files changed, 35 insertions(+), 37 deletions(-)
diffs (287 lines):
diff -r f203180816d5 -r d81bbabf1d34 sys/dev/pci/amdpm_smbus.c
--- a/sys/dev/pci/amdpm_smbus.c Tue Feb 14 14:33:53 2012 +0000
+++ b/sys/dev/pci/amdpm_smbus.c Tue Feb 14 15:08:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amdpm_smbus.c,v 1.17 2011/11/19 02:39:14 christos Exp $ */
+/* $NetBSD: amdpm_smbus.c,v 1.18 2012/02/14 15:08:07 pgoyette Exp $ */
/*
* Copyright (c) 2005 Anil Gopinath (anil_public%yahoo.com@localhost)
@@ -32,14 +32,14 @@
* AMD-8111 HyperTransport I/O Hub
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.17 2011/11/19 02:39:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.18 2012/02/14 15:08:07 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/rnd.h>
-#include <sys/rwlock.h>
+#include <sys/mutex.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
@@ -83,7 +83,7 @@
sc->sc_i2c.ic_write_byte = NULL;
sc->sc_i2c.ic_exec = amdpm_smbus_exec;
- rw_init(&sc->sc_rwlock);
+ mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
iba.iba_tag = &sc->sc_i2c;
(void)config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
@@ -94,7 +94,7 @@
{
struct amdpm_softc *sc = cookie;
- rw_enter(&sc->sc_rwlock, RW_WRITER);
+ mutex_enter(&sc->sc_mutex);
return 0;
}
@@ -103,7 +103,7 @@
{
struct amdpm_softc *sc = cookie;
- rw_exit(&sc->sc_rwlock);
+ mutex_exit(&sc->sc_mutex);
}
static int
diff -r f203180816d5 -r d81bbabf1d34 sys/dev/pci/amdpmvar.h
--- a/sys/dev/pci/amdpmvar.h Tue Feb 14 14:33:53 2012 +0000
+++ b/sys/dev/pci/amdpmvar.h Tue Feb 14 15:08:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amdpmvar.h,v 1.7 2011/11/19 22:51:23 tls Exp $ */
+/* $NetBSD: amdpmvar.h,v 1.8 2012/02/14 15:08:07 pgoyette Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#ifndef _DEV_PCI_AMDPMVAR_H_
#define _DEV_PCI_AMDPMVAR_H_
-#include <sys/rwlock.h>
+#include <sys/mutex.h>
struct amdpm_softc {
struct device sc_dev;
@@ -47,7 +47,7 @@
i2c_addr_t sc_smbus_slaveaddr; /* address of smbus slave */
struct i2c_controller sc_i2c; /* i2c controller info */
- krwlock_t sc_rwlock;
+ kmutex_t sc_mutex;
void *sc_ih;
diff -r f203180816d5 -r d81bbabf1d34 sys/dev/pci/ichsmb.c
--- a/sys/dev/pci/ichsmb.c Tue Feb 14 14:33:53 2012 +0000
+++ b/sys/dev/pci/ichsmb.c Tue Feb 14 15:08:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ichsmb.c,v 1.26 2012/01/30 19:41:19 drochner Exp $ */
+/* $NetBSD: ichsmb.c,v 1.27 2012/02/14 15:08:07 pgoyette Exp $ */
/* $OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $ */
/*
@@ -22,13 +22,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.26 2012/01/30 19:41:19 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.27 2012/02/14 15:08:07 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <sys/kernel.h>
-#include <sys/rwlock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/bus.h>
@@ -59,7 +59,7 @@
int sc_poll;
struct i2c_controller sc_i2c_tag;
- krwlock_t sc_i2c_rwlock;
+ kmutex_t sc_i2c_mutex;
struct {
i2c_op_t op;
void * buf;
@@ -166,7 +166,7 @@
}
/* Attach I2C bus */
- rw_init(&sc->sc_i2c_rwlock);
+ mutex_init(&sc->sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
sc->sc_i2c_tag.ic_cookie = sc;
sc->sc_i2c_tag.ic_acquire_bus = ichsmb_i2c_acquire_bus;
sc->sc_i2c_tag.ic_release_bus = ichsmb_i2c_release_bus;
@@ -186,10 +186,10 @@
{
struct ichsmb_softc *sc = cookie;
- if (cold || sc->sc_poll || (flags & I2C_F_POLL))
+ if (cold)
return 0;
- rw_enter(&sc->sc_i2c_rwlock, RW_WRITER);
+ mutex_enter(&sc->sc_i2c_mutex);
return 0;
}
@@ -198,10 +198,10 @@
{
struct ichsmb_softc *sc = cookie;
- if (cold || sc->sc_poll || (flags & I2C_F_POLL))
+ if (cold)
return;
- rw_exit(&sc->sc_i2c_rwlock);
+ mutex_exit(&sc->sc_i2c_mutex);
}
static int
diff -r f203180816d5 -r d81bbabf1d34 sys/dev/pci/nfsmb.c
--- a/sys/dev/pci/nfsmb.c Tue Feb 14 14:33:53 2012 +0000
+++ b/sys/dev/pci/nfsmb.c Tue Feb 14 15:08:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfsmb.c,v 1.22 2012/01/30 19:41:22 drochner Exp $ */
+/* $NetBSD: nfsmb.c,v 1.23 2012/02/14 15:08:07 pgoyette Exp $ */
/*
* Copyright (c) 2007 KIYOHARA Takashi
* All rights reserved.
@@ -26,13 +26,13 @@
*
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.22 2012/01/30 19:41:22 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfsmb.c,v 1.23 2012/02/14 15:08:07 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/errno.h>
#include <sys/kernel.h>
-#include <sys/rwlock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/bus.h>
@@ -73,7 +73,7 @@
bus_space_handle_t sc_ioh;
struct i2c_controller sc_i2c; /* i2c controller info */
- krwlock_t sc_rwlock;
+ kmutex_t sc_mutex;
};
@@ -237,7 +237,7 @@
sc->sc_i2c.ic_write_byte = NULL;
sc->sc_i2c.ic_exec = nfsmb_exec;
- rw_init(&sc->sc_rwlock);
+ mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
if (bus_space_map(sc->sc_iot, nfsmbcap->nfsmb_addr, NFORCE_SMBSIZE, 0,
&sc->sc_ioh) != 0) {
@@ -261,7 +261,7 @@
{
struct nfsmb_softc *sc = cookie;
- rw_enter(&sc->sc_rwlock, RW_WRITER);
+ mutex_enter(&sc->sc_mutex);
return 0;
}
@@ -270,7 +270,7 @@
{
struct nfsmb_softc *sc = cookie;
- rw_exit(&sc->sc_rwlock);
+ mutex_exit(&sc->sc_mutex);
}
static int
diff -r f203180816d5 -r d81bbabf1d34 sys/dev/pci/piixpm.c
--- a/sys/dev/pci/piixpm.c Tue Feb 14 14:33:53 2012 +0000
+++ b/sys/dev/pci/piixpm.c Tue Feb 14 15:08:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: piixpm.c,v 1.39 2012/01/30 19:41:22 drochner Exp $ */
+/* $NetBSD: piixpm.c,v 1.40 2012/02/14 15:08:07 pgoyette Exp $ */
/* $OpenBSD: piixpm.c,v 1.20 2006/02/27 08:25:02 grange Exp $ */
/*
@@ -22,13 +22,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.39 2012/01/30 19:41:22 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: piixpm.c,v 1.40 2012/02/14 15:08:07 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
-#include <sys/rwlock.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/bus.h>
@@ -82,7 +82,7 @@
pcireg_t sc_id;
struct i2c_controller sc_i2c_tag;
- krwlock_t sc_i2c_rwlock;
+ kmutex_t sc_i2c_mutex;
struct {
i2c_op_t op;
void * buf;
@@ -251,7 +251,7 @@
attach_i2c:
/* Attach I2C bus */
- rw_init(&sc->sc_i2c_rwlock);
+ mutex_init(&sc->sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE);
sc->sc_i2c_tag.ic_cookie = sc;
sc->sc_i2c_tag.ic_acquire_bus = piixpm_i2c_acquire_bus;
sc->sc_i2c_tag.ic_release_bus = piixpm_i2c_release_bus;
@@ -331,6 +331,7 @@
aprint_error_dev(sc->sc_dev, "can't map smbus I/O space\n");
return EBUSY;
}
+ aprint_normal_dev(sc->sc_dev, "polling (SB800)\n");
sc->sc_poll = 1;
return 0;
@@ -362,10 +363,9 @@
{
struct piixpm_softc *sc = cookie;
- if (cold || sc->sc_poll || (flags & I2C_F_POLL))
- return (0);
+ if (!cold)
+ mutex_enter(&sc->sc_i2c_mutex);
- rw_enter(&sc->sc_i2c_rwlock, RW_WRITER);
return 0;
}
@@ -374,10 +374,8 @@
{
struct piixpm_softc *sc = cookie;
- if (cold || sc->sc_poll || (flags & I2C_F_POLL))
- return;
-
- rw_exit(&sc->sc_i2c_rwlock);
+ if (!cold)
+ mutex_exit(&sc->sc_i2c_mutex);
}
static int
Home |
Main Index |
Thread Index |
Old Index