From owner-svn-src-stable@freebsd.org Mon Aug 24 14:26:49 2020 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BD6943C1B16; Mon, 24 Aug 2020 14:26:49 +0000 (UTC) (envelope-from trasz@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BZvZd4YLLz4t59; Mon, 24 Aug 2020 14:26:49 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 80B5119D41; Mon, 24 Aug 2020 14:26:49 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07OEQnQW098379; Mon, 24 Aug 2020 14:26:49 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07OEQn1h098378; Mon, 24 Aug 2020 14:26:49 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <202008241426.07OEQn1h098378@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Mon, 24 Aug 2020 14:26:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364688 - in stable/12/sys: kern sys X-SVN-Group: stable-12 X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: in stable/12/sys: kern sys X-SVN-Commit-Revision: 364688 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2020 14:26:49 -0000 Author: trasz Date: Mon Aug 24 14:26:48 2020 New Revision: 364688 URL: https://svnweb.freebsd.org/changeset/base/364688 Log: MFC r357492 by dchagin: For code reuse in Linuxulator rename get_proccess_cputime() and get_thread_cputime() and add prototypes for it to . As both functions become a public interface add process lock assert to ensure that the process is not exiting under it. Fix whitespace nit while here. Modified: stable/12/sys/kern/kern_time.c stable/12/sys/sys/syscallsubr.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_time.c ============================================================================== --- stable/12/sys/kern/kern_time.c Mon Aug 24 14:17:25 2020 (r364687) +++ stable/12/sys/kern/kern_time.c Mon Aug 24 14:26:48 2020 (r364688) @@ -243,7 +243,7 @@ sys_clock_gettime(struct thread *td, struct clock_gett return (error); } -static inline void +static inline void cputick2timespec(uint64_t runtime, struct timespec *ats) { runtime = cputick2usec(runtime); @@ -251,12 +251,15 @@ cputick2timespec(uint64_t runtime, struct timespec *at ats->tv_nsec = runtime % 1000000 * 1000; } -static void -get_thread_cputime(struct thread *targettd, struct timespec *ats) +void +kern_thread_cputime(struct thread *targettd, struct timespec *ats) { uint64_t runtime, curtime, switchtime; + struct proc *p; if (targettd == NULL) { /* current thread */ + p = curthread->td_proc; + PROC_LOCK_ASSERT(p, MA_OWNED); critical_enter(); switchtime = PCPU_GET(switchtime); curtime = cpu_ticks(); @@ -264,6 +267,8 @@ get_thread_cputime(struct thread *targettd, struct tim critical_exit(); runtime += curtime - switchtime; } else { + p = targettd->td_proc; + PROC_LOCK_ASSERT(p, MA_OWNED); thread_lock(targettd); runtime = targettd->td_runtime; thread_unlock(targettd); @@ -271,12 +276,13 @@ get_thread_cputime(struct thread *targettd, struct tim cputick2timespec(runtime, ats); } -static void -get_process_cputime(struct proc *targetp, struct timespec *ats) +void +kern_process_cputime(struct proc *targetp, struct timespec *ats) { uint64_t runtime; struct rusage ru; + PROC_LOCK_ASSERT(targetp, MA_OWNED); PROC_STATLOCK(targetp); rufetch(targetp, &ru); runtime = targetp->p_rux.rux_runtime; @@ -301,14 +307,14 @@ get_cputime(struct thread *td, clockid_t clock_id, str td2 = tdfind(tid, p->p_pid); if (td2 == NULL) return (EINVAL); - get_thread_cputime(td2, ats); + kern_thread_cputime(td2, ats); PROC_UNLOCK(td2->td_proc); } else { pid = clock_id & CPUCLOCK_ID_MASK; error = pget(pid, PGET_CANSEE, &p2); if (error != 0) return (EINVAL); - get_process_cputime(p2, ats); + kern_process_cputime(p2, ats); PROC_UNLOCK(p2); } return (0); @@ -361,11 +367,11 @@ kern_clock_gettime(struct thread *td, clockid_t clock_ ats->tv_nsec = 0; break; case CLOCK_THREAD_CPUTIME_ID: - get_thread_cputime(NULL, ats); + kern_thread_cputime(NULL, ats); break; case CLOCK_PROCESS_CPUTIME_ID: PROC_LOCK(p); - get_process_cputime(p, ats); + kern_process_cputime(p, ats); PROC_UNLOCK(p); break; default: Modified: stable/12/sys/sys/syscallsubr.h ============================================================================== --- stable/12/sys/sys/syscallsubr.h Mon Aug 24 14:17:25 2020 (r364687) +++ stable/12/sys/sys/syscallsubr.h Mon Aug 24 14:26:48 2020 (r364688) @@ -93,6 +93,8 @@ int kern_clock_nanosleep(struct thread *td, clockid_t const struct timespec *rqtp, struct timespec *rmtp); int kern_clock_settime(struct thread *td, clockid_t clock_id, struct timespec *ats); +void kern_thread_cputime(struct thread *targettd, struct timespec *ats); +void kern_process_cputime(struct proc *targetp, struct timespec *ats); int kern_close_range(struct thread *td, u_int lowfd, u_int highfd); int kern_close(struct thread *td, int fd); int kern_connectat(struct thread *td, int dirfd, int fd,