Skip to contentSkip to conversation

drivers:soc:fsl:qbman:qman.c: Sleep instead of stuck hacking jiffies.

PATCH Superseded Karim Eshapa 4 participants 12 messages Apr 29, 2017 – Jun 27, 2017 Freescale SoC drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers:soc:fsl:qbman:qman.c: Sleep instead of stuck hacking jiffies.

Convert the jiffies into usecs then use it with usleep_range such that instead of stuck doing nothing until action happens, sleep with range improves responsiveness and power usage and avoid hacking jiffies. it's used for approximate time. You can check /kernel/time/timer.c.

---
 drivers/soc/fsl/qbman/qman.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/soc/fsl/qbman/qman.c +2 -4
index 6f509f6..e0df4d1 100644
@@ -1084,11 +1084,9 @@ static int drain_mr_fqrni(struct qm_portal *p)
 		 * entries well before the ring has been fully consumed, so
 		 * we're being *really* paranoid here.
 		 */
-		u64 now, then = jiffies;
+		unsigned int udel_time = jiffies_to_usecs(10000);
 
-		do {
-			now = jiffies;
-		} while ((then + 10000) > now);
+		usleep_range(udel_time/2, udel_time);
 		msg = qm_mr_current(p);
 		if (!msg)
 			return 0;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 drivers:soc:fsl:qbman:qman.c: unsigned long jiffies value.

unsigned long jiffies value sorry for that.

---
 drivers/soc/fsl/qbman/qman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/fsl/qbman/qman.c +1 -1
index e0df4d1..6e1a44a 100644
@@ -1084,7 +1084,7 @@ static int drain_mr_fqrni(struct qm_portal *p)
 		 * entries well before the ring has been fully consumed, so
 		 * we're being *really* paranoid here.
 		 */
-		unsigned int udel_time = jiffies_to_usecs(10000);
+		unsigned long udel_time = jiffies_to_usecs(10000);
 
 		usleep_range(udel_time/2, udel_time);
 		msg = qm_mr_current(p);
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH] drivers:soc:fsl:qbman:qman.c: unsigned long jiffies value.

Quoted 1 line · Karim Eshapa

unsigned long jiffies value sorry for that.

You mean unsigned long msecs?

Quoted 16 lines

---
?drivers/soc/fsl/qbman/qman.c | 2 +-
?1 file changed, 1 insertion(+), 1 deletion(-)

drivers/soc/fsl/qbman/qman.c +0 -0
index e0df4d1..6e1a44a 100644
@@ -1084,7 +1084,7 @@ static int drain_mr_fqrni(struct qm_portal *p)

? ?* entries well before the ring has been fully consumed, so
? ?* we're being *really* paranoid here.
? ?*/

drivers/soc/fsl/qbman/qman.c +1 -1
-		unsigned int udel_time = jiffies_to_usecs(10000);
+		unsigned long udel_time = jiffies_to_usecs(10000);
Quoted 3 lines

?
? usleep_range(udel_time/2, udel_time);
? msg = qm_mr_current(p);

If unsigned int isn't big enough, then unsigned long won't be either on 32- bit. With such a long delay why not use msleep()?

As for the previous patch[1], you're halving the minimum timeout which may not be correct.

For the NXP people: Is there *really* no better way to handle this than waiting for so long? Nothing that can be checked to exit the loop early (at least, you could exit early if there is more work to do so only the final iteration takes the full timeout)? And why is the desired timeout specified in jiffies, the duration of which can change based on kernel config and doesn't reflect anything about the hardware?

-Scott

[1] When fixing a patch you've already posted that hasn't yet been applied, send a replacement (v2) patch rather than a separate fix.

#3 lore raw

RE:drivers:soc:fsl:qbman:qman.c: unsigned long jiffies value

Quoted 6 lines · Scott Wood
Quoted 2 lines · Karim Eshapa

unsigned long jiffies value sorry for that.

You mean unsigned long msecs?

Yes, I mean usecs.

Quoted 17 lines
Quoted 17 lines
---
 drivers/soc/fsl/qbman/qman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/fsl/qbman/qman.c +1 -1
index e0df4d1..6e1a44a 100644
@@ -1084,7 +1084,7 @@ static int drain_mr_fqrni(struct qm_portal *p)
               * entries well before the ring has been fully consumed, so
               * we're being *really* paranoid here.
               */
-             unsigned int udel_time = jiffies_to_usecs(10000);
+             unsigned long udel_time = jiffies_to_usecs(10000);
 
Quoted 6 lines

drivers/soc/fsl/qbman/qman.c static int drain_mr_fqrni(struct qm_portal *p) · line 1090

Quoted 2 lines
drivers/soc/fsl/qbman/qman.c +0 -0
              usleep_range(udel_time/2, udel_time);
              msg = qm_mr_current(p);

If unsigned int isn't big enough, then unsigned long won't be either on 32- bit. With such a long delay why not use msleep()?

I agree with you in long int.
After looking at Documentation/timers/timers-howto.txt I think the msleep() is better as we actually have long delay.
may be we can use jiffies_to_msecs() with msleep() in case of we still have this large jiffies difference.

Quoted 4 lines

As for the previous patch[1], you're halving the minimum timeout which may not be correct.

For the minimum timeout, I've read the following comments.

/*
* if MR was full and h/w had other FQRNI entries to produce, we
* need to allow it time to produce those entries once the
* existing entries are consumed. A worst-case situation
* (fully-loaded system) means h/w sequencers may have to do 3-4
* other things before servicing the portal's MR pump, each of
* which (if slow) may take ~50 qman cycles (which is ~200
* processor cycles). So rounding up and then multiplying this
* worst-case estimate by a factor of 10, just to be
* ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
* one entry at a time, so h/w has an opportunity to produce new
* entries well before the ring has been fully consumed, so
* we're being *really* paranoid here.
*/
u64 now, then = jiffies;

do {
now = jiffies;
} while ((then + 10000) > now);

He needs to guarantee certain action so, he made a very large factor of saftey therefore I've used sleep in range with approximate delay. But we still need the driver owner to define appropriate value to put.

Quoted 3 lines

[1] When fixing a patch you've already posted that hasn't yet been applied, send a replacement (v2) patch rather than a separate fix.

Thanks so much, I'm just newbies :)

Karim

#4 lore raw

PATCH v2 1/1 drivers:soc:fsl:qbman:qman.c: Sleep instead of stuck hacking jiffies.

In reply to Scott Wood

Avoid stuck and hacking jiffies for a long time and using msleep() for certatin numeber of cylces without the factor of safety but using the the long delay considering the factor of safety with the while loop such that after msleep for a short period of time we check the msg if it's OK, breaking the big loop delay.

---
 drivers/soc/fsl/qbman/qman.c | 47 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)
drivers/soc/fsl/qbman/qman.c +24 -23
index 6f509f6..4f99298 100644
@@ -1067,32 +1067,33 @@ static irqreturn_t portal_isr(int irq, void *ptr)
 static int drain_mr_fqrni(struct qm_portal *p)
 {
 	const union qm_mr_entry *msg;
+	unsigned long stop;
+	unsigned int timeout = jiffies_to_msecs(1000);
 loop:
 	msg = qm_mr_current(p);
-	if (!msg) {
-		/*
-		 * if MR was full and h/w had other FQRNI entries to produce, we
-		 * need to allow it time to produce those entries once the
-		 * existing entries are consumed. A worst-case situation
-		 * (fully-loaded system) means h/w sequencers may have to do 3-4
-		 * other things before servicing the portal's MR pump, each of
-		 * which (if slow) may take ~50 qman cycles (which is ~200
-		 * processor cycles). So rounding up and then multiplying this
-		 * worst-case estimate by a factor of 10, just to be
-		 * ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
-		 * one entry at a time, so h/w has an opportunity to produce new
-		 * entries well before the ring has been fully consumed, so
-		 * we're being *really* paranoid here.
-		 */
-		u64 now, then = jiffies;
-
-		do {
-			now = jiffies;
-		} while ((then + 10000) > now);
+	stop = jiffies + 10000;
+	/*
+	 * if MR was full and h/w had other FQRNI entries to produce, we
+	 * need to allow it time to produce those entries once the
+	 * existing entries are consumed. A worst-case situation
+	 * (fully-loaded system) means h/w sequencers may have to do 3-4
+	 * other things before servicing the portal's MR pump, each of
+	 * which (if slow) may take ~50 qman cycles (which is ~200
+	 * processor cycles). So rounding up and then multiplying this
+	 * worst-case estimate by a factor of 10, just to be
+	 * ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
+	 * one entry at a time, so h/w has an opportunity to produce new
+	 * entries well before the ring has been fully consumed, so
+	 * we're being *really* paranoid here.
+	 */
+	do {
+		if (msg)
+			break;
+		msleep(timeout);
 		msg = qm_mr_current(p);
-		if (!msg)
-			return 0;
-	}
+	} while (time_before(jiffies, stop));
+	if (!msg)
+		return 0;
 	if ((msg->verb & QM_MR_VERB_TYPE_MASK) != QM_MR_VERB_FQRNI) {
 		/* We aren't draining anything but FQRNIs */
 		pr_err("Found verb 0x%x in MR\n", msg->verb);
Signature · 1 line
2.7.4
#5 lore raw
Quoted 5 lines · Karim Eshapa
(quoted diff) +5 -0
+	stop = jiffies + 10000;
+	/*
+	?* if MR was full and h/w had other FQRNI entries to produce, we
+	?* need to allow it time to produce those entries once the
+	?* existing entries are consumed. A worst-case situation

Review

Quoted 10 lines
(quoted diff) +10 -0
+	?* (fully-loaded system) means h/w sequencers may have to do 3-4
+	?* other things before servicing the portal's MR pump, each of
+	?* which (if slow) may take ~50 qman cycles (which is ~200
+	?* processor cycles). So rounding up and then multiplying this
+	?* worst-case estimate by a factor of 10, just to be
+	?* ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
+	?* one entry at a time, so h/w has an opportunity to produce new
+	?* entries well before the ring has been fully consumed, so
+	?* we're being *really* paranoid here.
+	?*/

OK, upon reading this more closely it seems the intent was to delay for 10,000 *processor cycles* and somehow that got turned into 10,000 jiffies (which is 40 seconds at the default Hz!). We could just replace this whole thing with msleep(1) and still be far more paranoid than was originally intended.

Claudiu and Roy, any comments?

-Scott

#6 lore raw
Quoted 21 lines · Scott Wood
Quoted 5 lines · Karim Eshapa
drivers/soc/fsl/qbman/qman.c +5 -0
+	stop = jiffies + 10000;
+	/*
+	 * if MR was full and h/w had other FQRNI entries to produce, we
+	 * need to allow it time to produce those entries once the
+	 * existing entries are consumed. A worst-case situation

drivers/soc/fsl/qbman/qman.c static irqreturn_t portal_isr(int irq, void *ptr) · line 1088

Quoted 10 lines
drivers/soc/fsl/qbman/qman.c +10 -0
+	 * (fully-loaded system) means h/w sequencers may have to do 3-4
+	 * other things before servicing the portal's MR pump, each of
+	 * which (if slow) may take ~50 qman cycles (which is ~200
+	 * processor cycles). So rounding up and then multiplying this
+	 * worst-case estimate by a factor of 10, just to be
+	 * ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
+	 * one entry at a time, so h/w has an opportunity to produce new
+	 * entries well before the ring has been fully consumed, so
+	 * we're being *really* paranoid here.
+	 */

OK, upon reading this more closely it seems the intent was to delay for 10,000 *processor cycles* and somehow that got turned into 10,000 jiffies (which is 40 seconds at the default Hz!). We could just replace this whole thing with msleep(1) and still be far more paranoid than was originally intended.

Quoted 1 line

Claudiu and Roy, any comments?

Yes the timing here is certainly off, the code changed a few times since the comment was originally written.
An msleep(1) seems reasonable here to me.

Roy

Quoted 4 lines

-Scott

#7 lore raw
In reply to Karim Eshapa

Use msleep() instead of stucking with
long delay will be more efficient.

---
 drivers/soc/fsl/qbman/qman.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/soc/fsl/qbman/qman.c +1 -5
index 3d891db..18d391e 100644
@@ -1084,11 +1084,7 @@ static int drain_mr_fqrni(struct qm_portal *p)
 		 * entries well before the ring has been fully consumed, so
 		 * we're being *really* paranoid here.
 		 */
-		u64 now, then = jiffies;
-
-		do {
-			now = jiffies;
-		} while ((then + 10000) > now);
+		msleep(1);
 		msg = qm_mr_current(p);
 		if (!msg)
 			return 0;
Signature · 1 line
2.7.4
#10 lore raw
In reply to Karim Eshapa
Quoted 22 lines · Scott Wood
Quoted 21 lines · Karim Eshapa
Quoted 5 lines
drivers/soc/fsl/qbman/qman.c +5 -0
+    stop = jiffies + 10000;
+    /*
+     * if MR was full and h/w had other FQRNI entries to produce, we
+     * need to allow it time to produce those entries once the
+     * existing entries are consumed. A worst-case situation

drivers/soc/fsl/qbman/qman.c static irqreturn_t portal_isr(int irq, void *ptr) · line 1088

Quoted 10 lines
drivers/soc/fsl/qbman/qman.c +10 -0
+     * (fully-loaded system) means h/w sequencers may have to do 3-4
+     * other things before servicing the portal's MR pump, each of
+     * which (if slow) may take ~50 qman cycles (which is ~200
+     * processor cycles). So rounding up and then multiplying this
+     * worst-case estimate by a factor of 10, just to be
+     * ultra-paranoid, goes as high as 10,000 cycles. NB, we consume
+     * one entry at a time, so h/w has an opportunity to produce new
+     * entries well before the ring has been fully consumed, so
+     * we're being *really* paranoid here.
+     */

OK, upon reading this more closely it seems the intent was to delay for 10,000 *processor cycles* and somehow that got turned into 10,000 jiffies (which is 40 seconds at the default Hz!). We could just replace this whole thing with msleep(1) and still be far more paranoid than was originally intended.

Quoted 4 lines
Quoted 1 line

Claudiu and Roy, any comments?

Yes the timing here is certainly off, the code changed a few times since the comment was originally written.
An msleep(1) seems reasonable here to me.

If the previous patch with msleep(1) is OK. can I send a patch to slightly change the comments.

Thanks,
Karim

#11 lore raw
Quoted 26 lines · Karim Eshapa
Quoted 26 lines · Scott Wood
Quoted 25 lines · Karim Eshapa
Quoted 7 lines

+????stop = jiffies + 10000;
+????/*
+?????* if MR was full and h/w had other FQRNI entries to produce, we +?????* need to allow it time to produce those entries once the +?????* existing entries are consumed. A worst-case situation +?????* (fully-loaded system) means h/w sequencers may have to do 3-4 +?????* other things before servicing the portal's MR pump, each of

Quoted 8 lines

+?????* which (if slow) may take ~50 qman cycles (which is ~200 +?????* processor cycles). So rounding up and then multiplying this +?????* worst-case estimate by a factor of 10, just to be +?????* ultra-paranoid, goes as high as 10,000 cycles. NB, we consume +?????* one entry at a time, so h/w has an opportunity to produce new +?????* entries well before the ring has been fully consumed, so +?????* we're being *really* paranoid here.
+?????*/

OK, upon reading this more closely it seems the intent was to delay for 10,000
*processor cycles* and somehow that got turned into 10,000 jiffies (which is
40 seconds at the default Hz!).??We could just replace this whole thing with
msleep(1) and still be far more paranoid than was originally intended.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Claudiu and Roy, any comments?

Yes the timing here is certainly off, the code changed a few times since the comment was originally written.
An msleep(1) seems reasonable here to me.

If the previous patch with msleep(1) is OK. can I send a patch to slightly change the comments.

Yes.

-Scott

#9 lore raw
Quoted 22 lines

-----Original Message-----
From: Scott Wood [mailto:oss at buserror.net]
Sent: Saturday, June 24, 2017 9:47 PM
To: Karim Eshapa <[email protected]>
Cc: Roy Pledge <[email protected]>; linux-kernel at vger.kernel.org; Claudiu Manoil <[email protected]>; colin.king at canonical.com; linuxppc-dev at lists.ozlabs.org; linux-arm-kernel at lists.infradead.org; Leo Li <[email protected]>
Subject: Re: [v3] drivers:soc:fsl:qbman:qman.c: Sleep instead of stuck hacking jiffies.

Quoted 7 lines · Karim Eshapa

Use msleep() instead of stucking with
long delay will be more efficient.

---
 drivers/soc/fsl/qbman/qman.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Quoted 5 lines

(though the subject line should be "soc/qman: ...")

Leo, are you going to send this patch (and other qman patches) via arm-soc?

Yes. I can take it through the pull request for soc/fsl via arm-soc. As mentioned in the feedback from David in another email, probably we should update the comment and commit message to mention how 10000 cycles becomes 1ms.

Regards,
Leo