eal/bsd: fix spinlock not unlock in alarm callback

Message ID 20230213124452.46536-1-fengchengwen@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series eal/bsd: fix spinlock not unlock in alarm callback |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

fengchengwen Feb. 13, 2023, 12:44 p.m. UTC
  The spinlock should unlock when clock_gettime() failed. This patch
fixes it by invoking clock_gettime() before lock.

Fixes: 26021a715067 ("eal/bsd: support alarm API")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/eal/freebsd/eal_alarm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

fengchengwen Feb. 16, 2023, 1:28 a.m. UTC | #1
add cc maintainer

On 2023/2/13 20:44, Chengwen Feng wrote:
> The spinlock should unlock when clock_gettime() failed. This patch
> fixes it by invoking clock_gettime() before lock.
> 
> Fixes: 26021a715067 ("eal/bsd: support alarm API")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> ---
>  lib/eal/freebsd/eal_alarm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c
> index 1023c32937..1a3e6c0aad 100644
> --- a/lib/eal/freebsd/eal_alarm.c
> +++ b/lib/eal/freebsd/eal_alarm.c
> @@ -171,12 +171,12 @@ eal_alarm_callback(void *arg __rte_unused)
>  	struct timespec now;
>  	struct alarm_entry *ap;
>  
> -	rte_spinlock_lock(&alarm_list_lk);
> -	ap = LIST_FIRST(&alarm_list);
> -
>  	if (clock_gettime(CLOCK_TYPE_ID, &now) < 0)
>  		return;
>  
> +	rte_spinlock_lock(&alarm_list_lk);
> +	ap = LIST_FIRST(&alarm_list);
> +
>  	while (ap != NULL && timespec_cmp(&now, &ap->time) >= 0) {
>  		ap->executing = 1;
>  		ap->executing_id = pthread_self();
>
  
Bruce Richardson Feb. 16, 2023, 9:22 a.m. UTC | #2
On Thu, Feb 16, 2023 at 09:28:17AM +0800, fengchengwen wrote:
> add cc maintainer
> 
> On 2023/2/13 20:44, Chengwen Feng wrote:
> > The spinlock should unlock when clock_gettime() failed. This patch
> > fixes it by invoking clock_gettime() before lock.
> > 
> > Fixes: 26021a715067 ("eal/bsd: support alarm API")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> > ---
> >  lib/eal/freebsd/eal_alarm.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c
> > index 1023c32937..1a3e6c0aad 100644
> > --- a/lib/eal/freebsd/eal_alarm.c
> > +++ b/lib/eal/freebsd/eal_alarm.c
> > @@ -171,12 +171,12 @@ eal_alarm_callback(void *arg __rte_unused)
> >  	struct timespec now;
> >  	struct alarm_entry *ap;
> >  
> > -	rte_spinlock_lock(&alarm_list_lk);
> > -	ap = LIST_FIRST(&alarm_list);
> > -
> >  	if (clock_gettime(CLOCK_TYPE_ID, &now) < 0)
> >  		return;
> >  
> > +	rte_spinlock_lock(&alarm_list_lk);
> > +	ap = LIST_FIRST(&alarm_list);
> > +
> >  	while (ap != NULL && timespec_cmp(&now, &ap->time) >= 0) {
> >  		ap->executing = 1;
> >  		ap->executing_id = pthread_self();
> > 

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon Feb. 19, 2023, 10:27 p.m. UTC | #3
16/02/2023 10:22, Bruce Richardson:
> On Thu, Feb 16, 2023 at 09:28:17AM +0800, fengchengwen wrote:
> > add cc maintainer
> > 
> > On 2023/2/13 20:44, Chengwen Feng wrote:
> > > The spinlock should unlock when clock_gettime() failed. This patch
> > > fixes it by invoking clock_gettime() before lock.
> > > 
> > > Fixes: 26021a715067 ("eal/bsd: support alarm API")
> > > Cc: stable@dpdk.org
> > > 
> > > Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks.
  

Patch

diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c
index 1023c32937..1a3e6c0aad 100644
--- a/lib/eal/freebsd/eal_alarm.c
+++ b/lib/eal/freebsd/eal_alarm.c
@@ -171,12 +171,12 @@  eal_alarm_callback(void *arg __rte_unused)
 	struct timespec now;
 	struct alarm_entry *ap;
 
-	rte_spinlock_lock(&alarm_list_lk);
-	ap = LIST_FIRST(&alarm_list);
-
 	if (clock_gettime(CLOCK_TYPE_ID, &now) < 0)
 		return;
 
+	rte_spinlock_lock(&alarm_list_lk);
+	ap = LIST_FIRST(&alarm_list);
+
 	while (ap != NULL && timespec_cmp(&now, &ap->time) >= 0) {
 		ap->executing = 1;
 		ap->executing_id = pthread_self();