From owner-freebsd-questions@FreeBSD.ORG Sun Mar 27 21:33:31 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0A13A16A4CE for ; Sun, 27 Mar 2005 21:33:31 +0000 (GMT) Received: from smtp11.wanadoo.fr (smtp11.wanadoo.fr [193.252.22.31]) by mx1.FreeBSD.org (Postfix) with ESMTP id 725F843D41 for ; Sun, 27 Mar 2005 21:33:30 +0000 (GMT) (envelope-from atkielski.anthony@wanadoo.fr) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1112.wanadoo.fr (SMTP Server) with ESMTP id 038971C000A9 for ; Sun, 27 Mar 2005 23:33:29 +0200 (CEST) Received: from pix.atkielski.com (ASt-Lambert-111-2-1-3.w81-50.abo.wanadoo.fr [81.50.80.3]) by mwinf1112.wanadoo.fr (SMTP Server) with ESMTP id CCD701C000A8 for ; Sun, 27 Mar 2005 23:33:28 +0200 (CEST) X-ME-UUID: 20050327213328839.CCD701C000A8@mwinf1112.wanadoo.fr Date: Sun, 27 Mar 2005 23:33:28 +0200 From: Anthony Atkielski X-Priority: 3 (Normal) Message-ID: <1162017909.20050327233328@wanadoo.fr> To: freebsd-questions@freebsd.org In-Reply-To: <200503272151.06216.list-freebsd-2004@morbius.sent.com> References: <8C7006AE7E80573-FAC-3B652@mblk-r28.sysops.aol.com> <49251524.20050326234521@wanadoo.fr> <200503272151.06216.list-freebsd-2004@morbius.sent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: hyper threading. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Mar 2005 21:33:31 -0000 RW writes: > Multiple processors can run multiple processes at the same time. A HT > processor can only run two threads from the same process. This is incorrect. HT processors don't care where the threads come from; it is possible to run threads from two completely different processes on the same HT processor. The threads have completely independent architectural states and can come from anywhere in the system. However, the design of hyperthreading favors a certain amount of commonality between the contexts of each thread. While it's best to have different instruction mixes, it helps if both threads are executing in the same memory spaces, since resources such as on-device cache are shared between the threads in the HT processor. Completely different threads in different processes executing out of different areas of memory might cause more contention for cache and similar resources (TLB, etc.), diminishing the advantage of hyperthreading. Also, spin waits need special consideration on HT processors. If one thread spins on a gate or semaphore held by the other thread, it effectively slows the other thread down, keeping both threads moving more slowly than they might if they were in completely separate processors. A solution for this suggested by Intel is the PAUSE instruction, which forces complete execution of a spin-wait instruction before the next execution can begin, thus freeing resources for the other thread in the processor. Intel recommends the use of PAUSE even when HT processors are not being used. Still another recommendation is to schedule first physically independent processors, then HT logical processors. This requires that the OS be aware of the difference between the two. This usually makes more efficient use of processor resources, except for some very specific cases where running two threads on the same HT processor might run as fast or faster than running them separately (if they are referencing a lot of the same shared resources, such as cache). Intel claims up to a 30% improvement in throughput for an HT processor as compared to a normal processor. For truly separate physical processors, the improvement is more like 60%, and possibly much more. Hyperthreading should not be seen as a substitute for multiple processors. It's more like a way to make better use of each processor. Hyperthreading is especially useful when multiple execution threads exist in a common context, such as multithreaded daemons or multithreaded desktop applications. In these situations, the HT architecture is used to the fullest, with corresponding improvements in performance. Recent changes in FreeBSD architecture to allow a multithreaded kernel are among the situations in which hyperthreading can be put to good use. The new multithreaded architecture of Apache 2.x should also be able to put HT to good use. -- Anthony