Skip to contentSkip to conversation

lib: sbi: Optimize probe of srst/susp

PATCH Superseded Xiang W 2 participants 3 messages May 1, 2023 – May 2, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xiang W

author
#0 lore raw

PATCH v2 1/1 lib: sbi: Optimize probe of srst/susp

No need to do a fully comprehensive count, just find a supported reset or suspend type

---
V2: Add a similar optimization to susp as suggested by Andrew

 lib/sbi/sbi_ecall_srst.c |  7 ++++---
 lib/sbi/sbi_ecall_susp.c | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)
lib/sbi/sbi_ecall_srst.c +4 -3
index 93b012c..91059d7 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one standard reset types should be supported by
@@ -60,10 +60,11 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 	for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 		if (sbi_system_reset_supported(type,
 					SBI_SRST_RESET_REASON_NONE))
-			count++;
+			*out_val = 1;
+			return 0;
 	}
 
-	*out_val = (count) ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
lib/sbi/sbi_ecall_susp.c +6 -4
index f20126c..c8b8f64 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one suspend type should be supported by the
 	 * platform for the SBI SUSP extension to be usable.
 	 */
 	for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-		if (sbi_system_suspend_supported(type))
-			count++;
+		if (sbi_system_suspend_supported(type)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = count ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/1 lib: sbi: Optimize probe of srst/susp

Quoted 5 lines · Xiang W

No need to do a fully comprehensive count, just find a supported reset or suspend type

I didn't provide any tags in my review of v1 and, if I had, it would've been an r-b, not an s-o-b.

Quoted 21 lines

---
V2: Add a similar optimization to susp as suggested by Andrew

 lib/sbi/sbi_ecall_srst.c |  7 ++++---
 lib/sbi/sbi_ecall_susp.c | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)
lib/sbi/sbi_ecall_srst.c +1 -1
index 93b012c..91059d7 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one standard reset types should be supported by

lib/sbi/sbi_ecall_srst.c static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val) · line 64

Quoted 6 lines
lib/sbi/sbi_ecall_srst.c +2 -1
@@ -60,10 +60,11 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 	for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 		if (sbi_system_reset_supported(type,
 					SBI_SRST_RESET_REASON_NONE))
-			count++;
+			*out_val = 1;
+			return 0;

Missing {} around these two statements. Sorry I missed that in the v1 review. Seeing them added in the SUSP change below points it out.

Quoted 39 lines
lib/sbi/sbi_ecall_srst.c +1 -1
 	}
 
-	*out_val = (count) ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
lib/sbi/sbi_ecall_susp.c +6 -4
index f20126c..c8b8f64 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one suspend type should be supported by the
 	 * platform for the SBI SUSP extension to be usable.
 	 */
 	for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-		if (sbi_system_suspend_supported(type))
-			count++;
+		if (sbi_system_suspend_supported(type)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = count ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
Signature · 1 line
2.39.2

Otherwise,

Thanks,
drew

author
#2 lore raw

PATCH v2 1/1 lib: sbi: Optimize probe of srst/susp

? 2023-05-02???? 10:37 +0200?Andrew Jones???

Quoted 9 lines · Xiang W
Quoted 5 lines

No need to do a fully comprehensive count, just find a supported reset or suspend type

I didn't provide any tags in my review of v1 and, if I had, it would've been an r-b, not an s-o-b.

I thought your suggestion was constructive, so I took the liberty of using s-o-b. For that I apologize for the logo. Thanks for the review.

Thanks,
Xiang W

Quoted 78 lines
Quoted 22 lines

---
V2: Add a similar optimization to susp as suggested by Andrew

?lib/sbi/sbi_ecall_srst.c |? 7 ++++--- ?lib/sbi/sbi_ecall_susp.c | 10 ++++++---- ?2 files changed, 10 insertions(+), 7 deletions(-)

lib/sbi/sbi_ecall_srst.c +0 -0
index 93b012c..91059d7 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,

?
?static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val) ?{
-???????u32 type, count = 0;
+???????u32 type;
?
????????/*
???????? * At least one standard reset types should be supported by

lib/sbi/sbi_ecall_srst.c static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val) · line 64

Quoted 6 lines
lib/sbi/sbi_ecall_srst.c +2 -1
@@ -60,10 +60,11 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 ????????for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 ????????????????if (sbi_system_reset_supported(type,
 ????????????????????????????????????????SBI_SRST_RESET_REASON_NONE))
-???????????????????????count++;
+???????????????????????*out_val = 1;
+???????????????????????return 0;

Missing {} around these two statements. Sorry I missed that in the v1 review. Seeing them added in the SUSP change below points it out.

Quoted 28 lines
lib/sbi/sbi_ecall_srst.c +0 -0
 ????????}

?
-???????*out_val = (count) ? 1 : 0;
+???????*out_val = 0;
????????return 0;
?}
?

lib/sbi/sbi_ecall_susp.c +0 -0
index f20126c..c8b8f64 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,

?
?static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val) ?{
-???????u32 type, count = 0;
+???????u32 type;
?
????????/*
???????? * At least one suspend type should be supported by the ???????? * platform for the SBI SUSP extension to be usable. ???????? */
????????for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) { -???????????????if (sbi_system_suspend_supported(type)) -???????????????????????count++;
+???????????????if (sbi_system_suspend_supported(type)) { +???????????????????????*out_val = 1; +???????????????????????return 0;

Quoted 11 lines

+???????????????}
????????}
?
-???????*out_val = count ? 1 : 0;
+???????*out_val = 0;
????????return 0;
?}
?

Signature · 1 line
2.39.2

Otherwise,

Thanks,
drew