From owner-svn-src-all@FreeBSD.ORG Fri Jul 23 16:46:42 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CA39D1065678; Fri, 23 Jul 2010 16:46:42 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A0AAC8FC19; Fri, 23 Jul 2010 16:46:42 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o6NGkgBj053860; Fri, 23 Jul 2010 16:46:42 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o6NGkgiv053858; Fri, 23 Jul 2010 16:46:42 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201007231646.o6NGkgiv053858@svn.freebsd.org> From: Andriy Gapon Date: Fri, 23 Jul 2010 16:46:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210422 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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, 23 Jul 2010 16:46:42 -0000 Author: avg Date: Fri Jul 23 16:46:42 2010 New Revision: 210422 URL: http://svn.freebsd.org/changeset/base/210422 Log: cpufreq: allocate long-lived buffer for handling of sysctl requests At present the cpufreq sysctl handler for current level setting would allocate and deallocate a temporary buffer of 24KB even to handle a read-only query. This puts unnecessary load on memory subsystem when current level is checked frequently, e.g. when the likes of powerd and system monitoring software are running. Change the strategy to allocating a long-lived buffer for handling the requests. Reviewed by: njl MFC after: 2 weeks Modified: head/sys/kern/kern_cpu.c Modified: head/sys/kern/kern_cpu.c ============================================================================== --- head/sys/kern/kern_cpu.c Fri Jul 23 15:32:44 2010 (r210421) +++ head/sys/kern/kern_cpu.c Fri Jul 23 16:46:42 2010 (r210422) @@ -76,6 +76,7 @@ struct cpufreq_softc { device_t dev; struct sysctl_ctx_list sysctl_ctx; struct task startup_task; + struct cf_level *levels_buf; }; struct cf_setting_array { @@ -180,6 +181,8 @@ cpufreq_attach(device_t dev) CF_DEBUG("initializing one-time data for %s\n", device_get_nameunit(dev)); + sc->levels_buf = malloc(CF_MAX_LEVELS * sizeof(*sc->levels_buf), + M_DEVBUF, M_WAITOK); SYSCTL_ADD_PROC(&sc->sysctl_ctx, SYSCTL_CHILDREN(device_get_sysctl_tree(parent)), OID_AUTO, "freq", CTLTYPE_INT | CTLFLAG_RW, sc, 0, @@ -227,6 +230,7 @@ cpufreq_detach(device_t dev) numdevs = devclass_get_count(cpufreq_dc); if (numdevs == 1) { CF_DEBUG("final shutdown for %s\n", device_get_nameunit(dev)); + free(sc->levels_buf, M_DEVBUF); } return (0); @@ -870,9 +874,7 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS) devs = NULL; sc = oidp->oid_arg1; - levels = malloc(CF_MAX_LEVELS * sizeof(*levels), M_TEMP, M_NOWAIT); - if (levels == NULL) - return (ENOMEM); + levels = sc->levels_buf; error = CPUFREQ_GET(sc->dev, &levels[0]); if (error) @@ -915,8 +917,6 @@ cpufreq_curr_sysctl(SYSCTL_HANDLER_ARGS) out: if (devs) free(devs, M_TEMP); - if (levels) - free(levels, M_TEMP); return (error); } @@ -934,7 +934,7 @@ cpufreq_levels_sysctl(SYSCTL_HANDLER_ARG /* Get settings from the device and generate the output string. */ count = CF_MAX_LEVELS; - levels = malloc(count * sizeof(*levels), M_TEMP, M_NOWAIT); + levels = sc->levels_buf; if (levels == NULL) { sbuf_delete(&sb); return (ENOMEM); @@ -957,7 +957,6 @@ cpufreq_levels_sysctl(SYSCTL_HANDLER_ARG error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); out: - free(levels, M_TEMP); sbuf_delete(&sb); return (error); }