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 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FD37C4829E for ; Thu, 15 Feb 2024 16:10:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F02BE10E9C0; Thu, 15 Feb 2024 16:10:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="lBUI+8GJ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7526D10E9C0 for ; Thu, 15 Feb 2024 16:10:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708013442; x=1739549442; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HAojpmusZ/MTgrIrGBsawHxEoFCs7UM8Nt+xkoZV+yI=; b=lBUI+8GJtTf7s1GNezWWkDW4yoJ/47yT70cTO1FRjzT+OyfMMZeoBvLO KBIAmAaZkQf5+OUxP982oWHNc9e/I4JO+th92OMy9PWmZ3sL5m0bvoWRc tuRN5LjFi3dJ6AZnnzSUZcXEU4f5eb4iLiB2AY5iCYwj9LVNXxBHo1x3o B0hq1ILx9f8blYlSQ5t9bbAd4sx32oKFJwzPkH4nW4BE4QQVAShTbdjBC m8GX+5/HlqW10CpyK6rD69EzQ2uith6SJlGNDohZBuIBeOpAznj3WsHNF NsHWGmH28ZbPMLzLK9O3CUKc1h+3CPwnlRg25Fdq8864u7SfeWJwmvFEh g==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="1982386" X-IronPort-AV: E=Sophos;i="6.06,162,1705392000"; d="scan'208";a="1982386" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 08:10:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,162,1705392000"; d="scan'208";a="3930525" Received: from unknown (HELO localhost) ([10.246.30.107]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 08:10:39 -0800 From: Kamil Konieczny To: igt-dev@lists.freedesktop.org Cc: =?UTF-8?q?Dominik=20Karol=20Pi=C4=85tkowski?= , =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Janusz Krzysztofik , Chris Wilson , Kamil Konieczny Subject: [PATCH i-g-t v9 4/7] lib/intel_multigpu: Introduced gem_multigpu_count_class and igt_multi_fork_foreach_gpu Date: Thu, 15 Feb 2024 17:10:11 +0100 Message-ID: <20240215161014.60304-5-kamil.konieczny@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240215161014.60304-1-kamil.konieczny@linux.intel.com> References: <20240215161014.60304-1-kamil.konieczny@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Dominik Karol Piątkowski Introduced gem_multigpu_count_class function that returns an actual number of GPUs present in system, which allows for writing multi-GPU test scenarios that does not require --device pci:vendor=intel,device=discrete,card=all to run as intended. Based on patch by Chris Wilson. Introduced igt_multi_fork_foreach_gpu macro that helps with writing multi-GPU test scenarios in idiomatic form: igt_multi_fork_foreach_gpu(i915, DRIVER_INTEL) test_function(i915); igt_waitchildren(); Cc: "Zbigniew Kempczyński" Cc: Janusz Krzysztofik Signed-off-by: "Dominik Karol Piątkowski" Signed-off-by: Chris Wilson Signed-off-by: Kamil Konieczny --- lib/intel_multigpu.c | 11 +++++++++++ lib/intel_multigpu.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/intel_multigpu.c b/lib/intel_multigpu.c index 34c9f936d..0e76d8aa3 100644 --- a/lib/intel_multigpu.c +++ b/lib/intel_multigpu.c @@ -3,10 +3,21 @@ * Copyright © 2023 Intel Corporation */ +#include "drmtest.h" #include "igt_core.h" #include "igt_device_scan.h" #include "intel_multigpu.h" +int gem_multigpu_count_class(int class) +{ + int count = 0; + + igt_foreach_gpu(fd, class) + count++; + + return count; +} + void gem_require_multigpu(int count) { struct igt_devices_print_format fmt = { diff --git a/lib/intel_multigpu.h b/lib/intel_multigpu.h index 98dc5a4ce..0ebc73e4a 100644 --- a/lib/intel_multigpu.h +++ b/lib/intel_multigpu.h @@ -6,6 +6,21 @@ #ifndef __INTEL_MULTIGPU_H #define __INTEL_MULTIGPU_H +#include "drmtest.h" +#include "igt_core.h" + void gem_require_multigpu(int count); +int gem_multigpu_count_class(int class); + +#define igt_foreach_gpu(fd__, id__) \ + for (int igt_unique(i) = 0, fd__; \ + (fd__ = __drm_open_driver_another(igt_unique(i)++, id__)) >= 0; \ + close(fd__)) + +#define igt_multi_fork_foreach_gpu(__fd, __id) \ + igt_multi_fork(igt_unique(__i), gem_multigpu_count_class(__id)) \ + for (int __fd = drm_open_driver_another(igt_unique(__i), __id); \ + __fd >= 0; \ + close(__fd), __fd = -1) \ #endif /* __INTEL_MULTIGPU_H */ -- 2.42.0