From owner-freebsd-arch@FreeBSD.ORG Sat Apr 19 10:56:20 2008 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 84EC4106566C for ; Sat, 19 Apr 2008 10:56:20 +0000 (UTC) (envelope-from jroberson@jroberson.net) Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.172]) by mx1.freebsd.org (Postfix) with ESMTP id 589E98FC0C for ; Sat, 19 Apr 2008 10:56:20 +0000 (UTC) (envelope-from jroberson@jroberson.net) Received: by wf-out-1314.google.com with SMTP id 25so780382wfa.7 for ; Sat, 19 Apr 2008 03:56:20 -0700 (PDT) Received: by 10.142.128.6 with SMTP id a6mr977334wfd.206.1208602579876; Sat, 19 Apr 2008 03:56:19 -0700 (PDT) Received: from ?10.0.1.199? ( [24.94.72.120]) by mx.google.com with ESMTPS id 9sm2125776wfc.16.2008.04.19.03.56.18 (version=SSLv3 cipher=OTHER); Sat, 19 Apr 2008 03:56:19 -0700 (PDT) Date: Sat, 19 Apr 2008 00:56:44 -1000 (HST) From: Jeff Roberson X-X-Sender: jroberson@desktop To: arch@freebsd.org Message-ID: <20080419004911.R942@desktop> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Subject: monitor/mwait support for idle X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Apr 2008 10:56:20 -0000 http://people.freebsd.org/~jeff/mwait.diff This patch implements support for the x86/amd64 monitor and mwait instructions in the idle loop. This also implements idle loop selection via a sysctl string. The following loops are supported, in decreasing order of performance and power consumption: spin - Simply returns mwait - Always use mwait to sleep. CPU enters C0 or C1 depending on how busy it is. mwait_hlt - Use mwait when busy but fall back to hlt/acpi when not. hlt - pure hlt loop acpi - uses acpi_cpu_idle if available and hlt if not. This is the default. This also introduces a new MD function 'cpu_wake_idle' which allows MD to use a faster mechanism than IPI to wake idle. In the spin case this is a nop. For hlt and acpi we resort to an IPI. If the processor is sleeping in mwait we can simply write to a per-cpu buffer to wake it up. This saves considerable cpu cycles on the initiator and target. The prototype for cpu_idle() changed to accept an integer indication of how busy we are from the scheduler. If we have been busy MD code may choose to enter a higher power state on idle. ULE now spins for a short while if we have been very busy regardless of MD settings. There seems to be a problem entering C0 on the Xeons I have access to. It returns from mwait too quickly. Hopefully intel will respond to my email about that. Feedback welcome. Thanks, Jeff