Skip to contentSkip to conversation

hw/nvram: Avoid unnecessary Xilinx eFuse backstore write

PATCH Applied Tong Ho 5 participants 5 messages Apr 27, 2023 – Jul 17, 2023

lore
Share & tools
lore

Tong Ho

author
#0 lore raw

PATCH 1/1 hw/nvram: Avoid unnecessary Xilinx eFuse backstore write

Add a check in the bit-set operation to write the backstore only if the affected bit is 0 before.

With this in place, there will be no need for callers to do the checking in order to avoid unnecessary writes.

---
 hw/nvram/xlnx-efuse.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/nvram/xlnx-efuse.c +9 -2
index fdfffaab99..655c40b8d1 100644
@@ -143,6 +143,8 @@ static bool efuse_ro_bits_find(XlnxEFuse *s, uint32_t k)
 
 bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
 {
+    uint32_t set, *row;
+
     if (efuse_ro_bits_find(s, bit)) {
         g_autofree char *path = object_get_canonical_path(OBJECT(s));
 
@@ -152,8 +154,13 @@ bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
         return false;
     }
 
-    s->fuse32[bit / 32] |= 1 << (bit % 32);
-    efuse_bdrv_sync(s, bit);
+    /* Avoid back-end write unless there is a real update */
+    row = &s->fuse32[bit / 32];
+    set = 1 << (bit % 32);
+    if (!(set & *row)) {
+        *row |= set;
+        efuse_bdrv_sync(s, bit);
+    }
     return true;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Tong Ho

Add a check in the bit-set operation to write the backstore only if the affected bit is 0 before.

With this in place, there will be no need for callers to do the checking in order to avoid unnecessary writes.

Alistair

Quoted 37 lines
---
 hw/nvram/xlnx-efuse.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/nvram/xlnx-efuse.c +9 -3
index fdfffaab99..655c40b8d1 100644
@@ -143,6 +143,8 @@ static bool efuse_ro_bits_find(XlnxEFuse *s, uint32_t k)
 
 bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
 {
+    uint32_t set, *row;
+
     if (efuse_ro_bits_find(s, bit)) {
         g_autofree char *path = object_get_canonical_path(OBJECT(s));
 
@@ -152,8 +154,13 @@ bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
         return false;
     }
 
-    s->fuse32[bit / 32] |= 1 << (bit % 32);
-    efuse_bdrv_sync(s, bit);
+    /* Avoid back-end write unless there is a real update */
+    row = &s->fuse32[bit / 32];
+    set = 1 << (bit % 32);
+    if (!(set & *row)) {
+        *row |= set;
+        efuse_bdrv_sync(s, bit);
+    }
     return true;
 }
 
--

2.25.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Tong Ho
Quoted 7 lines · Tong Ho

Add a check in the bit-set operation to write the backstore only if the affected bit is 0 before.

With this in place, there will be no need for callers to do the checking in order to avoid unnecessary writes.

Quoted 36 lines
---
 hw/nvram/xlnx-efuse.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/nvram/xlnx-efuse.c +9 -2
index fdfffaab99..655c40b8d1 100644
@@ -143,6 +143,8 @@ static bool efuse_ro_bits_find(XlnxEFuse *s, uint32_t k)
 
 bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
 {
+    uint32_t set, *row;
+
     if (efuse_ro_bits_find(s, bit)) {
         g_autofree char *path = object_get_canonical_path(OBJECT(s));
 
@@ -152,8 +154,13 @@ bool xlnx_efuse_set_bit(XlnxEFuse *s, unsigned int bit)
         return false;
     }
 
-    s->fuse32[bit / 32] |= 1 << (bit % 32);
-    efuse_bdrv_sync(s, bit);
+    /* Avoid back-end write unless there is a real update */
+    row = &s->fuse32[bit / 32];
+    set = 1 << (bit % 32);
+    if (!(set & *row)) {
+        *row |= set;
+        efuse_bdrv_sync(s, bit);
+    }
     return true;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#3 lore raw
In reply to Tong Ho
Quoted 10 lines · Tong Ho

Add a check in the bit-set operation to write the backstore only if the affected bit is 0 before.

With this in place, there will be no need for callers to do the checking in order to avoid unnecessary writes.

---
  hw/nvram/xlnx-efuse.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
#4 lore raw
In reply to Tong Ho
Quoted 9 lines · Tong Ho

Add a check in the bit-set operation to write the backstore only if the affected bit is 0 before.

With this in place, there will be no need for callers to do the checking in order to avoid unnecessary writes.

---

Applied to target-arm.next, thanks.

-- PMM