From nobody Thu Dec 02 19:07:13 2021 X-Original-To: dev-commits-src-main@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 1BADD18AE9B3; Thu, 2 Dec 2021 19:07:14 +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 4J4lnY59rqz4RGL; Thu, 2 Dec 2021 19:07:13 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 902D722C0F; Thu, 2 Dec 2021 19:07:13 +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 1B2J7Dq8095843; Thu, 2 Dec 2021 19:07:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B2J7D5F095842; Thu, 2 Dec 2021 19:07:13 GMT (envelope-from git) Date: Thu, 2 Dec 2021 19:07:13 GMT Message-Id: <202112021907.1B2J7D5F095842@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: d96fccc50513 - main - epoch: with EPOCH_TRACE add epoch_where_report() which will report where the epoch was entered and also mark the tracker, so that exit will also be reported. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d96fccc50513b807c5ec5e880c2340c1efcb97c1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638472033; 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=p3UOqd0XnC+rKw/lcjDu4l1p2ypioS4Pk9TdXReGDZo=; b=rJR2eNuOgl0udyAI7LY6O91dBoqaRNr12+IzZn3N0Yd9gvM6CYLkhvVxsO43bprEJWsTkp LO8+2ghCfxmqj9HrzqIxTB0YFORy4ekaJiI0KNoBSoOi4wcutA49YClTaaICMRyMVzq7aY rIKHDXlFUclMrXGiEdiAFTa8F4VpsEC2kuFiqAl3xojp9RkFRDpT2XZ52NFkaUbrheaePx p9kh97+JwavAJQuRUfSeb9e0L9lJ3YC1Jnh5jbTUZNL6bRK4MMw+57ZDzEchCrmGNsurod HjW8FCBm9Xt8NQOKFfd6pKR26g/WsBWOz69gqn0BVsgN7MYqCHMd/YAN9nHCHg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638472033; a=rsa-sha256; cv=none; b=pfI1UFfmJvdYhQmCwn+T3cF0sY5IGvS3jvn3aX6LZzaVn0oSBWY08M2bkUqfVXXayQih27 joMUAKT8SOqMwx2Ega4d8GhpvmYe6MdYdNxGfqQ/HUxs7vM2K6gAYW/ZF5WN1OMM9Iz2fe Cc6ylO2CZGO+6VAHBGC/4U2I+TYDvb+l5GaH7xdD09gCS5U4f6Htv8TWJVR3hLreXB2GPw hw/CMMBtvn0Sm++d7OZiDjIauHdOh43d2CN0KPXJ+z0ymk7XhbdLT0tZiP6HAe9SM/ndYR OiEfkM6MHVGaIePD3/9LFkR0Vo2yFD9+OLfYYtk2uOMkP1qAle1fzYp1STekFA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d96fccc50513b807c5ec5e880c2340c1efcb97c1 commit d96fccc50513b807c5ec5e880c2340c1efcb97c1 Author: Gleb Smirnoff AuthorDate: 2021-12-02 18:59:43 +0000 Commit: Gleb Smirnoff CommitDate: 2021-12-02 19:02:51 +0000 epoch: with EPOCH_TRACE add epoch_where_report() which will report where the epoch was entered and also mark the tracker, so that exit will also be reported. Helps to understand epoch entrance/exit scenarios in complex cases, like network stack. As everything else under EPOCH_TRACE it is a developer only tool. --- sys/kern/subr_epoch.c | 40 +++++++++++++++++++++++++++++++++------- sys/sys/epoch.h | 3 +++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/sys/kern/subr_epoch.c b/sys/kern/subr_epoch.c index 651fd8b419f0..74524fb3f97e 100644 --- a/sys/kern/subr_epoch.c +++ b/sys/kern/subr_epoch.c @@ -147,6 +147,13 @@ static struct sx epoch_sx; #define EPOCH_LOCK() sx_xlock(&epoch_sx) #define EPOCH_UNLOCK() sx_xunlock(&epoch_sx) +static epoch_record_t +epoch_currecord(epoch_t epoch) +{ + + return (zpcpu_get(epoch->e_pcpu_record)); +} + #ifdef EPOCH_TRACE struct stackentry { RB_ENTRY(stackentry) se_node; @@ -230,6 +237,7 @@ epoch_trace_enter(struct thread *td, epoch_t epoch, epoch_tracker_t et, et->et_epoch = epoch; et->et_file = file; et->et_line = line; + et->et_flags = 0; SLIST_INSERT_HEAD(&td->td_epochs, et, et_tlink); } @@ -250,6 +258,9 @@ epoch_trace_exit(struct thread *td, epoch_t epoch, epoch_tracker_t et, SLIST_REMOVE(&td->td_epochs, et, epoch_tracker, et_tlink); } else SLIST_REMOVE_HEAD(&td->td_epochs, et_tlink); + if (et->et_flags & ET_REPORT_EXIT) + printf("Td %p exiting epoch %s at %s:%d\n", td, epoch->e_name, + file, line); } /* Used by assertions that check thread state before going to sleep. */ @@ -262,6 +273,28 @@ epoch_trace_list(struct thread *td) printf("Epoch %s entered at %s:%d\n", iet->et_epoch->e_name, iet->et_file, iet->et_line); } + +void +epoch_where_report(epoch_t epoch) +{ + epoch_record_t er; + struct epoch_tracker *tdwait; + + MPASS(epoch != NULL); + MPASS((epoch->e_flags & EPOCH_PREEMPT) != 0); + MPASS(!THREAD_CAN_SLEEP()); + critical_enter(); + er = epoch_currecord(epoch); + TAILQ_FOREACH(tdwait, &er->er_tdlist, et_link) + if (tdwait->et_td == curthread) + break; + critical_exit(); + if (tdwait != NULL) { + tdwait->et_flags |= ET_REPORT_EXIT; + printf("Td %p entered epoch %s at %s:%d\n", curthread, + epoch->e_name, tdwait->et_file, tdwait->et_line); + } +} #endif /* EPOCH_TRACE */ static void @@ -422,13 +455,6 @@ epoch_free(epoch_t epoch) EPOCH_UNLOCK(); } -static epoch_record_t -epoch_currecord(epoch_t epoch) -{ - - return (zpcpu_get(epoch->e_pcpu_record)); -} - #define INIT_CHECK(epoch) \ do { \ if (__predict_false((epoch) == NULL)) \ diff --git a/sys/sys/epoch.h b/sys/sys/epoch.h index 85c791d3df6c..6ce0fcd01c60 100644 --- a/sys/sys/epoch.h +++ b/sys/sys/epoch.h @@ -61,6 +61,8 @@ struct epoch_tracker { SLIST_ENTRY(epoch_tracker) et_tlink; const char *et_file; int et_line; + int et_flags; +#define ET_REPORT_EXIT 0x1 #endif } __aligned(sizeof(void *)); typedef struct epoch_tracker *epoch_tracker_t; @@ -86,6 +88,7 @@ void _epoch_enter_preempt(epoch_t epoch, epoch_tracker_t et EPOCH_FILE_LINE); void _epoch_exit_preempt(epoch_t epoch, epoch_tracker_t et EPOCH_FILE_LINE); #ifdef EPOCH_TRACE void epoch_trace_list(struct thread *); +void epoch_where_report(epoch_t); #define epoch_enter_preempt(epoch, et) _epoch_enter_preempt(epoch, et, __FILE__, __LINE__) #define epoch_exit_preempt(epoch, et) _epoch_exit_preempt(epoch, et, __FILE__, __LINE__) #else