From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51865C43381 for ; Thu, 28 Feb 2019 06:59:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1541A21850 for ; Thu, 28 Feb 2019 06:59:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="NWFgSJm6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731263AbfB1G7p (ORCPT ); Thu, 28 Feb 2019 01:59:45 -0500 Received: from mail-eopbgr130081.outbound.protection.outlook.com ([40.107.13.81]:53176 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731175AbfB1G7n (ORCPT ); Thu, 28 Feb 2019 01:59:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Xw2Hhfp3+7ol98T+VRNJmzQ4+fHr9hEdGAlnFVyMdOs=; b=NWFgSJm6OYgz/QH4Je5SCTLt8WnJ7nTNSBSRiVGf7NzQEJ9VfIPVviw4JUwQvgGm0OlDkwKfOuH59IJW/uQC0hwYTbUmVgVxoPKUmJwWUf3kdg/m/whY6ysR632K9eZndLxTIbzr7swbu3IHO7HSnOrIvRbK/+ZIhSYnbBg0gnA= Received: from AM6PR05MB5240.eurprd05.prod.outlook.com (20.177.196.214) by AM6PR05MB5411.eurprd05.prod.outlook.com (20.177.189.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.16; Thu, 28 Feb 2019 06:59:25 +0000 Received: from AM6PR05MB5240.eurprd05.prod.outlook.com ([fe80::458c:8deb:ca54:1327]) by AM6PR05MB5240.eurprd05.prod.outlook.com ([fe80::458c:8deb:ca54:1327%2]) with mapi id 15.20.1665.015; Thu, 28 Feb 2019 06:59:25 +0000 From: Ido Schimmel To: "netdev@vger.kernel.org" CC: "davem@davemloft.net" , Jiri Pirko , mlxsw , Ido Schimmel Subject: [PATCH net-next 12/14] mlxsw: spectrum_acl: Allow to interrupt/continue rehash work Thread-Topic: [PATCH net-next 12/14] mlxsw: spectrum_acl: Allow to interrupt/continue rehash work Thread-Index: AQHUzzMkCMcwYg6aakeXR68fLRq/Dg== Date: Thu, 28 Feb 2019 06:59:25 +0000 Message-ID: <20190228065850.7471-13-idosch@mellanox.com> References: <20190228065850.7471-1-idosch@mellanox.com> In-Reply-To: <20190228065850.7471-1-idosch@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR08CA0025.eurprd08.prod.outlook.com (2603:10a6:20b:c0::13) To AM6PR05MB5240.eurprd05.prod.outlook.com (2603:10a6:20b:64::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=idosch@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c9bcb26e-d5b3-420e-5568-08d69d4a467c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM6PR05MB5411; x-ms-traffictypediagnostic: AM6PR05MB5411: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1;AM6PR05MB5411;23:4kTVBrIpctNv1FB6Y2pXy5pv8DoZneAaHMvzkFY?= =?iso-8859-1?Q?c9LfRRsoXHxJYrYKVMAwyqqbGR+GWzMkW3iY0+D8WHK8aV1csS9+yM6oNO?= =?iso-8859-1?Q?kYDSiBU/8NtxQRIkjBNwNCACZEZw5nGEyDNwDeHY2MMlCqjmofHID1ILI/?= =?iso-8859-1?Q?Nq7iVgfiggfvIrZuGvPfd0GMpD1JslznEKbZRWODXkw4TbnSWC+ahXtTXv?= =?iso-8859-1?Q?xt+AXnvyYZlH58Zpdk7fI677nIPITj6xfkb6GQZg6B4PePv3VzwtvxVZLd?= =?iso-8859-1?Q?vztQuddRo7vIFkLQvJQiRLDJGON9G/d5nfPUQVFcNRiEYqg9KFDFtclAoH?= =?iso-8859-1?Q?ZwhnMvqiWi6BJJO4E9pyOU8rVFZrrTKM1wYBcbuzggZ3Q8GJkGBMGbUCUV?= =?iso-8859-1?Q?+ABjUf/QY8iYsqoRJ24J82k3YH2ub85oHOzQVaKzuxWTcUwXmKyYR6WsfL?= =?iso-8859-1?Q?tj69FdN0p/+QDBmnKMAiIhV2GQl3GxPyj+AJASEiZhBsQAKTBUB1yKPNiJ?= =?iso-8859-1?Q?IqDKoKWOIApC6yht5wJ7NDGKZrdJjNbK/ZFk+vrLJSJj049R4YksZEv4Rs?= =?iso-8859-1?Q?Q0G1LZYql/jecRkDupHMAz3T6tAtlMIqSsIffh+jycAofS0RyT2OP0q/2q?= =?iso-8859-1?Q?Qeo+IdsupwAw0qTtutzePWCfq2yiks5OhoLm0K7L+dZaRlw+HoYVrYa/MY?= =?iso-8859-1?Q?SZFVR3mYYmvL/N0venFOTeKenIyYMMd5QNeck1Eh0yTLWwD7/sPczpu5oN?= =?iso-8859-1?Q?CRv/7Z/VqL/0l/7IwtomRNye8umCC4O0ZJhvXY3HQF+CksQPgTcO8GTj0Y?= =?iso-8859-1?Q?6dSlLrslQTM4eGz6wS7u20ooxkg5/uh1Phjjr7Nkp1n5Tlb7t2To5SH3n6?= =?iso-8859-1?Q?FF9J6yJsLoVtQjxqBGBG2SdewPdrss46uJxqcWumE1Y9Jt40s7+ypNiiWz?= =?iso-8859-1?Q?g3kJLD1j4cdBlYwSW+VfLN5ckQ2zb1i05AaXaXkIIP0ssQ7YiSgfT2yWN2?= =?iso-8859-1?Q?kU3NLn5K/O0zfwu2NOZ2CWbLVUtU/yogb+IXXYgWdy/+tLdeO/8fTPtWvr?= =?iso-8859-1?Q?L2FOBVM5FdvvZL4/GHivp+Mmc1iXYX8VvwGWxFxZ+WNyiv0MM4Igo/zlLX?= =?iso-8859-1?Q?4G3XCxKCEVNukncf7P9Ai9lYiSqQETbaeZ3CENO0AgozN2sdWyjRsoiMgc?= =?iso-8859-1?Q?nkcTrsa/9/k+N2GckZ+qLdcPLA5Q+LVHSodZjmOA3ms/cisMCWmO5vtqrm?= =?iso-8859-1?Q?niJ+qP+0Cq1ta3yuVsnsI5W2QUOW35t+W1GXlB9EBOanM1nCNT49aTVS/y?= =?iso-8859-1?Q?bfbbXY9NKRO5lwn5dGHeq2JWP3WyxRBp9mNFG6JVFQKKaC0FBEIxY5npVS?= =?iso-8859-1?Q?U4Xp3BjQ7nl6d9eukOdLVya3efEQm?= x-microsoft-antispam-prvs: x-forefront-prvs: 0962D394D2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(39860400002)(136003)(396003)(346002)(199004)(189003)(5640700003)(6486002)(6436002)(14454004)(478600001)(2351001)(107886003)(4326008)(68736007)(25786009)(97736004)(386003)(6506007)(11346002)(446003)(2616005)(26005)(102836004)(486006)(476003)(186003)(2501003)(14444005)(256004)(5660300002)(1076003)(71190400001)(71200400001)(76176011)(52116002)(8936002)(1730700003)(8676002)(81156014)(81166006)(50226002)(6916009)(99286004)(36756003)(6512007)(86362001)(6116002)(3846002)(105586002)(106356001)(54906003)(53936002)(66066001)(7736002)(316002)(305945005)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR05MB5411;H:AM6PR05MB5240.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: A0tHwq6vHbGL2vAosruPnJGU52kOnwdK7n/1YDT8gGlqD1aNgQs0klGNn6EJsHSB/Ke9A6liCsAiMaDtbG07LxZfQgbyM4r6XG7B6L1hjG1xVAyyyFSYFApUTOFqbEU1746aHdFW8lQA2Kpc2KTGJAg0tNWSjpT9AONCWZW+C7q5cM8n+zhN70vGpQEuCkzg2Qtav+wXFBQhQZ0tdHi+Hc+UnwZedRkElPDtSGCe8XsGbGClrQ4Aj9colhpkNEzZ63mBQMwqntilCCjwG4dt9uxAO3LAgDQz2VzyXELvmPvF1JNBMafQoUBMBPLyvIKDfV/6afdxnhDQDdrz8cF2bcYaoQLdM+nM9CjZAouPBPJNdsqVRgA+mQkSpIOJmke6+ufuf+uyy6gDyMaJQmhstLbB8qPKo/W62O5NIHyqE7g= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9bcb26e-d5b3-420e-5568-08d69d4a467c X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Feb 2019 06:59:25.7829 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB5411 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Currently, migration of vregions with many entries may take long time during which insertions and removals of the rules are blocked due to wait to acquire vregion->lock. To overcome this, allow to interrupt and continue rehash work according to the set credits - number of rules to migrate. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/spectrum_acl_tcam.c | 82 ++++++++++++++----- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/driv= ers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 9dc83815644e..cfd05af3f0f6 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -27,6 +27,7 @@ size_t mlxsw_sp_acl_tcam_priv_size(struct mlxsw_sp *mlxsw= _sp) =20 #define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT 5000 /* ms */ #define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN 3000 /* ms */ +#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS 100 /* number of entries = */ =20 int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam *tcam) @@ -732,16 +733,26 @@ mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(struct= mlxsw_sp_acl_tcam_vregion =20 static int mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_acl_tcam_vregion *vregion); + struct mlxsw_sp_acl_tcam_vregion *vregion, + int *credits); =20 static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work= ) { struct mlxsw_sp_acl_tcam_vregion *vregion =3D container_of(work, struct mlxsw_sp_acl_tcam_vregion, rehash.dw.work); + int credits =3D MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS; + int err; =20 - mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, vregion); - mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion); + err =3D mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, + vregion, &credits); + if (credits < 0) + /* Rehash gone out of credits so it was interrupted. + * Schedule the work as soon as possible to continue. + */ + mlxsw_core_schedule_dw(&vregion->rehash.dw, 0); + else + mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion); } =20 static struct mlxsw_sp_acl_tcam_vregion * @@ -1176,7 +1187,8 @@ mlxsw_sp_acl_tcam_ventry_activity_get(struct mlxsw_sp= *mlxsw_sp, static int mlxsw_sp_acl_tcam_ventry_migrate(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_ventry *ventry, - struct mlxsw_sp_acl_tcam_chunk *chunk) + struct mlxsw_sp_acl_tcam_chunk *chunk, + int *credits) { struct mlxsw_sp_acl_tcam_entry *new_entry; =20 @@ -1184,6 +1196,9 @@ mlxsw_sp_acl_tcam_ventry_migrate(struct mlxsw_sp *mlx= sw_sp, if (ventry->entry->chunk =3D=3D chunk) return 0; =20 + if (--(*credits) < 0) + return 0; + new_entry =3D mlxsw_sp_acl_tcam_entry_create(mlxsw_sp, ventry, chunk); if (IS_ERR(new_entry)) return PTR_ERR(new_entry); @@ -1223,7 +1238,8 @@ static int mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vchunk *vchunk, struct mlxsw_sp_acl_tcam_region *region, - struct mlxsw_sp_acl_tcam_rehash_ctx *ctx) + struct mlxsw_sp_acl_tcam_rehash_ctx *ctx, + int *credits) { struct mlxsw_sp_acl_tcam_ventry *ventry; int err; @@ -1240,7 +1256,7 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp = *mlxsw_sp, =20 list_for_each_entry(ventry, &vchunk->ventry_list, list) { err =3D mlxsw_sp_acl_tcam_ventry_migrate(mlxsw_sp, ventry, - vchunk->chunk); + vchunk->chunk, credits); if (err) { if (ctx->this_is_rollback) return err; @@ -1250,6 +1266,11 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp= *mlxsw_sp, */ swap(vchunk->chunk, vchunk->chunk2); return err; + } else if (*credits < 0) { + /* We are out of credits, the rest of the ventries + * will be migrated later. + */ + return 0; } } =20 @@ -1260,7 +1281,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp = *mlxsw_sp, static int mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion, - struct mlxsw_sp_acl_tcam_rehash_ctx *ctx) + struct mlxsw_sp_acl_tcam_rehash_ctx *ctx, + int *credits) { struct mlxsw_sp_acl_tcam_vchunk *vchunk; int err; @@ -1268,8 +1290,8 @@ mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp = *mlxsw_sp, list_for_each_entry(vchunk, &vregion->vchunk_list, list) { err =3D mlxsw_sp_acl_tcam_vchunk_migrate_one(mlxsw_sp, vchunk, vregion->region, - ctx); - if (err) + ctx, credits); + if (err || *credits < 0) return err; } return 0; @@ -1278,13 +1300,15 @@ mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_s= p *mlxsw_sp, static int mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion, - struct mlxsw_sp_acl_tcam_rehash_ctx *ctx) + struct mlxsw_sp_acl_tcam_rehash_ctx *ctx, + int *credits) { int err, err2; =20 trace_mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion); mutex_lock(&vregion->lock); - err =3D mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx); + err =3D mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, + ctx, credits); if (err) { /* In case migration was not successful, we need to swap * so the original region pointer is assigned again @@ -1292,7 +1316,8 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *ml= xsw_sp, */ swap(vregion->region, vregion->region2); ctx->this_is_rollback =3D true; - err2 =3D mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, ctx); + err2 =3D mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion, + ctx, credits); if (err2) vregion->failed_rollback =3D true; } @@ -1301,6 +1326,12 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *m= lxsw_sp, return err; } =20 +static bool +mlxsw_sp_acl_tcam_vregion_rehash_in_progress(const struct mlxsw_sp_acl_tca= m_rehash_ctx *ctx) +{ + return ctx->hints_priv; +} + static int mlxsw_sp_acl_tcam_vregion_rehash_start(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion, @@ -1372,19 +1403,28 @@ mlxsw_sp_acl_tcam_vregion_rehash_end(struct mlxsw_s= p *mlxsw_sp, =20 static int mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_acl_tcam_vregion *vregion) + struct mlxsw_sp_acl_tcam_vregion *vregion, + int *credits) { struct mlxsw_sp_acl_tcam_rehash_ctx *ctx =3D &vregion->rehash.ctx; int err; =20 - err =3D mlxsw_sp_acl_tcam_vregion_rehash_start(mlxsw_sp, vregion, ctx); - if (err) { - if (err !=3D -EAGAIN) - dev_err(mlxsw_sp->bus_info->dev, "Failed get rehash hints\n"); - return err; + /* Check if the previous rehash work was interrupted + * which means we have to continue it now. + * If not, start a new rehash. + */ + if (!mlxsw_sp_acl_tcam_vregion_rehash_in_progress(ctx)) { + err =3D mlxsw_sp_acl_tcam_vregion_rehash_start(mlxsw_sp, + vregion, ctx); + if (err) { + if (err !=3D -EAGAIN) + dev_err(mlxsw_sp->bus_info->dev, "Failed get rehash hints\n"); + return err; + } } =20 - err =3D mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion, ctx); + err =3D mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion, + ctx, credits); if (err) { dev_err(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n"); if (vregion->failed_rollback) { @@ -1394,7 +1434,9 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlx= sw_sp, } } =20 - mlxsw_sp_acl_tcam_vregion_rehash_end(mlxsw_sp, vregion, ctx); + if (*credits >=3D 0) + mlxsw_sp_acl_tcam_vregion_rehash_end(mlxsw_sp, vregion, ctx); + return err; } =20 --=20 2.20.1