From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.52]) by dpdk.org (Postfix) with ESMTP id 758E2F04 for ; Mon, 23 Apr 2018 21:40:43 +0200 (CEST) Received: by mail-pg0-f52.google.com with SMTP id b5so9076653pgv.5 for ; Mon, 23 Apr 2018 12:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=yBJO/oFfn7s0tIER6sgYOzYD5oE+72P05/ID6h8rfEY=; b=nV5zRK9SdiPy/fm3XtFwhRBRqoRSGWiTpUCgm/X3Xf10fLTAR0JJJUd72fj1jf5C+e AaAm8j1fbHH1/ZuZR3DJQwuoeKwr+B9auqLMk0xZgbbiX1Qgh1SmH9KFL/CS1M5MvC0i Rs6c1AIxnuPxBUg2plE5kOxnuAY/ONnmsZUFiA1ZiD4VQUu6KdwOvhYD1MBfxO9RdcyB dPM+dBQNB6HRBl9DXDdWaBZczBpW5XZrnmiXPvbpb2+kdW/07VJqKkGX0k6/Lrv+IH6z hELUdW/W3uyy6yl8wbCDluDMScKP5YT2aEIDPB3fLbz9f8fiG0VhbASxAuOqsNAqF+OG +UsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=yBJO/oFfn7s0tIER6sgYOzYD5oE+72P05/ID6h8rfEY=; b=AfHqx2wmOhtaRjll4Jfh+KuKfe4LPSHvBpChHBve0e3Fo0WTR6Zn79F8fhEcVR94ap ycqAXdi/sB6zgWWVZeuJtuxuVOqOHD8RyYwT8LFsLNUtOaREwils1JRjE3dzaBno9d28 YbZfM7nYXZ/KBXFHAYiKEqtJQhSl3CAWwWv820YDqaHPgXIsdSSX6UKll7RqoG3ZNI8j AAhBY+C6jHlnFZ0Yau+7LWzjNv/vYXmaMwJjtVq5YNXm29xYj8Md00x/z19A74K9xJBX qpNLlM+bmco/nRHSiBjc00dtR5Ww5DcnULmP57ydAoZZK848l+a8mT6To0SEHALflc28 nx/g== X-Gm-Message-State: ALQs6tBcmATE+eq1UTDceUMXFbte51CrnnZdQqsYaj7IV4tXryQPAypO LvE0tRGYjo3sLR/x977KCcWVvENypQrxCMFVX4PvpQ== X-Google-Smtp-Source: AIpwx4/YjqiBgbNpMfCTPPo0hc0fu0DA9BsvpND+tjfY9eYWCXnsKoxKsVzJQ2xGaJHXVEHyCqGEUwhUhSg9O8mLW9Q= X-Received: by 10.101.85.202 with SMTP id k10mr16061381pgs.422.1524512442074; Mon, 23 Apr 2018 12:40:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.140.145 with HTTP; Mon, 23 Apr 2018 12:40:41 -0700 (PDT) In-Reply-To: References: From: Brijesh Singh Date: Mon, 23 Apr 2018 12:40:41 -0700 Message-ID: To: dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] rte_hash thread safe X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Apr 2018 19:40:43 -0000 A gentle reminder, I am curious to know if/how rte_hash is thread safe for lookups.It is not obvious to me how following code is thread safe: _rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig, void **data) { =E2=80=A6 if (rte_hash_cmp_eq(key, k->key, h) =3D=3D 0) { if (data !=3D NULL) *data =3D k->pdata; } a key could be deleted and another key inserted in its slot while the lookup is happening. For example, in the following sequence of events: The slot has Key1,V1 Lookup Thread T1 compares the input key to Key1 and it matches. The thread gets context switched out Thread T2 deletes Key1. Thread T2 inserts Key2 with value V2. T1 reads the data from the slot and returns V2. This is incorrect. Regards, Brijesh On Wed, Apr 11, 2018 at 9:12 PM, Brijesh Singh wrote: > Hello, > > I want to use DPDK's rte_hash library to keep track of tcp flows. The > lookups will be done by multiple threads but inserts will be done only > on one thread. > > As per the documentation rte_hash library has thread safe lookups. Key > /data inserts should be done on single thread, since those operations > are not thread safe. Is this documentation still correct? > > The lookup code compares the key and returns the data if the key > matches, this doesn't look like thread safe. Am I missing something? > > _rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, > > hash_sig_t sig, void **data) > > { > > > > =E2=80=A6 > > if (rte_hash_cmp_eq(key, k->key, h) =3D=3D 0) { > > if (data !=3D NULL) > > *data =3D k->pdata; > > } > > Regards, > Brijesh