From: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 3/9] drm/xe: Introduce GuC Doorbells Manager
Date: Tue, 12 Dec 2023 08:51:33 +0100 [thread overview]
Message-ID: <20231212075133.we4ftkk54smmwlmm@intel.com> (raw)
In-Reply-To: <20231211200424.1703-4-michal.wajdeczko@intel.com>
Michal Wajdeczko <michal.wajdeczko@intel.com> wrote on pon [2023-gru-11 21:04:18 +0100]:
> The GFX doorbell solution provides a mechanism for submission of
> workload to the graphics hardware by a ring3 application without
> the penalty of ring transition for each workload submission.
>
> This feature is not currently used by the Linux drivers, but in
> SR-IOV mode the doorbells are treated as shared resource and the
> PF driver must be able to provision exclusive range of doorbells
> IDs across all enabled VFs.
>
> Introduce simple GuC doorbell ID manager that will be used by the
> PF driver for VFs provisioning and can later be used by submission
> code once we are ready to switch from H2G based notifications to
> doorbells mechanism.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
>
> ---
> v2: fix renames, lock in fini
> v3: reorder init
> ---
> drivers/gpu/drm/xe/Makefile | 1 +
> drivers/gpu/drm/xe/xe_guc_db_mgr.c | 257 +++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_guc_db_mgr.h | 22 +++
> drivers/gpu/drm/xe/xe_guc_types.h | 15 ++
> drivers/gpu/drm/xe/xe_uc.c | 5 +
> 5 files changed, 300 insertions(+)
> create mode 100644 drivers/gpu/drm/xe/xe_guc_db_mgr.c
> create mode 100644 drivers/gpu/drm/xe/xe_guc_db_mgr.h
>
> diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
> index f4ae063a7005..0c2e247dc188 100644
> --- a/drivers/gpu/drm/xe/Makefile
> +++ b/drivers/gpu/drm/xe/Makefile
> @@ -84,6 +84,7 @@ xe-y += xe_bb.o \
> xe_guc.o \
> xe_guc_ads.o \
> xe_guc_ct.o \
> + xe_guc_db_mgr.o \
> xe_guc_debugfs.o \
> xe_guc_hwconfig.o \
> xe_guc_log.o \
> diff --git a/drivers/gpu/drm/xe/xe_guc_db_mgr.c b/drivers/gpu/drm/xe/xe_guc_db_mgr.c
> new file mode 100644
> index 000000000000..15816f90e960
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_guc_db_mgr.c
> @@ -0,0 +1,257 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2023 Intel Corporation
> + */
> +
> +#include <linux/bitmap.h>
> +#include <linux/mutex.h>
> +
> +#include <drm/drm_managed.h>
> +
> +#include "regs/xe_guc_regs.h"
> +
> +#include "xe_assert.h"
> +#include "xe_gt_printk.h"
> +#include "xe_guc.h"
> +#include "xe_guc_db_mgr.h"
> +#include "xe_guc_types.h"
> +
> +/**
> + * DOC: GuC Doorbells
> + *
> + * The GFX doorbell solution provides a mechanism for submission of workload
> + * to the graphics hardware by a ring3 application without the penalty of
> + * ring transition for each workload submission.
> + *
> + * In SR-IOV mode, the doorbells are treated as shared resource and PF must
> + * be able to provision exclusive range of IDs across VFs, which may want to
> + * use this feature.
> + */
> +
> +static struct xe_guc *dbm_to_guc(struct xe_guc_db_mgr *dbm)
> +{
> + return container_of(dbm, struct xe_guc, dbm);
> +}
> +
> +static struct xe_gt *dbm_to_gt(struct xe_guc_db_mgr *dbm)
> +{
> + return guc_to_gt(dbm_to_guc(dbm));
> +}
> +
> +static struct xe_device *dbm_to_xe(struct xe_guc_db_mgr *dbm)
> +{
> + return gt_to_xe(dbm_to_gt(dbm));
> +}
> +
> +#define dbm_assert(_dbm, _cond) xe_gt_assert(dbm_to_gt(_dbm), _cond)
> +#define dbm_mutex(_dbm) (&dbm_to_guc(_dbm)->submission_state.lock)
> +
> +static void __fini_dbm(struct drm_device *drm, void *arg)
> +{
> + struct xe_guc_db_mgr *dbm = arg;
> + unsigned int weight;
> +
> + mutex_lock(dbm_mutex(dbm));
> +
> + weight = bitmap_weight(dbm->bitmap, dbm->count);
> + if (weight) {
> + struct drm_printer p = xe_gt_info_printer(dbm_to_gt(dbm));
> +
> + xe_gt_err(dbm_to_gt(dbm), "GuC doorbells manager unclean (%u/%u)\n",
> + weight, dbm->count);
> + xe_guc_db_mgr_print(dbm, &p, 1);
> + }
> +
> + bitmap_free(dbm->bitmap);
> + dbm->bitmap = NULL;
> + dbm->count = 0;
> +
> + mutex_unlock(dbm_mutex(dbm));
> +}
> +
> +/**
> + * xe_guc_db_mgr_init() - Initialize GuC Doorbells Manager.
> + * @dbm: the &xe_guc_db_mgr to initialize
> + * @count: number of doorbells to manage
> + *
> + * The bare-metal or PF driver can pass ~0 as &count to indicate that all
> + * doorbells supported by the hardware are available for use.
> + *
> + * Only VF's drivers will have to provide explicit number of doorbells IDs
> + * that they can use.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_guc_db_mgr_init(struct xe_guc_db_mgr *dbm, unsigned int count)
> +{
> + int ret;
> +
> + if (count == ~0)
> + count = GUC_NUM_DOORBELLS;
> +
> + dbm_assert(dbm, !dbm->bitmap);
> + dbm_assert(dbm, count <= GUC_NUM_DOORBELLS);
> +
> + if (!count)
> + goto done;
> +
> + dbm->bitmap = bitmap_zalloc(count, GFP_KERNEL);
> + if (!dbm->bitmap)
> + return -ENOMEM;
> + dbm->count = count;
> +
> + ret = drmm_add_action_or_reset(&dbm_to_xe(dbm)->drm, __fini_dbm, dbm);
> + if (ret)
> + return ret;
> +done:
> + xe_gt_dbg(dbm_to_gt(dbm), "using %u doorbell(s)\n", dbm->count);
> + return 0;
> +}
> +
> +static int dbm_reserve_chunk_locked(struct xe_guc_db_mgr *dbm,
> + unsigned int count, unsigned int spare)
> +{
> + unsigned int used;
> + int index;
> +
> + dbm_assert(dbm, count);
> + dbm_assert(dbm, count <= GUC_NUM_DOORBELLS);
> + dbm_assert(dbm, dbm->count <= GUC_NUM_DOORBELLS);
> + lockdep_assert_held(dbm_mutex(dbm));
> +
> + if (!dbm->count)
> + return -ENODATA;
> +
> + if (spare) {
> + used = bitmap_weight(dbm->bitmap, dbm->count);
> + if (used + count + spare > dbm->count)
> + return -EDQUOT;
> + }
> +
> + index = bitmap_find_next_zero_area(dbm->bitmap, dbm->count, 0, count, 0);
> + if (index >= dbm->count)
> + return -ENOSPC;
> +
> + bitmap_set(dbm->bitmap, index, count);
> +
> + return index;
> +}
> +
> +static void dbm_release_chunk_locked(struct xe_guc_db_mgr *dbm,
> + unsigned int start, unsigned int count)
> +{
> + dbm_assert(dbm, count);
> + dbm_assert(dbm, count <= GUC_NUM_DOORBELLS);
> + dbm_assert(dbm, dbm->count);
> + dbm_assert(dbm, dbm->count <= GUC_NUM_DOORBELLS);
> + lockdep_assert_held(dbm_mutex(dbm));
> +
> + if (IS_ENABLED(CONFIG_DRM_XE_DEBUG)) {
> + unsigned int n;
> +
> + for (n = 0; n < count; n++)
> + dbm_assert(dbm, test_bit(start + n, dbm->bitmap));
> + }
> + bitmap_clear(dbm->bitmap, start, count);
> +}
> +
> +/**
> + * xe_guc_db_mgr_reserve_id_locked() - Reserve a single GuC Doorbell ID.
> + * @dbm: the &xe_guc_db_mgr
> + *
> + * This function expects that submission lock is already taken.
> + *
> + * Return: ID of the allocated GuC doorbell or a negative error code on failure.
> + */
> +int xe_guc_db_mgr_reserve_id_locked(struct xe_guc_db_mgr *dbm)
> +{
> + return dbm_reserve_chunk_locked(dbm, 1, 0);
> +}
> +
> +/**
> + * xe_guc_db_mgr_release_id_locked() - Release a single GuC Doorbell ID.
> + * @dbm: the &xe_guc_db_mgr
> + * @id: the GuC Doorbell ID to release
> + *
> + * This function expects that submission lock is already taken.
> + */
> +void xe_guc_db_mgr_release_id_locked(struct xe_guc_db_mgr *dbm, unsigned int id)
> +{
> + return dbm_release_chunk_locked(dbm, id, 1);
> +}
> +
> +/**
> + * xe_guc_db_mgr_reserve_range() - Reserve a range of GuC Doorbell IDs.
> + * @dbm: the &xe_guc_db_mgr
> + * @count: number of GuC doorbell IDs to reserve
> + * @spare: number of GuC doorbell IDs to keep available
> + *
> + * This function is dedicated for the for use by the PF which expects that
> + * allocated range for the VF will be contiguous and that there will be at
> + * least &spare IDs still available for the PF use after this reservation.
> + *
> + * Return: starting ID of the allocated GuC doorbell ID range or
> + * a negative error code on failure.
> + */
> +int xe_guc_db_mgr_reserve_range(struct xe_guc_db_mgr *dbm,
> + unsigned int count, unsigned int spare)
> +{
> + int ret;
> +
> + mutex_lock(dbm_mutex(dbm));
> + ret = dbm_reserve_chunk_locked(dbm, count, spare);
> + mutex_unlock(dbm_mutex(dbm));
> +
> + return ret;
> +}
> +
> +/**
> + * xe_guc_db_mgr_release_range() - Release a range of Doorbell IDs.
> + * @dbm: the &xe_guc_db_mgr
> + * @start: the starting ID of GuC doorbell ID range to release
> + * @count: number of GuC doorbell IDs to release
> + */
> +void xe_guc_db_mgr_release_range(struct xe_guc_db_mgr *dbm,
> + unsigned int start, unsigned int count)
> +{
> + mutex_lock(dbm_mutex(dbm));
> + dbm_release_chunk_locked(dbm, start, count);
> + mutex_unlock(dbm_mutex(dbm));
> +}
> +
> +/**
> + * xe_guc_db_mgr_print() - Print status of GuC Doorbells Manager.
> + * @dbm: the &xe_guc_db_mgr to print
> + * @p: the &drm_printer to print to
> + * @indent: tab indentation level
> + */
> +void xe_guc_db_mgr_print(struct xe_guc_db_mgr *dbm,
> + struct drm_printer *p, int indent)
> +{
> + unsigned int rs, re;
> + unsigned int total;
> +
> + drm_printf_indent(p, indent, "count: %u\n", dbm->count);
> + if (!dbm->bitmap)
> + return;
> +
> + mutex_lock(dbm_mutex(dbm));
> +
> + total = 0;
> + for_each_clear_bitrange(rs, re, dbm->bitmap, dbm->count) {
> + drm_printf_indent(p, indent, "available range: %u..%u (%u)\n",
> + rs, re - 1, re - rs);
> + total += re - rs;
> + }
> + drm_printf_indent(p, indent, "available total: %u\n", total);
> +
> + total = 0;
> + for_each_set_bitrange(rs, re, dbm->bitmap, dbm->count) {
> + drm_printf_indent(p, indent, "reserved range: %u..%u (%u)\n",
> + rs, re - 1, re - rs);
> + total += re - rs;
> + }
> + drm_printf_indent(p, indent, "reserved total: %u\n", total);
> +
> + mutex_unlock(dbm_mutex(dbm));
> +}
> diff --git a/drivers/gpu/drm/xe/xe_guc_db_mgr.h b/drivers/gpu/drm/xe/xe_guc_db_mgr.h
> new file mode 100644
> index 000000000000..c250fa0ca9d6
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_guc_db_mgr.h
> @@ -0,0 +1,22 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2023 Intel Corporation
> + */
> +
> +#ifndef _XE_GUC_DB_MGR_H_
> +#define _XE_GUC_DB_MGR_H_
> +
> +struct drm_printer;
> +struct xe_guc_db_mgr;
> +
> +int xe_guc_db_mgr_init(struct xe_guc_db_mgr *dbm, unsigned int count);
> +
> +int xe_guc_db_mgr_reserve_id_locked(struct xe_guc_db_mgr *dbm);
> +void xe_guc_db_mgr_release_id_locked(struct xe_guc_db_mgr *dbm, unsigned int id);
> +
> +int xe_guc_db_mgr_reserve_range(struct xe_guc_db_mgr *dbm, unsigned int count, unsigned int spare);
> +void xe_guc_db_mgr_release_range(struct xe_guc_db_mgr *dbm, unsigned int start, unsigned int count);
> +
> +void xe_guc_db_mgr_print(struct xe_guc_db_mgr *dbm, struct drm_printer *p, int indent);
> +
> +#endif
> diff --git a/drivers/gpu/drm/xe/xe_guc_types.h b/drivers/gpu/drm/xe/xe_guc_types.h
> index cd80802e8918..16de203c62a7 100644
> --- a/drivers/gpu/drm/xe/xe_guc_types.h
> +++ b/drivers/gpu/drm/xe/xe_guc_types.h
> @@ -17,6 +17,19 @@
> #include "xe_guc_pc_types.h"
> #include "xe_uc_fw_types.h"
>
> +/**
> + * struct xe_guc_db_mgr - GuC Doorbells Manager.
> + *
> + * Note: GuC Doorbells Manager is relying on &xe_guc::submission_state.lock
> + * to protect its members.
> + */
> +struct xe_guc_db_mgr {
> + /** @count: number of doorbells to manage */
> + unsigned int count;
> + /** @bitmap: bitmap to track allocated doorbells */
> + unsigned long *bitmap;
> +};
> +
> /**
> * struct xe_guc - Graphic micro controller
> */
> @@ -31,6 +44,8 @@ struct xe_guc {
> struct xe_guc_ct ct;
> /** @pc: GuC Power Conservation */
> struct xe_guc_pc pc;
> + /** @dbm: GuC Doorbell Manager */
> + struct xe_guc_db_mgr dbm;
> /** @submission_state: GuC submission state */
> struct {
> /** @exec_queue_lookup: Lookup an xe_engine from guc_id */
> diff --git a/drivers/gpu/drm/xe/xe_uc.c b/drivers/gpu/drm/xe/xe_uc.c
> index 25e1ddfd2f86..4408ea1751e7 100644
> --- a/drivers/gpu/drm/xe/xe_uc.c
> +++ b/drivers/gpu/drm/xe/xe_uc.c
> @@ -9,6 +9,7 @@
> #include "xe_gsc.h"
> #include "xe_gt.h"
> #include "xe_guc.h"
> +#include "xe_guc_db_mgr.h"
> #include "xe_guc_pc.h"
> #include "xe_guc_submit.h"
> #include "xe_huc.h"
> @@ -60,6 +61,10 @@ int xe_uc_init(struct xe_uc *uc)
> if (ret)
> goto err;
>
> + ret = xe_guc_db_mgr_init(&uc->guc.dbm, ~0);
> + if (ret)
> + goto err;
> +
> return 0;
After the fixes you made, this series seems okay to me already:
Reviewed-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
>
> err:
> --
> 2.25.1
>
--
next prev parent reply other threads:[~2023-12-12 7:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 20:04 [PATCH v3 0/9] Introduce GuC Doorbells Manager Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 1/9] drm/xe: Add GT oriented drm_printers Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 2/9] drm/xe: Use GT oriented functions to report TLB timeout Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 3/9] drm/xe: Introduce GuC Doorbells Manager Michal Wajdeczko
2023-12-12 7:51 ` Piotr Piórkowski [this message]
2023-12-11 20:04 ` [PATCH v3 4/9] drm/xe/kunit: Set SR-IOV mode of the fake device Michal Wajdeczko
2023-12-12 4:57 ` Lucas De Marchi
2023-12-11 20:04 ` [PATCH v3 5/9] drm/xe/kunit: Define helper functions to allocate mock device Michal Wajdeczko
2023-12-12 5:09 ` Lucas De Marchi
2023-12-11 20:04 ` [PATCH v3 6/9] drm/xe/kunit: Use xe kunit helpers in RTP test Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 7/9] drm/xe/kunit: Use xe kunit helpers in WA test Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 8/9] drm/xe/kunit: Enable CONFIG_LOCKDEP in tests Michal Wajdeczko
2023-12-11 20:04 ` [PATCH v3 9/9] drm/xe/kunit: Add GuC Doorbells Manager tests Michal Wajdeczko
2023-12-12 8:04 ` Piotr Piórkowski
2023-12-11 23:09 ` ✓ CI.Patch_applied: success for Introduce GuC Doorbells Manager (rev3) Patchwork
2023-12-11 23:10 ` ✗ CI.checkpatch: warning " Patchwork
2023-12-11 23:11 ` ✓ CI.KUnit: success " Patchwork
2023-12-11 23:18 ` ✓ CI.Build: " Patchwork
2023-12-11 23:19 ` ✓ CI.Hooks: " Patchwork
2023-12-11 23:20 ` ✓ CI.checksparse: " Patchwork
2023-12-11 23:55 ` ✓ CI.BAT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231212075133.we4ftkk54smmwlmm@intel.com \
--to=piotr.piorkowski@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=michal.wajdeczko@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox