From nobody Tue Feb 14 18:23:54 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PGV2y5PS5z3ppCM; Tue, 14 Feb 2023 18:23:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PGV2y4qkvz3kJG; Tue, 14 Feb 2023 18:23:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676399034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SwpJVWVPLvH8jMW6liC1szJUQCycjz6FDL4TtLYX5yU=; b=cyIxlMT9mJ9EBYIzBLwZUMGxlMtbzVsaj0MUyWcf0cFJBxAYhiZxZPgTKWSiskrk0rVEQm 2BmVu+LwQYJggTtTGgJ9DAANgMhqd1JMfznjBOkGGgXqzE025cVi5HJwSksA+qqi6ymF6e yvabbP5mG7UI0otzvaEr2dEtclAz5f00gwuEf+yqQr5+AqRGyVpeNkOlXc9ResZsxGOXfa GpaNc2b0Pt6xyvFKePvOJ/pAvYPf9s8NJe5OUWskckvshd1yGIyP+E9MlGv/5uU6ilB/Zg 3z/ltmPdVzKTnoteKAw62tHCax4bXmWZOEfBZpF6wr7EoGNkqRwvxE4ZpyZULw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676399034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SwpJVWVPLvH8jMW6liC1szJUQCycjz6FDL4TtLYX5yU=; b=PFfRlePlH2WjuP5kMcKmLSv2q5WdpwQE5sxiSdX3VmYgO6Nxkf0ePPMFNAZ2Wg3KiRhBkk R/P32aJnCLZtyIQfS9oFkhK78DGNj3VmRI21lkvnrzP/krofmDQUvk/q4YZuA6YvVK+1oY ttkzWTd/tbmmvuW9GLsOhEDltO2IaT3BjIQ21pn05dvQxbR59Tw7V0fMiVkN6oJYUQ9SSX 9HBpwLpUbzy7mY5IoPkNVYykGfy10e94wfDb1tiToImQ2EckoFsLpZzSVvj3dZsxBJv0IT IYXWnD6L4jqVUlCWFhskbphAGOcKoyVe3gJj2UePiI9A99K8jBp7E9AwJG8Qrg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676399034; a=rsa-sha256; cv=none; b=upDPgOCix0OOADQXNnRye5a6DBy0Ar6nQcMH3XNpjWEp4OF6cYTR5m+ZS4EtVvuWyj3ZAN C1rriv9XVfX/zOelisvtxxWpE5AvN8WCtRI8b+UvIJERleENXO64PT5vVHvANa4wVoRXmz WSoC5X6b2MOaXtxTd1Rnfb3lHp41FYWnVSCD6hwzsK8E58SLQnveC03ZEbwKEpBot1no/7 Sbnnnp/4KQOfnf9hHl9c3mFevPI77XNETforhuBJp8TPiZ9A7smHsNloWBuStMBFOnIZSp FvfLBTzwiOvnAdgzF+timAAAZnHtGjedmaW7dj42lKWNHXvUHmw+eXchNzvXxA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PGV2y3x4rz17wW; Tue, 14 Feb 2023 18:23:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31EINsTf087460; Tue, 14 Feb 2023 18:23:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31EINsQi087459; Tue, 14 Feb 2023 18:23:54 GMT (envelope-from git) Date: Tue, 14 Feb 2023 18:23:54 GMT Message-Id: <202302141823.31EINsQi087459@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 28137bdb19aa - main - intrng: track counter allocation with a bitmap List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 28137bdb19aa34b8351108de4257795a93c0ba09 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=28137bdb19aa34b8351108de4257795a93c0ba09 commit 28137bdb19aa34b8351108de4257795a93c0ba09 Author: Mitchell Horne AuthorDate: 2023-02-14 18:02:12 +0000 Commit: Mitchell Horne CommitDate: 2023-02-14 18:06:00 +0000 intrng: track counter allocation with a bitmap Crucially, this allows releasing counters, and interrupt sources by extension. Where before we were incrementing intrcnt_index with atomics, now we protect the bitmap using the existing isrc_table_lock mutex. Reviewed by: mmel MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D38437 --- sys/kern/subr_intr.c | 54 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/sys/kern/subr_intr.c b/sys/kern/subr_intr.c index 96a319b3c8b4..a95d2adbed04 100644 --- a/sys/kern/subr_intr.c +++ b/sys/kern/subr_intr.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -152,7 +153,8 @@ u_long *intrcnt; char *intrnames; size_t sintrcnt; size_t sintrnames; -static u_int intrcnt_index; +int nintrcnt; +static bitstr_t *intrcnt_bitmap; static struct intr_irqsrc *intr_map_get_isrc(u_int res_id); static void intr_map_set_isrc(u_int res_id, struct intr_irqsrc *isrc); @@ -166,7 +168,6 @@ static void intr_map_copy_map_data(u_int res_id, device_t *dev, intptr_t *xref, static void intr_irq_init(void *dummy __unused) { - u_int intrcnt_count; SLIST_INIT(&pic_list); mtx_init(&pic_list_lock, "intr pic list", NULL, MTX_DEF); @@ -177,17 +178,21 @@ intr_irq_init(void *dummy __unused) * - 2 counters for each I/O interrupt. * - MAXCPU counters for each IPI counters for SMP. */ - intrcnt_count = intr_nirq * 2; + nintrcnt = intr_nirq * 2; #ifdef SMP - intrcnt_count += INTR_IPI_COUNT * MAXCPU; + nintrcnt += INTR_IPI_COUNT * MAXCPU; #endif - intrcnt = mallocarray(intrcnt_count, sizeof(u_long), M_INTRNG, + intrcnt = mallocarray(nintrcnt, sizeof(u_long), M_INTRNG, M_WAITOK | M_ZERO); - intrnames = mallocarray(intrcnt_count, INTRNAME_LEN, M_INTRNG, + intrnames = mallocarray(nintrcnt, INTRNAME_LEN, M_INTRNG, M_WAITOK | M_ZERO); - sintrcnt = intrcnt_count * sizeof(u_long); - sintrnames = intrcnt_count * INTRNAME_LEN; + sintrcnt = nintrcnt * sizeof(u_long); + sintrnames = nintrcnt * INTRNAME_LEN; + + /* Allocate the bitmap tracking counter allocations. */ + intrcnt_bitmap = bit_alloc(nintrcnt, M_INTRNG, M_WAITOK | M_ZERO); + irq_sources = mallocarray(intr_nirq, sizeof(struct intr_irqsrc*), M_INTRNG, M_WAITOK | M_ZERO); } @@ -266,13 +271,17 @@ isrc_update_name(struct intr_irqsrc *isrc, const char *name) static void isrc_setup_counters(struct intr_irqsrc *isrc) { - u_int index; + int index; + + mtx_assert(&isrc_table_lock, MA_OWNED); /* - * XXX - it does not work well with removable controllers and - * interrupt sources !!! + * Allocate two counter values, the second tracking "stray" interrupts. */ - index = atomic_fetchadd_int(&intrcnt_index, 2); + bit_ffc_area(intrcnt_bitmap, nintrcnt, 2, &index); + if (index == -1) + panic("Failed to allocate 2 counters. Array exhausted?"); + bit_nset(intrcnt_bitmap, index, index + 1); isrc->isrc_index = index; isrc->isrc_count = &intrcnt[index]; isrc_update_name(isrc, NULL); @@ -284,8 +293,11 @@ isrc_setup_counters(struct intr_irqsrc *isrc) static void isrc_release_counters(struct intr_irqsrc *isrc) { + int idx = isrc->isrc_index; - panic("%s: not implemented", __func__); + mtx_assert(&isrc_table_lock, MA_OWNED); + + bit_nclear(intrcnt_bitmap, idx, idx + 1); } #ifdef SMP @@ -298,11 +310,25 @@ intr_ipi_setup_counters(const char *name) u_int index, i; char str[INTRNAME_LEN]; - index = atomic_fetchadd_int(&intrcnt_index, MAXCPU); + mtx_lock(&isrc_table_lock); + + /* + * We should never have a problem finding MAXCPU contiguous counters, + * in practice. Interrupts will be allocated sequentially during boot, + * so the array should fill from low to high index. Once reserved, the + * IPI counters will never be released. Similarly, we will not need to + * allocate more IPIs once the system is running. + */ + bit_ffc_area(intrcnt_bitmap, nintrcnt, MAXCPU, &index); + if (index == -1) + panic("Failed to allocate %d counters. Array exhausted?", + MAXCPU); + bit_nset(intrcnt_bitmap, index, index + MAXCPU - 1); for (i = 0; i < MAXCPU; i++) { snprintf(str, INTRNAME_LEN, "cpu%d:%s", i, name); intrcnt_setname(str, index + i); } + mtx_unlock(&isrc_table_lock); return (&intrcnt[index]); } #endif