Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4215355imm; Wed, 30 May 2018 01:04:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLD7g+RbXGtuwndkzYyEagr3QjGHIRBob5kx/njlmqukt6SJl+5uO4LZaAbl7ofTpTPIrFc X-Received: by 2002:a17:902:b216:: with SMTP id t22-v6mr1829355plr.199.1527667474393; Wed, 30 May 2018 01:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527667474; cv=none; d=google.com; s=arc-20160816; b=Y1q4/UDmKKUfV0/zPwMMygTp5PYBtF2QHo9v0BNWiNDlcJkNZTUrTYFa8F5Bqv1zGt 1yfzIEuGUs1zIK4qXhkQcgAV+hH+OCH9NdagrmHlxaPJl17Poafd2Q+2v3KXnFn7DIWA ngTDGE6kBRFoA9PbJWIo1O5Z1PAOpz+F/1R5k0FjQYuYipUyhS+DFYyGI2S5KyTbu2Ib P/4ypyrgWdT0xGdvzQJHmfCq1aQA5sJnwYed88S6e7uKlDiEn8baJSc7jTPnUympsAeP 9XCO2S4pEXZWCRDQMuFq5A4gyzxkw8GjJwWUKPqAuKJ7fP9g3GgGPNUiHQIJGkvWVkuy CJ/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature:arc-authentication-results; bh=h4EIiTrXGr59sA+zxs66wJj8orpo36NsGNOs7DQBFCI=; b=w/5JVH+iPOb6qAE1c2NUyHTwVDA0j4mKmw2HNkR7y1JN4BD6vfER7i9J9F/uxCGMh5 FqcN/uW91cbTLLvhjhaGdqeuU64HTm7rAlRObwiloL0p5DAD6ihKArmEWl66j41LYcYw 7qL9tC+Xo/UscBYjjKXK58ABzp/Grf4v8hqzTN4CHcfsbrfkByoxvOpLoRNTo2pKjORn 8xjJRxHDzGtvrMczsIPiy0SqNsV5BnRl9OJBk8DOlpXG6luS6W/9RSp8z5J9P9dv6Tua j+f0t8uR+S3zCmDGeHSkF8T2l5RBBFg642m1YHuj0EzAKR974BcN2+HkxtkPSl/izT5X o/hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dev-mellanox-co-il.20150623.gappssmtp.com header.s=20150623 header.b=Rk1JMxMr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.co.il Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h189-v6si9620331pge.266.2018.05.30.01.04.20; Wed, 30 May 2018 01:04:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@dev-mellanox-co-il.20150623.gappssmtp.com header.s=20150623 header.b=Rk1JMxMr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.co.il Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935991AbeE3ICd (ORCPT + 99 others); Wed, 30 May 2018 04:02:33 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:37953 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935939AbeE3ICW (ORCPT ); Wed, 30 May 2018 04:02:22 -0400 Received: by mail-wm0-f66.google.com with SMTP id m129-v6so45796222wmb.3 for ; Wed, 30 May 2018 01:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=h4EIiTrXGr59sA+zxs66wJj8orpo36NsGNOs7DQBFCI=; b=Rk1JMxMr3jxROLVz3mrxa620a1qlZKsIeDvsmFW7Eg1YZIcMJ0DtisCstMan39w4/9 gl6dWWBcz21KSkXVY2qVBwdicI+2Ld+sshbBUvEK/k9uTIns2eEZSzy4PQAX/fNRW/yc lmFoyD88b8v++3lsx+qJy7z0LwchEA3XuY+cW58lEq59W51w70nP2PCBYu8VzTFTuncJ h0hRebyoR+7nwUtl+ZKbwDROVBNRx9WMuPssx8LLjMEOrYELxC1jh1TsFJCD3pyuufv9 1hf132NAxY1zmLPpNKybd5kAUMPMlqvgWrxShvU8Lyim7N2c2r67+GH3gMRQlYkMUoSu fqkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=h4EIiTrXGr59sA+zxs66wJj8orpo36NsGNOs7DQBFCI=; b=r++piPp9GMBjgX2ehYgUmtaVtHVg+sA8QDuMp3sFIG6UMVYMsuhD2gy6/a4XSzNCkL 0ZAz8l/ByjX7213RE5X2rCz6Bk4R+Xumiv7cYVU77EiqAAysX5Th58oH7I139g7SFRR1 /2R4nYBApK2GXFOLDEyH1tcsSxeC7qGISnJOnBdRSTu8v5iAJz4umVs9t3pnQTD/8TIk 0+8MR8EgejvK+GYLNdMv/25iIvsfZXBD40Td9q+bWNvRylepQ29pA/Zk3v6bX8mn+RyQ ioz8MoMYC4xJTxasvhEju3blGtEHiSuqSKSTUDuVnO3Bya7ZoXhBdIEVHZuh87mwWSls F/Iw== X-Gm-Message-State: ALKqPweCEsw+vinLnuOGMk+ccAgWqfLpGKudBmus4OmTUJJgbyWmmbVy mgrpAAHtJnZD57osqqDcg/8f1g== X-Received: by 2002:a1c:e906:: with SMTP id q6-v6mr666676wmc.23.1527667340818; Wed, 30 May 2018 01:02:20 -0700 (PDT) Received: from localhost ([188.120.148.224]) by smtp.gmail.com with ESMTPSA id t46-v6sm43190145wrc.95.2018.05.30.01.02.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 01:02:19 -0700 (PDT) Date: Wed, 30 May 2018 11:02:16 +0300 From: jackm To: Jason Gunthorpe Cc: =?ISO-8859-1?Q?H=E5kon?= Bugge , Hans Westgaard Ry , Doug Ledford , Daniel Jurgens , Parav Pandit , Pravin Shedge , OFED mailing list , linux-kernel@vger.kernel.org, Leon Romanovsky Subject: Re: [PATCH] IB/mad: Use ID allocator routines to allocate agent number Message-ID: <20180530110216.00000913@dev.mellanox.co.il> In-Reply-To: <20180529164032.GB18457@ziepe.ca> References: <20180529073808.27735-1-hans.westgaard.ry@oracle.com> <20180529154922.GA18457@ziepe.ca> <20180529164032.GB18457@ziepe.ca> Organization: Mellanox X-Mailer: Claws Mail 3.15.0 (GTK+ 2.24.31; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 29 May 2018 10:40:32 -0600 Jason Gunthorpe wrote: > On Tue, May 29, 2018 at 06:16:14PM +0200, H=E5kon Bugge wrote: > > =20 > > > On 29 May 2018, at 17:49, Jason Gunthorpe wrote: > > >=20 > > > On Tue, May 29, 2018 at 09:38:08AM +0200, Hans Westgaard Ry > > > wrote: =20 > > >> The agent TID is a 64 bit value split in two dwords. The least > > >> significant dword is the TID running counter. The most > > >> significant dword is the agent number. In the CX-3 shared port > > >> model, the mlx4 driver uses the most significant byte of the > > >> agent number to store the slave number, making agent numbers > > >> greater and equal to 2^24 (3 bytes) unusable. =20 > > >=20 > > > There is no reason for this to be an ida, just do something like > > >=20 > > > mad_agent_priv->agent.hi_tid =3D > > > atomic_inc_return(&ib_mad_client_id) & > > > mad_agent_priv->ib_dev->tid_mask; > > >=20 > > > And have the driver set tid_mask to 3 bytes of 0xFF =20 > >=20 > > The issue is that some of the mad agents are long-lived, so you will > > wrap and use the same TID twice. =20 >=20 > We already have that problem, and using ida is problematic because we > need to maximize the time between TID re-use, which ida isn't doing. >=20 > Preventing re-use seems like a seperate issue from limiting the range > to be compatible with mlx4. >=20 Preventing immediate re-use can be accomplished by judicious use of the start argument (second argument) in the call to ida_simple_get (to introduce hysteresis into the id allocations). For example, can do something like: static atomic_t ib_mad_client_id_min =3D ATOMIC_INIT(1); ... ib_mad_client_id =3D ida_simple_get(&ib_mad_client_ids, atomic_read(&ib_mad_client_id_min= ), ib_mad_sysctl_client_id_max, GFP_KERNEL); .... if (!(ib_mad_client_id % 1000) || ib_mad_sysctl_client_id_max - ib_mad_client_id <=3D 1000) atomic_set(&ib_mad_client_id_min, 1); else atomic_set(&ib_mad_client_id_min, ib_mad_client_id + 1); The above avoids immediate re-use of ids, and only searches for past freed ids if the last allocated-id is zero mod 1000. This is just suggestion -- will probably need some variation of the above to handle what happens over time (i.e., to not depend on the modulo operation to reset the search start to 1), to properly handle how we deal with the start value when we are close to the allowed client_id_max, and also to implement some sort of locking. -Jack