From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 17D79A0C41; Tue, 11 May 2021 08:48:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09434410FE; Tue, 11 May 2021 08:46:37 +0200 (CEST) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by mails.dpdk.org (Postfix) with ESMTP id 17F6641157 for ; Tue, 11 May 2021 08:46:32 +0200 (CEST) Received: by mail-lj1-f180.google.com with SMTP id b7so23793033ljr.4 for ; Mon, 10 May 2021 23:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rz71/71Hu/SeU0B7hSRScwyLgKXuMWaMpT9AOXXeDm4=; b=uE1RfGNPFn2yii6117P9/BYOJnM0Mi73IP9TvSA69jn1llccFBJ+MKiq78pqnzgWja RQuE1n9J+00kegjOsg+94q2sjMAja/hbd+UwseFUC1NY72L2BQChYd3gsBsD6xYUR2mN T09ytvCuX/2jDAJ1xH9tC9WHi/L96nufDTYg/oiK+nAnEvnZuk9uvVLP8jKOUMKF354y SOykmHZx4QM7WcUegY8LNJT+tLQgwME+OQGkGKrEwBxez3+NNoWWQhObNKCAFNIs/avx GpODquPeXU92PYTFmWkqZsRR1y0EzUjmRFkL4nPFAaQy5LhVtrLkGqRTXIRjO9zgh3/z Hd8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rz71/71Hu/SeU0B7hSRScwyLgKXuMWaMpT9AOXXeDm4=; b=NWuSEYE4zSgsLfDWvdhWW9ORKiIcgJZczur69Ub0jS1KSK6QLrnr6WP6VG3dmqShAV CPFca1UQAT9GFsOXZA36wuHHm9kC1K/py9FXh7dNN8qc/C8ScQAkKgsQayDL2xfjx+1E GUetq7ZuTWhPSjDtHTqnygrgff6LUfoa5zJRZzDWD+r+afPH8M3D5fbgdHBc++o2rHDT LndxGVN3w+FL6JSN7BTcq7zFBIOy5kBL5QhFSO7CQ61KpLiveoMWtU/fC0zuEwIlO1P0 Ns96v9JYXAxFhmA4I+UxR0I/mSLA17UJiGU1Sb9VjPHont9ooh9ecTUKhrN9fQyjT20/ c1MQ== X-Gm-Message-State: AOAM531LDJDmIEypp+XLr/MV8tN9DLAC4Lq2YbiJh1ChAh9AlTqlw9PI vO7CLJJrEo7Bqrmhvy4ls0da4g== X-Google-Smtp-Source: ABdhPJxRSem6ArsOhajSdZkJvymNxtNgsef7Z/yo4xWeWa88mtDqletHtAPDaJRj9gllFftOo4W1Nw== X-Received: by 2002:a2e:9896:: with SMTP id b22mr23193302ljj.329.1620715591773; Mon, 10 May 2021 23:46:31 -0700 (PDT) Received: from DESKTOP-U5LNN3J.localdomain (89-79-189-199.dynamic.chello.pl. [89.79.189.199]) by smtp.gmail.com with ESMTPSA id v20sm2496776lfd.92.2021.05.10.23.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 23:46:31 -0700 (PDT) From: Michal Krawczyk To: ferruh.yigit@intel.com Cc: dev@dpdk.org, ndagan@amazon.com, gtzalik@amazon.com, igorch@amazon.com, upstream@semihalf.com, Stanislaw Kardach , Michal Krawczyk , Shay Agroskin Date: Tue, 11 May 2021 08:45:50 +0200 Message-Id: <20210511064554.10656-16-mk@semihalf.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511064554.10656-1-mk@semihalf.com> References: <87e65a42-4ae5-1a81-8f8e-74759fc14999@intel.com> <20210511064554.10656-1-mk@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 15/19] net/ena: handle spurious wakeups in ENA wait event X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stanislaw Kardach pthread_cond_timedwait() may spuriously wakeup according to POSIX. Therefore it is required to check whether predicate is actually true before finishing the waiting loop. Signed-off-by: Stanislaw Kardach Reviewed-by: Michal Krawczyk Reviewed-by: Igor Chauskin Reviewed-by: Shay Agroskin --- v4: * Replace rte_panic with the error log. drivers/net/ena/base/ena_plat_dpdk.h | 73 ++++++++++++++++++---------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 13264d021b..f66df95591 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -77,6 +77,14 @@ typedef uint64_t dma_addr_t; #define mmiowb rte_io_wmb #define __iomem +#ifndef READ_ONCE +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#endif + +#define READ_ONCE8(var) READ_ONCE(var) +#define READ_ONCE16(var) READ_ONCE(var) +#define READ_ONCE32(var) READ_ONCE(var) + #define US_PER_S 1000000 #define ENA_GET_SYSTEM_USECS() \ (rte_get_timer_cycles() * US_PER_S / rte_get_timer_hz()) @@ -138,40 +146,59 @@ extern int ena_logtype_com; ({(void)flags; rte_spinlock_unlock(&(spinlock)); }) #define ENA_SPINLOCK_DESTROY(spinlock) ((void)(spinlock)) -#define q_waitqueue_t \ - struct { \ - pthread_cond_t cond; \ - pthread_mutex_t mutex; \ - } +typedef struct { + pthread_cond_t cond; + pthread_mutex_t mutex; + uint8_t flag; +} ena_wait_event_t; -#define ena_wait_queue_t q_waitqueue_t - -#define ENA_WAIT_EVENT_INIT(waitqueue) \ +#define ENA_WAIT_EVENT_INIT(waitevent) \ do { \ - pthread_mutex_init(&(waitqueue).mutex, NULL); \ - pthread_cond_init(&(waitqueue).cond, NULL); \ + ena_wait_event_t *_we = &(waitevent); \ + pthread_mutex_init(&_we->mutex, NULL); \ + pthread_cond_init(&_we->cond, NULL); \ + _we->flag = 0; \ } while (0) #define ENA_WAIT_EVENT_WAIT(waitevent, timeout) \ do { \ + ena_wait_event_t *_we = &(waitevent); \ + typeof(timeout) _tmo = (timeout); \ + int ret = 0; \ struct timespec wait; \ struct timeval now; \ unsigned long timeout_us; \ gettimeofday(&now, NULL); \ - wait.tv_sec = now.tv_sec + (timeout) / 1000000UL; \ - timeout_us = (timeout) % 1000000UL; \ + wait.tv_sec = now.tv_sec + _tmo / 1000000UL; \ + timeout_us = _tmo % 1000000UL; \ wait.tv_nsec = (now.tv_usec + timeout_us) * 1000UL; \ - pthread_mutex_lock(&(waitevent).mutex); \ - pthread_cond_timedwait(&(waitevent).cond, \ - &(waitevent).mutex, &wait); \ - pthread_mutex_unlock(&(waitevent).mutex); \ + pthread_mutex_lock(&_we->mutex); \ + while (ret == 0 && !_we->flag) { \ + ret = pthread_cond_timedwait(&_we->cond, \ + &_we->mutex, &wait); \ + } \ + /* Asserts only if not working on ena_wait_event_t */ \ + if (unlikely(ret != 0 && ret != ETIMEDOUT)) \ + ena_trc_err(NULL, \ + "Invalid wait event. pthread ret: %d\n", ret); \ + else if (unlikely(ret == ETIMEDOUT)) \ + ena_trc_err(NULL, \ + "Timeout waiting for " #waitevent "\n"); \ + _we->flag = 0; \ + pthread_mutex_unlock(&_we->mutex); \ + } while (0) +#define ENA_WAIT_EVENT_SIGNAL(waitevent) \ + do { \ + ena_wait_event_t *_we = &(waitevent); \ + pthread_mutex_lock(&_we->mutex); \ + _we->flag = 1; \ + pthread_cond_signal(&_we->cond); \ + pthread_mutex_unlock(&_we->mutex); \ } while (0) -#define ENA_WAIT_EVENT_SIGNAL(waitevent) pthread_cond_signal(&waitevent.cond) /* pthread condition doesn't need to be rearmed after usage */ #define ENA_WAIT_EVENT_CLEAR(...) -#define ENA_WAIT_EVENT_DESTROY(waitqueue) ((void)(waitqueue)) +#define ENA_WAIT_EVENT_DESTROY(waitevent) ((void)(waitevent)) -#define ena_wait_event_t ena_wait_queue_t #define ENA_MIGHT_SLEEP() #define ena_time_t uint64_t @@ -289,14 +316,6 @@ extern rte_atomic64_t ena_alloc_cnt; ((timeout_us) * rte_get_timer_hz() / 1000000 + rte_get_timer_cycles()) #define ENA_WAIT_EVENTS_DESTROY(admin_queue) ((void)(admin_queue)) -#ifndef READ_ONCE -#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) -#endif - -#define READ_ONCE8(var) READ_ONCE(var) -#define READ_ONCE16(var) READ_ONCE(var) -#define READ_ONCE32(var) READ_ONCE(var) - /* The size must be 8 byte align */ #define ENA_MEMCPY_TO_DEVICE_64(dst, src, size) \ do { \ -- 2.25.1