From: Bjorn Helgaas <helgaas@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Lukas Wunner <lukas@wunner.de>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Tyrel Datwyler <tyreld@linux.vnet.ibm.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] pci: ibmphp_hpc: turn semaphores into completions or mutexes
Date: Tue, 29 Jan 2019 17:16:58 -0600 [thread overview]
Message-ID: <20190129231658.GH91506@google.com> (raw)
In-Reply-To: <20181210214955.1826522-1-arnd@arndb.de>
On Mon, Dec 10, 2018 at 10:49:10PM +0100, Arnd Bergmann wrote:
> The sem_exit variable is conceptually a completion, so it should
> be called that.
>
> Similarly, the semOperations semaphore is a simple mutex, and
> can be changed into that, respectively.
>
> With both converted, the ibmphp_hpc_initvars() function is no longer
> used and can be removed.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Applied to pci/hotplug for v5.1, thanks!
> ---
> drivers/pci/hotplug/ibmphp.h | 1 -
> drivers/pci/hotplug/ibmphp_core.c | 2 --
> drivers/pci/hotplug/ibmphp_hpc.c | 47 +++++++++----------------------
> 3 files changed, 14 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
> index b89f850c3a4e..e90a4ebf6550 100644
> --- a/drivers/pci/hotplug/ibmphp.h
> +++ b/drivers/pci/hotplug/ibmphp.h
> @@ -378,7 +378,6 @@ int ibmphp_add_pfmem_from_mem(struct resource_node *);
> struct bus_node *ibmphp_find_res_bus(u8);
> void ibmphp_print_test(void); /* for debugging purposes */
>
> -void ibmphp_hpc_initvars(void);
> int ibmphp_hpc_readslot(struct slot *, u8, u8 *);
> int ibmphp_hpc_writeslot(struct slot *, u8);
> void ibmphp_lock_operations(void);
> diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
> index 5752b57198e3..e04b17d81e38 100644
> --- a/drivers/pci/hotplug/ibmphp_core.c
> +++ b/drivers/pci/hotplug/ibmphp_core.c
> @@ -1312,8 +1312,6 @@ static int __init ibmphp_init(void)
>
> ibmphp_debug = debug;
>
> - ibmphp_hpc_initvars();
> -
> for (i = 0; i < 16; i++)
> irqs[i] = 0;
>
> diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
> index 752c384cbd4c..508a62a6b5f9 100644
> --- a/drivers/pci/hotplug/ibmphp_hpc.c
> +++ b/drivers/pci/hotplug/ibmphp_hpc.c
> @@ -15,13 +15,13 @@
>
> #include <linux/wait.h>
> #include <linux/time.h>
> +#include <linux/completion.h>
> #include <linux/delay.h>
> #include <linux/module.h>
> #include <linux/pci.h>
> #include <linux/init.h>
> #include <linux/mutex.h>
> #include <linux/sched.h>
> -#include <linux/semaphore.h>
> #include <linux/kthread.h>
> #include "ibmphp.h"
>
> @@ -88,10 +88,10 @@ static int to_debug = 0;
> //----------------------------------------------------------------------------
> // global variables
> //----------------------------------------------------------------------------
> -static struct mutex sem_hpcaccess; // lock access to HPC
> -static struct semaphore semOperations; // lock all operations and
> +static DEFINE_MUTEX(sem_hpcaccess); // lock access to HPC
> +static DEFINE_MUTEX(operations_mutex); // lock all operations and
> // access to data structures
> -static struct semaphore sem_exit; // make sure polling thread goes away
> +static DECLARE_COMPLETION(exit_complete); // make sure polling thread goes away
> static struct task_struct *ibmphp_poll_thread;
> //----------------------------------------------------------------------------
> // local function prototypes
> @@ -109,23 +109,6 @@ static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8
> //----------------------------------------------------------------------------
>
>
> -/*----------------------------------------------------------------------
> -* Name: ibmphp_hpc_initvars
> -*
> -* Action: initialize semaphores and variables
> -*---------------------------------------------------------------------*/
> -void __init ibmphp_hpc_initvars(void)
> -{
> - debug("%s - Entry\n", __func__);
> -
> - mutex_init(&sem_hpcaccess);
> - sema_init(&semOperations, 1);
> - sema_init(&sem_exit, 0);
> - to_debug = 0;
> -
> - debug("%s - Exit\n", __func__);
> -}
> -
> /*----------------------------------------------------------------------
> * Name: i2c_ctrl_read
> *
> @@ -780,7 +763,7 @@ void free_hpc_access(void)
> *---------------------------------------------------------------------*/
> void ibmphp_lock_operations(void)
> {
> - down(&semOperations);
> + mutex_lock(&operations_mutex);
> to_debug = 1;
> }
>
> @@ -790,7 +773,7 @@ void ibmphp_lock_operations(void)
> void ibmphp_unlock_operations(void)
> {
> debug("%s - Entry\n", __func__);
> - up(&semOperations);
> + mutex_unlock(&operations_mutex);
> to_debug = 0;
> debug("%s - Exit\n", __func__);
> }
> @@ -816,7 +799,7 @@ static int poll_hpc(void *data)
>
> while (!kthread_should_stop()) {
> /* try to get the lock to do some kind of hardware access */
> - down(&semOperations);
> + mutex_lock(&operations_mutex);
>
> switch (poll_state) {
> case POLL_LATCH_REGISTER:
> @@ -871,13 +854,13 @@ static int poll_hpc(void *data)
> break;
> case POLL_SLEEP:
> /* don't sleep with a lock on the hardware */
> - up(&semOperations);
> + mutex_unlock(&operations_mutex);
> msleep(POLL_INTERVAL_SEC * 1000);
>
> if (kthread_should_stop())
> goto out_sleep;
>
> - down(&semOperations);
> + mutex_lock(&operations_mutex);
>
> if (poll_count >= POLL_LATCH_CNT) {
> poll_count = 0;
> @@ -887,12 +870,12 @@ static int poll_hpc(void *data)
> break;
> }
> /* give up the hardware semaphore */
> - up(&semOperations);
> + mutex_unlock(&operations_mutex);
> /* sleep for a short time just for good measure */
> out_sleep:
> msleep(100);
> }
> - up(&sem_exit);
> + complete(&exit_complete);
> debug("%s - Exit\n", __func__);
> return 0;
> }
> @@ -1060,9 +1043,9 @@ void __exit ibmphp_hpc_stop_poll_thread(void)
> debug("after locking operations\n");
>
> // wait for poll thread to exit
> - debug("before sem_exit down\n");
> - down(&sem_exit);
> - debug("after sem_exit down\n");
> + debug("before exit_complete down\n");
> + wait_for_completion(&exit_complete);
> + debug("after exit_completion down\n");
>
> // cleanup
> debug("before free_hpc_access\n");
> @@ -1070,8 +1053,6 @@ void __exit ibmphp_hpc_stop_poll_thread(void)
> debug("after free_hpc_access\n");
> ibmphp_unlock_operations();
> debug("after unlock operations\n");
> - up(&sem_exit);
> - debug("after sem exit up\n");
>
> debug("%s - Exit\n", __func__);
> }
> --
> 2.20.0
>
prev parent reply other threads:[~2019-01-29 23:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 21:49 [PATCH] pci: ibmphp_hpc: turn semaphores into completions or mutexes Arnd Bergmann
2019-01-29 23:16 ` Bjorn Helgaas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190129231658.GH91506@google.com \
--to=helgaas@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=rafael.j.wysocki@intel.com \
--cc=tyreld@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.