Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2001346ybi; Thu, 18 Jul 2019 01:49:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyA1TFax+aYNR8JR3fwSNvL08uhSyfRfHPHtozOX3rIRC+VLc3fiqKwHqlCOG5NCZXM+FTi X-Received: by 2002:a17:902:20c8:: with SMTP id v8mr49017994plg.284.1563439755300; Thu, 18 Jul 2019 01:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563439755; cv=none; d=google.com; s=arc-20160816; b=lxWc6lwVKix7q2V9M2CbVwY6N9pa5C00I1aRaYlbzlLFC/E0G2tMvR1lvXC/fAWWGJ D47bbgTpggrkpCCwZ8qz1tFwFanw/PciRaEupsNtMtG3LyPRU8hdlfRtgoYSM90o7Q4P MwDEaJAsAI8mAxbE6AZ86+0ax1v4o0pBXXqu6YzeJlCCTRb2Cd3tKhEpfm7U/sUl1I3+ m222wMx4GxSeafVBaHrwp6PYvBqVeUfc81sXMg/3DJwbu3K/B7uXxBgF5JGyGouJZR/u iA9DMf1eBEnLhO+TjPqRL+RKVpiEUL+oaPlQ1mhkQtqbyGbMf6Ml8DDNGdZEd8LHkjIQ wfJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=SuXqyPAcJbV/ZT1YP0LMBniVGMFj3t4c1tGQ9Lrmu74=; b=mkMf7WdXdaF9F1C73wwpxoddlSSth7H++Ky3+NMWYaUu5vHhmmsXBji2NC19GNhZMO YWYxcCvqtgla1u+/+GsXIiTWUJCetDsgcvRP7d3i6+KvARKrj7miveOPm/kHlra8g59N pjMmMahwnNMhDFxppKRSlQTrz+NDhgI71TA2zBOLfvSoQVF3D6o/aQNJ9WLvZyur+M6z F0ux/odGvP93378AoFPa7BEMXRB/g6zpHE2dUBM999yZp6C2vupkTYo22/j+26Ac3d31 kTnIfqNZopOPj/0QvkmzEut9d5EkQC9TOSWNDz1vFTmUs0dZB92nnroUvQGc4K9zpNCr zrRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o0ovaDdo; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12si1574408pjq.63.2019.07.18.01.48.59; Thu, 18 Jul 2019 01:49:15 -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=@gmail.com header.s=20161025 header.b=o0ovaDdo; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733131AbfGRIsd (ORCPT + 99 others); Thu, 18 Jul 2019 04:48:33 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36590 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbfGRIsd (ORCPT ); Thu, 18 Jul 2019 04:48:33 -0400 Received: by mail-wr1-f65.google.com with SMTP id n4so27778416wrs.3 for ; Thu, 18 Jul 2019 01:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SuXqyPAcJbV/ZT1YP0LMBniVGMFj3t4c1tGQ9Lrmu74=; b=o0ovaDdoMLzcTFBPoX+4wzYH2fkIPrs06qPfxO1GtR+XypODgS8FRLw0QubfjsX5DU 9lJALk4N6kdYSmyY5ncK2rGEjV6geOxKjDmkWfHem/pnJWbVbrnYcgmVcFdyRJbBUcpc +oXbM+yaJLF20zkSFV8G1Rba/bC5ClQstg7nXHNhl7x+M2rO96tzgVc/cNRFMypI4V58 SzupPQPbzHfZgY+gdyPNnEXD6QzdawHoe1HZqOtFRI3uQaV8CkN8PQCiJ0oE49+n7Mgw V0sntcIxc3Qg+ru1qyuiamGmdeOw8yAR+ILuZeaRREgzJxPwnybxS7P7yEVp09rt7hWI lTkg== 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; bh=SuXqyPAcJbV/ZT1YP0LMBniVGMFj3t4c1tGQ9Lrmu74=; b=kevwKU9JQA32ZpywfXBOFmKZEw4udbYNbR+mIGN8wj9ZAnzkNpHc2IPyVcs2pnq2Nr 0pm623TgekGrkZThcaz0yV7uV/QIeSOq4cqTs3A+a8jgWt0ud0bzPt6f/h4CuElCG9lK PirLifu+XQAD/It6OohW8AubjyQkWh1Is63pe8u8N1uTKtY7OmQo6mbYuHFBb5VrYINP 7EDtFVnar0Wz2WOSViNp8YIdAb0EZ5v9bSZM1WWcu5mnVZ2Z2kdChV3Zerr+j9FBI9fv Ie+MQhsxdyu2z+uYlQqBDoGrlEeeLRBBLwWL0Elh2BMm4LdMfkziay1qvxDKiti7LO8v iP/A== X-Gm-Message-State: APjAAAXq2LxXR9CR4WwNWzXlaKmawiO2OHstGmx2III1EjX3GhZo0XWu OcrR5FZku5kU8/At0SQ13CoGSqcj X-Received: by 2002:adf:ca0f:: with SMTP id o15mr48446748wrh.135.1563439710707; Thu, 18 Jul 2019 01:48:30 -0700 (PDT) Received: from ogabbay-VM.habana-labs.com ([31.154.190.6]) by smtp.gmail.com with ESMTPSA id u2sm24855896wmc.3.2019.07.18.01.48.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 01:48:30 -0700 (PDT) From: Oded Gabbay To: linux-kernel@vger.kernel.org, oshpigelman@habana.ai, ttayar@habana.ai Cc: gregkh@linuxfoundation.org Subject: [PATCH] habanalabs: cap simulator timeout Date: Thu, 18 Jul 2019 11:48:28 +0300 Message-Id: <20190718084828.8581-1-oded.gabbay@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the driver timeout functions, we give the simulator a factor of 10 in the timeout. This was necessary when the requested timeout is small but if it was a few seconds, this can result in a very large timeout which is unnecessary. This patch caps the maximum timeout of the simulator to 10 seconds, which is our largest timeout in the code. That is more then enough for anything the simulator is doing. Signed-off-by: Oded Gabbay --- drivers/misc/habanalabs/habanalabs.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/misc/habanalabs/habanalabs.h b/drivers/misc/habanalabs/habanalabs.h index 10da9940ee0d..57183ae9b95d 100644 --- a/drivers/misc/habanalabs/habanalabs.h +++ b/drivers/misc/habanalabs/habanalabs.h @@ -36,6 +36,8 @@ #define HL_PCI_ELBI_TIMEOUT_MSEC 10 /* 10ms */ +#define HL_SIM_MAX_TIMEOUT_US 10000000 /* 10s */ + #define HL_MAX_QUEUES 128 #define HL_MAX_JOBS_PER_CS 64 @@ -1036,14 +1038,18 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | \ (val) << REG_FIELD_SHIFT(reg, field)) +/* Timeout should be longer when working with simulator but cap the + * increased timeout to some maximum + */ #define hl_poll_timeout(hdev, addr, val, cond, sleep_us, timeout_us) \ ({ \ ktime_t __timeout; \ - /* timeout should be longer when working with simulator */ \ if (hdev->pdev) \ __timeout = ktime_add_us(ktime_get(), timeout_us); \ else \ - __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \ + __timeout = ktime_add_us(ktime_get(),\ + min((u64)(timeout_us * 10), \ + (u64) HL_SIM_MAX_TIMEOUT_US)); \ might_sleep_if(sleep_us); \ for (;;) { \ (val) = RREG32(addr); \ @@ -1067,11 +1073,12 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); #define hl_poll_timeout_memory(hdev, addr, val, cond, sleep_us, timeout_us) \ ({ \ ktime_t __timeout; \ - /* timeout should be longer when working with simulator */ \ if (hdev->pdev) \ __timeout = ktime_add_us(ktime_get(), timeout_us); \ else \ - __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \ + __timeout = ktime_add_us(ktime_get(),\ + min((u64)(timeout_us * 10), \ + (u64) HL_SIM_MAX_TIMEOUT_US)); \ might_sleep_if(sleep_us); \ for (;;) { \ /* Verify we read updates done by other cores or by device */ \ @@ -1093,11 +1100,12 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); timeout_us) \ ({ \ ktime_t __timeout; \ - /* timeout should be longer when working with simulator */ \ if (hdev->pdev) \ __timeout = ktime_add_us(ktime_get(), timeout_us); \ else \ - __timeout = ktime_add_us(ktime_get(), (timeout_us * 10)); \ + __timeout = ktime_add_us(ktime_get(),\ + min((u64)(timeout_us * 10), \ + (u64) HL_SIM_MAX_TIMEOUT_US)); \ might_sleep_if(sleep_us); \ for (;;) { \ (val) = readl(addr); \ -- 2.17.1