Skip to contentSkip to conversation

remoteproc: Create a separate workqueue for recovery tasks

PATCH In review Rishabh Bhatnagar 3 participants 7 messages Dec 12, 2020 – Jan 8, 2021 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: Create a separate workqueue for recovery tasks

Create an unbound high priority workqueue for recovery tasks. Recovery time is an important parameter for a subsystem and there might be situations where multiple subsystems crash around the same time. Scheduling into an unbound workqueue increases parallelization and avoids time impact. Also creating a high priority workqueue will utilize separate worker threads with higher nice values than normal ones.

---
 drivers/remoteproc/remoteproc_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +8 -1
index 46c2937..8fd8166 100644
@@ -48,6 +48,8 @@ static DEFINE_MUTEX(rproc_list_mutex);
 static LIST_HEAD(rproc_list);
 static struct notifier_block rproc_panic_nb;
 
+static struct workqueue_struct *rproc_wq;
+
 typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
 				 void *, int offset, int avail);
 
@@ -2475,7 +2477,7 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
 		rproc->name, rproc_crash_to_string(type));
 
 	/* create a new task to handle the error */
-	schedule_work(&rproc->crash_handler);
+	queue_work(rproc_wq, &rproc->crash_handler);
 }
 EXPORT_SYMBOL(rproc_report_crash);
 
@@ -2520,6 +2522,10 @@ static void __exit rproc_exit_panic(void)
 
 static int __init remoteproc_init(void)
 {
+	rproc_wq = alloc_workqueue("rproc_wq", WQ_UNBOUND | WQ_HIGHPRI, 0);
+	if (!rproc_wq)
+		return -ENOMEM;
+
 	rproc_init_sysfs();
 	rproc_init_debugfs();
 	rproc_init_cdev();
@@ -2536,6 +2542,7 @@ static void __exit remoteproc_exit(void)
 	rproc_exit_panic();
 	rproc_exit_debugfs();
 	rproc_exit_sysfs();
+	destroy_workqueue(rproc_wq);
 }
 module_exit(remoteproc_exit);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

This simply repeats $subject

Quoted 4 lines

Recovery time is an important parameter for a subsystem and there might be situations where multiple subsystems crash around the same time. Scheduling into an unbound workqueue increases parallelization and avoids time impact.

You should be able to write this more succinctly. The important part is that you want an unbound work queue to allow recovery to happen in parallel - which naturally implies that you care about recovery latency.

Quoted 4 lines

Also creating a high priority workqueue
will utilize separate worker threads with higher nice values than normal ones.

This doesn't describe why you need the higher priority.

I believe, and certainly with the in-line coredump, that we're running our recovery work for way too long to be queued on the system_wq. As such the content of the patch looks good!

Regards,
Bjorn

Quoted 50 lines
---
 drivers/remoteproc/remoteproc_core.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +8 -1
index 46c2937..8fd8166 100644
@@ -48,6 +48,8 @@ static DEFINE_MUTEX(rproc_list_mutex);
 static LIST_HEAD(rproc_list);
 static struct notifier_block rproc_panic_nb;
 
+static struct workqueue_struct *rproc_wq;
+
 typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
 				 void *, int offset, int avail);
 
@@ -2475,7 +2477,7 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
 		rproc->name, rproc_crash_to_string(type));
 
 	/* create a new task to handle the error */
-	schedule_work(&rproc->crash_handler);
+	queue_work(rproc_wq, &rproc->crash_handler);
 }
 EXPORT_SYMBOL(rproc_report_crash);
 
@@ -2520,6 +2522,10 @@ static void __exit rproc_exit_panic(void)
 
 static int __init remoteproc_init(void)
 {
+	rproc_wq = alloc_workqueue("rproc_wq", WQ_UNBOUND | WQ_HIGHPRI, 0);
+	if (!rproc_wq)
+		return -ENOMEM;
+
 	rproc_init_sysfs();
 	rproc_init_debugfs();
 	rproc_init_cdev();
@@ -2536,6 +2542,7 @@ static void __exit remoteproc_exit(void)
 	rproc_exit_panic();
 	rproc_exit_debugfs();
 	rproc_exit_sysfs();
+	destroy_workqueue(rproc_wq);
 }
 module_exit(remoteproc_exit);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
Quoted 3 lines · Bjorn Andersson
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

I have been looking at a different issue that is caused by crash notification.

What happened was that the modem crashed while the AP was in system suspend (or possibly even resuming) state. And there is no guarantee that the system will have called a driver's ->resume callback when the crash notification is delivered.

In my case (in the IPA driver), handling a modem crash cannot be done while the driver is suspended; i.e. the activities in its ->resume callback must be completed before we can recover from the crash.

For this reason I might like to change the way the crash notification is handled, but what I'd rather see is to have the work queue not run until user space is unfrozen, which would guarantee that all drivers that have registered for a crash notification will be resumed when the notification arrives.

I'm not sure how that interacts with what you are looking for here. I think the workqueue could still be unbound, but its work would be delayed longer before any notification (and recovery) started.

-Alex

Quoted 76 lines

This simply repeats $subject

Quoted 4 lines

Recovery time is an important parameter for a subsystem and there might be situations where multiple subsystems crash around the same time. Scheduling into an unbound workqueue increases parallelization and avoids time impact.

You should be able to write this more succinctly. The important part is that you want an unbound work queue to allow recovery to happen in parallel - which naturally implies that you care about recovery latency.

Quoted 4 lines

Also creating a high priority workqueue
will utilize separate worker threads with higher nice values than normal ones.

This doesn't describe why you need the higher priority.

I believe, and certainly with the in-line coredump, that we're running our recovery work for way too long to be queued on the system_wq. As such the content of the patch looks good!

Regards,
Bjorn

Quoted 50 lines
---
  drivers/remoteproc/remoteproc_core.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +8 -1
index 46c2937..8fd8166 100644
@@ -48,6 +48,8 @@ static DEFINE_MUTEX(rproc_list_mutex);
  static LIST_HEAD(rproc_list);
  static struct notifier_block rproc_panic_nb;
 
+static struct workqueue_struct *rproc_wq;
+
  typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
  				 void *, int offset, int avail);
 
@@ -2475,7 +2477,7 @@ void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type)
  		rproc->name, rproc_crash_to_string(type));
 
  	/* create a new task to handle the error */
-	schedule_work(&rproc->crash_handler);
+	queue_work(rproc_wq, &rproc->crash_handler);
  }
  EXPORT_SYMBOL(rproc_report_crash);
 
@@ -2520,6 +2522,10 @@ static void __exit rproc_exit_panic(void)
 
  static int __init remoteproc_init(void)
  {
+	rproc_wq = alloc_workqueue("rproc_wq", WQ_UNBOUND | WQ_HIGHPRI, 0);
+	if (!rproc_wq)
+		return -ENOMEM;
+
  	rproc_init_sysfs();
  	rproc_init_debugfs();
  	rproc_init_cdev();
@@ -2536,6 +2542,7 @@ static void __exit remoteproc_exit(void)
  	rproc_exit_panic();
  	rproc_exit_debugfs();
  	rproc_exit_sysfs();
+	destroy_workqueue(rproc_wq);
  }
  module_exit(remoteproc_exit);
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw
Quoted 26 lines · Alex Elder
Quoted 3 lines · Bjorn Andersson
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

I have been looking at a different issue that is caused by crash notification.

What happened was that the modem crashed while the AP was in system suspend (or possibly even resuming) state. And there is no guarantee that the system will have called a driver's ->resume callback when the crash notification is delivered.

In my case (in the IPA driver), handling a modem crash cannot be done while the driver is suspended; i.e. the activities in its ->resume callback must be completed before we can recover from the crash.

For this reason I might like to change the way the crash notification is handled, but what I'd rather see is to have the work queue not run until user space is unfrozen, which would guarantee that all drivers that have registered for a crash notification will be resumed when the notification arrives.

Quoted 8 lines

I'm not sure how that interacts with what you are looking for here. I think the workqueue could still be unbound, but its work would be delayed longer before any notification (and recovery) started.

-Alex

In that case, maybe adding a "WQ_FREEZABLE" flag might help?

Quoted 72 lines
Quoted 72 lines

This simply repeats $subject

Quoted 4 lines

Recovery time is an important parameter for a subsystem and there might be situations where multiple subsystems crash around the same time. Scheduling into an unbound workqueue increases parallelization and avoids time impact.

You should be able to write this more succinctly. The important part is that you want an unbound work queue to allow recovery to happen in parallel - which naturally implies that you care about recovery latency.

Quoted 4 lines

Also creating a high priority workqueue
will utilize separate worker threads with higher nice values than normal ones.

This doesn't describe why you need the higher priority.

I believe, and certainly with the in-line coredump, that we're running our recovery work for way too long to be queued on the system_wq. As such the content of the patch looks good!

Regards,
Bjorn

Quoted 45 lines
---
  drivers/remoteproc/remoteproc_core.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +1 -0
index 46c2937..8fd8166 100644
@@ -48,6 +48,8 @@ static DEFINE_MUTEX(rproc_list_mutex);
  static LIST_HEAD(rproc_list);
  static struct notifier_block rproc_panic_nb;
  +static struct workqueue_struct *rproc_wq;
+
  typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
  				 void *, int offset, int avail);
  @@ -2475,7 +2477,7 @@ void rproc_report_crash(struct rproc *rproc, 

enum rproc_crash_type type)

  		rproc->name, rproc_crash_to_string(type));
    	/* create a new task to handle the error */
drivers/remoteproc/remoteproc_core.c +6 -1
-	schedule_work(&rproc->crash_handler);
+	queue_work(rproc_wq, &rproc->crash_handler);
  }
  EXPORT_SYMBOL(rproc_report_crash);
  @@ -2520,6 +2522,10 @@ static void __exit rproc_exit_panic(void)
    static int __init remoteproc_init(void)
  {
+	rproc_wq = alloc_workqueue("rproc_wq", WQ_UNBOUND | WQ_HIGHPRI, 0);
+	if (!rproc_wq)
+		return -ENOMEM;
+
  	rproc_init_sysfs();
  	rproc_init_debugfs();
  	rproc_init_cdev();
@@ -2536,6 +2542,7 @@ static void __exit remoteproc_exit(void)
  	rproc_exit_panic();
  	rproc_exit_debugfs();
  	rproc_exit_sysfs();
+	destroy_workqueue(rproc_wq);
  }
  module_exit(remoteproc_exit);
  -- The Qualcomm Innovation Center, Inc. is a member of the Code 

Aurora Forum,
a Linux Foundation Collaborative Project

#4 lore raw
Quoted 32 lines · On 12/17/20 12:21 PM, [email protected] wrote:
Quoted 31 lines · Alex Elder
Quoted 3 lines · Bjorn Andersson
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

I have been looking at a different issue that is caused by crash notification.

What happened was that the modem crashed while the AP was in system suspend (or possibly even resuming) state.  And there is no guarantee that the system will have called a driver's ->resume callback when the crash notification is delivered.

In my case (in the IPA driver), handling a modem crash cannot be done while the driver is suspended; i.e. the activities in its ->resume callback must be completed before we can recover from the crash.

For this reason I might like to change the way the crash notification is handled, but what I'd rather see is to have the work queue not run until user space is unfrozen, which would guarantee that all drivers that have registered for a crash notification will be resumed when the notification arrives.

I'm not sure how that interacts with what you are looking for here.  I think the workqueue could still be unbound, but its work would be delayed longer before any notification (and recovery) started.

Quoted 4 lines
Quoted 3 lines

                    -Alex

In that case, maybe adding a "WQ_FREEZABLE" flag might help?

Yes, exactly. But how does that affect whatever you were trying to do with your patch?

-Alex

. . .

#5 lore raw
Quoted 33 lines · Alex Elder
Quoted 32 lines · On 12/17/20 12:21 PM, [email protected] wrote:
Quoted 31 lines · Alex Elder
Quoted 3 lines · Bjorn Andersson
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

I have been looking at a different issue that is caused by crash notification.

What happened was that the modem crashed while the AP was in system suspend (or possibly even resuming) state.  And there is no guarantee that the system will have called a driver's ->resume callback when the crash notification is delivered.

In my case (in the IPA driver), handling a modem crash cannot be done while the driver is suspended; i.e. the activities in its ->resume callback must be completed before we can recover from the crash.

For this reason I might like to change the way the crash notification is handled, but what I'd rather see is to have the work queue not run until user space is unfrozen, which would guarantee that all drivers that have registered for a crash notification will be resumed when the notification arrives.

I'm not sure how that interacts with what you are looking for here.  I think the workqueue could still be unbound, but its work would be delayed longer before any notification (and recovery) started.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

                    -Alex

In that case, maybe adding a "WQ_FREEZABLE" flag might help?

Yes, exactly. But how does that affect whatever you were trying to do with your patch?

I don't see any impact on Rishabh's change in particular, syntactically it would just be a matter of adding another flag and the impact would be separate from his patch.

In other words, creating a separate work queue to get the long running work off the system_wq and making sure that these doesn't run during suspend & resume seems very reasonable to me.

The one piece that I'm still contemplating is the HIPRIO, I would like to better understand the actual impact - or perhaps is this a result of everyone downstream moving all their work to HIPRIO work queues, starving the recovery?

Regards,
Bjorn

#6 lore raw
Quoted 48 lines · Bjorn Andersson
Quoted 33 lines · Alex Elder
Quoted 32 lines · On 12/17/20 12:21 PM, [email protected] wrote:
Quoted 31 lines · Alex Elder
Quoted 3 lines · Bjorn Andersson
Quoted 1 line · Rishabh Bhatnagar

Create an unbound high priority workqueue for recovery tasks.

I have been looking at a different issue that is caused by crash notification.

What happened was that the modem crashed while the AP was in system suspend (or possibly even resuming) state.  And there is no guarantee that the system will have called a driver's ->resume callback when the crash notification is delivered.

In my case (in the IPA driver), handling a modem crash cannot be done while the driver is suspended; i.e. the activities in its ->resume callback must be completed before we can recover from the crash.

For this reason I might like to change the way the crash notification is handled, but what I'd rather see is to have the work queue not run until user space is unfrozen, which would guarantee that all drivers that have registered for a crash notification will be resumed when the notification arrives.

I'm not sure how that interacts with what you are looking for here.  I think the workqueue could still be unbound, but its work would be delayed longer before any notification (and recovery) started.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

                    -Alex

In that case, maybe adding a "WQ_FREEZABLE" flag might help?

Yes, exactly. But how does that affect whatever you were trying to do with your patch?

I don't see any impact on Rishabh's change in particular, syntactically it would just be a matter of adding another flag and the impact would be separate from his patch.

Quoted 9 lines

In other words, creating a separate work queue to get the long running work off the system_wq and making sure that these doesn't run during suspend & resume seems very reasonable to me.

The one piece that I'm still contemplating is the HIPRIO, I would like to better understand the actual impact - or perhaps is this a result of everyone downstream moving all their work to HIPRIO work queues, starving the recovery?

Hi Bjorn,
You are right, this is a result of downstream having HIPRIO workqueues therefore starving recovery. I don't have actual data to support the flag as of now. If needed for now we can skip this flag and add it later with sufficient data?

Quoted 2 lines

Regards,
Bjorn