From owner-svn-src-all@freebsd.org Fri Jul 3 14:54:47 2020 Return-Path: Delivered-To: svn-src-all@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 84D86350C90; Fri, 3 Jul 2020 14:54:47 +0000 (UTC) (envelope-from cem@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 49yyfv2sCpz4Mdp; Fri, 3 Jul 2020 14:54:47 +0000 (UTC) (envelope-from cem@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 45C8FD6F0; Fri, 3 Jul 2020 14:54:47 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 063EslYt049007; Fri, 3 Jul 2020 14:54:47 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 063EskxA049004; Fri, 3 Jul 2020 14:54:46 GMT (envelope-from cem@FreeBSD.org) Message-Id: <202007031454.063EskxA049004@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Fri, 3 Jul 2020 14:54:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362913 - in head/sys: amd64/amd64 amd64/include crypto/aesni crypto/blake2 X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/sys: amd64/amd64 amd64/include crypto/aesni crypto/blake2 X-SVN-Commit-Revision: 362913 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jul 2020 14:54:47 -0000 Author: cem Date: Fri Jul 3 14:54:46 2020 New Revision: 362913 URL: https://svnweb.freebsd.org/changeset/base/362913 Log: Add domain policy allocation for amd64 fpu_kern_ctx Like other types of allocation, fpu_kern_ctx are frequently allocated per-cpu. Provide the API and sketch some example consumers. fpu_kern_alloc_ctx_domain() preferentially allocates memory from the provided domain, and falls back to other domains if that one is empty (DOMAINSET_PREF(domain) policy). Maybe it makes more sense to just shove one of these in the DPCPU area sooner or later -- left for future work. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D22053 Modified: head/sys/amd64/amd64/fpu.c head/sys/amd64/include/fpu.h head/sys/crypto/aesni/aesni.c head/sys/crypto/blake2/blake2_cryptodev.c Modified: head/sys/amd64/amd64/fpu.c ============================================================================== --- head/sys/amd64/amd64/fpu.c Fri Jul 3 11:46:42 2020 (r362912) +++ head/sys/amd64/amd64/fpu.c Fri Jul 3 14:54:46 2020 (r362913) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1030,17 +1031,31 @@ struct fpu_kern_ctx { char hwstate1[]; }; +static inline size_t __pure2 +fpu_kern_alloc_sz(u_int max_est) +{ + return (sizeof(struct fpu_kern_ctx) + XSAVE_AREA_ALIGN + max_est); +} + +static inline int __pure2 +fpu_kern_malloc_flags(u_int fpflags) +{ + return (((fpflags & FPU_KERN_NOWAIT) ? M_NOWAIT : M_WAITOK) | M_ZERO); +} + struct fpu_kern_ctx * -fpu_kern_alloc_ctx(u_int flags) +fpu_kern_alloc_ctx_domain(int domain, u_int flags) { - struct fpu_kern_ctx *res; - size_t sz; + return (malloc_domainset(fpu_kern_alloc_sz(cpu_max_ext_state_size), + M_FPUKERN_CTX, DOMAINSET_PREF(domain), + fpu_kern_malloc_flags(flags))); +} - sz = sizeof(struct fpu_kern_ctx) + XSAVE_AREA_ALIGN + - cpu_max_ext_state_size; - res = malloc(sz, M_FPUKERN_CTX, ((flags & FPU_KERN_NOWAIT) ? - M_NOWAIT : M_WAITOK) | M_ZERO); - return (res); +struct fpu_kern_ctx * +fpu_kern_alloc_ctx(u_int flags) +{ + return (malloc(fpu_kern_alloc_sz(cpu_max_ext_state_size), + M_FPUKERN_CTX, fpu_kern_malloc_flags(flags))); } void Modified: head/sys/amd64/include/fpu.h ============================================================================== --- head/sys/amd64/include/fpu.h Fri Jul 3 11:46:42 2020 (r362912) +++ head/sys/amd64/include/fpu.h Fri Jul 3 14:54:46 2020 (r362913) @@ -71,6 +71,7 @@ int fputrap_sse(void); int fputrap_x87(void); void fpuuserinited(struct thread *td); struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int flags); +struct fpu_kern_ctx *fpu_kern_alloc_ctx_domain(int domain, u_int flags); void fpu_kern_free_ctx(struct fpu_kern_ctx *ctx); void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags); Modified: head/sys/crypto/aesni/aesni.c ============================================================================== --- head/sys/crypto/aesni/aesni.c Fri Jul 3 11:46:42 2020 (r362912) +++ head/sys/crypto/aesni/aesni.c Fri Jul 3 14:54:46 2020 (r362913) @@ -180,7 +180,12 @@ aesni_attach(device_t dev) M_WAITOK|M_ZERO); CPU_FOREACH(i) { - ctx_fpu[i] = fpu_kern_alloc_ctx(0); +#ifdef __amd64__ + ctx_fpu[i] = fpu_kern_alloc_ctx_domain( + pcpu_find(i)->pc_domain, FPU_KERN_NORMAL); +#else + ctx_fpu[i] = fpu_kern_alloc_ctx(FPU_KERN_NORMAL); +#endif mtx_init(&ctx_mtx[i], "anifpumtx", NULL, MTX_DEF|MTX_NEW); } Modified: head/sys/crypto/blake2/blake2_cryptodev.c ============================================================================== --- head/sys/crypto/blake2/blake2_cryptodev.c Fri Jul 3 11:46:42 2020 (r362912) +++ head/sys/crypto/blake2/blake2_cryptodev.c Fri Jul 3 14:54:46 2020 (r362913) @@ -142,7 +142,12 @@ blake2_attach(device_t dev) M_WAITOK | M_ZERO); CPU_FOREACH(i) { - ctx_fpu[i] = fpu_kern_alloc_ctx(0); +#ifdef __amd64__ + ctx_fpu[i] = fpu_kern_alloc_ctx_domain( + pcpu_find(i)->pc_domain, FPU_KERN_NORMAL); +#else + ctx_fpu[i] = fpu_kern_alloc_ctx(FPU_KERN_NORMAL); +#endif mtx_init(&ctx_mtx[i], "bl2fpumtx", NULL, MTX_DEF | MTX_NEW); }