All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] smartpqi: Remove semaphores
@ 2016-10-20  8:54 Binoy Jayan
  2016-10-20  8:54 ` [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex Binoy Jayan
  2016-10-20  8:54 ` [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem " Binoy Jayan
  0 siblings, 2 replies; 9+ messages in thread
From: Binoy Jayan @ 2016-10-20  8:54 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen
  Cc: kevin Barnett, Don Brace, Scott Benesh, Johannes Thumshirn,
	linux-scsi, Arnd Bergmann, linux-kernel, Binoy Jayan

Hi,

The following are a set of patches which removes semaphores from 
scsi/smartpqi. These are part of a bigger effort to eliminate all
semaphores from the linux kernel.

Thanks,
Binoy

Binoy Jayan (2):
  scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  scsi: smartpqi: Replace semaphore lun_reset_sem with mutex

 drivers/scsi/smartpqi/smartpqi.h      |  6 ++++--
 drivers/scsi/smartpqi/smartpqi_init.c | 37 +++++++++--------------------------
 2 files changed, 13 insertions(+), 30 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-20  8:54 [PATCH 0/2] smartpqi: Remove semaphores Binoy Jayan
@ 2016-10-20  8:54 ` Binoy Jayan
  2016-10-20  9:06   ` Arnd Bergmann
  2016-10-20  9:10   ` Arnd Bergmann
  2016-10-20  8:54 ` [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem " Binoy Jayan
  1 sibling, 2 replies; 9+ messages in thread
From: Binoy Jayan @ 2016-10-20  8:54 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen
  Cc: kevin Barnett, Don Brace, Scott Benesh, Johannes Thumshirn,
	linux-scsi, Arnd Bergmann, linux-kernel, Binoy Jayan

Semaphores are going away in the future, so replace the semaphore
sync_request_sem with the a mutex lock. timeout_msecs is not used
for the lock sync_request_sem, so remove the timed locking too.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
 drivers/scsi/smartpqi/smartpqi.h      |  4 +++-
 drivers/scsi/smartpqi/smartpqi_init.c | 31 ++++++-------------------------
 2 files changed, 9 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h
index 07b6444..b4559b1 100644
--- a/drivers/scsi/smartpqi/smartpqi.h
+++ b/drivers/scsi/smartpqi/smartpqi.h
@@ -19,6 +19,8 @@
 #if !defined(_SMARTPQI_H)
 #define _SMARTPQI_H
 
+#include <linux/mutex.h>
+
 #pragma pack(1)
 
 #define PQI_DEVICE_SIGNATURE	"PQI DREG"
@@ -961,7 +963,7 @@ struct pqi_ctrl_info {
 	unsigned int	num_heartbeats_requested;
 	struct timer_list heartbeat_timer;
 
-	struct semaphore sync_request_sem;
+	struct mutex sync_request_mutex;
 	struct semaphore lun_reset_sem;
 };
 
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index a535b26..4974f7e 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -3444,29 +3444,11 @@ static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info,
 	unsigned long msecs_blocked;
 	size_t iu_length;
 
-	/*
-	 * Note that specifying PQI_SYNC_FLAGS_INTERRUPTABLE and a timeout value
-	 * are mutually exclusive.
-	 */
-
-	if (flags & PQI_SYNC_FLAGS_INTERRUPTABLE) {
-		if (down_interruptible(&ctrl_info->sync_request_sem))
+	if (flags & PQI_SYNC_FLAGS_INTERRUPTABLE)
+		if (mutex_lock_interruptible(&ctrl_info->sync_request_mutex))
 			return -ERESTARTSYS;
-	} else {
-		if (timeout_msecs == NO_TIMEOUT) {
-			down(&ctrl_info->sync_request_sem);
-		} else {
-			start_jiffies = jiffies;
-			if (down_timeout(&ctrl_info->sync_request_sem,
-				msecs_to_jiffies(timeout_msecs)))
-				return -ETIMEDOUT;
-			msecs_blocked =
-				jiffies_to_msecs(jiffies - start_jiffies);
-			if (msecs_blocked >= timeout_msecs)
-				return -ETIMEDOUT;
-			timeout_msecs -= msecs_blocked;
-		}
-	}
+	else
+		mutex_lock(&ctrl_info->sync_request_mutex);
 
 	io_request = pqi_alloc_io_request(ctrl_info);
 
@@ -3508,7 +3490,7 @@ static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info,
 
 	pqi_free_io_request(io_request);
 
-	up(&ctrl_info->sync_request_sem);
+	mutex_unlock(&ctrl_info->sync_request_mutex);
 
 	return rc;
 }
@@ -5540,8 +5522,7 @@ static struct pqi_ctrl_info *pqi_alloc_ctrl_info(int numa_node)
 	INIT_DELAYED_WORK(&ctrl_info->rescan_work, pqi_rescan_worker);
 	INIT_DELAYED_WORK(&ctrl_info->update_time_work, pqi_update_time_worker);
 
-	sema_init(&ctrl_info->sync_request_sem,
-		PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS);
+	mutex_init(&ctrl_info->sync_request_mutex);
 	sema_init(&ctrl_info->lun_reset_sem, PQI_RESERVED_IO_SLOTS_LUN_RESET);
 
 	ctrl_info->ctrl_id = atomic_inc_return(&pqi_controller_count) - 1;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem with mutex
  2016-10-20  8:54 [PATCH 0/2] smartpqi: Remove semaphores Binoy Jayan
  2016-10-20  8:54 ` [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex Binoy Jayan
@ 2016-10-20  8:54 ` Binoy Jayan
  2016-10-20  9:08   ` Arnd Bergmann
  1 sibling, 1 reply; 9+ messages in thread
From: Binoy Jayan @ 2016-10-20  8:54 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen
  Cc: kevin Barnett, Don Brace, Scott Benesh, Johannes Thumshirn,
	linux-scsi, Arnd Bergmann, linux-kernel, Binoy Jayan

Semaphores are going away in the future, so replace the semaphore
lun_reset_sem with the a mutex lock.

Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
---
 drivers/scsi/smartpqi/smartpqi.h      | 2 +-
 drivers/scsi/smartpqi/smartpqi_init.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h
index b4559b1..3ecec27 100644
--- a/drivers/scsi/smartpqi/smartpqi.h
+++ b/drivers/scsi/smartpqi/smartpqi.h
@@ -964,7 +964,7 @@ struct pqi_ctrl_info {
 	struct timer_list heartbeat_timer;
 
 	struct mutex sync_request_mutex;
-	struct semaphore lun_reset_sem;
+	struct mutex lun_reset_mutex;
 };
 
 enum pqi_ctrl_mode {
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 4974f7e..1e5df85 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -4601,7 +4601,7 @@ static int pqi_lun_reset(struct pqi_ctrl_info *ctrl_info,
 	DECLARE_COMPLETION_ONSTACK(wait);
 	struct pqi_task_management_request *request;
 
-	down(&ctrl_info->lun_reset_sem);
+	mutex_lock(&ctrl_info->lun_reset_mutex);
 
 	io_request = pqi_alloc_io_request(ctrl_info);
 	io_request->io_complete_callback = pqi_lun_reset_complete;
@@ -4627,7 +4627,7 @@ static int pqi_lun_reset(struct pqi_ctrl_info *ctrl_info,
 		rc = io_request->status;
 
 	pqi_free_io_request(io_request);
-	up(&ctrl_info->lun_reset_sem);
+	mutex_unlock(&ctrl_info->lun_reset_mutex);
 
 	return rc;
 }
@@ -5523,7 +5523,7 @@ static struct pqi_ctrl_info *pqi_alloc_ctrl_info(int numa_node)
 	INIT_DELAYED_WORK(&ctrl_info->update_time_work, pqi_update_time_worker);
 
 	mutex_init(&ctrl_info->sync_request_mutex);
-	sema_init(&ctrl_info->lun_reset_sem, PQI_RESERVED_IO_SLOTS_LUN_RESET);
+	mutex_init(&ctrl_info->lun_reset_mutex);
 
 	ctrl_info->ctrl_id = atomic_inc_return(&pqi_controller_count) - 1;
 	ctrl_info->max_msix_vectors = PQI_MAX_MSIX_VECTORS;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-20  8:54 ` [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex Binoy Jayan
@ 2016-10-20  9:06   ` Arnd Bergmann
  2016-10-24 10:04     ` Binoy Jayan
  2016-10-20  9:10   ` Arnd Bergmann
  1 sibling, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2016-10-20  9:06 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	linux-kernel

On Thursday, October 20, 2016 2:24:01 PM CEST Binoy Jayan wrote:
> Semaphores are going away in the future, so replace the semaphore
> sync_request_sem with the a mutex lock. timeout_msecs is not used
> for the lock sync_request_sem, so remove the timed locking too.
> 
> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>

The patch looks correct to me, but I think if you remove the support
for handling timeouts, you should update the prototype of
pqi_submit_raid_request_synchronous to no longer pass the timeout
argument in the first place.

	Arnd

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem with mutex
  2016-10-20  8:54 ` [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem " Binoy Jayan
@ 2016-10-20  9:08   ` Arnd Bergmann
  0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-10-20  9:08 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	linux-kernel

On Thursday, October 20, 2016 2:24:02 PM CEST Binoy Jayan wrote:
> Semaphores are going away in the future, so replace the semaphore
> lun_reset_sem with the a mutex lock.
> 
> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
> 

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-20  8:54 ` [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex Binoy Jayan
  2016-10-20  9:06   ` Arnd Bergmann
@ 2016-10-20  9:10   ` Arnd Bergmann
  2016-10-24 10:09     ` Binoy Jayan
  1 sibling, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2016-10-20  9:10 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	linux-kernel

On Thursday, October 20, 2016 2:24:01 PM CEST Binoy Jayan wrote:
> -       sema_init(&ctrl_info->sync_request_sem,
> -               PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS);
> +       mutex_init(&ctrl_info->sync_request_mutex);
> 

Looking at this again, I see that PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS
is '3', so this is in fact a counting semaphore rather than a mutex,
and the conversion is changing the behavior.

The patch can't go in unless you either show that it should be
a normal mutex rather than a counting semaphore, or you find a way
to keep the behavior the same.

	Arnd

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-20  9:06   ` Arnd Bergmann
@ 2016-10-24 10:04     ` Binoy Jayan
  2016-10-24 10:10       ` Arnd Bergmann
  0 siblings, 1 reply; 9+ messages in thread
From: Binoy Jayan @ 2016-10-24 10:04 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	Linux kernel mailing list

Hi Arnd

On 20 October 2016 at 14:36, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday, October 20, 2016 2:24:01 PM CEST Binoy Jayan wrote:
>> Semaphores are going away in the future, so replace the semaphore
>> sync_request_sem with the a mutex lock. timeout_msecs is not used
>> for the lock sync_request_sem, so remove the timed locking too.
>>
>> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
>
> The patch looks correct to me, but I think if you remove the support
> for handling timeouts, you should update the prototype of
> pqi_submit_raid_request_synchronous to no longer pass the timeout
> argument in the first place.

But we still need "timeout_msecs" in a call to
pqi_submit_raid_request_synchronous_with_io_request()

drivers/scsi/smartpqi/smartpqi_init.c +3484

-Binoy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-20  9:10   ` Arnd Bergmann
@ 2016-10-24 10:09     ` Binoy Jayan
  0 siblings, 0 replies; 9+ messages in thread
From: Binoy Jayan @ 2016-10-24 10:09 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	Linux kernel mailing list

On 20 October 2016 at 14:40, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday, October 20, 2016 2:24:01 PM CEST Binoy Jayan wrote:
>> -       sema_init(&ctrl_info->sync_request_sem,
>> -               PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS);
>> +       mutex_init(&ctrl_info->sync_request_mutex);
>>
>
> Looking at this again, I see that PQI_RESERVED_IO_SLOTS_SYNCHRONOUS_REQUESTS
> is '3', so this is in fact a counting semaphore rather than a mutex,
> and the conversion is changing the behavior.
>
> The patch can't go in unless you either show that it should be
> a normal mutex rather than a counting semaphore, or you find a way
> to keep the behavior the same.

This still holds true, will try changing this accordingly.

-Binoy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex
  2016-10-24 10:04     ` Binoy Jayan
@ 2016-10-24 10:10       ` Arnd Bergmann
  0 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2016-10-24 10:10 UTC (permalink / raw)
  To: Binoy Jayan
  Cc: James E.J. Bottomley, Martin K. Petersen, kevin Barnett,
	Don Brace, Scott Benesh, Johannes Thumshirn, linux-scsi,
	Linux kernel mailing list

On Monday, October 24, 2016 3:34:27 PM CEST Binoy Jayan wrote:
> Hi Arnd
> 
> On 20 October 2016 at 14:36, Arnd Bergmann <arnd@arndb.de> wrote:
> > On Thursday, October 20, 2016 2:24:01 PM CEST Binoy Jayan wrote:
> >> Semaphores are going away in the future, so replace the semaphore
> >> sync_request_sem with the a mutex lock. timeout_msecs is not used
> >> for the lock sync_request_sem, so remove the timed locking too.
> >>
> >> Signed-off-by: Binoy Jayan <binoy.jayan@linaro.org>
> >
> > The patch looks correct to me, but I think if you remove the support
> > for handling timeouts, you should update the prototype of
> > pqi_submit_raid_request_synchronous to no longer pass the timeout
> > argument in the first place.
> 
> But we still need "timeout_msecs" in a call to
> pqi_submit_raid_request_synchronous_with_io_request()
> 
> drivers/scsi/smartpqi/smartpqi_init.c +3484

Why? If it's always zero, we can remove that too.

	Arnd

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-10-24 10:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-20  8:54 [PATCH 0/2] smartpqi: Remove semaphores Binoy Jayan
2016-10-20  8:54 ` [PATCH 1/2] scsi: smartpqi: Replace semaphore sync_request_sem with mutex Binoy Jayan
2016-10-20  9:06   ` Arnd Bergmann
2016-10-24 10:04     ` Binoy Jayan
2016-10-24 10:10       ` Arnd Bergmann
2016-10-20  9:10   ` Arnd Bergmann
2016-10-24 10:09     ` Binoy Jayan
2016-10-20  8:54 ` [PATCH 2/2] scsi: smartpqi: Replace semaphore lun_reset_sem " Binoy Jayan
2016-10-20  9:08   ` Arnd Bergmann

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.