Skip to contentSkip to conversation

Miscellaneous about sbi_tlb and sbi_ipi

PATCH Superseded Xiang W 2 participants 12 messages Feb 2, 2023 – Apr 11, 2023

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Xiang W

author
#0 lore raw

v4 cover Miscellaneous about sbi_tlb and sbi_ipi

Removed the mutual waiting between process and sync in sbi_tlb Update ipi first then wait together

V4 Changes:
PATCH1: Fixed not adding one to tlb_sync when SBI_FIFO_UNCHANGED
PATCH4: Add comments

V3 Changes:
PATCH2: Remove missing sync in update
add PATCH4: Optimize sbi_tlb queue waiting

V2 Changes:
PATCH2: Fix m changes after update IPIs

Xiang W (4):
lib: sbi: Optimize sbi_tlb
lib: sbi: Optimize sbi_ipi
lib: sbi: rename function of sbi_ipi
lib: sbi: Optimize sbi_tlb queue waiting

 include/sbi/sbi_ipi.h |  3 +++
 lib/sbi/sbi_ipi.c     | 43 ++++++++++++++++++++++++++++++-------
 lib/sbi/sbi_tlb.c     | 49 +++++++++++++++++++------------------------
 3 files changed, 61 insertions(+), 34 deletions(-)
Signature · 1 line
2.39.0
author
#1 lore raw

PATCH v4 1/4 lib: sbi: Optimize sbi_tlb

Originally, the process and sync of sbi_tlb need to wait for each other. Evasion by atomic addition and subtraction.

---
 lib/sbi/sbi_tlb.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
lib/sbi/sbi_tlb.c +11 -10
index 4c142ea..8bab31a 100644
@@ -215,7 +215,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
 {
 	u32 rhartid;
 	struct sbi_scratch *rscratch = NULL;
-	unsigned long *rtlb_sync = NULL;
+	atomic_t *rtlb_sync = NULL;
 
 	tinfo->local_fn(tinfo);
 
@@ -225,7 +225,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
 			continue;
 
 		rtlb_sync = sbi_scratch_offset_ptr(rscratch, tlb_sync_off);
-		while (atomic_raw_xchg_ulong(rtlb_sync, 1)) ;
+		atomic_sub_return(rtlb_sync, 1);
 	}
 }
 
@@ -257,10 +257,10 @@ static void tlb_process(struct sbi_scratch *scratch)
 
 static void tlb_sync(struct sbi_scratch *scratch)
 {
-	unsigned long *tlb_sync =
+	atomic_t *tlb_sync =
 			sbi_scratch_offset_ptr(scratch, tlb_sync_off);
 
-	while (!atomic_raw_xchg_ulong(tlb_sync, 0)) {
+	while (atomic_read(tlb_sync) > 0) {
 		/*
 		 * While we are waiting for remote hart to set the sync,
 		 * consume fifo requests to avoid deadlock.
@@ -343,6 +343,7 @@ static int tlb_update(struct sbi_scratch *scratch,
 			  u32 remote_hartid, void *data)
 {
 	int ret;
+	atomic_t *tlb_sync;
 	struct sbi_fifo *tlb_fifo_r;
 	struct sbi_tlb_info *tinfo = data;
 	u32 curr_hartid = current_hartid();
@@ -369,11 +370,8 @@ static int tlb_update(struct sbi_scratch *scratch,
 	tlb_fifo_r = sbi_scratch_offset_ptr(remote_scratch, tlb_fifo_off);
 
 	ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb);
-	if (ret != SBI_FIFO_UNCHANGED) {
-		return 1;
-	}
 
-	while (sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
+	while (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
 		/**
 		 * For now, Busy loop until there is space in the fifo.
 		 * There may be case where target hart is also
@@ -387,6 +385,9 @@ static int tlb_update(struct sbi_scratch *scratch,
 			    curr_hartid, remote_hartid);
 	}
 
+	tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off);
+	atomic_add_return(tlb_sync, 1);
+
 	return 0;
 }
 
@@ -413,7 +414,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
 {
 	int ret;
 	void *tlb_mem;
-	unsigned long *tlb_sync;
+	atomic_t *tlb_sync;
 	struct sbi_fifo *tlb_q;
 	const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
@@ -455,7 +456,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
 	tlb_q = sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
 	tlb_mem = sbi_scratch_offset_ptr(scratch, tlb_fifo_mem_off);
 
-	*tlb_sync = 0;
+	tlb_sync->counter = 0;
 
 	sbi_fifo_init(tlb_q, tlb_mem,
 		      SBI_TLB_FIFO_NUM_ENTRIES, SBI_TLB_INFO_SIZE);
Signature · 1 line
2.39.0
#2 lore raw

PATCH v4 1/4 lib: sbi: Optimize sbi_tlb

Quoted 85 lines · On Thu, Feb 2, 2023 at 2:52?PM Xiang W <[email protected]> wrote:

Originally, the process and sync of sbi_tlb need to wait for each other. Evasion by atomic addition and subtraction.

---
 lib/sbi/sbi_tlb.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
lib/sbi/sbi_tlb.c +10 -9
index 4c142ea..8bab31a 100644
@@ -215,7 +215,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
 {
        u32 rhartid;
        struct sbi_scratch *rscratch = NULL;
-       unsigned long *rtlb_sync = NULL;
+       atomic_t *rtlb_sync = NULL;
 
        tinfo->local_fn(tinfo);
 
@@ -225,7 +225,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
                        continue;
 
                rtlb_sync = sbi_scratch_offset_ptr(rscratch, tlb_sync_off);
-               while (atomic_raw_xchg_ulong(rtlb_sync, 1)) ;
+               atomic_sub_return(rtlb_sync, 1);
        }
 }
 
@@ -257,10 +257,10 @@ static void tlb_process(struct sbi_scratch *scratch)
 
 static void tlb_sync(struct sbi_scratch *scratch)
 {
-       unsigned long *tlb_sync =
+       atomic_t *tlb_sync =
                        sbi_scratch_offset_ptr(scratch, tlb_sync_off);
 
-       while (!atomic_raw_xchg_ulong(tlb_sync, 0)) {
+       while (atomic_read(tlb_sync) > 0) {
                /*
                 * While we are waiting for remote hart to set the sync,
                 * consume fifo requests to avoid deadlock.
@@ -343,6 +343,7 @@ static int tlb_update(struct sbi_scratch *scratch,
                          u32 remote_hartid, void *data)
 {
        int ret;
+       atomic_t *tlb_sync;
        struct sbi_fifo *tlb_fifo_r;
        struct sbi_tlb_info *tinfo = data;
        u32 curr_hartid = current_hartid();
@@ -369,11 +370,8 @@ static int tlb_update(struct sbi_scratch *scratch,
        tlb_fifo_r = sbi_scratch_offset_ptr(remote_scratch, tlb_fifo_off);
 
        ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb);
-       if (ret != SBI_FIFO_UNCHANGED) {
-               return 1;
-       }
 
-       while (sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
+       while (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
                /**
                 * For now, Busy loop until there is space in the fifo.
                 * There may be case where target hart is also
@@ -387,6 +385,9 @@ static int tlb_update(struct sbi_scratch *scratch,
                            curr_hartid, remote_hartid);
        }
 
+       tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off);
+       atomic_add_return(tlb_sync, 1);
+
        return 0;
 }
 
@@ -413,7 +414,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
 {
        int ret;
        void *tlb_mem;
-       unsigned long *tlb_sync;
+       atomic_t *tlb_sync;
        struct sbi_fifo *tlb_q;
        const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 

lib/sbi/sbi_tlb.c int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) · line 459

Quoted 5 lines
lib/sbi/sbi_tlb.c +1 -1
@@ -455,7 +456,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot)
        tlb_q = sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
        tlb_mem = sbi_scratch_offset_ptr(scratch, tlb_fifo_mem_off);
 
-       *tlb_sync = 0;
+       tlb_sync->counter = 0;

Use ATOMIC_INIT() here.

Quoted 11 lines
lib/sbi/sbi_tlb.c +0 -1
        sbi_fifo_init(tlb_q, tlb_mem,
                      SBI_TLB_FIFO_NUM_ENTRIES, SBI_TLB_INFO_SIZE);
--

2.39.0

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Otherwise it looks good to me.

Regards,
Anup

author
#3 lore raw

PATCH v4 2/4 lib: sbi: Optimize sbi_ipi

In reply to Xiang W

the original sbI_ipi will be processed by hart by hart, after optimization, send ipi first and finally wait together.

---
 lib/sbi/sbi_ipi.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)
lib/sbi/sbi_ipi.c +36 -6
index 1bcc2e4..92a33bd 100644
@@ -31,7 +31,7 @@ static unsigned long ipi_data_off;
 static const struct sbi_ipi_device *ipi_dev = NULL;
 static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];
 
-static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
+static int sbi_ipi_update(struct sbi_scratch *scratch, u32 remote_hartid,
 			u32 event, void *data)
 {
 	int ret;
@@ -69,6 +69,18 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
 
 	sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT);
 
+	return 0;
+}
+
+static int sbi_ipi_sync(struct sbi_scratch *scratch, u32 event)
+{
+	const struct sbi_ipi_event_ops *ipi_ops;
+
+	if ((SBI_IPI_EVENT_MAX <= event) ||
+	    !ipi_ops_array[event])
+		return SBI_EINVAL;
+	ipi_ops = ipi_ops_array[event];
+
 	if (ipi_ops->sync)
 		ipi_ops->sync(scratch);
 
@@ -83,7 +95,7 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
 int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
 {
 	int rc;
-	ulong i, m;
+	ulong i, m, n;
 	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 
@@ -92,19 +104,37 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
 		if (rc)
 			return rc;
 		m &= hmask;
+		n = m;
 
-		/* Send IPIs */
+		/* update IPIs */
 		for (i = hbase; m; i++, m >>= 1) {
 			if (m & 1UL)
-				sbi_ipi_send(scratch, i, event, data);
+				sbi_ipi_update(scratch, i, event, data);
+		}
+
+		/* sync IPIs */
+		m = n;
+		for (i = hbase; m; i++, m >>= 1) {
+			if (m & 1UL)
+				sbi_ipi_sync(scratch, event);
 		}
 	} else {
+		/* update IPIs */
+		hbase = 0;
+		while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
+			for (i = hbase; m; i++, m >>= 1) {
+				if (m & 1UL)
+					sbi_ipi_update(scratch, i, event, data);
+			}
+			hbase += BITS_PER_LONG;
+		}
+
+		/* sync IPIs */
 		hbase = 0;
 		while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
-			/* Send IPIs */
 			for (i = hbase; m; i++, m >>= 1) {
 				if (m & 1UL)
-					sbi_ipi_send(scratch, i, event, data);
+					sbi_ipi_sync(scratch, event);
 			}
 			hbase += BITS_PER_LONG;
 		}
Signature · 1 line
2.39.0
#4 lore raw

PATCH v4 2/4 lib: sbi: Optimize sbi_ipi

Quoted 2 lines · On Thu, Feb 2, 2023 at 2:52?PM Xiang W <[email protected]> wrote:

the original sbI_ipi will be processed by hart by hart, after optimization,

s/sbl_ipi/sbi_ipi/

Quoted 12 lines

send ipi first and finally wait together.

---
 lib/sbi/sbi_ipi.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)
lib/sbi/sbi_ipi.c +0 -0
index 1bcc2e4..92a33bd 100644

lib/sbi/sbi_ipi.c static unsigned long ipi_data_off; · line 35

Quoted 6 lines
lib/sbi/sbi_ipi.c +1 -1
@@ -31,7 +31,7 @@ static unsigned long ipi_data_off;
 static const struct sbi_ipi_device *ipi_dev = NULL;
 static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];
 
-static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
+static int sbi_ipi_update(struct sbi_scratch *scratch, u32 remote_hartid,
                        u32 event, void *data)

This is unnecessary renaming. Please drop this renaming.

Quoted 53 lines
lib/sbi/sbi_ipi.c +25 -3
 {
        int ret;
@@ -69,6 +69,18 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
 
        sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT);
 
+       return 0;
+}
+
+static int sbi_ipi_sync(struct sbi_scratch *scratch, u32 event)
+{
+       const struct sbi_ipi_event_ops *ipi_ops;
+
+       if ((SBI_IPI_EVENT_MAX <= event) ||
+           !ipi_ops_array[event])
+               return SBI_EINVAL;
+       ipi_ops = ipi_ops_array[event];
+
        if (ipi_ops->sync)
                ipi_ops->sync(scratch);
 
@@ -83,7 +95,7 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
 int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
 {
        int rc;
-       ulong i, m;
+       ulong i, m, n;
        struct sbi_domain *dom = sbi_domain_thishart_ptr();
        struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 
@@ -92,19 +104,37 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
                if (rc)
                        return rc;
                m &= hmask;
+               n = m;
 
-               /* Send IPIs */
+               /* update IPIs */
                for (i = hbase; m; i++, m >>= 1) {
                        if (m & 1UL)
-                               sbi_ipi_send(scratch, i, event, data);
+                               sbi_ipi_update(scratch, i, event, data);
+               }
+
+               /* sync IPIs */
+               m = n;
+               for (i = hbase; m; i++, m >>= 1) {
+                       if (m & 1UL)
+                               sbi_ipi_sync(scratch, event);
                }
        } else {
+               /* update IPIs */
+               hbase = 0;

lib/sbi/sbi_ipi.c int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) · line 133

Quoted 10 lines
lib/sbi/sbi_ipi.c +9 -0
+               while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
+                       for (i = hbase; m; i++, m >>= 1) {
+                               if (m & 1UL)
+                                       sbi_ipi_update(scratch, i, event, data);
+                       }
+                       hbase += BITS_PER_LONG;
+               }
+
+               /* sync IPIs */
                hbase = 0;

Set "m = n" here.

Quoted 13 lines
lib/sbi/sbi_ipi.c +1 -3
                while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
-                       /* Send IPIs */
                        for (i = hbase; m; i++, m >>= 1) {
                                if (m & 1UL)
-                                       sbi_ipi_send(scratch, i, event, data);
+                                       sbi_ipi_sync(scratch, event);
                        }
                        hbase += BITS_PER_LONG;
                }
--

2.39.0

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup

author
#5 lore raw

PATCH v4 3/4 lib: sbi: rename function of sbi_ipi

In reply to Xiang W

Renamed some functions and reused some code

---
 lib/sbi/sbi_tlb.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
lib/sbi/sbi_tlb.c +10 -17
index 8bab31a..741f4bb 100644
@@ -211,7 +211,7 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data)
 		sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT);
 }
 
-static void tlb_entry_process(struct sbi_tlb_info *tinfo)
+static void tlb_process_helper(struct sbi_tlb_info *tinfo)
 {
 	u32 rhartid;
 	struct sbi_scratch *rscratch = NULL;
@@ -229,30 +229,23 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
 	}
 }
 
-static void tlb_process_count(struct sbi_scratch *scratch, int count)
+static int tlb_process_once(struct sbi_scratch *scratch)
 {
 	struct sbi_tlb_info tinfo;
-	unsigned int deq_count = 0;
 	struct sbi_fifo *tlb_fifo =
 			sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
 
-	while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) {
-		tlb_entry_process(&tinfo);
-		deq_count++;
-		if (deq_count > count)
-			break;
-
+	if (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) {
+		tlb_process_helper(&tinfo);
+		return 0;
 	}
+
+	return -1;
 }
 
 static void tlb_process(struct sbi_scratch *scratch)
 {
-	struct sbi_tlb_info tinfo;
-	struct sbi_fifo *tlb_fifo =
-			sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
-
-	while (!sbi_fifo_dequeue(tlb_fifo, &tinfo))
-		tlb_entry_process(&tinfo);
+	while (!tlb_process_once(scratch));
 }
 
 static void tlb_sync(struct sbi_scratch *scratch)
@@ -265,7 +258,7 @@ static void tlb_sync(struct sbi_scratch *scratch)
 		 * While we are waiting for remote hart to set the sync,
 		 * consume fifo requests to avoid deadlock.
 		 */
-		tlb_process_count(scratch, 1);
+		tlb_process_once(scratch);
 	}
 
 	return;
@@ -380,7 +373,7 @@ static int tlb_update(struct sbi_scratch *scratch,
 		 * TODO: Introduce a wait/wakeup event mechanism to handle
 		 * this properly.
 		 */
-		tlb_process_count(scratch, 1);
+		tlb_process_once(scratch);
 		sbi_dprintf("hart%d: hart%d tlb fifo full\n",
 			    curr_hartid, remote_hartid);
 	}
Signature · 1 line
2.39.0
#6 lore raw

PATCH v4 3/4 lib: sbi: rename function of sbi_ipi

Quoted 4 lines · On Thu, Feb 2, 2023 at 2:22?PM Xiang W <[email protected]> wrote:

Renamed some functions and reused some code

The patch subject and commit description needs to be improved.

The subject can be "sbi: tlb: Simplify to tlb_process_count() function"

Quoted 9 lines
---
 lib/sbi/sbi_tlb.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
lib/sbi/sbi_tlb.c +0 -0
index 8bab31a..741f4bb 100644

lib/sbi/sbi_tlb.c static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) · line 214

Quoted 5 lines
lib/sbi/sbi_tlb.c +1 -1
@@ -211,7 +211,7 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data)
                sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT);
 }
 
-static void tlb_entry_process(struct sbi_tlb_info *tinfo)
+static void tlb_process_helper(struct sbi_tlb_info *tinfo)

No need to rename this function.

lib/sbi/sbi_tlb.c static void tlb_entry_process(struct sbi_tlb_info *tinfo) · line 232

Quoted 9 lines
lib/sbi/sbi_tlb.c +1 -1
 {
        u32 rhartid;
        struct sbi_scratch *rscratch = NULL;
@@ -229,30 +229,23 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo)
        }
 }
 
-static void tlb_process_count(struct sbi_scratch *scratch, int count)
+static int tlb_process_once(struct sbi_scratch *scratch)

This function can return "true" on success and "false" on failure.

Quoted 54 lines
lib/sbi/sbi_tlb.c +8 -16
 {
        struct sbi_tlb_info tinfo;
-       unsigned int deq_count = 0;
        struct sbi_fifo *tlb_fifo =
                        sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
 
-       while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) {
-               tlb_entry_process(&tinfo);
-               deq_count++;
-               if (deq_count > count)
-                       break;
-
+       if (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) {
+               tlb_process_helper(&tinfo);
+               return 0;
        }
+
+       return -1;
 }
 
 static void tlb_process(struct sbi_scratch *scratch)
 {
-       struct sbi_tlb_info tinfo;
-       struct sbi_fifo *tlb_fifo =
-                       sbi_scratch_offset_ptr(scratch, tlb_fifo_off);
-
-       while (!sbi_fifo_dequeue(tlb_fifo, &tinfo))
-               tlb_entry_process(&tinfo);
+       while (!tlb_process_once(scratch));
 }
 
 static void tlb_sync(struct sbi_scratch *scratch)
@@ -265,7 +258,7 @@ static void tlb_sync(struct sbi_scratch *scratch)
                 * While we are waiting for remote hart to set the sync,
                 * consume fifo requests to avoid deadlock.
                 */
-               tlb_process_count(scratch, 1);
+               tlb_process_once(scratch);
        }
 
        return;
@@ -380,7 +373,7 @@ static int tlb_update(struct sbi_scratch *scratch,
                 * TODO: Introduce a wait/wakeup event mechanism to handle
                 * this properly.
                 */
-               tlb_process_count(scratch, 1);
+               tlb_process_once(scratch);
                sbi_dprintf("hart%d: hart%d tlb fifo full\n",
                            curr_hartid, remote_hartid);
        }
--

2.39.0

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup

author
#7 lore raw

PATCH v4 4/4 lib: sbi: Optimize sbi_tlb queue waiting

In reply to Xiang W

When tlb_fifo is full, it will wait and affect the ipi update to other harts. This patch is optimized.

---
 include/sbi/sbi_ipi.h |  3 +++
 lib/sbi/sbi_ipi.c     | 47 +++++++++++++++++++++----------------------
 lib/sbi/sbi_tlb.c     |  3 ++-
 3 files changed, 28 insertions(+), 25 deletions(-)
include/sbi/sbi_ipi.h +3 -0
index f6ac807..aad7f77 100644
@@ -41,6 +41,9 @@ struct sbi_ipi_event_ops {
 	 * Update callback to save/enqueue data for remote HART
 	 * Note: This is an optional callback and it is called just before
 	 * triggering IPI to remote HART.
+	 * @return 0  success
+	 * @return -1 break IPI, done on local hart
+	 * @return -2 need retry
 	 */
 	int (* update)(struct sbi_scratch *scratch,
 			struct sbi_scratch *remote_scratch,
lib/sbi/sbi_ipi.c +23 -24

81 lines not on this page · raw message

lib/sbi/sbi_tlb.c +2 -1
index 741f4bb..1be2058 100644
@@ -364,7 +364,7 @@ static int tlb_update(struct sbi_scratch *scratch,
 
 	ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb);
 
-	while (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
+	if (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) {
 		/**
 		 * For now, Busy loop until there is space in the fifo.
 		 * There may be case where target hart is also
@@ -376,6 +376,7 @@ static int tlb_update(struct sbi_scratch *scratch,
 		tlb_process_once(scratch);
 		sbi_dprintf("hart%d: hart%d tlb fifo full\n",
 			    curr_hartid, remote_hartid);
+		return -2;
 	}
 
 	tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off);
Signature · 1 line
2.39.0
author
#8 lore raw

v4 cover Miscellaneous about sbi_tlb and sbi_ipi

In reply to Xiang W

? 2023-02-02???? 16:51 +0800?Xiang W???

Quoted 3 lines

Removed the mutual waiting between process and sync in sbi_tlb Update ipi first then wait together

Please review!
Optimization can improve tlb sync efficiency.

sequence diagram before optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      |               |  |process |           |
      |               |  |        |           |
      |               +<-+        |           |
      | sync          |           |           |
      +<------------->+           |           |
      | update hart 1             |           |
      +<------------------------->+--+        |
      |                           |  |process |
      |                           |  |        |
      |                           +<-+        |
      | sync                      |           |
      +<------------------------->+           |
      | update hart 2                         |
      +<------------------------------------->+--+
      |                                       |  |process
      |                                       |  |
      |                                       +<-+
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .

sequence diagram after optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      | update hart 1 |  |process |           |
      +<--------------|--|------->+--+        |
      | update hart 2 +<-+        |  |process |
      +<--------------|-----------|--|------->+--+
      |               |           +<-+        |  |process
      |               |           |           |  |
      | sync          |           |           +<-+
      +<------------->+           |           |
      | sync                      |           |
      +<------------------------->+           |
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .

Regards,
Xiang W

Quoted 22 lines

V4 Changes:
PATCH1: Fixed not adding one to tlb_sync when SBI_FIFO_UNCHANGED
PATCH4: Add comments

V3 Changes:
PATCH2: Remove missing sync in update
add PATCH4: Optimize sbi_tlb queue waiting

V2 Changes:
PATCH2: Fix m changes after update IPIs

Xiang W (4):
? lib: sbi: Optimize sbi_tlb
? lib: sbi: Optimize sbi_ipi
? lib: sbi: rename function of sbi_ipi
? lib: sbi: Optimize sbi_tlb queue waiting

?include/sbi/sbi_ipi.h |? 3 +++
?lib/sbi/sbi_ipi.c???? | 43 ++++++++++++++++++++++++++++++-------
?lib/sbi/sbi_tlb.c???? | 49 +++++++++++++++++++------------------------

?3 files changed, 61 insertions(+), 34 deletions(-)

#9 lore raw

v4 cover Miscellaneous about sbi_tlb and sbi_ipi

Quoted 52 lines · On Thu, Mar 16, 2023 at 1:52?PM Xiang W <[email protected]> wrote:

? 2023-02-02???? 16:51 +0800?Xiang W???

Quoted 3 lines

Removed the mutual waiting between process and sync in sbi_tlb Update ipi first then wait together

Please review!
Optimization can improve tlb sync efficiency.

sequence diagram before optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      |               |  |process |           |
      |               |  |        |           |
      |               +<-+        |           |
      | sync          |           |           |
      +<------------->+           |           |
      | update hart 1             |           |
      +<------------------------->+--+        |
      |                           |  |process |
      |                           |  |        |
      |                           +<-+        |
      | sync                      |           |
      +<------------------------->+           |
      | update hart 2                         |
      +<------------------------------------->+--+
      |                                       |  |process
      |                                       |  |
      |                                       +<-+
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .

sequence diagram after optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      | update hart 1 |  |process |           |
      +<--------------|--|------->+--+        |
      | update hart 2 +<-+        |  |process |
      +<--------------|-----------|--|------->+--+
      |               |           +<-+        |  |process
      |               |           |           |  |
      | sync          |           |           +<-+
Quoted 8 lines
      +<------------->+           |           |
      | sync                      |           |
      +<------------------------->+           |
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .

Sorry for being slow on this series. Overall, the approach looks good but I need to review individual patches.

In the meantime, I suggest you try running stress-ng one QEMU virt machine with this patch applied in OpenSBI.

Regards,
Anup

Quoted 32 lines

Regards,
Xiang W

Quoted 17 lines

V4 Changes:
PATCH1: Fixed not adding one to tlb_sync when SBI_FIFO_UNCHANGED
PATCH4: Add comments

V3 Changes:
PATCH2: Remove missing sync in update
add PATCH4: Optimize sbi_tlb queue waiting

V2 Changes:
PATCH2: Fix m changes after update IPIs

Xiang W (4):
lib: sbi: Optimize sbi_tlb
lib: sbi: Optimize sbi_ipi
lib: sbi: rename function of sbi_ipi
lib: sbi: Optimize sbi_tlb queue waiting

Quoted 5 lines
 include/sbi/sbi_ipi.h |  3 +++
 lib/sbi/sbi_ipi.c     | 43 ++++++++++++++++++++++++++++++-------
 lib/sbi/sbi_tlb.c     | 49 +++++++++++++++++++------------------------
 3 files changed, 61 insertions(+), 34 deletions(-)

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#10 lore raw

v4 cover Miscellaneous about sbi_tlb and sbi_ipi

Quoted 63 lines · On Thu, Apr 6, 2023 at 10:27?AM Anup Patel <[email protected]> wrote:
Quoted 52 lines · On Thu, Mar 16, 2023 at 1:52?PM Xiang W <[email protected]> wrote:

? 2023-02-02???? 16:51 +0800?Xiang W???

Quoted 3 lines

Removed the mutual waiting between process and sync in sbi_tlb Update ipi first then wait together

Please review!
Optimization can improve tlb sync efficiency.

sequence diagram before optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      |               |  |process |           |
      |               |  |        |           |
      |               +<-+        |           |
      | sync          |           |           |
      +<------------->+           |           |
      | update hart 1             |           |
      +<------------------------->+--+        |
      |                           |  |process |
      |                           |  |        |
      |                           +<-+        |
      | sync                      |           |
      +<------------------------->+           |
      | update hart 2                         |
      +<------------------------------------->+--+
      |                                       |  |process
      |                                       |  |
      |                                       +<-+
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .

sequence diagram after optimization:
===================================================================
send ipi hart hart 0 hart 1 hart 2 ...

      +               +           +           +
      |               |           |           |
      | update hart 0 |           |           |
      +<------------->+--+        |           |
      | update hart 1 |  |process |           |
      +<--------------|--|------->+--+        |
      | update hart 2 +<-+        |  |process |
      +<--------------|-----------|--|------->+--+
      |               |           +<-+        |  |process
      |               |           |           |  |
      | sync          |           |           +<-+
Quoted 8 lines
      +<------------->+           |           |
      | sync                      |           |
      +<------------------------->+           |
      | sync                                  |
      +<------------------------------------->+
      .
      .
      .
Quoted 5 lines

Sorry for being slow on this series. Overall, the approach looks good but I need to review individual patches.

In the meantime, I suggest you try running stress-ng one QEMU virt machine with this patch applied in OpenSBI.

To run stress-ng on QEMU virt machine, launch QEMU virt machine with at least 1G RAM and Fedora RootFS located at:
https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/
https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/Fedora-Developer-37-20221130.n.0-nvme.raw.img.xz

I typically run a cyclic stress-ng test as follows:
stress-ng --verbose --seq 4 -t 20 -x cyclic

Regards,
Anup

Quoted 36 lines

Regards,
Anup

Quoted 32 lines

Regards,
Xiang W

Quoted 17 lines

V4 Changes:
PATCH1: Fixed not adding one to tlb_sync when SBI_FIFO_UNCHANGED
PATCH4: Add comments

V3 Changes:
PATCH2: Remove missing sync in update
add PATCH4: Optimize sbi_tlb queue waiting

V2 Changes:
PATCH2: Fix m changes after update IPIs

Xiang W (4):
lib: sbi: Optimize sbi_tlb
lib: sbi: Optimize sbi_ipi
lib: sbi: rename function of sbi_ipi
lib: sbi: Optimize sbi_tlb queue waiting

Quoted 5 lines
 include/sbi/sbi_ipi.h |  3 +++
 lib/sbi/sbi_ipi.c     | 43 ++++++++++++++++++++++++++++++-------
 lib/sbi/sbi_tlb.c     | 49 +++++++++++++++++++------------------------
 3 files changed, 61 insertions(+), 34 deletions(-)

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

author
#11 lore raw

v4 cover Miscellaneous about sbi_tlb and sbi_ipi

? 2023-04-06???? 12:30 +0530?Anup Patel???

Quoted 70 lines · On Thu, Apr 6, 2023 at 10:27?AM Anup Patel <[email protected]> wrote:
Quoted 63 lines · On Thu, Mar 16, 2023 at 1:52?PM Xiang W <[email protected]> wrote:
Quoted 56 lines

? 2023-02-02???? 16:51 +0800?Xiang W???

Quoted 3 lines

Removed the mutual waiting between process and sync in sbi_tlb Update ipi first then wait together

Please review!
Optimization can improve tlb sync efficiency.

sequence diagram before optimization:
===================================================================
send ipi hart?????? hart 0?????? hart 1???? hart 2?? ... ????? +?????????????? +?????????? +?????????? +

????? |?????????????? |?????????? |?????????? |
????? | update hart 0 |?????????? |?????????? |
????? +<------------->+--+??????? |?????????? |
????? |?????????????? |? |process |?????????? |
????? |?????????????? |? |??????? |?????????? |
????? |?????????????? +<-+??????? |?????????? |
????? | sync????????? |?????????? |?????????? |
????? +<------------->+?????????? |?????????? |
????? | update hart 1???????????? |?????????? |
????? +<------------------------->+--+??????? |
????? |?????????????????????????? |? |process |
????? |?????????????????????????? |? |??????? |
????? |?????????????????????????? +<-+??????? |
????? | sync????????????????????? |?????????? |
????? +<------------------------->+?????????? |
????? | update hart 2???????????????????????? |
????? +<------------------------------------->+--+
????? |?????????????????????????????????????? |? |process
????? |?????????????????????????????????????? |? |
????? |?????????????????????????????????????? +<-+
????? | sync????????????????????????????????? |

????? +<------------------------------------->+
????? .
????? .
????? .

sequence diagram after optimization:
===================================================================
send ipi hart?????? hart 0?????? hart 1???? hart 2?? ... ????? +?????????????? +?????????? +?????????? +

????? |?????????????? |?????????? |?????????? |
????? | update hart 0 |?????????? |?????????? |
????? +<------------->+--+??????? |?????????? |
????? | update hart 1 |? |process |?????????? |
????? +<--------------|--|------->+--+??????? |
????? | update hart 2 +<-+??????? |? |process |
????? +<--------------|-----------|--|------->+--+
????? |?????????????? |?????????? +<-+??????? |? |process
????? |?????????????? |?????????? |?????????? |? |
????? | sync????????? |?????????? |?????????? +<-+
????? +<------------->+?????????? |?????????? |
????? | sync????????????????????? |?????????? |
????? +<------------------------->+?????????? |
????? | sync????????????????????????????????? |
Quoted 4 lines

????? +<------------------------------------->+
????? .
????? .
????? .

Quoted 5 lines

Sorry for being slow on this series. Overall, the approach looks good but I need to review individual patches.

In the meantime, I suggest you try running stress-ng one QEMU virt machine with this patch applied in OpenSBI.

Quoted 8 lines

To run stress-ng on QEMU virt machine, launch QEMU virt machine with at least 1G RAM and Fedora RootFS located at:
https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/
https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/Fedora-Developer-37-20221130.n.0-nvme.raw.img.xz

I typically run a cyclic stress-ng test as follows:
stress-ng --verbose --seq 4 -t 20 -x cyclic

The following is the log of my test:

without patches: https://drive.google.com/file/d/1I1pfA39tJvcZqFI55FSPxD-6o7mBaD1x/view?usp=share_link
with patches: https://drive.google.com/file/d/1FRRa6HJilS87dTgFYdA4XJRHhPIOBZms/view?usp=share_link

Regards,
Xiang W

Quoted 40 lines

Regards,
Anup

Quoted 36 lines

Regards,
Anup

Quoted 32 lines

Regards,
Xiang W

Quoted 17 lines

V4 Changes:
PATCH1: Fixed not adding one to tlb_sync when SBI_FIFO_UNCHANGED
PATCH4: Add comments

V3 Changes:
PATCH2: Remove missing sync in update
add PATCH4: Optimize sbi_tlb queue waiting

V2 Changes:
PATCH2: Fix m changes after update IPIs

Xiang W (4):
? lib: sbi: Optimize sbi_tlb
? lib: sbi: Optimize sbi_ipi
? lib: sbi: rename function of sbi_ipi
? lib: sbi: Optimize sbi_tlb queue waiting

Quoted 5 lines
?include/sbi/sbi_ipi.h |? 3 +++
?lib/sbi/sbi_ipi.c???? | 43 ++++++++++++++++++++++++++++++-------
?lib/sbi/sbi_tlb.c???? | 49 +++++++++++++++++++------------------------

?3 files changed, 61 insertions(+), 34 deletions(-)

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi