From nobody Fri Feb 11 17:51:45 2022 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 8C2BB19B696E; Fri, 11 Feb 2022 17:52:01 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4JwLm033mHz3CKC; Fri, 11 Feb 2022 17:52:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 21BHpjJ7051435 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 11 Feb 2022 19:51:48 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 21BHpjSq051434; Fri, 11 Feb 2022 19:51:45 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 11 Feb 2022 19:51:45 +0200 From: Konstantin Belousov To: Mateusz Guzik Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 32114b639fa1 - main - Add PROC_COW_CHANGECOUNT and thread_cow_synced Message-ID: References: <202202111357.21BDvxhr093033@gitrepo.freebsd.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <202202111357.21BDvxhr093033@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4JwLm033mHz3CKC X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-0.63 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.93)[-0.925]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FREEMAIL_FROM(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; NEURAL_HAM_LONG(-0.69)[-0.693]; R_SPF_SOFTFAIL(0.00)[~all:c]; NEURAL_SPAM_SHORT(0.99)[0.992]; TO_DN_SOME(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; FREEMAIL_ENVFROM(0.00)[gmail.com]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] X-ThisMailContainsUnwantedMimeParts: N On Fri, Feb 11, 2022 at 01:57:59PM +0000, Mateusz Guzik wrote: > The branch main has been updated by mjg: > > URL: https://cgit.FreeBSD.org/src/commit/?id=32114b639fa1ad777312eebe14a9f677bd7be2ea > > commit 32114b639fa1ad777312eebe14a9f677bd7be2ea > Author: Mateusz Guzik > AuthorDate: 2022-02-01 13:13:13 +0000 > Commit: Mateusz Guzik > CommitDate: 2022-02-11 11:44:07 +0000 > > Add PROC_COW_CHANGECOUNT and thread_cow_synced > > Combined they can be used to avoid a proc lock/unlock cycle in the > syscall handler for curthread, see upcoming examples. > --- > sys/kern/kern_thread.c | 13 +++++++++++++ > sys/sys/proc.h | 9 +++++++++ > 2 files changed, 22 insertions(+) > > diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c > index dcb52b137b58..bb724a17803e 100644 > --- a/sys/kern/kern_thread.c > +++ b/sys/kern/kern_thread.c > @@ -868,6 +868,19 @@ thread_cow_update(struct thread *td) > lim_free(oldlimit); > } > > +void > +thread_cow_synced(struct thread *td) > +{ > + struct proc *p; > + > + p = td->td_proc; > + PROC_LOCK_ASSERT(p, MA_OWNED); > + MPASS(td->td_cowgen != p->p_cowgen); > + MPASS(td->td_ucred == p->p_ucred); > + MPASS(td->td_limit == p->p_limit); > + td->td_cowgen = p->p_cowgen; This should be store-release, I think. And corresponding loads in trap() needs to get acquire semantic. This is probably a pre-existing bug. > +} > + > /* > * Discard the current thread and exit from its context. > * Always called with scheduler locked. > diff --git a/sys/sys/proc.h b/sys/sys/proc.h > index ff97bfbd54a9..0e33192303f4 100644 > --- a/sys/sys/proc.h > +++ b/sys/sys/proc.h > @@ -1009,6 +1009,14 @@ extern pid_t pid_max; > (p)->p_cowgen++; \ > } while (0) > > +#define PROC_COW_CHANGECOUNT(td, p) ({ \ > + struct thread *_td = (td); \ > + struct proc *_p = (p); \ > + MPASS(_td == curthread); \ > + PROC_LOCK_ASSERT(_p, MA_OWNED); \ > + _p->p_cowgen - _td->td_cowgen; \ > +}) > + > /* Check whether a thread is safe to be swapped out. */ > #define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP) > > @@ -1200,6 +1208,7 @@ void thread_cow_get_proc(struct thread *newtd, struct proc *p); > void thread_cow_get(struct thread *newtd, struct thread *td); > void thread_cow_free(struct thread *td); > void thread_cow_update(struct thread *td); > +void thread_cow_synced(struct thread *td); > int thread_create(struct thread *td, struct rtprio *rtp, > int (*initialize_thread)(struct thread *, void *), void *thunk); > void thread_exit(void) __dead2;